Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ics10-grandpa-cw: decode consensus state to check for expiration #448

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions light-clients/ics10-grandpa-cw/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ fn process_message(
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
let client_id = ClientId::from_str("08-wasm-0").expect("client id is valid");
match msg {
QueryMsg::ClientTypeMsg(_) => unimplemented!("ClientTypeMsg"),
Expand All @@ -351,7 +351,13 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
} else {
let height = client_state.latest_height();
match get_consensus_state(deps, &client_id, height) {
Ok(_) => to_binary(&QueryResponse::status("Active".to_string())),
Ok(consensus_state_raw) => {
let consensus_state = Context::decode_consensus_state(&consensus_state_raw)?;
if client_state.expired(env.block.time - consensus_state.timestamp) {
blasrodri marked this conversation as resolved.
Show resolved Hide resolved
return to_binary(&QueryResponse::status("Expired".to_string()));
}
to_binary(&QueryResponse::status("Active".to_string()))
},
Err(_) => to_binary(&QueryResponse::status("Expired".to_string())),
}
}
Expand Down
Loading