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

Add SPL Token 2022 to the list of known token ids #23067

Merged
merged 3 commits into from
Apr 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
506 changes: 261 additions & 245 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions account-decoder/Cargo.toml
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ solana-config-program = { path = "../programs/config", version = "=1.11.0" }
solana-sdk = { path = "../sdk", version = "=1.11.0" }
solana-vote-program = { path = "../programs/vote", version = "=1.11.0" }
spl-token = { version = "=3.2.0", features = ["no-entrypoint"] }
spl-token-2022 = { version = "=0.1.0", features = ["no-entrypoint"] }
thiserror = "1.0"
zstd = "0.11.1"

10 changes: 8 additions & 2 deletions account-decoder/src/parse_token.rs
Original file line number Diff line number Diff line change
@@ -19,14 +19,20 @@ 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
fn spl_token_2022_id() -> Pubkey {
Pubkey::new_from_array(spl_token_2022::id().to_bytes())
}

// Returns all known SPL Token program ids
pub fn spl_token_ids() -> Vec<Pubkey> {
vec![spl_token_id()]
vec![spl_token_id(), spl_token_2022_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 {
*program_id == spl_token_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
540 changes: 254 additions & 286 deletions programs/bpf/Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions transaction-status/Cargo.toml
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@ solana-vote-program = { path = "../programs/vote", version = "=1.11.0" }
spl-associated-token-account = { version = "=1.0.3", features = ["no-entrypoint"] }
spl-memo = { version = "=3.0.1", features = ["no-entrypoint"] }
spl-token = { version = "=3.2.0", features = ["no-entrypoint"] }
spl-token-2022 = { version = "=0.1.0", features = ["no-entrypoint"] }
thiserror = "1.0"

[package.metadata.docs.rs]
48 changes: 31 additions & 17 deletions transaction-status/src/parse_associated_token.rs
Original file line number Diff line number Diff line change
@@ -51,8 +51,9 @@ fn check_num_associated_token_accounts(
mod test {
use {
super::*,
solana_account_decoder::parse_token::pubkey_from_spl_token,
spl_associated_token_account::{
create_associated_token_account,
create_associated_token_account, get_associated_token_address,
solana_program::{
instruction::CompiledInstruction as SplAssociatedTokenCompiledInstruction,
message::Message, pubkey::Pubkey as SplAssociatedTokenPubkey,
@@ -74,33 +75,46 @@ mod test {
}
}

fn convert_account_keys(message: &Message) -> Vec<Pubkey> {
message
.account_keys
.iter()
.map(pubkey_from_spl_token)
.collect()
}

#[test]
fn test_parse_associated_token() {
let mut keys: Vec<Pubkey> = vec![];
for _ in 0..7 {
keys.push(solana_sdk::pubkey::new_rand());
}
let funder = Pubkey::new_unique();
let wallet_address = Pubkey::new_unique();
let mint = Pubkey::new_unique();
let associated_account_address =
get_associated_token_address(&convert_pubkey(wallet_address), &convert_pubkey(mint));
let rent_sysvar = solana_sdk::sysvar::rent::id();

let create_ix = create_associated_token_account(
&convert_pubkey(keys[0]),
&convert_pubkey(keys[1]),
&convert_pubkey(keys[2]),
&convert_pubkey(funder),
&convert_pubkey(wallet_address),
&convert_pubkey(mint),
);
let message = Message::new(&[create_ix], None);
let compiled_instruction = convert_compiled_instruction(&message.instructions[0]);
let account_keys = AccountKeys::new(&keys, None);
assert_eq!(
parse_associated_token(&compiled_instruction, &account_keys).unwrap(),
parse_associated_token(
&compiled_instruction,
&AccountKeys::new(&convert_account_keys(&message), None)
)
.unwrap(),
ParsedInstructionEnum {
instruction_type: "create".to_string(),
info: json!({
"source": keys[0].to_string(),
"account": keys[1].to_string(),
"wallet": keys[2].to_string(),
"mint": keys[3].to_string(),
"systemProgram": keys[4].to_string(),
"tokenProgram": keys[5].to_string(),
"rentSysvar": keys[6].to_string(),
"source": funder.to_string(),
"account": associated_account_address.to_string(),
"wallet": wallet_address.to_string(),
"mint": mint.to_string(),
"systemProgram": solana_sdk::system_program::id().to_string(),
"tokenProgram": spl_token::id().to_string(),
"rentSysvar": rent_sysvar.to_string(),
})
}
);
737 changes: 453 additions & 284 deletions transaction-status/src/parse_token.rs

Large diffs are not rendered by default.