@subsquid/solana-normalization 0.0.4 → 1.0.0-portal-api.d887ad

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,77 @@
1
+ import * as rpc from '@subsquid/solana-rpc-data'
2
+ import {Base58Bytes} from '@subsquid/solana-rpc-data'
3
+ import assert from 'assert'
4
+
5
+
6
+ export interface Journal {
7
+ warn(props: any, msg: string): void
8
+ error(props: any, msg: string): void
9
+ }
10
+
11
+
12
+ export class TransactionContext {
13
+ public readonly erroredInstruction: number
14
+ public readonly exceededCallDepth: boolean
15
+
16
+ private accounts: Base58Bytes[]
17
+
18
+ constructor(
19
+ public readonly transactionIndex: number,
20
+ public readonly tx: rpc.Transaction,
21
+ private journal: Journal
22
+ ) {
23
+ if (tx.version == 'legacy') {
24
+ this.accounts = tx.transaction.message.accountKeys
25
+ } else {
26
+ this.accounts = tx.transaction.message.accountKeys.concat(
27
+ tx.meta.loadedAddresses?.writable ?? [],
28
+ tx.meta.loadedAddresses?.readonly ?? []
29
+ )
30
+ }
31
+
32
+ let err = this.tx.meta.err
33
+ if (err && 'InstructionError' in err) {
34
+ let pos = err.InstructionError?.[0]
35
+ let type = err.InstructionError?.[1]
36
+ if (Number.isSafeInteger(pos)) {
37
+ this.erroredInstruction = pos
38
+ } else {
39
+ this.erroredInstruction = tx.transaction.message.instructions.length
40
+ this.warn({transactionError: err}, 'got InstructionError of unrecognized shape')
41
+ }
42
+ this.exceededCallDepth = type === 'CallDepth'
43
+ } else {
44
+ this.erroredInstruction = tx.transaction.message.instructions.length
45
+ this.exceededCallDepth = false
46
+ }
47
+ }
48
+
49
+ get isCommitted(): boolean {
50
+ return this.tx.meta.err == null
51
+ }
52
+
53
+ get transactionHash(): string {
54
+ return this.tx.transaction.signatures[0]
55
+ }
56
+
57
+ getAccount(index: number): Base58Bytes {
58
+ assert(index < this.accounts.length)
59
+ return this.accounts[index]
60
+ }
61
+
62
+ warn(props: any, msg: string): void {
63
+ this.journal.warn({
64
+ transactionHash: this.transactionHash,
65
+ transactionIndex: this.transactionIndex,
66
+ ...props
67
+ }, msg)
68
+ }
69
+
70
+ error(props: any, msg: string): void {
71
+ this.journal.error({
72
+ transactionHash: this.transactionHash,
73
+ transactionIndex: this.transactionIndex,
74
+ ...props
75
+ }, msg)
76
+ }
77
+ }
package/src/votes.ts ADDED
@@ -0,0 +1,22 @@
1
+ import {Block} from './data'
2
+
3
+
4
+ export function removeVotes(block: Block): void {
5
+ let removed = new Set<number>()
6
+
7
+ for (let i of block.instructions) {
8
+ if (i.programId == 'Vote111111111111111111111111111111111111111') {
9
+ removed.add(i.transactionIndex)
10
+ }
11
+ }
12
+
13
+ function kept(item: {transactionIndex: number}): boolean {
14
+ return !removed.has(item.transactionIndex)
15
+ }
16
+
17
+ block.transactions = block.transactions.filter(kept)
18
+ block.instructions = block.instructions.filter(kept)
19
+ block.logs = block.logs.filter(kept)
20
+ block.balances = block.balances.filter(kept)
21
+ block.tokenBalances = block.tokenBalances.filter(kept)
22
+ }