-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
generic state lens client state type (#3574)
- Loading branch information
Showing
24 changed files
with
817 additions
and
465 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 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 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
89 changes: 5 additions & 84 deletions
89
lib/state-lens-ics23-ics23-light-client-types/src/client_state.rs
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,89 +1,10 @@ | ||
use unionlabs::primitives::H256; | ||
use unionlabs::{primitives::H256, tuple::AsTuple}; | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub type ClientState = state_lens_light_client_types::ClientState<Extra>; | ||
|
||
#[derive(Debug, Clone, PartialEq, AsTuple)] | ||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] | ||
pub struct ClientState { | ||
/// l2 chain id | ||
pub l2_chain_id: String, | ||
/// l1 client id used to check the l2 inclusion proof against | ||
pub l1_client_id: u32, | ||
/// l2 client id | ||
pub l2_client_id: u32, | ||
/// l2 latest height | ||
pub l2_latest_height: u64, | ||
pub struct Extra { | ||
/// ibc contract that is running on l2 | ||
pub contract_address: H256, | ||
} | ||
|
||
#[cfg(feature = "ethabi")] | ||
pub mod ethabi { | ||
use core::str; | ||
use std::string::FromUtf8Error; | ||
|
||
use alloy::sol_types::SolValue; | ||
use unionlabs::{ | ||
encoding::{Decode, Encode, EthAbi}, | ||
TryFromEthAbiBytesErrorAlloy, | ||
}; | ||
|
||
use crate::ClientState; | ||
|
||
alloy::sol! { | ||
struct SolClientState { | ||
string l2ChainId; | ||
uint32 l1ClientId; | ||
uint32 l2ClientId; | ||
uint64 l2LatestHeight; | ||
bytes32 contractAddress; | ||
} | ||
} | ||
|
||
impl Encode<EthAbi> for ClientState { | ||
fn encode(self) -> Vec<u8> { | ||
SolClientState { | ||
l2ChainId: self.l2_chain_id, | ||
l1ClientId: self.l1_client_id, | ||
l2ClientId: self.l2_client_id, | ||
l2LatestHeight: self.l2_latest_height, | ||
contractAddress: self.contract_address.into(), | ||
} | ||
.abi_encode_params() | ||
} | ||
} | ||
|
||
impl Decode<EthAbi> for ClientState { | ||
type Error = TryFromEthAbiBytesErrorAlloy<Error>; | ||
|
||
fn decode(bytes: &[u8]) -> Result<Self, Self::Error> { | ||
let client_state = SolClientState::abi_decode_params(bytes, true)?; | ||
|
||
Ok(Self { | ||
l2_chain_id: String::from_utf8(client_state.l2ChainId.into_bytes()) | ||
.map_err(|err| TryFromEthAbiBytesErrorAlloy::Convert(Error::ChainId(err)))?, | ||
l1_client_id: client_state.l1ClientId, | ||
l2_client_id: client_state.l2ClientId, | ||
l2_latest_height: client_state.l2LatestHeight, | ||
contract_address: client_state.contractAddress.into(), | ||
}) | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, thiserror::Error)] | ||
pub enum Error { | ||
#[error("invalid chain_id")] | ||
ChainId(#[from] FromUtf8Error), | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
#[test] | ||
fn test_decode() { | ||
// TODO(aeryz): impl | ||
} | ||
|
||
#[test] | ||
fn test_encode() { | ||
// TODO(aeryz): impl | ||
} | ||
} | ||
} |
Oops, something went wrong.