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,17 +262,27 @@ 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) =
264
- if let Some ( program_id) = value_of ( matches , "program_id" ) {
280
+ if let Some ( program_id) = pubkey_from_matches ( "program_id" ) {
265
281
( program_id, true )
266
282
} else if !sign_only {
267
- if let Some ( address) = value_of ( matches , "token" )
268
- . or_else ( || value_of ( matches , "account" ) )
269
- . or_else ( || value_of ( matches , "address" ) )
283
+ if let Some ( address) = pubkey_from_matches ( "token" )
284
+ . or_else ( || pubkey_from_matches ( "account" ) )
285
+ . or_else ( || pubkey_from_matches ( "address" ) )
270
286
{
271
287
(
272
288
rpc_client
@@ -289,7 +305,7 @@ impl<'a> Config<'a> {
289
305
&& !matches. is_present ( COMPUTE_UNIT_LIMIT_ARG . name )
290
306
{
291
307
clap:: Error :: with_description (
292
- & format ! (
308
+ format ! (
293
309
"Need to set `{}` if `{}` and `--{}` are set" ,
294
310
COMPUTE_UNIT_LIMIT_ARG . long, COMPUTE_UNIT_PRICE_ARG . long, BLOCKHASH_ARG . long,
295
311
) ,
@@ -298,7 +314,12 @@ impl<'a> Config<'a> {
298
314
. exit ( ) ;
299
315
}
300
316
301
- let nonce_blockhash = value_of ( matches, BLOCKHASH_ARG . name ) ;
317
+ let nonce_blockhash = matches
318
+ . try_get_one :: < Hash > ( BLOCKHASH_ARG . name )
319
+ . ok ( )
320
+ . flatten ( )
321
+ . copied ( ) ;
322
+
302
323
let compute_unit_price = value_of ( matches, COMPUTE_UNIT_PRICE_ARG . name ) ;
303
324
let compute_unit_limit = value_of ( matches, COMPUTE_UNIT_LIMIT_ARG . name )
304
325
. map ( ComputeUnitLimit :: Static )
@@ -309,6 +330,7 @@ impl<'a> Config<'a> {
309
330
ComputeUnitLimit :: Simulated
310
331
}
311
332
} ) ;
333
+
312
334
Self {
313
335
default_signer,
314
336
rpc_client,
0 commit comments