starknet 4.10.0 → 4.12.0
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 +32 -0
- package/__tests__/account.test.ts +42 -0
- package/__tests__/defaultProvider.test.ts +22 -12
- package/__tests__/fixtures.ts +3 -1
- package/__tests__/rpcProvider.test.ts +6 -4
- package/account/default.js +3 -3
- package/dist/account/default.js +3 -3
- package/dist/provider/default.d.ts +4 -2
- package/dist/provider/default.js +13 -2
- package/dist/provider/interface.d.ts +18 -3
- package/dist/provider/rpc.d.ts +13 -9
- package/dist/provider/rpc.js +63 -29
- package/dist/provider/sequencer.d.ts +2 -0
- package/dist/provider/sequencer.js +15 -0
- package/dist/types/api/openrpc.d.ts +147 -98
- package/dist/types/api/openrpc.js +22 -4
- package/dist/types/lib.d.ts +9 -2
- package/dist/types/lib.js +6 -0
- package/package.json +1 -1
- package/provider/default.d.ts +4 -2
- package/provider/default.js +13 -2
- package/provider/interface.d.ts +18 -3
- package/provider/rpc.d.ts +13 -9
- package/provider/rpc.js +63 -29
- package/provider/sequencer.d.ts +2 -0
- package/provider/sequencer.js +15 -0
- package/src/account/default.ts +8 -4
- package/src/provider/default.ts +21 -3
- package/src/provider/interface.ts +26 -2
- package/src/provider/rpc.ts +70 -42
- package/src/provider/sequencer.ts +11 -0
- package/src/types/api/openrpc.ts +193 -105
- package/src/types/api/rpc.ts +0 -1
- package/src/types/lib.ts +10 -2
- package/types/api/openrpc.d.ts +147 -98
- package/types/api/openrpc.js +22 -4
- package/types/lib.d.ts +9 -2
- package/types/lib.js +6 -0
- package/__tests__/udc.test.ts +0 -41
package/dist/provider/rpc.js
CHANGED
|
@@ -72,7 +72,7 @@ var RpcProvider = /** @class */ (function () {
|
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
74
|
RpcProvider.prototype.fetch = function (method, params) {
|
|
75
|
-
return (0, fetchPonyfill_1.default)(this.nodeUrl, {
|
|
75
|
+
return (0, fetchPonyfill_1.default)("".concat(this.nodeUrl, "/rpc/v0.2"), {
|
|
76
76
|
method: 'POST',
|
|
77
77
|
body: (0, json_1.stringify)({ method: method, jsonrpc: '2.0', params: params, id: 0 }),
|
|
78
78
|
headers: this.headers,
|
|
@@ -153,7 +153,8 @@ var RpcProvider = /** @class */ (function () {
|
|
|
153
153
|
});
|
|
154
154
|
});
|
|
155
155
|
};
|
|
156
|
-
RpcProvider.prototype.getClassHashAt = function (
|
|
156
|
+
RpcProvider.prototype.getClassHashAt = function (contractAddress, blockIdentifier) {
|
|
157
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
157
158
|
return __awaiter(this, void 0, void 0, function () {
|
|
158
159
|
var block_id;
|
|
159
160
|
return __generator(this, function (_a) {
|
|
@@ -193,6 +194,7 @@ var RpcProvider = /** @class */ (function () {
|
|
|
193
194
|
});
|
|
194
195
|
};
|
|
195
196
|
RpcProvider.prototype.getStateUpdate = function (blockIdentifier) {
|
|
197
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
196
198
|
return __awaiter(this, void 0, void 0, function () {
|
|
197
199
|
var block_id;
|
|
198
200
|
return __generator(this, function (_a) {
|
|
@@ -247,10 +249,20 @@ var RpcProvider = /** @class */ (function () {
|
|
|
247
249
|
});
|
|
248
250
|
});
|
|
249
251
|
};
|
|
250
|
-
RpcProvider.prototype.
|
|
252
|
+
RpcProvider.prototype.getClassByHash = function (classHash) {
|
|
251
253
|
return __awaiter(this, void 0, void 0, function () {
|
|
252
254
|
return __generator(this, function (_a) {
|
|
253
|
-
return [2 /*return*/, this.
|
|
255
|
+
return [2 /*return*/, this.getClass(classHash)];
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
};
|
|
259
|
+
RpcProvider.prototype.getClass = function (classHash, blockIdentifier) {
|
|
260
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
261
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
262
|
+
var block_id;
|
|
263
|
+
return __generator(this, function (_a) {
|
|
264
|
+
block_id = new utils_1.Block(blockIdentifier).identifier;
|
|
265
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getClass', { class_hash: classHash, block_id: block_id })];
|
|
254
266
|
});
|
|
255
267
|
});
|
|
256
268
|
};
|
|
@@ -270,7 +282,7 @@ var RpcProvider = /** @class */ (function () {
|
|
|
270
282
|
RpcProvider.prototype.getCode = function (_contractAddress, _blockIdentifier) {
|
|
271
283
|
return __awaiter(this, void 0, void 0, function () {
|
|
272
284
|
return __generator(this, function (_a) {
|
|
273
|
-
throw new Error('RPC
|
|
285
|
+
throw new Error('RPC does not implement getCode function');
|
|
274
286
|
});
|
|
275
287
|
});
|
|
276
288
|
};
|
|
@@ -359,46 +371,61 @@ var RpcProvider = /** @class */ (function () {
|
|
|
359
371
|
return __awaiter(this, void 0, void 0, function () {
|
|
360
372
|
return __generator(this, function (_b) {
|
|
361
373
|
return [2 /*return*/, this.fetchEndpoint('starknet_addDeclareTransaction', {
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
374
|
+
declare_transaction: {
|
|
375
|
+
contract_class: {
|
|
376
|
+
program: contractDefinition.program,
|
|
377
|
+
entry_points_by_type: contractDefinition.entry_points_by_type,
|
|
378
|
+
abi: contractDefinition.abi, // rpc 2.0
|
|
379
|
+
},
|
|
380
|
+
type: 'DECLARE',
|
|
381
|
+
version: (0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
|
|
382
|
+
max_fee: (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
|
|
383
|
+
signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(signature || []),
|
|
384
|
+
sender_address: senderAddress,
|
|
385
|
+
nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
|
|
366
386
|
},
|
|
367
|
-
version: (0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
|
|
368
|
-
max_fee: (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
|
|
369
|
-
signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(signature || []),
|
|
370
|
-
sender_address: senderAddress,
|
|
371
|
-
nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
|
|
372
387
|
})];
|
|
373
388
|
});
|
|
374
389
|
});
|
|
375
390
|
};
|
|
376
|
-
|
|
391
|
+
/**
|
|
392
|
+
* @deprecated This method wont be supported soon, use Account.deploy instead
|
|
393
|
+
*/
|
|
394
|
+
RpcProvider.prototype.deployContract = function (_a, details) {
|
|
377
395
|
var contract = _a.contract, constructorCalldata = _a.constructorCalldata, addressSalt = _a.addressSalt;
|
|
378
396
|
return __awaiter(this, void 0, void 0, function () {
|
|
379
397
|
var contractDefinition;
|
|
380
398
|
return __generator(this, function (_b) {
|
|
381
399
|
contractDefinition = (0, provider_1.parseContract)(contract);
|
|
382
400
|
return [2 /*return*/, this.fetchEndpoint('starknet_addDeployTransaction', {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
401
|
+
deploy_transaction: {
|
|
402
|
+
contract_address_salt: addressSalt !== null && addressSalt !== void 0 ? addressSalt : (0, stark_1.randomAddress)(),
|
|
403
|
+
constructor_calldata: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(constructorCalldata !== null && constructorCalldata !== void 0 ? constructorCalldata : []),
|
|
404
|
+
contract_class: {
|
|
405
|
+
program: contractDefinition.program,
|
|
406
|
+
entry_points_by_type: contractDefinition.entry_points_by_type,
|
|
407
|
+
abi: contractDefinition.abi,
|
|
408
|
+
},
|
|
409
|
+
type: 'DEPLOY',
|
|
410
|
+
version: (0, number_1.toHex)((0, number_1.toBN)((details === null || details === void 0 ? void 0 : details.version) || 0)),
|
|
389
411
|
},
|
|
390
412
|
})];
|
|
391
413
|
});
|
|
392
414
|
});
|
|
393
415
|
};
|
|
394
|
-
RpcProvider.prototype.deployAccountContract = function (_a) {
|
|
395
|
-
var classHash = _a.classHash, constructorCalldata = _a.constructorCalldata, addressSalt = _a.addressSalt;
|
|
416
|
+
RpcProvider.prototype.deployAccountContract = function (_a, details) {
|
|
417
|
+
var classHash = _a.classHash, constructorCalldata = _a.constructorCalldata, addressSalt = _a.addressSalt, signature = _a.signature;
|
|
396
418
|
return __awaiter(this, void 0, void 0, function () {
|
|
397
419
|
return __generator(this, function (_b) {
|
|
398
420
|
return [2 /*return*/, this.fetchEndpoint('starknet_addDeployAccountTransaction', {
|
|
399
421
|
constructor_calldata: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(constructorCalldata || []),
|
|
400
422
|
class_hash: (0, number_1.toHex)((0, number_1.toBN)(classHash)),
|
|
401
423
|
contract_address_salt: (0, number_1.toHex)((0, number_1.toBN)(addressSalt || 0)),
|
|
424
|
+
type: 'DEPLOY',
|
|
425
|
+
max_fee: (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
|
|
426
|
+
version: (0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
|
|
427
|
+
signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(signature || []),
|
|
428
|
+
nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
|
|
402
429
|
})];
|
|
403
430
|
});
|
|
404
431
|
});
|
|
@@ -407,13 +434,15 @@ var RpcProvider = /** @class */ (function () {
|
|
|
407
434
|
return __awaiter(this, void 0, void 0, function () {
|
|
408
435
|
return __generator(this, function (_a) {
|
|
409
436
|
return [2 /*return*/, this.fetchEndpoint('starknet_addInvokeTransaction', {
|
|
410
|
-
|
|
411
|
-
|
|
437
|
+
invoke_transaction: {
|
|
438
|
+
sender_address: functionInvocation.contractAddress,
|
|
412
439
|
calldata: (0, provider_1.parseCalldata)(functionInvocation.calldata),
|
|
440
|
+
type: 'INVOKE',
|
|
441
|
+
max_fee: (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
|
|
442
|
+
version: (0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
|
|
443
|
+
signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(functionInvocation.signature || []),
|
|
444
|
+
nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
|
|
413
445
|
},
|
|
414
|
-
signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(functionInvocation.signature || []),
|
|
415
|
-
max_fee: (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
|
|
416
|
-
version: (0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
|
|
417
446
|
})];
|
|
418
447
|
});
|
|
419
448
|
});
|
|
@@ -459,7 +488,7 @@ var RpcProvider = /** @class */ (function () {
|
|
|
459
488
|
RpcProvider.prototype.waitForTransaction = function (txHash, retryInterval) {
|
|
460
489
|
if (retryInterval === void 0) { retryInterval = 8000; }
|
|
461
490
|
return __awaiter(this, void 0, void 0, function () {
|
|
462
|
-
var retries, onchain, successStates, errorStates, res, message, error, error_2;
|
|
491
|
+
var retries, onchain, successStates, errorStates, res, error, message, error, error_2;
|
|
463
492
|
return __generator(this, function (_a) {
|
|
464
493
|
switch (_a.label) {
|
|
465
494
|
case 0:
|
|
@@ -481,6 +510,10 @@ var RpcProvider = /** @class */ (function () {
|
|
|
481
510
|
return [4 /*yield*/, this.getTransactionReceipt(txHash)];
|
|
482
511
|
case 4:
|
|
483
512
|
res = _a.sent();
|
|
513
|
+
if (!('status' in res)) {
|
|
514
|
+
error = new Error('pending transaction');
|
|
515
|
+
throw error;
|
|
516
|
+
}
|
|
484
517
|
if (res.status && successStates.includes(res.status)) {
|
|
485
518
|
onchain = true;
|
|
486
519
|
}
|
|
@@ -519,6 +552,7 @@ var RpcProvider = /** @class */ (function () {
|
|
|
519
552
|
* @returns Number of transactions
|
|
520
553
|
*/
|
|
521
554
|
RpcProvider.prototype.getTransactionCount = function (blockIdentifier) {
|
|
555
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
522
556
|
return __awaiter(this, void 0, void 0, function () {
|
|
523
557
|
var block_id;
|
|
524
558
|
return __generator(this, function (_a) {
|
|
@@ -38,6 +38,8 @@ export declare class SequencerProvider implements ProviderInterface {
|
|
|
38
38
|
getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
|
|
39
39
|
getTransactionReceipt(txHash: BigNumberish): Promise<GetTransactionReceiptResponse>;
|
|
40
40
|
getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<ContractClass>;
|
|
41
|
+
getClassHashAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<string>;
|
|
42
|
+
getClassByHash(classHash: string): Promise<ContractClass>;
|
|
41
43
|
invokeFunction(functionInvocation: Invocation, details: InvocationsDetailsWithNonce): Promise<InvokeFunctionResponse>;
|
|
42
44
|
deployContract({ contract, constructorCalldata, addressSalt, }: DeployContractPayload): Promise<DeployContractResponse>;
|
|
43
45
|
deployAccountContract({ classHash, constructorCalldata, addressSalt, signature }: DeployAccountContractTransaction, details: InvocationsDetailsWithNonce): Promise<DeployContractResponse>;
|
|
@@ -326,6 +326,21 @@ var SequencerProvider = /** @class */ (function () {
|
|
|
326
326
|
});
|
|
327
327
|
});
|
|
328
328
|
};
|
|
329
|
+
SequencerProvider.prototype.getClassHashAt = function (contractAddress, blockIdentifier) {
|
|
330
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
331
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
332
|
+
return __generator(this, function (_a) {
|
|
333
|
+
return [2 /*return*/, this.fetchEndpoint('get_class_hash_at', { blockIdentifier: blockIdentifier, contractAddress: contractAddress })];
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
};
|
|
337
|
+
SequencerProvider.prototype.getClassByHash = function (classHash) {
|
|
338
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
339
|
+
return __generator(this, function (_a) {
|
|
340
|
+
return [2 /*return*/, this.fetchEndpoint('get_class_by_hash', { classHash: classHash }).then(provider_1.parseContract)];
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
};
|
|
329
344
|
SequencerProvider.prototype.invokeFunction = function (functionInvocation, details) {
|
|
330
345
|
var _a, _b;
|
|
331
346
|
return __awaiter(this, void 0, void 0, function () {
|