Skip to content

Commit

Permalink
chore(voyager): fix encode/decode issues after rebase
Browse files Browse the repository at this point in the history
Signed-off-by: aeryz <[email protected]>
  • Loading branch information
aeryz committed Jan 22, 2025
1 parent 7fe84ae commit dfb054a
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions lib/state-lens-ics23-smt-light-client-types/src/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,61 @@ pub struct Extra {
/// state_root = consensus_state[state_root_offset:state_root_offset+32]
pub state_root_offset: u16,
}

#[cfg(feature = "ethabi")]
mod ethabi {
use alloy::{
dyn_abi::SolType,
sol_types::{private::SolTypeValue, SolValue},
};

use super::*;

impl SolType for Extra {
type RustType = Self;

type Token<'a> = <<<Self as AsTuple>::Tuple as SolValue>::SolType as SolType>::Token<'a>;

const SOL_NAME: &'static str = "Extra";

const ENCODED_SIZE: Option<usize> = None;

const PACKED_ENCODED_SIZE: Option<usize> = None;

fn valid_token(_token: &Self::Token<'_>) -> bool {
true
}

fn detokenize((timestamp_offset, state_root_offset): Self::Token<'_>) -> Self::RustType {
Self {
timestamp_offset: <<u16 as SolValue>::SolType as SolType>::detokenize(
timestamp_offset,
),
state_root_offset: <<u16 as SolValue>::SolType as SolType>::detokenize(
state_root_offset,
),
}
}
}

impl SolValue for Extra {
type SolType = Self;
}

impl SolTypeValue<Self> for Extra {
fn stv_to_tokens(&self) -> <Self as SolType>::Token<'_> {
(
<<u16 as SolValue>::SolType as SolType>::tokenize(&self.timestamp_offset),
<<u16 as SolValue>::SolType as SolType>::tokenize(&self.state_root_offset),
)
}

fn stv_abi_encode_packed_to(&self, _out: &mut Vec<u8>) {
todo!()
}

fn stv_eip712_data_word(&self) -> alloy::sol_types::Word {
todo!()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ alloy = { workspace = true, features = ["rpc",
beacon-api = { workspace = true }
beacon-api-types = { workspace = true, features = ["serde"] }
cometbft-rpc = { workspace = true }
movement-light-client-types = { workspace = true, features = ["serde"] }
ibc-union-spec.workspace = true
jsonrpsee = { workspace = true, features = ["macros", "server", "tracing"] }
movement-light-client-types = { workspace = true, features = ["serde"] }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
state-lens-ics23-smt-light-client-types = { workspace = true, features = ["serde"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use jsonrpsee::{
use movement_light_client_types::ConsensusState as MovementConsensusState;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use state_lens_ics23_move_light_client_types::{client_state::Extra, ClientState, ConsensusState};
use state_lens_ics23_smt_light_client_types::{client_state::Extra, ClientState, ConsensusState};
use tracing::instrument;
use unionlabs::ibc::core::client::height::Height;
use voyager_message::{
Expand Down
2 changes: 1 addition & 1 deletion voyager/modules/client/state-lens/ics23-smt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name = "voyager-client-module-state-lens-ics23-smt"
version = "0.1.0"

[dependencies]
beacon-api-types = { workspace = true, features = ["serde"] }
alloy = { workspace = true, features = ["sol-types"] }
chain-utils = { workspace = true }
enumorph = { workspace = true }
ethereum-light-client-types = { workspace = true, features = ["serde", "ethabi", "bincode"] }
Expand Down
12 changes: 4 additions & 8 deletions voyager/modules/client/state-lens/ics23-smt/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use ethereum_light_client_types::StorageProof;
use alloy::sol_types::SolValue;
use jsonrpsee::{
core::{async_trait, RpcResult},
types::ErrorObject,
Extensions,
};
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
use state_lens_ics23_move_light_client_types::{ClientState, ConsensusState};
use state_lens_ics23_smt_light_client_types::{ClientState, ConsensusState};
use state_lens_light_client_types::Header;
use tracing::instrument;
use unionlabs::{
Expand Down Expand Up @@ -105,13 +105,9 @@ impl Module {
}

pub fn decode_client_state(&self, client_state: &[u8]) -> RpcResult<SelfClientState> {
println!(
"client_state: {:?}?",
<SelfClientState>::decode_as::<EthAbi>(client_state).unwrap()
);
match self.ibc_interface {
SupportedIbcInterface::IbcSolidity => {
<SelfClientState>::decode_as::<EthAbi>(client_state).map_err(|err| {
ClientState::abi_decode_params(client_state, true).map_err(|err| {
ErrorObject::owned(
FATAL_JSONRPC_ERROR_CODE,
format!("unable to decode client state: {err}"),
Expand Down Expand Up @@ -208,7 +204,7 @@ impl ClientModuleServer for Module {
)
})
.map(|cs| match self.ibc_interface {
SupportedIbcInterface::IbcSolidity => cs.encode_as::<EthAbi>(),
SupportedIbcInterface::IbcSolidity => cs.abi_encode_params(),
SupportedIbcInterface::IbcCosmwasm => cs.encode_as::<Bincode>(),
})
.map(Into::into)
Expand Down

0 comments on commit dfb054a

Please sign in to comment.