Skip to content

Commit

Permalink
Merge pull request #278 from turbofish-org/ibc-patch
Browse files Browse the repository at this point in the history
IBC gRPC fix
  • Loading branch information
keppel authored Nov 16, 2024
2 parents b111255 + 52a81fd commit c1c7a04
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 45 deletions.
51 changes: 51 additions & 0 deletions src/ibc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,57 @@ impl Ibc {
Ok(self.transfer_mut().incoming_transfer_mut().take())
}

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

let consensus_state = WrappedConsensusState {
inner: header.into(),
};

let mut client_state = client
.client_state
.get(Default::default())?
.ok_or(Error::Ibc("Client not found".to_string()))?
.inner
.inner()
.clone();

client_state.latest_height = height;
client.client_state.insert(
Default::default(),
WrappedClientState {
inner: client_state.into(),
},
)?;

client
.consensus_states
.insert(height.into(), consensus_state)?;

Ok(())
}

fn signer(&mut self) -> crate::Result<Address> {
self.context::<Signer>()
.ok_or_else(|| Error::Coins("No Signer context available".into()))?
Expand Down
Loading

0 comments on commit c1c7a04

Please sign in to comment.