-
Notifications
You must be signed in to change notification settings - Fork 186
Add support for evm actor in state decode params API #5928
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
5e1b135
Add more evm methods support
sudo-shashank 675ea95
Add test snapshots
sudo-shashank 9f61a31
Merge branch 'main' into shashank/evm-state-decode-params
sudo-shashank 615985f
Merge branch 'main' into shashank/evm-state-decode-params
sudo-shashank c5bd5c2
Merge branch 'main' into shashank/evm-state-decode-params
sudo-shashank a4dfff2
Merge branch 'main' into shashank/evm-state-decode-params
sudo-shashank 6b503b6
Merge branch 'main' into shashank/evm-state-decode-params
sudo-shashank 0ddf9d9
fmt
sudo-shashank c42b6f3
fmt
sudo-shashank c984a48
Merge branch 'main' into shashank/evm-state-decode-params
sudo-shashank b105cfc
Use serde
sudo-shashank a2c016d
Merge branch 'main' into shashank/evm-state-decode-params
sudo-shashank ce06d41
Merge branch 'main' into shashank/evm-state-decode-params
sudo-shashank b8be085
add GetStorageAt
sudo-shashank 61a2860
Merge branch 'main' into shashank/evm-state-decode-params
sudo-shashank b14e1d5
lint fix
sudo-shashank 0a5bf32
fix error msg
sudo-shashank 318fd27
fix
sudo-shashank 13a687f
Merge branch 'main' into shashank/evm-state-decode-params
sudo-shashank 89d1ad4
Merge branch 'main' into shashank/evm-state-decode-params
sudo-shashank ca4a825
Merge branch 'main' into shashank/evm-state-decode-params
sudo-shashank 529531a
Merge branch 'main' into shashank/evm-state-decode-params
sudo-shashank fe0cb6a
minor fix
sudo-shashank 20e52b4
use ensure
sudo-shashank f37dca4
Merge branch 'main' into shashank/evm-state-decode-params
sudo-shashank File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
158 changes: 158 additions & 0 deletions
158
src/lotus_json/actor_states/methods/evm_actor_params.rs
This file contains hidden or 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,158 @@ | ||
| // Copyright 2019-2025 ChainSafe Systems | ||
| // SPDX-License-Identifier: Apache-2.0, MIT | ||
| use super::*; | ||
| use crate::rpc::eth::types::GetStorageAtParams; | ||
| use crate::shim::econ::TokenAmount; | ||
| use ::cid::Cid; | ||
| use fvm_ipld_encoding::RawBytes; | ||
| use paste::paste; | ||
| use schemars::JsonSchema; | ||
| use serde::{Deserialize, Serialize}; | ||
| use std::fmt::Debug; | ||
|
|
||
| #[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, PartialEq)] | ||
| #[serde(rename_all = "PascalCase")] | ||
| pub struct EVMConstructorParamsLotusJson { | ||
| pub creator: [u8; 20], | ||
| #[schemars(with = "LotusJson<RawBytes>")] | ||
| #[serde(with = "crate::lotus_json")] | ||
| pub initcode: RawBytes, | ||
| } | ||
|
|
||
| macro_rules! impl_evm_constructor_params { | ||
| ($($version:literal),+) => { | ||
| $( | ||
| paste! { | ||
| impl HasLotusJson for fil_actor_evm_state::[<v $version>]::ConstructorParams { | ||
| type LotusJson = EVMConstructorParamsLotusJson; | ||
|
|
||
| #[cfg(test)] | ||
| fn snapshots() -> Vec<(serde_json::Value, Self)> { | ||
| vec![ | ||
| ( | ||
| json!({ | ||
| "Creator": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | ||
| "Initcode": "ESIzRFU=" | ||
| }), | ||
| Self { | ||
| creator: fil_actor_evm_state::evm_shared::[<v $version>]::address::EthAddress([0; 20]), | ||
| initcode: RawBytes::new(hex::decode("1122334455").unwrap()), | ||
| }, | ||
| ), | ||
| ] | ||
| } | ||
|
|
||
| fn into_lotus_json(self) -> Self::LotusJson { | ||
| EVMConstructorParamsLotusJson { | ||
| creator: self.creator.0, | ||
| initcode: self.initcode, | ||
| } | ||
| } | ||
|
|
||
| fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { | ||
| Self { | ||
| creator: fil_actor_evm_state::evm_shared::[<v $version>]::address::EthAddress(lotus_json.creator), | ||
| initcode: lotus_json.initcode, | ||
| } | ||
| } | ||
| } | ||
| } | ||
| )+ | ||
| }; | ||
| } | ||
|
|
||
| impl_evm_constructor_params!(10, 11, 12, 13, 14, 15, 16); | ||
|
|
||
| #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema)] | ||
| #[serde(rename_all = "PascalCase")] | ||
| pub struct EVMDelegateCallParamsLotusJson { | ||
| #[schemars(with = "LotusJson<Cid>")] | ||
| #[serde(with = "crate::lotus_json")] | ||
| pub code: Cid, | ||
| #[schemars(with = "LotusJson<RawBytes>")] | ||
| #[serde(with = "crate::lotus_json")] | ||
| pub input: RawBytes, | ||
| pub caller: [u8; 20], | ||
| #[schemars(with = "LotusJson<TokenAmount>")] | ||
| #[serde(with = "crate::lotus_json")] | ||
| pub value: TokenAmount, | ||
| } | ||
|
|
||
| macro_rules! impl_evm_delegate_call_params_lotus_json { | ||
| ($($version:literal),+) => { | ||
| $( | ||
| paste! { | ||
| impl HasLotusJson for fil_actor_evm_state::[<v $version>]::DelegateCallParams { | ||
| type LotusJson = EVMDelegateCallParamsLotusJson; | ||
|
|
||
| #[cfg(test)] | ||
| fn snapshots() -> Vec<(serde_json::Value, Self)> { | ||
| vec![( | ||
| json!({ | ||
| "Code": "bafy2bzaceaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", | ||
| "Input": "ESIzRFU=", | ||
| "Caller": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | ||
akaladarshi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "Value": "0" | ||
| }), | ||
| Self { | ||
| code: Cid::default(), | ||
| input: hex::decode("1122334455").unwrap(), | ||
| caller: fil_actor_evm_state::evm_shared::[<v $version>]::address::EthAddress([0; 20]), | ||
| value: TokenAmount::from_atto(0).into(), | ||
| }, | ||
| )] | ||
| } | ||
|
|
||
| fn into_lotus_json(self) -> Self::LotusJson { | ||
| EVMDelegateCallParamsLotusJson { | ||
| code: self.code, | ||
| input: self.input.into(), | ||
| caller: self.caller.0, | ||
| value: self.value.into(), | ||
| } | ||
| } | ||
| fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { | ||
| Self { | ||
| code: lotus_json.code, | ||
| input: lotus_json.input.into(), | ||
| caller: fil_actor_evm_state::evm_shared::[<v $version>]::address::EthAddress(lotus_json.caller), | ||
| value: lotus_json.value.into(), | ||
| } | ||
| } | ||
| }} | ||
| )+ | ||
| }; | ||
| } | ||
|
|
||
| impl_evm_delegate_call_params_lotus_json!(10, 11, 12, 13, 14, 15, 16); | ||
|
|
||
| #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)] | ||
| #[serde(rename_all = "PascalCase")] | ||
| pub struct GetStorageAtParamsLotusJson { | ||
| pub storage_key: [u8; 32], | ||
| } | ||
|
|
||
| impl HasLotusJson for GetStorageAtParams { | ||
| type LotusJson = GetStorageAtParamsLotusJson; | ||
|
|
||
| #[cfg(test)] | ||
| fn snapshots() -> Vec<(serde_json::Value, Self)> { | ||
| vec![( | ||
| json!({ | ||
| "StorageKey": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10] | ||
| }), | ||
| GetStorageAtParams::new(vec![0xa]).unwrap(), | ||
| )] | ||
| } | ||
|
|
||
| fn into_lotus_json(self) -> Self::LotusJson { | ||
| GetStorageAtParamsLotusJson { | ||
| storage_key: self.0, | ||
| } | ||
| } | ||
|
|
||
| fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { | ||
| GetStorageAtParams::new(lotus_json.storage_key.to_vec()) | ||
| .expect("expected array to have 32 elements") | ||
| } | ||
| } | ||
62 changes: 0 additions & 62 deletions
62
src/lotus_json/actor_states/methods/evm_constructor_params.rs
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.