Skip to content

Commit

Permalink
upgrade alloy-primitives
Browse files Browse the repository at this point in the history
  • Loading branch information
Wollac committed Aug 28, 2023
1 parent e45b2b0 commit 8e6235d
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 46 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions guests/eth-block/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use hashbrown::HashMap;
use revm::primitives::B160 as RevmB160;
use serde::{Deserialize, Serialize};
use zeth_primitives::{
block::Header, transaction::Transaction, trie::MptNode, withdrawal::Withdrawal, Bytes, B160,
block::Header, transaction::Transaction, trie::MptNode, withdrawal::Withdrawal, Address, Bytes,
B256, U256,
};

Expand All @@ -30,7 +30,7 @@ pub struct Input {
/// Previous block header
pub parent_header: Header,
/// Address to which all priority fees in this block are transferred.
pub beneficiary: B160,
pub beneficiary: Address,
/// Scalar equal to the current limit of gas expenditure per block.
pub gas_limit: U256,
/// Scalar corresponding to the seconds since Epoch at this block's inception.
Expand Down
2 changes: 1 addition & 1 deletion primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
alloy-primitives = { git = "https://github.com/alloy-rs/core.git", rev = "58e2259", features = ["rlp", "serde"] }
alloy-primitives = { version = "0.3", features = ["rlp", "serde"] }
alloy-rlp = { version = "0.3", default-features = false }
alloy-rlp-derive = { version = "0.3", default-features = false }
anyhow = "1.0"
Expand Down
4 changes: 2 additions & 2 deletions primitives/src/access_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use alloy_primitives::{StorageKey, B160};
use alloy_primitives::{Address, StorageKey};
use alloy_rlp_derive::{RlpEncodable, RlpEncodableWrapper};
use serde::{Deserialize, Serialize};

Expand All @@ -32,7 +32,7 @@ pub struct AccessList(pub Vec<AccessListItem>);
#[derive(Debug, Clone, PartialEq, Eq, Default, RlpEncodable, Serialize, Deserialize)]
pub struct AccessListItem {
/// The Ethereum address that the transaction will access.
pub address: B160,
pub address: Address,
/// A list of storage keys associated with the given address that the transaction will
/// access.
pub storage_keys: Vec<StorageKey>,
Expand Down
6 changes: 3 additions & 3 deletions primitives/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use alloy_primitives::{b256, BlockHash, BlockNumber, Bloom, Bytes, B160, B256, B64, U256};
use alloy_primitives::{b256, Address, BlockHash, BlockNumber, Bloom, Bytes, B256, B64, U256};
use alloy_rlp_derive::RlpEncodable;
use serde::{Deserialize, Serialize};

Expand All @@ -30,7 +30,7 @@ pub struct Header {
/// Unused 256-bit hash, always [EMPTY_LIST_HASH].
pub ommers_hash: B256,
/// Address that receives the priority fees of each transaction in the block.
pub beneficiary: B160,
pub beneficiary: Address,
/// Root hash of the state trie after all transactions in the block are executed.
pub state_root: B256,
/// Root hash of the trie containing all transactions in the block.
Expand Down Expand Up @@ -69,7 +69,7 @@ impl Default for Header {
Header {
parent_hash: B256::ZERO,
ommers_hash: EMPTY_LIST_HASH,
beneficiary: B160::ZERO,
beneficiary: Address::ZERO,
state_root: EMPTY_ROOT,
transactions_root: EMPTY_ROOT,
receipts_root: EMPTY_ROOT,
Expand Down
6 changes: 3 additions & 3 deletions primitives/src/ethers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

//! Convert from Ethers types.
use alloy_primitives::{Bloom, B160, B256, U256};
use alloy_primitives::{Address, Bloom, B256, U256};
use anyhow::{anyhow, Context};
use ethers_core::types::{
transaction::eip2930::{
Expand All @@ -41,9 +41,9 @@ pub fn from_ethers_u256(v: EthersU256) -> U256 {
U256::from_limbs(v.0)
}

/// Convert an `EthersH160` type to the `B160` type.
/// Convert an `EthersH160` type to the `Address` type.
#[inline]
pub fn from_ethers_h160(v: EthersH160) -> B160 {
pub fn from_ethers_h160(v: EthersH160) -> Address {
v.0.into()
}

Expand Down
4 changes: 2 additions & 2 deletions primitives/src/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use alloy_primitives::{Bloom, BloomInput, Bytes, B160, B256, U256};
use alloy_primitives::{Address, Bloom, BloomInput, Bytes, B256, U256};
use alloy_rlp::Encodable;
use alloy_rlp_derive::RlpEncodable;
use serde::{Deserialize, Serialize};
Expand All @@ -21,7 +21,7 @@ use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize, RlpEncodable)]
pub struct Log {
/// Contract that emitted this log.
pub address: B160,
pub address: Address,
/// Topics of the log. The number of logs depend on what `LOG` opcode is used.
pub topics: Vec<B256>,
/// Arbitrary length data.
Expand Down
12 changes: 6 additions & 6 deletions primitives/src/revm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@

//! Convert to revm types.
use alloy_primitives::{B160, B256};
use alloy_primitives::{Address, B256};
use revm_primitives::{Log as RevmLog, B160 as RevmB160, B256 as RevmB256, U256 as RevmU256};

use crate::{
access_list::{AccessList, AccessListItem},
receipt::Log,
};

/// Converts a `B160` type to its corresponding `RevmB160` representation.
/// Converts a `Address` type to its corresponding `RevmB160` representation.
#[inline]
pub fn to_revm_b160(v: B160) -> RevmB160 {
v.0.into()
pub fn to_revm_b160(v: Address) -> RevmB160 {
v.0 .0.into()
}

/// Converts a `B256` type to its corresponding `RevmB256` representation.
Expand All @@ -34,9 +34,9 @@ pub fn to_revm_b256(v: B256) -> RevmB256 {
v.0.into()
}

/// Converts a `RevmB160` type to its corresponding `B160` representation.
/// Converts a `RevmB160` type to its corresponding `Address` representation.
#[inline]
pub fn from_revm_b160(v: RevmB160) -> B160 {
pub fn from_revm_b160(v: RevmB160) -> Address {
v.0.into()
}

Expand Down
6 changes: 3 additions & 3 deletions primitives/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use alloy_primitives::{B160, U256};
use alloy_primitives::{Address, U256};
use alloy_rlp_derive::{RlpEncodable, RlpMaxEncodedLen};
use anyhow::Context;
use k256::{
Expand Down Expand Up @@ -52,7 +52,7 @@ impl Transaction {
/// This method uses the ECDSA recovery mechanism to derive the sender's public key
/// and subsequently their Ethereum address. If the recovery is unsuccessful, an
/// error is returned.
pub fn recover_from(&self) -> anyhow::Result<B160> {
pub fn recover_from(&self) -> anyhow::Result<Address> {
let is_y_odd = self.is_y_odd().context("v invalid")?;
let signature = K256Signature::from_scalars(
self.signature.r.to_be_bytes(),
Expand All @@ -73,7 +73,7 @@ impl Transaction {
debug_assert_eq!(public_key[0], 0x04);
let hash = keccak(&public_key[1..]);

Ok(B160::from_slice(&hash[12..]))
Ok(Address::from_slice(&hash[12..]))
}

/// Determines whether the y-coordinate of the ECDSA signature's associated public key
Expand Down
12 changes: 6 additions & 6 deletions primitives/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use alloy_primitives::{Bytes, ChainId, TxHash, TxNumber, B160, B256, U256};
use alloy_primitives::{Address, Bytes, ChainId, TxHash, TxNumber, B256, U256};
use alloy_rlp::{Encodable, EMPTY_STRING_CODE};
use alloy_rlp_derive::RlpEncodable;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -312,16 +312,16 @@ pub enum TransactionKind {
Create,
/// Indicates that the transaction is a call to an existing contract, identified by
/// its 160-bit address.
Call(B160),
Call(Address),
}

/// Provides a conversion from [TransactionKind] to `Option<B160>`.
/// Provides a conversion from [TransactionKind] to `Option<Address>`.
///
/// This implementation allows for a straightforward extraction of the Ethereum address
/// from a [TransactionKind]. If the transaction kind is a `Call`, the address is wrapped
/// in a `Some`. If it's a `Create`, the result is `None`.
impl From<TransactionKind> for Option<B160> {
/// Converts a [TransactionKind] into an `Option<B160>`.
impl From<TransactionKind> for Option<Address> {
/// Converts a [TransactionKind] into an `Option<Address>`.
///
/// - If the transaction kind is `Create`, this returns `None`.
/// - If the transaction kind is `Call`, this returns the address wrapped in a `Some`.
Expand Down Expand Up @@ -461,7 +461,7 @@ impl Transaction {
///
/// For contract creation transactions, this method returns `None` as there's no
/// recipient address.
pub fn to(&self) -> Option<B160> {
pub fn to(&self) -> Option<Address> {
match &self.essence {
TxEssence::Legacy(tx) => tx.to.into(),
TxEssence::Eip2930(tx) => tx.to.into(),
Expand Down
6 changes: 3 additions & 3 deletions primitives/src/withdrawal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use alloy_primitives::B160;
use alloy_primitives::Address;
use alloy_rlp_derive::{RlpEncodable, RlpMaxEncodedLen};
use serde::{Deserialize, Serialize};

Expand All @@ -32,9 +32,9 @@ pub struct Withdrawal {
pub index: u64,
/// The distinct index of the validator initiating this withdrawal.
pub validator_index: u64,
/// The Ethereum address, encapsulated as a `B160` type, where the withdrawn ether
/// The Ethereum address, encapsulated as a `Address` type, where the withdrawn ether
/// will be sent.
pub address: B160,
pub address: Address,
/// The total withdrawal amount, denominated in gwei.
pub amount: u64,
}
8 changes: 4 additions & 4 deletions testing/ef-tests/src/ethers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl Provider for TestProvider {
Ok(Block::<H256> {
parent_hash: self.header.parent_hash.0.into(),
uncles_hash: self.header.ommers_hash.0.into(),
author: Some(self.header.beneficiary.0.into()),
author: Some(self.header.beneficiary.0 .0.into()),
state_root: self.header.state_root.0.into(),
transactions_root: self.header.transactions_root.0.into(),
receipts_root: self.header.receipts_root.0.into(),
Expand Down Expand Up @@ -126,7 +126,7 @@ impl Provider for TestProvider {
}
}

fn build_tries(state: &TestState) -> (MptNode, HashMap<B160, MptNode>) {
fn build_tries(state: &TestState) -> (MptNode, HashMap<Address, MptNode>) {
let mut state_trie = MptNode::default();
let mut storage_tries = HashMap::new();
for (address, account) in &state.0 {
Expand Down Expand Up @@ -157,7 +157,7 @@ fn build_tries(state: &TestState) -> (MptNode, HashMap<B160, MptNode>) {
}

fn get_proof(
address: B160,
address: Address,
indices: impl IntoIterator<Item = LibU256>,
state: &TestState,
) -> Result<EIP1186ProofResponse, anyhow::Error> {
Expand Down Expand Up @@ -189,7 +189,7 @@ fn get_proof(
}

Ok(EIP1186ProofResponse {
address: address.0.into(),
address: address.0 .0.into(),
balance: account.balance.to_be_bytes().into(),
code_hash: keccak(account.code).into(),
nonce: account.nonce.to_be_bytes().into(),
Expand Down
10 changes: 5 additions & 5 deletions testing/ef-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use zeth_primitives::{
},
trie::{self, MptNode, MptNodeData, StateAccount},
withdrawal::Withdrawal,
Bloom, Bytes, RlpBytes, StorageKey, B160, B256, B64, U256, U64,
Address, Bloom, Bytes, RlpBytes, StorageKey, B256, B64, U256, U64,
};

use crate::ethers::{get_state_update_proofs, TestProvider};
Expand Down Expand Up @@ -106,7 +106,7 @@ impl From<DbAccount> for TestAccount {

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct TestState(pub HashMap<B160, TestAccount>);
pub struct TestState(pub HashMap<Address, TestAccount>);

impl From<&MemDb> for TestState {
fn from(db: &MemDb) -> Self {
Expand All @@ -130,7 +130,7 @@ impl From<&ProviderDb> for TestState {
pub struct TestHeader {
pub base_fee_per_gas: Option<U256>,
pub bloom: Bloom,
pub coinbase: B160,
pub coinbase: Address,
pub extra_data: Bytes,
pub difficulty: U256,
pub gas_limit: U256,
Expand Down Expand Up @@ -184,7 +184,7 @@ pub struct TestTransaction {
pub max_priority_fee_per_gas: Option<U256>,
pub value: U256,
#[serde_as(as = "NoneAsEmptyString")]
pub to: Option<B160>,
pub to: Option<Address>,
pub nonce: U64,
pub v: U64,
pub r: U256,
Expand Down Expand Up @@ -252,7 +252,7 @@ pub struct TestAccessList(pub Vec<TestAccessListItem>);
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TestAccessListItem {
pub address: B160,
pub address: Address,
pub storage_keys: Vec<StorageKey>,
}

Expand Down
5 changes: 3 additions & 2 deletions testing/ef-tests/testguest/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8e6235d

Please sign in to comment.