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

Commit 65b81cc

Browse files
authored
token-cli: Add command_update_group_max_size to token CLI (#6150)
* add `spl-token-group-interface` to `spl-token-cli` * add cli for updating token group max-size * Add test for `command_update_group_max_size` * Rewrote subcommand description * removed commented out code * changed update_authority validator to is_valid_signer * changed update_authority value_name to Signer * fixed subcommand about field
1 parent d40368b commit 65b81cc

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

token/cli/src/clap_app.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ pub enum CommandName {
108108
InitializeMetadata,
109109
UpdateMetadata,
110110
InitializeGroup,
111+
UpdateGroupMaxSize,
111112
UpdateConfidentialTransferSettings,
112113
ConfigureConfidentialTransferAccount,
113114
EnableConfidentialCredits,
@@ -1007,6 +1008,39 @@ pub fn app<'a, 'b>(
10071008
),
10081009
)
10091010
)
1011+
.subcommand(
1012+
SubCommand::with_name(CommandName::UpdateGroupMaxSize.into())
1013+
.about("Updates the maximum number of members for a group.")
1014+
.arg(
1015+
Arg::with_name("token")
1016+
.validator(is_valid_pubkey)
1017+
.value_name("TOKEN_MINT_ADDRESS")
1018+
.takes_value(true)
1019+
.required(true)
1020+
.index(1)
1021+
.help("The token address of the group account."),
1022+
)
1023+
.arg(
1024+
Arg::with_name("new_max_size")
1025+
.validator(is_amount)
1026+
.value_name("NEW_MAX_SIZE")
1027+
.takes_value(true)
1028+
.required(true)
1029+
.index(2)
1030+
.help("The number of members in the group."),
1031+
)
1032+
.arg(
1033+
Arg::with_name("update_authority")
1034+
.long("update-authority")
1035+
.value_name("SIGNER")
1036+
.validator(is_valid_signer)
1037+
.takes_value(true)
1038+
.help(
1039+
"Specify the update authority address. \
1040+
Defaults to the client keypair address."
1041+
),
1042+
)
1043+
)
10101044
.subcommand(
10111045
SubCommand::with_name(CommandName::CreateAccount.into())
10121046
.about("Create a new token account")

token/cli/src/command.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,32 @@ async fn command_initialize_group(
627627
}
628628
})
629629
}
630+
631+
#[allow(clippy::too_many_arguments)]
632+
async fn command_update_group_max_size(
633+
config: &Config<'_>,
634+
token_pubkey: Pubkey,
635+
update_authority: Pubkey,
636+
new_max_size: u32,
637+
bulk_signers: Vec<Arc<dyn Signer>>,
638+
) -> CommandResult {
639+
let token = token_client_from_config(config, &token_pubkey, None)?;
640+
641+
let res = token
642+
.token_group_update_max_size(&update_authority, new_max_size, &bulk_signers)
643+
.await?;
644+
645+
let tx_return = finish_tx(config, &res, false).await?;
646+
Ok(match tx_return {
647+
TransactionReturnData::CliSignature(signature) => {
648+
config.output_format.formatted_string(&signature)
649+
}
650+
TransactionReturnData::CliSignOnlyData(sign_only_data) => {
651+
config.output_format.formatted_string(&sign_only_data)
652+
}
653+
})
654+
}
655+
630656
async fn command_set_transfer_fee(
631657
config: &Config<'_>,
632658
token_pubkey: Pubkey,
@@ -3507,6 +3533,24 @@ pub async fn process_command<'a>(
35073533
)
35083534
.await
35093535
}
3536+
(CommandName::UpdateGroupMaxSize, arg_matches) => {
3537+
let token_pubkey = pubkey_of_signer(arg_matches, "token", &mut wallet_manager)
3538+
.unwrap()
3539+
.unwrap();
3540+
let new_max_size = value_t_or_exit!(arg_matches, "new_max_size", u32);
3541+
let (update_authority_signer, update_authority) =
3542+
config.signer_or_default(arg_matches, "update_authority", &mut wallet_manager);
3543+
let bulk_signers = vec![update_authority_signer];
3544+
3545+
command_update_group_max_size(
3546+
config,
3547+
token_pubkey,
3548+
update_authority,
3549+
new_max_size,
3550+
bulk_signers,
3551+
)
3552+
.await
3553+
}
35103554
(CommandName::CreateAccount, arg_matches) => {
35113555
let token = pubkey_of_signer(arg_matches, "token", &mut wallet_manager)
35123556
.unwrap()

token/cli/tests/command.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3842,4 +3842,27 @@ async fn group(test_validator: &TestValidator, payer: &Keypair) {
38423842
extension_pointer.group_address,
38433843
Some(mint).try_into().unwrap()
38443844
);
3845+
3846+
let new_max_size = 12;
3847+
3848+
// Update token-group max-size
3849+
process_test_command(
3850+
&config,
3851+
payer,
3852+
&[
3853+
"spl-token",
3854+
CommandName::UpdateGroupMaxSize.into(),
3855+
&mint.to_string(),
3856+
&new_max_size.to_string(),
3857+
],
3858+
)
3859+
.await
3860+
.unwrap();
3861+
3862+
let account = config.rpc_client.get_account(&mint).await.unwrap();
3863+
3864+
let updated_mint_state = StateWithExtensionsOwned::<Mint>::unpack(account.data).unwrap();
3865+
3866+
let updated_extension = updated_mint_state.get_extension::<TokenGroup>().unwrap();
3867+
assert_eq!(updated_extension.max_size, new_max_size.into());
38453868
}

0 commit comments

Comments
 (0)