spl-token: New program feature flag (#21354)

* spl-token: Add feature flag for new release

* Remove all spl token version declarations
This commit is contained in:
Jon Cinque 2021-11-21 14:27:03 +01:00 committed by GitHub
parent 2ed7e3af89
commit 02bc4e3fc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 229 additions and 245 deletions

View File

@ -22,7 +22,7 @@ serde_json = "1.0.71"
solana-config-program = { path = "../programs/config", version = "=1.9.0" }
solana-sdk = { path = "../sdk", version = "=1.9.0" }
solana-vote-program = { path = "../programs/vote", version = "=1.9.0" }
spl-token-v2-0 = { package = "spl-token", version = "=3.2.0", features = ["no-entrypoint"] }
spl-token = { version = "=3.2.0", features = ["no-entrypoint"] }
thiserror = "1.0"
zstd = "0.9.0"

View File

@ -4,7 +4,7 @@ use crate::{
parse_nonce::parse_nonce,
parse_stake::parse_stake,
parse_sysvar::parse_sysvar,
parse_token::{parse_token, spl_token_id_v2_0},
parse_token::{parse_token, spl_token_id},
parse_vote::parse_vote,
};
use inflector::Inflector;
@ -19,7 +19,7 @@ lazy_static! {
static ref STAKE_PROGRAM_ID: Pubkey = stake::program::id();
static ref SYSTEM_PROGRAM_ID: Pubkey = system_program::id();
static ref SYSVAR_PROGRAM_ID: Pubkey = sysvar::id();
static ref TOKEN_PROGRAM_ID: Pubkey = spl_token_id_v2_0();
static ref TOKEN_PROGRAM_ID: Pubkey = spl_token_id();
static ref VOTE_PROGRAM_ID: Pubkey = solana_vote_program::id();
pub static ref PARSABLE_PROGRAM_IDS: HashMap<Pubkey, ParsableAccount> = {
let mut m = HashMap::new();

View File

@ -3,7 +3,7 @@ use crate::{
StringAmount, StringDecimals,
};
use solana_sdk::pubkey::Pubkey;
use spl_token_v2_0::{
use spl_token::{
solana_program::{
program_option::COption, program_pack::Pack, pubkey::Pubkey as SplTokenPubkey,
},
@ -11,25 +11,25 @@ use spl_token_v2_0::{
};
use std::str::FromStr;
// A helper function to convert spl_token_v2_0::id() as spl_sdk::pubkey::Pubkey to
// A helper function to convert spl_token::id() as spl_sdk::pubkey::Pubkey to
// solana_sdk::pubkey::Pubkey
pub fn spl_token_id_v2_0() -> Pubkey {
Pubkey::new_from_array(spl_token_v2_0::id().to_bytes())
pub fn spl_token_id() -> Pubkey {
Pubkey::new_from_array(spl_token::id().to_bytes())
}
// A helper function to convert spl_token_v2_0::native_mint::id() as spl_sdk::pubkey::Pubkey to
// A helper function to convert spl_token::native_mint::id() as spl_sdk::pubkey::Pubkey to
// solana_sdk::pubkey::Pubkey
pub fn spl_token_v2_0_native_mint() -> Pubkey {
Pubkey::new_from_array(spl_token_v2_0::native_mint::id().to_bytes())
pub fn spl_token_native_mint() -> Pubkey {
Pubkey::new_from_array(spl_token::native_mint::id().to_bytes())
}
// A helper function to convert a solana_sdk::pubkey::Pubkey to spl_sdk::pubkey::Pubkey
pub fn spl_token_v2_0_pubkey(pubkey: &Pubkey) -> SplTokenPubkey {
pub fn spl_token_pubkey(pubkey: &Pubkey) -> SplTokenPubkey {
SplTokenPubkey::new_from_array(pubkey.to_bytes())
}
// A helper function to convert a spl_sdk::pubkey::Pubkey to solana_sdk::pubkey::Pubkey
pub fn pubkey_from_spl_token_v2_0(pubkey: &SplTokenPubkey) -> Pubkey {
pub fn pubkey_from_spl_token(pubkey: &SplTokenPubkey) -> Pubkey {
Pubkey::new_from_array(pubkey.to_bytes())
}

View File

@ -27,7 +27,7 @@ solana-sdk = { path = "../sdk", version = "=1.9.0" }
solana-streamer = { path = "../streamer", version = "=1.9.0" }
solana-transaction-status = { path = "../transaction-status", version = "=1.9.0" }
solana-version = { path = "../version", version = "=1.9.0" }
spl-token-v2-0 = { package = "spl-token", version = "=3.2.0", features = ["no-entrypoint"] }
spl-token = { version = "=3.2.0", features = ["no-entrypoint"] }
[dev-dependencies]
solana-local-cluster = { path = "../local-cluster", version = "=1.9.0" }

View File

@ -3,12 +3,12 @@ use clap::{crate_description, crate_name, value_t, values_t_or_exit, App, Arg};
use log::*;
use rand::{thread_rng, Rng};
use rayon::prelude::*;
use solana_account_decoder::parse_token::spl_token_v2_0_pubkey;
use solana_account_decoder::parse_token::spl_token_pubkey;
use solana_clap_utils::input_parsers::pubkey_of;
use solana_client::{rpc_client::RpcClient, transaction_executor::TransactionExecutor};
use solana_faucet::faucet::{request_airdrop_transaction, FAUCET_PORT};
use solana_gossip::gossip_service::discover;
use solana_runtime::inline_spl_token_v2_0;
use solana_runtime::inline_spl_token;
use solana_sdk::{
commitment_config::CommitmentConfig,
instruction::{AccountMeta, Instruction},
@ -20,7 +20,7 @@ use solana_sdk::{
transaction::Transaction,
};
use solana_streamer::socket::SocketAddrSpace;
use solana_transaction_status::parse_token::spl_token_v2_0_instruction;
use solana_transaction_status::parse_token::spl_token_instruction;
use std::{
net::SocketAddr,
process::exit,
@ -115,7 +115,7 @@ fn make_create_message(
.into_iter()
.map(|_| {
let program_id = if mint.is_some() {
inline_spl_token_v2_0::id()
inline_spl_token::id()
} else {
system_program::id()
};
@ -132,12 +132,12 @@ fn make_create_message(
&program_id,
)];
if let Some(mint_address) = mint {
instructions.push(spl_token_v2_0_instruction(
spl_token_v2_0::instruction::initialize_account(
&spl_token_v2_0::id(),
&spl_token_v2_0_pubkey(&to_pubkey),
&spl_token_v2_0_pubkey(&mint_address),
&spl_token_v2_0_pubkey(&base_keypair.pubkey()),
instructions.push(spl_token_instruction(
spl_token::instruction::initialize_account(
&spl_token::id(),
&spl_token_pubkey(&to_pubkey),
&spl_token_pubkey(&mint_address),
&spl_token_pubkey(&base_keypair.pubkey()),
)
.unwrap(),
));
@ -163,7 +163,7 @@ fn make_close_message(
.into_iter()
.map(|_| {
let program_id = if spl_token {
inline_spl_token_v2_0::id()
inline_spl_token::id()
} else {
system_program::id()
};
@ -171,12 +171,12 @@ fn make_close_message(
let address =
Pubkey::create_with_seed(&base_keypair.pubkey(), &seed, &program_id).unwrap();
if spl_token {
spl_token_v2_0_instruction(
spl_token_v2_0::instruction::close_account(
&spl_token_v2_0::id(),
&spl_token_v2_0_pubkey(&address),
&spl_token_v2_0_pubkey(&keypair.pubkey()),
&spl_token_v2_0_pubkey(&base_keypair.pubkey()),
spl_token_instruction(
spl_token::instruction::close_account(
&spl_token::id(),
&spl_token_pubkey(&address),
&spl_token_pubkey(&keypair.pubkey()),
&spl_token_pubkey(&base_keypair.pubkey()),
&[],
)
.unwrap(),

View File

@ -49,7 +49,7 @@ solana-storage-bigtable = { path = "../storage-bigtable", version = "=1.9.0" }
solana-transaction-status = { path = "../transaction-status", version = "=1.9.0" }
solana-version = { path = "../version", version = "=1.9.0" }
solana-vote-program = { path = "../programs/vote", version = "=1.9.0" }
spl-token-v2-0 = { package = "spl-token", version = "=3.2.0", features = ["no-entrypoint"] }
spl-token = { version = "=3.2.0", features = ["no-entrypoint"] }
stream-cancel = "0.8.1"
thiserror = "1.0"
tokio = { version = "1", features = ["full"] }

View File

@ -2,7 +2,7 @@ use {
jsonrpc_core::{Error, Result},
solana_account_decoder::{
parse_account_data::AccountAdditionalData,
parse_token::{get_token_account_mint, spl_token_id_v2_0, spl_token_v2_0_native_mint},
parse_token::{get_token_account_mint, spl_token_id, spl_token_native_mint},
UiAccount, UiAccountData, UiAccountEncoding,
},
solana_client::rpc_response::RpcKeyedAccount,
@ -11,7 +11,7 @@ use {
account::{AccountSharedData, ReadableAccount},
pubkey::Pubkey,
},
spl_token_v2_0::{solana_program::program_pack::Pack, state::Mint},
spl_token::{solana_program::program_pack::Pack, state::Mint},
std::{collections::HashMap, sync::Arc},
};
@ -74,8 +74,8 @@ where
/// Analyze a mint Pubkey that may be the native_mint and get the mint-account owner (token
/// program_id) and decimals
pub fn get_mint_owner_and_decimals(bank: &Arc<Bank>, mint: &Pubkey) -> Result<(Pubkey, u8)> {
if mint == &spl_token_v2_0_native_mint() {
Ok((spl_token_id_v2_0(), spl_token_v2_0::native_mint::DECIMALS))
if mint == &spl_token_native_mint() {
Ok((spl_token_id(), spl_token::native_mint::DECIMALS))
} else {
let mint_account = bank.get_account(mint).ok_or_else(|| {
Error::invalid_params("Invalid param: could not find mint".to_string())

View File

@ -10,7 +10,7 @@ use {
jsonrpc_derive::rpc,
serde::{Deserialize, Serialize},
solana_account_decoder::{
parse_token::{spl_token_id_v2_0, token_amount_to_ui_amount, UiTokenAmount},
parse_token::{spl_token_id, token_amount_to_ui_amount, UiTokenAmount},
UiAccount, UiAccountEncoding, UiDataSliceConfig, MAX_BASE58_BYTES,
},
solana_client::{
@ -43,7 +43,7 @@ use {
bank::{Bank, TransactionSimulationResult},
bank_forks::BankForks,
commitment::{BlockCommitmentArray, BlockCommitmentCache, CommitmentSlots},
inline_spl_token_v2_0::{SPL_TOKEN_ACCOUNT_MINT_OFFSET, SPL_TOKEN_ACCOUNT_OWNER_OFFSET},
inline_spl_token::{SPL_TOKEN_ACCOUNT_MINT_OFFSET, SPL_TOKEN_ACCOUNT_OWNER_OFFSET},
non_circulating_supply::calculate_non_circulating_supply,
snapshot_config::SnapshotConfig,
snapshot_utils,
@ -78,7 +78,7 @@ use {
TransactionConfirmationStatus, TransactionStatus, UiConfirmedBlock, UiTransactionEncoding,
},
solana_vote_program::vote_state::{VoteState, MAX_LOCKOUT_HISTORY},
spl_token_v2_0::{
spl_token::{
solana_program::program_pack::Pack,
state::{Account as TokenAccount, Mint},
},
@ -396,9 +396,7 @@ impl JsonRpcRequestProcessor {
self.get_filtered_program_accounts(&bank, program_id, filters)?
}
};
let result = if program_id == &spl_token_id_v2_0()
&& encoding == UiAccountEncoding::JsonParsed
{
let result = if program_id == &spl_token_id() && encoding == UiAccountEncoding::JsonParsed {
get_parsed_token_accounts(bank.clone(), keyed_accounts.into_iter()).collect()
} else {
keyed_accounts
@ -1628,14 +1626,13 @@ impl JsonRpcRequestProcessor {
Error::invalid_params("Invalid param: could not find account".to_string())
})?;
if account.owner() != &spl_token_id_v2_0() {
if account.owner() != &spl_token_id() {
return Err(Error::invalid_params(
"Invalid param: not a v2.0 Token account".to_string(),
"Invalid param: not a Token account".to_string(),
));
}
let token_account = TokenAccount::unpack(account.data()).map_err(|_| {
Error::invalid_params("Invalid param: not a v2.0 Token account".to_string())
})?;
let token_account = TokenAccount::unpack(account.data())
.map_err(|_| Error::invalid_params("Invalid param: not a Token account".to_string()))?;
let mint = &Pubkey::from_str(&token_account.mint.to_string())
.expect("Token account mint should be convertible to Pubkey");
let (_, decimals) = get_mint_owner_and_decimals(&bank, mint)?;
@ -1652,9 +1649,9 @@ impl JsonRpcRequestProcessor {
let mint_account = bank.get_account(mint).ok_or_else(|| {
Error::invalid_params("Invalid param: could not find account".to_string())
})?;
if mint_account.owner() != &spl_token_id_v2_0() {
if mint_account.owner() != &spl_token_id() {
return Err(Error::invalid_params(
"Invalid param: not a v2.0 Token mint".to_string(),
"Invalid param: not a Token mint".to_string(),
));
}
let mint = Mint::unpack(mint_account.data()).map_err(|_| {
@ -1672,9 +1669,9 @@ impl JsonRpcRequestProcessor {
) -> Result<RpcResponse<Vec<RpcTokenAccountBalance>>> {
let bank = self.bank(commitment);
let (mint_owner, decimals) = get_mint_owner_and_decimals(&bank, mint)?;
if mint_owner != spl_token_id_v2_0() {
if mint_owner != spl_token_id() {
return Err(Error::invalid_params(
"Invalid param: not a v2.0 Token mint".to_string(),
"Invalid param: not a Token mint".to_string(),
));
}
let mut token_balances: Vec<RpcTokenAccountBalance> = self
@ -1893,7 +1890,7 @@ impl JsonRpcRequestProcessor {
.get_filtered_indexed_accounts(
&IndexKey::SplTokenOwner(*owner_key),
|account| {
account.owner() == &spl_token_id_v2_0()
account.owner() == &spl_token_id()
&& filters.iter().all(|filter_type| match filter_type {
RpcFilterType::DataSize(size) => {
account.data().len() as u64 == *size
@ -1910,7 +1907,7 @@ impl JsonRpcRequestProcessor {
message: e.to_string(),
})?)
} else {
self.get_filtered_program_accounts(bank, &spl_token_id_v2_0(), filters)
self.get_filtered_program_accounts(bank, &spl_token_id(), filters)
}
}
@ -1950,7 +1947,7 @@ impl JsonRpcRequestProcessor {
.get_filtered_indexed_accounts(
&IndexKey::SplTokenMint(*mint_key),
|account| {
account.owner() == &spl_token_id_v2_0()
account.owner() == &spl_token_id()
&& filters.iter().all(|filter_type| match filter_type {
RpcFilterType::DataSize(size) => {
account.data().len() as u64 == *size
@ -1967,7 +1964,7 @@ impl JsonRpcRequestProcessor {
message: e.to_string(),
})?)
} else {
self.get_filtered_program_accounts(bank, &spl_token_id_v2_0(), filters)
self.get_filtered_program_accounts(bank, &spl_token_id(), filters)
}
}
@ -2149,7 +2146,7 @@ fn get_encoded_account(
) -> Result<Option<UiAccount>> {
match bank.get_account(pubkey) {
Some(account) => {
let response = if account.owner() == &spl_token_id_v2_0()
let response = if account.owner() == &spl_token_id()
&& encoding == UiAccountEncoding::JsonParsed
{
get_parsed_token_account(bank.clone(), pubkey, account)
@ -2189,7 +2186,7 @@ fn encode_account<T: ReadableAccount>(
/// NOTE: `optimize_filters()` should almost always be called before using this method because of
/// the strict match on `MemcmpEncodedBytes::Bytes`.
fn get_spl_token_owner_filter(program_id: &Pubkey, filters: &[RpcFilterType]) -> Option<Pubkey> {
if program_id != &spl_token_id_v2_0() {
if program_id != &spl_token_id() {
return None;
}
let mut data_size_filter: Option<u64> = None;
@ -2231,7 +2228,7 @@ fn get_spl_token_owner_filter(program_id: &Pubkey, filters: &[RpcFilterType]) ->
/// NOTE: `optimize_filters()` should almost always be called before using this method because of
/// the strict match on `MemcmpEncodedBytes::Bytes`.
fn get_spl_token_mint_filter(program_id: &Pubkey, filters: &[RpcFilterType]) -> Option<Pubkey> {
if program_id != &spl_token_id_v2_0() {
if program_id != &spl_token_id() {
return None;
}
let mut data_size_filter: Option<u64> = None;
@ -2277,15 +2274,15 @@ fn get_token_program_id_and_mint(
match token_account_filter {
TokenAccountsFilter::Mint(mint) => {
let (mint_owner, _) = get_mint_owner_and_decimals(bank, &mint)?;
if mint_owner != spl_token_id_v2_0() {
if mint_owner != spl_token_id() {
return Err(Error::invalid_params(
"Invalid param: not a v2.0 Token mint".to_string(),
"Invalid param: not a Token mint".to_string(),
));
}
Ok((mint_owner, Some(mint)))
}
TokenAccountsFilter::ProgramId(program_id) => {
if program_id == spl_token_id_v2_0() {
if program_id == spl_token_id() {
Ok((program_id, None))
} else {
Err(Error::invalid_params(
@ -4337,7 +4334,7 @@ pub mod tests {
vote_instruction,
vote_state::{BlockTimestamp, Vote, VoteInit, VoteStateVersions, MAX_LOCKOUT_HISTORY},
},
spl_token_v2_0::{
spl_token::{
solana_program::{program_option::COption, pubkey::Pubkey as SplTokenPubkey},
state::AccountState as TokenAccountState,
state::Mint,
@ -7232,7 +7229,7 @@ pub mod tests {
let token_account = AccountSharedData::from(Account {
lamports: 111,
data: account_data.to_vec(),
owner: spl_token_id_v2_0(),
owner: spl_token_id(),
..Account::default()
});
let token_account_pubkey = solana_sdk::pubkey::new_rand();
@ -7251,7 +7248,7 @@ pub mod tests {
let mint_account = AccountSharedData::from(Account {
lamports: 111,
data: mint_data.to_vec(),
owner: spl_token_id_v2_0(),
owner: spl_token_id(),
..Account::default()
});
bank.store_account(&Pubkey::from_str(&mint.to_string()).unwrap(), &mint_account);
@ -7328,7 +7325,7 @@ pub mod tests {
let token_account = AccountSharedData::from(Account {
lamports: 111,
data: account_data.to_vec(),
owner: spl_token_id_v2_0(),
owner: spl_token_id(),
..Account::default()
});
let token_with_different_mint_pubkey = solana_sdk::pubkey::new_rand();
@ -7343,7 +7340,7 @@ pub mod tests {
"params":["{}", {{"programId": "{}"}}]
}}"#,
owner,
spl_token_id_v2_0(),
spl_token_id(),
);
let res = io.handle_request_sync(&req, meta.clone());
let result: Value = serde_json::from_str(&res.expect("actual response"))
@ -7361,7 +7358,7 @@ pub mod tests {
"params":["{}", {{"programId": "{}"}}, {{"encoding": "jsonParsed"}}]
}}"#,
owner,
spl_token_id_v2_0(),
spl_token_id(),
);
let res = io.handle_request_sync(&req, meta.clone());
let result: Value = serde_json::from_str(&res.expect("actual response"))
@ -7378,7 +7375,7 @@ pub mod tests {
"method":"getProgramAccounts",
"params":["{}", {{"encoding": "jsonParsed"}}]
}}"#,
spl_token_id_v2_0(),
spl_token_id(),
);
let res = io.handle_request_sync(&req, meta.clone());
let result: Value = serde_json::from_str(&res.expect("actual response"))
@ -7442,7 +7439,7 @@ pub mod tests {
"params":["{}", {{"programId": "{}"}}]
}}"#,
solana_sdk::pubkey::new_rand(),
spl_token_id_v2_0(),
spl_token_id(),
);
let res = io.handle_request_sync(&req, meta.clone());
let result: Value = serde_json::from_str(&res.expect("actual response"))
@ -7460,7 +7457,7 @@ pub mod tests {
"params":["{}", {{"programId": "{}"}}]
}}"#,
delegate,
spl_token_id_v2_0(),
spl_token_id(),
);
let res = io.handle_request_sync(&req, meta.clone());
let result: Value = serde_json::from_str(&res.expect("actual response"))
@ -7525,7 +7522,7 @@ pub mod tests {
"params":["{}", {{"programId": "{}"}}]
}}"#,
solana_sdk::pubkey::new_rand(),
spl_token_id_v2_0(),
spl_token_id(),
);
let res = io.handle_request_sync(&req, meta.clone());
let result: Value = serde_json::from_str(&res.expect("actual response"))
@ -7547,7 +7544,7 @@ pub mod tests {
let mint_account = AccountSharedData::from(Account {
lamports: 111,
data: mint_data.to_vec(),
owner: spl_token_id_v2_0(),
owner: spl_token_id(),
..Account::default()
});
bank.store_account(
@ -7569,7 +7566,7 @@ pub mod tests {
let token_account = AccountSharedData::from(Account {
lamports: 111,
data: account_data.to_vec(),
owner: spl_token_id_v2_0(),
owner: spl_token_id(),
..Account::default()
});
let token_with_smaller_balance = solana_sdk::pubkey::new_rand();
@ -7633,7 +7630,7 @@ pub mod tests {
let token_account = AccountSharedData::from(Account {
lamports: 111,
data: account_data.to_vec(),
owner: spl_token_id_v2_0(),
owner: spl_token_id(),
..Account::default()
});
let token_account_pubkey = solana_sdk::pubkey::new_rand();
@ -7652,7 +7649,7 @@ pub mod tests {
let mint_account = AccountSharedData::from(Account {
lamports: 111,
data: mint_data.to_vec(),
owner: spl_token_id_v2_0(),
owner: spl_token_id(),
..Account::default()
});
bank.store_account(&Pubkey::from_str(&mint.to_string()).unwrap(), &mint_account);

View File

@ -14,7 +14,7 @@ use {
crossbeam_channel::{Receiver, RecvTimeoutError, SendError, Sender},
rayon::prelude::*,
serde::Serialize,
solana_account_decoder::{parse_token::spl_token_id_v2_0, UiAccount, UiAccountEncoding},
solana_account_decoder::{parse_token::spl_token_id, UiAccount, UiAccountEncoding},
solana_client::{
rpc_filter::RpcFilterType,
rpc_response::{
@ -301,9 +301,7 @@ fn filter_account_result(
// If last_modified_slot < last_notified_slot this means that we last notified for a fork
// and should notify that the account state has been reverted.
let results: Box<dyn Iterator<Item = UiAccount>> = if last_modified_slot != last_notified_slot {
if account.owner() == &spl_token_id_v2_0()
&& params.encoding == UiAccountEncoding::JsonParsed
{
if account.owner() == &spl_token_id() && params.encoding == UiAccountEncoding::JsonParsed {
Box::new(iter::once(get_parsed_token_account(
bank,
&params.pubkey,
@ -354,8 +352,7 @@ fn filter_program_results(
RpcFilterType::Memcmp(compare) => compare.bytes_match(account.data()),
})
});
let accounts: Box<dyn Iterator<Item = RpcKeyedAccount>> = if params.pubkey
== spl_token_id_v2_0()
let accounts: Box<dyn Iterator<Item = RpcKeyedAccount>> = if params.pubkey == spl_token_id()
&& params.encoding == UiAccountEncoding::JsonParsed
&& !accounts_is_empty
{

View File

@ -7374,7 +7374,7 @@ pub mod tests {
accounts_index::RefCount,
accounts_index::{tests::*, AccountSecondaryIndexesIncludeExclude},
append_vec::{test_utils::TempFile, AccountMeta},
inline_spl_token_v2_0,
inline_spl_token,
};
use assert_matches::assert_matches;
use rand::{thread_rng, Rng};
@ -8916,14 +8916,14 @@ pub mod tests {
// Set up account to be added to secondary index
let mint_key = Pubkey::new_unique();
let mut account_data_with_mint =
vec![0; inline_spl_token_v2_0::state::Account::get_packed_len()];
vec![0; inline_spl_token::state::Account::get_packed_len()];
account_data_with_mint[..PUBKEY_BYTES].clone_from_slice(&(mint_key.to_bytes()));
let mut normal_account = AccountSharedData::new(1, 0, AccountSharedData::default().owner());
normal_account.set_owner(inline_spl_token_v2_0::id());
normal_account.set_owner(inline_spl_token::id());
normal_account.set_data(account_data_with_mint.clone());
let mut zero_account = AccountSharedData::new(0, 0, AccountSharedData::default().owner());
zero_account.set_owner(inline_spl_token_v2_0::id());
zero_account.set_owner(inline_spl_token::id());
zero_account.set_data(account_data_with_mint);
//store an account

View File

@ -4,7 +4,7 @@ use crate::{
bucket_map_holder::{Age, BucketMapHolder},
contains::Contains,
in_mem_accounts_index::{InMemAccountsIndex, InsertNewEntryResults},
inline_spl_token_v2_0::{self, SPL_TOKEN_ACCOUNT_MINT_OFFSET, SPL_TOKEN_ACCOUNT_OWNER_OFFSET},
inline_spl_token::{self, SPL_TOKEN_ACCOUNT_MINT_OFFSET, SPL_TOKEN_ACCOUNT_OWNER_OFFSET},
pubkey_bins::PubkeyBinCalculator24,
secondary_index::*,
};
@ -1556,8 +1556,8 @@ impl<T: IndexValue> AccountsIndex<T> {
// 2) When the fetch from storage occurs, it will return AccountSharedData::Default
// (as persisted tombstone for snapshots). This will then ultimately be
// filtered out by post-scan filters, like in `get_filtered_spl_token_accounts_by_owner()`.
if *account_owner == inline_spl_token_v2_0::id()
&& account_data.len() == inline_spl_token_v2_0::state::Account::get_packed_len()
if *account_owner == inline_spl_token::id()
&& account_data.len() == inline_spl_token::state::Account::get_packed_len()
{
if account_indexes.contains(&AccountIndex::SplTokenOwner) {
let owner_key = Pubkey::new(
@ -3696,7 +3696,7 @@ pub mod tests {
let index_key = Pubkey::new_unique();
let account_key = Pubkey::new_unique();
let mut account_data = vec![0; inline_spl_token_v2_0::state::Account::get_packed_len()];
let mut account_data = vec![0; inline_spl_token::state::Account::get_packed_len()];
account_data[key_start..key_end].clone_from_slice(&(index_key.to_bytes()));
// Insert slots into secondary index
@ -3705,7 +3705,7 @@ pub mod tests {
*slot,
&account_key,
// Make sure these accounts are added to secondary index
&inline_spl_token_v2_0::id(),
&inline_spl_token::id(),
&account_data,
secondary_indexes,
true,
@ -3871,7 +3871,7 @@ pub mod tests {
let mut secondary_indexes = secondary_indexes.clone();
let account_key = Pubkey::new_unique();
let index_key = Pubkey::new_unique();
let mut account_data = vec![0; inline_spl_token_v2_0::state::Account::get_packed_len()];
let mut account_data = vec![0; inline_spl_token::state::Account::get_packed_len()];
account_data[key_start..key_end].clone_from_slice(&(index_key.to_bytes()));
// Wrong program id
@ -3892,7 +3892,7 @@ pub mod tests {
index.upsert(
0,
&account_key,
&inline_spl_token_v2_0::id(),
&inline_spl_token::id(),
&account_data[1..],
&secondary_indexes,
true,
@ -3908,7 +3908,7 @@ pub mod tests {
for _ in 0..2 {
index.update_secondary_indexes(
&account_key,
&inline_spl_token_v2_0::id(),
&inline_spl_token::id(),
&account_data,
&secondary_indexes,
);
@ -3927,7 +3927,7 @@ pub mod tests {
secondary_index.reverse_index.clear();
index.update_secondary_indexes(
&account_key,
&inline_spl_token_v2_0::id(),
&inline_spl_token::id(),
&account_data,
&secondary_indexes,
);
@ -3944,7 +3944,7 @@ pub mod tests {
secondary_index.reverse_index.clear();
index.update_secondary_indexes(
&account_key,
&inline_spl_token_v2_0::id(),
&inline_spl_token::id(),
&account_data,
&secondary_indexes,
);
@ -4001,10 +4001,10 @@ pub mod tests {
let secondary_key1 = Pubkey::new_unique();
let secondary_key2 = Pubkey::new_unique();
let slot = 1;
let mut account_data1 = vec![0; inline_spl_token_v2_0::state::Account::get_packed_len()];
let mut account_data1 = vec![0; inline_spl_token::state::Account::get_packed_len()];
account_data1[index_key_start..index_key_end]
.clone_from_slice(&(secondary_key1.to_bytes()));
let mut account_data2 = vec![0; inline_spl_token_v2_0::state::Account::get_packed_len()];
let mut account_data2 = vec![0; inline_spl_token::state::Account::get_packed_len()];
account_data2[index_key_start..index_key_end]
.clone_from_slice(&(secondary_key2.to_bytes()));
@ -4012,7 +4012,7 @@ pub mod tests {
index.upsert(
slot,
&account_key,
&inline_spl_token_v2_0::id(),
&inline_spl_token::id(),
&account_data1,
secondary_indexes,
true,
@ -4024,7 +4024,7 @@ pub mod tests {
index.upsert(
slot,
&account_key,
&inline_spl_token_v2_0::id(),
&inline_spl_token::id(),
&account_data2,
secondary_indexes,
true,
@ -4044,7 +4044,7 @@ pub mod tests {
index.upsert(
later_slot,
&account_key,
&inline_spl_token_v2_0::id(),
&inline_spl_token::id(),
&account_data1,
secondary_indexes,
true,

View File

@ -46,7 +46,7 @@ use crate::{
builtins::{self, ActivationType, Builtin, Builtins},
cost_tracker::CostTracker,
epoch_stakes::{EpochStakes, NodeVoteAccounts},
inline_spl_token_v2_0,
inline_spl_token,
message_processor::MessageProcessor,
rent_collector::RentCollector,
stake_weighted_timestamp::{
@ -6100,8 +6100,8 @@ impl Bank {
self.rent_collector.rent.burn_percent = 50; // 50% rent burn
}
if new_feature_activations.contains(&feature_set::spl_token_v2_set_authority_fix::id()) {
self.apply_spl_token_v2_set_authority_fix();
if new_feature_activations.contains(&feature_set::spl_token_v3_3_0_release::id()) {
self.apply_spl_token_v3_3_0_release();
}
if new_feature_activations.contains(&feature_set::rent_for_sysvars::id()) {
// when this feature is activated, immediately all of existing sysvars are susceptible
@ -6237,13 +6237,13 @@ impl Bank {
}
}
fn apply_spl_token_v2_set_authority_fix(&mut self) {
if let Some(old_account) = self.get_account_with_fixed_root(&inline_spl_token_v2_0::id()) {
fn apply_spl_token_v3_3_0_release(&mut self) {
if let Some(old_account) = self.get_account_with_fixed_root(&inline_spl_token::id()) {
if let Some(new_account) =
self.get_account_with_fixed_root(&inline_spl_token_v2_0::new_token_program::id())
self.get_account_with_fixed_root(&inline_spl_token::new_token_program::id())
{
datapoint_info!(
"bank-apply_spl_token_v2_set_authority_fix",
"bank-apply_spl_token_v3_3_0_release",
("slot", self.slot, i64),
);
@ -6252,15 +6252,15 @@ impl Bank {
.fetch_sub(old_account.lamports(), Relaxed);
// Transfer new token account to old token account
self.store_account(&inline_spl_token_v2_0::id(), &new_account);
self.store_account(&inline_spl_token::id(), &new_account);
// Clear new token account
self.store_account(
&inline_spl_token_v2_0::new_token_program::id(),
&inline_spl_token::new_token_program::id(),
&AccountSharedData::default(),
);
self.remove_executor(&inline_spl_token_v2_0::id());
self.remove_executor(&inline_spl_token::id());
}
}
}
@ -6274,8 +6274,8 @@ impl Bank {
if reconfigure_token2_native_mint {
let mut native_mint_account = solana_sdk::account::AccountSharedData::from(Account {
owner: inline_spl_token_v2_0::id(),
data: inline_spl_token_v2_0::native_mint::ACCOUNT_DATA.to_vec(),
owner: inline_spl_token::id(),
data: inline_spl_token::native_mint::ACCOUNT_DATA.to_vec(),
lamports: sol_to_lamports(1.),
executable: false,
rent_epoch: self.epoch() + 1,
@ -6285,7 +6285,7 @@ impl Bank {
// https://github.com/solana-labs/solana-program-library/issues/374, ensure that the
// spl-token 2 native mint account is owned by the spl-token 2 program.
let store = if let Some(existing_native_mint_account) =
self.get_account_with_fixed_root(&inline_spl_token_v2_0::native_mint::id())
self.get_account_with_fixed_root(&inline_spl_token::native_mint::id())
{
if existing_native_mint_account.owner() == &solana_sdk::system_program::id() {
native_mint_account.set_lamports(existing_native_mint_account.lamports());
@ -6300,10 +6300,7 @@ impl Bank {
};
if store {
self.store_account(
&inline_spl_token_v2_0::native_mint::id(),
&native_mint_account,
);
self.store_account(&inline_spl_token::native_mint::id(), &native_mint_account);
}
}
}
@ -12733,18 +12730,15 @@ pub(crate) mod tests {
assert_eq!(genesis_config.cluster_type, ClusterType::Development);
let bank = Arc::new(Bank::new_for_tests(&genesis_config));
assert_eq!(
bank.get_balance(&inline_spl_token_v2_0::native_mint::id()),
bank.get_balance(&inline_spl_token::native_mint::id()),
1000000000
);
// Testnet - Native mint blinks into existence at epoch 93
genesis_config.cluster_type = ClusterType::Testnet;
let bank = Arc::new(Bank::new_for_tests(&genesis_config));
assert_eq!(
bank.get_balance(&inline_spl_token_v2_0::native_mint::id()),
0
);
bank.deposit(&inline_spl_token_v2_0::native_mint::id(), 4200000000)
assert_eq!(bank.get_balance(&inline_spl_token::native_mint::id()), 0);
bank.deposit(&inline_spl_token::native_mint::id(), 4200000000)
.unwrap();
let bank = Bank::new_from_parent(
@ -12754,23 +12748,20 @@ pub(crate) mod tests {
);
let native_mint_account = bank
.get_account(&inline_spl_token_v2_0::native_mint::id())
.get_account(&inline_spl_token::native_mint::id())
.unwrap();
assert_eq!(native_mint_account.data().len(), 82);
assert_eq!(
bank.get_balance(&inline_spl_token_v2_0::native_mint::id()),
bank.get_balance(&inline_spl_token::native_mint::id()),
4200000000
);
assert_eq!(native_mint_account.owner(), &inline_spl_token_v2_0::id());
assert_eq!(native_mint_account.owner(), &inline_spl_token::id());
// MainnetBeta - Native mint blinks into existence at epoch 75
genesis_config.cluster_type = ClusterType::MainnetBeta;
let bank = Arc::new(Bank::new_for_tests(&genesis_config));
assert_eq!(
bank.get_balance(&inline_spl_token_v2_0::native_mint::id()),
0
);
bank.deposit(&inline_spl_token_v2_0::native_mint::id(), 4200000000)
assert_eq!(bank.get_balance(&inline_spl_token::native_mint::id()), 0);
bank.deposit(&inline_spl_token::native_mint::id(), 4200000000)
.unwrap();
let bank = Bank::new_from_parent(
@ -12780,14 +12771,14 @@ pub(crate) mod tests {
);
let native_mint_account = bank
.get_account(&inline_spl_token_v2_0::native_mint::id())
.get_account(&inline_spl_token::native_mint::id())
.unwrap();
assert_eq!(native_mint_account.data().len(), 82);
assert_eq!(
bank.get_balance(&inline_spl_token_v2_0::native_mint::id()),
bank.get_balance(&inline_spl_token::native_mint::id()),
4200000000
);
assert_eq!(native_mint_account.owner(), &inline_spl_token_v2_0::id());
assert_eq!(native_mint_account.owner(), &inline_spl_token::id());
}
#[test]
@ -13115,19 +13106,19 @@ pub(crate) mod tests {
}
#[test]
fn test_spl_token_v2_replacement() {
fn test_spl_token_replacement() {
let (genesis_config, _mint_keypair) = create_genesis_config(0);
let mut bank = Bank::new_for_tests(&genesis_config);
// Setup original token account
bank.store_account_and_update_capitalization(
&inline_spl_token_v2_0::id(),
&inline_spl_token::id(),
&AccountSharedData::from(Account {
lamports: 100,
..Account::default()
}),
);
assert_eq!(bank.get_balance(&inline_spl_token_v2_0::id()), 100);
assert_eq!(bank.get_balance(&inline_spl_token::id()), 100);
// Setup new token account
let new_token_account = AccountSharedData::from(Account {
@ -13135,27 +13126,27 @@ pub(crate) mod tests {
..Account::default()
});
bank.store_account_and_update_capitalization(
&inline_spl_token_v2_0::new_token_program::id(),
&inline_spl_token::new_token_program::id(),
&new_token_account,
);
assert_eq!(
bank.get_balance(&inline_spl_token_v2_0::new_token_program::id()),
bank.get_balance(&inline_spl_token::new_token_program::id()),
123
);
let original_capitalization = bank.capitalization();
bank.apply_spl_token_v2_set_authority_fix();
bank.apply_spl_token_v3_3_0_release();
// New token account is now empty
assert_eq!(
bank.get_balance(&inline_spl_token_v2_0::new_token_program::id()),
bank.get_balance(&inline_spl_token::new_token_program::id()),
0
);
// Old token account holds the new token account
assert_eq!(
bank.get_account(&inline_spl_token_v2_0::id()),
bank.get_account(&inline_spl_token::id()),
Some(new_token_account)
);

View File

@ -1,8 +1,8 @@
// Partial SPL Token v2.0.x declarations inlined to avoid an external dependency on the spl-token crate
// Partial SPL Token declarations inlined to avoid an external dependency on the spl-token crate
solana_sdk::declare_id!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
pub(crate) mod new_token_program {
solana_sdk::declare_id!("nTokHfnBtpt4V6xiEbBSduiGCrQ6wSF3rxC8WeWAQ9F");
solana_sdk::declare_id!("nTok2oJvx1CgbYA2SznfJLmnKLEL6sYdh2ypZms2nhm");
}
/*

View File

@ -31,7 +31,7 @@ pub mod execute_cost_table;
pub mod genesis_utils;
pub mod hardened_unpack;
pub mod in_mem_accounts_index;
pub mod inline_spl_token_v2_0;
pub mod inline_spl_token;
pub mod loader_utils;
pub mod message_processor;
pub mod non_circulating_supply;

View File

@ -241,6 +241,10 @@ pub mod nonce_must_be_writable {
solana_sdk::declare_id!("BiCU7M5w8ZCMykVSyhZ7Q3m2SWoR2qrEQ86ERcDX77ME");
}
pub mod spl_token_v3_3_0_release {
solana_sdk::declare_id!("Ftok2jhqAqxUWEiCVRrfRs9DPppWP8cgTB7NQNKL88mS");
}
lazy_static! {
/// Map of feature identifiers to user-visible description
pub static ref FEATURE_NAMES: HashMap<Pubkey, &'static str> = [
@ -296,6 +300,7 @@ lazy_static! {
(add_compute_budget_program::id(), "Add compute_budget_program"),
(reject_deployment_of_unresolved_syscalls::id(), "Reject deployment of programs with unresolved syscall symbols"),
(nonce_must_be_writable::id(), "nonce must be writable"),
(spl_token_v3_3_0_release::id(), "spl-token v3.3.0 release"),
/*************** ADD NEW FEATURES HERE ***************/
]
.iter()

View File

@ -27,8 +27,8 @@ solana-remote-wallet = { path = "../remote-wallet", version = "=1.9.0" }
solana-sdk = { path = "../sdk", version = "=1.9.0" }
solana-transaction-status = { path = "../transaction-status", version = "=1.9.0" }
solana-version = { path = "../version", version = "=1.9.0" }
spl-associated-token-account-v1-0 = { package = "spl-associated-token-account", version = "=1.0.3" }
spl-token-v2-0 = { package = "spl-token", version = "=3.2.0", features = ["no-entrypoint"] }
spl-associated-token-account = { version = "=1.0.3" }
spl-token = { version = "=3.2.0", features = ["no-entrypoint"] }
tempfile = "3.2.0"
thiserror = "1.0"

View File

@ -12,7 +12,7 @@ use indicatif::{ProgressBar, ProgressStyle};
use pickledb::PickleDb;
use serde::{Deserialize, Serialize};
use solana_account_decoder::parse_token::{
pubkey_from_spl_token_v2_0, real_number_string, spl_token_v2_0_pubkey,
pubkey_from_spl_token, real_number_string, spl_token_pubkey,
};
use solana_client::{
client_error::{ClientError, Result as ClientResult},
@ -35,8 +35,8 @@ use solana_sdk::{
transaction::Transaction,
};
use solana_transaction_status::TransactionStatus;
use spl_associated_token_account_v1_0::get_associated_token_address;
use spl_token_v2_0::solana_program::program_error::ProgramError;
use spl_associated_token_account::get_associated_token_address;
use spl_token::solana_program::program_error::ProgramError;
use std::{
cmp::{self},
io,
@ -309,12 +309,11 @@ fn build_messages(
let wallet_address = allocation.recipient.parse().unwrap();
let associated_token_address = get_associated_token_address(
&wallet_address,
&spl_token_v2_0_pubkey(&spl_token_args.mint),
&spl_token_pubkey(&spl_token_args.mint),
);
let do_create_associated_token_account = client
.get_multiple_accounts(&[pubkey_from_spl_token_v2_0(&associated_token_address)])?
[0]
.is_none();
.get_multiple_accounts(&[pubkey_from_spl_token(&associated_token_address)])?[0]
.is_none();
if do_create_associated_token_account {
*created_accounts += 1;
}

View File

@ -4,16 +4,13 @@ use crate::{
};
use console::style;
use solana_account_decoder::parse_token::{
pubkey_from_spl_token_v2_0, real_number_string, real_number_string_trimmed,
spl_token_v2_0_pubkey,
pubkey_from_spl_token, real_number_string, real_number_string_trimmed, spl_token_pubkey,
};
use solana_client::rpc_client::RpcClient;
use solana_sdk::{instruction::Instruction, message::Message, native_token::lamports_to_sol};
use solana_transaction_status::parse_token::spl_token_v2_0_instruction;
use spl_associated_token_account_v1_0::{
create_associated_token_account, get_associated_token_address,
};
use spl_token_v2_0::{
use solana_transaction_status::parse_token::spl_token_instruction;
use spl_associated_token_account::{create_associated_token_account, get_associated_token_address};
use spl_token::{
solana_program::program_pack::Pack,
state::{Account as SplTokenAccount, Mint},
};
@ -24,7 +21,7 @@ pub fn update_token_args(client: &RpcClient, args: &mut Option<SplTokenArgs>) ->
.get_account(&spl_token_args.token_account_address)
.unwrap_or_default();
let mint_address =
pubkey_from_spl_token_v2_0(&SplTokenAccount::unpack(&sender_account.data)?.mint);
pubkey_from_spl_token(&SplTokenAccount::unpack(&sender_account.data)?.mint);
spl_token_args.mint = mint_address;
update_decimals(client, args)?;
}
@ -54,33 +51,31 @@ pub fn build_spl_token_instructions(
.as_ref()
.expect("spl_token_args must be some");
let wallet_address = allocation.recipient.parse().unwrap();
let associated_token_address = get_associated_token_address(
&wallet_address,
&spl_token_v2_0_pubkey(&spl_token_args.mint),
);
let associated_token_address =
get_associated_token_address(&wallet_address, &spl_token_pubkey(&spl_token_args.mint));
let mut instructions = vec![];
if do_create_associated_token_account {
let create_associated_token_account_instruction = create_associated_token_account(
&spl_token_v2_0_pubkey(&args.fee_payer.pubkey()),
&spl_token_pubkey(&args.fee_payer.pubkey()),
&wallet_address,
&spl_token_v2_0_pubkey(&spl_token_args.mint),
&spl_token_pubkey(&spl_token_args.mint),
);
instructions.push(spl_token_v2_0_instruction(
instructions.push(spl_token_instruction(
create_associated_token_account_instruction,
));
}
let spl_instruction = spl_token_v2_0::instruction::transfer_checked(
&spl_token_v2_0::id(),
&spl_token_v2_0_pubkey(&spl_token_args.token_account_address),
&spl_token_v2_0_pubkey(&spl_token_args.mint),
let spl_instruction = spl_token::instruction::transfer_checked(
&spl_token::id(),
&spl_token_pubkey(&spl_token_args.token_account_address),
&spl_token_pubkey(&spl_token_args.mint),
&associated_token_address,
&spl_token_v2_0_pubkey(&args.sender_keypair.pubkey()),
&spl_token_pubkey(&args.sender_keypair.pubkey()),
&[],
allocation.amount,
spl_token_args.decimals,
)
.unwrap();
instructions.push(spl_token_v2_0_instruction(spl_instruction));
instructions.push(spl_token_instruction(spl_instruction));
instructions
}
@ -136,11 +131,11 @@ pub fn print_token_balances(
let address = allocation.recipient.parse().unwrap();
let expected = allocation.amount;
let associated_token_address = get_associated_token_address(
&spl_token_v2_0_pubkey(&address),
&spl_token_v2_0_pubkey(&spl_token_args.mint),
&spl_token_pubkey(&address),
&spl_token_pubkey(&spl_token_args.mint),
);
let recipient_account = client
.get_account(&pubkey_from_spl_token_v2_0(&associated_token_address))
.get_account(&pubkey_from_spl_token(&associated_token_address))
.unwrap_or_default();
let (actual, difference) = if let Ok(recipient_token) =
SplTokenAccount::unpack(&recipient_account.data)

View File

@ -25,9 +25,9 @@ solana-metrics = { path = "../metrics", version = "=1.9.0" }
solana-runtime = { path = "../runtime", version = "=1.9.0" }
solana-sdk = { path = "../sdk", version = "=1.9.0" }
solana-vote-program = { path = "../programs/vote", version = "=1.9.0" }
spl-associated-token-account-v1-0 = { package = "spl-associated-token-account", version = "=1.0.3", features = ["no-entrypoint"] }
spl-associated-token-account = { version = "=1.0.3", features = ["no-entrypoint"] }
spl-memo = { version = "=3.0.1", features = ["no-entrypoint"] }
spl-token-v2-0 = { package = "spl-token", version = "=3.2.0", features = ["no-entrypoint"] }
spl-token = { version = "=3.2.0", features = ["no-entrypoint"] }
thiserror = "1.0"
[package.metadata.docs.rs]

View File

@ -6,10 +6,10 @@ use {
solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey},
};
// A helper function to convert spl_associated_token_account_v1_0::id() as spl_sdk::pubkey::Pubkey
// A helper function to convert spl_associated_token_account::id() as spl_sdk::pubkey::Pubkey
// to solana_sdk::pubkey::Pubkey
pub fn spl_associated_token_id_v1_0() -> Pubkey {
Pubkey::new_from_array(spl_associated_token_account_v1_0::id().to_bytes())
pub fn spl_associated_token_id() -> Pubkey {
Pubkey::new_from_array(spl_associated_token_account::id().to_bytes())
}
pub fn parse_associated_token(
@ -51,7 +51,7 @@ fn check_num_associated_token_accounts(
mod test {
use {
super::*,
spl_associated_token_account_v1_0::{
spl_associated_token_account::{
create_associated_token_account,
solana_program::{
instruction::CompiledInstruction as SplAssociatedTokenCompiledInstruction,

View File

@ -1,7 +1,7 @@
use {
crate::{
extract_memos::{spl_memo_id_v1, spl_memo_id_v3},
parse_associated_token::{parse_associated_token, spl_associated_token_id_v1_0},
parse_associated_token::{parse_associated_token, spl_associated_token_id},
parse_bpf_loader::{parse_bpf_loader, parse_bpf_upgradeable_loader},
parse_stake::parse_stake,
parse_system::parse_system,
@ -10,7 +10,7 @@ use {
},
inflector::Inflector,
serde_json::Value,
solana_account_decoder::parse_token::spl_token_id_v2_0,
solana_account_decoder::parse_token::spl_token_id,
solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey, stake, system_program},
std::{
collections::HashMap,
@ -20,14 +20,14 @@ use {
};
lazy_static! {
static ref ASSOCIATED_TOKEN_PROGRAM_ID: Pubkey = spl_associated_token_id_v1_0();
static ref ASSOCIATED_TOKEN_PROGRAM_ID: Pubkey = spl_associated_token_id();
static ref BPF_LOADER_PROGRAM_ID: Pubkey = solana_sdk::bpf_loader::id();
static ref BPF_UPGRADEABLE_LOADER_PROGRAM_ID: Pubkey = solana_sdk::bpf_loader_upgradeable::id();
static ref MEMO_V1_PROGRAM_ID: Pubkey = spl_memo_id_v1();
static ref MEMO_V3_PROGRAM_ID: Pubkey = spl_memo_id_v3();
static ref STAKE_PROGRAM_ID: Pubkey = stake::program::id();
static ref SYSTEM_PROGRAM_ID: Pubkey = system_program::id();
static ref TOKEN_PROGRAM_ID: Pubkey = spl_token_id_v2_0();
static ref TOKEN_PROGRAM_ID: Pubkey = spl_token_id();
static ref VOTE_PROGRAM_ID: Pubkey = solana_vote_program::id();
static ref PARSABLE_PROGRAM_IDS: HashMap<Pubkey, ParsableProgram> = {
let mut m = HashMap::new();

View File

@ -3,12 +3,12 @@ use {
check_num_accounts, ParsableProgram, ParseInstructionError, ParsedInstructionEnum,
},
serde_json::{json, Map, Value},
solana_account_decoder::parse_token::{pubkey_from_spl_token_v2_0, token_amount_to_ui_amount},
solana_account_decoder::parse_token::{pubkey_from_spl_token, token_amount_to_ui_amount},
solana_sdk::{
instruction::{AccountMeta, CompiledInstruction, Instruction},
pubkey::Pubkey,
},
spl_token_v2_0::{
spl_token::{
instruction::{AuthorityType, TokenInstruction},
solana_program::{
instruction::Instruction as SplTokenInstruction, program_option::COption,
@ -438,14 +438,14 @@ fn check_num_token_accounts(accounts: &[u8], num: usize) -> Result<(), ParseInst
check_num_accounts(accounts, num, ParsableProgram::SplToken)
}
pub fn spl_token_v2_0_instruction(instruction: SplTokenInstruction) -> Instruction {
pub fn spl_token_instruction(instruction: SplTokenInstruction) -> Instruction {
Instruction {
program_id: pubkey_from_spl_token_v2_0(&instruction.program_id),
program_id: pubkey_from_spl_token(&instruction.program_id),
accounts: instruction
.accounts
.iter()
.map(|meta| AccountMeta {
pubkey: pubkey_from_spl_token_v2_0(&meta.pubkey),
pubkey: pubkey_from_spl_token(&meta.pubkey),
is_signer: meta.is_signer,
is_writable: meta.is_writable,
})
@ -459,7 +459,7 @@ mod test {
use {
super::*,
solana_sdk::instruction::CompiledInstruction,
spl_token_v2_0::{
spl_token::{
instruction::*,
solana_program::{
instruction::CompiledInstruction as SplTokenCompiledInstruction, message::Message,
@ -493,7 +493,7 @@ mod test {
// Test InitializeMint variations
let initialize_mint_ix = initialize_mint(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[0]),
&convert_pubkey(keys[2]),
Some(&convert_pubkey(keys[3])),
@ -517,7 +517,7 @@ mod test {
);
let initialize_mint_ix = initialize_mint(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[0]),
&convert_pubkey(keys[2]),
None,
@ -541,7 +541,7 @@ mod test {
// Test InitializeAccount
let initialize_account_ix = initialize_account(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[0]),
&convert_pubkey(keys[1]),
&convert_pubkey(keys[2]),
@ -564,7 +564,7 @@ mod test {
// Test InitializeMultisig
let initialize_multisig_ix = initialize_multisig(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[0]),
&[
&convert_pubkey(keys[2]),
@ -591,7 +591,7 @@ mod test {
// Test Transfer, incl multisig
let transfer_ix = transfer(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[1]),
&convert_pubkey(keys[2]),
&convert_pubkey(keys[0]),
@ -615,7 +615,7 @@ mod test {
);
let transfer_ix = transfer(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[2]),
&convert_pubkey(keys[3]),
&convert_pubkey(keys[4]),
@ -641,7 +641,7 @@ mod test {
// Test Approve, incl multisig
let approve_ix = approve(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[1]),
&convert_pubkey(keys[2]),
&convert_pubkey(keys[0]),
@ -665,7 +665,7 @@ mod test {
);
let approve_ix = approve(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[2]),
&convert_pubkey(keys[3]),
&convert_pubkey(keys[4]),
@ -691,7 +691,7 @@ mod test {
// Test Revoke
let revoke_ix = revoke(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[1]),
&convert_pubkey(keys[0]),
&[],
@ -712,7 +712,7 @@ mod test {
// Test SetOwner
let set_authority_ix = set_authority(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[0]),
Some(&convert_pubkey(keys[2])),
AuthorityType::FreezeAccount,
@ -736,7 +736,7 @@ mod test {
);
let set_authority_ix = set_authority(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[1]),
None,
AuthorityType::CloseAccount,
@ -762,7 +762,7 @@ mod test {
// Test MintTo
let mint_to_ix = mint_to(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[1]),
&convert_pubkey(keys[2]),
&convert_pubkey(keys[0]),
@ -787,7 +787,7 @@ mod test {
// Test Burn
let burn_ix = burn(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[1]),
&convert_pubkey(keys[2]),
&convert_pubkey(keys[0]),
@ -812,7 +812,7 @@ mod test {
// Test CloseAccount
let close_account_ix = close_account(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[1]),
&convert_pubkey(keys[2]),
&convert_pubkey(keys[0]),
@ -835,7 +835,7 @@ mod test {
// Test FreezeAccount
let freeze_account_ix = freeze_account(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[1]),
&convert_pubkey(keys[2]),
&convert_pubkey(keys[0]),
@ -858,7 +858,7 @@ mod test {
// Test ThawAccount
let thaw_account_ix = thaw_account(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[1]),
&convert_pubkey(keys[2]),
&convert_pubkey(keys[0]),
@ -881,7 +881,7 @@ mod test {
// Test TransferChecked, incl multisig
let transfer_ix = transfer_checked(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[0]),
&convert_pubkey(keys[1]),
&convert_pubkey(keys[2]),
@ -913,7 +913,7 @@ mod test {
);
let transfer_ix = transfer_checked(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[2]),
&convert_pubkey(keys[3]),
&convert_pubkey(keys[4]),
@ -947,7 +947,7 @@ mod test {
// Test ApproveChecked, incl multisig
let approve_ix = approve_checked(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[1]),
&convert_pubkey(keys[2]),
&convert_pubkey(keys[3]),
@ -979,7 +979,7 @@ mod test {
);
let approve_ix = approve_checked(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[2]),
&convert_pubkey(keys[3]),
&convert_pubkey(keys[4]),
@ -1013,7 +1013,7 @@ mod test {
// Test MintToChecked
let mint_to_ix = mint_to_checked(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[1]),
&convert_pubkey(keys[2]),
&convert_pubkey(keys[0]),
@ -1044,7 +1044,7 @@ mod test {
// Test BurnChecked
let burn_ix = burn_checked(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[1]),
&convert_pubkey(keys[2]),
&convert_pubkey(keys[0]),
@ -1074,7 +1074,7 @@ mod test {
);
// Test SyncNative
let sync_native_ix = sync_native(&spl_token_v2_0::id(), &convert_pubkey(keys[0])).unwrap();
let sync_native_ix = sync_native(&spl_token::id(), &convert_pubkey(keys[0])).unwrap();
let message = Message::new(&[sync_native_ix], None);
let compiled_instruction = convert_compiled_instruction(&message.instructions[0]);
assert_eq!(
@ -1098,7 +1098,7 @@ mod test {
// Test InitializeMint variations
let initialize_mint_ix = initialize_mint(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[0]),
&convert_pubkey(keys[1]),
Some(&convert_pubkey(keys[2])),
@ -1113,7 +1113,7 @@ mod test {
assert!(parse_token(&compiled_instruction, &keys).is_err());
let initialize_mint_ix = initialize_mint(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[0]),
&convert_pubkey(keys[1]),
None,
@ -1129,7 +1129,7 @@ mod test {
// Test InitializeAccount
let initialize_account_ix = initialize_account(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[0]),
&convert_pubkey(keys[1]),
&convert_pubkey(keys[2]),
@ -1144,7 +1144,7 @@ mod test {
// Test InitializeMultisig
let initialize_multisig_ix = initialize_multisig(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[0]),
&[
&convert_pubkey(keys[1]),
@ -1163,7 +1163,7 @@ mod test {
// Test Transfer, incl multisig
let transfer_ix = transfer(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[1]),
&convert_pubkey(keys[2]),
&convert_pubkey(keys[0]),
@ -1179,7 +1179,7 @@ mod test {
assert!(parse_token(&compiled_instruction, &keys).is_err());
let transfer_ix = transfer(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[2]),
&convert_pubkey(keys[3]),
&convert_pubkey(keys[4]),
@ -1196,7 +1196,7 @@ mod test {
// Test Approve, incl multisig
let approve_ix = approve(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[1]),
&convert_pubkey(keys[2]),
&convert_pubkey(keys[0]),
@ -1212,7 +1212,7 @@ mod test {
assert!(parse_token(&compiled_instruction, &keys).is_err());
let approve_ix = approve(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[2]),
&convert_pubkey(keys[3]),
&convert_pubkey(keys[4]),
@ -1229,7 +1229,7 @@ mod test {
// Test Revoke
let revoke_ix = revoke(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[1]),
&convert_pubkey(keys[0]),
&[],
@ -1244,7 +1244,7 @@ mod test {
// Test SetAuthority
let set_authority_ix = set_authority(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[1]),
Some(&convert_pubkey(keys[2])),
AuthorityType::FreezeAccount,
@ -1261,7 +1261,7 @@ mod test {
// Test MintTo
let mint_to_ix = mint_to(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[1]),
&convert_pubkey(keys[2]),
&convert_pubkey(keys[0]),
@ -1278,7 +1278,7 @@ mod test {
// Test Burn
let burn_ix = burn(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[1]),
&convert_pubkey(keys[2]),
&convert_pubkey(keys[0]),
@ -1295,7 +1295,7 @@ mod test {
// Test CloseAccount
let close_account_ix = close_account(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[1]),
&convert_pubkey(keys[2]),
&convert_pubkey(keys[0]),
@ -1311,7 +1311,7 @@ mod test {
// Test FreezeAccount
let freeze_account_ix = freeze_account(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[1]),
&convert_pubkey(keys[2]),
&convert_pubkey(keys[0]),
@ -1327,7 +1327,7 @@ mod test {
// Test ThawAccount
let thaw_account_ix = thaw_account(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[1]),
&convert_pubkey(keys[2]),
&convert_pubkey(keys[0]),
@ -1343,7 +1343,7 @@ mod test {
// Test TransferChecked, incl multisig
let transfer_ix = transfer_checked(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[1]),
&convert_pubkey(keys[2]),
&convert_pubkey(keys[3]),
@ -1361,7 +1361,7 @@ mod test {
assert!(parse_token(&compiled_instruction, &keys).is_err());
let transfer_ix = transfer_checked(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[2]),
&convert_pubkey(keys[3]),
&convert_pubkey(keys[4]),
@ -1380,7 +1380,7 @@ mod test {
// Test ApproveChecked, incl multisig
let approve_ix = approve_checked(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[1]),
&convert_pubkey(keys[2]),
&convert_pubkey(keys[3]),
@ -1398,7 +1398,7 @@ mod test {
assert!(parse_token(&compiled_instruction, &keys).is_err());
let approve_ix = approve_checked(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[2]),
&convert_pubkey(keys[3]),
&convert_pubkey(keys[4]),
@ -1417,7 +1417,7 @@ mod test {
// Test MintToChecked
let mint_to_ix = mint_to_checked(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[1]),
&convert_pubkey(keys[2]),
&convert_pubkey(keys[0]),
@ -1435,7 +1435,7 @@ mod test {
// Test BurnChecked
let burn_ix = burn_checked(
&spl_token_v2_0::id(),
&spl_token::id(),
&convert_pubkey(keys[1]),
&convert_pubkey(keys[2]),
&convert_pubkey(keys[0]),
@ -1452,7 +1452,7 @@ mod test {
assert!(parse_token(&compiled_instruction, &keys).is_err());
// Test SyncNative
let sync_native_ix = sync_native(&spl_token_v2_0::id(), &convert_pubkey(keys[0])).unwrap();
let sync_native_ix = sync_native(&spl_token::id(), &convert_pubkey(keys[0])).unwrap();
let message = Message::new(&[sync_native_ix], None);
let mut compiled_instruction = convert_compiled_instruction(&message.instructions[0]);
assert!(parse_token(&compiled_instruction, &[]).is_err());

View File

@ -1,14 +1,14 @@
use {
crate::TransactionTokenBalance,
solana_account_decoder::parse_token::{
pubkey_from_spl_token_v2_0, spl_token_id_v2_0, spl_token_v2_0_native_mint,
token_amount_to_ui_amount, UiTokenAmount,
pubkey_from_spl_token, spl_token_id, spl_token_native_mint, token_amount_to_ui_amount,
UiTokenAmount,
},
solana_measure::measure::Measure,
solana_metrics::datapoint_debug,
solana_runtime::{bank::Bank, transaction_batch::TransactionBatch},
solana_sdk::{account::ReadableAccount, pubkey::Pubkey},
spl_token_v2_0::{
spl_token::{
solana_program::program_pack::Pack,
state::{Account as TokenAccount, Mint},
},
@ -36,12 +36,12 @@ impl TransactionTokenBalancesSet {
}
fn is_token_program(program_id: &Pubkey) -> bool {
program_id == &spl_token_id_v2_0()
program_id == &spl_token_id()
}
fn get_mint_decimals(bank: &Bank, mint: &Pubkey) -> Option<u8> {
if mint == &spl_token_v2_0_native_mint() {
Some(spl_token_v2_0::native_mint::DECIMALS)
if mint == &spl_token_native_mint() {
Some(spl_token::native_mint::DECIMALS)
} else {
let mint_account = bank.get_account(mint)?;
@ -113,7 +113,7 @@ fn collect_token_balance_from_account(
let account = bank.get_account(account_id)?;
let token_account = TokenAccount::unpack(account.data()).ok()?;
let mint = pubkey_from_spl_token_v2_0(&token_account.mint);
let mint = pubkey_from_spl_token(&token_account.mint);
let decimals = mint_decimals.get(&mint).cloned().or_else(|| {
let decimals = get_mint_decimals(bank, &mint)?;