|
| 1 | +use neutron_std_derive::CosmwasmExt; |
| 2 | +/// Describes a "light" consensus state of the chain at a particular height |
| 3 | +#[allow(clippy::derive_partial_eq_without_eq)] |
| 4 | +#[derive( |
| 5 | + Clone, |
| 6 | + PartialEq, |
| 7 | + Eq, |
| 8 | + ::prost::Message, |
| 9 | + ::serde::Serialize, |
| 10 | + ::serde::Deserialize, |
| 11 | + ::schemars::JsonSchema, |
| 12 | + CosmwasmExt, |
| 13 | +)] |
| 14 | +#[proto_message(type_url = "/neutron.state_verifier.v1.ConsensusState")] |
| 15 | +pub struct ConsensusState { |
| 16 | + /// Describes a block height for which the consensus height is saved |
| 17 | + #[prost(int64, tag = "1")] |
| 18 | + #[serde( |
| 19 | + serialize_with = "crate::serde::as_str::serialize", |
| 20 | + deserialize_with = "crate::serde::as_str::deserialize" |
| 21 | + )] |
| 22 | + pub height: i64, |
| 23 | + /// ConsensusState defines the consensus state from Tendermint |
| 24 | + #[prost(message, optional, tag = "2")] |
| 25 | + pub cs: ::core::option::Option< |
| 26 | + super::super::super::ibc::lightclients::tendermint::v1::ConsensusState, |
| 27 | + >, |
| 28 | +} |
| 29 | +/// Defines the state verifier module's genesis state. |
| 30 | +#[allow(clippy::derive_partial_eq_without_eq)] |
| 31 | +#[derive( |
| 32 | + Clone, |
| 33 | + PartialEq, |
| 34 | + Eq, |
| 35 | + ::prost::Message, |
| 36 | + ::serde::Serialize, |
| 37 | + ::serde::Deserialize, |
| 38 | + ::schemars::JsonSchema, |
| 39 | + CosmwasmExt, |
| 40 | +)] |
| 41 | +#[proto_message(type_url = "/neutron.state_verifier.v1.GenesisState")] |
| 42 | +pub struct GenesisState { |
| 43 | + #[prost(message, repeated, tag = "1")] |
| 44 | + pub states: ::prost::alloc::vec::Vec<ConsensusState>, |
| 45 | +} |
| 46 | +/// Describes a structure to verify storage values from the chain state from a particular height in the past |
| 47 | +#[allow(clippy::derive_partial_eq_without_eq)] |
| 48 | +#[derive( |
| 49 | + Clone, |
| 50 | + PartialEq, |
| 51 | + Eq, |
| 52 | + ::prost::Message, |
| 53 | + ::serde::Serialize, |
| 54 | + ::serde::Deserialize, |
| 55 | + ::schemars::JsonSchema, |
| 56 | + CosmwasmExt, |
| 57 | +)] |
| 58 | +#[proto_message(type_url = "/neutron.state_verifier.v1.QueryVerifyStateValuesRequest")] |
| 59 | +#[proto_query( |
| 60 | + path = "/neutron.state_verifier.v1.Query/VerifyStateValues", |
| 61 | + response_type = QueryVerifyStateValuesResponse |
| 62 | +)] |
| 63 | +pub struct QueryVerifyStateValuesRequest { |
| 64 | + /// Refers to the block height to which the storage values belong. |
| 65 | + #[prost(uint64, tag = "1")] |
| 66 | + #[serde( |
| 67 | + serialize_with = "crate::serde::as_str::serialize", |
| 68 | + deserialize_with = "crate::serde::as_str::deserialize" |
| 69 | + )] |
| 70 | + pub height: u64, |
| 71 | + /// A slice of neutron.interchainqueries.StorageValue which relate to the specified height and must be verified against |
| 72 | + #[prost(message, repeated, tag = "2")] |
| 73 | + pub storage_values: ::prost::alloc::vec::Vec<super::super::interchainqueries::StorageValue>, |
| 74 | +} |
| 75 | +/// Describes a response structure for `VerifyStateValues` query |
| 76 | +#[allow(clippy::derive_partial_eq_without_eq)] |
| 77 | +#[derive( |
| 78 | + Clone, |
| 79 | + PartialEq, |
| 80 | + Eq, |
| 81 | + ::prost::Message, |
| 82 | + ::serde::Serialize, |
| 83 | + ::serde::Deserialize, |
| 84 | + ::schemars::JsonSchema, |
| 85 | + CosmwasmExt, |
| 86 | +)] |
| 87 | +#[proto_message(type_url = "/neutron.state_verifier.v1.QueryVerifyStateValuesResponse")] |
| 88 | +pub struct QueryVerifyStateValuesResponse { |
| 89 | + /// The field describes a validity of all the storage values passed to the request at a specific height |
| 90 | + #[prost(bool, tag = "1")] |
| 91 | + pub valid: bool, |
| 92 | +} |
| 93 | +/// Describes a structure to query ConsensusState by the specified height |
| 94 | +#[allow(clippy::derive_partial_eq_without_eq)] |
| 95 | +#[derive( |
| 96 | + Clone, |
| 97 | + PartialEq, |
| 98 | + Eq, |
| 99 | + ::prost::Message, |
| 100 | + ::serde::Serialize, |
| 101 | + ::serde::Deserialize, |
| 102 | + ::schemars::JsonSchema, |
| 103 | + CosmwasmExt, |
| 104 | +)] |
| 105 | +#[proto_message(type_url = "/neutron.state_verifier.v1.QueryConsensusStateRequest")] |
| 106 | +#[proto_query( |
| 107 | + path = "/neutron.state_verifier.v1.Query/QueryConsensusState", |
| 108 | + response_type = QueryConsensusStateResponse |
| 109 | +)] |
| 110 | +pub struct QueryConsensusStateRequest { |
| 111 | + /// Refers to the block height for which you want to query ConsensusState |
| 112 | + #[prost(uint64, tag = "1")] |
| 113 | + #[serde( |
| 114 | + serialize_with = "crate::serde::as_str::serialize", |
| 115 | + deserialize_with = "crate::serde::as_str::deserialize" |
| 116 | + )] |
| 117 | + pub height: u64, |
| 118 | +} |
| 119 | +/// Describes a response structure for `QueryConsensusStateRequest` query |
| 120 | +#[allow(clippy::derive_partial_eq_without_eq)] |
| 121 | +#[derive( |
| 122 | + Clone, |
| 123 | + PartialEq, |
| 124 | + Eq, |
| 125 | + ::prost::Message, |
| 126 | + ::serde::Serialize, |
| 127 | + ::serde::Deserialize, |
| 128 | + ::schemars::JsonSchema, |
| 129 | + CosmwasmExt, |
| 130 | +)] |
| 131 | +#[proto_message(type_url = "/neutron.state_verifier.v1.QueryConsensusStateResponse")] |
| 132 | +pub struct QueryConsensusStateResponse { |
| 133 | + /// ConsensusState defines the consensus state from the state-verifier module |
| 134 | + #[prost(message, optional, tag = "2")] |
| 135 | + pub cs: ::core::option::Option<ConsensusState>, |
| 136 | +} |
| 137 | +pub struct StateVerifierQuerier<'a, Q: cosmwasm_std::CustomQuery> { |
| 138 | + querier: &'a cosmwasm_std::QuerierWrapper<'a, Q>, |
| 139 | +} |
| 140 | +impl<'a, Q: cosmwasm_std::CustomQuery> StateVerifierQuerier<'a, Q> { |
| 141 | + pub fn new(querier: &'a cosmwasm_std::QuerierWrapper<'a, Q>) -> Self { |
| 142 | + Self { querier } |
| 143 | + } |
| 144 | + pub fn verify_state_values( |
| 145 | + &self, |
| 146 | + height: u64, |
| 147 | + storage_values: ::prost::alloc::vec::Vec<super::super::interchainqueries::StorageValue>, |
| 148 | + ) -> Result<QueryVerifyStateValuesResponse, cosmwasm_std::StdError> { |
| 149 | + QueryVerifyStateValuesRequest { |
| 150 | + height, |
| 151 | + storage_values, |
| 152 | + } |
| 153 | + .query(self.querier) |
| 154 | + } |
| 155 | + pub fn query_consensus_state( |
| 156 | + &self, |
| 157 | + height: u64, |
| 158 | + ) -> Result<QueryConsensusStateResponse, cosmwasm_std::StdError> { |
| 159 | + QueryConsensusStateRequest { height }.query(self.querier) |
| 160 | + } |
| 161 | +} |
0 commit comments