1
- use cast:: { Cast , TxBuilder } ;
1
+ use crate :: tx;
2
+ use cast:: Cast ;
2
3
use clap:: Parser ;
3
4
use ethers_core:: types:: NameOrAddress ;
4
5
use ethers_middleware:: SignerMiddleware ;
@@ -82,7 +83,7 @@ impl SendTxArgs {
82
83
let SendTxArgs {
83
84
eth,
84
85
to,
85
- sig,
86
+ mut sig,
86
87
cast_async,
87
88
mut args,
88
89
mut tx,
@@ -93,24 +94,20 @@ impl SendTxArgs {
93
94
unlocked,
94
95
} = self ;
95
96
96
- let mut sig = sig. unwrap_or_default ( ) ;
97
97
let code = if let Some ( SendTxSubcommands :: Create {
98
98
code,
99
99
sig : constructor_sig,
100
100
args : constructor_args,
101
101
} ) = command
102
102
{
103
- sig = constructor_sig. unwrap_or_default ( ) ;
103
+ sig = constructor_sig;
104
104
args = constructor_args;
105
105
Some ( code)
106
106
} else {
107
107
None
108
108
} ;
109
109
110
- // ensure mandatory fields are provided
111
- if code. is_none ( ) && to. is_none ( ) {
112
- eyre:: bail!( "Must specify a recipient address or contract code to deploy" ) ;
113
- }
110
+ tx:: validate_to_address ( & code, & to) ?;
114
111
115
112
let config = Config :: from ( & eth) ;
116
113
let provider = utils:: get_provider ( & config) ?;
@@ -155,7 +152,8 @@ impl SendTxArgs {
155
152
config. sender . to_ethers ( ) ,
156
153
to,
157
154
code,
158
- ( sig, args) ,
155
+ sig,
156
+ args,
159
157
tx,
160
158
chain,
161
159
api_key,
@@ -173,19 +171,7 @@ impl SendTxArgs {
173
171
let signer = eth. wallet . signer ( ) . await ?;
174
172
let from = signer. address ( ) ;
175
173
176
- // prevent misconfigured hwlib from sending a transaction that defies
177
- // user-specified --from
178
- if let Some ( specified_from) = eth. wallet . from {
179
- if specified_from != from. to_alloy ( ) {
180
- eyre:: bail!(
181
- "\
182
- The specified sender via CLI/env vars does not match the sender configured via
183
- the hardware wallet's HD Path.
184
- Please use the `--hd-path <PATH>` parameter to specify the BIP32 Path which
185
- corresponds to the sender, or let foundry automatically detect it by not specifying any sender address."
186
- )
187
- }
188
- }
174
+ tx:: validate_from_address ( eth. wallet . from , from. to_alloy ( ) ) ?;
189
175
190
176
if resend {
191
177
tx. nonce = Some ( provider. get_transaction_count ( from, None ) . await ?. to_alloy ( ) ) ;
@@ -198,7 +184,8 @@ corresponds to the sender, or let foundry automatically detect it by not specify
198
184
from,
199
185
to,
200
186
code,
201
- ( sig, args) ,
187
+ sig,
188
+ args,
202
189
tx,
203
190
chain,
204
191
api_key,
@@ -217,7 +204,8 @@ async fn cast_send<M: Middleware, F: Into<NameOrAddress>, T: Into<NameOrAddress>
217
204
from : F ,
218
205
to : Option < T > ,
219
206
code : Option < String > ,
220
- args : ( String , Vec < String > ) ,
207
+ sig : Option < String > ,
208
+ args : Vec < String > ,
221
209
tx : TransactionOpts ,
222
210
chain : Chain ,
223
211
etherscan_api_key : Option < String > ,
@@ -228,30 +216,8 @@ async fn cast_send<M: Middleware, F: Into<NameOrAddress>, T: Into<NameOrAddress>
228
216
where
229
217
M :: Error : ' static ,
230
218
{
231
- let ( sig, params) = args;
232
- let params = if !sig. is_empty ( ) { Some ( ( & sig[ ..] , params) ) } else { None } ;
233
- let mut builder = TxBuilder :: new ( & provider, from, to, chain, tx. legacy ) . await ?;
234
- builder
235
- . etherscan_api_key ( etherscan_api_key)
236
- . gas ( tx. gas_limit )
237
- . gas_price ( tx. gas_price )
238
- . priority_gas_price ( tx. priority_gas_price )
239
- . value ( tx. value )
240
- . nonce ( tx. nonce ) ;
241
-
242
- if let Some ( code) = code {
243
- let mut data = hex:: decode ( code) ?;
244
-
245
- if let Some ( ( sig, args) ) = params {
246
- let ( mut sigdata, _) = builder. create_args ( sig, args) . await ?;
247
- data. append ( & mut sigdata) ;
248
- }
249
-
250
- builder. set_data ( data) ;
251
- } else {
252
- builder. args ( params) . await ?;
253
- } ;
254
- let builder_output = builder. build ( ) ;
219
+ let builder_output =
220
+ tx:: build_tx ( & provider, from, to, code, sig, args, tx, chain, etherscan_api_key) . await ?;
255
221
256
222
let cast = Cast :: new ( provider) ;
257
223
0 commit comments