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

Commit 7f851bd

Browse files
committed
token-cli: add --recipient-owner flag to mint
1 parent bc02c11 commit 7f851bd

File tree

1 file changed

+75
-8
lines changed

1 file changed

+75
-8
lines changed

token/cli/src/main.rs

Lines changed: 75 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2659,7 +2659,7 @@ fn app<'a, 'b>(
26592659
.arg(
26602660
Arg::with_name("recipient")
26612661
.validator(is_valid_pubkey)
2662-
.value_name("RECIPIENT_ADDRESS or RECIPIENT_TOKEN_ACCOUNT_ADDRESS")
2662+
.value_name("RECIPIENT_WALLET_ADDRESS or RECIPIENT_TOKEN_ACCOUNT_ADDRESS")
26632663
.takes_value(true)
26642664
.index(3)
26652665
.required(true)
@@ -2794,10 +2794,20 @@ fn app<'a, 'b>(
27942794
.validator(is_valid_pubkey)
27952795
.value_name("RECIPIENT_TOKEN_ACCOUNT_ADDRESS")
27962796
.takes_value(true)
2797+
.conflicts_with("recipient_owner")
27972798
.index(3)
27982799
.help("The token account address of recipient \
27992800
[default: associated token account for --mint-authority]"),
28002801
)
2802+
.arg(
2803+
Arg::with_name("recipient_owner")
2804+
.long("recipient-owner")
2805+
.validator(is_valid_pubkey)
2806+
.value_name("RECIPIENT_WALLET_ADDRESS")
2807+
.takes_value(true)
2808+
.conflicts_with("recipient")
2809+
.help("The owner of the recipient associated token account"),
2810+
)
28012811
.arg(
28022812
Arg::with_name("mint_authority")
28032813
.long("mint-authority")
@@ -3777,6 +3787,10 @@ async fn process_command<'a>(
37773787
pubkey_of_signer(arg_matches, "recipient", &mut wallet_manager).unwrap()
37783788
{
37793789
address
3790+
} else if let Some(address) =
3791+
pubkey_of_signer(arg_matches, "recipient_owner", &mut wallet_manager).unwrap()
3792+
{
3793+
get_associated_token_address_with_program_id(&address, &token, &config.program_id)
37803794
} else {
37813795
let owner = config.default_signer()?.pubkey();
37823796
config.associated_token_address_for_token_and_program(
@@ -4718,21 +4732,74 @@ mod tests {
47184732
let config = test_config_with_default_signer(&test_validator, &payer, program_id);
47194733
let token = create_token(&config, &payer).await;
47204734
let account = create_associated_account(&config, &payer, token).await;
4721-
let result = process_test_command(
4735+
let mut amount = 0;
4736+
4737+
// mint via implicit owner
4738+
process_test_command(
47224739
&config,
47234740
&payer,
47244741
&[
47254742
"spl-token",
47264743
CommandName::Mint.into(),
47274744
&token.to_string(),
4728-
"100",
4745+
"1",
47294746
],
47304747
)
4731-
.await;
4732-
result.unwrap();
4733-
let account = config.rpc_client.get_account(&account).await.unwrap();
4734-
let token_account = StateWithExtensionsOwned::<Account>::unpack(account.data).unwrap();
4735-
assert_eq!(token_account.base.amount, 100);
4748+
.await
4749+
.unwrap();
4750+
amount += 1;
4751+
4752+
let account_data = config.rpc_client.get_account(&account).await.unwrap();
4753+
let token_account =
4754+
StateWithExtensionsOwned::<Account>::unpack(account_data.data).unwrap();
4755+
assert_eq!(token_account.base.amount, amount);
4756+
assert_eq!(token_account.base.mint, token);
4757+
assert_eq!(token_account.base.owner, payer.pubkey());
4758+
4759+
// mint via explicit recipient
4760+
process_test_command(
4761+
&config,
4762+
&payer,
4763+
&[
4764+
"spl-token",
4765+
CommandName::Mint.into(),
4766+
&token.to_string(),
4767+
"1",
4768+
&account.to_string(),
4769+
],
4770+
)
4771+
.await
4772+
.unwrap();
4773+
amount += 1;
4774+
4775+
let account_data = config.rpc_client.get_account(&account).await.unwrap();
4776+
let token_account =
4777+
StateWithExtensionsOwned::<Account>::unpack(account_data.data).unwrap();
4778+
assert_eq!(token_account.base.amount, amount);
4779+
assert_eq!(token_account.base.mint, token);
4780+
assert_eq!(token_account.base.owner, payer.pubkey());
4781+
4782+
// mint via explicit owner
4783+
process_test_command(
4784+
&config,
4785+
&payer,
4786+
&[
4787+
"spl-token",
4788+
CommandName::Mint.into(),
4789+
&token.to_string(),
4790+
"1",
4791+
"--recipient-owner",
4792+
&payer.pubkey().to_string(),
4793+
],
4794+
)
4795+
.await
4796+
.unwrap();
4797+
amount += 1;
4798+
4799+
let account_data = config.rpc_client.get_account(&account).await.unwrap();
4800+
let token_account =
4801+
StateWithExtensionsOwned::<Account>::unpack(account_data.data).unwrap();
4802+
assert_eq!(token_account.base.amount, amount);
47364803
assert_eq!(token_account.base.mint, token);
47374804
assert_eq!(token_account.base.owner, payer.pubkey());
47384805
}

0 commit comments

Comments
 (0)