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

Commit 72ec14a

Browse files
Flesh out SetAuthority capabilities (#531)
1 parent e825b9d commit 72ec14a

File tree

1 file changed

+54
-13
lines changed

1 file changed

+54
-13
lines changed

token/cli/src/main.rs

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -172,20 +172,35 @@ fn command_create_account(
172172
Ok(Some(transaction))
173173
}
174174

175-
fn command_assign(config: &Config, account: Pubkey, new_owner: Pubkey) -> CommandResult {
175+
fn command_authorize(
176+
config: &Config,
177+
account: Pubkey,
178+
authority_type: AuthorityType,
179+
new_owner: Option<Pubkey>,
180+
) -> CommandResult {
181+
let auth_str = match authority_type {
182+
AuthorityType::MintTokens => "mint authority",
183+
AuthorityType::FreezeAccount => "freeze authority",
184+
AuthorityType::AccountOwner => "owner",
185+
AuthorityType::CloseAccount => "close authority",
186+
};
176187
println!(
177-
"Assigning {}\n Current owner: {}\n New owner: {}",
188+
"Updating {}\n Current {}: {}\n New {}: {}",
178189
account,
190+
auth_str,
179191
config.owner.pubkey(),
192+
auth_str,
180193
new_owner
194+
.map(|pubkey| pubkey.to_string())
195+
.unwrap_or_else(|| "disabled".to_string())
181196
);
182197

183198
let mut transaction = Transaction::new_with_payer(
184199
&[set_authority(
185200
&spl_token::id(),
186201
&account,
187-
Some(&new_owner),
188-
AuthorityType::AccountOwner,
202+
new_owner.as_ref(),
203+
authority_type,
189204
&config.owner.pubkey(),
190205
&[],
191206
)?],
@@ -731,8 +746,8 @@ fn main() {
731746
),
732747
)
733748
.subcommand(
734-
SubCommand::with_name("assign")
735-
.about("Assign a token or token account to a new owner")
749+
SubCommand::with_name("authorize")
750+
.about("Authorize a new signing keypair to a token or token account")
736751
.arg(
737752
Arg::with_name("address")
738753
.validator(is_pubkey_or_keypair)
@@ -743,13 +758,31 @@ fn main() {
743758
.help("The address of the token account"),
744759
)
745760
.arg(
746-
Arg::with_name("new_owner")
747-
.validator(is_pubkey_or_keypair)
748-
.value_name("OWNER_ADDRESS")
761+
Arg::with_name("authority_type")
762+
.value_name("AUTHORITY_TYPE")
749763
.takes_value(true)
764+
.possible_values(&["mint", "freeze", "owner", "close"])
750765
.index(2)
751766
.required(true)
752-
.help("The address of the new owner"),
767+
.help("The new authority type. \
768+
Token mints support `mint` and `freeze` authorities;\
769+
Token accounts support `owner` and `close` authorities."),
770+
)
771+
.arg(
772+
Arg::with_name("new_authority")
773+
.validator(is_pubkey_or_keypair)
774+
.value_name("AUTHORITY_ADDRESS")
775+
.takes_value(true)
776+
.index(3)
777+
.required_unless("disable")
778+
.help("The address of the new authority"),
779+
)
780+
.arg(
781+
Arg::with_name("disable")
782+
.long("disable")
783+
.takes_value(false)
784+
.conflicts_with("new_authority")
785+
.help("Disable mint, freeze, or close functionality by setting authority to None.")
753786
),
754787
)
755788
.subcommand(
@@ -1035,10 +1068,18 @@ fn main() {
10351068

10361069
command_create_account(&config, token, account)
10371070
}
1038-
("assign", Some(arg_matches)) => {
1071+
("authorize", Some(arg_matches)) => {
10391072
let address = pubkey_of(arg_matches, "address").unwrap();
1040-
let new_owner = pubkey_of(arg_matches, "new_owner").unwrap();
1041-
command_assign(&config, address, new_owner)
1073+
let authority_type = arg_matches.value_of("authority_type").unwrap();
1074+
let authority_type = match authority_type {
1075+
"mint" => AuthorityType::MintTokens,
1076+
"freeze" => AuthorityType::FreezeAccount,
1077+
"owner" => AuthorityType::AccountOwner,
1078+
"close" => AuthorityType::CloseAccount,
1079+
_ => unreachable!(),
1080+
};
1081+
let new_authority = pubkey_of(arg_matches, "new_authority");
1082+
command_authorize(&config, address, authority_type, new_authority)
10421083
}
10431084
("transfer", Some(arg_matches)) => {
10441085
let sender = pubkey_of(arg_matches, "sender").unwrap();

0 commit comments

Comments
 (0)