Skip to content

Commit

Permalink
imp: removed ExportMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
srdtrk committed Jul 15, 2024
1 parent 5a5f63e commit 586ed88
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 95 deletions.
57 changes: 2 additions & 55 deletions ibc-clients/cw-context/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ use ibc_core::client::types::error::ClientError;
use ibc_core::client::types::Height;
use ibc_core::host::types::identifiers::ClientId;
use ibc_core::host::types::path::{
iteration_key, ClientStatePath, ClientUpdateHeightPath, ClientUpdateTimePath,
ITERATE_CONSENSUS_STATE_PREFIX,
ClientStatePath, ClientUpdateHeightPath, ClientUpdateTimePath, ITERATE_CONSENSUS_STATE_PREFIX,
};
use ibc_core::primitives::proto::{Any, Protobuf};
use prost::Message;

use crate::api::ClientType;
use crate::types::{ContractError, GenesisMetadata, HeightTravel, MigrationPrefix};
use crate::types::{ContractError, HeightTravel, MigrationPrefix};
use crate::utils::AnyCodec;

/// - [`Height`] cannot be used directly as keys in the map,
Expand Down Expand Up @@ -219,58 +218,6 @@ where
client_update_height_path.leaf().into_bytes()
}

/// Returns the genesis metadata by iterating over the stored consensus
/// state metadata.
pub fn get_metadata(&self) -> Result<Option<Vec<GenesisMetadata>>, ContractError> {
let mut metadata = Vec::<GenesisMetadata>::new();

let iterator = CONSENSUS_STATE_HEIGHT_MAP
.keys(self.storage_ref(), None, None, Order::Ascending)
.map(|deserialized_result| {
let (rev_number, rev_height) =
deserialized_result.map_err(|e| ClientError::Other {
description: e.to_string(),
})?;
Height::new(rev_number, rev_height)
});

for height_result in iterator {
let height = height_result?;

let processed_height_key = self.client_update_height_key(&height);
metadata.push(GenesisMetadata {
key: processed_height_key.clone().into(),
value: self.retrieve(&processed_height_key)?.into(),
});
let processed_time_key = self.client_update_time_key(&height);
metadata.push(GenesisMetadata {
key: processed_time_key.clone().into(),
value: self.retrieve(&processed_time_key)?.into(),
});
}

let iterator = CONSENSUS_STATE_HEIGHT_MAP
.keys(self.storage_ref(), None, None, Order::Ascending)
.map(|deserialized_result| {
let (rev_number, rev_height) =
deserialized_result.map_err(|e| ClientError::Other {
description: e.to_string(),
})?;
Height::new(rev_number, rev_height)
});

for height_result in iterator {
let height = height_result?;

metadata.push(GenesisMetadata {
key: iteration_key(height.revision_number(), height.revision_height()).into(),
value: height.encode_vec().into(),
});
}

Ok(Some(metadata))
}

/// Returns the checksum of the current contract.
pub fn obtain_checksum(&self) -> Result<Checksum, ClientError> {
match &self.checksum {
Expand Down
13 changes: 4 additions & 9 deletions ibc-clients/cw-context/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ use crate::api::ClientType;
use crate::context::Context;
use crate::types::{
CheckForMisbehaviourMsg, CheckForMisbehaviourResponse, ContractError, ContractResult,
ExportMetadataMsg, ExportMetadataResponse, InstantiateMsg, QueryMsg, StatusMsg, StatusResponse,
SudoMsg, TimestampAtHeightResponse, UpdateStateMsg, UpdateStateOnMisbehaviourMsg,
VerifyClientMessageMsg, VerifyClientMessageResponse, VerifyMembershipMsg,
VerifyNonMembershipMsg, VerifyUpgradeAndUpdateStateMsg,
InstantiateMsg, QueryMsg, StatusMsg, StatusResponse, SudoMsg, TimestampAtHeightResponse,
UpdateStateMsg, UpdateStateOnMisbehaviourMsg, VerifyClientMessageMsg,
VerifyClientMessageResponse, VerifyMembershipMsg, VerifyNonMembershipMsg,
VerifyUpgradeAndUpdateStateMsg,
};

impl<'a, C: ClientType<'a>> Context<'a, C>
Expand Down Expand Up @@ -174,11 +174,6 @@ where
},
))
}
QueryMsg::ExportMetadata(ExportMetadataMsg {}) => {
to_json_binary(&ExportMetadataResponse {
genesis_metadata: self.get_metadata()?,
})
}
QueryMsg::TimestampAtHeight(msg) => {
let client_cons_state_path = ClientConsensusStatePath::new(
client_id,
Expand Down
6 changes: 0 additions & 6 deletions ibc-clients/cw-context/src/types/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,6 @@ pub struct MigrateClientStoreMsg {}
pub enum QueryMsg {
#[returns(crate::types::response::StatusResponse)]
Status(StatusMsg),
// NOTE: The `ExportMetadata` variant is removed from 08-wasm module
#[returns(crate::types::response::ExportMetadataResponse)]
ExportMetadata(ExportMetadataMsg),
#[returns(crate::types::response::TimestampAtHeightResponse)]
TimestampAtHeight(TimestampAtHeightMsg),
#[returns(crate::types::response::VerifyClientMessageResponse)]
Expand All @@ -220,9 +217,6 @@ pub enum QueryMsg {
#[cw_serde]
pub struct StatusMsg {}

#[cw_serde]
pub struct ExportMetadataMsg {}

#[cw_serde]
pub struct TimestampAtHeightMsg {
pub height: Height,
Expand Down
15 changes: 0 additions & 15 deletions ibc-clients/cw-context/src/types/response.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Contains the response types for the CosmWasm contract.
use cosmwasm_schema::cw_serde;
use cosmwasm_std::Binary;
use ibc_core::client::types::Height;

/// The response to [`super::msgs::QueryMsg::Status`]
Expand All @@ -11,14 +10,6 @@ pub struct StatusResponse {
pub status: String,
}

/// The response to [`super::msgs::QueryMsg::ExportMetadata`]
#[cw_serde]
pub struct ExportMetadataResponse {
/// The genesis metadata
#[serde(skip_serializing_if = "Option::is_none")]
pub genesis_metadata: Option<Vec<GenesisMetadata>>,
}

/// The response to [`super::msgs::QueryMsg::TimestampAtHeight`]
#[cw_serde]
pub struct TimestampAtHeightResponse {
Expand All @@ -40,12 +31,6 @@ pub struct CheckForMisbehaviourResponse {
pub found_misbehaviour: bool,
}

#[cw_serde]
pub struct GenesisMetadata {
pub key: Binary,
pub value: Binary,
}

#[cw_serde]
pub struct ContractResult {
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
13 changes: 3 additions & 10 deletions tests-integration/tests/cosmwasm/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ use ibc::core::client::types::{Height, Status};
use ibc::core::host::types::identifiers::ChainId;
use ibc::core::primitives::Timestamp;
use ibc_client_cw::types::{
CheckForMisbehaviourMsgRaw, CheckForMisbehaviourResponse, ContractError, ExportMetadataMsg,
ExportMetadataResponse, GenesisMetadata, InstantiateMsg, MigrationPrefix, QueryMsg, StatusMsg,
StatusResponse, UpdateStateMsgRaw, UpdateStateOnMisbehaviourMsgRaw, VerifyClientMessageRaw,
VerifyClientMessageResponse,
CheckForMisbehaviourMsgRaw, CheckForMisbehaviourResponse, ContractError, InstantiateMsg,
MigrationPrefix, QueryMsg, StatusMsg, StatusResponse, UpdateStateMsgRaw,
UpdateStateOnMisbehaviourMsgRaw, VerifyClientMessageRaw, VerifyClientMessageResponse,
};
use ibc_client_cw::utils::AnyCodec;
use ibc_client_tendermint_cw::entrypoint::TendermintContext;
Expand Down Expand Up @@ -175,12 +174,6 @@ impl Fixture {
assert_eq!(resp.status, expected.to_string());
}

pub fn get_metadata(&self, deps: Deps<'_>) -> Option<Vec<GenesisMetadata>> {
self.query::<ExportMetadataResponse>(deps, ExportMetadataMsg {}.into())
.map(|resp| resp.genesis_metadata)
.unwrap()
}

pub fn query<T: DeserializeOwned>(&self, deps: Deps<'_>, msg: QueryMsg) -> StdResult<T> {
let ctx = self.ctx_ref(deps);

Expand Down

0 comments on commit 586ed88

Please sign in to comment.