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

Commit ca68578

Browse files
committed
Add memo support to transfer and burn commands
1 parent 8674173 commit ca68578

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

token/cli/src/main.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use solana_clap_utils::{
1414
is_valid_signer, normalize_to_url_if_moniker,
1515
},
1616
keypair::{signer_from_path, CliSignerInfo},
17+
memo::memo_arg,
1718
nonce::*,
1819
offline::{self, *},
1920
ArgConstant,
@@ -555,6 +556,7 @@ fn command_transfer(
555556
mint_decimals: Option<u8>,
556557
recipient_is_ata_owner: bool,
557558
use_unchecked_instruction: bool,
559+
memo: Option<String>,
558560
) -> CommandResult {
559561
let sender = if let Some(sender) = sender {
560562
sender
@@ -714,12 +716,16 @@ fn command_transfer(
714716
decimals,
715717
)?);
716718
}
719+
if let Some(text) = memo {
720+
instructions.push(spl_memo::build_memo(text.as_bytes(), &[&config.fee_payer]));
721+
}
717722
Ok(Some((
718723
minimum_balance_for_rent_exemption,
719724
vec![instructions],
720725
)))
721726
}
722727

728+
#[allow(clippy::too_many_arguments)]
723729
fn command_burn(
724730
config: &Config,
725731
source: Pubkey,
@@ -728,6 +734,7 @@ fn command_burn(
728734
mint_address: Option<Pubkey>,
729735
mint_decimals: Option<u8>,
730736
use_unchecked_instruction: bool,
737+
memo: Option<String>,
731738
) -> CommandResult {
732739
println_display(
733740
config,
@@ -737,7 +744,7 @@ fn command_burn(
737744
let (mint_pubkey, decimals) = resolve_mint_info(config, &source, mint_address, mint_decimals)?;
738745
let amount = spl_token::ui_amount_to_amount(ui_amount, decimals);
739746

740-
let instructions = if use_unchecked_instruction {
747+
let mut instructions = if use_unchecked_instruction {
741748
vec![burn(
742749
&spl_token::id(),
743750
&source,
@@ -757,6 +764,9 @@ fn command_burn(
757764
decimals,
758765
)?]
759766
};
767+
if let Some(text) = memo {
768+
instructions.push(spl_memo::build_memo(text.as_bytes(), &[&config.fee_payer]));
769+
}
760770
Ok(Some((0, vec![instructions])))
761771
}
762772

@@ -1458,13 +1468,8 @@ fn main() {
14581468
"Enable the mint authority to freeze associated token accounts."
14591469
),
14601470
)
1461-
.arg(
1462-
Arg::with_name("memo")
1463-
.long("memo")
1464-
.takes_value(true)
1465-
.help("Specify text that should be written as a memo when the token is created"),
1466-
)
14671471
.nonce_args(true)
1472+
.arg(memo_arg())
14681473
.offline_args(),
14691474
)
14701475
.subcommand(
@@ -1682,6 +1687,7 @@ fn main() {
16821687
.arg(multisig_signer_arg())
16831688
.arg(mint_decimals_arg())
16841689
.nonce_args(true)
1690+
.arg(memo_arg())
16851691
.offline_args_config(&SignOnlyNeedsMintDecimals{}),
16861692
)
16871693
.subcommand(
@@ -1715,6 +1721,7 @@ fn main() {
17151721
.arg(multisig_signer_arg())
17161722
.mint_args()
17171723
.nonce_args(true)
1724+
.arg(memo_arg())
17181725
.offline_args_config(&SignOnlyNeedsFullMintSpec{}),
17191726
)
17201727
.subcommand(
@@ -2360,6 +2367,7 @@ fn main() {
23602367
no_wait = matches.is_present("no_wait");
23612368
let recipient_is_ata_owner = matches.is_present("recipient_is_ata_owner");
23622369
let use_unchecked_instruction = matches.is_present("use_unchecked_instruction");
2370+
let memo = value_t!(arg_matches, "memo", String).ok();
23632371

23642372
command_transfer(
23652373
&config,
@@ -2373,6 +2381,7 @@ fn main() {
23732381
mint_decimals,
23742382
recipient_is_ata_owner,
23752383
use_unchecked_instruction,
2384+
memo,
23762385
)
23772386
}
23782387
("burn", Some(arg_matches)) => {
@@ -2389,6 +2398,7 @@ fn main() {
23892398
pubkey_of_signer(arg_matches, MINT_ADDRESS_ARG.name, &mut wallet_manager).unwrap();
23902399
let mint_decimals = value_of::<u8>(arg_matches, MINT_DECIMALS_ARG.name);
23912400
let use_unchecked_instruction = matches.is_present("use_unchecked_instruction");
2401+
let memo = value_t!(arg_matches, "memo", String).ok();
23922402
command_burn(
23932403
&config,
23942404
source,
@@ -2397,6 +2407,7 @@ fn main() {
23972407
mint_address,
23982408
mint_decimals,
23992409
use_unchecked_instruction,
2410+
memo,
24002411
)
24012412
}
24022413
("mint", Some(arg_matches)) => {

0 commit comments

Comments
 (0)