Skip to content

Commit

Permalink
chore: impl To* traits for Bytes (#6400)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Nov 22, 2023
1 parent b8c50d7 commit 441c853
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 24 deletions.
4 changes: 2 additions & 2 deletions crates/cheatcodes/src/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ impl<DB: DatabaseExt> Inspector<DB> 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())
Expand Down Expand Up @@ -1153,7 +1153,7 @@ impl<DB: DatabaseExt> Inspector<DB> 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())
Expand Down
2 changes: 1 addition & 1 deletion crates/chisel/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
2 changes: 1 addition & 1 deletion crates/chisel/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion crates/evm/evm/src/inspectors/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<DB: Database> Inspector<DB> 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()
});
}
Expand Down
2 changes: 1 addition & 1 deletion crates/evm/traces/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};

Expand Down
2 changes: 1 addition & 1 deletion crates/forge/bin/cmd/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ fn dummy_link_bytecode(mut obj: CompactBytecode) -> Option<Bytes> {
}

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.
Expand Down
9 changes: 6 additions & 3 deletions crates/forge/bin/cmd/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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();

Expand Down
6 changes: 3 additions & 3 deletions crates/forge/bin/cmd/script/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion crates/forge/bin/cmd/script/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}),
Expand Down
4 changes: 2 additions & 2 deletions crates/forge/bin/cmd/script/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down Expand Up @@ -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,
) {
Expand Down
9 changes: 3 additions & 6 deletions crates/forge/src/multi_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -330,11 +330,8 @@ impl MultiContractRunnerBuilder {
id.clone(),
(
abi.clone(),
bytecode.0.into(),
dependencies
.into_iter()
.map(|dep| dep.bytecode.0.into())
.collect::<Vec<_>>(),
bytecode,
dependencies.into_iter().map(|dep| dep.bytecode).collect::<Vec<_>>(),
),
);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions crates/utils/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 441c853

Please sign in to comment.