Skip to content

Commit de4d9d8

Browse files
fix: icon client add prev consensus height method (#661)
1 parent 2681351 commit de4d9d8

File tree

6 files changed

+33
-2
lines changed

6 files changed

+33
-2
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ debug/
4545
target/
4646
artifacts/*
4747

48+
report/**
49+
4850
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
4951
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
5052
#Cargo.lock

contracts/cosmwasm-vm/cw-common/src/client_msg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub enum QueryMsg {
7777
VerifyConnectionOpenTry(VerifyConnectionPayload),
7878
#[returns(bool)]
7979
VerifyConnectionOpenAck(VerifyConnectionPayload),
80-
#[returns(Vec<u8>)]
80+
#[returns(Vec<u64>)]
8181
GetPreviousConsensusState { client_id: String, height: u64 },
8282
}
8383

contracts/cosmwasm-vm/cw-common/src/core_msg.rs

+2
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,6 @@ pub enum QueryMsg {
205205
start_sequence: u64,
206206
end_sequence: u64,
207207
},
208+
#[returns(Vec<u64>)]
209+
GetPreviousConsensusStateHeight { client_id: String, height: u64 },
208210
}

contracts/cosmwasm-vm/cw-ibc-core/src/contract.rs

+8
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,14 @@ impl<'a> CwIbcCoreContext<'a> {
495495
.unwrap();
496496
to_binary(&missing)
497497
}
498+
QueryMsg::GetPreviousConsensusStateHeight { client_id, height } => {
499+
let client_val = IbcClientId::from_str(&client_id).unwrap();
500+
let client = self.get_client(deps.storage, &client_val).unwrap();
501+
let res = client
502+
.get_previous_consensus_state(deps, &client_val, height)
503+
.unwrap();
504+
to_binary(&res)
505+
}
498506
}
499507
}
500508

contracts/cosmwasm-vm/cw-ibc-core/src/light_client/light_client.rs

+19
Original file line numberDiff line numberDiff line change
@@ -209,4 +209,23 @@ impl LightClient {
209209
let response: Vec<u8> = deps.querier.query(&query).map_err(ContractError::Std)?;
210210
Ok(response)
211211
}
212+
213+
pub fn get_previous_consensus_state(
214+
&self,
215+
deps: Deps,
216+
client_id: &IbcClientId,
217+
height: u64,
218+
) -> Result<Vec<u64>, ContractError> {
219+
let query_message = cw_common::client_msg::QueryMsg::GetPreviousConsensusState {
220+
client_id: client_id.as_str().to_string(),
221+
height,
222+
};
223+
let msg = to_binary(&query_message).map_err(ContractError::Std)?;
224+
225+
let query = build_smart_query(self.address.clone(), msg);
226+
227+
let response: Vec<u64> = deps.querier.query(&query).map_err(ContractError::Std)?;
228+
229+
Ok(response)
230+
}
212231
}

contracts/cosmwasm-vm/cw-icon-light-client/src/contract.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
493493
to_binary(&(is_channel_valid && _sequence_valid))
494494
}
495495
QueryMsg::GetPreviousConsensusState { client_id, height } => {
496-
let res =
496+
let res: Vec<u64> =
497497
QueryHandler::get_previous_consensus(deps.storage, height, client_id).unwrap();
498498
to_binary(&res)
499499
}

0 commit comments

Comments
 (0)