From 441c8537acde910ec663af371c747dd0779bbb70 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Wed, 22 Nov 2023 16:06:09 +0100 Subject: [PATCH] chore: impl To* traits for Bytes (#6400) --- crates/cheatcodes/src/inspector.rs | 4 ++-- crates/chisel/src/executor.rs | 2 +- crates/chisel/src/runner.rs | 2 +- crates/evm/evm/src/inspectors/logs.rs | 2 +- crates/evm/traces/src/lib.rs | 2 +- crates/forge/bin/cmd/coverage.rs | 2 +- crates/forge/bin/cmd/create.rs | 9 ++++++--- crates/forge/bin/cmd/script/executor.rs | 6 +++--- crates/forge/bin/cmd/script/mod.rs | 2 +- crates/forge/bin/cmd/script/runner.rs | 4 ++-- crates/forge/src/multi_runner.rs | 9 +++------ crates/utils/src/lib.rs | 4 ++-- crates/utils/src/types.rs | 9 +++++++++ 13 files changed, 33 insertions(+), 24 deletions(-) diff --git a/crates/cheatcodes/src/inspector.rs b/crates/cheatcodes/src/inspector.rs index 2115d8da549f..0e6bb3624c8f 100644 --- a/crates/cheatcodes/src/inspector.rs +++ b/crates/cheatcodes/src/inspector.rs @@ -787,7 +787,7 @@ impl Inspector for Cheatcodes { from: Some(broadcast.new_origin.to_ethers()), to: Some(NameOrAddress::Address(call.contract.to_ethers())), value: Some(call.transfer.value.to_ethers()), - data: Some(call.input.clone().0.into()), + data: Some(call.input.clone().to_ethers()), nonce: Some(account.info.nonce.into()), gas: if is_fixed_gas_limit { Some(call.gas_limit.into()) @@ -1153,7 +1153,7 @@ impl Inspector for Cheatcodes { from: Some(broadcast.new_origin.to_ethers()), to: to.map(|a| NameOrAddress::Address(a.to_ethers())), value: Some(call.value.to_ethers()), - data: Some(bytecode.0.into()), + data: Some(bytecode.to_ethers()), nonce: Some(nonce.into()), gas: if is_fixed_gas_limit { Some(call.gas_limit.into()) diff --git a/crates/chisel/src/executor.rs b/crates/chisel/src/executor.rs index 421c434effc7..04af448c75b9 100644 --- a/crates/chisel/src/executor.rs +++ b/crates/chisel/src/executor.rs @@ -107,7 +107,7 @@ impl SessionSource { let mut runner = self.prepare_runner(final_pc).await; // Return [ChiselResult] or bubble up error - runner.run(bytecode.into_owned().0.into()) + runner.run(bytecode.into_owned()) } else { // Return a default result if no statements are present. Ok((Address::ZERO, ChiselResult::default())) diff --git a/crates/chisel/src/runner.rs b/crates/chisel/src/runner.rs index 644c6ea96e12..286cc937c994 100644 --- a/crates/chisel/src/runner.rs +++ b/crates/chisel/src/runner.rs @@ -92,7 +92,7 @@ impl ChiselRunner { // We don't care about deployment traces / logs here let DeployResult { address, .. } = self .executor - .deploy(self.sender, bytecode.0.into(), U256::ZERO, None) + .deploy(self.sender, bytecode, U256::ZERO, None) .map_err(|err| eyre::eyre!("Failed to deploy REPL contract:\n{}", err))?; // Reset the sender's balance to the initial balance for calls. diff --git a/crates/evm/evm/src/inspectors/logs.rs b/crates/evm/evm/src/inspectors/logs.rs index 32ccc103aa36..277a3bcf804d 100644 --- a/crates/evm/evm/src/inspectors/logs.rs +++ b/crates/evm/evm/src/inspectors/logs.rs @@ -49,7 +49,7 @@ impl Inspector for LogCollector { self.logs.push(Log { address: address.to_ethers(), topics: topics.iter().copied().map(|t| t.to_ethers()).collect(), - data: data.clone().0.into(), + data: data.clone().to_ethers(), ..Default::default() }); } diff --git a/crates/evm/traces/src/lib.rs b/crates/evm/traces/src/lib.rs index 3fdf14f6cdf4..d0bb8dd4eb46 100644 --- a/crates/evm/traces/src/lib.rs +++ b/crates/evm/traces/src/lib.rs @@ -177,7 +177,7 @@ impl CallTraceArena { // If the top-level trace succeeded, then it was a success failed: !main_trace.success, gas: receipt_gas_used.to_ethers(), - return_value: main_trace.output.to_bytes().0.into(), + return_value: main_trace.output.to_bytes().to_ethers(), ..Default::default() }; diff --git a/crates/forge/bin/cmd/coverage.rs b/crates/forge/bin/cmd/coverage.rs index b68e35b398b0..635991ad49c5 100644 --- a/crates/forge/bin/cmd/coverage.rs +++ b/crates/forge/bin/cmd/coverage.rs @@ -391,7 +391,7 @@ fn dummy_link_bytecode(mut obj: CompactBytecode) -> Option { } obj.object.resolve(); - obj.object.into_bytes().map(|o| o.0.into()) + obj.object.into_bytes() } /// Helper function that will link references in unlinked bytecode to the 0 address. diff --git a/crates/forge/bin/cmd/create.rs b/crates/forge/bin/cmd/create.rs index a187148b8891..42c3149eafc0 100644 --- a/crates/forge/bin/cmd/create.rs +++ b/crates/forge/bin/cmd/create.rs @@ -201,7 +201,7 @@ impl CreateArgs { panic!("no bytecode found in bin object for {}", self.contract.name) }); let provider = Arc::new(provider); - let factory = ContractFactory::new(abi.clone(), bin.clone().0.into(), provider.clone()); + let factory = ContractFactory::new(abi.clone(), bin.clone(), provider.clone()); let is_args_empty = args.is_empty(); let deployer = @@ -553,8 +553,11 @@ where // create the tx object. Since we're deploying a contract, `to` is `None` // We default to EIP1559 transactions, but the sender can convert it back // to a legacy one. - let tx = - Eip1559TransactionRequest { to: None, data: Some(data.0.into()), ..Default::default() }; + let tx = Eip1559TransactionRequest { + to: None, + data: Some(data.to_ethers()), + ..Default::default() + }; let tx = tx.into(); diff --git a/crates/forge/bin/cmd/script/executor.rs b/crates/forge/bin/cmd/script/executor.rs index c4cff1304de2..2d85e46b5c1b 100644 --- a/crates/forge/bin/cmd/script/executor.rs +++ b/crates/forge/bin/cmd/script/executor.rs @@ -53,7 +53,7 @@ impl ScriptArgs { let mut runner = self.prepare_runner(script_config, sender, SimulationStage::Local).await; let (address, mut result) = runner.setup( predeploy_libraries, - bytecode.0.into(), + bytecode, needs_setup(&abi), script_config.sender_nonce, self.broadcast, @@ -65,7 +65,7 @@ impl ScriptArgs { // Only call the method if `setUp()` succeeded. if result.success { - let script_result = runner.script(address, calldata.0.into())?; + let script_result = runner.script(address, calldata)?; result.success &= script_result.success; result.gas_used = script_result.gas_used; @@ -154,7 +154,7 @@ impl ScriptArgs { "Transaction doesn't have a `from` address at execution time", ).to_alloy(), tx.to.clone(), - tx.data.clone().map(|b| b.0.into()), + tx.data.clone().map(|b| b.to_alloy()), tx.value.map(|v| v.to_alloy()), ) .expect("Internal EVM error"); diff --git a/crates/forge/bin/cmd/script/mod.rs b/crates/forge/bin/cmd/script/mod.rs index e9ba8b4271a6..a825a2e39921 100644 --- a/crates/forge/bin/cmd/script/mod.rs +++ b/crates/forge/bin/cmd/script/mod.rs @@ -428,7 +428,7 @@ impl ScriptArgs { rpc: fork_url.clone(), transaction: TypedTransaction::Legacy(TransactionRequest { from: Some(from.to_ethers()), - data: Some(bytes.clone().0.into()), + data: Some(bytes.clone().to_ethers()), nonce: Some((nonce + i as u64).into()), ..Default::default() }), diff --git a/crates/forge/bin/cmd/script/runner.rs b/crates/forge/bin/cmd/script/runner.rs index 7035c44de775..592501cc5541 100644 --- a/crates/forge/bin/cmd/script/runner.rs +++ b/crates/forge/bin/cmd/script/runner.rs @@ -79,7 +79,7 @@ impl ScriptRunner { .. } = self .executor - .deploy(CALLER, code.0.into(), U256::ZERO, None) + .deploy(CALLER, code, U256::ZERO, None) .map_err(|err| eyre::eyre!("Failed to deploy script:\n{}", err))?; traces.extend(constructor_traces.map(|traces| (TraceKind::Deployment, traces))); @@ -217,7 +217,7 @@ impl ScriptRunner { } else if to.is_none() { let (address, gas_used, logs, traces, debug) = match self.executor.deploy( from, - calldata.expect("No data for create transaction").0.into(), + calldata.expect("No data for create transaction"), value.unwrap_or(U256::ZERO), None, ) { diff --git a/crates/forge/src/multi_runner.rs b/crates/forge/src/multi_runner.rs index 6ba28253ccb2..5253bf7c103c 100644 --- a/crates/forge/src/multi_runner.rs +++ b/crates/forge/src/multi_runner.rs @@ -218,7 +218,7 @@ impl MultiContractRunner { name, executor, contract, - deploy_code.0.into(), + deploy_code, self.evm_opts.initial_balance, self.sender, self.errors.as_ref(), @@ -330,11 +330,8 @@ impl MultiContractRunnerBuilder { id.clone(), ( abi.clone(), - bytecode.0.into(), - dependencies - .into_iter() - .map(|dep| dep.bytecode.0.into()) - .collect::>(), + bytecode, + dependencies.into_iter().map(|dep| dep.bytecode).collect::>(), ), ); } diff --git a/crates/utils/src/lib.rs b/crates/utils/src/lib.rs index fc23b1d72eca..d795d667dd03 100644 --- a/crates/utils/src/lib.rs +++ b/crates/utils/src/lib.rs @@ -382,7 +382,7 @@ fn recurse_link<'a>( id: library, address: *deployed_address, nonce: *cached_nonce, - bytecode: next_target_bytecode.object.into_bytes().unwrap_or_else(|| panic!("Bytecode should be linked for {next_target}")).0.into(), + bytecode: next_target_bytecode.object.into_bytes().unwrap_or_else(|| panic!("Bytecode should be linked for {next_target}")), }); *deployed_address } else { @@ -399,7 +399,7 @@ fn recurse_link<'a>( id: library, address: computed_address, nonce: used_nonce, - bytecode: next_target_bytecode.object.into_bytes().unwrap_or_else(|| panic!("Bytecode should be linked for {next_target}")).0.into(), + bytecode: next_target_bytecode.object.into_bytes().unwrap_or_else(|| panic!("Bytecode should be linked for {next_target}")), }); // remember this library for later diff --git a/crates/utils/src/types.rs b/crates/utils/src/types.rs index 1c2f4bf9c303..a62422c3db6d 100644 --- a/crates/utils/src/types.rs +++ b/crates/utils/src/types.rs @@ -237,3 +237,12 @@ impl ToEthers for U64 { EthersU64(self.into_limbs()) } } + +impl ToEthers for Bytes { + type To = EthersBytes; + + #[inline(always)] + fn to_ethers(self) -> Self::To { + EthersBytes(self.0) + } +}