-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(
rpc-types
): RLP encoding/decoding for transaction types (#36)
* feat: add rlp encoding/decoding to tx types * feat: add encodable/decodable traits to tx * chore: remove out-of-scope func * chore: remove bad links on comments * chore: fix docs * clippy
- Loading branch information
Showing
5 changed files
with
798 additions
and
9 deletions.
There are no files selected for viewing
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
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,52 @@ | ||
use alloy_primitives::U8; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// Identifier for legacy transaction, however a legacy tx is technically not | ||
/// typed. | ||
pub const LEGACY_TX_TYPE_ID: u8 = 0; | ||
|
||
/// Identifier for an EIP2930 transaction. | ||
pub const EIP2930_TX_TYPE_ID: u8 = 1; | ||
|
||
/// Identifier for an EIP1559 transaction. | ||
pub const EIP1559_TX_TYPE_ID: u8 = 2; | ||
|
||
/// Identifier for an EIP4844 transaction. | ||
pub const EIP4844_TX_TYPE_ID: u8 = 3; | ||
|
||
/// Transaction Type | ||
/// | ||
/// Currently being used as 2-bit type when encoding it to Compact on | ||
/// crate::TransactionSignedNoHash (see Reth's Compact encoding). Adding more transaction types will break the codec and | ||
/// database format on Reth. | ||
/// | ||
/// Other required changes when adding a new type can be seen on [PR#3953](https://github.com/paradigmxyz/reth/pull/3953/files). | ||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Default, Serialize, Deserialize)] | ||
pub enum TxType { | ||
/// Legacy transaction pre EIP-2929 | ||
#[default] | ||
Legacy = 0_isize, | ||
/// AccessList transaction | ||
EIP2930 = 1_isize, | ||
/// Transaction with Priority fee | ||
EIP1559 = 2_isize, | ||
/// Shard Blob Transactions - EIP-4844 | ||
EIP4844 = 3_isize, | ||
} | ||
|
||
impl From<TxType> for u8 { | ||
fn from(value: TxType) -> Self { | ||
match value { | ||
TxType::Legacy => LEGACY_TX_TYPE_ID, | ||
TxType::EIP2930 => EIP2930_TX_TYPE_ID, | ||
TxType::EIP1559 => EIP1559_TX_TYPE_ID, | ||
TxType::EIP4844 => EIP4844_TX_TYPE_ID, | ||
} | ||
} | ||
} | ||
|
||
impl From<TxType> for U8 { | ||
fn from(value: TxType) -> Self { | ||
U8::from(u8::from(value)) | ||
} | ||
} |
Oops, something went wrong.