Populate memo in bigtable transaction structs (#19512)

* Populate memo in bigtable transaction structs

* Preface memos with len
This commit is contained in:
Tyera Eulberg
2021-08-30 21:14:18 -06:00
committed by GitHub
parent dc3d7ad2bd
commit f4ae450f34
4 changed files with 65 additions and 10 deletions

View File

@@ -1,4 +1,5 @@
use crate::{
extract_memos::{spl_memo_id_v1, spl_memo_id_v3},
parse_associated_token::{parse_associated_token, spl_associated_token_id_v1_0},
parse_bpf_loader::{parse_bpf_loader, parse_bpf_upgradeable_loader},
parse_stake::parse_stake,
@@ -10,15 +11,18 @@ use inflector::Inflector;
use serde_json::Value;
use solana_account_decoder::parse_token::spl_token_id_v2_0;
use solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey, stake, system_program};
use std::{collections::HashMap, str::from_utf8};
use std::{
collections::HashMap,
str::{from_utf8, Utf8Error},
};
use thiserror::Error;
lazy_static! {
static ref ASSOCIATED_TOKEN_PROGRAM_ID: Pubkey = spl_associated_token_id_v1_0();
static ref BPF_LOADER_PROGRAM_ID: Pubkey = solana_sdk::bpf_loader::id();
static ref BPF_UPGRADEABLE_LOADER_PROGRAM_ID: Pubkey = solana_sdk::bpf_loader_upgradeable::id();
static ref MEMO_V1_PROGRAM_ID: Pubkey = Pubkey::new_from_array(spl_memo::v1::id().to_bytes());
static ref MEMO_V3_PROGRAM_ID: Pubkey = Pubkey::new_from_array(spl_memo::id().to_bytes());
static ref MEMO_V1_PROGRAM_ID: Pubkey = spl_memo_id_v1();
static ref MEMO_V3_PROGRAM_ID: Pubkey = spl_memo_id_v3();
static ref STAKE_PROGRAM_ID: Pubkey = stake::program::id();
static ref SYSTEM_PROGRAM_ID: Pubkey = system_program::id();
static ref TOKEN_PROGRAM_ID: Pubkey = spl_token_id_v2_0();
@@ -121,11 +125,15 @@ pub fn parse(
}
fn parse_memo(instruction: &CompiledInstruction) -> Result<Value, ParseInstructionError> {
from_utf8(&instruction.data)
.map(|s| Value::String(s.to_string()))
parse_memo_data(&instruction.data)
.map(Value::String)
.map_err(|_| ParseInstructionError::InstructionNotParsable(ParsableProgram::SplMemo))
}
pub fn parse_memo_data(data: &[u8]) -> Result<String, Utf8Error> {
from_utf8(data).map(|s| s.to_string())
}
pub(crate) fn check_num_accounts(
accounts: &[u8],
num: usize,