26
26
} ,
27
27
token:: ComputeUnitLimit ,
28
28
} ,
29
- std:: { process:: exit, rc:: Rc , sync:: Arc } ,
29
+ std:: { process:: exit, rc:: Rc , str :: FromStr , sync:: Arc } ,
30
30
} ;
31
31
32
32
type SignersOf = Vec < ( Arc < dyn Signer > , Pubkey ) > ;
@@ -227,11 +227,17 @@ impl<'a> Config<'a> {
227
227
OutputFormat :: Display
228
228
} ) ;
229
229
230
- let nonce_account = pubkey_of_signer ( matches, NONCE_ARG . name , wallet_manager)
231
- . unwrap_or_else ( |e| {
232
- eprintln ! ( "error: {}" , e) ;
233
- exit ( 1 ) ;
234
- } ) ;
230
+ let nonce_account = match pubkey_of_signer ( matches, NONCE_ARG . name , wallet_manager) {
231
+ Ok ( account) => account,
232
+ Err ( e) => {
233
+ if e. is :: < clap:: parser:: MatchesError > ( ) {
234
+ None
235
+ } else {
236
+ eprintln ! ( "error: {}" , e) ;
237
+ exit ( 1 ) ;
238
+ }
239
+ }
240
+ } ;
235
241
let nonce_authority = if nonce_account. is_some ( ) {
236
242
let ( nonce_authority, _) = signer_from_path (
237
243
matches,
@@ -256,18 +262,28 @@ impl<'a> Config<'a> {
256
262
None
257
263
} ;
258
264
259
- let sign_only = matches. is_present ( SIGN_ONLY_ARG . name ) ;
260
- let dump_transaction_message = matches. is_present ( DUMP_TRANSACTION_MESSAGE . name ) ;
265
+ let sign_only = matches. try_contains_id ( SIGN_ONLY_ARG . name ) . unwrap_or ( false ) ;
266
+ let dump_transaction_message = matches
267
+ . try_contains_id ( DUMP_TRANSACTION_MESSAGE . name )
268
+ . unwrap_or ( false ) ;
269
+
270
+ let pubkey_from_matches = |name| {
271
+ matches
272
+ . try_get_one :: < String > ( name)
273
+ . ok ( )
274
+ . flatten ( )
275
+ . and_then ( |pubkey| Pubkey :: from_str ( pubkey) . ok ( ) )
276
+ } ;
261
277
262
278
let default_program_id = spl_token:: id ( ) ;
263
279
let ( program_id, restrict_to_program_id) = if matches. is_present ( "program_2022" ) {
264
280
( spl_token_2022:: id ( ) , true )
265
- } else if let Some ( program_id) = value_of ( matches , "program_id" ) {
281
+ } else if let Some ( program_id) = pubkey_from_matches ( "program_id" ) {
266
282
( program_id, true )
267
283
} else if !sign_only {
268
- if let Some ( address) = value_of ( matches , "token" )
269
- . or_else ( || value_of ( matches , "account" ) )
270
- . or_else ( || value_of ( matches , "address" ) )
284
+ if let Some ( address) = pubkey_from_matches ( "token" )
285
+ . or_else ( || pubkey_from_matches ( "account" ) )
286
+ . or_else ( || pubkey_from_matches ( "address" ) )
271
287
{
272
288
(
273
289
rpc_client
@@ -290,7 +306,7 @@ impl<'a> Config<'a> {
290
306
&& !matches. is_present ( COMPUTE_UNIT_LIMIT_ARG . name )
291
307
{
292
308
clap:: Error :: with_description (
293
- & format ! (
309
+ format ! (
294
310
"Need to set `{}` if `{}` and `--{}` are set" ,
295
311
COMPUTE_UNIT_LIMIT_ARG . long, COMPUTE_UNIT_PRICE_ARG . long, BLOCKHASH_ARG . long,
296
312
) ,
@@ -299,7 +315,12 @@ impl<'a> Config<'a> {
299
315
. exit ( ) ;
300
316
}
301
317
302
- let nonce_blockhash = value_of ( matches, BLOCKHASH_ARG . name ) ;
318
+ let nonce_blockhash = matches
319
+ . try_get_one :: < Hash > ( BLOCKHASH_ARG . name )
320
+ . ok ( )
321
+ . flatten ( )
322
+ . copied ( ) ;
323
+
303
324
let compute_unit_price = value_of ( matches, COMPUTE_UNIT_PRICE_ARG . name ) ;
304
325
let compute_unit_limit = value_of ( matches, COMPUTE_UNIT_LIMIT_ARG . name )
305
326
. map ( ComputeUnitLimit :: Static )
@@ -310,6 +331,7 @@ impl<'a> Config<'a> {
310
331
ComputeUnitLimit :: Simulated
311
332
}
312
333
} ) ;
334
+
313
335
Self {
314
336
default_signer,
315
337
rpc_client,
0 commit comments