Skip to content

Commit

Permalink
expose EIP-155 helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr committed Oct 30, 2024
1 parent b09274e commit fabd775
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions crates/consensus/src/transaction/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,15 +359,15 @@ impl Decodable for TxLegacy {
}

/// Helper for encoding `y_parity` boolean and optional `chain_id` into EIP-155 `v` value.
const fn to_eip155_value(y_parity: bool, chain_id: Option<ChainId>) -> u64 {
pub const fn to_eip155_value(y_parity: bool, chain_id: Option<ChainId>) -> u64 {
match chain_id {
Some(id) => 35 + id * 2 + y_parity as u64,
None => 27 + y_parity as u64,
}
}

/// Helper for decoding EIP-155 `v` value into `y_parity` boolean and optional `chain_id`.
const fn from_eip155_value(value: u64) -> Option<(bool, Option<ChainId>)> {
pub const fn from_eip155_value(value: u64) -> Option<(bool, Option<ChainId>)> {
match value {
27 => Some((false, None)),
28 => Some((true, None)),
Expand Down
2 changes: 1 addition & 1 deletion crates/consensus/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ mod envelope;
pub use envelope::{TxEnvelope, TxType};

mod legacy;
pub use legacy::TxLegacy;
pub use legacy::{from_eip155_value, to_eip155_value, TxLegacy};

mod rlp;
#[doc(hidden)]
Expand Down

0 comments on commit fabd775

Please sign in to comment.