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

Commit 6b05f02

Browse files
committed
token-cli: implement --immutable for create-account
1 parent 697a9e3 commit 6b05f02

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

token/cli/src/main.rs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,14 +497,26 @@ async fn command_set_interest_rate(
497497
})
498498
}
499499

500+
// XXX OK wtf do i need to do for this shit
501+
// create account needs to go through the client
502+
// create associated vs create aux with ext... pretty simple?
503+
// then i want to impl --immutable, also simple
504+
// error if the mint is tokenkeg, rebuke if the token is associated
505+
// XXX umm then for default... i think its not possible to use this for ata?
506+
// test it out quicky
507+
508+
// XXX NEXT UP impl this shit for wrap. maybe put wrap/unwrap in the client?
509+
// and also reply to jon. i need to take a nap tho omg im dying
500510
async fn command_create_account(
501511
config: &Config<'_>,
502512
token_pubkey: Pubkey,
503513
owner: Pubkey,
504514
maybe_account: Option<Pubkey>,
515+
immutable_owner: bool,
505516
bulk_signers: Vec<Arc<dyn Signer>>,
506517
) -> CommandResult {
507518
let token = token_client_from_config(config, &token_pubkey);
519+
let mut extensions = vec![];
508520

509521
let (account, associated) = if let Some(account) = maybe_account {
510522
(account, false)
@@ -522,6 +534,23 @@ async fn command_create_account(
522534
}
523535
}
524536

537+
if immutable_owner {
538+
if config.program_id == spl_token::id() {
539+
return Err(format!(
540+
"Specified --immutable, but token program {} does not support the extension",
541+
config.program_id
542+
)
543+
.into());
544+
} else if associated {
545+
println_display(
546+
config,
547+
"Note: --immutable specified, but Token-2022 ATAs are always immutable".to_string(),
548+
);
549+
} else {
550+
extensions.push(ExtensionType::ImmutableOwner);
551+
}
552+
}
553+
525554
let res = if associated {
526555
token.create_associated_token_account(&owner).await
527556
} else {
@@ -531,7 +560,7 @@ async fn command_create_account(
531560
.unwrap_or_else(|| panic!("No signer provided for account {}", account));
532561

533562
token
534-
.create_auxiliary_token_account_with_extension_space(&**signer, &owner, vec![])
563+
.create_auxiliary_token_account_with_extension_space(&**signer, &owner, extensions)
535564
.await
536565
}?;
537566

@@ -2170,6 +2199,14 @@ fn app<'a, 'b>(
21702199
[default: associated token account for --owner]"
21712200
),
21722201
)
2202+
.arg(
2203+
Arg::with_name("immutable")
2204+
.long("immutable")
2205+
.takes_value(false)
2206+
.help(
2207+
"Lock the owner of this token account from ever being changed"
2208+
),
2209+
)
21732210
.arg(owner_address_arg())
21742211
.nonce_args(true)
21752212
)
@@ -3029,7 +3066,15 @@ async fn process_command<'a>(
30293066
);
30303067

30313068
let owner = config.pubkey_or_default(arg_matches, "owner", &mut wallet_manager);
3032-
command_create_account(config, token, owner, account, bulk_signers).await
3069+
command_create_account(
3070+
config,
3071+
token,
3072+
owner,
3073+
account,
3074+
arg_matches.is_present("immutable"),
3075+
bulk_signers,
3076+
)
3077+
.await
30333078
}
30343079
(CommandName::CreateMultisig, arg_matches) => {
30353080
let minimum_signers = value_of::<u8>(arg_matches, "minimum_signers").unwrap();

0 commit comments

Comments
 (0)