Skip to content

Commit

Permalink
minimize solana-sdk usage in account-decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinheavey committed Dec 19, 2024
1 parent 22c8951 commit fbc15f1
Show file tree
Hide file tree
Showing 16 changed files with 129 additions and 76 deletions.
15 changes: 15 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions account-decoder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,23 @@ lazy_static = { workspace = true }
serde = { workspace = true }
serde_derive = { workspace = true }
serde_json = { workspace = true }
solana-account = { workspace = true }
solana-account-decoder-client-types = { workspace = true, features = ["zstd"] }
solana-clock = { workspace = true }
solana-config-program = { workspace = true }
solana-epoch-schedule = { workspace = true }
solana-fee-calculator = { workspace = true }
solana-instruction = { workspace = true }
solana-nonce = { workspace = true }
solana-program = { workspace = true }
solana-program-pack = { workspace = true }
solana-pubkey = { workspace = true }
solana-rent = { workspace = true }
solana-sdk = { workspace = true }
solana-sdk-ids = { workspace = true }
solana-slot-hashes = { workspace = true }
solana-slot-history = { workspace = true }
solana-sysvar = { workspace = true }
spl-token = { workspace = true, features = ["no-entrypoint"] }
spl-token-2022 = { workspace = true, features = ["no-entrypoint"] }
spl-token-group-interface = { workspace = true }
Expand All @@ -31,6 +45,8 @@ zstd = { workspace = true }

[dev-dependencies]
assert_matches = { workspace = true }
solana-hash = { workspace = true }
solana-program = { workspace = true, default-features = false }
spl-pod = { workspace = true }

[package.metadata.docs.rs]
Expand Down
6 changes: 4 additions & 2 deletions account-decoder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ pub use solana_account_decoder_client_types::{
use {
crate::parse_account_data::{parse_account_data_v2, AccountAdditionalDataV2},
base64::{prelude::BASE64_STANDARD, Engine},
solana_sdk::{account::ReadableAccount, fee_calculator::FeeCalculator, pubkey::Pubkey},
solana_account::ReadableAccount,
solana_fee_calculator::FeeCalculator,
solana_pubkey::Pubkey,
std::io::Write,
};

Expand Down Expand Up @@ -141,7 +143,7 @@ mod test {
use {
super::*,
assert_matches::assert_matches,
solana_sdk::account::{Account, AccountSharedData},
solana_account::{Account, AccountSharedData},
};

#[test]
Expand Down
38 changes: 19 additions & 19 deletions account-decoder/src/parse_account_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,25 @@ use {
parse_token::parse_token_v2, parse_vote::parse_vote,
},
inflector::Inflector,
solana_sdk::{
address_lookup_table, clock::UnixTimestamp, instruction::InstructionError, pubkey::Pubkey,
stake, system_program, sysvar, vote,
solana_clock::UnixTimestamp,
solana_instruction::error::InstructionError,
solana_pubkey::Pubkey,
solana_sdk_ids::{
address_lookup_table, bpf_loader_upgradeable, config, stake, system_program, sysvar, vote,
},
spl_token_2022::extension::interest_bearing_mint::InterestBearingConfig,
std::collections::HashMap,
thiserror::Error,
};

lazy_static! {
static ref ADDRESS_LOOKUP_PROGRAM_ID: Pubkey = address_lookup_table::program::id();
static ref BPF_UPGRADEABLE_LOADER_PROGRAM_ID: Pubkey = solana_sdk::bpf_loader_upgradeable::id();
static ref CONFIG_PROGRAM_ID: Pubkey = solana_config_program::id();
static ref STAKE_PROGRAM_ID: Pubkey = stake::program::id();
static ref ADDRESS_LOOKUP_PROGRAM_ID: Pubkey = address_lookup_table::id();
static ref BPF_UPGRADEABLE_LOADER_PROGRAM_ID: Pubkey = bpf_loader_upgradeable::id();
static ref CONFIG_PROGRAM_ID: Pubkey = config::id();
static ref STAKE_PROGRAM_ID: Pubkey = stake::id();
static ref SYSTEM_PROGRAM_ID: Pubkey = system_program::id();
static ref SYSVAR_PROGRAM_ID: Pubkey = sysvar::id();
static ref VOTE_PROGRAM_ID: Pubkey = vote::program::id();
static ref VOTE_PROGRAM_ID: Pubkey = vote::id();
pub static ref PARSABLE_PROGRAM_IDS: HashMap<Pubkey, ParsableAccount> = {
let mut m = HashMap::new();
m.insert(
Expand Down Expand Up @@ -160,22 +162,20 @@ pub fn parse_account_data_v2(
mod test {
use {
super::*,
solana_sdk::{
nonce::{
state::{Data, Versions},
State,
},
vote::{
program::id as vote_program_id,
state::{VoteState, VoteStateVersions},
},
solana_nonce::{
state::{Data, State},
versions::Versions,
},
solana_sdk::vote::{
program::id as vote_program_id,
state::{VoteState, VoteStateVersions},
},
};

#[test]
fn test_parse_account_data() {
let account_pubkey = solana_sdk::pubkey::new_rand();
let other_program = solana_sdk::pubkey::new_rand();
let account_pubkey = solana_pubkey::new_rand();
let other_program = solana_pubkey::new_rand();
let data = vec![0; 4];
assert!(parse_account_data_v2(&account_pubkey, &other_program, &data, None).is_err());

Expand Down
9 changes: 4 additions & 5 deletions account-decoder/src/parse_address_lookup_table.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use {
crate::parse_account_data::{ParsableAccount, ParseAccountError},
solana_sdk::{address_lookup_table::state::AddressLookupTable, instruction::InstructionError},
solana_instruction::error::InstructionError,
solana_program::address_lookup_table::state::AddressLookupTable,
};

pub fn parse_address_lookup_table(
Expand Down Expand Up @@ -61,10 +62,8 @@ impl<'a> From<AddressLookupTable<'a>> for UiLookupTable {
mod test {
use {
super::*,
solana_sdk::{
address_lookup_table::state::{LookupTableMeta, LOOKUP_TABLE_META_SIZE},
pubkey::Pubkey,
},
solana_program::address_lookup_table::state::{LookupTableMeta, LOOKUP_TABLE_META_SIZE},
solana_pubkey::Pubkey,
std::borrow::Cow,
};

Expand Down
5 changes: 3 additions & 2 deletions account-decoder/src/parse_bpf_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use {
},
base64::{prelude::BASE64_STANDARD, Engine},
bincode::{deserialize, serialized_size},
solana_sdk::{bpf_loader_upgradeable::UpgradeableLoaderState, pubkey::Pubkey},
solana_pubkey::Pubkey,
solana_sdk::bpf_loader_upgradeable::UpgradeableLoaderState,
};

pub fn parse_bpf_upgradeable_loader(
Expand Down Expand Up @@ -93,7 +94,7 @@ pub struct UiProgramData {

#[cfg(test)]
mod test {
use {super::*, bincode::serialize, solana_sdk::pubkey::Pubkey};
use {super::*, bincode::serialize, solana_pubkey::Pubkey};

#[test]
fn test_parse_bpf_upgradeable_loader_accounts() {
Expand Down
12 changes: 5 additions & 7 deletions account-decoder/src/parse_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ use {
bincode::deserialize,
serde_json::Value,
solana_config_program::{get_config_data, ConfigKeys},
solana_sdk::{
pubkey::Pubkey,
stake::config::{
Config as StakeConfig, {self as stake_config},
},
solana_pubkey::Pubkey,
solana_sdk::stake::config::{
Config as StakeConfig, {self as stake_config},
},
};

Expand Down Expand Up @@ -99,7 +97,7 @@ pub struct UiConfig<T> {
mod test {
use {
super::*, crate::validator_info::ValidatorInfo, serde_json::json,
solana_config_program::create_config_account, solana_sdk::account::ReadableAccount,
solana_account::ReadableAccount, solana_config_program::create_config_account,
};

#[test]
Expand All @@ -123,7 +121,7 @@ mod test {
}))
.unwrap(),
};
let info_pubkey = solana_sdk::pubkey::new_rand();
let info_pubkey = solana_pubkey::new_rand();
let validator_info_config_account = create_config_account(
vec![(validator_info::id(), false), (info_pubkey, true)],
&validator_info,
Expand Down
18 changes: 7 additions & 11 deletions account-decoder/src/parse_nonce.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use {
crate::{parse_account_data::ParseAccountError, UiFeeCalculator},
solana_sdk::{
instruction::InstructionError,
nonce::{state::Versions, State},
},
solana_instruction::error::InstructionError,
solana_nonce::{state::State, versions::Versions},
};

pub fn parse_nonce(data: &[u8]) -> Result<UiNonceState, ParseAccountError> {
Expand Down Expand Up @@ -45,14 +43,12 @@ pub struct UiNonceData {
mod test {
use {
super::*,
solana_sdk::{
hash::Hash,
nonce::{
state::{Data, Versions},
State,
},
pubkey::Pubkey,
solana_hash::Hash,
solana_nonce::{
state::{Data, State},
versions::Versions,
},
solana_pubkey::Pubkey,
};

#[test]
Expand Down
12 changes: 5 additions & 7 deletions account-decoder/src/parse_stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ use {
StringAmount,
},
bincode::deserialize,
solana_sdk::{
clock::{Epoch, UnixTimestamp},
stake::state::{Authorized, Delegation, Lockup, Meta, Stake, StakeStateV2},
},
solana_clock::{Epoch, UnixTimestamp},
solana_sdk::stake::state::{Authorized, Delegation, Lockup, Meta, Stake, StakeStateV2},
};

pub fn parse_stake(data: &[u8]) -> Result<StakeAccountType, ParseAccountError> {
Expand Down Expand Up @@ -153,8 +151,8 @@ mod test {
StakeAccountType::Uninitialized
);

let pubkey = solana_sdk::pubkey::new_rand();
let custodian = solana_sdk::pubkey::new_rand();
let pubkey = solana_pubkey::new_rand();
let custodian = solana_pubkey::new_rand();
let authorized = Authorized::auto(&pubkey);
let lockup = Lockup {
unix_timestamp: 0,
Expand Down Expand Up @@ -188,7 +186,7 @@ mod test {
})
);

let voter_pubkey = solana_sdk::pubkey::new_rand();
let voter_pubkey = solana_pubkey::new_rand();
let stake = Stake {
delegation: Delegation {
voter_pubkey,
Expand Down
31 changes: 16 additions & 15 deletions account-decoder/src/parse_sysvar.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
#[allow(deprecated)]
use solana_sdk::sysvar::{fees::Fees, recent_blockhashes::RecentBlockhashes};
use solana_sysvar::{fees::Fees, recent_blockhashes::RecentBlockhashes};
use {
crate::{
parse_account_data::{ParsableAccount, ParseAccountError},
StringAmount, UiFeeCalculator,
},
bincode::deserialize,
bv::BitVec,
solana_sdk::{
clock::{Clock, Epoch, Slot, UnixTimestamp},
epoch_schedule::EpochSchedule,
pubkey::Pubkey,
rent::Rent,
slot_hashes::SlotHashes,
slot_history::{self, SlotHistory},
solana_clock::{Clock, Epoch, Slot, UnixTimestamp},
solana_epoch_schedule::EpochSchedule,
solana_pubkey::Pubkey,
solana_rent::Rent,
solana_sdk_ids::sysvar,
solana_slot_hashes::SlotHashes,
solana_slot_history::{self as slot_history, SlotHistory},
solana_sysvar::{
epoch_rewards::EpochRewards,
last_restart_slot::LastRestartSlot,
rewards::Rewards,
stake_history::{StakeHistory, StakeHistoryEntry},
sysvar::{
self, epoch_rewards::EpochRewards, last_restart_slot::LastRestartSlot, rewards::Rewards,
},
},
};

Expand Down Expand Up @@ -268,10 +269,10 @@ impl From<EpochRewards> for UiEpochRewards {
#[cfg(test)]
mod test {
#[allow(deprecated)]
use solana_sdk::sysvar::recent_blockhashes::IterItem;
use solana_sysvar::recent_blockhashes::IterItem;
use {
super::*,
solana_sdk::{account::create_account_for_test, fee_calculator::FeeCalculator, hash::Hash},
super::*, solana_account::create_account_for_test, solana_fee_calculator::FeeCalculator,
solana_hash::Hash,
};

#[test]
Expand Down Expand Up @@ -376,7 +377,7 @@ mod test {
}]),
);

let bad_pubkey = solana_sdk::pubkey::new_rand();
let bad_pubkey = solana_pubkey::new_rand();
assert!(parse_sysvar(&stake_history_sysvar.data, &bad_pubkey).is_err());

let bad_data = vec![0; 4];
Expand Down
2 changes: 1 addition & 1 deletion account-decoder/src/parse_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use {
parse_account_data::{ParsableAccount, ParseAccountError, SplTokenAdditionalData},
parse_token_extension::parse_extension,
},
solana_sdk::pubkey::Pubkey,
solana_pubkey::Pubkey,
spl_token_2022::{
extension::{BaseStateWithExtensions, StateWithExtensions},
generic_token_account::GenericTokenAccount,
Expand Down
3 changes: 2 additions & 1 deletion account-decoder/src/parse_token_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ pub use solana_account_decoder_client_types::token::{
};
use {
crate::parse_token::convert_account_state,
solana_sdk::{clock::UnixTimestamp, program_pack::Pack},
solana_clock::UnixTimestamp,
solana_program_pack::Pack,
spl_token_2022::{
extension::{self, BaseState, BaseStateWithExtensions, ExtensionType, StateWithExtensions},
solana_program::pubkey::Pubkey,
Expand Down
8 changes: 3 additions & 5 deletions account-decoder/src/parse_vote.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use {
crate::{parse_account_data::ParseAccountError, StringAmount},
solana_sdk::{
clock::{Epoch, Slot},
pubkey::Pubkey,
vote::state::{BlockTimestamp, Lockout, VoteState},
},
solana_clock::{Epoch, Slot},
solana_pubkey::Pubkey,
solana_sdk::vote::state::{BlockTimestamp, Lockout, VoteState},
};

pub fn parse_vote(data: &[u8]) -> Result<VoteAccountType, ParseAccountError> {
Expand Down
2 changes: 1 addition & 1 deletion account-decoder/src/validator_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub const MAX_SHORT_FIELD_LENGTH: usize = 80;
pub const MAX_LONG_FIELD_LENGTH: usize = 300;
pub const MAX_VALIDATOR_INFO: u64 = 576;

solana_sdk::declare_id!("Va1idator1nfo111111111111111111111111111111");
solana_pubkey::declare_id!("Va1idator1nfo111111111111111111111111111111");

#[derive(Debug, Deserialize, PartialEq, Eq, Serialize, Default)]
pub struct ValidatorInfo {
Expand Down
Loading

0 comments on commit fbc15f1

Please sign in to comment.