Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 186303a

Browse files
committed
token-cli: convert create_multisig to client
1 parent 37168db commit 186303a

File tree

2 files changed

+56
-56
lines changed

2 files changed

+56
-56
lines changed

token/cli/src/main.rs

Lines changed: 24 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use solana_sdk::{
3535
program_pack::Pack,
3636
pubkey::Pubkey,
3737
signature::{Keypair, Signer},
38-
system_instruction, system_program,
38+
system_program,
3939
transaction::Transaction,
4040
};
4141
use spl_associated_token_account::{
@@ -47,7 +47,7 @@ use spl_token_2022::{
4747
mint_close_authority::MintCloseAuthority, ExtensionType, StateWithExtensionsOwned,
4848
},
4949
instruction::*,
50-
state::{Account, Mint, Multisig},
50+
state::{Account, Mint},
5151
};
5252
use spl_token_client::{
5353
client::{ProgramRpcClientSendTransaction, RpcClientResponse},
@@ -390,7 +390,13 @@ async fn command_create_token(
390390
rate_bps: Option<i16>,
391391
bulk_signers: Vec<Arc<dyn Signer>>,
392392
) -> CommandResult {
393-
println_display(config, format!("Creating token {}", token_pubkey));
393+
println_display(
394+
config,
395+
format!(
396+
"Creating token {} under program {}",
397+
token_pubkey, config.program_id
398+
),
399+
);
394400

395401
let token = token_client_from_config(config, &token_pubkey);
396402

@@ -574,56 +580,33 @@ async fn command_create_account(
574580

575581
async fn command_create_multisig(
576582
config: &Config<'_>,
577-
multisig: Pubkey,
583+
multisig: Arc<dyn Signer>,
578584
minimum_signers: u8,
579585
multisig_members: Vec<Pubkey>,
580-
bulk_signers: BulkSigners,
581586
) -> CommandResult {
582587
println_display(
583588
config,
584589
format!(
585-
"Creating {}/{} multisig {}",
590+
"Creating {}/{} multisig {} under program {}",
586591
minimum_signers,
587592
multisig_members.len(),
588-
multisig
593+
multisig.pubkey(),
594+
config.program_id,
589595
),
590596
);
591597

592-
let minimum_balance_for_rent_exemption = if !config.sign_only {
593-
config
594-
.program_client
595-
.get_minimum_balance_for_rent_exemption(Multisig::LEN)
596-
.await?
597-
} else {
598-
0
599-
};
598+
// default is safe here because create_multisig doesnt use it
599+
let token = token_client_from_config(config, &Pubkey::default());
600600

601-
let instructions = vec![
602-
system_instruction::create_account(
603-
&config.fee_payer.pubkey(),
604-
&multisig,
605-
minimum_balance_for_rent_exemption,
606-
Multisig::LEN as u64,
607-
&config.program_id,
608-
),
609-
initialize_multisig(
610-
&config.program_id,
611-
&multisig,
612-
multisig_members.iter().collect::<Vec<_>>().as_slice(),
601+
let res = token
602+
.create_multisig(
603+
&*multisig,
604+
&multisig_members.iter().collect::<Vec<_>>(),
613605
minimum_signers,
614-
)?,
615-
];
606+
)
607+
.await?;
616608

617-
let tx_return = handle_tx(
618-
&CliSignerInfo {
619-
signers: bulk_signers,
620-
},
621-
config,
622-
false,
623-
minimum_balance_for_rent_exemption,
624-
instructions,
625-
)
626-
.await?;
609+
let tx_return = finish_tx(config, &res, false).await?;
627610
Ok(match tx_return {
628611
TransactionReturnData::CliSignature(signature) => {
629612
config.output_format.formatted_string(&signature)
@@ -3063,20 +3046,10 @@ async fn process_command<'a>(
30633046
exit(1);
30643047
}
30653048

3066-
let (signer, account) = get_signer(arg_matches, "address_keypair", &mut wallet_manager)
3049+
let (signer, _) = get_signer(arg_matches, "address_keypair", &mut wallet_manager)
30673050
.unwrap_or_else(new_throwaway_signer);
3068-
if !bulk_signers.contains(&signer) {
3069-
bulk_signers.push(signer);
3070-
}
30713051

3072-
command_create_multisig(
3073-
config,
3074-
account,
3075-
minimum_signers,
3076-
multisig_members,
3077-
bulk_signers,
3078-
)
3079-
.await
3052+
command_create_multisig(config, signer, minimum_signers, multisig_members).await
30803053
}
30813054
(CommandName::Authorize, arg_matches) => {
30823055
let address = pubkey_of_signer(arg_matches, "address", &mut wallet_manager)

token/client/src/token.rs

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use {
88
instruction::Instruction,
99
message::Message,
1010
program_error::ProgramError,
11+
program_pack::Pack,
1112
pubkey::Pubkey,
1213
signer::{signers::Signers, Signer, SignerError},
1314
system_instruction,
@@ -27,7 +28,7 @@ use {
2728
errors::ProofError,
2829
instruction::transfer_with_fee::FeeParameters,
2930
},
30-
state::{Account, AccountState, Mint},
31+
state::{Account, AccountState, Mint, Multisig},
3132
},
3233
std::{
3334
convert::TryInto,
@@ -479,6 +480,35 @@ where
479480
Ok(token)
480481
}
481482

483+
/// Create multisig
484+
pub async fn create_multisig(
485+
&self,
486+
account: &dyn Signer,
487+
multisig_members: &[&Pubkey],
488+
minimum_signers: u8,
489+
) -> TokenResult<T::Output> {
490+
let instructions = vec![
491+
system_instruction::create_account(
492+
&self.payer.pubkey(),
493+
&account.pubkey(),
494+
self.client
495+
.get_minimum_balance_for_rent_exemption(Multisig::LEN)
496+
.await
497+
.map_err(TokenError::Client)?,
498+
Multisig::LEN as u64,
499+
&self.program_id,
500+
),
501+
instruction::initialize_multisig(
502+
&self.program_id,
503+
&account.pubkey(),
504+
multisig_members,
505+
minimum_signers,
506+
)?,
507+
];
508+
509+
self.process_ixs(&instructions, &vec![account]).await
510+
}
511+
482512
/// Get the address for the associated token account.
483513
pub fn get_associated_token_address(&self, owner: &Pubkey) -> Pubkey {
484514
get_associated_token_address_with_program_id(owner, &self.pubkey, &self.program_id)
@@ -496,7 +526,6 @@ where
496526
&[],
497527
)
498528
.await
499-
.map_err(Into::into)
500529
}
501530

502531
/// Create and initialize a new token account.
@@ -551,9 +580,7 @@ where
551580
owner,
552581
)?);
553582

554-
self.process_ixs(&instructions, &vec![account])
555-
.await
556-
.map_err(Into::into)
583+
self.process_ixs(&instructions, &vec![account]).await
557584
}
558585

559586
/// Retrieve a raw account

0 commit comments

Comments
 (0)