From 9a75781760476ff406c667887a83c4eb59f2801e Mon Sep 17 00:00:00 2001 From: Alexey Safonov Date: Sun, 21 Jul 2024 20:37:47 +0530 Subject: [PATCH] solana: allow to request all balances of transaction (#313) --- .../transaction-balances_2024-07-17-10-01.json | 10 ++++++++++ solana/solana-stream/src/data/request.ts | 1 + solana/solana-stream/src/rpc/filter.ts | 8 ++++++++ 3 files changed, 19 insertions(+) create mode 100644 common/changes/@subsquid/solana-stream/transaction-balances_2024-07-17-10-01.json diff --git a/common/changes/@subsquid/solana-stream/transaction-balances_2024-07-17-10-01.json b/common/changes/@subsquid/solana-stream/transaction-balances_2024-07-17-10-01.json new file mode 100644 index 000000000..9badee908 --- /dev/null +++ b/common/changes/@subsquid/solana-stream/transaction-balances_2024-07-17-10-01.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@subsquid/solana-stream", + "comment": "allow to request all balances of transaction", + "type": "minor" + } + ], + "packageName": "@subsquid/solana-stream" +} \ No newline at end of file diff --git a/solana/solana-stream/src/data/request.ts b/solana/solana-stream/src/data/request.ts index 0994178c2..cf1e3ba9a 100644 --- a/solana/solana-stream/src/data/request.ts +++ b/solana/solana-stream/src/data/request.ts @@ -66,6 +66,7 @@ export interface InstructionRequestWhere { export interface InstructionRequestRelations { transaction?: boolean + transactionBalances?: boolean transactionTokenBalances?: boolean transactionInstructions?: boolean logs?: boolean diff --git a/solana/solana-stream/src/rpc/filter.ts b/solana/solana-stream/src/rpc/filter.ts index 2006bcbed..eb6c2d515 100644 --- a/solana/solana-stream/src/rpc/filter.ts +++ b/solana/solana-stream/src/rpc/filter.ts @@ -173,6 +173,11 @@ class BlockFilter { return groupBy(this.block.instructions, i => i.transactionIndex) } + @def + private balancesByTx(): Map { + return groupBy(this.block.balances, b => b.transactionIndex) + } + @def private tokenBalancesByTx(): Map { return groupBy(this.block.tokenBalances, b => b.transactionIndex) @@ -220,6 +225,9 @@ class BlockFilter { if (rel.transaction) { this.include.transactions.add(this.getTransaction(ins.transactionIndex)) } + if (rel.transactionBalances) { + include(this.include.balances, this.balancesByTx().get(ins.transactionIndex)) + } if (rel.transactionTokenBalances) { include(this.include.tokenBalances, this.tokenBalancesByTx().get(ins.transactionIndex)) }