This repository has been archived by the owner on Jun 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
imp: refactor mock rollup for committing states
- Loading branch information
1 parent
45aaaf7
commit 16ac05f
Showing
24 changed files
with
1,039 additions
and
802 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
pub mod app; | ||
pub mod builder; | ||
pub mod handle; | ||
pub mod helpers; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use std::fmt::Debug; | ||
|
||
use basecoin_store::context::ProvableStore; | ||
use ibc_client_tendermint::types::Header; | ||
use ibc_core::handler::types::events::IbcEvent; | ||
use ibc_core::host::ValidationContext; | ||
use ibc_core::primitives::proto::Any; | ||
use ibc_core_host_cosmos::IBC_QUERY_PATH; | ||
|
||
use crate::cosmos::app::MockCosmosChain; | ||
use crate::relayer::handle::{Handle, QueryReq, QueryResp}; | ||
|
||
impl<S: ProvableStore + Debug + Default> Handle for MockCosmosChain<S> { | ||
fn query(&self, request: QueryReq) -> QueryResp { | ||
match request { | ||
QueryReq::ChainId => QueryResp::ChainId(self.chain_id().clone()), | ||
QueryReq::HostHeight => QueryResp::HostHeight(self.ibc_ctx().host_height().unwrap()), | ||
QueryReq::HostConsensusState(height) => QueryResp::HostConsensusState( | ||
self.ibc_ctx().host_consensus_state(&height).unwrap().into(), | ||
), | ||
QueryReq::ClientCounter => { | ||
QueryResp::ClientCounter(self.ibc_ctx().client_counter().unwrap()) | ||
} | ||
QueryReq::ClientState(client_id) => { | ||
QueryResp::ClientState(self.ibc_ctx().client_state(&client_id).unwrap().into()) | ||
} | ||
QueryReq::NextSeqSend(path) => { | ||
QueryResp::NextSeqSend(self.ibc_ctx().get_next_sequence_send(&path).unwrap()) | ||
} | ||
QueryReq::Header(target_height, trusted_height) => { | ||
let blocks = self.get_blocks(); | ||
|
||
let revision_height = target_height.revision_height() as usize; | ||
|
||
if revision_height > blocks.len() { | ||
panic!("block index out of bounds"); | ||
} | ||
|
||
let target_block = blocks[revision_height - 1].clone(); | ||
|
||
let header = Header { | ||
signed_header: target_block.signed_header, | ||
validator_set: target_block.validators, | ||
trusted_height, | ||
trusted_next_validator_set: target_block.next_validators, | ||
}; | ||
|
||
QueryResp::Header(header.into()) | ||
} | ||
QueryReq::ValueWithProof(path, height) => { | ||
let (value, proof) = self.query( | ||
path.to_string().as_bytes().to_vec(), | ||
IBC_QUERY_PATH.to_string(), | ||
&height, | ||
); | ||
|
||
QueryResp::ValueWithProof(value, proof.into()) | ||
} | ||
} | ||
} | ||
|
||
fn send_msg(&self, msgs: Vec<Any>) -> Vec<IbcEvent> { | ||
msgs.into_iter() | ||
.flat_map(|msg| self.app.ibc().process_message(msg).unwrap()) | ||
.collect() | ||
} | ||
} |
Oops, something went wrong.