rpc: Support token-2022 in token-specific calls (#25150)
* rpc: Support token-2022 in token-specific calls * Address feedback
This commit is contained in:
parent
dff089e0dd
commit
0820065c98
|
@ -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,
|
||||
|
@ -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);
|
||||
|
@ -73,6 +72,7 @@ pub enum ParsableAccount {
|
|||
Config,
|
||||
Nonce,
|
||||
SplToken,
|
||||
SplToken2022,
|
||||
Stake,
|
||||
Sysvar,
|
||||
Vote,
|
||||
|
@ -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)?)?,
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
]);
|
||||
|
|
1355
rpc/src/rpc.rs
1355
rpc/src/rpc.rs
File diff suppressed because it is too large
Load Diff
|
@ -4,7 +4,7 @@ use crate::inline_spl_token::{self, GenericTokenAccount};
|
|||
solana_sdk::declare_id!("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb");
|
||||
|
||||
// `spl_token_program_2022::extension::AccountType::Account` ordinal value
|
||||
const ACCOUNTTYPE_ACCOUNT: u8 = 2;
|
||||
pub const ACCOUNTTYPE_ACCOUNT: u8 = 2;
|
||||
|
||||
pub struct Account;
|
||||
impl GenericTokenAccount for Account {
|
||||
|
|
Loading…
Reference in New Issue