-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
131 additions
and
49 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
[package] | ||
name = "reth-primitives-traits" | ||
version.workspace = true | ||
edition.workspace = true | ||
homepage.workspace = true | ||
license.workspace = true | ||
repository.workspace = true | ||
rust-version.workspace = true | ||
description = "Common types in reth." | ||
|
||
[lints] | ||
workspace = true | ||
|
||
[dependencies] | ||
reth-codecs.workspace = true | ||
|
||
alloy-genesis.workspace = true | ||
alloy-primitives.workspace = true | ||
alloy-consensus.workspace = true | ||
|
||
# required by reth-codecs | ||
modular-bitfield.workspace = true | ||
bytes.workspace = true | ||
serde.workspace = true | ||
|
||
# arbitrary utils | ||
arbitrary = { workspace = true, features = ["derive"], optional = true } | ||
proptest = { workspace = true, optional = true } | ||
proptest-derive = { workspace = true, optional = true } | ||
|
||
[dev-dependencies] | ||
arbitrary = { workspace = true, features = ["derive"] } | ||
proptest.workspace = true | ||
proptest-derive.workspace = true | ||
test-fuzz.workspace = true | ||
|
||
[features] | ||
arbitrary = [ | ||
"dep:arbitrary", | ||
"dep:proptest", | ||
"dep:proptest-derive" | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use alloy_consensus::constants::KECCAK_EMPTY; | ||
use alloy_genesis::GenesisAccount; | ||
use alloy_primitives::{keccak256, B256, U256}; | ||
use reth_codecs::{main_codec, Compact}; | ||
|
||
/// An Ethereum account. | ||
#[main_codec] | ||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)] | ||
pub struct Account { | ||
/// Account nonce. | ||
pub nonce: u64, | ||
/// Account balance. | ||
pub balance: U256, | ||
/// Hash of the account's bytecode. | ||
pub bytecode_hash: Option<B256>, | ||
} | ||
|
||
impl Account { | ||
/// Whether the account has bytecode. | ||
pub const fn has_bytecode(&self) -> bool { | ||
self.bytecode_hash.is_some() | ||
} | ||
|
||
/// After `SpuriousDragon` empty account is defined as account with nonce == 0 && balance == 0 | ||
/// && bytecode = None (or hash is [`KECCAK_EMPTY`]). | ||
pub fn is_empty(&self) -> bool { | ||
self.nonce == 0 && | ||
self.balance.is_zero() && | ||
self.bytecode_hash.map_or(true, |hash| hash == KECCAK_EMPTY) | ||
} | ||
|
||
/// Makes an [Account] from [`GenesisAccount`] type | ||
pub fn from_genesis_account(value: &GenesisAccount) -> Self { | ||
Self { | ||
// nonce must exist, so we default to zero when converting a genesis account | ||
nonce: value.nonce.unwrap_or_default(), | ||
balance: value.balance, | ||
bytecode_hash: value.code.as_ref().map(keccak256), | ||
} | ||
} | ||
|
||
/// Returns an account bytecode's hash. | ||
/// In case of no bytecode, returns [`KECCAK_EMPTY`]. | ||
pub fn get_bytecode_hash(&self) -> B256 { | ||
self.bytecode_hash.unwrap_or(KECCAK_EMPTY) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//! Common abstracted types in reth. | ||
#![doc( | ||
html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png", | ||
html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256", | ||
issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/" | ||
)] | ||
#![cfg_attr(not(test), warn(unused_crate_dependencies))] | ||
// TODO: remove when https://github.com/proptest-rs/proptest/pull/427 is merged | ||
#![allow(unknown_lints, non_local_definitions)] | ||
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] | ||
|
||
/// Minimal account | ||
pub mod account; | ||
pub use account::Account; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters