Clean up Spl type conversions (#31845)

* Use spl-token ids directly in program-id checks

* Remove id redefinitions

* Deprecate pubkey_from_spl_token and remove usage

* Deprecate spl_token_pubkey and remove usage

* Deprecate native mint helpers and remove usage

* Deprecate spl_token_instruction and remove usage
This commit is contained in:
Tyera 2023-05-30 14:34:38 -06:00 committed by GitHub
parent f63f811170
commit 6bd4ae6955
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 174 additions and 227 deletions

View File

@ -1,13 +1,9 @@
use { use {
crate::{ crate::{
parse_address_lookup_table::parse_address_lookup_table, parse_address_lookup_table::parse_address_lookup_table,
parse_bpf_loader::parse_bpf_upgradeable_loader, parse_bpf_loader::parse_bpf_upgradeable_loader, parse_config::parse_config,
parse_config::parse_config, parse_nonce::parse_nonce, parse_stake::parse_stake, parse_sysvar::parse_sysvar,
parse_nonce::parse_nonce, parse_token::parse_token, parse_vote::parse_vote,
parse_stake::parse_stake,
parse_sysvar::parse_sysvar,
parse_token::{parse_token, spl_token_2022_id, spl_token_id},
parse_vote::parse_vote,
}, },
inflector::Inflector, inflector::Inflector,
serde_json::Value, serde_json::Value,
@ -38,8 +34,8 @@ lazy_static! {
); );
m.insert(*CONFIG_PROGRAM_ID, ParsableAccount::Config); m.insert(*CONFIG_PROGRAM_ID, ParsableAccount::Config);
m.insert(*SYSTEM_PROGRAM_ID, ParsableAccount::Nonce); m.insert(*SYSTEM_PROGRAM_ID, ParsableAccount::Nonce);
m.insert(spl_token_id(), ParsableAccount::SplToken); m.insert(spl_token::id(), ParsableAccount::SplToken);
m.insert(spl_token_2022_id(), ParsableAccount::SplToken2022); m.insert(spl_token_2022::id(), ParsableAccount::SplToken2022);
m.insert(*STAKE_PROGRAM_ID, ParsableAccount::Stake); m.insert(*STAKE_PROGRAM_ID, ParsableAccount::Stake);
m.insert(*SYSVAR_PROGRAM_ID, ParsableAccount::Sysvar); m.insert(*SYSVAR_PROGRAM_ID, ParsableAccount::Sysvar);
m.insert(*VOTE_PROGRAM_ID, ParsableAccount::Vote); m.insert(*VOTE_PROGRAM_ID, ParsableAccount::Vote);

View File

@ -16,45 +16,43 @@ use {
std::str::FromStr, std::str::FromStr,
}; };
// A helper function to convert spl_token::id() as spl_sdk::pubkey::Pubkey to
// solana_sdk::pubkey::Pubkey
pub(crate) fn spl_token_id() -> Pubkey {
Pubkey::new_from_array(spl_token::id().to_bytes())
}
// A helper function to convert spl_token_2022::id() as spl_sdk::pubkey::Pubkey to
// solana_sdk::pubkey::Pubkey
pub(crate) fn spl_token_2022_id() -> Pubkey {
Pubkey::new_from_array(spl_token_2022::id().to_bytes())
}
// Returns all known SPL Token program ids // Returns all known SPL Token program ids
pub fn spl_token_ids() -> Vec<Pubkey> { pub fn spl_token_ids() -> Vec<Pubkey> {
vec![spl_token_id(), spl_token_2022_id()] vec![spl_token::id(), spl_token_2022::id()]
} }
// Check if the provided program id as a known SPL Token program id // Check if the provided program id as a known SPL Token program id
pub fn is_known_spl_token_id(program_id: &Pubkey) -> bool { pub fn is_known_spl_token_id(program_id: &Pubkey) -> bool {
*program_id == spl_token_id() || *program_id == spl_token_2022_id() *program_id == spl_token::id() || *program_id == spl_token_2022::id()
} }
// A helper function to convert spl_token::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 // solana_sdk::pubkey::Pubkey
#[deprecated(
since = "1.16.0",
note = "Pubkey conversions no longer needed. Please use spl_token::native_mint::id() directly"
)]
pub fn spl_token_native_mint() -> Pubkey { pub fn spl_token_native_mint() -> Pubkey {
Pubkey::new_from_array(spl_token::native_mint::id().to_bytes()) Pubkey::new_from_array(spl_token::native_mint::id().to_bytes())
} }
// The program id of the `spl_token_native_mint` account // The program id of the `spl_token_native_mint` account
#[deprecated(
since = "1.16.0",
note = "Pubkey conversions no longer needed. Please use spl_token::id() directly"
)]
pub fn spl_token_native_mint_program_id() -> Pubkey { pub fn spl_token_native_mint_program_id() -> Pubkey {
spl_token_id() spl_token::id()
} }
// A helper function to convert a solana_sdk::pubkey::Pubkey to spl_sdk::pubkey::Pubkey // A helper function to convert a solana_sdk::pubkey::Pubkey to spl_sdk::pubkey::Pubkey
#[deprecated(since = "1.16.0", note = "Pubkey conversions no longer needed")]
pub fn spl_token_pubkey(pubkey: &Pubkey) -> SplTokenPubkey { pub fn spl_token_pubkey(pubkey: &Pubkey) -> SplTokenPubkey {
SplTokenPubkey::new_from_array(pubkey.to_bytes()) SplTokenPubkey::new_from_array(pubkey.to_bytes())
} }
// A helper function to convert a spl_sdk::pubkey::Pubkey to solana_sdk::pubkey::Pubkey // A helper function to convert a spl_sdk::pubkey::Pubkey to solana_sdk::pubkey::Pubkey
#[deprecated(since = "1.16.0", note = "Pubkey conversions no longer needed")]
pub fn pubkey_from_spl_token(pubkey: &SplTokenPubkey) -> Pubkey { pub fn pubkey_from_spl_token(pubkey: &SplTokenPubkey) -> Pubkey {
Pubkey::new_from_array(pubkey.to_bytes()) Pubkey::new_from_array(pubkey.to_bytes())
} }

View File

@ -4,7 +4,6 @@ use {
log::*, log::*,
rand::{thread_rng, Rng}, rand::{thread_rng, Rng},
rayon::prelude::*, rayon::prelude::*,
solana_account_decoder::parse_token::spl_token_pubkey,
solana_clap_utils::{ solana_clap_utils::{
hidden_unless_forced, input_parsers::pubkey_of, input_validators::is_url_or_moniker, hidden_unless_forced, input_parsers::pubkey_of, input_validators::is_url_or_moniker,
}, },
@ -24,7 +23,6 @@ use {
transaction::Transaction, transaction::Transaction,
}, },
solana_streamer::socket::SocketAddrSpace, solana_streamer::socket::SocketAddrSpace,
solana_transaction_status::parse_token::spl_token_instruction,
std::{ std::{
cmp::min, cmp::min,
process::exit, process::exit,
@ -160,15 +158,15 @@ fn make_create_message(
&program_id, &program_id,
)]; )];
if let Some(mint_address) = mint { if let Some(mint_address) = mint {
instructions.push(spl_token_instruction( instructions.push(
spl_token::instruction::initialize_account( spl_token::instruction::initialize_account(
&spl_token::id(), &spl_token::id(),
&spl_token_pubkey(&to_pubkey), &to_pubkey,
&spl_token_pubkey(&mint_address), &mint_address,
&spl_token_pubkey(&base_keypair.pubkey()), &base_keypair.pubkey(),
) )
.unwrap(), .unwrap(),
)); );
} }
instructions instructions
@ -203,16 +201,16 @@ fn make_close_message(
let address = let address =
Pubkey::create_with_seed(&base_keypair.pubkey(), &seed, &program_id).unwrap(); Pubkey::create_with_seed(&base_keypair.pubkey(), &seed, &program_id).unwrap();
if spl_token { if spl_token {
Some(spl_token_instruction( Some(
spl_token::instruction::close_account( spl_token::instruction::close_account(
&spl_token::id(), &spl_token::id(),
&spl_token_pubkey(&address), &address,
&spl_token_pubkey(&keypair.pubkey()), &keypair.pubkey(),
&spl_token_pubkey(&base_keypair.pubkey()), &base_keypair.pubkey(),
&[], &[],
) )
.unwrap(), .unwrap(),
)) )
} else { } else {
Some(system_instruction::transfer_with_seed( Some(system_instruction::transfer_with_seed(
&address, &address,
@ -812,16 +810,14 @@ pub mod test {
spl_mint_len as u64, spl_mint_len as u64,
&inline_spl_token::id(), &inline_spl_token::id(),
), ),
spl_token_instruction( spl_token::instruction::initialize_mint(
spl_token::instruction::initialize_mint( &spl_token::id(),
&spl_token::id(), &spl_mint_keypair.pubkey(),
&spl_token_pubkey(&spl_mint_keypair.pubkey()), &spl_mint_keypair.pubkey(),
&spl_token_pubkey(&spl_mint_keypair.pubkey()), None,
None, 2,
2, )
) .unwrap(),
.unwrap(),
),
], ],
Some(&funder.pubkey()), Some(&funder.pubkey()),
&[&funder, &spl_mint_keypair], &[&funder, &spl_mint_keypair],

View File

@ -1,7 +1,6 @@
use { use {
solana_account_decoder::parse_token::{ solana_account_decoder::parse_token::{
is_known_spl_token_id, pubkey_from_spl_token, spl_token_native_mint, is_known_spl_token_id, token_amount_to_ui_amount, UiTokenAmount,
token_amount_to_ui_amount, UiTokenAmount,
}, },
solana_measure::measure::Measure, solana_measure::measure::Measure,
solana_metrics::datapoint_debug, solana_metrics::datapoint_debug,
@ -18,7 +17,7 @@ use {
}; };
fn get_mint_decimals(bank: &Bank, mint: &Pubkey) -> Option<u8> { fn get_mint_decimals(bank: &Bank, mint: &Pubkey) -> Option<u8> {
if mint == &spl_token_native_mint() { if mint == &spl_token::native_mint::id() {
Some(spl_token::native_mint::DECIMALS) Some(spl_token::native_mint::DECIMALS)
} else { } else {
let mint_account = bank.get_account(mint)?; let mint_account = bank.get_account(mint)?;
@ -101,7 +100,7 @@ fn collect_token_balance_from_account(
} }
let token_account = StateWithExtensions::<TokenAccount>::unpack(account.data()).ok()?; let token_account = StateWithExtensions::<TokenAccount>::unpack(account.data()).ok()?;
let mint = pubkey_from_spl_token(&token_account.base.mint); let mint = token_account.base.mint;
let decimals = mint_decimals.get(&mint).cloned().or_else(|| { let decimals = mint_decimals.get(&mint).cloned().or_else(|| {
let decimals = get_mint_decimals(bank, &mint)?; let decimals = get_mint_decimals(bank, &mint)?;
@ -121,7 +120,6 @@ fn collect_token_balance_from_account(
mod test { mod test {
use { use {
super::*, super::*,
solana_account_decoder::parse_token::{pubkey_from_spl_token, spl_token_pubkey},
solana_sdk::{account::Account, genesis_config::create_genesis_config}, solana_sdk::{account::Account, genesis_config::create_genesis_config},
spl_token_2022::{ spl_token_2022::{
extension::{ extension::{
@ -154,7 +152,7 @@ mod test {
let mint = Account { let mint = Account {
lamports: 100, lamports: 100,
data: data.to_vec(), data: data.to_vec(),
owner: pubkey_from_spl_token(&spl_token::id()), owner: spl_token::id(),
executable: false, executable: false,
rent_epoch: 0, rent_epoch: 0,
}; };
@ -169,8 +167,8 @@ mod test {
let token_owner = Pubkey::new_unique(); let token_owner = Pubkey::new_unique();
let token_data = TokenAccount { let token_data = TokenAccount {
mint: spl_token_pubkey(&mint_pubkey), mint: mint_pubkey,
owner: spl_token_pubkey(&token_owner), owner: token_owner,
amount: 42, amount: 42,
delegate: COption::None, delegate: COption::None,
state: spl_token_2022::state::AccountState::Initialized, state: spl_token_2022::state::AccountState::Initialized,
@ -184,7 +182,7 @@ mod test {
let spl_token_account = Account { let spl_token_account = Account {
lamports: 100, lamports: 100,
data: data.to_vec(), data: data.to_vec(),
owner: pubkey_from_spl_token(&spl_token::id()), owner: spl_token::id(),
executable: false, executable: false,
rent_epoch: 0, rent_epoch: 0,
}; };
@ -197,8 +195,8 @@ mod test {
}; };
let other_mint_data = TokenAccount { let other_mint_data = TokenAccount {
mint: spl_token_pubkey(&other_mint_pubkey), mint: other_mint_pubkey,
owner: spl_token_pubkey(&token_owner), owner: token_owner,
amount: 42, amount: 42,
delegate: COption::None, delegate: COption::None,
state: spl_token_2022::state::AccountState::Initialized, state: spl_token_2022::state::AccountState::Initialized,
@ -212,7 +210,7 @@ mod test {
let other_mint_token_account = Account { let other_mint_token_account = Account {
lamports: 100, lamports: 100,
data: data.to_vec(), data: data.to_vec(),
owner: pubkey_from_spl_token(&spl_token::id()), owner: spl_token::id(),
executable: false, executable: false,
rent_epoch: 0, rent_epoch: 0,
}; };
@ -311,13 +309,13 @@ mod test {
.init_extension::<MintCloseAuthority>(true) .init_extension::<MintCloseAuthority>(true)
.unwrap(); .unwrap();
mint_close_authority.close_authority = mint_close_authority.close_authority =
OptionalNonZeroPubkey::try_from(Some(spl_token_pubkey(&mint_authority))).unwrap(); OptionalNonZeroPubkey::try_from(Some(mint_authority)).unwrap();
let mint_pubkey = Pubkey::new_unique(); let mint_pubkey = Pubkey::new_unique();
let mint = Account { let mint = Account {
lamports: 100, lamports: 100,
data: mint_data.to_vec(), data: mint_data.to_vec(),
owner: pubkey_from_spl_token(&spl_token_2022::id()), owner: spl_token_2022::id(),
executable: false, executable: false,
rent_epoch: 0, rent_epoch: 0,
}; };
@ -332,8 +330,8 @@ mod test {
let token_owner = Pubkey::new_unique(); let token_owner = Pubkey::new_unique();
let token_base = TokenAccount { let token_base = TokenAccount {
mint: spl_token_pubkey(&mint_pubkey), mint: mint_pubkey,
owner: spl_token_pubkey(&token_owner), owner: token_owner,
amount: 42, amount: 42,
delegate: COption::None, delegate: COption::None,
state: spl_token_2022::state::AccountState::Initialized, state: spl_token_2022::state::AccountState::Initialized,
@ -361,7 +359,7 @@ mod test {
let spl_token_account = Account { let spl_token_account = Account {
lamports: 100, lamports: 100,
data: account_data.to_vec(), data: account_data.to_vec(),
owner: pubkey_from_spl_token(&spl_token_2022::id()), owner: spl_token_2022::id(),
executable: false, executable: false,
rent_epoch: 0, rent_epoch: 0,
}; };
@ -374,8 +372,8 @@ mod test {
}; };
let other_mint_token_base = TokenAccount { let other_mint_token_base = TokenAccount {
mint: spl_token_pubkey(&other_mint_pubkey), mint: other_mint_pubkey,
owner: spl_token_pubkey(&token_owner), owner: token_owner,
amount: 42, amount: 42,
delegate: COption::None, delegate: COption::None,
state: spl_token_2022::state::AccountState::Initialized, state: spl_token_2022::state::AccountState::Initialized,
@ -403,7 +401,7 @@ mod test {
let other_mint_token_account = Account { let other_mint_token_account = Account {
lamports: 100, lamports: 100,
data: account_data.to_vec(), data: account_data.to_vec(),
owner: pubkey_from_spl_token(&spl_token_2022::id()), owner: spl_token_2022::id(),
executable: false, executable: false,
rent_epoch: 0, rent_epoch: 0,
}; };

View File

@ -1,11 +1,8 @@
use { use {
jsonrpc_core::{Error, Result}, jsonrpc_core::{Error, Result},
solana_account_decoder::{ solana_account_decoder::{
parse_account_data::AccountAdditionalData, parse_account_data::AccountAdditionalData, parse_token::get_token_account_mint, UiAccount,
parse_token::{ UiAccountData, UiAccountEncoding,
get_token_account_mint, spl_token_native_mint, spl_token_native_mint_program_id,
},
UiAccount, UiAccountData, UiAccountEncoding,
}, },
solana_rpc_client_api::response::RpcKeyedAccount, solana_rpc_client_api::response::RpcKeyedAccount,
solana_runtime::bank::Bank, solana_runtime::bank::Bank,
@ -76,11 +73,8 @@ where
/// Analyze a mint Pubkey that may be the native_mint and get the mint-account owner (token /// Analyze a mint Pubkey that may be the native_mint and get the mint-account owner (token
/// program_id) and decimals /// program_id) and decimals
pub fn get_mint_owner_and_decimals(bank: &Arc<Bank>, mint: &Pubkey) -> Result<(Pubkey, u8)> { pub fn get_mint_owner_and_decimals(bank: &Arc<Bank>, mint: &Pubkey) -> Result<(Pubkey, u8)> {
if mint == &spl_token_native_mint() { if mint == &spl_token::native_mint::id() {
Ok(( Ok((spl_token::id(), spl_token::native_mint::DECIMALS))
spl_token_native_mint_program_id(),
spl_token::native_mint::DECIMALS,
))
} else { } else {
let mint_account = bank.get_account(mint).ok_or_else(|| { let mint_account = bank.get_account(mint).ok_or_else(|| {
Error::invalid_params("Invalid param: could not find mint".to_string()) Error::invalid_params("Invalid param: could not find mint".to_string())

View File

@ -14,9 +14,7 @@ use {
indicatif::{ProgressBar, ProgressStyle}, indicatif::{ProgressBar, ProgressStyle},
pickledb::PickleDb, pickledb::PickleDb,
serde::{Deserialize, Serialize}, serde::{Deserialize, Serialize},
solana_account_decoder::parse_token::{ solana_account_decoder::parse_token::real_number_string,
pubkey_from_spl_token, real_number_string, spl_token_pubkey,
},
solana_rpc_client::rpc_client::RpcClient, solana_rpc_client::rpc_client::RpcClient,
solana_rpc_client_api::{ solana_rpc_client_api::{
client_error::{Error as ClientError, Result as ClientResult}, client_error::{Error as ClientError, Result as ClientResult},
@ -309,11 +307,7 @@ fn build_messages(
.iter() .iter()
.map(|x| { .map(|x| {
let wallet_address = x.recipient.parse().unwrap(); let wallet_address = x.recipient.parse().unwrap();
let associated_token_address = get_associated_token_address( get_associated_token_address(&wallet_address, &spl_token_args.mint)
&wallet_address,
&spl_token_pubkey(&spl_token_args.mint),
);
pubkey_from_spl_token(&associated_token_address)
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let mut maybe_accounts = client.get_multiple_accounts(&associated_token_addresses)?; let mut maybe_accounts = client.get_multiple_accounts(&associated_token_addresses)?;

View File

@ -4,12 +4,9 @@ use {
commands::{get_fee_estimate_for_messages, Allocation, Error, FundingSource}, commands::{get_fee_estimate_for_messages, Allocation, Error, FundingSource},
}, },
console::style, console::style,
solana_account_decoder::parse_token::{ solana_account_decoder::parse_token::{real_number_string, real_number_string_trimmed},
pubkey_from_spl_token, real_number_string, real_number_string_trimmed, spl_token_pubkey,
},
solana_rpc_client::rpc_client::RpcClient, solana_rpc_client::rpc_client::RpcClient,
solana_sdk::{instruction::Instruction, message::Message, native_token::lamports_to_sol}, solana_sdk::{instruction::Instruction, message::Message, native_token::lamports_to_sol},
solana_transaction_status::parse_token::spl_token_instruction,
spl_associated_token_account::{ spl_associated_token_account::{
get_associated_token_address, instruction::create_associated_token_account, get_associated_token_address, instruction::create_associated_token_account,
}, },
@ -24,9 +21,7 @@ pub fn update_token_args(client: &RpcClient, args: &mut Option<SplTokenArgs>) ->
let sender_account = client let sender_account = client
.get_account(&spl_token_args.token_account_address) .get_account(&spl_token_args.token_account_address)
.unwrap_or_default(); .unwrap_or_default();
let mint_address = spl_token_args.mint = 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)?; update_decimals(client, args)?;
} }
Ok(()) Ok(())
@ -56,31 +51,29 @@ pub fn build_spl_token_instructions(
.expect("spl_token_args must be some"); .expect("spl_token_args must be some");
let wallet_address = allocation.recipient.parse().unwrap(); let wallet_address = allocation.recipient.parse().unwrap();
let associated_token_address = let associated_token_address =
get_associated_token_address(&wallet_address, &spl_token_pubkey(&spl_token_args.mint)); get_associated_token_address(&wallet_address, &spl_token_args.mint);
let mut instructions = vec![]; let mut instructions = vec![];
if do_create_associated_token_account { if do_create_associated_token_account {
let create_associated_token_account_instruction = create_associated_token_account( instructions.push(create_associated_token_account(
&spl_token_pubkey(&args.fee_payer.pubkey()), &args.fee_payer.pubkey(),
&wallet_address, &wallet_address,
&spl_token_pubkey(&spl_token_args.mint), &spl_token_args.mint,
&spl_token::id(), &spl_token::id(),
);
instructions.push(spl_token_instruction(
create_associated_token_account_instruction,
)); ));
} }
let spl_instruction = spl_token::instruction::transfer_checked( instructions.push(
&spl_token::id(), spl_token::instruction::transfer_checked(
&spl_token_pubkey(&spl_token_args.token_account_address), &spl_token::id(),
&spl_token_pubkey(&spl_token_args.mint), &spl_token_args.token_account_address,
&associated_token_address, &spl_token_args.mint,
&spl_token_pubkey(&args.sender_keypair.pubkey()), &associated_token_address,
&[], &args.sender_keypair.pubkey(),
allocation.amount, &[],
spl_token_args.decimals, allocation.amount,
) spl_token_args.decimals,
.unwrap(); )
instructions.push(spl_token_instruction(spl_instruction)); .unwrap(),
);
instructions instructions
} }
@ -128,12 +121,9 @@ pub fn print_token_balances(
) -> Result<(), Error> { ) -> Result<(), Error> {
let address = allocation.recipient.parse().unwrap(); let address = allocation.recipient.parse().unwrap();
let expected = allocation.amount; let expected = allocation.amount;
let associated_token_address = get_associated_token_address( let associated_token_address = get_associated_token_address(&address, &spl_token_args.mint);
&spl_token_pubkey(&address),
&spl_token_pubkey(&spl_token_args.mint),
);
let recipient_account = client let recipient_account = client
.get_account(&pubkey_from_spl_token(&associated_token_address)) .get_account(&associated_token_address)
.unwrap_or_default(); .unwrap_or_default();
let (actual, difference) = if let Ok(recipient_token) = let (actual, difference) = if let Ok(recipient_token) =
SplTokenAccount::unpack(&recipient_account.data) SplTokenAccount::unpack(&recipient_account.data)

View File

@ -94,7 +94,6 @@ mod test {
use spl_associated_token_account::create_associated_token_account as create_associated_token_account_deprecated; use spl_associated_token_account::create_associated_token_account as create_associated_token_account_deprecated;
use { use {
super::*, super::*,
solana_account_decoder::parse_token::pubkey_from_spl_token,
spl_associated_token_account::{ spl_associated_token_account::{
get_associated_token_address, get_associated_token_address_with_program_id, get_associated_token_address, get_associated_token_address_with_program_id,
instruction::{ instruction::{
@ -122,14 +121,6 @@ mod test {
} }
} }
fn convert_account_keys(message: &Message) -> Vec<Pubkey> {
message
.account_keys
.iter()
.map(pubkey_from_spl_token)
.collect()
}
#[test] #[test]
fn test_parse_create_deprecated() { fn test_parse_create_deprecated() {
let funder = Pubkey::new_unique(); let funder = Pubkey::new_unique();
@ -159,7 +150,7 @@ mod test {
assert_eq!( assert_eq!(
parse_associated_token( parse_associated_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
expected_parsed_ix, expected_parsed_ix,
@ -175,7 +166,7 @@ mod test {
assert_eq!( assert_eq!(
parse_associated_token( parse_associated_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
expected_parsed_ix, expected_parsed_ix,
@ -185,7 +176,7 @@ mod test {
compiled_instruction.accounts.pop(); compiled_instruction.accounts.pop();
assert!(parse_associated_token( assert!(parse_associated_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.is_err()); .is_err());
} }
@ -212,7 +203,7 @@ mod test {
assert_eq!( assert_eq!(
parse_associated_token( parse_associated_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -230,7 +221,7 @@ mod test {
compiled_instruction.accounts.pop(); compiled_instruction.accounts.pop();
assert!(parse_associated_token( assert!(parse_associated_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.is_err()); .is_err());
} }
@ -257,7 +248,7 @@ mod test {
assert_eq!( assert_eq!(
parse_associated_token( parse_associated_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -275,7 +266,7 @@ mod test {
compiled_instruction.accounts.pop(); compiled_instruction.accounts.pop();
assert!(parse_associated_token( assert!(parse_associated_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.is_err()); .is_err());
} }
@ -312,7 +303,7 @@ mod test {
assert_eq!( assert_eq!(
parse_associated_token( parse_associated_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -331,7 +322,7 @@ mod test {
compiled_instruction.accounts.pop(); compiled_instruction.accounts.pop();
assert!(parse_associated_token( assert!(parse_associated_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.is_err()); .is_err());
} }

View File

@ -8,9 +8,7 @@ use {
transfer_fee::*, transfer_fee::*,
}, },
serde_json::{json, Map, Value}, serde_json::{json, Map, Value},
solana_account_decoder::parse_token::{ solana_account_decoder::parse_token::{token_amount_to_ui_amount, UiAccountState},
pubkey_from_spl_token, token_amount_to_ui_amount, UiAccountState,
},
solana_sdk::{ solana_sdk::{
instruction::{AccountMeta, CompiledInstruction, Instruction}, instruction::{AccountMeta, CompiledInstruction, Instruction},
message::AccountKeys, message::AccountKeys,
@ -699,14 +697,15 @@ fn check_num_token_accounts(accounts: &[u8], num: usize) -> Result<(), ParseInst
check_num_accounts(accounts, num, ParsableProgram::SplToken) check_num_accounts(accounts, num, ParsableProgram::SplToken)
} }
#[deprecated(since = "1.16.0", note = "Instruction conversions no longer needed")]
pub fn spl_token_instruction(instruction: SplTokenInstruction) -> Instruction { pub fn spl_token_instruction(instruction: SplTokenInstruction) -> Instruction {
Instruction { Instruction {
program_id: pubkey_from_spl_token(&instruction.program_id), program_id: instruction.program_id,
accounts: instruction accounts: instruction
.accounts .accounts
.iter() .iter()
.map(|meta| AccountMeta { .map(|meta| AccountMeta {
pubkey: pubkey_from_spl_token(&meta.pubkey), pubkey: meta.pubkey,
is_signer: meta.is_signer, is_signer: meta.is_signer,
is_writable: meta.is_writable, is_writable: meta.is_writable,
}) })
@ -751,14 +750,6 @@ mod test {
} }
} }
pub(super) fn convert_account_keys(message: &Message) -> Vec<Pubkey> {
message
.account_keys
.iter()
.map(pubkey_from_spl_token)
.collect()
}
fn test_parse_token(program_id: &SplTokenPubkey) { fn test_parse_token(program_id: &SplTokenPubkey) {
let mint_pubkey = Pubkey::new_unique(); let mint_pubkey = Pubkey::new_unique();
let mint_authority = Pubkey::new_unique(); let mint_authority = Pubkey::new_unique();
@ -779,7 +770,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -807,7 +798,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -835,7 +826,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -864,7 +855,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -891,7 +882,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -918,7 +909,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -952,7 +943,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -987,7 +978,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -1021,7 +1012,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -1053,7 +1044,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -1086,7 +1077,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -1117,7 +1108,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -1148,7 +1139,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -1176,7 +1167,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -1205,7 +1196,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -1234,7 +1225,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -1263,7 +1254,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -1291,7 +1282,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -1318,7 +1309,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -1345,7 +1336,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -1375,7 +1366,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -1414,7 +1405,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -1455,7 +1446,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -1494,7 +1485,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -1534,7 +1525,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -1569,7 +1560,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -1595,7 +1586,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -1614,7 +1605,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -1637,7 +1628,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -1659,7 +1650,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -1682,7 +1673,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -1702,7 +1693,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -1735,7 +1726,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {

View File

@ -66,7 +66,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -97,7 +97,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -126,7 +126,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -157,7 +157,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {

View File

@ -78,7 +78,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -105,7 +105,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -138,7 +138,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {

View File

@ -68,7 +68,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -99,7 +99,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -128,7 +128,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -159,7 +159,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {

View File

@ -43,7 +43,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -66,7 +66,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {

View File

@ -39,7 +39,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {

View File

@ -62,7 +62,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -98,7 +98,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {

View File

@ -188,7 +188,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -217,7 +217,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -254,7 +254,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -304,7 +304,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -348,7 +348,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -378,7 +378,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -412,7 +412,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -447,7 +447,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -480,7 +480,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -510,7 +510,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {
@ -542,7 +542,7 @@ mod test {
assert_eq!( assert_eq!(
parse_token( parse_token(
&compiled_instruction, &compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None) &AccountKeys::new(&message.account_keys, None)
) )
.unwrap(), .unwrap(),
ParsedInstructionEnum { ParsedInstructionEnum {

View File

@ -868,7 +868,6 @@ mod tests {
super::*, super::*,
rand::{distributions::Uniform, thread_rng, Rng}, rand::{distributions::Uniform, thread_rng, Rng},
serde_json::Value, serde_json::Value,
solana_account_decoder::parse_token::spl_token_pubkey,
solana_core::tower_storage::NullTowerStorage, solana_core::tower_storage::NullTowerStorage,
solana_gossip::cluster_info::ClusterInfo, solana_gossip::cluster_info::ClusterInfo,
solana_ledger::genesis_utils::{create_genesis_config, GenesisConfigInfo}, solana_ledger::genesis_utils::{create_genesis_config, GenesisConfigInfo},
@ -1006,7 +1005,7 @@ mod tests {
let wallet1_pubkey = Pubkey::new_unique(); let wallet1_pubkey = Pubkey::new_unique();
let wallet2_pubkey = Pubkey::new_unique(); let wallet2_pubkey = Pubkey::new_unique();
let non_existent_pubkey = Pubkey::new_unique(); let non_existent_pubkey = Pubkey::new_unique();
let delegate = spl_token_pubkey(&Pubkey::new_unique()); let delegate = Pubkey::new_unique();
let mut num_default_spl_token_program_accounts = 0; let mut num_default_spl_token_program_accounts = 0;
let mut num_default_system_program_accounts = 0; let mut num_default_system_program_accounts = 0;
@ -1068,14 +1067,14 @@ mod tests {
// Add a token account // Add a token account
let mut account1_data = vec![0; TokenAccount::get_packed_len()]; let mut account1_data = vec![0; TokenAccount::get_packed_len()];
let token_account1 = TokenAccount { let token_account1 = TokenAccount {
mint: spl_token_pubkey(&mint1_pubkey), mint: mint1_pubkey,
owner: spl_token_pubkey(&wallet1_pubkey), owner: wallet1_pubkey,
delegate: COption::Some(delegate), delegate: COption::Some(delegate),
amount: 420, amount: 420,
state: TokenAccountState::Initialized, state: TokenAccountState::Initialized,
is_native: COption::None, is_native: COption::None,
delegated_amount: 30, delegated_amount: 30,
close_authority: COption::Some(spl_token_pubkey(&wallet1_pubkey)), close_authority: COption::Some(wallet1_pubkey),
}; };
TokenAccount::pack(token_account1, &mut account1_data).unwrap(); TokenAccount::pack(token_account1, &mut account1_data).unwrap();
let token_account1 = AccountSharedData::from(Account { let token_account1 = AccountSharedData::from(Account {
@ -1089,11 +1088,11 @@ mod tests {
// Add the mint // Add the mint
let mut mint1_data = vec![0; Mint::get_packed_len()]; let mut mint1_data = vec![0; Mint::get_packed_len()];
let mint1_state = Mint { let mint1_state = Mint {
mint_authority: COption::Some(spl_token_pubkey(&wallet1_pubkey)), mint_authority: COption::Some(wallet1_pubkey),
supply: 500, supply: 500,
decimals: 2, decimals: 2,
is_initialized: true, is_initialized: true,
freeze_authority: COption::Some(spl_token_pubkey(&wallet1_pubkey)), freeze_authority: COption::Some(wallet1_pubkey),
}; };
Mint::pack(mint1_state, &mut mint1_data).unwrap(); Mint::pack(mint1_state, &mut mint1_data).unwrap();
let mint_account1 = AccountSharedData::from(Account { let mint_account1 = AccountSharedData::from(Account {
@ -1107,14 +1106,14 @@ mod tests {
// Add another token account with the different owner, but same delegate, and mint // Add another token account with the different owner, but same delegate, and mint
let mut account2_data = vec![0; TokenAccount::get_packed_len()]; let mut account2_data = vec![0; TokenAccount::get_packed_len()];
let token_account2 = TokenAccount { let token_account2 = TokenAccount {
mint: spl_token_pubkey(&mint1_pubkey), mint: mint1_pubkey,
owner: spl_token_pubkey(&wallet2_pubkey), owner: wallet2_pubkey,
delegate: COption::Some(delegate), delegate: COption::Some(delegate),
amount: 420, amount: 420,
state: TokenAccountState::Initialized, state: TokenAccountState::Initialized,
is_native: COption::None, is_native: COption::None,
delegated_amount: 30, delegated_amount: 30,
close_authority: COption::Some(spl_token_pubkey(&wallet2_pubkey)), close_authority: COption::Some(wallet2_pubkey),
}; };
TokenAccount::pack(token_account2, &mut account2_data).unwrap(); TokenAccount::pack(token_account2, &mut account2_data).unwrap();
let token_account2 = AccountSharedData::from(Account { let token_account2 = AccountSharedData::from(Account {
@ -1128,14 +1127,14 @@ mod tests {
// Add another token account with the same owner and delegate but different mint // Add another token account with the same owner and delegate but different mint
let mut account3_data = vec![0; TokenAccount::get_packed_len()]; let mut account3_data = vec![0; TokenAccount::get_packed_len()];
let token_account3 = TokenAccount { let token_account3 = TokenAccount {
mint: spl_token_pubkey(&mint2_pubkey), mint: mint2_pubkey,
owner: spl_token_pubkey(&wallet2_pubkey), owner: wallet2_pubkey,
delegate: COption::Some(delegate), delegate: COption::Some(delegate),
amount: 42, amount: 42,
state: TokenAccountState::Initialized, state: TokenAccountState::Initialized,
is_native: COption::None, is_native: COption::None,
delegated_amount: 30, delegated_amount: 30,
close_authority: COption::Some(spl_token_pubkey(&wallet2_pubkey)), close_authority: COption::Some(wallet2_pubkey),
}; };
TokenAccount::pack(token_account3, &mut account3_data).unwrap(); TokenAccount::pack(token_account3, &mut account3_data).unwrap();
let token_account3 = AccountSharedData::from(Account { let token_account3 = AccountSharedData::from(Account {
@ -1149,11 +1148,11 @@ mod tests {
// Add the new mint // Add the new mint
let mut mint2_data = vec![0; Mint::get_packed_len()]; let mut mint2_data = vec![0; Mint::get_packed_len()];
let mint2_state = Mint { let mint2_state = Mint {
mint_authority: COption::Some(spl_token_pubkey(&wallet2_pubkey)), mint_authority: COption::Some(wallet2_pubkey),
supply: 200, supply: 200,
decimals: 3, decimals: 3,
is_initialized: true, is_initialized: true,
freeze_authority: COption::Some(spl_token_pubkey(&wallet2_pubkey)), freeze_authority: COption::Some(wallet2_pubkey),
}; };
Mint::pack(mint2_state, &mut mint2_data).unwrap(); Mint::pack(mint2_state, &mut mint2_data).unwrap();
let mint_account2 = AccountSharedData::from(Account { let mint_account2 = AccountSharedData::from(Account {
@ -1365,14 +1364,14 @@ mod tests {
let account_pubkey = Pubkey::new_unique(); let account_pubkey = Pubkey::new_unique();
// Add a token account // Add a token account
let token_state = TokenAccount { let token_state = TokenAccount {
mint: spl_token_pubkey(&mint_pubkey), mint: mint_pubkey,
owner: spl_token_pubkey(&owner_pubkey), owner: owner_pubkey,
delegate: COption::Some(spl_token_pubkey(&delagate_pubkey)), delegate: COption::Some(delagate_pubkey),
amount: 100, amount: 100,
state: TokenAccountState::Initialized, state: TokenAccountState::Initialized,
is_native: COption::None, is_native: COption::None,
delegated_amount: 10, delegated_amount: 10,
close_authority: COption::Some(spl_token_pubkey(&owner_pubkey)), close_authority: COption::Some(owner_pubkey),
}; };
TokenAccount::pack(token_state, &mut account_data).unwrap(); TokenAccount::pack(token_state, &mut account_data).unwrap();
let token_account = AccountSharedData::from(Account { let token_account = AccountSharedData::from(Account {
@ -1389,11 +1388,11 @@ mod tests {
.next() .next()
.unwrap()]; .unwrap()];
let mint_state = Mint { let mint_state = Mint {
mint_authority: COption::Some(spl_token_pubkey(&mint_authority_pubkey)), mint_authority: COption::Some(mint_authority_pubkey),
supply: 100 * (num_token_accounts.unwrap_or(1) as u64), supply: 100 * (num_token_accounts.unwrap_or(1) as u64),
decimals: 2, decimals: 2,
is_initialized: true, is_initialized: true,
freeze_authority: COption::Some(spl_token_pubkey(&mint_authority_pubkey)), freeze_authority: COption::Some(mint_authority_pubkey),
}; };
Mint::pack(mint_state, &mut mint_data).unwrap(); Mint::pack(mint_state, &mut mint_data).unwrap();
let mint_account = AccountSharedData::from(Account { let mint_account = AccountSharedData::from(Account {