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

Commit 9888848

Browse files
token-cli: Add command authorize support for TokenGroup (#6165)
* Add command Authorize support for TokenGroup * Add TokenGroup CliAuthorityType * Add test for changing token update_authority * fixed err for wrong extension * fixed var names in test * Update token/cli/src/clap_app.rs Co-authored-by: Jon C <[email protected]> * Update token/cli/src/clap_app.rs Co-authored-by: Jon C <[email protected]> * Renamed instances of TokenGroup to Group for CliAuthorityType --------- Co-authored-by: Jon C <[email protected]>
1 parent 1a59767 commit 9888848

File tree

3 files changed

+55
-14
lines changed

3 files changed

+55
-14
lines changed

token/cli/src/clap_app.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ pub enum CliAuthorityType {
191191
Metadata,
192192
GroupPointer,
193193
GroupMemberPointer,
194+
Group,
194195
}
195196
impl TryFrom<CliAuthorityType> for AuthorityType {
196197
type Error = Error;
@@ -218,6 +219,9 @@ impl TryFrom<CliAuthorityType> for AuthorityType {
218219
}
219220
CliAuthorityType::GroupPointer => Ok(AuthorityType::GroupPointer),
220221
CliAuthorityType::GroupMemberPointer => Ok(AuthorityType::GroupMemberPointer),
222+
CliAuthorityType::Group => {
223+
Err("Group update authority does not map to a token authority type".into())
224+
}
221225
}
222226
}
223227
}

token/cli/src/command.rs

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ use {
7070
client::{ProgramRpcClientSendTransaction, RpcClientResponse},
7171
token::{ExtensionInitializationParams, Token},
7272
},
73+
spl_token_group_interface::state::TokenGroup,
7374
spl_token_metadata_interface::state::{Field, TokenMetadata},
7475
std::{collections::HashMap, fmt::Display, process::exit, rc::Rc, str::FromStr, sync::Arc},
7576
};
@@ -1016,6 +1017,13 @@ async fn command_authorize(
10161017
))
10171018
}
10181019
}
1020+
CliAuthorityType::Group => {
1021+
if let Ok(extension) = mint.get_extension::<TokenGroup>() {
1022+
Ok(Option::<Pubkey>::from(extension.update_authority))
1023+
} else {
1024+
Err(format!("Mint `{}` does not support token groups", account))
1025+
}
1026+
}
10191027
}?;
10201028

10211029
Ok((account, previous_authority))
@@ -1056,6 +1064,7 @@ async fn command_authorize(
10561064
| CliAuthorityType::MetadataPointer
10571065
| CliAuthorityType::Metadata
10581066
| CliAuthorityType::GroupPointer
1067+
| CliAuthorityType::Group
10591068
| CliAuthorityType::GroupMemberPointer => Err(format!(
10601069
"Authority type `{auth_str}` not supported for SPL Token accounts",
10611070
)),
@@ -1107,20 +1116,28 @@ async fn command_authorize(
11071116
),
11081117
);
11091118

1110-
let res = if let CliAuthorityType::Metadata = authority_type {
1111-
token
1112-
.token_metadata_update_authority(&authority, new_authority, &bulk_signers)
1113-
.await?
1114-
} else {
1115-
token
1116-
.set_authority(
1117-
&account,
1118-
&authority,
1119-
new_authority.as_ref(),
1120-
authority_type.try_into()?,
1121-
&bulk_signers,
1122-
)
1123-
.await?
1119+
let res = match authority_type {
1120+
CliAuthorityType::Metadata => {
1121+
token
1122+
.token_metadata_update_authority(&authority, new_authority, &bulk_signers)
1123+
.await?
1124+
}
1125+
CliAuthorityType::Group => {
1126+
token
1127+
.token_group_update_authority(&authority, new_authority, &bulk_signers)
1128+
.await?
1129+
}
1130+
_ => {
1131+
token
1132+
.set_authority(
1133+
&account,
1134+
&authority,
1135+
new_authority.as_ref(),
1136+
authority_type.try_into()?,
1137+
&bulk_signers,
1138+
)
1139+
.await?
1140+
}
11241141
};
11251142

11261143
let tx_return = finish_tx(config, &res, false).await?;

token/cli/tests/command.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3912,4 +3912,24 @@ async fn group(test_validator: &TestValidator, payer: &Keypair) {
39123912
assert_eq!(extension.group, mint);
39133913
assert_eq!(extension.mint, member_mint);
39143914
assert_eq!(u32::from(extension.member_number), 1);
3915+
3916+
// update authority
3917+
process_test_command(
3918+
&config,
3919+
payer,
3920+
&[
3921+
"spl-token",
3922+
CommandName::Authorize.into(),
3923+
&mint.to_string(),
3924+
"group",
3925+
&mint.to_string(),
3926+
],
3927+
)
3928+
.await
3929+
.unwrap();
3930+
3931+
let account = config.rpc_client.get_account(&mint).await.unwrap();
3932+
let mint_state = StateWithExtensionsOwned::<Mint>::unpack(account.data).unwrap();
3933+
let extension = mint_state.get_extension::<TokenGroup>().unwrap();
3934+
assert_eq!(extension.update_authority, Some(mint).try_into().unwrap());
39153935
}

0 commit comments

Comments
 (0)