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

Commit 8dde48e

Browse files
committed
token-cli: display permanent delegate warning
1 parent f5133d6 commit 8dde48e

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

token/cli/src/main.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,11 +1763,23 @@ async fn command_address(
17631763
async fn command_display(config: &Config<'_>, address: Pubkey) -> CommandResult {
17641764
let account_data = config.get_account_checked(&address).await?;
17651765

1766-
let decimals = if let Some(mint_address) = get_token_account_mint(&account_data.data) {
1767-
Some(config.get_mint_info(&mint_address, None).await?.decimals)
1768-
} else {
1769-
None
1770-
};
1766+
let (decimals, has_permanent_delegate) =
1767+
if let Some(mint_address) = get_token_account_mint(&account_data.data) {
1768+
let mint_account = config.get_account_checked(&mint_address).await?;
1769+
let mint_state = StateWithExtensionsOwned::<Mint>::unpack(mint_account.data)
1770+
.map_err(|_| format!("Could not deserialize token mint {}", mint_address))?;
1771+
1772+
let has_permanent_delegate =
1773+
if let Ok(permanent_delegate) = mint_state.get_extension::<PermanentDelegate>() {
1774+
Option::<Pubkey>::from(permanent_delegate.delegate).is_some()
1775+
} else {
1776+
false
1777+
};
1778+
1779+
(Some(mint_state.base.decimals), has_permanent_delegate)
1780+
} else {
1781+
(None, false)
1782+
};
17711783

17721784
let token_data = parse_token(&account_data.data, decimals);
17731785

@@ -1786,6 +1798,7 @@ async fn command_display(config: &Config<'_>, address: Pubkey) -> CommandResult
17861798
program_id: config.program_id.to_string(),
17871799
is_associated: associated_address == address,
17881800
account,
1801+
has_permanent_delegate,
17891802
};
17901803

17911804
Ok(config.output_format.formatted_string(&cli_output))

token/cli/src/output.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ pub(crate) struct CliTokenAccount {
191191
pub(crate) is_associated: bool,
192192
#[serde(flatten)]
193193
pub(crate) account: UiTokenAccount,
194+
#[serde(skip_serializing)]
195+
pub(crate) has_permanent_delegate: bool,
194196
}
195197

196198
impl QuietDisplay for CliTokenAccount {}
@@ -257,6 +259,22 @@ impl fmt::Display for CliTokenAccount {
257259
writeln!(f, "* Please run `spl-token gc` to clean up Aux accounts")?;
258260
}
259261

262+
if self.has_permanent_delegate {
263+
writeln!(f)?;
264+
writeln!(
265+
f,
266+
"* {} ",
267+
style("This token has a permanent delegate!").bold()
268+
)?;
269+
writeln!(
270+
f,
271+
" This means the mint may withdraw {} funds from this account at {} time.",
272+
style("all").bold(),
273+
style("any").bold(),
274+
)?;
275+
writeln!(f, " If this was not adequately disclosed to you, you may be dealing with a malicious mint.")?;
276+
}
277+
260278
Ok(())
261279
}
262280
}

token/cli/src/sort.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ pub(crate) fn sort_and_parse_token_accounts(
7676
program_id: program_id.to_string(),
7777
account: ui_token_account,
7878
is_associated,
79+
has_permanent_delegate: false,
7980
};
8081

8182
let entry = cli_accounts.entry(btree_key);

0 commit comments

Comments
 (0)