From 398f12dcc54c28a57fd92e19fc7c2112ce3e8e80 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 9 Sep 2020 22:23:11 +0000 Subject: [PATCH] Program subscriptions now properly check results len and token program id (#12139) (#12141) (cherry picked from commit 4431080066a616c1a2736328da7d2c1131caaef0) Co-authored-by: Tyera Eulberg --- core/src/rpc_subscriptions.rs | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/core/src/rpc_subscriptions.rs b/core/src/rpc_subscriptions.rs index ae6c0555b9..dfe09f5e15 100644 --- a/core/src/rpc_subscriptions.rs +++ b/core/src/rpc_subscriptions.rs @@ -293,7 +293,7 @@ fn filter_signature_result( fn filter_program_results( accounts: Vec<(Pubkey, Account)>, - _program_id: &Pubkey, + program_id: &Pubkey, last_notified_slot: Slot, config: Option, bank: Option>, @@ -301,24 +301,27 @@ fn filter_program_results( let config = config.unwrap_or_default(); let encoding = config.encoding.unwrap_or(UiAccountEncoding::Binary); let filters = config.filters; + let accounts_is_empty = accounts.is_empty(); let keyed_accounts = accounts.into_iter().filter(move |(_, account)| { filters.iter().all(|filter_type| match filter_type { RpcFilterType::DataSize(size) => account.data.len() as u64 == *size, RpcFilterType::Memcmp(compare) => compare.bytes_match(&account.data), }) }); - let accounts: Box> = - if encoding == UiAccountEncoding::JsonParsed { - let bank = bank.unwrap(); // If !accounts.is_empty(), bank must be Some - Box::new(get_parsed_token_accounts(bank, keyed_accounts)) - } else { - Box::new( - keyed_accounts.map(move |(pubkey, account)| RpcKeyedAccount { - pubkey: pubkey.to_string(), - account: UiAccount::encode(&pubkey, account, encoding.clone(), None, None), - }), - ) - }; + let accounts: Box> = if program_id == &spl_token_id_v2_0() + && encoding == UiAccountEncoding::JsonParsed + && !accounts_is_empty + { + let bank = bank.unwrap(); // If !accounts_is_empty, bank must be Some + Box::new(get_parsed_token_accounts(bank, keyed_accounts)) + } else { + Box::new( + keyed_accounts.map(move |(pubkey, account)| RpcKeyedAccount { + pubkey: pubkey.to_string(), + account: UiAccount::encode(&pubkey, account, encoding.clone(), None, None), + }), + ) + }; (accounts, last_notified_slot) }