alloy_network_primitives/
tx_builders.rs1use core::ops::{Deref, DerefMut};
2
3use alloc::vec::Vec;
4use alloy_consensus::BlobTransactionSidecar;
5use alloy_eips::{eip7594::BlobTransactionSidecarEip7594, 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
53pub trait TransactionBuilder7594: Default + Sized + Send + Sync + 'static {
55 fn max_fee_per_blob_gas(&self) -> Option<u128>;
57
58 fn set_max_fee_per_blob_gas(&mut self, max_fee_per_blob_gas: u128);
60
61 fn blob_sidecar_7594(&self) -> Option<&BlobTransactionSidecarEip7594>;
63
64 fn set_blob_sidecar_7594(&mut self, sidecar: BlobTransactionSidecarEip7594);
66
67 fn with_blob_sidecar(mut self, sidecar: BlobTransactionSidecarEip7594) -> Self {
69 self.set_blob_sidecar_7594(sidecar);
70 self
71 }
72}
73
74impl<T> TransactionBuilder4844 for WithOtherFields<T>
75where
76 T: TransactionBuilder4844,
77{
78 fn max_fee_per_blob_gas(&self) -> Option<u128> {
79 self.deref().max_fee_per_blob_gas()
80 }
81
82 fn set_max_fee_per_blob_gas(&mut self, max_fee_per_blob_gas: u128) {
83 self.deref_mut().set_max_fee_per_blob_gas(max_fee_per_blob_gas)
84 }
85
86 fn blob_sidecar(&self) -> Option<&BlobTransactionSidecar> {
87 self.deref().blob_sidecar()
88 }
89
90 fn set_blob_sidecar(&mut self, sidecar: BlobTransactionSidecar) {
91 self.deref_mut().set_blob_sidecar(sidecar)
92 }
93}
94
95impl<T> TransactionBuilder7702 for WithOtherFields<T>
96where
97 T: TransactionBuilder7702,
98{
99 fn authorization_list(&self) -> Option<&Vec<SignedAuthorization>> {
100 self.deref().authorization_list()
101 }
102
103 fn set_authorization_list(&mut self, authorization_list: Vec<SignedAuthorization>) {
104 self.deref_mut().set_authorization_list(authorization_list)
105 }
106}
107
108impl<T> TransactionBuilder7594 for WithOtherFields<T>
109where
110 T: TransactionBuilder7594,
111{
112 fn max_fee_per_blob_gas(&self) -> Option<u128> {
113 self.deref().max_fee_per_blob_gas()
114 }
115
116 fn set_max_fee_per_blob_gas(&mut self, max_fee_per_blob_gas: u128) {
117 self.deref_mut().set_max_fee_per_blob_gas(max_fee_per_blob_gas)
118 }
119
120 fn blob_sidecar_7594(&self) -> Option<&BlobTransactionSidecarEip7594> {
121 self.deref().blob_sidecar_7594()
122 }
123
124 fn set_blob_sidecar_7594(&mut self, sidecar: BlobTransactionSidecarEip7594) {
125 self.deref_mut().set_blob_sidecar_7594(sidecar)
126 }
127}