Update instruction encoding format (#11363)

* Rework parsed instruction format

* Rework parsed message accounts

* Review comments
This commit is contained in:
Tyera Eulberg
2020-08-05 00:58:58 -06:00
committed by GitHub
parent 86e3f96f16
commit 9d4f9be1fe
4 changed files with 264 additions and 173 deletions

View File

@@ -7,8 +7,10 @@ pub mod parse_accounts;
pub mod parse_instruction;
pub mod parse_token;
use crate::{parse_accounts::parse_accounts, parse_instruction::parse};
use serde_json::{json, Value};
use crate::{
parse_accounts::{parse_accounts, ParsedAccount},
parse_instruction::{parse, ParsedInstruction},
};
use solana_sdk::{
clock::{Slot, UnixTimestamp},
commitment_config::CommitmentConfig,
@@ -23,7 +25,14 @@ use solana_sdk::{
#[serde(rename_all = "camelCase", untagged)]
pub enum UiInstruction {
Compiled(UiCompiledInstruction),
Parsed(Value),
Parsed(UiParsedInstruction),
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", untagged)]
pub enum UiParsedInstruction {
Parsed(ParsedInstruction),
PartiallyDecoded(UiPartiallyDecodedInstruction),
}
/// A duplicate representation of a CompiledInstruction for pretty JSON serialization
@@ -183,7 +192,7 @@ pub struct UiRawMessage {
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct UiParsedMessage {
pub account_keys: Value,
pub account_keys: Vec<ParsedAccount>,
pub recent_blockhash: String,
pub instructions: Vec<UiInstruction>,
}
@@ -250,13 +259,15 @@ impl EncodedTransaction {
instruction,
&transaction.message.account_keys,
) {
UiInstruction::Parsed(parsed_instruction)
UiInstruction::Parsed(UiParsedInstruction::Parsed(
parsed_instruction,
))
} else {
UiInstruction::Parsed(json!(
UiInstruction::Parsed(UiParsedInstruction::PartiallyDecoded(
UiPartiallyDecodedInstruction::from(
instruction,
&transaction.message.account_keys
)
&transaction.message.account_keys,
),
))
}
})