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 ) > ;
@@ -224,11 +224,17 @@ impl<'a> Config<'a> {
224
224
OutputFormat :: Display
225
225
} ) ;
226
226
227
- let nonce_account = pubkey_of_signer ( matches, NONCE_ARG . name , wallet_manager)
228
- . unwrap_or_else ( |e| {
229
- eprintln ! ( "error: {}" , e) ;
230
- exit ( 1 ) ;
231
- } ) ;
227
+ let nonce_account = match pubkey_of_signer ( matches, NONCE_ARG . name , wallet_manager) {
228
+ Ok ( account) => account,
229
+ Err ( e) => {
230
+ if e. is :: < clap:: parser:: MatchesError > ( ) {
231
+ None
232
+ } else {
233
+ eprintln ! ( "error: {}" , e) ;
234
+ exit ( 1 ) ;
235
+ }
236
+ }
237
+ } ;
232
238
let nonce_authority = if nonce_account. is_some ( ) {
233
239
let ( nonce_authority, _) = signer_from_path (
234
240
matches,
@@ -253,17 +259,27 @@ impl<'a> Config<'a> {
253
259
None
254
260
} ;
255
261
256
- let sign_only = matches. is_present ( SIGN_ONLY_ARG . name ) ;
257
- let dump_transaction_message = matches. is_present ( DUMP_TRANSACTION_MESSAGE . name ) ;
262
+ let sign_only = matches. try_contains_id ( SIGN_ONLY_ARG . name ) . unwrap_or ( false ) ;
263
+ let dump_transaction_message = matches
264
+ . try_contains_id ( DUMP_TRANSACTION_MESSAGE . name )
265
+ . unwrap_or ( false ) ;
266
+
267
+ let pubkey_from_matches = |name| {
268
+ matches
269
+ . try_get_one :: < String > ( name)
270
+ . ok ( )
271
+ . flatten ( )
272
+ . and_then ( |pubkey| Pubkey :: from_str ( pubkey) . ok ( ) )
273
+ } ;
258
274
259
275
let default_program_id = spl_token:: id ( ) ;
260
276
let ( program_id, restrict_to_program_id) =
261
- if let Some ( program_id) = value_of ( matches , "program_id" ) {
277
+ if let Some ( program_id) = pubkey_from_matches ( "program_id" ) {
262
278
( program_id, true )
263
279
} else if !sign_only {
264
- if let Some ( address) = value_of ( matches , "token" )
265
- . or_else ( || value_of ( matches , "account" ) )
266
- . or_else ( || value_of ( matches , "address" ) )
280
+ if let Some ( address) = pubkey_from_matches ( "token" )
281
+ . or_else ( || pubkey_from_matches ( "account" ) )
282
+ . or_else ( || pubkey_from_matches ( "address" ) )
267
283
{
268
284
(
269
285
rpc_client
@@ -283,6 +299,12 @@ impl<'a> Config<'a> {
283
299
let nonce_blockhash = value_of ( matches, BLOCKHASH_ARG . name ) ;
284
300
let compute_unit_price = value_of ( matches, COMPUTE_UNIT_PRICE_ARG . name ) ;
285
301
let compute_unit_limit = value_of ( matches, COMPUTE_UNIT_LIMIT_ARG . name ) ;
302
+ let nonce_blockhash = matches
303
+ . try_get_one :: < Hash > ( BLOCKHASH_ARG . name )
304
+ . ok ( )
305
+ . flatten ( )
306
+ . copied ( ) ;
307
+
286
308
Self {
287
309
default_signer,
288
310
rpc_client,
0 commit comments