-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: move txtype-specific builders to network-primitives (#1602)
* chore: move txtype-specific builders to network-primitives * fmt * add file * use alloc::Vec
- Loading branch information
Showing
6 changed files
with
124 additions
and
111 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
use core::ops::{Deref, DerefMut}; | ||
|
||
use alloc::vec::Vec; | ||
use alloy_consensus::BlobTransactionSidecar; | ||
use alloy_eips::eip7702::SignedAuthorization; | ||
use alloy_serde::WithOtherFields; | ||
|
||
/// Transaction builder type supporting EIP-4844 transaction fields. | ||
pub trait TransactionBuilder4844: Default + Sized + Send + Sync + 'static { | ||
/// Get the max fee per blob gas for the transaction. | ||
fn max_fee_per_blob_gas(&self) -> Option<u128>; | ||
|
||
/// Set the max fee per blob gas for the transaction. | ||
fn set_max_fee_per_blob_gas(&mut self, max_fee_per_blob_gas: u128); | ||
|
||
/// Builder-pattern method for setting max fee per blob gas . | ||
fn with_max_fee_per_blob_gas(mut self, max_fee_per_blob_gas: u128) -> Self { | ||
self.set_max_fee_per_blob_gas(max_fee_per_blob_gas); | ||
self | ||
} | ||
|
||
/// Gets the EIP-4844 blob sidecar of the transaction. | ||
fn blob_sidecar(&self) -> Option<&BlobTransactionSidecar>; | ||
|
||
/// Sets the EIP-4844 blob sidecar of the transaction. | ||
/// | ||
/// Note: This will also set the versioned blob hashes accordingly: | ||
/// [BlobTransactionSidecar::versioned_hashes] | ||
fn set_blob_sidecar(&mut self, sidecar: BlobTransactionSidecar); | ||
|
||
/// Builder-pattern method for setting the EIP-4844 blob sidecar of the transaction. | ||
fn with_blob_sidecar(mut self, sidecar: BlobTransactionSidecar) -> Self { | ||
self.set_blob_sidecar(sidecar); | ||
self | ||
} | ||
} | ||
|
||
/// Transaction builder type supporting EIP-7702 transaction fields. | ||
pub trait TransactionBuilder7702: Default + Sized + Send + Sync + 'static { | ||
/// Get the EIP-7702 authorization list for the transaction. | ||
fn authorization_list(&self) -> Option<&Vec<SignedAuthorization>>; | ||
|
||
/// Sets the EIP-7702 authorization list. | ||
fn set_authorization_list(&mut self, authorization_list: Vec<SignedAuthorization>); | ||
|
||
/// Builder-pattern method for setting the authorization list. | ||
fn with_authorization_list(mut self, authorization_list: Vec<SignedAuthorization>) -> Self { | ||
self.set_authorization_list(authorization_list); | ||
self | ||
} | ||
} | ||
|
||
impl<T> TransactionBuilder4844 for WithOtherFields<T> | ||
where | ||
T: TransactionBuilder4844, | ||
{ | ||
fn max_fee_per_blob_gas(&self) -> Option<u128> { | ||
self.deref().max_fee_per_blob_gas() | ||
} | ||
|
||
fn set_max_fee_per_blob_gas(&mut self, max_fee_per_blob_gas: u128) { | ||
self.deref_mut().set_max_fee_per_blob_gas(max_fee_per_blob_gas) | ||
} | ||
|
||
fn blob_sidecar(&self) -> Option<&BlobTransactionSidecar> { | ||
self.deref().blob_sidecar() | ||
} | ||
|
||
fn set_blob_sidecar(&mut self, sidecar: BlobTransactionSidecar) { | ||
self.deref_mut().set_blob_sidecar(sidecar) | ||
} | ||
} | ||
|
||
impl<T> TransactionBuilder7702 for WithOtherFields<T> | ||
where | ||
T: TransactionBuilder7702, | ||
{ | ||
fn authorization_list(&self) -> Option<&Vec<SignedAuthorization>> { | ||
self.deref().authorization_list() | ||
} | ||
|
||
fn set_authorization_list(&mut self, authorization_list: Vec<SignedAuthorization>) { | ||
self.deref_mut().set_authorization_list(authorization_list) | ||
} | ||
} |
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