starknet 6.1.5 → 6.2.1
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/CHANGELOG.md +12 -0
- package/dist/index.d.ts +3324 -499
- package/dist/index.global.js +879 -189
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +881 -189
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +879 -189
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -18,7 +18,7 @@ __export(constants_exports, {
|
|
|
18
18
|
RPC_NODES: () => RPC_NODES,
|
|
19
19
|
StarknetChainId: () => StarknetChainId,
|
|
20
20
|
TEXT_TO_FELT_MAX_LEN: () => TEXT_TO_FELT_MAX_LEN,
|
|
21
|
-
TRANSACTION_VERSION: () =>
|
|
21
|
+
TRANSACTION_VERSION: () => ETransactionVersion4,
|
|
22
22
|
TransactionHashPrefix: () => TransactionHashPrefix,
|
|
23
23
|
UDC: () => UDC,
|
|
24
24
|
ZERO: () => ZERO
|
|
@@ -27,6 +27,30 @@ __export(constants_exports, {
|
|
|
27
27
|
// src/types/api/index.ts
|
|
28
28
|
var api_exports = {};
|
|
29
29
|
__export(api_exports, {
|
|
30
|
+
EBlockTag: () => EBlockTag2,
|
|
31
|
+
EDAMode: () => EDAMode2,
|
|
32
|
+
EDataAvailabilityMode: () => EDataAvailabilityMode2,
|
|
33
|
+
ESimulationFlag: () => ESimulationFlag2,
|
|
34
|
+
ETransactionExecutionStatus: () => ETransactionExecutionStatus2,
|
|
35
|
+
ETransactionFinalityStatus: () => ETransactionFinalityStatus2,
|
|
36
|
+
ETransactionStatus: () => ETransactionStatus2,
|
|
37
|
+
ETransactionType: () => ETransactionType2,
|
|
38
|
+
ETransactionVersion: () => ETransactionVersion4,
|
|
39
|
+
ETransactionVersion2: () => ETransactionVersion22,
|
|
40
|
+
ETransactionVersion3: () => ETransactionVersion32,
|
|
41
|
+
Errors: () => errors_exports2,
|
|
42
|
+
JRPC: () => jsonrpc_exports,
|
|
43
|
+
RPCSPEC06: () => rpcspec_0_6_exports,
|
|
44
|
+
RPCSPEC07: () => rpcspec_0_7_exports,
|
|
45
|
+
SPEC: () => components_exports2
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// src/types/api/jsonrpc/index.ts
|
|
49
|
+
var jsonrpc_exports = {};
|
|
50
|
+
|
|
51
|
+
// src/types/api/rpcspec_0_6/index.ts
|
|
52
|
+
var rpcspec_0_6_exports = {};
|
|
53
|
+
__export(rpcspec_0_6_exports, {
|
|
30
54
|
EBlockTag: () => EBlockTag,
|
|
31
55
|
EDAMode: () => EDAMode,
|
|
32
56
|
EDataAvailabilityMode: () => EDataAvailabilityMode,
|
|
@@ -39,13 +63,9 @@ __export(api_exports, {
|
|
|
39
63
|
ETransactionVersion2: () => ETransactionVersion2,
|
|
40
64
|
ETransactionVersion3: () => ETransactionVersion3,
|
|
41
65
|
Errors: () => errors_exports,
|
|
42
|
-
JRPC: () => jsonrpc_exports,
|
|
43
66
|
SPEC: () => components_exports
|
|
44
67
|
});
|
|
45
68
|
|
|
46
|
-
// src/types/api/jsonrpc/index.ts
|
|
47
|
-
var jsonrpc_exports = {};
|
|
48
|
-
|
|
49
69
|
// src/types/api/rpcspec_0_6/errors.ts
|
|
50
70
|
var errors_exports = {};
|
|
51
71
|
|
|
@@ -53,77 +73,173 @@ var errors_exports = {};
|
|
|
53
73
|
var components_exports = {};
|
|
54
74
|
|
|
55
75
|
// src/types/api/rpcspec_0_6/nonspec.ts
|
|
56
|
-
var ETransactionType = /* @__PURE__ */ ((
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return
|
|
76
|
+
var ETransactionType = /* @__PURE__ */ ((ETransactionType3) => {
|
|
77
|
+
ETransactionType3["DECLARE"] = "DECLARE";
|
|
78
|
+
ETransactionType3["DEPLOY"] = "DEPLOY";
|
|
79
|
+
ETransactionType3["DEPLOY_ACCOUNT"] = "DEPLOY_ACCOUNT";
|
|
80
|
+
ETransactionType3["INVOKE"] = "INVOKE";
|
|
81
|
+
ETransactionType3["L1_HANDLER"] = "L1_HANDLER";
|
|
82
|
+
return ETransactionType3;
|
|
63
83
|
})(ETransactionType || {});
|
|
64
|
-
var ESimulationFlag = /* @__PURE__ */ ((
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return
|
|
84
|
+
var ESimulationFlag = /* @__PURE__ */ ((ESimulationFlag3) => {
|
|
85
|
+
ESimulationFlag3["SKIP_VALIDATE"] = "SKIP_VALIDATE";
|
|
86
|
+
ESimulationFlag3["SKIP_FEE_CHARGE"] = "SKIP_FEE_CHARGE";
|
|
87
|
+
return ESimulationFlag3;
|
|
68
88
|
})(ESimulationFlag || {});
|
|
69
|
-
var ETransactionStatus = /* @__PURE__ */ ((
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return
|
|
89
|
+
var ETransactionStatus = /* @__PURE__ */ ((ETransactionStatus3) => {
|
|
90
|
+
ETransactionStatus3["RECEIVED"] = "RECEIVED";
|
|
91
|
+
ETransactionStatus3["REJECTED"] = "REJECTED";
|
|
92
|
+
ETransactionStatus3["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
|
|
93
|
+
ETransactionStatus3["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
|
|
94
|
+
return ETransactionStatus3;
|
|
75
95
|
})(ETransactionStatus || {});
|
|
76
|
-
var ETransactionFinalityStatus = /* @__PURE__ */ ((
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return
|
|
96
|
+
var ETransactionFinalityStatus = /* @__PURE__ */ ((ETransactionFinalityStatus3) => {
|
|
97
|
+
ETransactionFinalityStatus3["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
|
|
98
|
+
ETransactionFinalityStatus3["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
|
|
99
|
+
return ETransactionFinalityStatus3;
|
|
80
100
|
})(ETransactionFinalityStatus || {});
|
|
81
|
-
var ETransactionExecutionStatus = /* @__PURE__ */ ((
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return
|
|
101
|
+
var ETransactionExecutionStatus = /* @__PURE__ */ ((ETransactionExecutionStatus3) => {
|
|
102
|
+
ETransactionExecutionStatus3["SUCCEEDED"] = "SUCCEEDED";
|
|
103
|
+
ETransactionExecutionStatus3["REVERTED"] = "REVERTED";
|
|
104
|
+
return ETransactionExecutionStatus3;
|
|
85
105
|
})(ETransactionExecutionStatus || {});
|
|
86
|
-
var EBlockTag = /* @__PURE__ */ ((
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return
|
|
106
|
+
var EBlockTag = /* @__PURE__ */ ((EBlockTag3) => {
|
|
107
|
+
EBlockTag3["LATEST"] = "latest";
|
|
108
|
+
EBlockTag3["PENDING"] = "pending";
|
|
109
|
+
return EBlockTag3;
|
|
90
110
|
})(EBlockTag || {});
|
|
91
|
-
var EDataAvailabilityMode = /* @__PURE__ */ ((
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return
|
|
111
|
+
var EDataAvailabilityMode = /* @__PURE__ */ ((EDataAvailabilityMode3) => {
|
|
112
|
+
EDataAvailabilityMode3["L1"] = "L1";
|
|
113
|
+
EDataAvailabilityMode3["L2"] = "L2";
|
|
114
|
+
return EDataAvailabilityMode3;
|
|
95
115
|
})(EDataAvailabilityMode || {});
|
|
96
|
-
var EDAMode = /* @__PURE__ */ ((
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
return
|
|
116
|
+
var EDAMode = /* @__PURE__ */ ((EDAMode4) => {
|
|
117
|
+
EDAMode4[EDAMode4["L1"] = 0] = "L1";
|
|
118
|
+
EDAMode4[EDAMode4["L2"] = 1] = "L2";
|
|
119
|
+
return EDAMode4;
|
|
100
120
|
})(EDAMode || {});
|
|
101
|
-
var ETransactionVersion = /* @__PURE__ */ ((
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
return
|
|
121
|
+
var ETransactionVersion = /* @__PURE__ */ ((ETransactionVersion5) => {
|
|
122
|
+
ETransactionVersion5["V0"] = "0x0";
|
|
123
|
+
ETransactionVersion5["V1"] = "0x1";
|
|
124
|
+
ETransactionVersion5["V2"] = "0x2";
|
|
125
|
+
ETransactionVersion5["V3"] = "0x3";
|
|
126
|
+
ETransactionVersion5["F0"] = "0x100000000000000000000000000000000";
|
|
127
|
+
ETransactionVersion5["F1"] = "0x100000000000000000000000000000001";
|
|
128
|
+
ETransactionVersion5["F2"] = "0x100000000000000000000000000000002";
|
|
129
|
+
ETransactionVersion5["F3"] = "0x100000000000000000000000000000003";
|
|
130
|
+
return ETransactionVersion5;
|
|
111
131
|
})(ETransactionVersion || {});
|
|
112
|
-
var ETransactionVersion2 = /* @__PURE__ */ ((
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
return
|
|
132
|
+
var ETransactionVersion2 = /* @__PURE__ */ ((ETransactionVersion24) => {
|
|
133
|
+
ETransactionVersion24["V0"] = "0x0";
|
|
134
|
+
ETransactionVersion24["V1"] = "0x1";
|
|
135
|
+
ETransactionVersion24["V2"] = "0x2";
|
|
136
|
+
ETransactionVersion24["F0"] = "0x100000000000000000000000000000000";
|
|
137
|
+
ETransactionVersion24["F1"] = "0x100000000000000000000000000000001";
|
|
138
|
+
ETransactionVersion24["F2"] = "0x100000000000000000000000000000002";
|
|
139
|
+
return ETransactionVersion24;
|
|
120
140
|
})(ETransactionVersion2 || {});
|
|
121
|
-
var ETransactionVersion3 = /* @__PURE__ */ ((
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return
|
|
141
|
+
var ETransactionVersion3 = /* @__PURE__ */ ((ETransactionVersion34) => {
|
|
142
|
+
ETransactionVersion34["V3"] = "0x3";
|
|
143
|
+
ETransactionVersion34["F3"] = "0x100000000000000000000000000000003";
|
|
144
|
+
return ETransactionVersion34;
|
|
125
145
|
})(ETransactionVersion3 || {});
|
|
126
146
|
|
|
147
|
+
// src/types/api/rpcspec_0_7/index.ts
|
|
148
|
+
var rpcspec_0_7_exports = {};
|
|
149
|
+
__export(rpcspec_0_7_exports, {
|
|
150
|
+
EBlockTag: () => EBlockTag2,
|
|
151
|
+
EDAMode: () => EDAMode2,
|
|
152
|
+
EDataAvailabilityMode: () => EDataAvailabilityMode2,
|
|
153
|
+
ESimulationFlag: () => ESimulationFlag2,
|
|
154
|
+
ETransactionExecutionStatus: () => ETransactionExecutionStatus2,
|
|
155
|
+
ETransactionFinalityStatus: () => ETransactionFinalityStatus2,
|
|
156
|
+
ETransactionStatus: () => ETransactionStatus2,
|
|
157
|
+
ETransactionType: () => ETransactionType2,
|
|
158
|
+
ETransactionVersion: () => ETransactionVersion4,
|
|
159
|
+
ETransactionVersion2: () => ETransactionVersion22,
|
|
160
|
+
ETransactionVersion3: () => ETransactionVersion32,
|
|
161
|
+
Errors: () => errors_exports2,
|
|
162
|
+
SPEC: () => components_exports2
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// src/types/api/rpcspec_0_7/errors.ts
|
|
166
|
+
var errors_exports2 = {};
|
|
167
|
+
|
|
168
|
+
// src/types/api/rpcspec_0_7/components.ts
|
|
169
|
+
var components_exports2 = {};
|
|
170
|
+
|
|
171
|
+
// src/types/api/rpcspec_0_7/nonspec.ts
|
|
172
|
+
var ETransactionType2 = /* @__PURE__ */ ((ETransactionType3) => {
|
|
173
|
+
ETransactionType3["DECLARE"] = "DECLARE";
|
|
174
|
+
ETransactionType3["DEPLOY"] = "DEPLOY";
|
|
175
|
+
ETransactionType3["DEPLOY_ACCOUNT"] = "DEPLOY_ACCOUNT";
|
|
176
|
+
ETransactionType3["INVOKE"] = "INVOKE";
|
|
177
|
+
ETransactionType3["L1_HANDLER"] = "L1_HANDLER";
|
|
178
|
+
return ETransactionType3;
|
|
179
|
+
})(ETransactionType2 || {});
|
|
180
|
+
var ESimulationFlag2 = /* @__PURE__ */ ((ESimulationFlag3) => {
|
|
181
|
+
ESimulationFlag3["SKIP_VALIDATE"] = "SKIP_VALIDATE";
|
|
182
|
+
ESimulationFlag3["SKIP_FEE_CHARGE"] = "SKIP_FEE_CHARGE";
|
|
183
|
+
return ESimulationFlag3;
|
|
184
|
+
})(ESimulationFlag2 || {});
|
|
185
|
+
var ETransactionStatus2 = /* @__PURE__ */ ((ETransactionStatus3) => {
|
|
186
|
+
ETransactionStatus3["RECEIVED"] = "RECEIVED";
|
|
187
|
+
ETransactionStatus3["REJECTED"] = "REJECTED";
|
|
188
|
+
ETransactionStatus3["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
|
|
189
|
+
ETransactionStatus3["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
|
|
190
|
+
return ETransactionStatus3;
|
|
191
|
+
})(ETransactionStatus2 || {});
|
|
192
|
+
var ETransactionFinalityStatus2 = /* @__PURE__ */ ((ETransactionFinalityStatus3) => {
|
|
193
|
+
ETransactionFinalityStatus3["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
|
|
194
|
+
ETransactionFinalityStatus3["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
|
|
195
|
+
return ETransactionFinalityStatus3;
|
|
196
|
+
})(ETransactionFinalityStatus2 || {});
|
|
197
|
+
var ETransactionExecutionStatus2 = /* @__PURE__ */ ((ETransactionExecutionStatus3) => {
|
|
198
|
+
ETransactionExecutionStatus3["SUCCEEDED"] = "SUCCEEDED";
|
|
199
|
+
ETransactionExecutionStatus3["REVERTED"] = "REVERTED";
|
|
200
|
+
return ETransactionExecutionStatus3;
|
|
201
|
+
})(ETransactionExecutionStatus2 || {});
|
|
202
|
+
var EBlockTag2 = /* @__PURE__ */ ((EBlockTag3) => {
|
|
203
|
+
EBlockTag3["LATEST"] = "latest";
|
|
204
|
+
EBlockTag3["PENDING"] = "pending";
|
|
205
|
+
return EBlockTag3;
|
|
206
|
+
})(EBlockTag2 || {});
|
|
207
|
+
var EDataAvailabilityMode2 = /* @__PURE__ */ ((EDataAvailabilityMode3) => {
|
|
208
|
+
EDataAvailabilityMode3["L1"] = "L1";
|
|
209
|
+
EDataAvailabilityMode3["L2"] = "L2";
|
|
210
|
+
return EDataAvailabilityMode3;
|
|
211
|
+
})(EDataAvailabilityMode2 || {});
|
|
212
|
+
var EDAMode2 = /* @__PURE__ */ ((EDAMode4) => {
|
|
213
|
+
EDAMode4[EDAMode4["L1"] = 0] = "L1";
|
|
214
|
+
EDAMode4[EDAMode4["L2"] = 1] = "L2";
|
|
215
|
+
return EDAMode4;
|
|
216
|
+
})(EDAMode2 || {});
|
|
217
|
+
var ETransactionVersion4 = /* @__PURE__ */ ((ETransactionVersion5) => {
|
|
218
|
+
ETransactionVersion5["V0"] = "0x0";
|
|
219
|
+
ETransactionVersion5["V1"] = "0x1";
|
|
220
|
+
ETransactionVersion5["V2"] = "0x2";
|
|
221
|
+
ETransactionVersion5["V3"] = "0x3";
|
|
222
|
+
ETransactionVersion5["F0"] = "0x100000000000000000000000000000000";
|
|
223
|
+
ETransactionVersion5["F1"] = "0x100000000000000000000000000000001";
|
|
224
|
+
ETransactionVersion5["F2"] = "0x100000000000000000000000000000002";
|
|
225
|
+
ETransactionVersion5["F3"] = "0x100000000000000000000000000000003";
|
|
226
|
+
return ETransactionVersion5;
|
|
227
|
+
})(ETransactionVersion4 || {});
|
|
228
|
+
var ETransactionVersion22 = /* @__PURE__ */ ((ETransactionVersion24) => {
|
|
229
|
+
ETransactionVersion24["V0"] = "0x0";
|
|
230
|
+
ETransactionVersion24["V1"] = "0x1";
|
|
231
|
+
ETransactionVersion24["V2"] = "0x2";
|
|
232
|
+
ETransactionVersion24["F0"] = "0x100000000000000000000000000000000";
|
|
233
|
+
ETransactionVersion24["F1"] = "0x100000000000000000000000000000001";
|
|
234
|
+
ETransactionVersion24["F2"] = "0x100000000000000000000000000000002";
|
|
235
|
+
return ETransactionVersion24;
|
|
236
|
+
})(ETransactionVersion22 || {});
|
|
237
|
+
var ETransactionVersion32 = /* @__PURE__ */ ((ETransactionVersion34) => {
|
|
238
|
+
ETransactionVersion34["V3"] = "0x3";
|
|
239
|
+
ETransactionVersion34["F3"] = "0x100000000000000000000000000000003";
|
|
240
|
+
return ETransactionVersion34;
|
|
241
|
+
})(ETransactionVersion32 || {});
|
|
242
|
+
|
|
127
243
|
// src/utils/encode.ts
|
|
128
244
|
var encode_exports = {};
|
|
129
245
|
__export(encode_exports, {
|
|
@@ -218,11 +334,11 @@ var NetworkName = /* @__PURE__ */ ((NetworkName2) => {
|
|
|
218
334
|
NetworkName2["SN_SEPOLIA"] = "SN_SEPOLIA";
|
|
219
335
|
return NetworkName2;
|
|
220
336
|
})(NetworkName || {});
|
|
221
|
-
var StarknetChainId = /* @__PURE__ */ ((
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
return
|
|
337
|
+
var StarknetChainId = /* @__PURE__ */ ((StarknetChainId6) => {
|
|
338
|
+
StarknetChainId6["SN_MAIN"] = "0x534e5f4d41494e";
|
|
339
|
+
StarknetChainId6["SN_GOERLI"] = "0x534e5f474f45524c49";
|
|
340
|
+
StarknetChainId6["SN_SEPOLIA"] = "0x534e5f5345504f4c4941";
|
|
341
|
+
return StarknetChainId6;
|
|
226
342
|
})(StarknetChainId || {});
|
|
227
343
|
var TransactionHashPrefix = /* @__PURE__ */ ((TransactionHashPrefix2) => {
|
|
228
344
|
TransactionHashPrefix2["DECLARE"] = "0x6465636c617265";
|
|
@@ -289,6 +405,12 @@ var HttpError = class extends LibraryError {
|
|
|
289
405
|
}
|
|
290
406
|
};
|
|
291
407
|
|
|
408
|
+
// src/channel/rpc_0_6.ts
|
|
409
|
+
var rpc_0_6_exports = {};
|
|
410
|
+
__export(rpc_0_6_exports, {
|
|
411
|
+
RpcChannel: () => RpcChannel
|
|
412
|
+
});
|
|
413
|
+
|
|
292
414
|
// src/types/index.ts
|
|
293
415
|
var types_exports = {};
|
|
294
416
|
__export(types_exports, {
|
|
@@ -1189,13 +1311,40 @@ function extractCairo0Tuple(type) {
|
|
|
1189
1311
|
}
|
|
1190
1312
|
return recomposed;
|
|
1191
1313
|
}
|
|
1314
|
+
function getClosureOffset(input, open, close) {
|
|
1315
|
+
for (let i = 0, counter = 0; i < input.length; i++) {
|
|
1316
|
+
if (input[i] === open) {
|
|
1317
|
+
counter++;
|
|
1318
|
+
} else if (input[i] === close && --counter === 0) {
|
|
1319
|
+
return i;
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
return Number.POSITIVE_INFINITY;
|
|
1323
|
+
}
|
|
1192
1324
|
function extractCairo1Tuple(type) {
|
|
1193
|
-
const
|
|
1194
|
-
const
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1325
|
+
const input = type.slice(1, -1);
|
|
1326
|
+
const result = [];
|
|
1327
|
+
let currentIndex = 0;
|
|
1328
|
+
let limitIndex;
|
|
1329
|
+
while (currentIndex < input.length) {
|
|
1330
|
+
switch (true) {
|
|
1331
|
+
case input[currentIndex] === "(": {
|
|
1332
|
+
limitIndex = currentIndex + getClosureOffset(input.slice(currentIndex), "(", ")") + 1;
|
|
1333
|
+
break;
|
|
1334
|
+
}
|
|
1335
|
+
case (input.startsWith("core::result::Result::<", currentIndex) || input.startsWith("core::array::Array::<", currentIndex) || input.startsWith("core::option::Option::<", currentIndex)): {
|
|
1336
|
+
limitIndex = currentIndex + getClosureOffset(input.slice(currentIndex), "<", ">") + 1;
|
|
1337
|
+
break;
|
|
1338
|
+
}
|
|
1339
|
+
default: {
|
|
1340
|
+
const commaIndex = input.indexOf(",", currentIndex);
|
|
1341
|
+
limitIndex = commaIndex !== -1 ? commaIndex : Number.POSITIVE_INFINITY;
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
result.push(input.slice(currentIndex, limitIndex));
|
|
1345
|
+
currentIndex = limitIndex + 2;
|
|
1346
|
+
}
|
|
1347
|
+
return result;
|
|
1199
1348
|
}
|
|
1200
1349
|
function extractTupleMemberTypes(type) {
|
|
1201
1350
|
if (isCairo1Type(type)) {
|
|
@@ -2723,10 +2872,10 @@ function intDAM(dam) {
|
|
|
2723
2872
|
function toTransactionVersion(defaultVersion, providedVersion) {
|
|
2724
2873
|
const providedVersion0xs = providedVersion ? toHex(providedVersion) : void 0;
|
|
2725
2874
|
const defaultVersion0xs = toHex(defaultVersion);
|
|
2726
|
-
if (providedVersion && !Object.values(
|
|
2875
|
+
if (providedVersion && !Object.values(ETransactionVersion4).includes(providedVersion0xs)) {
|
|
2727
2876
|
throw Error(`providedVersion ${providedVersion} is not ETransactionVersion`);
|
|
2728
2877
|
}
|
|
2729
|
-
if (!Object.values(
|
|
2878
|
+
if (!Object.values(ETransactionVersion4).includes(defaultVersion0xs)) {
|
|
2730
2879
|
throw Error(`defaultVersion ${defaultVersion} is not ETransactionVersion`);
|
|
2731
2880
|
}
|
|
2732
2881
|
return providedVersion ? providedVersion0xs : defaultVersion0xs;
|
|
@@ -3160,9 +3309,9 @@ var RpcChannel = class {
|
|
|
3160
3309
|
const block_id = new Block(blockIdentifier).identifier;
|
|
3161
3310
|
const simulationFlags = [];
|
|
3162
3311
|
if (skipValidate)
|
|
3163
|
-
simulationFlags.push(
|
|
3312
|
+
simulationFlags.push(rpcspec_0_6_exports.ESimulationFlag.SKIP_VALIDATE);
|
|
3164
3313
|
if (skipFeeCharge)
|
|
3165
|
-
simulationFlags.push(
|
|
3314
|
+
simulationFlags.push(rpcspec_0_6_exports.ESimulationFlag.SKIP_FEE_CHARGE);
|
|
3166
3315
|
return this.fetchEndpoint("starknet_simulateTransactions", {
|
|
3167
3316
|
block_id,
|
|
3168
3317
|
transactions: invocations.map((it) => this.buildTransaction(it)),
|
|
@@ -3176,15 +3325,15 @@ var RpcChannel = class {
|
|
|
3176
3325
|
let isErrorState = false;
|
|
3177
3326
|
const retryInterval = options?.retryInterval ?? 5e3;
|
|
3178
3327
|
const errorStates = options?.errorStates ?? [
|
|
3179
|
-
|
|
3328
|
+
rpcspec_0_6_exports.ETransactionStatus.REJECTED
|
|
3180
3329
|
// TODO: commented out to preserve the long-standing behavior of "reverted" not being treated as an error by default
|
|
3181
3330
|
// should decide which behavior to keep in the future
|
|
3182
3331
|
// RPC.ETransactionExecutionStatus.REVERTED,
|
|
3183
3332
|
];
|
|
3184
3333
|
const successStates = options?.successStates ?? [
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3334
|
+
rpcspec_0_6_exports.ETransactionExecutionStatus.SUCCEEDED,
|
|
3335
|
+
rpcspec_0_6_exports.ETransactionStatus.ACCEPTED_ON_L2,
|
|
3336
|
+
rpcspec_0_6_exports.ETransactionStatus.ACCEPTED_ON_L1
|
|
3188
3337
|
];
|
|
3189
3338
|
let txStatus;
|
|
3190
3339
|
while (!onchain) {
|
|
@@ -3267,9 +3416,9 @@ var RpcChannel = class {
|
|
|
3267
3416
|
async getEstimateFee(invocations, { blockIdentifier = this.blockIdentifier, skipValidate = true }) {
|
|
3268
3417
|
const block_id = new Block(blockIdentifier).identifier;
|
|
3269
3418
|
let flags = {};
|
|
3270
|
-
if (isVersion("0.
|
|
3419
|
+
if (!isVersion("0.5", await this.getSpecVersion())) {
|
|
3271
3420
|
flags = {
|
|
3272
|
-
simulation_flags: skipValidate ? [
|
|
3421
|
+
simulation_flags: skipValidate ? [rpcspec_0_6_exports.ESimulationFlag.SKIP_VALIDATE] : []
|
|
3273
3422
|
};
|
|
3274
3423
|
}
|
|
3275
3424
|
return this.fetchEndpoint("starknet_estimateFee", {
|
|
@@ -3285,9 +3434,9 @@ var RpcChannel = class {
|
|
|
3285
3434
|
invoke_transaction: {
|
|
3286
3435
|
sender_address: functionInvocation.contractAddress,
|
|
3287
3436
|
calldata: CallData.toHex(functionInvocation.calldata),
|
|
3288
|
-
type:
|
|
3437
|
+
type: rpcspec_0_6_exports.ETransactionType.INVOKE,
|
|
3289
3438
|
max_fee: toHex(details.maxFee || 0),
|
|
3290
|
-
version:
|
|
3439
|
+
version: rpcspec_0_6_exports.ETransactionVersion.V1,
|
|
3291
3440
|
signature: signatureToHexArray(functionInvocation.signature),
|
|
3292
3441
|
nonce: toHex(details.nonce)
|
|
3293
3442
|
}
|
|
@@ -3295,10 +3444,10 @@ var RpcChannel = class {
|
|
|
3295
3444
|
} else {
|
|
3296
3445
|
promise = this.fetchEndpoint("starknet_addInvokeTransaction", {
|
|
3297
3446
|
invoke_transaction: {
|
|
3298
|
-
type:
|
|
3447
|
+
type: rpcspec_0_6_exports.ETransactionType.INVOKE,
|
|
3299
3448
|
sender_address: functionInvocation.contractAddress,
|
|
3300
3449
|
calldata: CallData.toHex(functionInvocation.calldata),
|
|
3301
|
-
version:
|
|
3450
|
+
version: rpcspec_0_6_exports.ETransactionVersion.V3,
|
|
3302
3451
|
signature: signatureToHexArray(functionInvocation.signature),
|
|
3303
3452
|
nonce: toHex(details.nonce),
|
|
3304
3453
|
resource_bounds: details.resourceBounds,
|
|
@@ -3317,13 +3466,13 @@ var RpcChannel = class {
|
|
|
3317
3466
|
if (!isSierra(contract) && !isV3Tx(details)) {
|
|
3318
3467
|
promise = this.fetchEndpoint("starknet_addDeclareTransaction", {
|
|
3319
3468
|
declare_transaction: {
|
|
3320
|
-
type:
|
|
3469
|
+
type: rpcspec_0_6_exports.ETransactionType.DECLARE,
|
|
3321
3470
|
contract_class: {
|
|
3322
3471
|
program: contract.program,
|
|
3323
3472
|
entry_points_by_type: contract.entry_points_by_type,
|
|
3324
3473
|
abi: contract.abi
|
|
3325
3474
|
},
|
|
3326
|
-
version:
|
|
3475
|
+
version: rpcspec_0_6_exports.ETransactionVersion.V1,
|
|
3327
3476
|
max_fee: toHex(details.maxFee || 0),
|
|
3328
3477
|
signature: signatureToHexArray(signature),
|
|
3329
3478
|
sender_address: senderAddress,
|
|
@@ -3333,7 +3482,7 @@ var RpcChannel = class {
|
|
|
3333
3482
|
} else if (isSierra(contract) && !isV3Tx(details)) {
|
|
3334
3483
|
promise = this.fetchEndpoint("starknet_addDeclareTransaction", {
|
|
3335
3484
|
declare_transaction: {
|
|
3336
|
-
type:
|
|
3485
|
+
type: rpcspec_0_6_exports.ETransactionType.DECLARE,
|
|
3337
3486
|
contract_class: {
|
|
3338
3487
|
sierra_program: decompressProgram(contract.sierra_program),
|
|
3339
3488
|
contract_class_version: contract.contract_class_version,
|
|
@@ -3341,7 +3490,7 @@ var RpcChannel = class {
|
|
|
3341
3490
|
abi: contract.abi
|
|
3342
3491
|
},
|
|
3343
3492
|
compiled_class_hash: compiledClassHash || "",
|
|
3344
|
-
version:
|
|
3493
|
+
version: rpcspec_0_6_exports.ETransactionVersion.V2,
|
|
3345
3494
|
max_fee: toHex(details.maxFee || 0),
|
|
3346
3495
|
signature: signatureToHexArray(signature),
|
|
3347
3496
|
sender_address: senderAddress,
|
|
@@ -3351,10 +3500,10 @@ var RpcChannel = class {
|
|
|
3351
3500
|
} else if (isSierra(contract) && isV3Tx(details)) {
|
|
3352
3501
|
promise = this.fetchEndpoint("starknet_addDeclareTransaction", {
|
|
3353
3502
|
declare_transaction: {
|
|
3354
|
-
type:
|
|
3503
|
+
type: rpcspec_0_6_exports.ETransactionType.DECLARE,
|
|
3355
3504
|
sender_address: senderAddress,
|
|
3356
3505
|
compiled_class_hash: compiledClassHash || "",
|
|
3357
|
-
version:
|
|
3506
|
+
version: rpcspec_0_6_exports.ETransactionVersion.V3,
|
|
3358
3507
|
signature: signatureToHexArray(signature),
|
|
3359
3508
|
nonce: toHex(details.nonce),
|
|
3360
3509
|
contract_class: {
|
|
@@ -3384,9 +3533,9 @@ var RpcChannel = class {
|
|
|
3384
3533
|
constructor_calldata: CallData.toHex(constructorCalldata || []),
|
|
3385
3534
|
class_hash: toHex(classHash),
|
|
3386
3535
|
contract_address_salt: toHex(addressSalt || 0),
|
|
3387
|
-
type:
|
|
3536
|
+
type: rpcspec_0_6_exports.ETransactionType.DEPLOY_ACCOUNT,
|
|
3388
3537
|
max_fee: toHex(details.maxFee || 0),
|
|
3389
|
-
version:
|
|
3538
|
+
version: rpcspec_0_6_exports.ETransactionVersion.V1,
|
|
3390
3539
|
signature: signatureToHexArray(signature),
|
|
3391
3540
|
nonce: toHex(details.nonce)
|
|
3392
3541
|
}
|
|
@@ -3394,8 +3543,8 @@ var RpcChannel = class {
|
|
|
3394
3543
|
} else {
|
|
3395
3544
|
promise = this.fetchEndpoint("starknet_addDeployAccountTransaction", {
|
|
3396
3545
|
deploy_account_transaction: {
|
|
3397
|
-
type:
|
|
3398
|
-
version:
|
|
3546
|
+
type: rpcspec_0_6_exports.ETransactionType.DEPLOY_ACCOUNT,
|
|
3547
|
+
version: rpcspec_0_6_exports.ETransactionVersion.V3,
|
|
3399
3548
|
signature: signatureToHexArray(signature),
|
|
3400
3549
|
nonce: toHex(details.nonce),
|
|
3401
3550
|
contract_address_salt: toHex(addressSalt || 0),
|
|
@@ -3478,7 +3627,7 @@ var RpcChannel = class {
|
|
|
3478
3627
|
if (invocation.type === "INVOKE_FUNCTION" /* INVOKE */) {
|
|
3479
3628
|
return {
|
|
3480
3629
|
// v0 v1 v3
|
|
3481
|
-
type:
|
|
3630
|
+
type: rpcspec_0_6_exports.ETransactionType.INVOKE,
|
|
3482
3631
|
// TODO: Diff between sequencer and rpc invoke type
|
|
3483
3632
|
sender_address: invocation.contractAddress,
|
|
3484
3633
|
calldata: CallData.toHex(invocation.calldata),
|
|
@@ -3524,106 +3673,645 @@ var RpcChannel = class {
|
|
|
3524
3673
|
}
|
|
3525
3674
|
};
|
|
3526
3675
|
|
|
3527
|
-
// src/
|
|
3528
|
-
var
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3676
|
+
// src/channel/rpc_0_7.ts
|
|
3677
|
+
var rpc_0_7_exports = {};
|
|
3678
|
+
__export(rpc_0_7_exports, {
|
|
3679
|
+
RpcChannel: () => RpcChannel2
|
|
3680
|
+
});
|
|
3681
|
+
var defaultOptions2 = {
|
|
3682
|
+
headers: { "Content-Type": "application/json" },
|
|
3683
|
+
blockIdentifier: "pending" /* pending */,
|
|
3684
|
+
retries: 200
|
|
3685
|
+
};
|
|
3686
|
+
var RpcChannel2 = class {
|
|
3687
|
+
nodeUrl;
|
|
3688
|
+
headers;
|
|
3689
|
+
retries;
|
|
3690
|
+
requestId;
|
|
3691
|
+
blockIdentifier;
|
|
3692
|
+
chainId;
|
|
3693
|
+
speckVersion;
|
|
3694
|
+
waitMode;
|
|
3695
|
+
// behave like web2 rpc and return when tx is processed
|
|
3696
|
+
constructor(optionsOrProvider) {
|
|
3697
|
+
const { nodeUrl, retries, headers, blockIdentifier, chainId, waitMode } = optionsOrProvider || {};
|
|
3698
|
+
if (Object.values(NetworkName).includes(nodeUrl)) {
|
|
3699
|
+
this.nodeUrl = getDefaultNodeUrl(nodeUrl, optionsOrProvider?.default);
|
|
3700
|
+
} else if (nodeUrl) {
|
|
3701
|
+
this.nodeUrl = nodeUrl;
|
|
3702
|
+
} else {
|
|
3703
|
+
this.nodeUrl = getDefaultNodeUrl(void 0, optionsOrProvider?.default);
|
|
3541
3704
|
}
|
|
3542
|
-
|
|
3705
|
+
this.retries = retries || defaultOptions2.retries;
|
|
3706
|
+
this.headers = { ...defaultOptions2.headers, ...headers };
|
|
3707
|
+
this.blockIdentifier = blockIdentifier || defaultOptions2.blockIdentifier;
|
|
3708
|
+
this.chainId = chainId;
|
|
3709
|
+
this.waitMode = waitMode || false;
|
|
3710
|
+
this.requestId = 0;
|
|
3543
3711
|
}
|
|
3544
|
-
|
|
3545
|
-
const
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
unit: val.unit,
|
|
3551
|
-
suggestedMaxFee: estimatedFeeToMaxFee(val.overall_fee),
|
|
3552
|
-
resourceBounds: estimateFeeToBounds(val)
|
|
3712
|
+
fetch(method, params, id = 0) {
|
|
3713
|
+
const rpcRequestBody = {
|
|
3714
|
+
id,
|
|
3715
|
+
jsonrpc: "2.0",
|
|
3716
|
+
method,
|
|
3717
|
+
...params && { params }
|
|
3553
3718
|
};
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
gas_consumed: toBigInt(val.gas_consumed),
|
|
3559
|
-
gas_price: toBigInt(val.gas_price),
|
|
3560
|
-
unit: val.unit,
|
|
3561
|
-
suggestedMaxFee: estimatedFeeToMaxFee(val.overall_fee),
|
|
3562
|
-
resourceBounds: estimateFeeToBounds(val)
|
|
3563
|
-
}));
|
|
3564
|
-
}
|
|
3565
|
-
parseSimulateTransactionResponse(res) {
|
|
3566
|
-
return res.map((it) => {
|
|
3567
|
-
return {
|
|
3568
|
-
...it,
|
|
3569
|
-
suggestedMaxFee: estimatedFeeToMaxFee(BigInt(it.fee_estimation.overall_fee)),
|
|
3570
|
-
resourceBounds: estimateFeeToBounds(it.fee_estimation)
|
|
3571
|
-
};
|
|
3719
|
+
return fetchPonyfill_default(this.nodeUrl, {
|
|
3720
|
+
method: "POST",
|
|
3721
|
+
body: stringify2(rpcRequestBody),
|
|
3722
|
+
headers: this.headers
|
|
3572
3723
|
});
|
|
3573
3724
|
}
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
}
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
this.channel = optionsOrProvider.channel;
|
|
3589
|
-
} else {
|
|
3590
|
-
this.channel = new RpcChannel({ ...optionsOrProvider, waitMode: false });
|
|
3725
|
+
errorHandler(method, params, rpcError, otherError) {
|
|
3726
|
+
if (rpcError) {
|
|
3727
|
+
const { code, message, data } = rpcError;
|
|
3728
|
+
throw new LibraryError(
|
|
3729
|
+
`RPC: ${method} with params ${stringify2(params, null, 2)}
|
|
3730
|
+
|
|
3731
|
+
${code}: ${message}: ${stringify2(data)}`
|
|
3732
|
+
);
|
|
3733
|
+
}
|
|
3734
|
+
if (otherError instanceof LibraryError) {
|
|
3735
|
+
throw otherError;
|
|
3736
|
+
}
|
|
3737
|
+
if (otherError) {
|
|
3738
|
+
throw Error(otherError.message);
|
|
3591
3739
|
}
|
|
3592
3740
|
}
|
|
3593
|
-
|
|
3594
|
-
|
|
3741
|
+
async fetchEndpoint(method, params) {
|
|
3742
|
+
try {
|
|
3743
|
+
const rawResult = await this.fetch(method, params, this.requestId += 1);
|
|
3744
|
+
const { error, result } = await rawResult.json();
|
|
3745
|
+
this.errorHandler(method, params, error);
|
|
3746
|
+
return result;
|
|
3747
|
+
} catch (error) {
|
|
3748
|
+
this.errorHandler(method, params, error?.response?.data, error);
|
|
3749
|
+
throw error;
|
|
3750
|
+
}
|
|
3595
3751
|
}
|
|
3596
3752
|
async getChainId() {
|
|
3597
|
-
|
|
3753
|
+
this.chainId ??= await this.fetchEndpoint("starknet_chainId");
|
|
3754
|
+
return this.chainId;
|
|
3598
3755
|
}
|
|
3599
3756
|
async getSpecVersion() {
|
|
3600
|
-
|
|
3757
|
+
this.speckVersion ??= await this.fetchEndpoint("starknet_specVersion");
|
|
3758
|
+
return this.speckVersion;
|
|
3601
3759
|
}
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3760
|
+
getNonceForAddress(contractAddress, blockIdentifier = this.blockIdentifier) {
|
|
3761
|
+
const contract_address = toHex(contractAddress);
|
|
3762
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3763
|
+
return this.fetchEndpoint("starknet_getNonce", {
|
|
3764
|
+
contract_address,
|
|
3765
|
+
block_id
|
|
3766
|
+
});
|
|
3607
3767
|
}
|
|
3608
3768
|
/**
|
|
3609
3769
|
* Get the most recent accepted block hash and number
|
|
3610
3770
|
*/
|
|
3611
|
-
|
|
3612
|
-
return this.
|
|
3771
|
+
getBlockLatestAccepted() {
|
|
3772
|
+
return this.fetchEndpoint("starknet_blockHashAndNumber");
|
|
3613
3773
|
}
|
|
3614
3774
|
/**
|
|
3615
3775
|
* Get the most recent accepted block number
|
|
3616
3776
|
* redundant use getBlockLatestAccepted();
|
|
3617
3777
|
* @returns Number of the latest block
|
|
3618
3778
|
*/
|
|
3619
|
-
|
|
3620
|
-
return this.
|
|
3779
|
+
getBlockNumber() {
|
|
3780
|
+
return this.fetchEndpoint("starknet_blockNumber");
|
|
3621
3781
|
}
|
|
3622
|
-
|
|
3623
|
-
|
|
3782
|
+
getBlockWithTxHashes(blockIdentifier = this.blockIdentifier) {
|
|
3783
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3784
|
+
return this.fetchEndpoint("starknet_getBlockWithTxHashes", { block_id });
|
|
3624
3785
|
}
|
|
3625
|
-
|
|
3626
|
-
|
|
3786
|
+
getBlockWithTxs(blockIdentifier = this.blockIdentifier) {
|
|
3787
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3788
|
+
return this.fetchEndpoint("starknet_getBlockWithTxs", { block_id });
|
|
3789
|
+
}
|
|
3790
|
+
getBlockWithReceipts(blockIdentifier = this.blockIdentifier) {
|
|
3791
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3792
|
+
return this.fetchEndpoint("starknet_getBlockWithReceipts", { block_id });
|
|
3793
|
+
}
|
|
3794
|
+
getBlockStateUpdate(blockIdentifier = this.blockIdentifier) {
|
|
3795
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3796
|
+
return this.fetchEndpoint("starknet_getStateUpdate", { block_id });
|
|
3797
|
+
}
|
|
3798
|
+
getBlockTransactionsTraces(blockIdentifier = this.blockIdentifier) {
|
|
3799
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3800
|
+
return this.fetchEndpoint("starknet_traceBlockTransactions", { block_id });
|
|
3801
|
+
}
|
|
3802
|
+
getBlockTransactionCount(blockIdentifier = this.blockIdentifier) {
|
|
3803
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3804
|
+
return this.fetchEndpoint("starknet_getBlockTransactionCount", { block_id });
|
|
3805
|
+
}
|
|
3806
|
+
getTransactionByHash(txHash) {
|
|
3807
|
+
const transaction_hash = toHex(txHash);
|
|
3808
|
+
return this.fetchEndpoint("starknet_getTransactionByHash", {
|
|
3809
|
+
transaction_hash
|
|
3810
|
+
});
|
|
3811
|
+
}
|
|
3812
|
+
getTransactionByBlockIdAndIndex(blockIdentifier, index) {
|
|
3813
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3814
|
+
return this.fetchEndpoint("starknet_getTransactionByBlockIdAndIndex", { block_id, index });
|
|
3815
|
+
}
|
|
3816
|
+
getTransactionReceipt(txHash) {
|
|
3817
|
+
const transaction_hash = toHex(txHash);
|
|
3818
|
+
return this.fetchEndpoint("starknet_getTransactionReceipt", { transaction_hash });
|
|
3819
|
+
}
|
|
3820
|
+
getTransactionTrace(txHash) {
|
|
3821
|
+
const transaction_hash = toHex(txHash);
|
|
3822
|
+
return this.fetchEndpoint("starknet_traceTransaction", { transaction_hash });
|
|
3823
|
+
}
|
|
3824
|
+
/**
|
|
3825
|
+
* Get the status of a transaction
|
|
3826
|
+
*/
|
|
3827
|
+
getTransactionStatus(transactionHash) {
|
|
3828
|
+
const transaction_hash = toHex(transactionHash);
|
|
3829
|
+
return this.fetchEndpoint("starknet_getTransactionStatus", { transaction_hash });
|
|
3830
|
+
}
|
|
3831
|
+
/**
|
|
3832
|
+
* @param invocations AccountInvocations
|
|
3833
|
+
* @param simulateTransactionOptions blockIdentifier and flags to skip validation and fee charge<br/>
|
|
3834
|
+
* - blockIdentifier<br/>
|
|
3835
|
+
* - skipValidate (default false)<br/>
|
|
3836
|
+
* - skipFeeCharge (default true)<br/>
|
|
3837
|
+
*/
|
|
3838
|
+
simulateTransaction(invocations, {
|
|
3839
|
+
blockIdentifier = this.blockIdentifier,
|
|
3840
|
+
skipValidate = true,
|
|
3841
|
+
skipFeeCharge = true
|
|
3842
|
+
} = {}) {
|
|
3843
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3844
|
+
const simulationFlags = [];
|
|
3845
|
+
if (skipValidate)
|
|
3846
|
+
simulationFlags.push(rpcspec_0_7_exports.ESimulationFlag.SKIP_VALIDATE);
|
|
3847
|
+
if (skipFeeCharge)
|
|
3848
|
+
simulationFlags.push(rpcspec_0_7_exports.ESimulationFlag.SKIP_FEE_CHARGE);
|
|
3849
|
+
return this.fetchEndpoint("starknet_simulateTransactions", {
|
|
3850
|
+
block_id,
|
|
3851
|
+
transactions: invocations.map((it) => this.buildTransaction(it)),
|
|
3852
|
+
simulation_flags: simulationFlags
|
|
3853
|
+
});
|
|
3854
|
+
}
|
|
3855
|
+
async waitForTransaction(txHash, options) {
|
|
3856
|
+
const transactionHash = toHex(txHash);
|
|
3857
|
+
let { retries } = this;
|
|
3858
|
+
let onchain = false;
|
|
3859
|
+
let isErrorState = false;
|
|
3860
|
+
const retryInterval = options?.retryInterval ?? 5e3;
|
|
3861
|
+
const errorStates = options?.errorStates ?? [
|
|
3862
|
+
rpcspec_0_7_exports.ETransactionStatus.REJECTED
|
|
3863
|
+
// TODO: commented out to preserve the long-standing behavior of "reverted" not being treated as an error by default
|
|
3864
|
+
// should decide which behavior to keep in the future
|
|
3865
|
+
// RPC.ETransactionExecutionStatus.REVERTED,
|
|
3866
|
+
];
|
|
3867
|
+
const successStates = options?.successStates ?? [
|
|
3868
|
+
rpcspec_0_7_exports.ETransactionExecutionStatus.SUCCEEDED,
|
|
3869
|
+
rpcspec_0_7_exports.ETransactionStatus.ACCEPTED_ON_L2,
|
|
3870
|
+
rpcspec_0_7_exports.ETransactionStatus.ACCEPTED_ON_L1
|
|
3871
|
+
];
|
|
3872
|
+
let txStatus;
|
|
3873
|
+
while (!onchain) {
|
|
3874
|
+
await wait(retryInterval);
|
|
3875
|
+
try {
|
|
3876
|
+
txStatus = await this.getTransactionStatus(transactionHash);
|
|
3877
|
+
const executionStatus = txStatus.execution_status;
|
|
3878
|
+
const finalityStatus = txStatus.finality_status;
|
|
3879
|
+
if (!finalityStatus) {
|
|
3880
|
+
const error = new Error("waiting for transaction status");
|
|
3881
|
+
throw error;
|
|
3882
|
+
}
|
|
3883
|
+
if (errorStates.includes(executionStatus) || errorStates.includes(finalityStatus)) {
|
|
3884
|
+
const message = `${executionStatus}: ${finalityStatus}`;
|
|
3885
|
+
const error = new Error(message);
|
|
3886
|
+
error.response = txStatus;
|
|
3887
|
+
isErrorState = true;
|
|
3888
|
+
throw error;
|
|
3889
|
+
} else if (successStates.includes(executionStatus) || successStates.includes(finalityStatus)) {
|
|
3890
|
+
onchain = true;
|
|
3891
|
+
}
|
|
3892
|
+
} catch (error) {
|
|
3893
|
+
if (error instanceof Error && isErrorState) {
|
|
3894
|
+
throw error;
|
|
3895
|
+
}
|
|
3896
|
+
if (retries <= 0) {
|
|
3897
|
+
throw new Error(`waitForTransaction timed-out with retries ${this.retries}`);
|
|
3898
|
+
}
|
|
3899
|
+
}
|
|
3900
|
+
retries -= 1;
|
|
3901
|
+
}
|
|
3902
|
+
let txReceipt = null;
|
|
3903
|
+
while (txReceipt === null) {
|
|
3904
|
+
try {
|
|
3905
|
+
txReceipt = await this.getTransactionReceipt(transactionHash);
|
|
3906
|
+
} catch (error) {
|
|
3907
|
+
if (retries <= 0) {
|
|
3908
|
+
throw new Error(`waitForTransaction timed-out with retries ${this.retries}`);
|
|
3909
|
+
}
|
|
3910
|
+
}
|
|
3911
|
+
retries -= 1;
|
|
3912
|
+
await wait(retryInterval);
|
|
3913
|
+
}
|
|
3914
|
+
return txReceipt;
|
|
3915
|
+
}
|
|
3916
|
+
getStorageAt(contractAddress, key, blockIdentifier = this.blockIdentifier) {
|
|
3917
|
+
const contract_address = toHex(contractAddress);
|
|
3918
|
+
const parsedKey = toStorageKey(key);
|
|
3919
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3920
|
+
return this.fetchEndpoint("starknet_getStorageAt", {
|
|
3921
|
+
contract_address,
|
|
3922
|
+
key: parsedKey,
|
|
3923
|
+
block_id
|
|
3924
|
+
});
|
|
3925
|
+
}
|
|
3926
|
+
getClassHashAt(contractAddress, blockIdentifier = this.blockIdentifier) {
|
|
3927
|
+
const contract_address = toHex(contractAddress);
|
|
3928
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3929
|
+
return this.fetchEndpoint("starknet_getClassHashAt", {
|
|
3930
|
+
block_id,
|
|
3931
|
+
contract_address
|
|
3932
|
+
});
|
|
3933
|
+
}
|
|
3934
|
+
getClass(classHash, blockIdentifier = this.blockIdentifier) {
|
|
3935
|
+
const class_hash = toHex(classHash);
|
|
3936
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3937
|
+
return this.fetchEndpoint("starknet_getClass", {
|
|
3938
|
+
class_hash,
|
|
3939
|
+
block_id
|
|
3940
|
+
});
|
|
3941
|
+
}
|
|
3942
|
+
getClassAt(contractAddress, blockIdentifier = this.blockIdentifier) {
|
|
3943
|
+
const contract_address = toHex(contractAddress);
|
|
3944
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3945
|
+
return this.fetchEndpoint("starknet_getClassAt", {
|
|
3946
|
+
block_id,
|
|
3947
|
+
contract_address
|
|
3948
|
+
});
|
|
3949
|
+
}
|
|
3950
|
+
async getEstimateFee(invocations, { blockIdentifier = this.blockIdentifier, skipValidate = true }) {
|
|
3951
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3952
|
+
let flags = {};
|
|
3953
|
+
if (!isVersion("0.5", await this.getSpecVersion())) {
|
|
3954
|
+
flags = {
|
|
3955
|
+
simulation_flags: skipValidate ? [rpcspec_0_7_exports.ESimulationFlag.SKIP_VALIDATE] : []
|
|
3956
|
+
};
|
|
3957
|
+
}
|
|
3958
|
+
return this.fetchEndpoint("starknet_estimateFee", {
|
|
3959
|
+
request: invocations.map((it) => this.buildTransaction(it, "fee")),
|
|
3960
|
+
block_id,
|
|
3961
|
+
...flags
|
|
3962
|
+
});
|
|
3963
|
+
}
|
|
3964
|
+
async invoke(functionInvocation, details) {
|
|
3965
|
+
let promise;
|
|
3966
|
+
if (!isV3Tx(details)) {
|
|
3967
|
+
promise = this.fetchEndpoint("starknet_addInvokeTransaction", {
|
|
3968
|
+
invoke_transaction: {
|
|
3969
|
+
sender_address: functionInvocation.contractAddress,
|
|
3970
|
+
calldata: CallData.toHex(functionInvocation.calldata),
|
|
3971
|
+
type: rpcspec_0_7_exports.ETransactionType.INVOKE,
|
|
3972
|
+
max_fee: toHex(details.maxFee || 0),
|
|
3973
|
+
version: rpcspec_0_7_exports.ETransactionVersion.V1,
|
|
3974
|
+
signature: signatureToHexArray(functionInvocation.signature),
|
|
3975
|
+
nonce: toHex(details.nonce)
|
|
3976
|
+
}
|
|
3977
|
+
});
|
|
3978
|
+
} else {
|
|
3979
|
+
promise = this.fetchEndpoint("starknet_addInvokeTransaction", {
|
|
3980
|
+
invoke_transaction: {
|
|
3981
|
+
type: rpcspec_0_7_exports.ETransactionType.INVOKE,
|
|
3982
|
+
sender_address: functionInvocation.contractAddress,
|
|
3983
|
+
calldata: CallData.toHex(functionInvocation.calldata),
|
|
3984
|
+
version: rpcspec_0_7_exports.ETransactionVersion.V3,
|
|
3985
|
+
signature: signatureToHexArray(functionInvocation.signature),
|
|
3986
|
+
nonce: toHex(details.nonce),
|
|
3987
|
+
resource_bounds: details.resourceBounds,
|
|
3988
|
+
tip: toHex(details.tip),
|
|
3989
|
+
paymaster_data: details.paymasterData.map((it) => toHex(it)),
|
|
3990
|
+
account_deployment_data: details.accountDeploymentData.map((it) => toHex(it)),
|
|
3991
|
+
nonce_data_availability_mode: details.nonceDataAvailabilityMode,
|
|
3992
|
+
fee_data_availability_mode: details.feeDataAvailabilityMode
|
|
3993
|
+
}
|
|
3994
|
+
});
|
|
3995
|
+
}
|
|
3996
|
+
return this.waitMode ? this.waitForTransaction((await promise).transaction_hash) : promise;
|
|
3997
|
+
}
|
|
3998
|
+
async declare({ contract, signature, senderAddress, compiledClassHash }, details) {
|
|
3999
|
+
let promise;
|
|
4000
|
+
if (!isSierra(contract) && !isV3Tx(details)) {
|
|
4001
|
+
promise = this.fetchEndpoint("starknet_addDeclareTransaction", {
|
|
4002
|
+
declare_transaction: {
|
|
4003
|
+
type: rpcspec_0_7_exports.ETransactionType.DECLARE,
|
|
4004
|
+
contract_class: {
|
|
4005
|
+
program: contract.program,
|
|
4006
|
+
entry_points_by_type: contract.entry_points_by_type,
|
|
4007
|
+
abi: contract.abi
|
|
4008
|
+
},
|
|
4009
|
+
version: rpcspec_0_7_exports.ETransactionVersion.V1,
|
|
4010
|
+
max_fee: toHex(details.maxFee || 0),
|
|
4011
|
+
signature: signatureToHexArray(signature),
|
|
4012
|
+
sender_address: senderAddress,
|
|
4013
|
+
nonce: toHex(details.nonce)
|
|
4014
|
+
}
|
|
4015
|
+
});
|
|
4016
|
+
} else if (isSierra(contract) && !isV3Tx(details)) {
|
|
4017
|
+
promise = this.fetchEndpoint("starknet_addDeclareTransaction", {
|
|
4018
|
+
declare_transaction: {
|
|
4019
|
+
type: rpcspec_0_7_exports.ETransactionType.DECLARE,
|
|
4020
|
+
contract_class: {
|
|
4021
|
+
sierra_program: decompressProgram(contract.sierra_program),
|
|
4022
|
+
contract_class_version: contract.contract_class_version,
|
|
4023
|
+
entry_points_by_type: contract.entry_points_by_type,
|
|
4024
|
+
abi: contract.abi
|
|
4025
|
+
},
|
|
4026
|
+
compiled_class_hash: compiledClassHash || "",
|
|
4027
|
+
version: rpcspec_0_7_exports.ETransactionVersion.V2,
|
|
4028
|
+
max_fee: toHex(details.maxFee || 0),
|
|
4029
|
+
signature: signatureToHexArray(signature),
|
|
4030
|
+
sender_address: senderAddress,
|
|
4031
|
+
nonce: toHex(details.nonce)
|
|
4032
|
+
}
|
|
4033
|
+
});
|
|
4034
|
+
} else if (isSierra(contract) && isV3Tx(details)) {
|
|
4035
|
+
promise = this.fetchEndpoint("starknet_addDeclareTransaction", {
|
|
4036
|
+
declare_transaction: {
|
|
4037
|
+
type: rpcspec_0_7_exports.ETransactionType.DECLARE,
|
|
4038
|
+
sender_address: senderAddress,
|
|
4039
|
+
compiled_class_hash: compiledClassHash || "",
|
|
4040
|
+
version: rpcspec_0_7_exports.ETransactionVersion.V3,
|
|
4041
|
+
signature: signatureToHexArray(signature),
|
|
4042
|
+
nonce: toHex(details.nonce),
|
|
4043
|
+
contract_class: {
|
|
4044
|
+
sierra_program: decompressProgram(contract.sierra_program),
|
|
4045
|
+
contract_class_version: contract.contract_class_version,
|
|
4046
|
+
entry_points_by_type: contract.entry_points_by_type,
|
|
4047
|
+
abi: contract.abi
|
|
4048
|
+
},
|
|
4049
|
+
resource_bounds: details.resourceBounds,
|
|
4050
|
+
tip: toHex(details.tip),
|
|
4051
|
+
paymaster_data: details.paymasterData.map((it) => toHex(it)),
|
|
4052
|
+
account_deployment_data: details.accountDeploymentData.map((it) => toHex(it)),
|
|
4053
|
+
nonce_data_availability_mode: details.nonceDataAvailabilityMode,
|
|
4054
|
+
fee_data_availability_mode: details.feeDataAvailabilityMode
|
|
4055
|
+
}
|
|
4056
|
+
});
|
|
4057
|
+
} else {
|
|
4058
|
+
throw Error("declare unspotted parameters");
|
|
4059
|
+
}
|
|
4060
|
+
return this.waitMode ? this.waitForTransaction((await promise).transaction_hash) : promise;
|
|
4061
|
+
}
|
|
4062
|
+
async deployAccount({ classHash, constructorCalldata, addressSalt, signature }, details) {
|
|
4063
|
+
let promise;
|
|
4064
|
+
if (!isV3Tx(details)) {
|
|
4065
|
+
promise = this.fetchEndpoint("starknet_addDeployAccountTransaction", {
|
|
4066
|
+
deploy_account_transaction: {
|
|
4067
|
+
constructor_calldata: CallData.toHex(constructorCalldata || []),
|
|
4068
|
+
class_hash: toHex(classHash),
|
|
4069
|
+
contract_address_salt: toHex(addressSalt || 0),
|
|
4070
|
+
type: rpcspec_0_7_exports.ETransactionType.DEPLOY_ACCOUNT,
|
|
4071
|
+
max_fee: toHex(details.maxFee || 0),
|
|
4072
|
+
version: rpcspec_0_7_exports.ETransactionVersion.V1,
|
|
4073
|
+
signature: signatureToHexArray(signature),
|
|
4074
|
+
nonce: toHex(details.nonce)
|
|
4075
|
+
}
|
|
4076
|
+
});
|
|
4077
|
+
} else {
|
|
4078
|
+
promise = this.fetchEndpoint("starknet_addDeployAccountTransaction", {
|
|
4079
|
+
deploy_account_transaction: {
|
|
4080
|
+
type: rpcspec_0_7_exports.ETransactionType.DEPLOY_ACCOUNT,
|
|
4081
|
+
version: rpcspec_0_7_exports.ETransactionVersion.V3,
|
|
4082
|
+
signature: signatureToHexArray(signature),
|
|
4083
|
+
nonce: toHex(details.nonce),
|
|
4084
|
+
contract_address_salt: toHex(addressSalt || 0),
|
|
4085
|
+
constructor_calldata: CallData.toHex(constructorCalldata || []),
|
|
4086
|
+
class_hash: toHex(classHash),
|
|
4087
|
+
resource_bounds: details.resourceBounds,
|
|
4088
|
+
tip: toHex(details.tip),
|
|
4089
|
+
paymaster_data: details.paymasterData.map((it) => toHex(it)),
|
|
4090
|
+
nonce_data_availability_mode: details.nonceDataAvailabilityMode,
|
|
4091
|
+
fee_data_availability_mode: details.feeDataAvailabilityMode
|
|
4092
|
+
}
|
|
4093
|
+
});
|
|
4094
|
+
}
|
|
4095
|
+
return this.waitMode ? this.waitForTransaction((await promise).transaction_hash) : promise;
|
|
4096
|
+
}
|
|
4097
|
+
callContract(call, blockIdentifier = this.blockIdentifier) {
|
|
4098
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
4099
|
+
return this.fetchEndpoint("starknet_call", {
|
|
4100
|
+
request: {
|
|
4101
|
+
contract_address: call.contractAddress,
|
|
4102
|
+
entry_point_selector: getSelectorFromName(call.entrypoint),
|
|
4103
|
+
calldata: CallData.toHex(call.calldata)
|
|
4104
|
+
},
|
|
4105
|
+
block_id
|
|
4106
|
+
});
|
|
4107
|
+
}
|
|
4108
|
+
/**
|
|
4109
|
+
* NEW: Estimate the fee for a message from L1
|
|
4110
|
+
* @param message Message From L1
|
|
4111
|
+
*/
|
|
4112
|
+
estimateMessageFee(message, blockIdentifier = this.blockIdentifier) {
|
|
4113
|
+
const { from_address, to_address, entry_point_selector, payload } = message;
|
|
4114
|
+
const formattedMessage = {
|
|
4115
|
+
from_address: toHex(from_address),
|
|
4116
|
+
to_address: toHex(to_address),
|
|
4117
|
+
entry_point_selector: getSelector(entry_point_selector),
|
|
4118
|
+
payload: getHexStringArray(payload)
|
|
4119
|
+
};
|
|
4120
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
4121
|
+
return this.fetchEndpoint("starknet_estimateMessageFee", {
|
|
4122
|
+
message: formattedMessage,
|
|
4123
|
+
block_id
|
|
4124
|
+
});
|
|
4125
|
+
}
|
|
4126
|
+
/**
|
|
4127
|
+
* Returns an object about the sync status, or false if the node is not synching
|
|
4128
|
+
* @returns Object with the stats data
|
|
4129
|
+
*/
|
|
4130
|
+
getSyncingStats() {
|
|
4131
|
+
return this.fetchEndpoint("starknet_syncing");
|
|
4132
|
+
}
|
|
4133
|
+
/**
|
|
4134
|
+
* Returns all events matching the given filter
|
|
4135
|
+
* @returns events and the pagination of the events
|
|
4136
|
+
*/
|
|
4137
|
+
getEvents(eventFilter) {
|
|
4138
|
+
return this.fetchEndpoint("starknet_getEvents", { filter: eventFilter });
|
|
4139
|
+
}
|
|
4140
|
+
buildTransaction(invocation, versionType) {
|
|
4141
|
+
const defaultVersions = getVersionsByType(versionType);
|
|
4142
|
+
let details;
|
|
4143
|
+
if (!isV3Tx(invocation)) {
|
|
4144
|
+
details = {
|
|
4145
|
+
signature: signatureToHexArray(invocation.signature),
|
|
4146
|
+
nonce: toHex(invocation.nonce),
|
|
4147
|
+
max_fee: toHex(invocation.maxFee || 0)
|
|
4148
|
+
};
|
|
4149
|
+
} else {
|
|
4150
|
+
details = {
|
|
4151
|
+
signature: signatureToHexArray(invocation.signature),
|
|
4152
|
+
nonce: toHex(invocation.nonce),
|
|
4153
|
+
resource_bounds: invocation.resourceBounds,
|
|
4154
|
+
tip: toHex(invocation.tip),
|
|
4155
|
+
paymaster_data: invocation.paymasterData.map((it) => toHex(it)),
|
|
4156
|
+
nonce_data_availability_mode: invocation.nonceDataAvailabilityMode,
|
|
4157
|
+
fee_data_availability_mode: invocation.feeDataAvailabilityMode,
|
|
4158
|
+
account_deployment_data: invocation.accountDeploymentData.map((it) => toHex(it))
|
|
4159
|
+
};
|
|
4160
|
+
}
|
|
4161
|
+
if (invocation.type === "INVOKE_FUNCTION" /* INVOKE */) {
|
|
4162
|
+
return {
|
|
4163
|
+
// v0 v1 v3
|
|
4164
|
+
type: rpcspec_0_7_exports.ETransactionType.INVOKE,
|
|
4165
|
+
// TODO: Diff between sequencer and rpc invoke type
|
|
4166
|
+
sender_address: invocation.contractAddress,
|
|
4167
|
+
calldata: CallData.toHex(invocation.calldata),
|
|
4168
|
+
version: toHex(invocation.version || defaultVersions.v3),
|
|
4169
|
+
...details
|
|
4170
|
+
};
|
|
4171
|
+
}
|
|
4172
|
+
if (invocation.type === "DECLARE" /* DECLARE */) {
|
|
4173
|
+
if (!isSierra(invocation.contract)) {
|
|
4174
|
+
return {
|
|
4175
|
+
type: invocation.type,
|
|
4176
|
+
contract_class: invocation.contract,
|
|
4177
|
+
sender_address: invocation.senderAddress,
|
|
4178
|
+
version: toHex(invocation.version || defaultVersions.v1),
|
|
4179
|
+
...details
|
|
4180
|
+
};
|
|
4181
|
+
}
|
|
4182
|
+
return {
|
|
4183
|
+
// Cairo 1 - v2 v3
|
|
4184
|
+
type: invocation.type,
|
|
4185
|
+
contract_class: {
|
|
4186
|
+
...invocation.contract,
|
|
4187
|
+
sierra_program: decompressProgram(invocation.contract.sierra_program)
|
|
4188
|
+
},
|
|
4189
|
+
compiled_class_hash: invocation.compiledClassHash || "",
|
|
4190
|
+
sender_address: invocation.senderAddress,
|
|
4191
|
+
version: toHex(invocation.version || defaultVersions.v3),
|
|
4192
|
+
...details
|
|
4193
|
+
};
|
|
4194
|
+
}
|
|
4195
|
+
if (invocation.type === "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */) {
|
|
4196
|
+
const { account_deployment_data, ...restDetails } = details;
|
|
4197
|
+
return {
|
|
4198
|
+
type: invocation.type,
|
|
4199
|
+
constructor_calldata: CallData.toHex(invocation.constructorCalldata || []),
|
|
4200
|
+
class_hash: toHex(invocation.classHash),
|
|
4201
|
+
contract_address_salt: toHex(invocation.addressSalt || 0),
|
|
4202
|
+
version: toHex(invocation.version || defaultVersions.v3),
|
|
4203
|
+
...restDetails
|
|
4204
|
+
};
|
|
4205
|
+
}
|
|
4206
|
+
throw Error("RPC buildTransaction received unknown TransactionType");
|
|
4207
|
+
}
|
|
4208
|
+
};
|
|
4209
|
+
|
|
4210
|
+
// src/utils/responseParser/rpc.ts
|
|
4211
|
+
var RPCResponseParser = class {
|
|
4212
|
+
parseGetBlockResponse(res) {
|
|
4213
|
+
return { status: "PENDING", ...res };
|
|
4214
|
+
}
|
|
4215
|
+
parseTransactionReceipt(res) {
|
|
4216
|
+
if ("actual_fee" in res && typeof res.actual_fee === "string") {
|
|
4217
|
+
return {
|
|
4218
|
+
...res,
|
|
4219
|
+
actual_fee: {
|
|
4220
|
+
amount: res.actual_fee,
|
|
4221
|
+
unit: "FRI"
|
|
4222
|
+
}
|
|
4223
|
+
};
|
|
4224
|
+
}
|
|
4225
|
+
return res;
|
|
4226
|
+
}
|
|
4227
|
+
parseFeeEstimateResponse(res) {
|
|
4228
|
+
const val = res[0];
|
|
4229
|
+
return {
|
|
4230
|
+
overall_fee: toBigInt(val.overall_fee),
|
|
4231
|
+
gas_consumed: toBigInt(val.gas_consumed),
|
|
4232
|
+
gas_price: toBigInt(val.gas_price),
|
|
4233
|
+
unit: val.unit,
|
|
4234
|
+
suggestedMaxFee: estimatedFeeToMaxFee(val.overall_fee),
|
|
4235
|
+
resourceBounds: estimateFeeToBounds(val)
|
|
4236
|
+
};
|
|
4237
|
+
}
|
|
4238
|
+
parseFeeEstimateBulkResponse(res) {
|
|
4239
|
+
return res.map((val) => ({
|
|
4240
|
+
overall_fee: toBigInt(val.overall_fee),
|
|
4241
|
+
gas_consumed: toBigInt(val.gas_consumed),
|
|
4242
|
+
gas_price: toBigInt(val.gas_price),
|
|
4243
|
+
unit: val.unit,
|
|
4244
|
+
suggestedMaxFee: estimatedFeeToMaxFee(val.overall_fee),
|
|
4245
|
+
resourceBounds: estimateFeeToBounds(val)
|
|
4246
|
+
}));
|
|
4247
|
+
}
|
|
4248
|
+
parseSimulateTransactionResponse(res) {
|
|
4249
|
+
return res.map((it) => {
|
|
4250
|
+
return {
|
|
4251
|
+
...it,
|
|
4252
|
+
suggestedMaxFee: estimatedFeeToMaxFee(BigInt(it.fee_estimation.overall_fee)),
|
|
4253
|
+
resourceBounds: estimateFeeToBounds(it.fee_estimation)
|
|
4254
|
+
};
|
|
4255
|
+
});
|
|
4256
|
+
}
|
|
4257
|
+
parseContractClassResponse(res) {
|
|
4258
|
+
return {
|
|
4259
|
+
...res,
|
|
4260
|
+
abi: typeof res.abi === "string" ? JSON.parse(res.abi) : res.abi
|
|
4261
|
+
};
|
|
4262
|
+
}
|
|
4263
|
+
};
|
|
4264
|
+
|
|
4265
|
+
// src/provider/rpc.ts
|
|
4266
|
+
var RpcProvider = class {
|
|
4267
|
+
responseParser = new RPCResponseParser();
|
|
4268
|
+
channel;
|
|
4269
|
+
constructor(optionsOrProvider) {
|
|
4270
|
+
if (optionsOrProvider && "channel" in optionsOrProvider) {
|
|
4271
|
+
this.channel = optionsOrProvider.channel;
|
|
4272
|
+
} else {
|
|
4273
|
+
this.channel = new RpcChannel2({ ...optionsOrProvider, waitMode: false });
|
|
4274
|
+
}
|
|
4275
|
+
}
|
|
4276
|
+
fetch(method, params, id = 0) {
|
|
4277
|
+
return this.channel.fetch(method, params, id);
|
|
4278
|
+
}
|
|
4279
|
+
async getChainId() {
|
|
4280
|
+
return this.channel.getChainId();
|
|
4281
|
+
}
|
|
4282
|
+
async getSpecVersion() {
|
|
4283
|
+
return this.channel.getSpecVersion();
|
|
4284
|
+
}
|
|
4285
|
+
async getNonceForAddress(contractAddress, blockIdentifier) {
|
|
4286
|
+
return this.channel.getNonceForAddress(contractAddress, blockIdentifier);
|
|
4287
|
+
}
|
|
4288
|
+
async getBlock(blockIdentifier) {
|
|
4289
|
+
return this.channel.getBlockWithTxHashes(blockIdentifier).then(this.responseParser.parseGetBlockResponse);
|
|
4290
|
+
}
|
|
4291
|
+
/**
|
|
4292
|
+
* Get the most recent accepted block hash and number
|
|
4293
|
+
*/
|
|
4294
|
+
async getBlockLatestAccepted() {
|
|
4295
|
+
return this.channel.getBlockLatestAccepted();
|
|
4296
|
+
}
|
|
4297
|
+
/**
|
|
4298
|
+
* Get the most recent accepted block number
|
|
4299
|
+
* redundant use getBlockLatestAccepted();
|
|
4300
|
+
* @returns Number of the latest block
|
|
4301
|
+
*/
|
|
4302
|
+
async getBlockNumber() {
|
|
4303
|
+
return this.channel.getBlockNumber();
|
|
4304
|
+
}
|
|
4305
|
+
async getBlockWithTxHashes(blockIdentifier) {
|
|
4306
|
+
return this.channel.getBlockWithTxHashes(blockIdentifier);
|
|
4307
|
+
}
|
|
4308
|
+
async getBlockWithTxs(blockIdentifier) {
|
|
4309
|
+
return this.channel.getBlockWithTxs(blockIdentifier);
|
|
4310
|
+
}
|
|
4311
|
+
async getBlockWithReceipts(blockIdentifier) {
|
|
4312
|
+
if (this.channel instanceof rpc_0_6_exports.RpcChannel)
|
|
4313
|
+
throw new LibraryError("Unsupported method for RPC version");
|
|
4314
|
+
return this.channel.getBlockWithReceipts(blockIdentifier);
|
|
3627
4315
|
}
|
|
3628
4316
|
getStateUpdate = this.getBlockStateUpdate;
|
|
3629
4317
|
async getBlockStateUpdate(blockIdentifier) {
|
|
@@ -4341,7 +5029,7 @@ var Signer = class {
|
|
|
4341
5029
|
async signTransaction(transactions, details) {
|
|
4342
5030
|
const compiledCalldata = getExecuteCalldata(transactions, details.cairoVersion);
|
|
4343
5031
|
let msgHash;
|
|
4344
|
-
if (Object.values(
|
|
5032
|
+
if (Object.values(ETransactionVersion22).includes(details.version)) {
|
|
4345
5033
|
const det = details;
|
|
4346
5034
|
msgHash = calculateInvokeTransactionHash2({
|
|
4347
5035
|
...det,
|
|
@@ -4349,7 +5037,7 @@ var Signer = class {
|
|
|
4349
5037
|
compiledCalldata,
|
|
4350
5038
|
version: det.version
|
|
4351
5039
|
});
|
|
4352
|
-
} else if (Object.values(
|
|
5040
|
+
} else if (Object.values(ETransactionVersion32).includes(details.version)) {
|
|
4353
5041
|
const det = details;
|
|
4354
5042
|
msgHash = calculateInvokeTransactionHash2({
|
|
4355
5043
|
...det,
|
|
@@ -4367,7 +5055,7 @@ var Signer = class {
|
|
|
4367
5055
|
async signDeployAccountTransaction(details) {
|
|
4368
5056
|
const compiledConstructorCalldata = CallData.compile(details.constructorCalldata);
|
|
4369
5057
|
let msgHash;
|
|
4370
|
-
if (Object.values(
|
|
5058
|
+
if (Object.values(ETransactionVersion22).includes(details.version)) {
|
|
4371
5059
|
const det = details;
|
|
4372
5060
|
msgHash = calculateDeployAccountTransactionHash3({
|
|
4373
5061
|
...det,
|
|
@@ -4375,7 +5063,7 @@ var Signer = class {
|
|
|
4375
5063
|
constructorCalldata: compiledConstructorCalldata,
|
|
4376
5064
|
version: det.version
|
|
4377
5065
|
});
|
|
4378
|
-
} else if (Object.values(
|
|
5066
|
+
} else if (Object.values(ETransactionVersion32).includes(details.version)) {
|
|
4379
5067
|
const det = details;
|
|
4380
5068
|
msgHash = calculateDeployAccountTransactionHash3({
|
|
4381
5069
|
...det,
|
|
@@ -4392,13 +5080,13 @@ var Signer = class {
|
|
|
4392
5080
|
}
|
|
4393
5081
|
async signDeclareTransaction(details) {
|
|
4394
5082
|
let msgHash;
|
|
4395
|
-
if (Object.values(
|
|
5083
|
+
if (Object.values(ETransactionVersion22).includes(details.version)) {
|
|
4396
5084
|
const det = details;
|
|
4397
5085
|
msgHash = calculateDeclareTransactionHash3({
|
|
4398
5086
|
...det,
|
|
4399
5087
|
version: det.version
|
|
4400
5088
|
});
|
|
4401
|
-
} else if (Object.values(
|
|
5089
|
+
} else if (Object.values(ETransactionVersion32).includes(details.version)) {
|
|
4402
5090
|
const det = details;
|
|
4403
5091
|
msgHash = calculateDeclareTransactionHash3({
|
|
4404
5092
|
...det,
|
|
@@ -4446,7 +5134,7 @@ var EthSigner = class {
|
|
|
4446
5134
|
async signTransaction(transactions, details) {
|
|
4447
5135
|
const compiledCalldata = getExecuteCalldata(transactions, details.cairoVersion);
|
|
4448
5136
|
let msgHash;
|
|
4449
|
-
if (Object.values(
|
|
5137
|
+
if (Object.values(ETransactionVersion22).includes(details.version)) {
|
|
4450
5138
|
const det = details;
|
|
4451
5139
|
msgHash = calculateInvokeTransactionHash2({
|
|
4452
5140
|
...det,
|
|
@@ -4454,7 +5142,7 @@ var EthSigner = class {
|
|
|
4454
5142
|
compiledCalldata,
|
|
4455
5143
|
version: det.version
|
|
4456
5144
|
});
|
|
4457
|
-
} else if (Object.values(
|
|
5145
|
+
} else if (Object.values(ETransactionVersion32).includes(details.version)) {
|
|
4458
5146
|
const det = details;
|
|
4459
5147
|
msgHash = calculateInvokeTransactionHash2({
|
|
4460
5148
|
...det,
|
|
@@ -4472,7 +5160,7 @@ var EthSigner = class {
|
|
|
4472
5160
|
async signDeployAccountTransaction(details) {
|
|
4473
5161
|
const compiledConstructorCalldata = CallData.compile(details.constructorCalldata);
|
|
4474
5162
|
let msgHash;
|
|
4475
|
-
if (Object.values(
|
|
5163
|
+
if (Object.values(ETransactionVersion22).includes(details.version)) {
|
|
4476
5164
|
const det = details;
|
|
4477
5165
|
msgHash = calculateDeployAccountTransactionHash3({
|
|
4478
5166
|
...det,
|
|
@@ -4480,7 +5168,7 @@ var EthSigner = class {
|
|
|
4480
5168
|
constructorCalldata: compiledConstructorCalldata,
|
|
4481
5169
|
version: det.version
|
|
4482
5170
|
});
|
|
4483
|
-
} else if (Object.values(
|
|
5171
|
+
} else if (Object.values(ETransactionVersion32).includes(details.version)) {
|
|
4484
5172
|
const det = details;
|
|
4485
5173
|
msgHash = calculateDeployAccountTransactionHash3({
|
|
4486
5174
|
...det,
|
|
@@ -4497,13 +5185,13 @@ var EthSigner = class {
|
|
|
4497
5185
|
}
|
|
4498
5186
|
async signDeclareTransaction(details) {
|
|
4499
5187
|
let msgHash;
|
|
4500
|
-
if (Object.values(
|
|
5188
|
+
if (Object.values(ETransactionVersion22).includes(details.version)) {
|
|
4501
5189
|
const det = details;
|
|
4502
5190
|
msgHash = calculateDeclareTransactionHash3({
|
|
4503
5191
|
...det,
|
|
4504
5192
|
version: det.version
|
|
4505
5193
|
});
|
|
4506
|
-
} else if (Object.values(
|
|
5194
|
+
} else if (Object.values(ETransactionVersion32).includes(details.version)) {
|
|
4507
5195
|
const det = details;
|
|
4508
5196
|
msgHash = calculateDeclareTransactionHash3({
|
|
4509
5197
|
...det,
|
|
@@ -5652,7 +6340,9 @@ export {
|
|
|
5652
6340
|
RpcProvider2 as Provider,
|
|
5653
6341
|
ProviderInterface,
|
|
5654
6342
|
api_exports as RPC,
|
|
5655
|
-
|
|
6343
|
+
rpc_0_6_exports as RPC06,
|
|
6344
|
+
rpc_0_7_exports as RPC07,
|
|
6345
|
+
RpcChannel2 as RpcChannel,
|
|
5656
6346
|
RpcProvider2 as RpcProvider,
|
|
5657
6347
|
SIMULATION_FLAG,
|
|
5658
6348
|
Signer,
|