alloy_network_primitives/
tx_builders.rs1use core::ops::{Deref, DerefMut};
2
3use alloc::vec::Vec;
4use alloy_consensus::BlobTransactionSidecar;
5use alloy_eips::eip7702::SignedAuthorization;
6use alloy_serde::WithOtherFields;
7
8pub trait TransactionBuilder4844: Default + Sized + Send + Sync + 'static {
10 fn max_fee_per_blob_gas(&self) -> Option<u128>;
12
13 fn set_max_fee_per_blob_gas(&mut self, max_fee_per_blob_gas: u128);
15
16 fn with_max_fee_per_blob_gas(mut self, max_fee_per_blob_gas: u128) -> Self {
18 self.set_max_fee_per_blob_gas(max_fee_per_blob_gas);
19 self
20 }
21
22 fn blob_sidecar(&self) -> Option<&BlobTransactionSidecar>;
24
25 fn set_blob_sidecar(&mut self, sidecar: BlobTransactionSidecar);
30
31 fn with_blob_sidecar(mut self, sidecar: BlobTransactionSidecar) -> Self {
33 self.set_blob_sidecar(sidecar);
34 self
35 }
36}
37
38pub trait TransactionBuilder7702: Default + Sized + Send + Sync + 'static {
40 fn authorization_list(&self) -> Option<&Vec<SignedAuthorization>>;
42
43 fn set_authorization_list(&mut self, authorization_list: Vec<SignedAuthorization>);
45
46 fn with_authorization_list(mut self, authorization_list: Vec<SignedAuthorization>) -> Self {
48 self.set_authorization_list(authorization_list);
49 self
50 }
51}
52
53impl<T> TransactionBuilder4844 for WithOtherFields<T>
54where
55 T: TransactionBuilder4844,
56{
57 fn max_fee_per_blob_gas(&self) -> Option<u128> {
58 self.deref().max_fee_per_blob_gas()
59 }
60
61 fn set_max_fee_per_blob_gas(&mut self, max_fee_per_blob_gas: u128) {
62 self.deref_mut().set_max_fee_per_blob_gas(max_fee_per_blob_gas)
63 }
64
65 fn blob_sidecar(&self) -> Option<&BlobTransactionSidecar> {
66 self.deref().blob_sidecar()
67 }
68
69 fn set_blob_sidecar(&mut self, sidecar: BlobTransactionSidecar) {
70 self.deref_mut().set_blob_sidecar(sidecar)
71 }
72}
73
74impl<T> TransactionBuilder7702 for WithOtherFields<T>
75where
76 T: TransactionBuilder7702,
77{
78 fn authorization_list(&self) -> Option<&Vec<SignedAuthorization>> {
79 self.deref().authorization_list()
80 }
81
82 fn set_authorization_list(&mut self, authorization_list: Vec<SignedAuthorization>) {
83 self.deref_mut().set_authorization_list(authorization_list)
84 }
85}