diff --git a/Cargo.lock b/Cargo.lock index d5b24f5cb1..3756acd7fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6932,10 +6932,10 @@ dependencies = [ "serde_derive", "serde_json", "solana-account-decoder", + "solana-inline-spl", "solana-sdk", "solana-transaction-status", "solana-version", - "spl-token-2022", "thiserror", ] diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index e3ca3c4860..de4621f11f 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -5657,10 +5657,10 @@ dependencies = [ "serde_derive", "serde_json", "solana-account-decoder", + "solana-inline-spl", "solana-sdk", "solana-transaction-status", "solana-version", - "spl-token-2022", "thiserror", ] diff --git a/rpc-client-api/Cargo.toml b/rpc-client-api/Cargo.toml index 92bc9d4958..9d924cf45d 100644 --- a/rpc-client-api/Cargo.toml +++ b/rpc-client-api/Cargo.toml @@ -19,10 +19,10 @@ serde = { workspace = true } serde_derive = { workspace = true } serde_json = { workspace = true } solana-account-decoder = { workspace = true } +solana-inline-spl = { workspace = true } solana-sdk = { workspace = true } solana-transaction-status = { workspace = true } solana-version = { workspace = true } -spl-token-2022 = { workspace = true, features = ["no-entrypoint"] } thiserror = { workspace = true } [dev-dependencies] diff --git a/rpc-client-api/src/filter.rs b/rpc-client-api/src/filter.rs index ef7aa12217..368d7ce7d7 100644 --- a/rpc-client-api/src/filter.rs +++ b/rpc-client-api/src/filter.rs @@ -1,8 +1,8 @@ #![allow(deprecated)] use { crate::version_req::VersionReq, + solana_inline_spl::{token::GenericTokenAccount, token_2022::Account}, solana_sdk::account::{AccountSharedData, ReadableAccount}, - spl_token_2022::{generic_token_account::GenericTokenAccount, state::Account}, std::borrow::Cow, thiserror::Error, }; @@ -79,6 +79,7 @@ impl RpcFilterType { } } + #[deprecated = "Use solana_rpc::filter::filter_allows instead"] pub fn allows(&self, account: &AccountSharedData) -> bool { match self { RpcFilterType::DataSize(size) => account.data().len() as u64 == *size, diff --git a/rpc/src/filter.rs b/rpc/src/filter.rs new file mode 100644 index 0000000000..81cebd2f47 --- /dev/null +++ b/rpc/src/filter.rs @@ -0,0 +1,13 @@ +use { + solana_inline_spl::{token::GenericTokenAccount, token_2022::Account}, + solana_rpc_client_api::filter::RpcFilterType, + solana_sdk::account::{AccountSharedData, ReadableAccount}, +}; + +pub fn filter_allows(filter: &RpcFilterType, account: &AccountSharedData) -> bool { + match filter { + RpcFilterType::DataSize(size) => account.data().len() as u64 == *size, + RpcFilterType::Memcmp(compare) => compare.bytes_match(account.data()), + RpcFilterType::TokenAccountState => Account::valid_account_data(account.data()), + } +} diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index 2a5065d95d..8dc81692d5 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -1,5 +1,6 @@ #![allow(clippy::arithmetic_side_effects)] mod cluster_tpu_info; +pub mod filter; pub mod max_slots; pub mod optimistically_confirmed_bank_tracker; pub mod parsed_token_accounts; diff --git a/rpc/src/rpc.rs b/rpc/src/rpc.rs index e83327aee8..c153d666b1 100644 --- a/rpc/src/rpc.rs +++ b/rpc/src/rpc.rs @@ -1,7 +1,8 @@ //! The `rpc` module implements the Solana RPC interface. use { crate::{ - max_slots::MaxSlots, optimistically_confirmed_bank_tracker::OptimisticallyConfirmedBank, + filter::filter_allows, max_slots::MaxSlots, + optimistically_confirmed_bank_tracker::OptimisticallyConfirmedBank, parsed_token_accounts::*, rpc_cache::LargestAccountsCache, rpc_health::*, }, base64::{prelude::BASE64_STANDARD, Engine}, @@ -2039,7 +2040,7 @@ impl JsonRpcRequestProcessor { let filter_closure = |account: &AccountSharedData| { filters .iter() - .all(|filter_type| filter_type.allows(account)) + .all(|filter_type| filter_allows(filter_type, account)) }; if self .config @@ -2116,7 +2117,7 @@ impl JsonRpcRequestProcessor { account.owner() == program_id && filters .iter() - .all(|filter_type| filter_type.allows(account)) + .all(|filter_type| filter_allows(filter_type, account)) }, &ScanConfig::default(), bank.byte_limit_for_scans(), @@ -2166,7 +2167,7 @@ impl JsonRpcRequestProcessor { account.owner() == program_id && filters .iter() - .all(|filter_type| filter_type.allows(account)) + .all(|filter_type| filter_allows(filter_type, account)) }, &ScanConfig::default(), bank.byte_limit_for_scans(), diff --git a/rpc/src/rpc_subscriptions.rs b/rpc/src/rpc_subscriptions.rs index f3594c67cc..828b7bf210 100644 --- a/rpc/src/rpc_subscriptions.rs +++ b/rpc/src/rpc_subscriptions.rs @@ -2,6 +2,7 @@ use { crate::{ + filter::filter_allows, optimistically_confirmed_bank_tracker::OptimisticallyConfirmedBank, parsed_token_accounts::{get_parsed_token_account, get_parsed_token_accounts}, rpc_pubsub_service::PubSubConfig, @@ -416,7 +417,7 @@ fn filter_program_results( let keyed_accounts = accounts.into_iter().filter(move |(_, account)| { filters .iter() - .all(|filter_type| filter_type.allows(account)) + .all(|filter_type| filter_allows(filter_type, account)) }); let accounts = if is_known_spl_token_id(¶ms.pubkey) && params.encoding == UiAccountEncoding::JsonParsed