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 has_blob_sidecar(&self) -> bool {
30 self.blob_sidecar().is_some()
31 }
32
33 fn set_blob_sidecar(&mut self, sidecar: BlobTransactionSidecar);
38
39 fn with_blob_sidecar(mut self, sidecar: BlobTransactionSidecar) -> Self {
41 self.set_blob_sidecar(sidecar);
42 self
43 }
44}
45
46pub trait TransactionBuilder7702: Default + Sized + Send + Sync + 'static {
48 fn authorization_list(&self) -> Option<&Vec<SignedAuthorization>>;
50
51 fn set_authorization_list(&mut self, authorization_list: Vec<SignedAuthorization>);
53
54 fn with_authorization_list(mut self, authorization_list: Vec<SignedAuthorization>) -> Self {
56 self.set_authorization_list(authorization_list);
57 self
58 }
59}
60
61pub trait TransactionBuilder7594: Default + Sized + Send + Sync + 'static {
63 fn max_fee_per_blob_gas(&self) -> Option<u128>;
65
66 fn set_max_fee_per_blob_gas(&mut self, max_fee_per_blob_gas: u128);
68
69 fn blob_sidecar_7594(&self) -> Option<&BlobTransactionSidecarEip7594>;
71
72 fn set_blob_sidecar_7594(&mut self, sidecar: BlobTransactionSidecarEip7594);
74
75 fn with_blob_sidecar(mut self, sidecar: BlobTransactionSidecarEip7594) -> Self {
77 self.set_blob_sidecar_7594(sidecar);
78 self
79 }
80}
81
82impl<T> TransactionBuilder4844 for WithOtherFields<T>
83where
84 T: TransactionBuilder4844,
85{
86 fn max_fee_per_blob_gas(&self) -> Option<u128> {
87 self.deref().max_fee_per_blob_gas()
88 }
89
90 fn set_max_fee_per_blob_gas(&mut self, max_fee_per_blob_gas: u128) {
91 self.deref_mut().set_max_fee_per_blob_gas(max_fee_per_blob_gas)
92 }
93
94 fn blob_sidecar(&self) -> Option<&BlobTransactionSidecar> {
95 self.deref().blob_sidecar()
96 }
97
98 fn has_blob_sidecar(&self) -> bool {
99 self.deref().has_blob_sidecar()
100 }
101
102 fn set_blob_sidecar(&mut self, sidecar: BlobTransactionSidecar) {
103 self.deref_mut().set_blob_sidecar(sidecar)
104 }
105}
106
107impl<T> TransactionBuilder7702 for WithOtherFields<T>
108where
109 T: TransactionBuilder7702,
110{
111 fn authorization_list(&self) -> Option<&Vec<SignedAuthorization>> {
112 self.deref().authorization_list()
113 }
114
115 fn set_authorization_list(&mut self, authorization_list: Vec<SignedAuthorization>) {
116 self.deref_mut().set_authorization_list(authorization_list)
117 }
118}
119
120impl<T> TransactionBuilder7594 for WithOtherFields<T>
121where
122 T: TransactionBuilder7594,
123{
124 fn max_fee_per_blob_gas(&self) -> Option<u128> {
125 self.deref().max_fee_per_blob_gas()
126 }
127
128 fn set_max_fee_per_blob_gas(&mut self, max_fee_per_blob_gas: u128) {
129 self.deref_mut().set_max_fee_per_blob_gas(max_fee_per_blob_gas)
130 }
131
132 fn blob_sidecar_7594(&self) -> Option<&BlobTransactionSidecarEip7594> {
133 self.deref().blob_sidecar_7594()
134 }
135
136 fn set_blob_sidecar_7594(&mut self, sidecar: BlobTransactionSidecarEip7594) {
137 self.deref_mut().set_blob_sidecar_7594(sidecar)
138 }
139}