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();
|
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 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()
|
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| {
|
.map(|inst| {
|
||||||
Instruction {
|
Instruction {
|
||||||
program_id: bs58::encode(acct_keys[inst.program_id_index as usize].to_vec()).into_string(),
|
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)
|
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() {
|
if filters.program_id.is_none() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
|
use crate::pb::sol::transactions::v1::{Instruction, Transaction, Transactions};
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use substreams_solana::pb::sf::solana::r#type::v1::{Block, ConfirmedTransaction};
|
use substreams_solana::pb::sf::solana::r#type::v1::{Block, ConfirmedTransaction};
|
||||||
use crate::pb::sol::transactions::v1::{Instruction, Transaction, Transactions};
|
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
struct TransactionFilterParams {
|
struct TransactionFilterParams {
|
||||||
@@ -12,26 +12,39 @@ struct TransactionFilterParams {
|
|||||||
fn map_filter_transactions(params: String, blk: Block) -> Result<Transactions, Vec<substreams::errors::Error>> {
|
fn map_filter_transactions(params: String, blk: Block) -> Result<Transactions, Vec<substreams::errors::Error>> {
|
||||||
let filters = parse_filters_from_params(params)?;
|
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))
|
.filter(|tx| apply_filter(tx, &filters))
|
||||||
.for_each(|tx| {
|
.for_each(|tx| {
|
||||||
let msg = tx.transaction.clone().unwrap().message.unwrap();
|
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()
|
let insts: Vec<Instruction> = msg
|
||||||
.map(|inst| {
|
.instructions
|
||||||
Instruction {
|
.iter()
|
||||||
program_id: bs58::encode(acct_keys[inst.program_id_index as usize].to_vec()).into_string(),
|
.map(|inst| Instruction {
|
||||||
accounts: inst.accounts.iter().map(|acct| bs58::encode(acct_keys[*acct as usize].to_vec()).into_string()).collect(),
|
program_id: bs58::encode(acct_keys[inst.program_id_index as usize].to_vec()).into_string(),
|
||||||
data: bs58::encode(inst.data.clone()).into_string(),
|
accounts: inst
|
||||||
}
|
.accounts
|
||||||
}).collect();
|
.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 {
|
let t = Transaction {
|
||||||
signatures: tx.transaction.clone().unwrap().signatures.iter().map(|sig| bs58::encode(sig).into_string()).collect(),
|
signatures: tx
|
||||||
instructions: insts
|
.transaction
|
||||||
|
.clone()
|
||||||
|
.unwrap()
|
||||||
|
.signatures
|
||||||
|
.iter()
|
||||||
|
.map(|sig| bs58::encode(sig).into_string())
|
||||||
|
.collect(),
|
||||||
|
instructions: insts,
|
||||||
};
|
};
|
||||||
transactions.push(t);
|
transactions.push(t);
|
||||||
});
|
});
|
||||||
@@ -58,12 +71,18 @@ fn apply_filter(transaction: &&ConfirmedTransaction, filters: &TransactionFilter
|
|||||||
|
|
||||||
let mut found = false;
|
let mut found = false;
|
||||||
|
|
||||||
transaction.transaction.as_ref().unwrap().signatures.iter().for_each(|sig| {
|
transaction
|
||||||
let xsig = bs58::encode(&sig).into_string();
|
.transaction
|
||||||
if xsig == filters.signature.clone().unwrap() {
|
.as_ref()
|
||||||
found = true;
|
.unwrap()
|
||||||
}
|
.signatures
|
||||||
});
|
.iter()
|
||||||
|
.for_each(|sig| {
|
||||||
|
let xsig = bs58::encode(&sig).into_string();
|
||||||
|
if xsig == filters.signature.clone().unwrap() {
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
found
|
found
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user