Merge pull request #5 from streamingfast/enol/add-resolved-accounts
Solana Explorer - Add Resolved Accounts
This commit is contained in:
@@ -14,11 +14,11 @@ fn map_filter_instructions(params: String, blk: Block) -> Result<Instructions, V
|
||||
|
||||
let mut instructions : Vec<Instruction> = Vec::new();
|
||||
|
||||
blk.transactions.iter().for_each(|tx| {
|
||||
blk.transactions_owned().into_iter().for_each(|tx| {
|
||||
let msg = tx.transaction.clone().unwrap().message.unwrap();
|
||||
let acct_keys = msg.account_keys.as_slice();
|
||||
let acct_keys = tx.resolved_accounts();
|
||||
let insts : Vec<Instruction> = msg.instructions.iter()
|
||||
.filter(|inst| apply_filter(inst, &filters, acct_keys.to_vec()))
|
||||
.filter(|inst| apply_filter(inst, &filters, &acct_keys))
|
||||
.map(|inst| {
|
||||
Instruction {
|
||||
program_id: bs58::encode(acct_keys[inst.program_id_index as usize].to_vec()).into_string(),
|
||||
@@ -44,7 +44,7 @@ fn parse_filters_from_params(params: String) -> Result<InstructionFilterParams,
|
||||
Ok(filters)
|
||||
}
|
||||
|
||||
fn apply_filter(instruction: &CompiledInstruction, filters: &InstructionFilterParams, account_keys: Vec<Vec<u8>>) -> bool {
|
||||
fn apply_filter(instruction: &CompiledInstruction, filters: &InstructionFilterParams, account_keys: &Vec<&Vec<u8>>) -> bool {
|
||||
if filters.program_id.is_none() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::pb::sol::transactions::v1::{Instruction, Transaction, Transactions};
|
||||
use anyhow::anyhow;
|
||||
use serde::Deserialize;
|
||||
use substreams_solana::pb::sf::solana::r#type::v1::{Block, ConfirmedTransaction};
|
||||
use crate::pb::sol::transactions::v1::{Instruction, Transaction, Transactions};
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct TransactionFilterParams {
|
||||
@@ -12,26 +12,39 @@ struct TransactionFilterParams {
|
||||
fn map_filter_transactions(params: String, blk: Block) -> Result<Transactions, Vec<substreams::errors::Error>> {
|
||||
let filters = parse_filters_from_params(params)?;
|
||||
|
||||
let mut transactions : Vec<Transaction> = Vec::new();
|
||||
let mut transactions: Vec<Transaction> = Vec::new();
|
||||
|
||||
blk.transactions.iter()
|
||||
blk.transactions
|
||||
.iter()
|
||||
.filter(|tx| apply_filter(tx, &filters))
|
||||
.for_each(|tx| {
|
||||
let msg = tx.transaction.clone().unwrap().message.unwrap();
|
||||
let acct_keys = msg.account_keys.as_slice();
|
||||
let acct_keys = tx.resolved_accounts();
|
||||
|
||||
let insts : Vec<Instruction> = msg.instructions.iter()
|
||||
.map(|inst| {
|
||||
Instruction {
|
||||
program_id: bs58::encode(acct_keys[inst.program_id_index as usize].to_vec()).into_string(),
|
||||
accounts: inst.accounts.iter().map(|acct| bs58::encode(acct_keys[*acct as usize].to_vec()).into_string()).collect(),
|
||||
data: bs58::encode(inst.data.clone()).into_string(),
|
||||
}
|
||||
}).collect();
|
||||
let insts: Vec<Instruction> = msg
|
||||
.instructions
|
||||
.iter()
|
||||
.map(|inst| Instruction {
|
||||
program_id: bs58::encode(acct_keys[inst.program_id_index as usize].to_vec()).into_string(),
|
||||
accounts: inst
|
||||
.accounts
|
||||
.iter()
|
||||
.map(|acct| bs58::encode(acct_keys[*acct as usize].to_vec()).into_string())
|
||||
.collect(),
|
||||
data: bs58::encode(inst.data.clone()).into_string(),
|
||||
})
|
||||
.collect();
|
||||
|
||||
let t = Transaction {
|
||||
signatures: tx.transaction.clone().unwrap().signatures.iter().map(|sig| bs58::encode(sig).into_string()).collect(),
|
||||
instructions: insts
|
||||
signatures: tx
|
||||
.transaction
|
||||
.clone()
|
||||
.unwrap()
|
||||
.signatures
|
||||
.iter()
|
||||
.map(|sig| bs58::encode(sig).into_string())
|
||||
.collect(),
|
||||
instructions: insts,
|
||||
};
|
||||
transactions.push(t);
|
||||
});
|
||||
@@ -58,12 +71,18 @@ fn apply_filter(transaction: &&ConfirmedTransaction, filters: &TransactionFilter
|
||||
|
||||
let mut found = false;
|
||||
|
||||
transaction.transaction.as_ref().unwrap().signatures.iter().for_each(|sig| {
|
||||
let xsig = bs58::encode(&sig).into_string();
|
||||
if xsig == filters.signature.clone().unwrap() {
|
||||
found = true;
|
||||
}
|
||||
});
|
||||
transaction
|
||||
.transaction
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.signatures
|
||||
.iter()
|
||||
.for_each(|sig| {
|
||||
let xsig = bs58::encode(&sig).into_string();
|
||||
if xsig == filters.signature.clone().unwrap() {
|
||||
found = true;
|
||||
}
|
||||
});
|
||||
|
||||
found
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user