Skip to content

Commit 3da1ab3

Browse files
authored
refactor: move abi and selectors code to common (#3343)
1 parent eb04214 commit 3da1ab3

File tree

20 files changed

+577
-543
lines changed

20 files changed

+577
-543
lines changed

Cargo.lock

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cast/src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ use ethers_core::{
1919
use ethers_etherscan::Client;
2020
use ethers_providers::{Middleware, PendingTransaction};
2121
use eyre::{Context, Result};
22-
use foundry_common::fmt::*;
22+
use foundry_common::{abi::encode_args, fmt::*};
2323
pub use foundry_evm::*;
24-
use foundry_utils::encode_args;
2524
use rustc_hex::{FromHexIter, ToHex};
2625
use std::{path::PathBuf, str::FromStr};
2726
pub use tx::TxBuilder;
@@ -1151,7 +1150,7 @@ impl SimpleCast {
11511150
/// }
11521151
/// ```
11531152
pub fn abi_decode(sig: &str, calldata: &str, input: bool) -> Result<Vec<Token>> {
1154-
foundry_utils::abi_decode(sig, calldata, input)
1153+
foundry_common::abi::abi_decode(sig, calldata, input)
11551154
}
11561155

11571156
/// Performs ABI encoding based off of the function signature. Does not include

cast/src/tx.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use ethers_core::{
77
};
88
use ethers_providers::Middleware;
99
use eyre::{eyre, Result, WrapErr};
10+
use foundry_common::abi::{encode_args, get_func, get_func_etherscan};
1011
use foundry_config::Chain;
11-
use foundry_utils::{encode_args, get_func, get_func_etherscan};
1212
use futures::future::join_all;
1313

1414
use crate::strip_0x;

cli/src/cast.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@ use foundry_cli::{
1515
utils,
1616
utils::consume_config_rpc_url,
1717
};
18-
use foundry_common::{fs, try_get_http_provider};
19-
use foundry_config::{Chain, Config};
20-
use foundry_utils::{
21-
format_tokens,
18+
use foundry_common::{
19+
abi::format_tokens,
20+
fs,
2221
selectors::{
2322
decode_calldata, decode_event_topic, decode_function_selector, import_selectors,
2423
parse_signatures, pretty_calldata, ParsedSignatures, SelectorImportData,
2524
},
25+
try_get_http_provider,
2626
};
27+
use foundry_config::{Chain, Config};
2728
use rustc_hex::ToHex;
2829
use std::{
2930
io::{self, Read, Write},

cli/src/cmd/forge/create.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ use ethers::{
1616
types::{transaction::eip2718::TypedTransaction, Chain},
1717
};
1818
use eyre::Context;
19-
use foundry_common::{compile, try_get_http_provider};
20-
use foundry_utils::parse_tokens;
19+
use foundry_common::{abi::parse_tokens, compile, try_get_http_provider};
2120
use rustc_hex::ToHex;
2221
use serde_json::json;
2322
use std::{path::PathBuf, sync::Arc};

cli/src/cmd/forge/fourbyte.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ use crate::{
44
};
55
use clap::Parser;
66
use ethers::prelude::artifacts::output_selection::ContractOutputSelection;
7-
use foundry_common::compile;
8-
use foundry_utils::selectors::{import_selectors, SelectorImportData};
7+
use foundry_common::{
8+
compile,
9+
selectors::{import_selectors, SelectorImportData},
10+
};
911

1012
#[derive(Debug, Clone, Parser)]
1113
pub struct UploadSelectorsArgs {

cli/src/cmd/forge/script/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ use forge::{
2828
},
2929
CallKind,
3030
};
31-
use foundry_common::{evm::EvmArgs, ContractsByArtifact, CONTRACT_MAX_SIZE, SELECTOR_LEN};
31+
use foundry_common::{
32+
abi::format_token, evm::EvmArgs, ContractsByArtifact, CONTRACT_MAX_SIZE, SELECTOR_LEN,
33+
};
3234
use foundry_config::{figment, Config};
33-
use foundry_utils::{encode_args, format_token};
3435
use serde::{Deserialize, Serialize};
3536
use std::{
3637
collections::{BTreeMap, HashMap, VecDeque},
@@ -40,7 +41,7 @@ use yansi::Paint;
4041

4142
mod build;
4243
use build::{filter_sources_and_artifacts, BuildOutput};
43-
use foundry_common::{contracts::get_contract_name, errors::UnlinkedByteCode};
44+
use foundry_common::{abi::encode_args, contracts::get_contract_name, errors::UnlinkedByteCode};
4445
use foundry_config::figment::{
4546
value::{Dict, Map},
4647
Metadata, Profile, Provider,

cli/src/cmd/forge/script/transaction.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ use ethers::{
66
prelude::{NameOrAddress, H256 as TxHash},
77
types::transaction::eip2718::TypedTransaction,
88
};
9-
use foundry_common::SELECTOR_LEN;
10-
use foundry_utils::format_token;
9+
use foundry_common::{abi::format_token, SELECTOR_LEN};
1110

1211
use serde::{Deserialize, Serialize};
1312
use std::collections::BTreeMap;

cli/src/cmd/forge/verify/etherscan.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ use ethers::{
1919
},
2020
};
2121
use eyre::{eyre, Context};
22+
use foundry_common::abi::encode_args;
2223
use foundry_config::{Chain, Config, SolcReq};
23-
use foundry_utils::{encode_args, Retry};
24+
use foundry_utils::Retry;
2425
use futures::FutureExt;
2526
use once_cell::sync::Lazy;
2627
use regex::Regex;

common/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ foundry-config = { path = "../config" }
1717
ethers-core = { git = "https://github.com/gakonst/ethers-rs", default-features = false }
1818
ethers-solc = { git = "https://github.com/gakonst/ethers-rs", default-features = false }
1919
ethers-providers = { git = "https://github.com/gakonst/ethers-rs", default-features = false }
20+
ethers-etherscan = { git = "https://github.com/gakonst/ethers-rs", default-features = false }
2021

2122
# io
2223
reqwest = { version = "0.11", default-features = false }
@@ -45,3 +46,6 @@ semver = "1.0.5"
4546
once_cell = "1.13.1"
4647
dunce = "1.0.2"
4748
regex = "1.6.0"
49+
50+
[dev-dependencies]
51+
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }

0 commit comments

Comments
 (0)