@@ -2,14 +2,14 @@ pub mod meta;
2
2
3
3
use {
4
4
crate :: meta:: parse_transfer_hook_account_arg,
5
- clap:: { crate_description, crate_name, crate_version, Arg , Command } ,
5
+ clap:: { crate_description, crate_name, crate_version, Arg , ArgAction , Command } ,
6
6
solana_clap_v3_utils:: {
7
7
input_parsers:: {
8
8
parse_url_or_moniker,
9
9
signer:: { SignerSource , SignerSourceParserBuilder } ,
10
10
} ,
11
11
input_validators:: normalize_to_url_if_moniker,
12
- keypair:: { pubkey_from_source , DefaultSigner } ,
12
+ keypair:: signer_from_path ,
13
13
} ,
14
14
solana_client:: nonblocking:: rpc_client:: RpcClient ,
15
15
solana_remote_wallet:: remote_wallet:: RemoteWalletManager ,
@@ -233,7 +233,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
233
233
Command :: new ( "create-extra-metas" )
234
234
. about ( "Create the extra account metas account for a transfer hook program" )
235
235
. arg (
236
- Arg :: with_name ( "program_id" )
236
+ Arg :: new ( "program_id" )
237
237
. value_parser ( SignerSourceParserBuilder :: default ( ) . allow_pubkey ( ) . allow_file_path ( ) . build ( ) )
238
238
. value_name ( "TRANSFER_HOOK_PROGRAM" )
239
239
. takes_value ( true )
@@ -242,7 +242,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
242
242
. help ( "The transfer hook program id" ) ,
243
243
)
244
244
. arg (
245
- Arg :: with_name ( "token" )
245
+ Arg :: new ( "token" )
246
246
. value_parser ( SignerSourceParserBuilder :: default ( ) . allow_pubkey ( ) . allow_file_path ( ) . build ( ) )
247
247
. value_name ( "TOKEN_MINT_ADDRESS" )
248
248
. takes_value ( true )
@@ -251,11 +251,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
251
251
. help ( "The token mint address for the transfer hook" ) ,
252
252
)
253
253
. arg (
254
- Arg :: with_name ( "transfer_hook_accounts" )
254
+ Arg :: new ( "transfer_hook_accounts" )
255
255
. value_parser ( parse_transfer_hook_account_arg)
256
256
. value_name ( "TRANSFER_HOOK_ACCOUNTS" )
257
257
. takes_value ( true )
258
- . multiple ( true )
258
+ . action ( ArgAction :: Append )
259
259
. min_values ( 0 )
260
260
. index ( 3 )
261
261
. help ( r#"Additional account(s) required for a transfer hook and their respective configurations, whether they are a fixed address or PDA.
@@ -317,7 +317,7 @@ extraMetas:
317
317
Command :: new ( "update-extra-metas" )
318
318
. about ( "Update the extra account metas account for a transfer hook program" )
319
319
. arg (
320
- Arg :: with_name ( "program_id" )
320
+ Arg :: new ( "program_id" )
321
321
. value_parser ( SignerSourceParserBuilder :: default ( ) . allow_pubkey ( ) . allow_file_path ( ) . build ( ) )
322
322
. value_name ( "TRANSFER_HOOK_PROGRAM" )
323
323
. takes_value ( true )
@@ -326,7 +326,7 @@ extraMetas:
326
326
. help ( "The transfer hook program id" ) ,
327
327
)
328
328
. arg (
329
- Arg :: with_name ( "token" )
329
+ Arg :: new ( "token" )
330
330
. value_parser ( SignerSourceParserBuilder :: default ( ) . allow_pubkey ( ) . allow_file_path ( ) . build ( ) )
331
331
. value_name ( "TOKEN_MINT_ADDRESS" )
332
332
. takes_value ( true )
@@ -335,11 +335,11 @@ extraMetas:
335
335
. help ( "The token mint address for the transfer hook" ) ,
336
336
)
337
337
. arg (
338
- Arg :: with_name ( "transfer_hook_accounts" )
338
+ Arg :: new ( "transfer_hook_accounts" )
339
339
. value_parser ( parse_transfer_hook_account_arg)
340
340
. value_name ( "TRANSFER_HOOK_ACCOUNTS" )
341
341
. takes_value ( true )
342
- . multiple ( true )
342
+ . action ( ArgAction :: Append )
343
343
. min_values ( 0 )
344
344
. index ( 3 )
345
345
. help ( r#"Additional account(s) required for a transfer hook and their respective configurations, whether they are a fixed address or PDA.
@@ -401,37 +401,37 @@ extraMetas:
401
401
let ( command, matches) = app_matches. subcommand ( ) . unwrap ( ) ;
402
402
let mut wallet_manager: Option < Rc < RemoteWalletManager > > = None ;
403
403
404
- let cli_config = if let Some ( config_file) = matches. value_of ( "config_file" ) {
404
+ let cli_config = if let Some ( config_file) = matches. get_one :: < String > ( "config_file" ) {
405
405
solana_cli_config:: Config :: load ( config_file) . unwrap_or_default ( )
406
406
} else {
407
407
solana_cli_config:: Config :: default ( )
408
408
} ;
409
409
410
410
let config = {
411
- let default_signer = DefaultSigner :: new (
412
- "fee_payer" ,
413
- matches
414
- . value_of ( "fee_payer" )
415
- . map ( |s| s. to_string ( ) )
416
- . unwrap_or_else ( || cli_config. keypair_path . clone ( ) ) ,
417
- ) ;
411
+ let default_signer = if let Some ( ( signer, _) ) =
412
+ SignerSource :: try_get_signer ( matches, "fee_payer" , & mut wallet_manager) ?
413
+ {
414
+ signer
415
+ } else {
416
+ signer_from_path (
417
+ matches,
418
+ & cli_config. keypair_path ,
419
+ "fee_payer" ,
420
+ & mut wallet_manager,
421
+ ) ?
422
+ } ;
418
423
419
424
let json_rpc_url = normalize_to_url_if_moniker (
420
425
matches
421
- . value_of ( "json_rpc_url" )
426
+ . get_one :: < String > ( "json_rpc_url" )
422
427
. unwrap_or ( & cli_config. json_rpc_url ) ,
423
428
) ;
424
429
425
430
Config {
426
431
commitment_config : CommitmentConfig :: confirmed ( ) ,
427
- default_signer : default_signer
428
- . signer_from_path ( matches, & mut wallet_manager)
429
- . unwrap_or_else ( |err| {
430
- eprintln ! ( "error: {err}" ) ;
431
- exit ( 1 ) ;
432
- } ) ,
432
+ default_signer,
433
433
json_rpc_url,
434
- verbose : matches. is_present ( "verbose" ) ,
434
+ verbose : matches. try_contains_id ( "verbose" ) ? ,
435
435
}
436
436
} ;
437
437
solana_logger:: setup_with_default ( "solana=info" ) ;
@@ -444,39 +444,30 @@ extraMetas:
444
444
445
445
match ( command, matches) {
446
446
( "create-extra-metas" , arg_matches) => {
447
- let program_id_source = arg_matches
448
- . try_get_one :: < SignerSource > ( "program_id" ) ?
449
- . unwrap ( ) ;
450
- let program_id = pubkey_from_source (
451
- arg_matches,
452
- program_id_source,
453
- "program_id" ,
454
- & mut wallet_manager,
455
- )
456
- . unwrap ( ) ;
457
-
458
- let token_source = arg_matches. try_get_one :: < SignerSource > ( "token" ) ?. unwrap ( ) ;
459
- let token = pubkey_from_source ( arg_matches, token_source, "token" , & mut wallet_manager)
460
- . unwrap ( ) ;
447
+ let program_id =
448
+ SignerSource :: try_get_pubkey ( arg_matches, "program_id" , & mut wallet_manager) ?
449
+ . unwrap ( ) ;
450
+ let token =
451
+ SignerSource :: try_get_pubkey ( arg_matches, "token" , & mut wallet_manager) ?. unwrap ( ) ;
461
452
462
453
let transfer_hook_accounts = arg_matches
463
454
. get_many :: < Vec < ExtraAccountMeta > > ( "transfer_hook_accounts" )
464
455
. unwrap_or_default ( )
465
456
. flatten ( )
466
457
. cloned ( )
467
458
. collect ( ) ;
468
- let mint_authority = DefaultSigner :: new (
469
- "mint_authority" ,
470
- matches
471
- . value_of ( "mint_authority" )
472
- . map ( |s| s . to_string ( ) )
473
- . unwrap_or_else ( || cli_config . keypair_path . clone ( ) ) ,
474
- )
475
- . signer_from_path ( matches , & mut wallet_manager )
476
- . unwrap_or_else ( |err| {
477
- eprintln ! ( "error: {err}" ) ;
478
- exit ( 1 ) ;
479
- } ) ;
459
+ let mint_authority = if let Some ( ( signer , _ ) ) =
460
+ SignerSource :: try_get_signer ( matches , "mint_authority" , & mut wallet_manager ) ?
461
+ {
462
+ signer
463
+ } else {
464
+ signer_from_path (
465
+ matches ,
466
+ & cli_config . keypair_path ,
467
+ "mint_authority" ,
468
+ & mut wallet_manager ,
469
+ ) ?
470
+ } ;
480
471
let signature = process_create_extra_account_metas (
481
472
& rpc_client,
482
473
& program_id,
@@ -493,39 +484,30 @@ extraMetas:
493
484
println ! ( "Signature: {signature}" ) ;
494
485
}
495
486
( "update-extra-metas" , arg_matches) => {
496
- let program_id_source = arg_matches
497
- . try_get_one :: < SignerSource > ( "program_id" ) ?
498
- . unwrap ( ) ;
499
- let program_id = pubkey_from_source (
500
- arg_matches,
501
- program_id_source,
502
- "program_id" ,
503
- & mut wallet_manager,
504
- )
505
- . unwrap ( ) ;
506
-
507
- let token_source = arg_matches. try_get_one :: < SignerSource > ( "token" ) ?. unwrap ( ) ;
508
- let token = pubkey_from_source ( arg_matches, token_source, "token" , & mut wallet_manager)
509
- . unwrap ( ) ;
487
+ let program_id =
488
+ SignerSource :: try_get_pubkey ( arg_matches, "program_id" , & mut wallet_manager) ?
489
+ . unwrap ( ) ;
490
+ let token =
491
+ SignerSource :: try_get_pubkey ( arg_matches, "token" , & mut wallet_manager) ?. unwrap ( ) ;
510
492
511
493
let transfer_hook_accounts = arg_matches
512
494
. get_many :: < Vec < ExtraAccountMeta > > ( "transfer_hook_accounts" )
513
495
. unwrap_or_default ( )
514
496
. flatten ( )
515
497
. cloned ( )
516
498
. collect ( ) ;
517
- let mint_authority = DefaultSigner :: new (
518
- "mint_authority" ,
519
- matches
520
- . value_of ( "mint_authority" )
521
- . map ( |s| s . to_string ( ) )
522
- . unwrap_or_else ( || cli_config . keypair_path . clone ( ) ) ,
523
- )
524
- . signer_from_path ( matches , & mut wallet_manager )
525
- . unwrap_or_else ( |err| {
526
- eprintln ! ( "error: {err}" ) ;
527
- exit ( 1 ) ;
528
- } ) ;
499
+ let mint_authority = if let Some ( ( signer , _ ) ) =
500
+ SignerSource :: try_get_signer ( matches , "mint_authority" , & mut wallet_manager ) ?
501
+ {
502
+ signer
503
+ } else {
504
+ signer_from_path (
505
+ matches ,
506
+ & cli_config . keypair_path ,
507
+ "mint_authority" ,
508
+ & mut wallet_manager ,
509
+ ) ?
510
+ } ;
529
511
let signature = process_update_extra_account_metas (
530
512
& rpc_client,
531
513
& program_id,
0 commit comments