Skip to content

Commit

Permalink
Merge pull request #1 from zeroXbrock/suavex_endpoints
Browse files Browse the repository at this point in the history
suavex_call for anvil
  • Loading branch information
zeroXbrock committed Feb 27, 2024
2 parents 6d5de51 + e61c230 commit 91ad869
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 26 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

21 changes: 0 additions & 21 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,10 @@ serde_json.opt-level = 3
alloy-dyn-abi.opt-level = 3
alloy-json-abi.opt-level = 3
alloy-primitives.opt-level = 3
alloy-sol-type-parser.opt-level = 3
alloy-sol-types.opt-level = 3
hashbrown.opt-level = 3
keccak.opt-level = 3
revm-interpreter.opt-level = 3
revm-precompile.opt-level = 3
revm-primitives.opt-level = 3
revm.opt-level = 3
ruint.opt-level = 3
sha2.opt-level = 3
sha3.opt-level = 3
tiny-keccak.opt-level = 3

# fuzzing
proptest.opt-level = 3
Expand All @@ -72,9 +64,6 @@ foundry-evm-fuzz.opt-level = 3
# forking
axum.opt-level = 3

# keystores
scrypt.opt-level = 3

# Local "release" mode, more optimized than dev but much faster to compile than release.
[profile.local]
inherits = "dev"
Expand Down Expand Up @@ -103,18 +92,12 @@ codegen-units = 1
# Override packages which aren't perf-sensitive for faster compilation speed.
[profile.release.package]
mdbook.opt-level = 1
protobuf.opt-level = 1
rusoto_core.opt-level = 1
rusoto_credential.opt-level = 1
rusoto_kms.opt-level = 1
toml_edit.opt-level = 1
trezor-client.opt-level = 1

[workspace.dependencies]
anvil = { path = "crates/anvil" }
cast = { path = "crates/cast" }
chisel = { path = "crates/chisel" }
forge = { path = "crates/forge" }

forge-doc = { path = "crates/doc" }
forge-fmt = { path = "crates/fmt" }
Expand Down Expand Up @@ -147,7 +130,6 @@ revm-inspectors = { git = "https://github.com/paradigmxyz/evm-inspectors", rev =
ethers = { version = "2.0", default-features = false }
ethers-core = { version = "2.0", default-features = false }
ethers-contract = { version = "2.0", default-features = false }
ethers-contract-abigen = { version = "2.0", default-features = false }
ethers-providers = { version = "2.0", default-features = false }
ethers-signers = { version = "2.0", default-features = false }
ethers-middleware = { version = "2.0", default-features = false }
Expand All @@ -159,7 +141,6 @@ alloy-eips = { git = "https://github.com/alloy-rs/alloy" }
alloy-genesis = { git = "https://github.com/alloy-rs/alloy" }
alloy-json-rpc = { git = "https://github.com/alloy-rs/alloy" }
alloy-network = { git = "https://github.com/alloy-rs/alloy" }
alloy-node-bindings = { git = "https://github.com/alloy-rs/alloy" }
alloy-providers = { git = "https://github.com/alloy-rs/alloy" }
alloy-pubsub = { git = "https://github.com/alloy-rs/alloy" }
alloy-rpc-client = { git = "https://github.com/alloy-rs/alloy" }
Expand All @@ -174,7 +155,6 @@ alloy-primitives = { version = "0.6.3", features = ["getrandom"] }
alloy-dyn-abi = "0.6.3"
alloy-json-abi = "0.6.3"
alloy-sol-types = "0.6.3"
syn-solidity = "0.6.3"
alloy-chains = "0.1"

alloy-rlp = "0.3.3"
Expand All @@ -189,7 +169,6 @@ hex = { package = "const-hex", version = "1.6", features = ["hex"] }
itertools = "0.11"
jsonpath_lib = "0.3"
pretty_assertions = "1.4"
protobuf = "=3.2.0"
rand = "0.8"
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", features = ["arbitrary_precision"] }
Expand Down
1 change: 1 addition & 0 deletions crates/anvil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ ctrlc = { version = "3", optional = true }
fdlimit = { version = "0.3", optional = true }
clap_complete_fig = "4"
ethereum-forkid = "0.12"
base64.workspace = true

[dev-dependencies]
ethers = { workspace = true, features = ["abigen"] }
Expand Down
3 changes: 3 additions & 0 deletions crates/anvil/core/src/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ pub enum EthRequest {
#[cfg_attr(feature = "serde", serde(default))] Option<StateOverride>,
),

#[cfg_attr(feature = "serde", serde(rename = "suavex_call"))]
SuavexCall(Address, String),

#[cfg_attr(feature = "serde", serde(rename = "eth_createAccessList"))]
EthCreateAccessList(
TransactionRequest,
Expand Down
30 changes: 25 additions & 5 deletions crates/anvil/src/eth/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use alloy_rpc_trace_types::{
parity::LocalizedTransactionTrace,
};
use alloy_rpc_types::{
request::TransactionRequest,
request::{TransactionInput, TransactionRequest},
state::StateOverride,
txpool::{TxpoolContent, TxpoolInspect, TxpoolInspectSummary, TxpoolStatus},
AccessList, AccessListWithGasUsed, Block, BlockId, BlockNumberOrTag as BlockNumber,
Expand All @@ -64,6 +64,7 @@ use anvil_core::{
},
};
use anvil_rpc::{error::RpcError, response::ResponseResult};
use base64::{engine::general_purpose::STANDARD as BASE64_STANDARD, Engine as _};
use foundry_common::provider::alloy::ProviderBuilder;
use foundry_evm::{
backend::DatabaseError,
Expand Down Expand Up @@ -333,7 +334,7 @@ impl EthApi {
if time >= U256::from(u64::MAX) {
return ResponseResult::Error(RpcError::invalid_params(
"The timestamp is too big",
))
));
}
let time = time.to::<u64>();
self.evm_set_next_block_timestamp(time).to_rpc_result()
Expand All @@ -342,7 +343,7 @@ impl EthApi {
if timestamp >= U256::from(u64::MAX) {
return ResponseResult::Error(RpcError::invalid_params(
"The timestamp is too big",
))
));
}
let time = timestamp.to::<u64>();
self.evm_set_time(time).to_rpc_result()
Expand Down Expand Up @@ -413,6 +414,9 @@ impl EthApi {
EthRequest::OtsGetContractCreator(address) => {
self.ots_get_contract_creator(address).await.to_rpc_result()
}
EthRequest::SuavexCall(address, input) => {
self.suavex_call(address, input).await.to_rpc_result()
}
}
}

Expand All @@ -430,13 +434,13 @@ impl EthApi {
false,
)
.unwrap();
return build_typed_transaction(request, nil_signature)
return build_typed_transaction(request, nil_signature);
}
_ => {
for signer in self.signers.iter() {
if signer.accounts().contains(from) {
let signature = signer.sign_transaction(request.clone(), from)?;
return build_typed_transaction(request, signature)
return build_typed_transaction(request, signature);
}
}
}
Expand Down Expand Up @@ -2106,6 +2110,22 @@ impl EthApi {

Ok(content)
}

/// eth_call for SUAVE MEVM.
/// Returns base64-encoded bytestring.
pub async fn suavex_call(&self, contract_address: Address, calldata: String) -> Result<String> {
node_info!("suavex_call");
// TODO: use serde for this
let input: Bytes = BASE64_STANDARD
.decode(calldata)
.map_err(|_| BlockchainError::RpcError(RpcError::parse_error()))?
.into();
let request = TransactionRequest::default()
.to(Some(contract_address.0.into()))
.input(TransactionInput::new(input));
let res = self.call(request, Some(BlockNumber::Latest.into()), None).await?;
Ok(BASE64_STANDARD.encode(res.to_vec()))
}
}

// === impl EthApi utility functions ===
Expand Down

0 comments on commit 91ad869

Please sign in to comment.