From 89c89ea0a4587e00d1f1f00eeb1277a94f3e32b5 Mon Sep 17 00:00:00 2001 From: Justin Starry Date: Thu, 1 Sep 2022 11:38:25 -0400 Subject: [PATCH 1/3] RPC: include resolved keys from table lookups in parsed message response --- transaction-status/src/lib.rs | 6 ++--- transaction-status/src/parse_accounts.rs | 30 +++++++++++++++++------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/transaction-status/src/lib.rs b/transaction-status/src/lib.rs index 9bfe29fce20d00..910a7243912293 100644 --- a/transaction-status/src/lib.rs +++ b/transaction-status/src/lib.rs @@ -3,7 +3,7 @@ pub use {crate::extract_memos::extract_and_fmt_memos, solana_sdk::reward_type::RewardType}; use { crate::{ - parse_accounts::{parse_accounts, parse_static_accounts, ParsedAccount}, + parse_accounts::{parse_legacy_message_accounts, parse_v0_message_accounts, ParsedAccount}, parse_instruction::{parse, ParsedInstruction}, }, solana_account_decoder::parse_token::UiTokenAmount, @@ -904,7 +904,7 @@ impl Encodable for Message { if encoding == UiTransactionEncoding::JsonParsed { let account_keys = AccountKeys::new(&self.account_keys, None); UiMessage::Parsed(UiParsedMessage { - account_keys: parse_accounts(self), + account_keys: parse_legacy_message_accounts(self), recent_blockhash: self.recent_blockhash.to_string(), instructions: self .instructions @@ -936,7 +936,7 @@ impl EncodableWithMeta for v0::Message { let account_keys = AccountKeys::new(&self.account_keys, Some(&meta.loaded_addresses)); let loaded_message = LoadedMessage::new_borrowed(self, &meta.loaded_addresses); UiMessage::Parsed(UiParsedMessage { - account_keys: parse_static_accounts(&loaded_message), + account_keys: parse_v0_message_accounts(&loaded_message), recent_blockhash: self.recent_blockhash.to_string(), instructions: self .instructions diff --git a/transaction-status/src/parse_accounts.rs b/transaction-status/src/parse_accounts.rs index a84fd06bf92ca1..6084d85e04635b 100644 --- a/transaction-status/src/parse_accounts.rs +++ b/transaction-status/src/parse_accounts.rs @@ -8,7 +8,7 @@ pub struct ParsedAccount { pub signer: bool, } -pub fn parse_accounts(message: &Message) -> Vec { +pub fn parse_legacy_message_accounts(message: &Message) -> Vec { let mut accounts: Vec = vec![]; for (i, account_key) in message.account_keys.iter().enumerate() { accounts.push(ParsedAccount { @@ -20,9 +20,9 @@ pub fn parse_accounts(message: &Message) -> Vec { accounts } -pub fn parse_static_accounts(message: &LoadedMessage) -> Vec { +pub fn parse_v0_message_accounts(message: &LoadedMessage) -> Vec { let mut accounts: Vec = vec![]; - for (i, account_key) in message.static_account_keys().iter().enumerate() { + for (i, account_key) in message.account_keys().iter().enumerate() { accounts.push(ParsedAccount { pubkey: account_key.to_string(), writable: message.is_writable(i), @@ -43,7 +43,7 @@ mod test { }; #[test] - fn test_parse_accounts() { + fn test_parse_legacy_message_accounts() { let pubkey0 = Pubkey::new_unique(); let pubkey1 = Pubkey::new_unique(); let pubkey2 = Pubkey::new_unique(); @@ -59,7 +59,7 @@ mod test { }; assert_eq!( - parse_accounts(&message), + parse_legacy_message_accounts(&message), vec![ ParsedAccount { pubkey: pubkey0.to_string(), @@ -86,11 +86,13 @@ mod test { } #[test] - fn test_parse_static_accounts() { + fn test_parse_v0_message_accounts() { let pubkey0 = Pubkey::new_unique(); let pubkey1 = Pubkey::new_unique(); let pubkey2 = Pubkey::new_unique(); let pubkey3 = Pubkey::new_unique(); + let pubkey4 = Pubkey::new_unique(); + let pubkey5 = Pubkey::new_unique(); let message = LoadedMessage::new( v0::Message { header: MessageHeader { @@ -102,13 +104,13 @@ mod test { ..v0::Message::default() }, LoadedAddresses { - writable: vec![Pubkey::new_unique()], - readonly: vec![Pubkey::new_unique()], + writable: vec![pubkey4], + readonly: vec![pubkey5], }, ); assert_eq!( - parse_static_accounts(&message), + parse_v0_message_accounts(&message), vec![ ParsedAccount { pubkey: pubkey0.to_string(), @@ -130,6 +132,16 @@ mod test { writable: false, signer: false, }, + ParsedAccount { + pubkey: pubkey4.to_string(), + writable: true, + signer: false, + }, + ParsedAccount { + pubkey: pubkey5.to_string(), + writable: false, + signer: false, + }, ] ); } From 7cd6e65a7beb03c0e8a294a501cd5b6d1a7a29c6 Mon Sep 17 00:00:00 2001 From: Justin Starry Date: Fri, 2 Sep 2022 07:48:52 -0500 Subject: [PATCH 2/3] Add source to ParsedAccount --- transaction-status/src/parse_accounts.rs | 25 ++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/transaction-status/src/parse_accounts.rs b/transaction-status/src/parse_accounts.rs index 6084d85e04635b..5f7e3557b3b02d 100644 --- a/transaction-status/src/parse_accounts.rs +++ b/transaction-status/src/parse_accounts.rs @@ -6,6 +6,14 @@ pub struct ParsedAccount { pub pubkey: String, pub writable: bool, pub signer: bool, + pub source: ParsedAccountSource, +} + +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] +#[serde(rename_all = "camelCase")] +pub enum ParsedAccountSource { + Transaction, + LookupTable, } pub fn parse_legacy_message_accounts(message: &Message) -> Vec { @@ -15,6 +23,7 @@ pub fn parse_legacy_message_accounts(message: &Message) -> Vec { pubkey: account_key.to_string(), writable: message.is_writable(i), signer: message.is_signer(i), + source: ParsedAccountSource::Transaction, }); } accounts @@ -23,10 +32,16 @@ pub fn parse_legacy_message_accounts(message: &Message) -> Vec { pub fn parse_v0_message_accounts(message: &LoadedMessage) -> Vec { let mut accounts: Vec = vec![]; for (i, account_key) in message.account_keys().iter().enumerate() { + let source = if i < message.static_account_keys().len() { + ParsedAccountSource::Transaction + } else { + ParsedAccountSource::LookupTable + }; accounts.push(ParsedAccount { pubkey: account_key.to_string(), writable: message.is_writable(i), signer: message.is_signer(i), + source, }); } accounts @@ -65,21 +80,25 @@ mod test { pubkey: pubkey0.to_string(), writable: true, signer: true, + source: ParsedAccountSource::Transaction, }, ParsedAccount { pubkey: pubkey1.to_string(), writable: false, signer: true, + source: ParsedAccountSource::Transaction, }, ParsedAccount { pubkey: pubkey2.to_string(), writable: true, signer: false, + source: ParsedAccountSource::Transaction, }, ParsedAccount { pubkey: pubkey3.to_string(), writable: false, signer: false, + source: ParsedAccountSource::Transaction, }, ] ); @@ -116,31 +135,37 @@ mod test { pubkey: pubkey0.to_string(), writable: true, signer: true, + source: ParsedAccountSource::Transaction, }, ParsedAccount { pubkey: pubkey1.to_string(), writable: false, signer: true, + source: ParsedAccountSource::Transaction, }, ParsedAccount { pubkey: pubkey2.to_string(), writable: true, signer: false, + source: ParsedAccountSource::Transaction, }, ParsedAccount { pubkey: pubkey3.to_string(), writable: false, signer: false, + source: ParsedAccountSource::Transaction, }, ParsedAccount { pubkey: pubkey4.to_string(), writable: true, signer: false, + source: ParsedAccountSource::LookupTable, }, ParsedAccount { pubkey: pubkey5.to_string(), writable: false, signer: false, + source: ParsedAccountSource::LookupTable, }, ] ); From f3bf8f97890903ed182ed10db9fc26caef696de7 Mon Sep 17 00:00:00 2001 From: Justin Starry Date: Fri, 2 Sep 2022 09:56:18 -0500 Subject: [PATCH 3/3] Ensure that rpc client can parse account meta from old api versions --- transaction-status/src/parse_accounts.rs | 26 ++++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/transaction-status/src/parse_accounts.rs b/transaction-status/src/parse_accounts.rs index 5f7e3557b3b02d..6ad0ec82a6fdad 100644 --- a/transaction-status/src/parse_accounts.rs +++ b/transaction-status/src/parse_accounts.rs @@ -6,7 +6,7 @@ pub struct ParsedAccount { pub pubkey: String, pub writable: bool, pub signer: bool, - pub source: ParsedAccountSource, + pub source: Option, } #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] @@ -23,7 +23,7 @@ pub fn parse_legacy_message_accounts(message: &Message) -> Vec { pubkey: account_key.to_string(), writable: message.is_writable(i), signer: message.is_signer(i), - source: ParsedAccountSource::Transaction, + source: Some(ParsedAccountSource::Transaction), }); } accounts @@ -41,7 +41,7 @@ pub fn parse_v0_message_accounts(message: &LoadedMessage) -> Vec pubkey: account_key.to_string(), writable: message.is_writable(i), signer: message.is_signer(i), - source, + source: Some(source), }); } accounts @@ -80,25 +80,25 @@ mod test { pubkey: pubkey0.to_string(), writable: true, signer: true, - source: ParsedAccountSource::Transaction, + source: Some(ParsedAccountSource::Transaction), }, ParsedAccount { pubkey: pubkey1.to_string(), writable: false, signer: true, - source: ParsedAccountSource::Transaction, + source: Some(ParsedAccountSource::Transaction), }, ParsedAccount { pubkey: pubkey2.to_string(), writable: true, signer: false, - source: ParsedAccountSource::Transaction, + source: Some(ParsedAccountSource::Transaction), }, ParsedAccount { pubkey: pubkey3.to_string(), writable: false, signer: false, - source: ParsedAccountSource::Transaction, + source: Some(ParsedAccountSource::Transaction), }, ] ); @@ -135,37 +135,37 @@ mod test { pubkey: pubkey0.to_string(), writable: true, signer: true, - source: ParsedAccountSource::Transaction, + source: Some(ParsedAccountSource::Transaction), }, ParsedAccount { pubkey: pubkey1.to_string(), writable: false, signer: true, - source: ParsedAccountSource::Transaction, + source: Some(ParsedAccountSource::Transaction), }, ParsedAccount { pubkey: pubkey2.to_string(), writable: true, signer: false, - source: ParsedAccountSource::Transaction, + source: Some(ParsedAccountSource::Transaction), }, ParsedAccount { pubkey: pubkey3.to_string(), writable: false, signer: false, - source: ParsedAccountSource::Transaction, + source: Some(ParsedAccountSource::Transaction), }, ParsedAccount { pubkey: pubkey4.to_string(), writable: true, signer: false, - source: ParsedAccountSource::LookupTable, + source: Some(ParsedAccountSource::LookupTable), }, ParsedAccount { pubkey: pubkey5.to_string(), writable: false, signer: false, - source: ParsedAccountSource::LookupTable, + source: Some(ParsedAccountSource::LookupTable), }, ] );