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

Commit

Permalink
rpc: Support token-2022 in token-specific calls (#25150)
Browse files Browse the repository at this point in the history
* rpc: Support token-2022 in token-specific calls

* Address feedback
  • Loading branch information
joncinque authored May 17, 2022
1 parent dff089e commit 0820065
Show file tree
Hide file tree
Showing 4 changed files with 901 additions and 490 deletions.
10 changes: 5 additions & 5 deletions account-decoder/src/parse_account_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use {
parse_nonce::parse_nonce,
parse_stake::parse_stake,
parse_sysvar::parse_sysvar,
parse_token::{parse_token, spl_token_ids},
parse_token::{parse_token, spl_token_2022_id, spl_token_id},
parse_vote::parse_vote,
},
inflector::Inflector,
Expand All @@ -30,9 +30,8 @@ lazy_static! {
);
m.insert(*CONFIG_PROGRAM_ID, ParsableAccount::Config);
m.insert(*SYSTEM_PROGRAM_ID, ParsableAccount::Nonce);
for spl_token_id in spl_token_ids() {
m.insert(spl_token_id, ParsableAccount::SplToken);
}
m.insert(spl_token_id(), ParsableAccount::SplToken);
m.insert(spl_token_2022_id(), ParsableAccount::SplToken2022);
m.insert(*STAKE_PROGRAM_ID, ParsableAccount::Stake);
m.insert(*SYSVAR_PROGRAM_ID, ParsableAccount::Sysvar);
m.insert(*VOTE_PROGRAM_ID, ParsableAccount::Vote);
Expand Down Expand Up @@ -73,6 +72,7 @@ pub enum ParsableAccount {
Config,
Nonce,
SplToken,
SplToken2022,
Stake,
Sysvar,
Vote,
Expand All @@ -99,7 +99,7 @@ pub fn parse_account_data(
}
ParsableAccount::Config => serde_json::to_value(parse_config(data, pubkey)?)?,
ParsableAccount::Nonce => serde_json::to_value(parse_nonce(data)?)?,
ParsableAccount::SplToken => {
ParsableAccount::SplToken | ParsableAccount::SplToken2022 => {
serde_json::to_value(parse_token(data, additional_data.spl_token_decimals)?)?
}
ParsableAccount::Stake => serde_json::to_value(parse_stake(data)?)?,
Expand Down
6 changes: 3 additions & 3 deletions account-decoder/src/parse_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ use {

// A helper function to convert spl_token::id() as spl_sdk::pubkey::Pubkey to
// solana_sdk::pubkey::Pubkey
fn spl_token_id() -> 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
fn spl_token_2022_id() -> Pubkey {
pub(crate) fn spl_token_2022_id() -> Pubkey {
Pubkey::new_from_array(spl_token_2022::id().to_bytes())
}

Expand Down Expand Up @@ -510,7 +510,7 @@ mod test {
delegate: COption::None,
delegated_amount: 0,
};
let account_size = ExtensionType::get_account_len::<Mint>(&[
let account_size = ExtensionType::get_account_len::<Account>(&[
ExtensionType::ImmutableOwner,
ExtensionType::MemoTransfer,
]);
Expand Down
Loading

0 comments on commit 0820065

Please sign in to comment.