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

IBC client updating #252

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Changes from all commits
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
39 changes: 39 additions & 0 deletions src/ibc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,45 @@
pub fn transfer_mut(&mut self) -> &mut Transfer {
&mut self.router.transfer
}

pub fn update_client_from_header(
&mut self,
client_index: u64,
rev_number: u64,
header_json: &str,
) -> crate::Result<()> {
let client_id: ClientId =
IbcClientId::new(ClientType::new("07-tendermint").unwrap(), client_index)
.unwrap()
.into();
let header: orga::cosmrs::tendermint::block::Header = serde_json::from_str(header_json)?;
let mut client = self
.ctx
.clients
.get_mut(client_id)?
.ok_or(Error::Ibc("Client not found".to_string()))?;
let height = Height::new(rev_number, header.height.value()).unwrap();
client.updates.insert(
height.into(),
(IbcTimestamp::from(header.time).into(), height.into()),
)?;

Check warning on line 238 in src/ibc/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/ibc/mod.rs#L218-L238

Added lines #L218 - L238 were not covered by tests

let mut state = client
.client_state
.get_mut(orga::encoding::FixedString::<"State">)?
.unwrap();

state.inner.latest_height = height;

let consensus_state = ConsensusState {
inner: header.into(),
};
client
.consensus_states
.insert(height.into(), consensus_state)?;

Check warning on line 252 in src/ibc/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/ibc/mod.rs#L240-L252

Added lines #L240 - L252 were not covered by tests

Ok(())
}

Check warning on line 255 in src/ibc/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/ibc/mod.rs#L254-L255

Added lines #L254 - L255 were not covered by tests
}

impl std::fmt::Debug for IbcContext {
Expand Down
Loading