|
1 |
| -use unionlabs::primitives::H256; |
| 1 | +use unionlabs::{primitives::H256, tuple::AsTuple}; |
2 | 2 |
|
3 |
| -#[derive(Debug, Clone, PartialEq)] |
| 3 | +pub type ClientState = state_lens_light_client_types::ClientState<Extra>; |
| 4 | + |
| 5 | +#[derive(Debug, Clone, PartialEq, AsTuple)] |
4 | 6 | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
5 |
| -pub struct ClientState { |
6 |
| - /// l2 chain id |
7 |
| - pub l2_chain_id: String, |
8 |
| - /// l1 client id used to check the l2 inclusion proof against |
9 |
| - pub l1_client_id: u32, |
10 |
| - /// l2 client id |
11 |
| - pub l2_client_id: u32, |
12 |
| - /// l2 latest height |
13 |
| - pub l2_latest_height: u64, |
| 7 | +pub struct Extra { |
14 | 8 | /// ibc contract that is running on l2
|
15 | 9 | pub contract_address: H256,
|
16 | 10 | }
|
17 |
| - |
18 |
| -#[cfg(feature = "ethabi")] |
19 |
| -pub mod ethabi { |
20 |
| - use core::str; |
21 |
| - use std::string::FromUtf8Error; |
22 |
| - |
23 |
| - use alloy::sol_types::SolValue; |
24 |
| - use unionlabs::{ |
25 |
| - encoding::{Decode, Encode, EthAbi}, |
26 |
| - TryFromEthAbiBytesErrorAlloy, |
27 |
| - }; |
28 |
| - |
29 |
| - use crate::ClientState; |
30 |
| - |
31 |
| - alloy::sol! { |
32 |
| - struct SolClientState { |
33 |
| - string l2ChainId; |
34 |
| - uint32 l1ClientId; |
35 |
| - uint32 l2ClientId; |
36 |
| - uint64 l2LatestHeight; |
37 |
| - bytes32 contractAddress; |
38 |
| - } |
39 |
| - } |
40 |
| - |
41 |
| - impl Encode<EthAbi> for ClientState { |
42 |
| - fn encode(self) -> Vec<u8> { |
43 |
| - SolClientState { |
44 |
| - l2ChainId: self.l2_chain_id, |
45 |
| - l1ClientId: self.l1_client_id, |
46 |
| - l2ClientId: self.l2_client_id, |
47 |
| - l2LatestHeight: self.l2_latest_height, |
48 |
| - contractAddress: self.contract_address.into(), |
49 |
| - } |
50 |
| - .abi_encode_params() |
51 |
| - } |
52 |
| - } |
53 |
| - |
54 |
| - impl Decode<EthAbi> for ClientState { |
55 |
| - type Error = TryFromEthAbiBytesErrorAlloy<Error>; |
56 |
| - |
57 |
| - fn decode(bytes: &[u8]) -> Result<Self, Self::Error> { |
58 |
| - let client_state = SolClientState::abi_decode_params(bytes, true)?; |
59 |
| - |
60 |
| - Ok(Self { |
61 |
| - l2_chain_id: String::from_utf8(client_state.l2ChainId.into_bytes()) |
62 |
| - .map_err(|err| TryFromEthAbiBytesErrorAlloy::Convert(Error::ChainId(err)))?, |
63 |
| - l1_client_id: client_state.l1ClientId, |
64 |
| - l2_client_id: client_state.l2ClientId, |
65 |
| - l2_latest_height: client_state.l2LatestHeight, |
66 |
| - contract_address: client_state.contractAddress.into(), |
67 |
| - }) |
68 |
| - } |
69 |
| - } |
70 |
| - |
71 |
| - #[derive(Debug, Clone, PartialEq, thiserror::Error)] |
72 |
| - pub enum Error { |
73 |
| - #[error("invalid chain_id")] |
74 |
| - ChainId(#[from] FromUtf8Error), |
75 |
| - } |
76 |
| - |
77 |
| - #[cfg(test)] |
78 |
| - mod test { |
79 |
| - #[test] |
80 |
| - fn test_decode() { |
81 |
| - // TODO(aeryz): impl |
82 |
| - } |
83 |
| - |
84 |
| - #[test] |
85 |
| - fn test_encode() { |
86 |
| - // TODO(aeryz): impl |
87 |
| - } |
88 |
| - } |
89 |
| -} |
0 commit comments