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

feat: move reth genesis to alloy-genesis #120

Merged
merged 9 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ alloy-transport = { version = "0.1.0", path = "crates/transport" }
alloy-transport-http = { version = "0.1.0", path = "crates/transport-http" }
alloy-transport-ipc = { version = "0.1.0", path = "crates/transport-ipc" }
alloy-transport-ws = { version = "0.1.0", path = "crates/transport-ws" }

alloy-genesis = {version = "0.1.0", path = "crates/genesis" }
alloy-primitives = { version = "0.6", default-features = false, features = ["std"] }
alloy-sol-types = { version = "0.6", default-features = false, features = ["std"] }
alloy-rlp = "0.3"
Expand All @@ -45,7 +45,11 @@ elliptic-curve = { version = "0.13", default-features = false, features = ["std"
k256 = { version = "0.13", default-features = false, features = ["ecdsa", "std"] }
sha2 = { version = "0.10", default-features = false, features = ["std"] }
spki = { version = "0.7", default-features = false, features = ["std"] }

secp256k1 = { version = "0.27.0", default-features = false, features = [
"global-context",
"rand-std",
"recovery",
] }
# async
async-trait = "0.1.74"
futures = "0.3.29"
Expand Down
26 changes: 26 additions & 0 deletions crates/genesis/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "alloy-genesis"
description = "Genesis types "

version.workspace = true
edition.workspace = true
rust-version.workspace = true
authors.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true
exclude.workspace = true

[dependencies]
alloy-primitives.workspace = true
alloy-rpc-types.workspace = true
secp256k1.workspace = true
alloy-signer.workspace = true

# serde
serde.workspace = true
serde_json.workspace = true
k256.workspace = true



42 changes: 42 additions & 0 deletions crates/genesis/src/account.rs
supernovahs marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/// Keccak256 over empty array.
pub const KECCAK_EMPTY: B256 =
b256!("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470");
use alloy_primitives::{b256, B256, U256};

// An Ethereum account.
#[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 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.
pub fn is_empty(&self) -> bool {
let is_bytecode_empty = match self.bytecode_hash {
None => true,
Some(hash) => hash == KECCAK_EMPTY,
};

self.nonce == 0 && self.balance.is_zero() && is_bytecode_empty
}

/// Returns an account bytecode's hash.
/// In case of no bytecode, returns [`KECCAK_EMPTY`].
pub fn get_bytecode_hash(&self) -> B256 {
match self.bytecode_hash {
Some(hash) => hash,
None => KECCAK_EMPTY,
}
}
}
Loading
Loading