alloy_network/any/
builder.rs1use crate::{
2 any::AnyNetwork, BuildResult, Network, NetworkWallet, TransactionBuilder,
3 TransactionBuilderError,
4};
5use alloy_primitives::{Address, Bytes, ChainId, TxKind, U256};
6use alloy_rpc_types_eth::{AccessList, TransactionInputKind, TransactionRequest};
7use alloy_serde::WithOtherFields;
8use std::ops::{Deref, DerefMut};
9
10impl TransactionBuilder<AnyNetwork> for WithOtherFields<TransactionRequest> {
11 fn chain_id(&self) -> Option<ChainId> {
12 self.deref().chain_id()
13 }
14
15 fn set_chain_id(&mut self, chain_id: ChainId) {
16 self.deref_mut().set_chain_id(chain_id)
17 }
18
19 fn nonce(&self) -> Option<u64> {
20 self.deref().nonce()
21 }
22
23 fn set_nonce(&mut self, nonce: u64) {
24 self.deref_mut().set_nonce(nonce)
25 }
26
27 fn input(&self) -> Option<&Bytes> {
28 self.deref().input()
29 }
30
31 fn set_input<T: Into<Bytes>>(&mut self, input: T) {
32 self.deref_mut().set_input(input);
33 }
34
35 fn set_input_kind<T: Into<Bytes>>(&mut self, input: T, kind: TransactionInputKind) {
36 self.deref_mut().set_input_kind(input, kind)
37 }
38
39 fn from(&self) -> Option<Address> {
40 self.deref().from()
41 }
42
43 fn set_from(&mut self, from: Address) {
44 self.deref_mut().set_from(from);
45 }
46
47 fn kind(&self) -> Option<TxKind> {
48 self.deref().kind()
49 }
50
51 fn clear_kind(&mut self) {
52 self.deref_mut().clear_kind()
53 }
54
55 fn set_kind(&mut self, kind: TxKind) {
56 self.deref_mut().set_kind(kind)
57 }
58
59 fn value(&self) -> Option<U256> {
60 self.deref().value()
61 }
62
63 fn set_value(&mut self, value: U256) {
64 self.deref_mut().set_value(value)
65 }
66
67 fn gas_price(&self) -> Option<u128> {
68 self.deref().gas_price()
69 }
70
71 fn set_gas_price(&mut self, gas_price: u128) {
72 self.deref_mut().set_gas_price(gas_price);
73 }
74
75 fn max_fee_per_gas(&self) -> Option<u128> {
76 self.deref().max_fee_per_gas()
77 }
78
79 fn set_max_fee_per_gas(&mut self, max_fee_per_gas: u128) {
80 self.deref_mut().set_max_fee_per_gas(max_fee_per_gas);
81 }
82
83 fn max_priority_fee_per_gas(&self) -> Option<u128> {
84 self.deref().max_priority_fee_per_gas()
85 }
86
87 fn set_max_priority_fee_per_gas(&mut self, max_priority_fee_per_gas: u128) {
88 self.deref_mut().set_max_priority_fee_per_gas(max_priority_fee_per_gas);
89 }
90
91 fn gas_limit(&self) -> Option<u64> {
92 self.deref().gas_limit()
93 }
94
95 fn set_gas_limit(&mut self, gas_limit: u64) {
96 self.deref_mut().set_gas_limit(gas_limit);
97 }
98
99 fn access_list(&self) -> Option<&AccessList> {
101 self.deref().access_list()
102 }
103
104 fn set_access_list(&mut self, access_list: AccessList) {
106 self.deref_mut().set_access_list(access_list)
107 }
108
109 fn complete_type(&self, ty: <AnyNetwork as Network>::TxType) -> Result<(), Vec<&'static str>> {
110 self.deref().complete_type(ty.try_into().map_err(|_| vec!["supported tx type"])?)
111 }
112
113 fn can_submit(&self) -> bool {
114 self.deref().can_submit()
115 }
116
117 fn can_build(&self) -> bool {
118 self.deref().can_build()
119 }
120
121 #[doc(alias = "output_transaction_type")]
122 fn output_tx_type(&self) -> <AnyNetwork as Network>::TxType {
123 self.deref().output_tx_type().into()
124 }
125
126 #[doc(alias = "output_transaction_type_checked")]
127 fn output_tx_type_checked(&self) -> Option<<AnyNetwork as Network>::TxType> {
128 self.deref().output_tx_type_checked().map(Into::into)
129 }
130
131 fn prep_for_submission(&mut self) {
132 self.deref_mut().prep_for_submission()
133 }
134
135 fn build_unsigned(self) -> BuildResult<<AnyNetwork as Network>::UnsignedTx, AnyNetwork> {
136 if let Err((tx_type, missing)) = self.missing_keys() {
137 return Err(TransactionBuilderError::InvalidTransactionRequest(
138 tx_type.into(),
139 missing,
140 )
141 .into_unbuilt(self));
142 }
143 Ok(self.inner.build_typed_tx().expect("checked by missing_keys").into())
144 }
145 async fn build<W: NetworkWallet<AnyNetwork>>(
146 self,
147 wallet: &W,
148 ) -> Result<<AnyNetwork as Network>::TxEnvelope, TransactionBuilderError<AnyNetwork>> {
149 Ok(wallet.sign_request(self).await?)
150 }
151}