Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RPC: include resolved keys from table lookups in parsed message response #27552

Merged
merged 3 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions transaction-status/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
55 changes: 46 additions & 9 deletions transaction-status/src/parse_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,42 @@ pub struct ParsedAccount {
pub pubkey: String,
pub writable: bool,
pub signer: bool,
pub source: Option<ParsedAccountSource>,
}

pub fn parse_accounts(message: &Message) -> Vec<ParsedAccount> {
#[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<ParsedAccount> {
let mut accounts: Vec<ParsedAccount> = vec![];
for (i, account_key) in message.account_keys.iter().enumerate() {
accounts.push(ParsedAccount {
pubkey: account_key.to_string(),
writable: message.is_writable(i),
signer: message.is_signer(i),
source: Some(ParsedAccountSource::Transaction),
});
}
accounts
}

pub fn parse_static_accounts(message: &LoadedMessage) -> Vec<ParsedAccount> {
pub fn parse_v0_message_accounts(message: &LoadedMessage) -> Vec<ParsedAccount> {
let mut accounts: Vec<ParsedAccount> = vec![];
for (i, account_key) in message.static_account_keys().iter().enumerate() {
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: Some(source),
});
}
accounts
Expand All @@ -43,7 +58,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();
Expand All @@ -59,38 +74,44 @@ mod test {
};

assert_eq!(
parse_accounts(&message),
parse_legacy_message_accounts(&message),
vec![
ParsedAccount {
pubkey: pubkey0.to_string(),
writable: true,
signer: true,
source: Some(ParsedAccountSource::Transaction),
},
ParsedAccount {
pubkey: pubkey1.to_string(),
writable: false,
signer: true,
source: Some(ParsedAccountSource::Transaction),
},
ParsedAccount {
pubkey: pubkey2.to_string(),
writable: true,
signer: false,
source: Some(ParsedAccountSource::Transaction),
},
ParsedAccount {
pubkey: pubkey3.to_string(),
writable: false,
signer: false,
source: Some(ParsedAccountSource::Transaction),
},
]
);
}

#[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 {
Expand All @@ -102,33 +123,49 @@ 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(),
writable: true,
signer: true,
source: Some(ParsedAccountSource::Transaction),
},
ParsedAccount {
pubkey: pubkey1.to_string(),
writable: false,
signer: true,
source: Some(ParsedAccountSource::Transaction),
},
ParsedAccount {
pubkey: pubkey2.to_string(),
writable: true,
signer: false,
source: Some(ParsedAccountSource::Transaction),
},
ParsedAccount {
pubkey: pubkey3.to_string(),
writable: false,
signer: false,
source: Some(ParsedAccountSource::Transaction),
},
ParsedAccount {
pubkey: pubkey4.to_string(),
writable: true,
signer: false,
source: Some(ParsedAccountSource::LookupTable),
},
ParsedAccount {
pubkey: pubkey5.to_string(),
writable: false,
signer: false,
source: Some(ParsedAccountSource::LookupTable),
},
]
);
Expand Down