23
23
spl_token_client:: client:: {
24
24
ProgramClient , ProgramOfflineClient , ProgramRpcClient , ProgramRpcClientSendTransaction ,
25
25
} ,
26
- std:: { process:: exit, rc:: Rc , sync:: Arc } ,
26
+ std:: { process:: exit, rc:: Rc , str :: FromStr , sync:: Arc } ,
27
27
} ;
28
28
29
29
type SignersOf = Vec < ( Arc < dyn Signer > , Pubkey ) > ;
@@ -222,11 +222,17 @@ impl<'a> Config<'a> {
222
222
OutputFormat :: Display
223
223
} ) ;
224
224
225
- let nonce_account = pubkey_of_signer ( matches, NONCE_ARG . name , wallet_manager)
226
- . unwrap_or_else ( |e| {
227
- eprintln ! ( "error: {}" , e) ;
228
- exit ( 1 ) ;
229
- } ) ;
225
+ let nonce_account = match pubkey_of_signer ( matches, NONCE_ARG . name , wallet_manager) {
226
+ Ok ( account) => account,
227
+ Err ( e) => {
228
+ if e. is :: < clap:: parser:: MatchesError > ( ) {
229
+ None
230
+ } else {
231
+ eprintln ! ( "error: {}" , e) ;
232
+ exit ( 1 ) ;
233
+ }
234
+ }
235
+ } ;
230
236
let nonce_authority = if nonce_account. is_some ( ) {
231
237
let ( nonce_authority, _) = signer_from_path (
232
238
matches,
@@ -251,17 +257,27 @@ impl<'a> Config<'a> {
251
257
None
252
258
} ;
253
259
254
- let sign_only = matches. is_present ( SIGN_ONLY_ARG . name ) ;
255
- let dump_transaction_message = matches. is_present ( DUMP_TRANSACTION_MESSAGE . name ) ;
260
+ let sign_only = matches. try_contains_id ( SIGN_ONLY_ARG . name ) . unwrap_or ( false ) ;
261
+ let dump_transaction_message = matches
262
+ . try_contains_id ( DUMP_TRANSACTION_MESSAGE . name )
263
+ . unwrap_or ( false ) ;
264
+
265
+ let pubkey_from_matches = |name| {
266
+ matches
267
+ . try_get_one :: < String > ( name)
268
+ . ok ( )
269
+ . flatten ( )
270
+ . and_then ( |pubkey| Pubkey :: from_str ( pubkey) . ok ( ) )
271
+ } ;
256
272
257
273
let default_program_id = spl_token:: id ( ) ;
258
274
let ( program_id, restrict_to_program_id) =
259
- if let Some ( program_id) = value_of ( matches , "program_id" ) {
275
+ if let Some ( program_id) = pubkey_from_matches ( "program_id" ) {
260
276
( program_id, true )
261
277
} else if !sign_only {
262
- if let Some ( address) = value_of ( matches , "token" )
263
- . or_else ( || value_of ( matches , "account" ) )
264
- . or_else ( || value_of ( matches , "address" ) )
278
+ if let Some ( address) = pubkey_from_matches ( "token" )
279
+ . or_else ( || pubkey_from_matches ( "account" ) )
280
+ . or_else ( || pubkey_from_matches ( "address" ) )
265
281
{
266
282
(
267
283
rpc_client
@@ -278,7 +294,12 @@ impl<'a> Config<'a> {
278
294
( default_program_id, false )
279
295
} ;
280
296
281
- let nonce_blockhash = value_of ( matches, BLOCKHASH_ARG . name ) ;
297
+ let nonce_blockhash = matches
298
+ . try_get_one :: < Hash > ( BLOCKHASH_ARG . name )
299
+ . ok ( )
300
+ . flatten ( )
301
+ . copied ( ) ;
302
+
282
303
Self {
283
304
default_signer,
284
305
rpc_client,
0 commit comments