@apibara/indexer 0.2.0 → 0.2.2
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/dist/starknet/block.d.ts +143 -36
- package/dist/starknet/block.test-d.d.ts +1 -0
- package/dist/starknet/block.test-d.js +95 -0
- package/dist/starknet/block.test-d.js.map +1 -0
- package/dist/starknet/filter.d.ts +4 -0
- package/package.json +1 -1
- package/src/starknet/block.test-d.ts +112 -0
- package/src/starknet/block.ts +153 -44
- package/src/starknet/filter.ts +4 -0
package/dist/starknet/block.d.ts
CHANGED
|
@@ -1,145 +1,252 @@
|
|
|
1
1
|
import { FieldElement } from "./felt";
|
|
2
2
|
export declare type Block = {
|
|
3
|
+
/** Block header. */
|
|
3
4
|
header?: BlockHeader;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
/** Transactions. */
|
|
6
|
+
transactions?: TransactionWithReceipt[];
|
|
7
|
+
/** Events. */
|
|
8
|
+
events?: EventWithTransaction[];
|
|
9
|
+
/** Messages from L2 to L1. */
|
|
10
|
+
l2ToL1Messages?: L2ToL1MessageWithTransaction[];
|
|
11
|
+
/** State update. */
|
|
12
|
+
stateUpdate?: StateUpdate;
|
|
8
13
|
};
|
|
9
14
|
export declare type BlockHeader = {
|
|
15
|
+
/** Block hash. */
|
|
10
16
|
blockHash: FieldElement;
|
|
17
|
+
/** Parent block hash. */
|
|
11
18
|
parentBlockHash: FieldElement;
|
|
19
|
+
/** Block number. */
|
|
12
20
|
blockNumber: string;
|
|
21
|
+
/** Sequencer address. */
|
|
13
22
|
sequencerAddress: FieldElement;
|
|
23
|
+
/** New state root. */
|
|
14
24
|
newRoot: FieldElement;
|
|
25
|
+
/** Block production timestamp. */
|
|
15
26
|
timestamp: string;
|
|
16
27
|
};
|
|
17
28
|
export declare type TransactionWithReceipt = {
|
|
29
|
+
/** Transaction. */
|
|
18
30
|
transaction: Transaction;
|
|
31
|
+
/** Transaction receipt. */
|
|
19
32
|
receipt: TransactionReceipt;
|
|
20
33
|
};
|
|
21
34
|
export declare type EventWithTransaction = {
|
|
35
|
+
/** Transaction. */
|
|
22
36
|
transaction: Transaction;
|
|
37
|
+
/** Transaction receipt. */
|
|
23
38
|
receipt: TransactionReceipt;
|
|
39
|
+
/** Event. */
|
|
24
40
|
event: Event;
|
|
25
41
|
};
|
|
26
42
|
export declare type L2ToL1MessageWithTransaction = {
|
|
43
|
+
/** Transaction. */
|
|
27
44
|
transaction: Transaction;
|
|
45
|
+
/** Message from L2 to L1. */
|
|
28
46
|
message: L2ToL1Message;
|
|
29
47
|
};
|
|
30
|
-
export declare type Transaction =
|
|
48
|
+
export declare type Transaction = TransactionCommon & (InvokeTransactionV0 | InvokeTransactionV1 | DeployTransaction | DeclareTransaction | DeployAccountTransaction | L1HandlerTransaction);
|
|
49
|
+
export declare type TransactionCommon = {
|
|
31
50
|
meta: TransactionMeta;
|
|
32
|
-
} & TransactionBody;
|
|
33
|
-
export declare type TransactionBody = {
|
|
34
|
-
invokeV0: InvokeTransactionV0;
|
|
35
|
-
} | {
|
|
36
|
-
invokeV1: InvokeTransactionV1;
|
|
37
|
-
} | {
|
|
38
|
-
deploy: DeployTransaction;
|
|
39
|
-
} | {
|
|
40
|
-
declare: DeclareTransaction;
|
|
41
|
-
} | {
|
|
42
|
-
deployAccount: DeployAccountTransaction;
|
|
43
|
-
} | {
|
|
44
|
-
l1Handler: L1HandlerTransaction;
|
|
45
51
|
};
|
|
46
52
|
export declare type TransactionMeta = {
|
|
53
|
+
/** Transaction hash. */
|
|
47
54
|
hash: FieldElement;
|
|
55
|
+
/** Maximum fee. */
|
|
48
56
|
maxFee: FieldElement;
|
|
57
|
+
/** Signature. */
|
|
49
58
|
signature: FieldElement[];
|
|
59
|
+
/** Nonce. */
|
|
50
60
|
nonce: FieldElement;
|
|
61
|
+
/** Transaction version. */
|
|
51
62
|
version: string;
|
|
52
63
|
};
|
|
53
64
|
export declare type InvokeTransactionV0 = {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
65
|
+
invokeV0?: {
|
|
66
|
+
/** Target contract address. */
|
|
67
|
+
contractAddress: FieldElement;
|
|
68
|
+
/** Selector of the function being invoked. */
|
|
69
|
+
entryPointSelector: FieldElement;
|
|
70
|
+
/** Calldata. */
|
|
71
|
+
calldata: FieldElement[];
|
|
72
|
+
};
|
|
73
|
+
invokeV1?: never;
|
|
74
|
+
deploy?: never;
|
|
75
|
+
declare?: never;
|
|
76
|
+
l1Handler?: never;
|
|
77
|
+
deployAccount?: never;
|
|
57
78
|
};
|
|
58
79
|
export declare type InvokeTransactionV1 = {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
80
|
+
invokeV1?: {
|
|
81
|
+
/** Address of the account sending the transaction. */
|
|
82
|
+
senderAddress: FieldElement;
|
|
83
|
+
/** Calldata. */
|
|
84
|
+
calldata: FieldElement[];
|
|
85
|
+
};
|
|
86
|
+
invokeV0?: never;
|
|
87
|
+
deploy?: never;
|
|
88
|
+
declare?: never;
|
|
89
|
+
l1Handler?: never;
|
|
90
|
+
deployAccount?: never;
|
|
62
91
|
};
|
|
63
92
|
export declare type DeployTransaction = {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
93
|
+
deploy?: {
|
|
94
|
+
/** Constructor calldata. */
|
|
95
|
+
constructorCalldata: FieldElement[];
|
|
96
|
+
/** Salt used when computing the contract's address. */
|
|
97
|
+
contractAddressSalt: FieldElement;
|
|
98
|
+
/** Hash of the class being deployed. */
|
|
99
|
+
classHash: FieldElement;
|
|
100
|
+
};
|
|
101
|
+
invokeV0?: never;
|
|
102
|
+
invokeV1?: never;
|
|
103
|
+
declare?: never;
|
|
104
|
+
l1Handler?: never;
|
|
105
|
+
deployAccount?: never;
|
|
67
106
|
};
|
|
68
107
|
export declare type DeclareTransaction = {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
108
|
+
declare?: {
|
|
109
|
+
/** Class hash. */
|
|
110
|
+
classHash: FieldElement;
|
|
111
|
+
/** Address of the account sending the transaction. */
|
|
112
|
+
senderAddress: FieldElement;
|
|
113
|
+
/** Hash of the cairo assembly resulting from the sierra compilation. */
|
|
114
|
+
compiledClassHash: FieldElement;
|
|
115
|
+
};
|
|
116
|
+
invokeV0?: never;
|
|
117
|
+
invokeV1?: never;
|
|
118
|
+
deploy?: never;
|
|
119
|
+
l1Handler?: never;
|
|
120
|
+
deployAccount?: never;
|
|
72
121
|
};
|
|
73
122
|
export declare type DeployAccountTransaction = {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
123
|
+
deployAccount?: {
|
|
124
|
+
/** Constructor calldata. */
|
|
125
|
+
constructorCalldata: FieldElement[];
|
|
126
|
+
/** Salt used when computing the contract's address. */
|
|
127
|
+
contractAddressSalt: FieldElement;
|
|
128
|
+
/** Hash of the class being deployed. */
|
|
129
|
+
classHash: FieldElement;
|
|
130
|
+
};
|
|
131
|
+
invokeV0?: never;
|
|
132
|
+
invokeV1?: never;
|
|
133
|
+
deploy?: never;
|
|
134
|
+
declare?: never;
|
|
135
|
+
l1Handler?: never;
|
|
77
136
|
};
|
|
78
137
|
export declare type L1HandlerTransaction = {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
138
|
+
l1Handler?: {
|
|
139
|
+
/** Target contract address. */
|
|
140
|
+
contractAddress: FieldElement;
|
|
141
|
+
/** Selector of the function being invoked. */
|
|
142
|
+
entryPointSelector: FieldElement;
|
|
143
|
+
/** Calldata. */
|
|
144
|
+
calldata: FieldElement[];
|
|
145
|
+
};
|
|
146
|
+
invokeV0?: never;
|
|
147
|
+
invokeV1?: never;
|
|
148
|
+
deploy?: never;
|
|
149
|
+
declare?: never;
|
|
150
|
+
deployAccount?: never;
|
|
82
151
|
};
|
|
83
152
|
export declare type TransactionReceipt = {
|
|
153
|
+
/** Transaction status. */
|
|
84
154
|
executionStatus: ExecutionStatus;
|
|
155
|
+
/** Transaction hash. */
|
|
85
156
|
transactionHash: FieldElement;
|
|
157
|
+
/** Transaction index. */
|
|
86
158
|
transactionIndex: string;
|
|
159
|
+
/** Actual fee paid by the account. */
|
|
87
160
|
actualFee: FieldElement;
|
|
161
|
+
/** Address of the contract created by the transaction. */
|
|
88
162
|
contractAddress: FieldElement;
|
|
163
|
+
/** Messages from L2 to L1. */
|
|
89
164
|
l2ToL1Messages: L2ToL1Message[];
|
|
165
|
+
/** Events. */
|
|
90
166
|
events: Event[];
|
|
167
|
+
/** Revert reason. */
|
|
91
168
|
revertReason?: string;
|
|
92
169
|
};
|
|
93
170
|
export declare type ExecutionStatus = "EXECUTION_STATUS_UNSPECIFIED" | "EXECUTION_STATUS_SUCCEEDED" | "EXECUTION_STATUS_REVERTED";
|
|
94
171
|
export declare type Event = {
|
|
172
|
+
/** Event index. */
|
|
95
173
|
index: number;
|
|
174
|
+
/** Contract address. */
|
|
96
175
|
fromAddress: FieldElement;
|
|
176
|
+
/** Event selector. */
|
|
97
177
|
keys: FieldElement[];
|
|
178
|
+
/** Event data. */
|
|
98
179
|
data: FieldElement[];
|
|
99
180
|
};
|
|
100
181
|
export declare type L2ToL1Message = {
|
|
182
|
+
/** Message index. */
|
|
101
183
|
index: number;
|
|
184
|
+
/** L2 sender address. */
|
|
102
185
|
fromAddress: FieldElement;
|
|
186
|
+
/** L1 target address. */
|
|
103
187
|
toAddress: FieldElement;
|
|
188
|
+
/** Calldata. */
|
|
104
189
|
payload: FieldElement[];
|
|
105
190
|
};
|
|
106
191
|
export declare type StateUpdate = {
|
|
192
|
+
/** New state root. */
|
|
107
193
|
newRoot: FieldElement;
|
|
194
|
+
/** Old state root. */
|
|
108
195
|
oldRoot: FieldElement;
|
|
196
|
+
/** State diff. */
|
|
109
197
|
stateDiff: StateDiff;
|
|
110
198
|
};
|
|
111
199
|
export declare type StateDiff = {
|
|
200
|
+
/** Changes in storage. */
|
|
112
201
|
storageDiffs: StorageDiff[];
|
|
202
|
+
/** Declared contracts. */
|
|
113
203
|
declaredContracts: DeclaredContract[];
|
|
204
|
+
/** Deployed contracts. */
|
|
114
205
|
deployedContracts: DeployedContract[];
|
|
206
|
+
/** Nonce updates. */
|
|
115
207
|
nonces: NonceUpdate[];
|
|
208
|
+
/** Classes declared. */
|
|
116
209
|
declaredClasses: DeclaredClass[];
|
|
210
|
+
/** Classes replaced. */
|
|
117
211
|
replacedClasses: ReplacedClass[];
|
|
118
212
|
};
|
|
119
213
|
export declare type StorageDiff = {
|
|
214
|
+
/** Contract address. */
|
|
120
215
|
contractAddress: FieldElement;
|
|
216
|
+
/** Changes in storage. */
|
|
121
217
|
storageEntries: StorageEntry[];
|
|
122
218
|
};
|
|
123
219
|
export declare type StorageEntry = {
|
|
220
|
+
/** Storage key. */
|
|
124
221
|
key: FieldElement;
|
|
222
|
+
/** New storage value. */
|
|
125
223
|
value: FieldElement;
|
|
126
224
|
};
|
|
127
225
|
export declare type DeclaredContract = {
|
|
226
|
+
/** Class hash. */
|
|
128
227
|
classHash: FieldElement;
|
|
129
228
|
};
|
|
130
229
|
export declare type DeclaredClass = {
|
|
230
|
+
/** Class hash. */
|
|
131
231
|
classHash: FieldElement;
|
|
232
|
+
/** Compiled class hash. */
|
|
132
233
|
compiledClassHash: FieldElement;
|
|
133
234
|
};
|
|
134
235
|
export declare type ReplacedClass = {
|
|
236
|
+
/** Contract address. */
|
|
135
237
|
contractAddress: FieldElement;
|
|
238
|
+
/** Class hash. */
|
|
136
239
|
classHash: FieldElement;
|
|
137
240
|
};
|
|
138
241
|
export declare type DeployedContract = {
|
|
242
|
+
/** Contract address. */
|
|
139
243
|
contractAddress: FieldElement;
|
|
244
|
+
/** Class hash. */
|
|
140
245
|
classHash: FieldElement;
|
|
141
246
|
};
|
|
142
247
|
export declare type NonceUpdate = {
|
|
248
|
+
/** Contract address. */
|
|
143
249
|
contractAddress: FieldElement;
|
|
250
|
+
/** New nonce. */
|
|
144
251
|
nonce: FieldElement;
|
|
145
252
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { assertType, describe, test } from "vitest";
|
|
2
|
+
import { FieldElement } from "./felt";
|
|
3
|
+
const address = "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7";
|
|
4
|
+
const entryPointSelector = "0x03943907ef0ef6f9d2e2408b05e520a66daaf74293dbf665e5a20b117676170e";
|
|
5
|
+
const calldata = [FieldElement.parse("0x01"), FieldElement.parse("0x02")];
|
|
6
|
+
const meta = {
|
|
7
|
+
hash: FieldElement.parse("0x01"),
|
|
8
|
+
maxFee: FieldElement.parse("0x02"),
|
|
9
|
+
signature: [FieldElement.parse("0x03")],
|
|
10
|
+
nonce: FieldElement.parse("0x04"),
|
|
11
|
+
version: "0",
|
|
12
|
+
};
|
|
13
|
+
const invokeV0 = {
|
|
14
|
+
contractAddress: FieldElement.parse(address),
|
|
15
|
+
entryPointSelector: FieldElement.parse(entryPointSelector),
|
|
16
|
+
calldata,
|
|
17
|
+
};
|
|
18
|
+
const invokeV1 = {
|
|
19
|
+
senderAddress: FieldElement.parse(address),
|
|
20
|
+
calldata,
|
|
21
|
+
};
|
|
22
|
+
const deploy = {
|
|
23
|
+
constructorCalldata: calldata,
|
|
24
|
+
contractAddressSalt: FieldElement.parse("0x01"),
|
|
25
|
+
classHash: FieldElement.parse("0x02"),
|
|
26
|
+
};
|
|
27
|
+
const declare = {
|
|
28
|
+
classHash: FieldElement.parse("0x01"),
|
|
29
|
+
senderAddress: FieldElement.parse(address),
|
|
30
|
+
compiledClassHash: FieldElement.parse("0x02"),
|
|
31
|
+
};
|
|
32
|
+
describe("Block", () => {
|
|
33
|
+
test("all optional", () => {
|
|
34
|
+
assertType({});
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
describe("BlockHeader", () => {
|
|
38
|
+
test("all fields", () => {
|
|
39
|
+
assertType({
|
|
40
|
+
blockHash: FieldElement.parse("0x01"),
|
|
41
|
+
parentBlockHash: FieldElement.parse("0x00"),
|
|
42
|
+
blockNumber: "1",
|
|
43
|
+
sequencerAddress: FieldElement.parse(address),
|
|
44
|
+
newRoot: FieldElement.parse("0x02"),
|
|
45
|
+
timestamp: "1",
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
describe("Transaction", () => {
|
|
50
|
+
test("only one type", () => {
|
|
51
|
+
// @ts-expect-error - should be one of the types
|
|
52
|
+
assertType({
|
|
53
|
+
meta,
|
|
54
|
+
invokeV0,
|
|
55
|
+
invokeV1,
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
test("invokeV0", () => {
|
|
59
|
+
assertType({
|
|
60
|
+
meta,
|
|
61
|
+
invokeV0,
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
test("invokeV1", () => {
|
|
65
|
+
assertType({
|
|
66
|
+
meta,
|
|
67
|
+
invokeV1,
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
test("deploy", () => {
|
|
71
|
+
assertType({
|
|
72
|
+
meta,
|
|
73
|
+
deploy,
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
test("declare", () => {
|
|
77
|
+
assertType({
|
|
78
|
+
meta,
|
|
79
|
+
declare,
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
test("l1Handler", () => {
|
|
83
|
+
assertType({
|
|
84
|
+
meta,
|
|
85
|
+
l1Handler: invokeV0,
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
test("deployAccount", () => {
|
|
89
|
+
assertType({
|
|
90
|
+
meta,
|
|
91
|
+
deployAccount: deploy,
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
//# sourceMappingURL=block.test-d.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block.test-d.js","sourceRoot":"","sources":["../../src/starknet/block.test-d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,I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YACJ,OAAO;SACR,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,WAAW,EAAE,GAAG,EAAE;QACrB,UAAU,CAAc;YACtB,IAAI;YACJ,SAAS,EAAE,QAAQ;SACpB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,eAAe,EAAE,GAAG,EAAE;QACzB,UAAU,CAAc;YACtB,IAAI;YACJ,aAAa,EAAE,MAAM;SACtB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -114,6 +114,10 @@ export declare type EventFilter = {
|
|
|
114
114
|
data?: FieldElement[];
|
|
115
115
|
/** Include events from reverted transactions. */
|
|
116
116
|
includeReverted?: boolean;
|
|
117
|
+
/** Include the transaction that emitted the event. Defaults to true. */
|
|
118
|
+
includeTransaction?: boolean;
|
|
119
|
+
/** Include the receipt of the transaction that emitted the event. Defaults to true. */
|
|
120
|
+
includeReceipt?: boolean;
|
|
117
121
|
};
|
|
118
122
|
export declare type L2ToL1MessageFilter = {
|
|
119
123
|
/** Filter by destination address. */
|
package/package.json
CHANGED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { assertType, describe, test } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { Block, BlockHeader, Transaction } from "./block";
|
|
4
|
+
import { FieldElement } from "./felt";
|
|
5
|
+
|
|
6
|
+
const address =
|
|
7
|
+
"0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7";
|
|
8
|
+
const entryPointSelector =
|
|
9
|
+
"0x03943907ef0ef6f9d2e2408b05e520a66daaf74293dbf665e5a20b117676170e";
|
|
10
|
+
const calldata = [FieldElement.parse("0x01"), FieldElement.parse("0x02")];
|
|
11
|
+
const meta = {
|
|
12
|
+
hash: FieldElement.parse("0x01"),
|
|
13
|
+
maxFee: FieldElement.parse("0x02"),
|
|
14
|
+
signature: [FieldElement.parse("0x03")],
|
|
15
|
+
nonce: FieldElement.parse("0x04"),
|
|
16
|
+
version: "0",
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const invokeV0 = {
|
|
20
|
+
contractAddress: FieldElement.parse(address),
|
|
21
|
+
entryPointSelector: FieldElement.parse(entryPointSelector),
|
|
22
|
+
calldata,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const invokeV1 = {
|
|
26
|
+
senderAddress: FieldElement.parse(address),
|
|
27
|
+
calldata,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const deploy = {
|
|
31
|
+
constructorCalldata: calldata,
|
|
32
|
+
contractAddressSalt: FieldElement.parse("0x01"),
|
|
33
|
+
classHash: FieldElement.parse("0x02"),
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const declare = {
|
|
37
|
+
classHash: FieldElement.parse("0x01"),
|
|
38
|
+
senderAddress: FieldElement.parse(address),
|
|
39
|
+
compiledClassHash: FieldElement.parse("0x02"),
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
describe("Block", () => {
|
|
43
|
+
test("all optional", () => {
|
|
44
|
+
assertType<Block>({});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe("BlockHeader", () => {
|
|
49
|
+
test("all fields", () => {
|
|
50
|
+
assertType<BlockHeader>({
|
|
51
|
+
blockHash: FieldElement.parse("0x01"),
|
|
52
|
+
parentBlockHash: FieldElement.parse("0x00"),
|
|
53
|
+
blockNumber: "1",
|
|
54
|
+
sequencerAddress: FieldElement.parse(address),
|
|
55
|
+
newRoot: FieldElement.parse("0x02"),
|
|
56
|
+
timestamp: "1",
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe("Transaction", () => {
|
|
62
|
+
test("only one type", () => {
|
|
63
|
+
// @ts-expect-error - should be one of the types
|
|
64
|
+
assertType<Transaction>({
|
|
65
|
+
meta,
|
|
66
|
+
invokeV0,
|
|
67
|
+
invokeV1,
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test("invokeV0", () => {
|
|
72
|
+
assertType<Transaction>({
|
|
73
|
+
meta,
|
|
74
|
+
invokeV0,
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test("invokeV1", () => {
|
|
79
|
+
assertType<Transaction>({
|
|
80
|
+
meta,
|
|
81
|
+
invokeV1,
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test("deploy", () => {
|
|
86
|
+
assertType<Transaction>({
|
|
87
|
+
meta,
|
|
88
|
+
deploy,
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test("declare", () => {
|
|
93
|
+
assertType<Transaction>({
|
|
94
|
+
meta,
|
|
95
|
+
declare,
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("l1Handler", () => {
|
|
100
|
+
assertType<Transaction>({
|
|
101
|
+
meta,
|
|
102
|
+
l1Handler: invokeV0,
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test("deployAccount", () => {
|
|
107
|
+
assertType<Transaction>({
|
|
108
|
+
meta,
|
|
109
|
+
deployAccount: deploy,
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
});
|
package/src/starknet/block.ts
CHANGED
|
@@ -1,114 +1,193 @@
|
|
|
1
1
|
import { FieldElement } from "./felt";
|
|
2
2
|
|
|
3
3
|
export type Block = {
|
|
4
|
+
/** Block header. */
|
|
4
5
|
header?: BlockHeader;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
/** Transactions. */
|
|
7
|
+
transactions?: TransactionWithReceipt[];
|
|
8
|
+
/** Events. */
|
|
9
|
+
events?: EventWithTransaction[];
|
|
10
|
+
/** Messages from L2 to L1. */
|
|
11
|
+
l2ToL1Messages?: L2ToL1MessageWithTransaction[];
|
|
12
|
+
/** State update. */
|
|
13
|
+
stateUpdate?: StateUpdate;
|
|
9
14
|
};
|
|
10
15
|
|
|
11
16
|
export type BlockHeader = {
|
|
17
|
+
/** Block hash. */
|
|
12
18
|
blockHash: FieldElement;
|
|
19
|
+
/** Parent block hash. */
|
|
13
20
|
parentBlockHash: FieldElement;
|
|
21
|
+
/** Block number. */
|
|
14
22
|
blockNumber: string;
|
|
23
|
+
/** Sequencer address. */
|
|
15
24
|
sequencerAddress: FieldElement;
|
|
25
|
+
/** New state root. */
|
|
16
26
|
newRoot: FieldElement;
|
|
27
|
+
/** Block production timestamp. */
|
|
17
28
|
timestamp: string;
|
|
18
29
|
};
|
|
19
30
|
|
|
20
31
|
export type TransactionWithReceipt = {
|
|
32
|
+
/** Transaction. */
|
|
21
33
|
transaction: Transaction;
|
|
34
|
+
/** Transaction receipt. */
|
|
22
35
|
receipt: TransactionReceipt;
|
|
23
36
|
};
|
|
24
37
|
|
|
25
38
|
export type EventWithTransaction = {
|
|
39
|
+
/** Transaction. */
|
|
26
40
|
transaction: Transaction;
|
|
41
|
+
/** Transaction receipt. */
|
|
27
42
|
receipt: TransactionReceipt;
|
|
43
|
+
/** Event. */
|
|
28
44
|
event: Event;
|
|
29
45
|
};
|
|
30
46
|
|
|
31
47
|
export type L2ToL1MessageWithTransaction = {
|
|
48
|
+
/** Transaction. */
|
|
32
49
|
transaction: Transaction;
|
|
50
|
+
/** Message from L2 to L1. */
|
|
33
51
|
message: L2ToL1Message;
|
|
34
52
|
};
|
|
35
53
|
|
|
36
|
-
export type Transaction =
|
|
54
|
+
export type Transaction = TransactionCommon &
|
|
55
|
+
(
|
|
56
|
+
| InvokeTransactionV0
|
|
57
|
+
| InvokeTransactionV1
|
|
58
|
+
| DeployTransaction
|
|
59
|
+
| DeclareTransaction
|
|
60
|
+
| DeployAccountTransaction
|
|
61
|
+
| L1HandlerTransaction
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
export type TransactionCommon = {
|
|
37
65
|
meta: TransactionMeta;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export type TransactionBody =
|
|
41
|
-
| {
|
|
42
|
-
invokeV0: InvokeTransactionV0;
|
|
43
|
-
}
|
|
44
|
-
| {
|
|
45
|
-
invokeV1: InvokeTransactionV1;
|
|
46
|
-
}
|
|
47
|
-
| {
|
|
48
|
-
deploy: DeployTransaction;
|
|
49
|
-
}
|
|
50
|
-
| {
|
|
51
|
-
declare: DeclareTransaction;
|
|
52
|
-
}
|
|
53
|
-
| {
|
|
54
|
-
deployAccount: DeployAccountTransaction;
|
|
55
|
-
}
|
|
56
|
-
| {
|
|
57
|
-
l1Handler: L1HandlerTransaction;
|
|
58
|
-
};
|
|
66
|
+
};
|
|
59
67
|
|
|
60
68
|
export type TransactionMeta = {
|
|
69
|
+
/** Transaction hash. */
|
|
61
70
|
hash: FieldElement;
|
|
71
|
+
/** Maximum fee. */
|
|
62
72
|
maxFee: FieldElement;
|
|
73
|
+
/** Signature. */
|
|
63
74
|
signature: FieldElement[];
|
|
75
|
+
/** Nonce. */
|
|
64
76
|
nonce: FieldElement;
|
|
77
|
+
/** Transaction version. */
|
|
65
78
|
version: string;
|
|
66
79
|
};
|
|
67
80
|
|
|
68
81
|
export type InvokeTransactionV0 = {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
82
|
+
invokeV0?: {
|
|
83
|
+
/** Target contract address. */
|
|
84
|
+
contractAddress: FieldElement;
|
|
85
|
+
/** Selector of the function being invoked. */
|
|
86
|
+
entryPointSelector: FieldElement;
|
|
87
|
+
/** Calldata. */
|
|
88
|
+
calldata: FieldElement[];
|
|
89
|
+
};
|
|
90
|
+
invokeV1?: never;
|
|
91
|
+
deploy?: never;
|
|
92
|
+
declare?: never;
|
|
93
|
+
l1Handler?: never;
|
|
94
|
+
deployAccount?: never;
|
|
72
95
|
};
|
|
73
96
|
|
|
74
97
|
export type InvokeTransactionV1 = {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
98
|
+
invokeV1?: {
|
|
99
|
+
/** Address of the account sending the transaction. */
|
|
100
|
+
senderAddress: FieldElement;
|
|
101
|
+
/** Calldata. */
|
|
102
|
+
calldata: FieldElement[];
|
|
103
|
+
};
|
|
104
|
+
invokeV0?: never;
|
|
105
|
+
deploy?: never;
|
|
106
|
+
declare?: never;
|
|
107
|
+
l1Handler?: never;
|
|
108
|
+
deployAccount?: never;
|
|
78
109
|
};
|
|
79
110
|
|
|
80
111
|
export type DeployTransaction = {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
112
|
+
deploy?: {
|
|
113
|
+
/** Constructor calldata. */
|
|
114
|
+
constructorCalldata: FieldElement[];
|
|
115
|
+
/** Salt used when computing the contract's address. */
|
|
116
|
+
contractAddressSalt: FieldElement;
|
|
117
|
+
/** Hash of the class being deployed. */
|
|
118
|
+
classHash: FieldElement;
|
|
119
|
+
};
|
|
120
|
+
invokeV0?: never;
|
|
121
|
+
invokeV1?: never;
|
|
122
|
+
declare?: never;
|
|
123
|
+
l1Handler?: never;
|
|
124
|
+
deployAccount?: never;
|
|
84
125
|
};
|
|
85
126
|
|
|
86
127
|
export type DeclareTransaction = {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
128
|
+
declare?: {
|
|
129
|
+
/** Class hash. */
|
|
130
|
+
classHash: FieldElement;
|
|
131
|
+
/** Address of the account sending the transaction. */
|
|
132
|
+
senderAddress: FieldElement;
|
|
133
|
+
/** Hash of the cairo assembly resulting from the sierra compilation. */
|
|
134
|
+
compiledClassHash: FieldElement;
|
|
135
|
+
};
|
|
136
|
+
invokeV0?: never;
|
|
137
|
+
invokeV1?: never;
|
|
138
|
+
deploy?: never;
|
|
139
|
+
l1Handler?: never;
|
|
140
|
+
deployAccount?: never;
|
|
90
141
|
};
|
|
91
142
|
|
|
92
143
|
export type DeployAccountTransaction = {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
144
|
+
deployAccount?: {
|
|
145
|
+
/** Constructor calldata. */
|
|
146
|
+
constructorCalldata: FieldElement[];
|
|
147
|
+
/** Salt used when computing the contract's address. */
|
|
148
|
+
contractAddressSalt: FieldElement;
|
|
149
|
+
/** Hash of the class being deployed. */
|
|
150
|
+
classHash: FieldElement;
|
|
151
|
+
};
|
|
152
|
+
invokeV0?: never;
|
|
153
|
+
invokeV1?: never;
|
|
154
|
+
deploy?: never;
|
|
155
|
+
declare?: never;
|
|
156
|
+
l1Handler?: never;
|
|
96
157
|
};
|
|
97
158
|
|
|
98
159
|
export type L1HandlerTransaction = {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
160
|
+
l1Handler?: {
|
|
161
|
+
/** Target contract address. */
|
|
162
|
+
contractAddress: FieldElement;
|
|
163
|
+
/** Selector of the function being invoked. */
|
|
164
|
+
entryPointSelector: FieldElement;
|
|
165
|
+
/** Calldata. */
|
|
166
|
+
calldata: FieldElement[];
|
|
167
|
+
};
|
|
168
|
+
invokeV0?: never;
|
|
169
|
+
invokeV1?: never;
|
|
170
|
+
deploy?: never;
|
|
171
|
+
declare?: never;
|
|
172
|
+
deployAccount?: never;
|
|
102
173
|
};
|
|
103
174
|
|
|
104
175
|
export type TransactionReceipt = {
|
|
176
|
+
/** Transaction status. */
|
|
105
177
|
executionStatus: ExecutionStatus;
|
|
178
|
+
/** Transaction hash. */
|
|
106
179
|
transactionHash: FieldElement;
|
|
180
|
+
/** Transaction index. */
|
|
107
181
|
transactionIndex: string;
|
|
182
|
+
/** Actual fee paid by the account. */
|
|
108
183
|
actualFee: FieldElement;
|
|
184
|
+
/** Address of the contract created by the transaction. */
|
|
109
185
|
contractAddress: FieldElement;
|
|
186
|
+
/** Messages from L2 to L1. */
|
|
110
187
|
l2ToL1Messages: L2ToL1Message[];
|
|
188
|
+
/** Events. */
|
|
111
189
|
events: Event[];
|
|
190
|
+
/** Revert reason. */
|
|
112
191
|
revertReason?: string;
|
|
113
192
|
};
|
|
114
193
|
|
|
@@ -118,64 +197,94 @@ export type ExecutionStatus =
|
|
|
118
197
|
| "EXECUTION_STATUS_REVERTED";
|
|
119
198
|
|
|
120
199
|
export type Event = {
|
|
200
|
+
/** Event index. */
|
|
121
201
|
index: number;
|
|
202
|
+
/** Contract address. */
|
|
122
203
|
fromAddress: FieldElement;
|
|
204
|
+
/** Event selector. */
|
|
123
205
|
keys: FieldElement[];
|
|
206
|
+
/** Event data. */
|
|
124
207
|
data: FieldElement[];
|
|
125
208
|
};
|
|
126
209
|
|
|
127
210
|
export type L2ToL1Message = {
|
|
211
|
+
/** Message index. */
|
|
128
212
|
index: number;
|
|
213
|
+
/** L2 sender address. */
|
|
129
214
|
fromAddress: FieldElement;
|
|
215
|
+
/** L1 target address. */
|
|
130
216
|
toAddress: FieldElement;
|
|
217
|
+
/** Calldata. */
|
|
131
218
|
payload: FieldElement[];
|
|
132
219
|
};
|
|
133
220
|
|
|
134
221
|
export type StateUpdate = {
|
|
222
|
+
/** New state root. */
|
|
135
223
|
newRoot: FieldElement;
|
|
224
|
+
/** Old state root. */
|
|
136
225
|
oldRoot: FieldElement;
|
|
226
|
+
/** State diff. */
|
|
137
227
|
stateDiff: StateDiff;
|
|
138
228
|
};
|
|
139
229
|
|
|
140
230
|
export type StateDiff = {
|
|
231
|
+
/** Changes in storage. */
|
|
141
232
|
storageDiffs: StorageDiff[];
|
|
233
|
+
/** Declared contracts. */
|
|
142
234
|
declaredContracts: DeclaredContract[];
|
|
235
|
+
/** Deployed contracts. */
|
|
143
236
|
deployedContracts: DeployedContract[];
|
|
237
|
+
/** Nonce updates. */
|
|
144
238
|
nonces: NonceUpdate[];
|
|
239
|
+
/** Classes declared. */
|
|
145
240
|
declaredClasses: DeclaredClass[];
|
|
241
|
+
/** Classes replaced. */
|
|
146
242
|
replacedClasses: ReplacedClass[];
|
|
147
243
|
};
|
|
148
244
|
|
|
149
245
|
export type StorageDiff = {
|
|
246
|
+
/** Contract address. */
|
|
150
247
|
contractAddress: FieldElement;
|
|
248
|
+
/** Changes in storage. */
|
|
151
249
|
storageEntries: StorageEntry[];
|
|
152
250
|
};
|
|
153
251
|
|
|
154
252
|
export type StorageEntry = {
|
|
253
|
+
/** Storage key. */
|
|
155
254
|
key: FieldElement;
|
|
255
|
+
/** New storage value. */
|
|
156
256
|
value: FieldElement;
|
|
157
257
|
};
|
|
158
258
|
|
|
159
259
|
export type DeclaredContract = {
|
|
260
|
+
/** Class hash. */
|
|
160
261
|
classHash: FieldElement;
|
|
161
262
|
};
|
|
162
263
|
|
|
163
264
|
export type DeclaredClass = {
|
|
265
|
+
/** Class hash. */
|
|
164
266
|
classHash: FieldElement;
|
|
267
|
+
/** Compiled class hash. */
|
|
165
268
|
compiledClassHash: FieldElement;
|
|
166
269
|
};
|
|
167
270
|
|
|
168
271
|
export type ReplacedClass = {
|
|
272
|
+
/** Contract address. */
|
|
169
273
|
contractAddress: FieldElement;
|
|
274
|
+
/** Class hash. */
|
|
170
275
|
classHash: FieldElement;
|
|
171
276
|
};
|
|
172
277
|
|
|
173
278
|
export type DeployedContract = {
|
|
279
|
+
/** Contract address. */
|
|
174
280
|
contractAddress: FieldElement;
|
|
281
|
+
/** Class hash. */
|
|
175
282
|
classHash: FieldElement;
|
|
176
283
|
};
|
|
177
284
|
|
|
178
285
|
export type NonceUpdate = {
|
|
286
|
+
/** Contract address. */
|
|
179
287
|
contractAddress: FieldElement;
|
|
288
|
+
/** New nonce. */
|
|
180
289
|
nonce: FieldElement;
|
|
181
290
|
};
|
package/src/starknet/filter.ts
CHANGED
|
@@ -136,6 +136,10 @@ export type EventFilter = {
|
|
|
136
136
|
data?: FieldElement[];
|
|
137
137
|
/** Include events from reverted transactions. */
|
|
138
138
|
includeReverted?: boolean;
|
|
139
|
+
/** Include the transaction that emitted the event. Defaults to true. */
|
|
140
|
+
includeTransaction?: boolean;
|
|
141
|
+
/** Include the receipt of the transaction that emitted the event. Defaults to true. */
|
|
142
|
+
includeReceipt?: boolean;
|
|
139
143
|
};
|
|
140
144
|
|
|
141
145
|
export type L2ToL1MessageFilter = {
|