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, 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 from(&self) -> Option<Address> {
36 self.deref().from()
37 }
38
39 fn set_from(&mut self, from: Address) {
40 self.deref_mut().set_from(from);
41 }
42
43 fn kind(&self) -> Option<TxKind> {
44 self.deref().kind()
45 }
46
47 fn clear_kind(&mut self) {
48 self.deref_mut().clear_kind()
49 }
50
51 fn set_kind(&mut self, kind: TxKind) {
52 self.deref_mut().set_kind(kind)
53 }
54
55 fn value(&self) -> Option<U256> {
56 self.deref().value()
57 }
58
59 fn set_value(&mut self, value: U256) {
60 self.deref_mut().set_value(value)
61 }
62
63 fn gas_price(&self) -> Option<u128> {
64 self.deref().gas_price()
65 }
66
67 fn set_gas_price(&mut self, gas_price: u128) {
68 self.deref_mut().set_gas_price(gas_price);
69 }
70
71 fn max_fee_per_gas(&self) -> Option<u128> {
72 self.deref().max_fee_per_gas()
73 }
74
75 fn set_max_fee_per_gas(&mut self, max_fee_per_gas: u128) {
76 self.deref_mut().set_max_fee_per_gas(max_fee_per_gas);
77 }
78
79 fn max_priority_fee_per_gas(&self) -> Option<u128> {
80 self.deref().max_priority_fee_per_gas()
81 }
82
83 fn set_max_priority_fee_per_gas(&mut self, max_priority_fee_per_gas: u128) {
84 self.deref_mut().set_max_priority_fee_per_gas(max_priority_fee_per_gas);
85 }
86
87 fn gas_limit(&self) -> Option<u64> {
88 self.deref().gas_limit()
89 }
90
91 fn set_gas_limit(&mut self, gas_limit: u64) {
92 self.deref_mut().set_gas_limit(gas_limit);
93 }
94
95 fn access_list(&self) -> Option<&AccessList> {
97 self.deref().access_list()
98 }
99
100 fn set_access_list(&mut self, access_list: AccessList) {
102 self.deref_mut().set_access_list(access_list)
103 }
104
105 fn complete_type(&self, ty: <AnyNetwork as Network>::TxType) -> Result<(), Vec<&'static str>> {
106 self.deref().complete_type(ty.try_into().map_err(|_| vec!["supported tx type"])?)
107 }
108
109 fn can_submit(&self) -> bool {
110 self.deref().can_submit()
111 }
112
113 fn can_build(&self) -> bool {
114 self.deref().can_build()
115 }
116
117 #[doc(alias = "output_transaction_type")]
118 fn output_tx_type(&self) -> <AnyNetwork as Network>::TxType {
119 self.deref().output_tx_type().into()
120 }
121
122 #[doc(alias = "output_transaction_type_checked")]
123 fn output_tx_type_checked(&self) -> Option<<AnyNetwork as Network>::TxType> {
124 self.deref().output_tx_type_checked().map(Into::into)
125 }
126
127 fn prep_for_submission(&mut self) {
128 self.deref_mut().prep_for_submission()
129 }
130
131 fn build_unsigned(self) -> BuildResult<<AnyNetwork as Network>::UnsignedTx, AnyNetwork> {
132 if let Err((tx_type, missing)) = self.missing_keys() {
133 return Err(TransactionBuilderError::InvalidTransactionRequest(
134 tx_type.into(),
135 missing,
136 )
137 .into_unbuilt(self));
138 }
139 Ok(self.inner.build_typed_tx().expect("checked by missing_keys").into())
140 }
141
142 async fn build<W: NetworkWallet<AnyNetwork>>(
143 self,
144 wallet: &W,
145 ) -> Result<<AnyNetwork as Network>::TxEnvelope, TransactionBuilderError<AnyNetwork>> {
146 Ok(wallet.sign_request(self).await?)
147 }
148}