Skip to content

Commit

Permalink
Merge pull request #103 from Ackee-Blockchain/explorer-maintanance
Browse files Browse the repository at this point in the history
🔥 Removed/Update deprecated functions, removed allow deprecated macros
  • Loading branch information
Ikrk authored Sep 26, 2023
2 parents 5b1f934 + e47065f commit 91f320d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 41 deletions.
8 changes: 3 additions & 5 deletions crates/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ use serde::de::DeserializeOwned;
use solana_account_decoder::parse_token::UiTokenAmount;
use solana_cli_output::display::println_transaction;
use solana_transaction_status::{EncodedConfirmedTransactionWithStatusMeta, UiTransactionEncoding};
// The deprecated `create_associated_token_account` function is used because of different versions
// of some crates are required in this `client` crate and `anchor-spl` crate
#[allow(deprecated)]
use spl_associated_token_account::{create_associated_token_account, get_associated_token_address};
use spl_associated_token_account::get_associated_token_address;
use spl_associated_token_account::instruction::create_associated_token_account;
use std::{mem, rc::Rc};
use std::{thread::sleep, time::Duration};

Expand Down Expand Up @@ -646,11 +644,11 @@ impl Client {
#[throws]
pub async fn create_associated_token_account(&self, owner: &Keypair, mint: Pubkey) -> Pubkey {
self.send_transaction(
#[allow(deprecated)]
&[create_associated_token_account(
&self.payer().pubkey(),
&owner.pubkey(),
&mint,
&spl_token::ID,
)],
&[],
)
Expand Down
30 changes: 8 additions & 22 deletions crates/explorer/src/parse/associated_token_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn parse_associated_token_account(
));
}
}
check_num_associated_token_accounts(&instruction.accounts, 7)?;
check_num_associated_token_accounts(&instruction.accounts, 6)?;
Ok(ParsedInstructionEnum {
instruction_type: "Create".to_string(),
info: json!({
Expand All @@ -27,7 +27,6 @@ pub fn parse_associated_token_account(
"Mint": account_keys[instruction.accounts[3] as usize].to_string(),
"System Program": account_keys[instruction.accounts[4] as usize].to_string(),
"Token Program": account_keys[instruction.accounts[5] as usize].to_string(),
"Rent Sysvar": account_keys[instruction.accounts[6] as usize].to_string(),
}),
})
}
Expand All @@ -42,14 +41,12 @@ fn check_num_associated_token_accounts(
#[cfg(test)]
mod test {
use super::*;
use solana_account_decoder::parse_token::pubkey_from_spl_token;
#[allow(deprecated)]
use spl_associated_token_account::create_associated_token_account as create_associated_token_account_deprecated;
use spl_associated_token_account::instruction::create_associated_token_account;
use spl_associated_token_account::{
get_associated_token_address,
solana_program::{
instruction::CompiledInstruction as SplAssociatedTokenCompiledInstruction,
message::Message, pubkey::Pubkey as SplAssociatedTokenPubkey, sysvar,
message::Message, pubkey::Pubkey as SplAssociatedTokenPubkey,
},
};

Expand All @@ -66,33 +63,23 @@ mod test {
data: instruction.data.clone(),
}
}

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

#[test]
fn test_parse_associated_token_deprecated() {
fn test_parse_associated_token() {
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));
#[allow(deprecated)]
let create_ix = create_associated_token_account_deprecated(
let create_ix = create_associated_token_account(
&convert_pubkey(funder),
&convert_pubkey(wallet_address),
&convert_pubkey(mint),
&&spl_token::id(),
);
let message = Message::new(&[create_ix], None);
let compiled_instruction = convert_compiled_instruction(&message.instructions[0]);
assert_eq!(
parse_associated_token_account(&compiled_instruction, &convert_account_keys(&message))
.unwrap(),
parse_associated_token_account(&compiled_instruction, &message.account_keys).unwrap(),
ParsedInstructionEnum {
instruction_type: "Create".to_string(),
info: json!({
Expand All @@ -101,8 +88,7 @@ mod test {
"Wallet": wallet_address.to_string(),
"Mint": mint.to_string(),
"System Program": solana_sdk::system_program::id().to_string(),
"Token Program": spl_token::id().to_string(),
"Rent Sysvar": sysvar::rent::id().to_string(),
"Token Program": &spl_token::id().to_string(),
})
}
);
Expand Down
17 changes: 4 additions & 13 deletions crates/explorer/src/parse/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,6 @@ fn check_num_token_accounts(accounts: &[u8], num: usize) -> Result<(), ParseInst
#[cfg(test)]
mod test {
use super::*;
use solana_account_decoder::parse_token::pubkey_from_spl_token;
use solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey};
use spl_token::{
instruction::*,
Expand All @@ -533,14 +532,6 @@ mod test {
}
}

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

fn make_coerced_message(
mut instruction: SplTokenInstruction,
program_id: &SplTokenPubkey,
Expand Down Expand Up @@ -573,7 +564,7 @@ mod test {
let message = make_coerced_message(initialize_mint_ix, program_id);
let compiled_instruction = convert_compiled_instruction(&message.instructions[0]);
assert_eq!(
parse_token(&compiled_instruction, &convert_account_keys(&message)).unwrap(),
parse_token(&compiled_instruction, &message.account_keys).unwrap(),
ParsedInstructionEnum {
instruction_type: "initializeMint".to_string(),
info: json!({
Expand All @@ -597,7 +588,7 @@ mod test {
let message = make_coerced_message(initialize_mint_ix, program_id);
let compiled_instruction = convert_compiled_instruction(&message.instructions[0]);
assert_eq!(
parse_token(&compiled_instruction, &convert_account_keys(&message)).unwrap(),
parse_token(&compiled_instruction, &message.account_keys).unwrap(),
ParsedInstructionEnum {
instruction_type: "initializeMint".to_string(),
info: json!({
Expand All @@ -622,7 +613,7 @@ mod test {
let message = make_coerced_message(initialize_account_ix, program_id);
let compiled_instruction = convert_compiled_instruction(&message.instructions[0]);
assert_eq!(
parse_token(&compiled_instruction, &convert_account_keys(&message)).unwrap(),
parse_token(&compiled_instruction, &message.account_keys).unwrap(),
ParsedInstructionEnum {
instruction_type: "initializeAccount".to_string(),
info: json!({
Expand All @@ -645,7 +636,7 @@ mod test {
let message = make_coerced_message(initialize_account_ix, program_id);
let compiled_instruction = convert_compiled_instruction(&message.instructions[0]);
assert_eq!(
parse_token(&compiled_instruction, &convert_account_keys(&message)).unwrap(),
parse_token(&compiled_instruction, &message.account_keys).unwrap(),
ParsedInstructionEnum {
instruction_type: "initializeAccount2".to_string(),
info: json!({
Expand Down
4 changes: 3 additions & 1 deletion crates/explorer/src/parse/vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ fn check_num_vote_accounts(accounts: &[u8], num: usize) -> Result<(), ParseInstr
#[cfg(test)]
mod test {
use super::*;
use solana_program::vote::instruction::CreateVoteAccountConfig;
use solana_sdk::{hash::Hash, message::Message, pubkey::Pubkey, sysvar};
use solana_vote_program::{
vote_instruction,
Expand All @@ -236,11 +237,12 @@ mod test {
commission,
};

let instructions = vote_instruction::create_account(
let instructions = vote_instruction::create_account_with_config(
&Pubkey::new_unique(),
&vote_pubkey,
&vote_init,
lamports,
CreateVoteAccountConfig::default(),
);
let message = Message::new(&instructions, None);
assert_eq!(
Expand Down

0 comments on commit 91f320d

Please sign in to comment.