Skip to content

Commit a0279f0

Browse files
committed
Added logic for ABI
1 parent 48ed8db commit a0279f0

File tree

4 files changed

+72
-29
lines changed

4 files changed

+72
-29
lines changed

crates/core/src/driver/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
33
use alloy::json_abi::JsonAbi;
44
use alloy::primitives::Bytes;
5-
use alloy::rpc::types::TransactionInput;
5+
use alloy::rpc::types::trace::geth::GethTrace;
6+
use alloy::rpc::types::{TransactionInput, TransactionReceipt};
67
use alloy::{
78
primitives::{Address, TxKind, map::HashMap},
89
rpc::types::{
@@ -17,6 +18,7 @@ use revive_dt_node_interaction::EthereumNode;
1718
use revive_dt_report::reporter::{CompilationTask, Report, Span};
1819
use revive_solc_json_interface::SolcStandardJsonOutput;
1920
use serde_json::Value;
21+
use std::collections::HashMap as StdHashMap;
2022

2123
use crate::Platform;
2224

@@ -29,8 +31,8 @@ pub struct State<'a, T: Platform> {
2931
config: &'a Arguments,
3032
span: Span,
3133
contracts: Contracts<T>,
32-
deployed_contracts: HashMap<String, Address>,
33-
deployed_abis: HashMap<String, JsonAbi>,
34+
deployed_contracts: StdHashMap<String, Address>,
35+
deployed_abis: StdHashMap<String, JsonAbi>,
3436
}
3537

3638
impl<'a, T> State<'a, T>

crates/format/src/input.rs

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use alloy::{
66
primitives::{Address, Bytes, TxKind},
77
rpc::types::{TransactionInput, TransactionRequest},
88
};
9+
use alloy_primitives::U256;
10+
use alloy_sol_types::SolValue;
911
use semver::VersionReq;
1012
use serde::{Deserialize, de::Deserializer};
1113
use serde_json::Value;
@@ -142,35 +144,68 @@ impl Input {
142144
_ => anyhow::bail!("Expected compound calldata for function call"),
143145
};
144146

145-
// Convert each argument
146-
let mut tokens = Vec::new();
147+
if calldata_args.len() != function.inputs.len() {
148+
anyhow::bail!(
149+
"Function expects {} args, but got {}",
150+
function.inputs.len(),
151+
calldata_args.len()
152+
);
153+
}
154+
155+
let mut encoded = selector.to_vec();
156+
147157
for (i, param) in function.inputs.iter().enumerate() {
148-
let arg = calldata_args
149-
.get(i)
150-
.ok_or_else(|| anyhow::anyhow!("Missing calldata argument {}", i))?;
151-
let token = match arg {
152-
CalldataArg::Literal(value) => match param.ty.to_string().as_str() {
153-
"uint256" | "uint" => Token::Uint(value.parse()?),
154-
"address" => Token::Address(value.parse()?),
155-
_ => anyhow::bail!("Unsupported literal type {}", param.ty),
158+
let arg = calldata_args.get(i).unwrap();
159+
let encoded_arg = match arg {
160+
CalldataArg::Literal(value) => match param.ty.as_str() {
161+
"uint256" | "uint" => {
162+
let val: U256 = value.parse()?;
163+
val.abi_encode()
164+
}
165+
"uint24" => {
166+
let val: u32 = value.parse()?;
167+
(val & 0xFFFFFF).abi_encode()
168+
}
169+
"bool" => {
170+
let val: bool = value.parse()?;
171+
val.abi_encode()
172+
}
173+
"address" => {
174+
let addr: Address = value.parse()?;
175+
addr.abi_encode()
176+
}
177+
"string" => value.abi_encode(),
178+
"bytes32" => {
179+
let val = hex::decode(value.trim_start_matches("0x"))?;
180+
let mut fixed = [0u8; 32];
181+
fixed[..val.len()].copy_from_slice(&val);
182+
fixed.abi_encode()
183+
}
184+
"uint256[]" | "uint[]" => {
185+
let nums: Vec<u64> = serde_json::from_str(value)?;
186+
nums.abi_encode()
187+
}
188+
"bytes" => {
189+
let val = hex::decode(value.trim_start_matches("0x"))?;
190+
val.abi_encode()
191+
}
192+
_ => anyhow::bail!("Unsupported type: {}", param.ty),
156193
},
157194
CalldataArg::AddressRef(name) => {
158-
let addr = if name.ends_with(".address") {
159-
let contract_name = name.trim_end_matches(".address");
160-
deployed_contracts.get(contract_name).copied()
161-
} else {
162-
None
163-
};
164-
Token::Address(
165-
addr.ok_or_else(|| anyhow::anyhow!("Address for '{}' not found", name))?,
166-
)
195+
let contract_name = name.trim_end_matches(".address");
196+
let addr = deployed_contracts
197+
.get(contract_name)
198+
.copied()
199+
.ok_or_else(|| {
200+
anyhow::anyhow!("Address for '{}' not found", contract_name)
201+
})?;
202+
addr.abi_encode()
167203
}
168204
};
169-
tokens.push(token);
205+
206+
encoded.extend(encoded_arg);
170207
}
171208

172-
// Encode
173-
let encoded = function.encode_input(&tokens)?;
174209
Ok(Bytes::from(encoded))
175210
}
176211

crates/node/src/geth.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! The go-ethereum node implementation.
22
33
use std::{
4+
collections::HashMap as StdHashMap,
45
fs::{File, create_dir_all, remove_dir_all},
56
io::{BufRead, BufReader, Read, Write},
67
path::PathBuf,
@@ -50,7 +51,7 @@ pub struct Instance {
5051
network_id: u64,
5152
start_timeout: u64,
5253
wallet: EthereumWallet,
53-
nonces: Mutex<HashMap<Address, u64>>,
54+
nonces: Mutex<StdHashMap<Address, u64>>,
5455
}
5556

5657
impl Instance {
@@ -158,6 +159,8 @@ impl EthereumNode for Instance {
158159
let connection_string = self.connection_string();
159160
let wallet = self.wallet.clone();
160161

162+
log::debug!("Submitting transaction: {:#?}", transaction);
163+
161164
execute_transaction(Box::pin(async move {
162165
Ok(ProviderBuilder::new()
163166
.wallet(wallet)
@@ -235,7 +238,7 @@ impl Node for Instance {
235238
network_id: config.network_id,
236239
start_timeout: config.geth_start_timeout,
237240
wallet: config.wallet(),
238-
nonces: Mutex::new(HashMap::new()),
241+
nonces: Mutex::new(StdHashMap::new()),
239242
}
240243
}
241244

crates/node/src/kitchensink.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::{
2+
collections::HashMap as StdHashMap,
23
fs::create_dir_all,
34
io::BufRead,
45
path::PathBuf,
@@ -44,7 +45,7 @@ pub struct KitchensinkNode {
4445
base_directory: PathBuf,
4546
process_substrate: Option<Child>,
4647
process_proxy: Option<Child>,
47-
nonces: Mutex<HashMap<Address, u64>>,
48+
nonces: Mutex<StdHashMap<Address, u64>>,
4849
}
4950

5051
impl KitchensinkNode {
@@ -251,6 +252,8 @@ impl EthereumNode for KitchensinkNode {
251252
let url = self.rpc_url.clone();
252253
let wallet = self.wallet.clone();
253254

255+
log::debug!("Submitting transaction: {:#?}", transaction);
256+
254257
execute_transaction(Box::pin(async move {
255258
Ok(ProviderBuilder::new()
256259
.wallet(wallet)
@@ -325,7 +328,7 @@ impl Node for KitchensinkNode {
325328
base_directory,
326329
process_substrate: None,
327330
process_proxy: None,
328-
nonces: Mutex::new(HashMap::new()),
331+
nonces: Mutex::new(StdHashMap::new()),
329332
}
330333
}
331334

0 commit comments

Comments
 (0)