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

Commit 48e6acb

Browse files
authored
token-cli: Support base token-2022 (without extensions) (#3071)
1 parent d4bd86e commit 48e6acb

File tree

6 files changed

+308
-215
lines changed

6 files changed

+308
-215
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

token/cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ solana-remote-wallet = "=1.10.29"
2828
solana-sdk = "=1.10.29"
2929
solana-transaction-status = "=1.10.29"
3030
spl-token = { version = "3.3", path="../program", features = [ "no-entrypoint" ] }
31+
spl-token-2022 = { version = "0.4", path="../program-2022", features = [ "no-entrypoint" ] }
3132
spl-associated-token-account = { version = "1.0.5", path="../../associated-token-account/program", features = [ "no-entrypoint" ] }
3233
spl-memo = { version = "3.0.1", path="../../memo/program", features = ["no-entrypoint"] }
3334
strum = "0.24"

token/cli/src/bench.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ use {
1616
system_instruction,
1717
},
1818
spl_associated_token_account::*,
19-
spl_token::{
19+
spl_token_2022::{
20+
extension::StateWithExtensions,
2021
instruction,
2122
state::{Account, Mint},
2223
},
@@ -265,7 +266,7 @@ async fn get_valid_mint_program_id(
265266
.await
266267
.map_err(|err| format!("Token mint {} does not exist: {}", token, err))?;
267268

268-
Mint::unpack(&mint_account.data)
269+
StateWithExtensions::<Mint>::unpack(&mint_account.data)
269270
.map_err(|err| format!("Invalid token mint {}: {}", token, err))?;
270271
Ok(mint_account.owner)
271272
}
@@ -341,9 +342,9 @@ async fn command_close_accounts(
341342

342343
for (account, (address, _seed)) in accounts_chunk.iter().zip(address_chunk) {
343344
if let Some(account) = account {
344-
match Account::unpack(&account.data) {
345+
match StateWithExtensions::<Account>::unpack(&account.data) {
345346
Ok(token_account) => {
346-
if token_account.amount != 0 {
347+
if token_account.base.amount != 0 {
347348
eprintln!(
348349
"Token account {} holds a balance; unable to close it",
349350
address,

token/cli/src/config.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ use solana_clap_utils::{
77
use solana_cli_output::OutputFormat;
88
use solana_client::nonblocking::rpc_client::RpcClient;
99
use solana_remote_wallet::remote_wallet::RemoteWalletManager;
10-
use solana_sdk::{program_pack::Pack, pubkey::Pubkey, signature::Signer};
10+
use solana_sdk::{pubkey::Pubkey, signature::Signer};
1111
use spl_associated_token_account::*;
12-
use spl_token::state::{Account, Mint};
12+
use spl_token_2022::{
13+
extension::StateWithExtensionsOwned,
14+
state::{Account, Mint},
15+
};
1316
use std::{process::exit, sync::Arc};
1417

1518
#[cfg(test)]
@@ -223,21 +226,21 @@ impl<'a> Config<'a> {
223226
} else {
224227
let account = self.rpc_client.get_account(mint).await?;
225228
self.check_owner(mint, &account.owner)?;
226-
let mint_account = Mint::unpack(&account.data)
229+
let mint_account = StateWithExtensionsOwned::<Mint>::unpack(account.data)
227230
.map_err(|_| format!("Could not find mint account {}", mint))?;
228231
if let Some(decimals) = mint_decimals {
229-
if decimals != mint_account.decimals {
232+
if decimals != mint_account.base.decimals {
230233
return Err(format!(
231234
"Mint {:?} has decimals {}, not configured decimals {}",
232-
mint, mint_account.decimals, decimals
235+
mint, mint_account.base.decimals, decimals
233236
)
234237
.into());
235238
}
236239
}
237240
Ok(MintInfo {
238241
program_id: account.owner,
239242
address: *mint,
240-
decimals: mint_account.decimals,
243+
decimals: mint_account.base.decimals,
241244
})
242245
}
243246
}
@@ -261,9 +264,9 @@ impl<'a> Config<'a> {
261264
) -> Result<Pubkey, Error> {
262265
if !self.sign_only {
263266
let account = self.rpc_client.get_account(token_account).await?;
264-
let source_account = Account::unpack(&account.data)
267+
let source_account = StateWithExtensionsOwned::<Account>::unpack(account.data)
265268
.map_err(|_| format!("Could not find token account {}", token_account))?;
266-
let source_mint = source_account.mint;
269+
let source_mint = source_account.base.mint;
267270
if let Some(mint) = mint_address {
268271
if source_mint != mint {
269272
return Err(format!(

0 commit comments

Comments
 (0)