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

Commit f8d82e5

Browse files
committed
token-cli: safer behavior for transfer decimals
1 parent 7b86fc9 commit f8d82e5

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

token/cli/src/main.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -782,16 +782,23 @@ async fn command_transfer(
782782
let token = token_client_from_config(config, &token_pubkey);
783783
let mint_info = config.get_mint_info(&token_pubkey, mint_decimals).await?;
784784

785-
// decimals arg, which determines whether transfer or transfer_checked instruction is used
786-
// the logic here is tricky because "do what we are told" and "do the right thing" are at odds
785+
// if the user got the decimals wrong, they may well have calculated the transfer amount wrong
786+
if !config.sign_only && mint_decimals.is_some() && mint_decimals != Some(mint_info.decimals) {
787+
return Err(format!(
788+
"Decimals {} was provided, but actual value is {}",
789+
mint_decimals.unwrap(),
790+
mint_info.decimals
791+
)
792+
.into());
793+
}
794+
795+
// decimals determines whether transfer_checked is used or not
787796
let decimals = if use_unchecked_instruction {
788797
None
789-
} else if !config.sign_only {
790-
Some(mint_info.decimals)
791798
} else if mint_decimals.is_some() {
792799
mint_decimals
793800
} else {
794-
return Err("Decimals must be specified with --mint-decimals in offline mode".into());
801+
Some(mint_info.decimals)
795802
};
796803

797804
// pubkey of the actual account we are sending from

0 commit comments

Comments
 (0)