@@ -499,77 +499,43 @@ async fn command_set_interest_rate(
499
499
500
500
async fn command_create_account (
501
501
config : & Config < ' _ > ,
502
- token : Pubkey ,
502
+ token_pubkey : Pubkey ,
503
503
owner : Pubkey ,
504
504
maybe_account : Option < Pubkey > ,
505
505
bulk_signers : Vec < Arc < dyn Signer > > ,
506
506
) -> CommandResult {
507
- let minimum_balance_for_rent_exemption = if !config. sign_only {
508
- config
509
- . program_client
510
- . get_minimum_balance_for_rent_exemption ( Account :: LEN )
511
- . await ?
512
- } else {
513
- 0
514
- } ;
507
+ let token = token_client_from_config ( config, & token_pubkey) ;
515
508
516
- let mint_info = config. get_mint_info ( & token, None ) . await ?;
517
- let ( account, system_account_ok, instructions) = if let Some ( account) = maybe_account {
518
- println_display ( config, format ! ( "Creating account {}" , account) ) ;
519
- (
520
- account,
521
- false ,
522
- vec ! [
523
- system_instruction:: create_account(
524
- & config. fee_payer. pubkey( ) ,
525
- & account,
526
- minimum_balance_for_rent_exemption,
527
- Account :: LEN as u64 ,
528
- & mint_info. program_id,
529
- ) ,
530
- initialize_account( & mint_info. program_id, & account, & token, & owner) ?,
531
- ] ,
532
- )
509
+ let ( account, associated) = if let Some ( account) = maybe_account {
510
+ ( account, false )
533
511
} else {
534
- let account =
535
- get_associated_token_address_with_program_id ( & owner, & token, & mint_info. program_id ) ;
536
- println_display ( config, format ! ( "Creating account {}" , account) ) ;
537
- (
538
- account,
539
- true ,
540
- vec ! [ create_associated_token_account(
541
- & config. fee_payer. pubkey( ) ,
542
- & owner,
543
- & token,
544
- & mint_info. program_id,
545
- ) ] ,
546
- )
512
+ ( token. get_associated_token_address ( & owner) , true )
547
513
} ;
548
514
515
+ println_display ( config, format ! ( "Creating account {}" , account) ) ;
516
+
549
517
if !config. sign_only {
550
- if let Some ( account_data) = config
551
- . rpc_client
552
- . get_account_with_commitment ( & account, config. rpc_client . commitment ( ) )
553
- . await ?
554
- . value
555
- {
556
- if !( account_data. owner == system_program:: id ( ) && system_account_ok) {
518
+ if let Some ( account_data) = config. program_client . get_account ( account) . await ? {
519
+ if account_data. owner != system_program:: id ( ) || !associated {
557
520
return Err ( format ! ( "Error: Account already exists: {}" , account) . into ( ) ) ;
558
521
}
559
522
}
560
523
}
561
524
562
- let tx_return = handle_tx (
563
- & CliSignerInfo {
564
- signers : bulk_signers,
565
- } ,
566
- config,
567
- false ,
568
- minimum_balance_for_rent_exemption,
569
- instructions,
570
- )
571
- . await ?;
525
+ let res = if associated {
526
+ token. create_associated_token_account ( & owner) . await
527
+ } else {
528
+ let signer = bulk_signers
529
+ . iter ( )
530
+ . find ( |signer| signer. pubkey ( ) == account)
531
+ . unwrap_or_else ( || panic ! ( "No signer provided for account {}" , account) ) ;
572
532
533
+ token
534
+ . create_auxiliary_token_account_with_extension_space ( & * * signer, & owner, vec ! [ ] )
535
+ . await
536
+ } ?;
537
+
538
+ let tx_return = finish_tx ( config, & res, false ) . await ?;
573
539
Ok ( match tx_return {
574
540
TransactionReturnData :: CliSignature ( signature) => {
575
541
config. output_format . formatted_string ( & signature)
0 commit comments