Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use From<Address> for TxKind #651

Merged
merged 2 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/consensus/src/transaction/eip1559.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ mod tests {
use super::TxEip1559;
use crate::SignableTransaction;
use alloy_eips::eip2930::AccessList;
use alloy_primitives::{address, b256, hex, Address, Signature, TxKind, B256, U256};
use alloy_primitives::{address, b256, hex, Address, Signature, B256, U256};

#[test]
fn recover_signer_eip1559() {
Expand All @@ -355,7 +355,7 @@ mod tests {
chain_id: 1,
nonce: 0x42,
gas_limit: 44386,
to: TxKind::Call( address!("6069a6c32cf691f5982febae4faf8a6f3ab2f0f6")),
to: address!("6069a6c32cf691f5982febae4faf8a6f3ab2f0f6").into(),
value: U256::from(0_u64),
input: hex!("a22cb4650000000000000000000000005eee75727d804a2b13038928d36f8b188945a57a0000000000000000000000000000000000000000000000000000000000000000").into(),
max_fee_per_gas: 0x4a817c800,
Expand Down Expand Up @@ -388,7 +388,7 @@ mod tests {
chain_id: 1,
nonce: 0x42,
gas_limit: 44386,
to: TxKind::Call( address!("6069a6c32cf691f5982febae4faf8a6f3ab2f0f6")),
to: address!("6069a6c32cf691f5982febae4faf8a6f3ab2f0f6").into(),
value: U256::from(0_u64),
input: hex!("a22cb4650000000000000000000000005eee75727d804a2b13038928d36f8b188945a57a0000000000000000000000000000000000000000000000000000000000000000").into(),
max_fee_per_gas: 0x4a817c800,
Expand Down
2 changes: 1 addition & 1 deletion crates/consensus/src/transaction/eip2930.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ mod tests {
nonce: 0,
gas_price: 1,
gas_limit: 2,
to: TxKind::Call(Address::default()),
to: Address::default().into(),
value: U256::from(3_u64),
input: Bytes::from(vec![1, 2]),
access_list: Default::default(),
Expand Down
8 changes: 4 additions & 4 deletions crates/consensus/src/transaction/eip4844.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,11 @@ impl Transaction for TxEip4844Variant {
}

fn to(&self) -> TxKind {
let address = match self {
match self {
TxEip4844Variant::TxEip4844(tx) => tx.to,
TxEip4844Variant::TxEip4844WithSidecar(tx) => tx.tx.to,
};
TxKind::Call(address)
}
.into()
}

fn value(&self) -> U256 {
Expand Down Expand Up @@ -716,7 +716,7 @@ impl Transaction for TxEip4844 {
}

fn to(&self) -> TxKind {
TxKind::Call(self.to)
self.to.into()
}

fn value(&self) -> U256 {
Expand Down
10 changes: 5 additions & 5 deletions crates/consensus/src/transaction/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ mod tests {
max_fee_per_gas: 3,
max_priority_fee_per_gas: 4,
gas_limit: 5,
to: TxKind::Call(Address::left_padding_from(&[6])),
to: Address::left_padding_from(&[6]).into(),
value: U256::from(7_u64),
input: Bytes::from(vec![8]),
access_list: Default::default(),
Expand All @@ -433,7 +433,7 @@ mod tests {
nonce: 2,
gas_price: 3,
gas_limit: 4,
to: TxKind::Call(Address::left_padding_from(&[5])),
to: Address::left_padding_from(&[5]).into(),
value: U256::from(6_u64),
input: Bytes::from(vec![7]),
access_list: AccessList(vec![AccessListItem {
Expand All @@ -454,7 +454,7 @@ mod tests {
max_fee_per_gas: 3,
max_priority_fee_per_gas: 4,
gas_limit: 5,
to: TxKind::Call(Address::left_padding_from(&[6])),
to: Address::left_padding_from(&[6]).into(),
value: U256::from(7_u64),
input: Bytes::from(vec![8]),
access_list: Default::default(),
Expand Down Expand Up @@ -503,7 +503,7 @@ mod tests {
nonce: 100,
gas_price: 3_000_000_000,
gas_limit: 50_000,
to: TxKind::Call(Address::default()),
to: Address::default().into(),
value: U256::from(10e18),
input: Bytes::new(),
};
Expand Down Expand Up @@ -538,7 +538,7 @@ mod tests {
nonce: u64::MAX,
gas_price: u128::MAX,
gas_limit: u128::MAX,
to: TxKind::Call(Address::random()),
to: Address::random().into(),
value: U256::MAX,
input: Bytes::new(),
access_list: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion crates/consensus/src/transaction/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ mod tests {
nonce: 0x18,
gas_price: 0xfa56ea00,
gas_limit: 119902,
to: TxKind::Call( hex!("06012c8cf97bead5deae237070f9587f8e7a266d").into()),
to: TxKind::Call(hex!("06012c8cf97bead5deae237070f9587f8e7a266d").into()),
value: U256::from(0x1c6bf526340000u64),
input: hex!("f7d8c88300000000000000000000000000000000000000000000000000000000000cee6100000000000000000000000000000000000000000000000000000000000ac3e1").into(),
};
Expand Down
4 changes: 2 additions & 2 deletions crates/network/src/ethereum/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl TransactionBuilder<Ethereum> for TransactionRequest {
mod tests {
use crate::{TransactionBuilder, TransactionBuilderError};
use alloy_consensus::{BlobTransactionSidecar, TxEip1559, TxType, TypedTransaction};
use alloy_primitives::{Address, TxKind};
use alloy_primitives::Address;
use alloy_rpc_types::{AccessList, TransactionRequest};

#[test]
Expand All @@ -192,7 +192,7 @@ mod tests {
chain_id: 1,
nonce: 0,
gas_limit: 21_000,
to: TxKind::Call(Address::ZERO),
to: Address::ZERO.into(),
max_priority_fee_per_gas: 20e9 as u128,
max_fee_per_gas: 20e9 as u128,
..Default::default()
Expand Down
2 changes: 1 addition & 1 deletion crates/network/src/transaction/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub trait TransactionBuilder<N: Network>: Default + Sized + Send + Sync + 'stati

/// Set the recipient for the transaction.
fn set_to(&mut self, to: Address) {
self.set_kind(TxKind::Call(to));
self.set_kind(to.into());
}

/// Builder-pattern method for setting the recipient.
Expand Down
7 changes: 3 additions & 4 deletions crates/provider/src/provider/trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -904,11 +904,10 @@ impl<T: Transport + Clone, N: Network> Provider<T, N> for RootProvider<T, N> {
#[cfg(test)]
#[allow(clippy::missing_const_for_fn)]
mod tests {
use crate::ProviderBuilder;

use super::*;
use crate::ProviderBuilder;
use alloy_node_bindings::Anvil;
use alloy_primitives::{address, b256, bytes, TxKind};
use alloy_primitives::{address, b256, bytes};
use alloy_rpc_types::request::TransactionRequest;

fn init_tracing() {
Expand Down Expand Up @@ -1031,7 +1030,7 @@ mod tests {
let provider = ProviderBuilder::new().on_anvil();
let tx = TransactionRequest {
value: Some(U256::from(100)),
to: Some(TxKind::Call(address!("d8dA6BF26964aF9D7eEd9e03E53415D37aA96045"))),
to: Some(address!("d8dA6BF26964aF9D7eEd9e03E53415D37aA96045").into()),
gas_price: Some(20e9 as u128),
gas: Some(21000),
..Default::default()
Expand Down
10 changes: 5 additions & 5 deletions crates/rpc-types/src/eth/transaction/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ impl From<TxLegacy> for TransactionRequest {
fn from(tx: TxLegacy) -> TransactionRequest {
TransactionRequest {
from: None,
to: if let TxKind::Call(to) = tx.to { Some(TxKind::Call(to)) } else { None },
to: if let TxKind::Call(to) = tx.to { Some(to.into()) } else { None },
gas_price: Some(tx.gas_price),
gas: Some(tx.gas_limit),
value: Some(tx.value),
Expand All @@ -617,7 +617,7 @@ impl From<TxEip2930> for TransactionRequest {
fn from(tx: TxEip2930) -> TransactionRequest {
TransactionRequest {
from: None,
to: if let TxKind::Call(to) = tx.to { Some(TxKind::Call(to)) } else { None },
to: if let TxKind::Call(to) = tx.to { Some(to.into()) } else { None },
gas_price: Some(tx.gas_price),
gas: Some(tx.gas_limit),
value: Some(tx.value),
Expand All @@ -635,7 +635,7 @@ impl From<TxEip1559> for TransactionRequest {
fn from(tx: TxEip1559) -> TransactionRequest {
TransactionRequest {
from: None,
to: if let TxKind::Call(to) = tx.to { Some(TxKind::Call(to)) } else { None },
to: if let TxKind::Call(to) = tx.to { Some(to.into()) } else { None },
max_fee_per_gas: Some(tx.max_fee_per_gas),
max_priority_fee_per_gas: Some(tx.max_priority_fee_per_gas),
gas: Some(tx.gas_limit),
Expand All @@ -654,7 +654,7 @@ impl From<TxEip4844> for TransactionRequest {
fn from(tx: TxEip4844) -> TransactionRequest {
TransactionRequest {
from: None,
to: Some(TxKind::Call(tx.to)),
to: Some(tx.to.into()),
max_fee_per_blob_gas: Some(tx.max_fee_per_blob_gas),
gas: Some(tx.gas_limit),
max_fee_per_gas: Some(tx.max_fee_per_gas),
Expand All @@ -677,7 +677,7 @@ impl From<TxEip4844WithSidecar> for TransactionRequest {
let tx = tx.tx;
TransactionRequest {
from: None,
to: Some(TxKind::Call(tx.to)),
to: Some(tx.to.into()),
max_fee_per_blob_gas: Some(tx.max_fee_per_blob_gas),
gas: Some(tx.gas_limit),
max_fee_per_gas: Some(tx.max_fee_per_gas),
Expand Down
4 changes: 1 addition & 3 deletions crates/signer-ledger/src/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,7 @@ mod tests {
nonce: 5,
gas_price: 400e9 as u128,
gas_limit: 1000000,
to: alloy_primitives::TxKind::Call(address!(
"2ed7afa17473e17ac59908f088b4371d28585476"
)),
to: address!("2ed7afa17473e17ac59908f088b4371d28585476").into(),
// TODO: this fails for some reason with 6a80 APDU_CODE_BAD_KEY_HANDLE
// approve uni v2 router 0xff
// input: bytes!("095ea7b30000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),
Expand Down
4 changes: 1 addition & 3 deletions crates/signer-wallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,7 @@ mod test {
// retrieved test vector from:
// https://web3js.readthedocs.io/en/v1.2.0/web3-eth-accounts.html#eth-accounts-signtransaction
let mut tx = TxLegacy {
to: alloy_primitives::TxKind::Call(address!(
"F0109fC8DF283027b6285cc889F5aA624EaC1F55"
)),
to: address!("F0109fC8DF283027b6285cc889F5aA624EaC1F55").into(),
value: U256::from(1_000_000_000),
gas_limit: 2_000_000,
nonce: 0,
Expand Down
Loading