@subsquid/evm-objects 0.0.2-portal-api.a8e10e

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.
package/src/types.ts ADDED
@@ -0,0 +1,91 @@
1
+ import {Bytes, FieldSelection} from '@subsquid/evm-stream'
2
+ import * as base from '@subsquid/evm-stream'
3
+
4
+
5
+ export type BlockHeader<F extends FieldSelection = {}> = base.BlockHeader<F> & {
6
+ id: string
7
+ }
8
+
9
+
10
+ export type Transaction<F extends FieldSelection = {}> = base.Transaction<F> & {
11
+ id: string
12
+ block: BlockHeader<F>
13
+ logs: Log<F>[]
14
+ traces: Trace<F>[]
15
+ stateDiffs: StateDiff<F>[]
16
+ }
17
+
18
+
19
+ export type Log<F extends FieldSelection = {}> = base.Log<F> & {
20
+ id: string
21
+ block: BlockHeader<F>
22
+ transaction?: Transaction<F>
23
+ getTransaction(): Transaction<F>
24
+ }
25
+
26
+
27
+ export type TraceCreate<F extends FieldSelection = {}> = base.TraceCreate<F> & {
28
+ id: string
29
+ block: BlockHeader<F>
30
+ transaction?: Transaction<F>
31
+ getTransaction(): Transaction<F>
32
+ parent?: Trace<F>
33
+ getParent(): Trace<F>
34
+ children: Trace<F>[]
35
+ }
36
+
37
+
38
+ export type TraceCall<F extends FieldSelection = {}> = base.TraceCall<F> & {
39
+ id: string
40
+ block: BlockHeader<F>
41
+ transaction?: Transaction<F>
42
+ getTransaction(): Transaction<F>
43
+ parent?: Trace<F>
44
+ getParent(): Trace<F>
45
+ children: Trace<F>[]
46
+ }
47
+
48
+
49
+ export type TraceSuicide<F extends FieldSelection = {}> = base.TraceSuicide<F> & {
50
+ id: string
51
+ block: BlockHeader<F>
52
+ transaction?: Transaction<F>
53
+ getTransaction(): Transaction<F>
54
+ parent?: Trace<F>
55
+ getParent(): Trace<F>
56
+ children: Trace<F>[]
57
+ }
58
+
59
+
60
+ export type TraceReward<F extends FieldSelection = {}> = base.TraceReward<F> & {
61
+ id: string
62
+ block: BlockHeader<F>
63
+ transaction?: Transaction<F>
64
+ getTransaction(): Transaction<F>
65
+ parent?: Trace<F>
66
+ getParent(): Trace<F>
67
+ children: Trace<F>[]
68
+ }
69
+
70
+
71
+ export type Trace<F extends FieldSelection = {}> =
72
+ | TraceCreate<F>
73
+ | TraceCall<F>
74
+ | TraceSuicide<F>
75
+ | TraceReward<F>
76
+
77
+
78
+ export type StateDiff<F extends FieldSelection = {}> = base.StateDiff<F> & {
79
+ block: BlockHeader<F>
80
+ transaction?: Transaction<F>
81
+ getTransaction(): Transaction<F>
82
+ }
83
+
84
+
85
+ export interface Block<F extends FieldSelection = {}> {
86
+ header: BlockHeader<F>
87
+ transactions: Transaction<F>[]
88
+ logs: Log<F>[]
89
+ traces: Trace<F>[]
90
+ stateDiffs: StateDiff<F>[]
91
+ }
package/src/util.ts ADDED
@@ -0,0 +1,27 @@
1
+ import {Bytes32} from '@subsquid/evm-stream'
2
+
3
+
4
+ export interface HashAndNumber {
5
+ hash: Bytes32
6
+ number: number
7
+ }
8
+
9
+
10
+ export function shortHash(hash: string): string {
11
+ if (hash.startsWith('0x')) {
12
+ return hash.slice(2, 7)
13
+ } else {
14
+ return hash.slice(0, 5)
15
+ }
16
+ }
17
+
18
+
19
+ export function formatId(block: HashAndNumber, ...address: number[]): string {
20
+ let no = block.number.toString().padStart(10, '0')
21
+ let hash = shortHash(block.hash)
22
+ let id = `${no}-${hash}`
23
+ for (let index of address) {
24
+ id += '-' + index.toString().padStart(6, '0')
25
+ }
26
+ return id
27
+ }