quantumcoin 7.0.3 → 7.0.5
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/.github/workflows/publish-npmjs.yaml +22 -22
- package/.gitignore +15 -15
- package/LICENSE +21 -21
- package/README-SDK.md +758 -754
- package/README.md +165 -150
- package/SPEC.md +3845 -3843
- package/config.d.ts +50 -50
- package/config.js +115 -115
- package/examples/AllSolidityTypes.sol +184 -184
- package/examples/SimpleIERC20.sol +74 -74
- package/examples/events.js +41 -35
- package/examples/events.ts +35 -0
- package/examples/example-generator-sdk-js.js +100 -95
- package/examples/example-generator-sdk-js.ts +77 -0
- package/examples/example-generator-sdk-ts.js +100 -95
- package/examples/example-generator-sdk-ts.ts +77 -0
- package/examples/example.js +72 -61
- package/examples/example.ts +61 -0
- package/examples/offline-signing.js +79 -73
- package/examples/offline-signing.ts +66 -0
- package/examples/package-lock.json +596 -57
- package/examples/package.json +32 -16
- package/examples/read-operations.js +32 -27
- package/examples/read-operations.ts +31 -0
- package/examples/sdk-generator-erc20.inline.json +251 -251
- package/examples/solidity-types.ts +43 -43
- package/examples/wallet-offline.js +35 -29
- package/examples/wallet-offline.ts +34 -0
- package/generate-sdk.js +1824 -1490
- package/index.js +12 -12
- package/package.json +95 -75
- package/scripts/copy-declarations.js +31 -0
- package/scripts/run-all-one-by-one.js +151 -0
- package/src/abi/fragments.d.ts +42 -42
- package/src/abi/fragments.js +63 -63
- package/src/abi/index.d.ts +13 -13
- package/src/abi/index.js +9 -9
- package/src/abi/interface.d.ts +128 -132
- package/src/abi/interface.js +590 -590
- package/src/abi/js-abi-coder.d.ts +8 -0
- package/src/abi/js-abi-coder.js +474 -474
- package/src/constants.d.ts +66 -61
- package/src/constants.js +101 -94
- package/src/contract/contract-factory.d.ts +28 -28
- package/src/contract/contract-factory.js +105 -105
- package/src/contract/contract.d.ts +113 -114
- package/src/contract/contract.js +354 -354
- package/src/contract/index.d.ts +9 -9
- package/src/contract/index.js +9 -9
- package/src/errors/index.d.ts +92 -92
- package/src/errors/index.js +188 -188
- package/src/generator/index.d.ts +74 -0
- package/src/generator/index.js +1404 -1404
- package/src/index.d.ts +125 -127
- package/src/index.js +41 -41
- package/src/internal/hex.d.ts +61 -61
- package/src/internal/hex.js +144 -144
- package/src/providers/extra-providers.d.ts +139 -128
- package/src/providers/extra-providers.js +600 -575
- package/src/providers/index.d.ts +17 -16
- package/src/providers/index.js +10 -10
- package/src/providers/json-rpc-provider.d.ts +12 -12
- package/src/providers/json-rpc-provider.js +79 -79
- package/src/providers/provider.d.ts +208 -203
- package/src/providers/provider.js +393 -371
- package/src/types/index.d.ts +214 -462
- package/src/types/index.js +9 -9
- package/src/utils/address.d.ts +72 -72
- package/src/utils/address.js +181 -182
- package/src/utils/encoding.d.ts +120 -120
- package/src/utils/encoding.js +306 -306
- package/src/utils/hashing.d.ts +82 -76
- package/src/utils/hashing.js +313 -298
- package/src/utils/index.d.ts +65 -55
- package/src/utils/index.js +13 -13
- package/src/utils/result.d.ts +57 -57
- package/src/utils/result.js +128 -128
- package/src/utils/rlp.d.ts +12 -12
- package/src/utils/rlp.js +200 -200
- package/src/utils/units.d.ts +29 -29
- package/src/utils/units.js +107 -107
- package/src/wallet/index.d.ts +10 -10
- package/src/wallet/index.js +8 -8
- package/src/wallet/wallet.d.ts +168 -160
- package/src/wallet/wallet.js +500 -489
- package/test/e2e/all-solidity-types.dynamic.test.js +207 -200
- package/test/e2e/all-solidity-types.dynamic.test.ts +191 -0
- package/test/e2e/all-solidity-types.fixtures.js +231 -231
- package/test/e2e/all-solidity-types.generated-sdks.e2e.test.js +387 -368
- package/test/e2e/all-solidity-types.generated-sdks.e2e.test.ts +350 -0
- package/test/e2e/helpers.js +59 -47
- package/test/e2e/signing-context-and-fee.e2e.test.js +141 -0
- package/test/e2e/signing-context-and-fee.e2e.test.ts +128 -0
- package/test/e2e/simple-erc20.generated-sdks.e2e.test.js +168 -151
- package/test/e2e/simple-erc20.generated-sdks.e2e.test.ts +141 -0
- package/test/e2e/transactional.test.js +245 -191
- package/test/e2e/transactional.test.ts +208 -0
- package/test/e2e/typed-generator.e2e.test.js +407 -404
- package/test/e2e/typed-generator.e2e.test.ts +337 -0
- package/test/fixtures/ConstructorParam.sol +23 -23
- package/test/fixtures/MultiContracts.sol +37 -37
- package/test/fixtures/SimpleStorage.sol +18 -18
- package/test/fixtures/StakingContract.abi.json +1 -1
- package/test/integration/ipc-provider.test.js +49 -44
- package/test/integration/ipc-provider.test.ts +44 -0
- package/test/integration/provider.test.js +88 -72
- package/test/integration/provider.test.ts +85 -0
- package/test/integration/ws-provider.test.js +41 -33
- package/test/integration/ws-provider.test.ts +38 -0
- package/test/security/malformed-input.test.js +37 -31
- package/test/security/malformed-input.test.ts +35 -0
- package/test/unit/_encrypted-output.txt +6 -0
- package/test/unit/_log-encrypted-jsons.js +45 -0
- package/test/unit/_write-keystore-fixture.js +16 -0
- package/test/unit/abi-interface.test.js +103 -98
- package/test/unit/abi-interface.test.ts +102 -0
- package/test/unit/address-wallet.test.js +392 -257
- package/test/unit/address-wallet.test.ts +379 -0
- package/test/unit/browser-provider.test.js +85 -82
- package/test/unit/browser-provider.test.ts +79 -0
- package/test/unit/contract.test.js +85 -82
- package/test/unit/contract.test.ts +83 -0
- package/test/unit/encoding-units-rlp.test.js +92 -89
- package/test/unit/encoding-units-rlp.test.ts +91 -0
- package/test/unit/errors.test.js +77 -74
- package/test/unit/errors.test.ts +76 -0
- package/test/unit/filter-by-blockhash.test.js +55 -52
- package/test/unit/filter-by-blockhash.test.ts +54 -0
- package/test/unit/fixtures/encrypted-keystores-48-32-36.js +9 -0
- package/test/unit/generate-contract-cli.test.js +42 -39
- package/test/unit/generate-contract-cli.test.ts +41 -0
- package/test/unit/generate-sdk-artifacts-json.test.js +113 -110
- package/test/unit/generate-sdk-artifacts-json.test.ts +110 -0
- package/test/unit/generator.test.js +102 -99
- package/test/unit/generator.test.ts +101 -0
- package/test/unit/hashing.test.js +68 -54
- package/test/unit/hashing.test.ts +67 -0
- package/test/unit/init.test.js +39 -36
- package/test/unit/init.test.ts +38 -0
- package/test/unit/interface.test.js +56 -53
- package/test/unit/interface.test.ts +54 -0
- package/test/unit/internal-hex.test.js +50 -47
- package/test/unit/internal-hex.test.ts +49 -0
- package/test/unit/populate-transaction.test.js +65 -62
- package/test/unit/populate-transaction.test.ts +64 -0
- package/test/unit/providers.test.js +200 -144
- package/test/unit/providers.test.ts +196 -0
- package/test/unit/result.test.js +80 -77
- package/test/unit/result.test.ts +79 -0
- package/test/unit/solidity-types.test.js +49 -46
- package/test/unit/solidity-types.test.ts +39 -0
- package/test/unit/utils.test.js +57 -54
- package/test/unit/utils.test.ts +56 -0
- package/test/verbose-logger.js +74 -0
- package/tsconfig.build.json +14 -0
|
@@ -1,371 +1,393 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Provider base classes and common types.
|
|
3
|
-
*
|
|
4
|
-
* This module models ethers.js v6 Provider patterns, adapted for QuantumCoin.
|
|
5
|
-
* The concrete JSON-RPC implementation lives in `json-rpc-provider.js`.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
const { EventEmitter } = require("events");
|
|
9
|
-
const { makeError, assertArgument } = require("../errors");
|
|
10
|
-
const { normalizeHex, isHexString } = require("../internal/hex");
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @typedef {import("../utils/encoding").BytesLike} BytesLike
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @typedef {Object} TransactionRequest
|
|
18
|
-
* @property {string=} to
|
|
19
|
-
* @property {string=} from
|
|
20
|
-
* @property {bigint|string|number=} value
|
|
21
|
-
* @property {string=} data
|
|
22
|
-
* @property {bigint|string|number=} gasLimit
|
|
23
|
-
* @property {bigint|string|number=} gasPrice
|
|
24
|
-
* @property {number=} nonce
|
|
25
|
-
* @property {number=} chainId
|
|
26
|
-
* @property {string=} remarks Optional remark field (hex, max 32 bytes)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
* @
|
|
32
|
-
* @property {
|
|
33
|
-
* @property {
|
|
34
|
-
* @property {number|string=}
|
|
35
|
-
* @property {string=}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (typeof hex === "
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
this.
|
|
98
|
-
this.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
this.
|
|
120
|
-
this.
|
|
121
|
-
this.
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
*
|
|
236
|
-
* @
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
*
|
|
303
|
-
* @param {string}
|
|
304
|
-
* @returns {Promise<TransactionResponse>}
|
|
305
|
-
*/
|
|
306
|
-
async
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Provider base classes and common types.
|
|
3
|
+
*
|
|
4
|
+
* This module models ethers.js v6 Provider patterns, adapted for QuantumCoin.
|
|
5
|
+
* The concrete JSON-RPC implementation lives in `json-rpc-provider.js`.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const { EventEmitter } = require("events");
|
|
9
|
+
const { makeError, assertArgument } = require("../errors");
|
|
10
|
+
const { normalizeHex, isHexString } = require("../internal/hex");
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @typedef {import("../utils/encoding").BytesLike} BytesLike
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @typedef {Object} TransactionRequest
|
|
18
|
+
* @property {string=} to
|
|
19
|
+
* @property {string=} from
|
|
20
|
+
* @property {bigint|string|number=} value
|
|
21
|
+
* @property {string=} data
|
|
22
|
+
* @property {bigint|string|number=} gasLimit
|
|
23
|
+
* @property {bigint|string|number=} gasPrice
|
|
24
|
+
* @property {number=} nonce
|
|
25
|
+
* @property {number=} chainId
|
|
26
|
+
* @property {string=} remarks Optional remark field (hex, max 32 bytes)
|
|
27
|
+
* @property {number|null=} signingContext Optional signing context (0, 1, 2, or null). Passed to SDK TransactionSigningRequest; default null.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @typedef {Object} Filter
|
|
32
|
+
* @property {string|string[]=} address
|
|
33
|
+
* @property {(string|string[]|null)[]=} topics
|
|
34
|
+
* @property {number|string=} fromBlock
|
|
35
|
+
* @property {number|string=} toBlock
|
|
36
|
+
* @property {string=} blockHash
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
function _hexToBigInt(hex) {
|
|
40
|
+
if (typeof hex === "bigint") return hex;
|
|
41
|
+
if (typeof hex === "number") return BigInt(hex);
|
|
42
|
+
// JSON-RPC "quantity" values may be odd-length (e.g. "0x0", "0x1").
|
|
43
|
+
assertArgument(typeof hex === "string" && /^0x[0-9a-fA-F]+$/.test(hex), "invalid hex quantity", "hex", hex);
|
|
44
|
+
return BigInt(hex);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function _hexToNumber(hex) {
|
|
48
|
+
return Number(_hexToBigInt(hex));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Convert block tag (number or string) to the format eth_getLogs expects (hex with 0x or "latest"/"pending"/"earliest").
|
|
53
|
+
* @param {number|string|undefined} blockTag
|
|
54
|
+
* @returns {string|undefined}
|
|
55
|
+
*/
|
|
56
|
+
function _blockTagToHex(blockTag) {
|
|
57
|
+
if (blockTag === undefined || blockTag === null) return undefined;
|
|
58
|
+
const s = String(blockTag).toLowerCase();
|
|
59
|
+
if (s === "latest" || s === "pending" || s === "earliest") return s;
|
|
60
|
+
const n = typeof blockTag === "number" ? blockTag : Number(blockTag);
|
|
61
|
+
if (!Number.isInteger(n) || n < 0) return undefined;
|
|
62
|
+
return normalizeHex("0x" + n.toString(16));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Minimal Log wrapper (ethers-like).
|
|
67
|
+
*/
|
|
68
|
+
class Log {
|
|
69
|
+
/**
|
|
70
|
+
* @param {any} log
|
|
71
|
+
* @param {AbstractProvider=} provider
|
|
72
|
+
*/
|
|
73
|
+
constructor(log, provider) {
|
|
74
|
+
this.provider = provider || null;
|
|
75
|
+
this.address = log.address;
|
|
76
|
+
this.topics = log.topics || [];
|
|
77
|
+
this.data = log.data || "0x";
|
|
78
|
+
this.blockHash = log.blockHash || null;
|
|
79
|
+
this.blockNumber = log.blockNumber != null ? _hexToNumber(log.blockNumber) : null;
|
|
80
|
+
this.transactionHash = log.transactionHash || null;
|
|
81
|
+
this.transactionIndex = log.transactionIndex != null ? _hexToNumber(log.transactionIndex) : null;
|
|
82
|
+
this.logIndex = log.logIndex != null ? _hexToNumber(log.logIndex) : null;
|
|
83
|
+
this.removed = Boolean(log.removed);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async getBlock() {
|
|
87
|
+
if (!this.provider || this.blockNumber == null) return null;
|
|
88
|
+
return this.provider.getBlock(this.blockNumber);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async getTransaction() {
|
|
92
|
+
if (!this.provider || !this.transactionHash) return null;
|
|
93
|
+
return this.provider.getTransaction(this.transactionHash);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async getTransactionReceipt() {
|
|
97
|
+
if (!this.provider || !this.transactionHash) return null;
|
|
98
|
+
return this.provider.getTransactionReceipt(this.transactionHash);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Minimal TransactionReceipt wrapper (ethers-like).
|
|
104
|
+
*/
|
|
105
|
+
class TransactionReceipt {
|
|
106
|
+
/**
|
|
107
|
+
* @param {any} receipt
|
|
108
|
+
* @param {AbstractProvider=} provider
|
|
109
|
+
*/
|
|
110
|
+
constructor(receipt, provider) {
|
|
111
|
+
this.provider = provider || null;
|
|
112
|
+
this.to = receipt.to || null;
|
|
113
|
+
this.from = receipt.from || null;
|
|
114
|
+
this.contractAddress = receipt.contractAddress || null;
|
|
115
|
+
this.transactionHash = receipt.transactionHash;
|
|
116
|
+
this.blockHash = receipt.blockHash;
|
|
117
|
+
this.blockNumber = receipt.blockNumber != null ? _hexToNumber(receipt.blockNumber) : null;
|
|
118
|
+
this.transactionIndex = receipt.transactionIndex != null ? _hexToNumber(receipt.transactionIndex) : null;
|
|
119
|
+
this.gasUsed = receipt.gasUsed != null ? _hexToBigInt(receipt.gasUsed) : null;
|
|
120
|
+
this.status = receipt.status != null ? _hexToNumber(receipt.status) : null;
|
|
121
|
+
this.logs = Array.isArray(receipt.logs) ? receipt.logs.map((l) => new Log(l, provider)) : [];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Minimal TransactionResponse wrapper (ethers-like).
|
|
127
|
+
*/
|
|
128
|
+
class TransactionResponse {
|
|
129
|
+
/**
|
|
130
|
+
* @param {any} tx
|
|
131
|
+
* @param {AbstractProvider=} provider
|
|
132
|
+
*/
|
|
133
|
+
constructor(tx, provider) {
|
|
134
|
+
this.provider = provider || null;
|
|
135
|
+
this.hash = tx.hash;
|
|
136
|
+
this.to = tx.to || null;
|
|
137
|
+
this.from = tx.from || null;
|
|
138
|
+
this.nonce = tx.nonce != null ? _hexToNumber(tx.nonce) : null;
|
|
139
|
+
this.data = tx.input || tx.data || "0x";
|
|
140
|
+
this.value = tx.value != null ? _hexToBigInt(tx.value) : 0n;
|
|
141
|
+
this.gasLimit = tx.gas != null ? _hexToBigInt(tx.gas) : null;
|
|
142
|
+
this.gasPrice = tx.gasPrice != null ? _hexToBigInt(tx.gasPrice) : null;
|
|
143
|
+
this.chainId = tx.chainId != null ? _hexToNumber(tx.chainId) : null;
|
|
144
|
+
this.blockNumber = tx.blockNumber != null ? _hexToNumber(tx.blockNumber) : null;
|
|
145
|
+
this.txType = tx.type != null ? _hexToNumber(tx.type) : null;
|
|
146
|
+
this.remarks = tx.remarks != null ? normalizeHex(tx.remarks) : null;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Wait for confirmations.
|
|
151
|
+
* @param {number=} confirmations
|
|
152
|
+
* @param {number=} timeoutMs
|
|
153
|
+
* @returns {Promise<TransactionReceipt>}
|
|
154
|
+
*/
|
|
155
|
+
async wait(confirmations, timeoutMs) {
|
|
156
|
+
if (!this.provider) throw makeError("missing provider", "UNKNOWN_ERROR", { operation: "wait" });
|
|
157
|
+
const conf = confirmations == null ? 1 : confirmations;
|
|
158
|
+
const start = Date.now();
|
|
159
|
+
const timeout = timeoutMs == null ? 120_000 : timeoutMs;
|
|
160
|
+
|
|
161
|
+
while (true) {
|
|
162
|
+
const receipt = await this.provider.getTransactionReceipt(this.hash);
|
|
163
|
+
if (receipt && receipt.blockNumber != null) {
|
|
164
|
+
if (conf <= 1) return receipt;
|
|
165
|
+
const current = await this.provider.getBlockNumber();
|
|
166
|
+
if (current - receipt.blockNumber + 1 >= conf) return receipt;
|
|
167
|
+
}
|
|
168
|
+
if (Date.now() - start > timeout) {
|
|
169
|
+
throw makeError("timeout waiting for transaction", "UNKNOWN_ERROR", { hash: this.hash });
|
|
170
|
+
}
|
|
171
|
+
await new Promise((r) => setTimeout(r, 2_000));
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Minimal Block wrapper (ethers-like).
|
|
178
|
+
*/
|
|
179
|
+
class Block {
|
|
180
|
+
/**
|
|
181
|
+
* @param {any} block
|
|
182
|
+
* @param {AbstractProvider=} provider
|
|
183
|
+
*/
|
|
184
|
+
constructor(block, provider) {
|
|
185
|
+
this.provider = provider || null;
|
|
186
|
+
this.hash = block.hash || null;
|
|
187
|
+
this.parentHash = block.parentHash || null;
|
|
188
|
+
this.number = block.number != null ? _hexToNumber(block.number) : null;
|
|
189
|
+
this.timestamp = block.timestamp != null ? _hexToNumber(block.timestamp) : null;
|
|
190
|
+
this.transactions = block.transactions || [];
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
async getTransaction(indexOrHash) {
|
|
194
|
+
if (!this.provider) return null;
|
|
195
|
+
if (typeof indexOrHash === "number") {
|
|
196
|
+
const hash = this.transactions[indexOrHash];
|
|
197
|
+
if (!hash) return null;
|
|
198
|
+
return this.provider.getTransaction(hash);
|
|
199
|
+
}
|
|
200
|
+
if (typeof indexOrHash === "string") return this.provider.getTransaction(indexOrHash);
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
async getTransactionReceipt(indexOrHash) {
|
|
205
|
+
if (!this.provider) return null;
|
|
206
|
+
const tx = await this.getTransaction(indexOrHash);
|
|
207
|
+
if (!tx) return null;
|
|
208
|
+
return this.provider.getTransactionReceipt(tx.hash);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
getPrefetchedTransactions() {
|
|
212
|
+
// This implementation returns only hashes unless `eth_getBlockByNumber(..., true)` is used.
|
|
213
|
+
return [];
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Base Provider class.
|
|
219
|
+
*/
|
|
220
|
+
class Provider extends EventEmitter {
|
|
221
|
+
constructor() {
|
|
222
|
+
super();
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* AbstractProvider base class (ethers-like).
|
|
228
|
+
*/
|
|
229
|
+
class AbstractProvider extends Provider {
|
|
230
|
+
constructor() {
|
|
231
|
+
super();
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Implemented by subclasses to perform JSON-RPC.
|
|
236
|
+
* @param {string} method
|
|
237
|
+
* @param {any[]=} params
|
|
238
|
+
* @returns {Promise<any>}
|
|
239
|
+
*/
|
|
240
|
+
async _perform(method, params) {
|
|
241
|
+
void method;
|
|
242
|
+
void params;
|
|
243
|
+
throw makeError("_perform not implemented", "NOT_IMPLEMENTED", {});
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
async getBlockNumber() {
|
|
247
|
+
const hex = await this._perform("eth_blockNumber", []);
|
|
248
|
+
return _hexToNumber(hex);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* @param {number|"latest"} blockNumber
|
|
253
|
+
* @returns {Promise<Block>}
|
|
254
|
+
*/
|
|
255
|
+
async getBlock(blockNumber) {
|
|
256
|
+
const tag = blockNumber === "latest" ? "latest" : normalizeHex("0x" + Number(blockNumber).toString(16));
|
|
257
|
+
const block = await this._perform("eth_getBlockByNumber", [tag, false]);
|
|
258
|
+
return new Block(block, this);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* @param {string} txHash
|
|
263
|
+
* @returns {Promise<TransactionResponse>}
|
|
264
|
+
*/
|
|
265
|
+
async getTransaction(txHash) {
|
|
266
|
+
const tx = await this._perform("eth_getTransactionByHash", [txHash]);
|
|
267
|
+
if (!tx) return null;
|
|
268
|
+
return new TransactionResponse(tx, this);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* @param {string} txHash
|
|
273
|
+
* @returns {Promise<TransactionReceipt>}
|
|
274
|
+
*/
|
|
275
|
+
async getTransactionReceipt(txHash) {
|
|
276
|
+
const receipt = await this._perform("eth_getTransactionReceipt", [txHash]);
|
|
277
|
+
if (!receipt) return null;
|
|
278
|
+
return new TransactionReceipt(receipt, this);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* @param {string} address
|
|
283
|
+
* @returns {Promise<bigint>}
|
|
284
|
+
*/
|
|
285
|
+
async getBalance(address) {
|
|
286
|
+
const bal = await this._perform("eth_getBalance", [address, "latest"]);
|
|
287
|
+
return _hexToBigInt(bal);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* @param {string} address
|
|
292
|
+
* @param {string=} blockTag
|
|
293
|
+
* @returns {Promise<number>}
|
|
294
|
+
*/
|
|
295
|
+
async getTransactionCount(address, blockTag) {
|
|
296
|
+
const tag = blockTag || "latest";
|
|
297
|
+
const nonce = await this._perform("eth_getTransactionCount", [address, tag]);
|
|
298
|
+
return _hexToNumber(nonce);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Broadcasts a signed transaction.
|
|
303
|
+
* @param {TransactionRequest|string} tx
|
|
304
|
+
* @returns {Promise<TransactionResponse>}
|
|
305
|
+
*/
|
|
306
|
+
async sendTransaction(tx) {
|
|
307
|
+
// For QuantumCoin.js, tx is expected to be a signed raw transaction hex string.
|
|
308
|
+
const raw = typeof tx === "string" ? tx : tx?.raw;
|
|
309
|
+
if (typeof raw !== "string") throw makeError("sendTransaction requires a signed raw transaction string", "INVALID_ARGUMENT", { tx });
|
|
310
|
+
const hash = await this._perform("eth_sendRawTransaction", [raw]);
|
|
311
|
+
// Fetch back transaction (best-effort)
|
|
312
|
+
const result = await this.getTransaction(hash);
|
|
313
|
+
return result || new TransactionResponse({ hash }, this);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Broadcast a signed raw transaction.
|
|
318
|
+
* Alias of sendTransaction(rawTx) for clarity when doing offline signing flows.
|
|
319
|
+
*
|
|
320
|
+
* @param {string} rawTx
|
|
321
|
+
* @returns {Promise<TransactionResponse>}
|
|
322
|
+
*/
|
|
323
|
+
async sendRawTransaction(rawTx) {
|
|
324
|
+
assertArgument(typeof rawTx === "string", "invalid rawTx", "rawTx", rawTx);
|
|
325
|
+
return this.sendTransaction(rawTx);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Perform a call (read-only) and return hex data.
|
|
330
|
+
* @param {TransactionRequest} tx
|
|
331
|
+
* @param {string=} blockTag
|
|
332
|
+
* @returns {Promise<string>}
|
|
333
|
+
*/
|
|
334
|
+
async call(tx, blockTag) {
|
|
335
|
+
const tag = blockTag || "latest";
|
|
336
|
+
return this._perform("eth_call", [tx, tag]);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Estimate gas for a call/transaction.
|
|
341
|
+
* @param {TransactionRequest} tx
|
|
342
|
+
* @returns {Promise<bigint>}
|
|
343
|
+
*/
|
|
344
|
+
async estimateGas(tx) {
|
|
345
|
+
const gas = await this._perform("eth_estimateGas", [tx]);
|
|
346
|
+
return _hexToBigInt(gas);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* @param {string} address
|
|
351
|
+
* @param {string=} blockTag
|
|
352
|
+
* @returns {Promise<string>}
|
|
353
|
+
*/
|
|
354
|
+
async getCode(address, blockTag) {
|
|
355
|
+
const tag = blockTag || "latest";
|
|
356
|
+
return this._perform("eth_getCode", [address, tag]);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* @param {string} address
|
|
361
|
+
* @param {bigint} position
|
|
362
|
+
* @param {string=} blockTag
|
|
363
|
+
* @returns {Promise<string>}
|
|
364
|
+
*/
|
|
365
|
+
async getStorageAt(address, position, blockTag) {
|
|
366
|
+
const tag = blockTag || "latest";
|
|
367
|
+
return this._perform("eth_getStorageAt", [address, "0x" + position.toString(16), tag]);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* @param {Filter} filter
|
|
372
|
+
* @returns {Promise<Log[]>}
|
|
373
|
+
*/
|
|
374
|
+
async getLogs(filter) {
|
|
375
|
+
const fromBlock = _blockTagToHex(filter.fromBlock);
|
|
376
|
+
const toBlock = _blockTagToHex(filter.toBlock);
|
|
377
|
+
const normalized = { ...filter };
|
|
378
|
+
if (fromBlock !== undefined) normalized.fromBlock = fromBlock;
|
|
379
|
+
if (toBlock !== undefined) normalized.toBlock = toBlock;
|
|
380
|
+
const logs = await this._perform("eth_getLogs", [normalized]);
|
|
381
|
+
return (logs || []).map((l) => new Log(l, this));
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
module.exports = {
|
|
386
|
+
Provider,
|
|
387
|
+
AbstractProvider,
|
|
388
|
+
Block,
|
|
389
|
+
TransactionResponse,
|
|
390
|
+
TransactionReceipt,
|
|
391
|
+
Log,
|
|
392
|
+
};
|
|
393
|
+
|