starknet 4.6.0 → 4.8.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 +44 -0
- package/CONTRIBUTING.md +2 -2
- package/__mocks__/l1l2_compiled.json +10107 -0
- package/__tests__/account.test.ts +2 -5
- package/__tests__/contract.test.ts +0 -1
- package/__tests__/defaultProvider.test.ts +5 -3
- package/__tests__/fixtures.ts +2 -0
- package/__tests__/sequencerProvider.test.ts +50 -9
- package/__tests__/utils/ellipticalCurve.test.ts +7 -8
- package/__tests__/utils/merkle.test.ts +15 -0
- package/account/default.d.ts +3 -2
- package/account/default.js +22 -29
- package/account/interface.d.ts +2 -1
- package/contract/contractFactory.d.ts +1 -2
- package/contract/default.d.ts +2 -2
- package/contract/default.js +7 -3
- package/dist/account/default.d.ts +3 -2
- package/dist/account/default.js +22 -29
- package/dist/account/interface.d.ts +2 -1
- package/dist/contract/contractFactory.d.ts +1 -2
- package/dist/contract/default.d.ts +2 -2
- package/dist/contract/default.js +7 -3
- package/dist/provider/default.d.ts +4 -3
- package/dist/provider/default.js +9 -3
- package/dist/provider/interface.d.ts +10 -3
- package/dist/provider/rpc.d.ts +12 -10
- package/dist/provider/rpc.js +80 -72
- package/dist/provider/sequencer.d.ts +6 -4
- package/dist/provider/sequencer.js +36 -7
- package/dist/signer/default.d.ts +2 -2
- package/dist/signer/default.js +2 -2
- package/dist/signer/interface.d.ts +2 -2
- package/dist/types/api/openrpc.d.ts +17 -27
- package/dist/types/api/rpc.d.ts +4 -128
- package/dist/types/api/sequencer.d.ts +36 -20
- package/dist/types/lib.d.ts +10 -4
- package/dist/types/provider.d.ts +7 -2
- package/dist/utils/hash.d.ts +8 -2
- package/dist/utils/hash.js +20 -5
- package/dist/utils/merkle.js +2 -1
- package/dist/utils/number.d.ts +5 -0
- package/dist/utils/number.js +29 -1
- package/dist/utils/responseParser/rpc.d.ts +2 -5
- package/dist/utils/responseParser/rpc.js +2 -38
- package/dist/utils/responseParser/sequencer.js +7 -19
- package/package.json +1 -1
- package/provider/default.d.ts +4 -3
- package/provider/default.js +9 -3
- package/provider/interface.d.ts +10 -3
- package/provider/rpc.d.ts +12 -10
- package/provider/rpc.js +80 -72
- package/provider/sequencer.d.ts +6 -4
- package/provider/sequencer.js +36 -7
- package/signer/default.d.ts +2 -2
- package/signer/default.js +2 -2
- package/signer/interface.d.ts +2 -2
- package/src/account/default.ts +21 -20
- package/src/account/interface.ts +2 -1
- package/src/contract/contractFactory.ts +1 -2
- package/src/contract/default.ts +16 -8
- package/src/provider/default.ts +12 -5
- package/src/provider/interface.ts +15 -4
- package/src/provider/rpc.ts +89 -73
- package/src/provider/sequencer.ts +47 -11
- package/src/signer/default.ts +8 -8
- package/src/signer/interface.ts +2 -2
- package/src/types/api/openrpc.ts +20 -25
- package/src/types/api/rpc.ts +4 -128
- package/src/types/api/sequencer.ts +39 -20
- package/src/types/lib.ts +7 -5
- package/src/types/provider.ts +7 -2
- package/src/utils/hash.ts +32 -8
- package/src/utils/merkle.ts +2 -1
- package/src/utils/number.ts +27 -0
- package/src/utils/responseParser/rpc.ts +7 -25
- package/src/utils/responseParser/sequencer.ts +12 -7
- package/types/api/openrpc.d.ts +17 -27
- package/types/api/rpc.d.ts +4 -128
- package/types/api/sequencer.d.ts +36 -20
- package/types/lib.d.ts +10 -4
- package/types/provider.d.ts +7 -2
- package/utils/hash.d.ts +8 -2
- package/utils/hash.js +20 -5
- package/utils/merkle.js +2 -1
- package/utils/number.d.ts +5 -0
- package/utils/number.js +29 -1
- package/utils/responseParser/rpc.d.ts +2 -5
- package/utils/responseParser/rpc.js +2 -38
- package/utils/responseParser/sequencer.js +7 -19
- package/www/docs/API/account.md +3 -3
- package/www/docs/API/contract.md +2 -2
- package/www/docs/API/provider.md +20 -6
- package/www/docs/API/utils.md +2 -2
- package/www/guides/account.md +1 -1
package/dist/utils/hash.js
CHANGED
|
@@ -28,7 +28,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
28
28
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
29
29
|
};
|
|
30
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
-
exports.calculateContractAddressFromHash = exports.
|
|
31
|
+
exports.calculateContractAddressFromHash = exports.calculateTransactionHash = exports.calculateDeployTransactionHash = exports.calculateTransactionHashCommon = exports.computeHashOnElements = exports.pedersen = exports.getSelector = exports.getSelectorFromName = exports.starknetKeccak = exports.keccakBn = exports.feeTransactionVersion = exports.transactionVersion = void 0;
|
|
32
32
|
var keccak_1 = require("ethereum-cryptography/keccak");
|
|
33
33
|
var utils_1 = require("ethereum-cryptography/utils");
|
|
34
34
|
var minimalistic_assert_1 = __importDefault(require("minimalistic-assert"));
|
|
@@ -36,7 +36,7 @@ var constants_1 = require("../constants");
|
|
|
36
36
|
var ellipticCurve_1 = require("./ellipticCurve");
|
|
37
37
|
var encode_1 = require("./encode");
|
|
38
38
|
var number_1 = require("./number");
|
|
39
|
-
exports.transactionVersion =
|
|
39
|
+
exports.transactionVersion = 1;
|
|
40
40
|
exports.feeTransactionVersion = (0, number_1.toBN)(2).pow((0, number_1.toBN)(128)).add((0, number_1.toBN)(exports.transactionVersion));
|
|
41
41
|
function keccakBn(value) {
|
|
42
42
|
var hexWithoutPrefix = (0, encode_1.removeHexPrefix)((0, number_1.toHex)((0, number_1.toBN)(value)));
|
|
@@ -70,6 +70,21 @@ function getSelectorFromName(funcName) {
|
|
|
70
70
|
return (0, number_1.toHex)(starknetKeccak(funcName));
|
|
71
71
|
}
|
|
72
72
|
exports.getSelectorFromName = getSelectorFromName;
|
|
73
|
+
/**
|
|
74
|
+
* Function to get hex selector from function name, decimal string or hex string
|
|
75
|
+
* @param value hex string | decimal string | string
|
|
76
|
+
* @returns Hex selector
|
|
77
|
+
*/
|
|
78
|
+
function getSelector(value) {
|
|
79
|
+
if ((0, number_1.isHex)(value)) {
|
|
80
|
+
return value;
|
|
81
|
+
}
|
|
82
|
+
if ((0, number_1.isStringWholeNumber)(value)) {
|
|
83
|
+
return (0, number_1.toHexString)(value);
|
|
84
|
+
}
|
|
85
|
+
return getSelectorFromName(value);
|
|
86
|
+
}
|
|
87
|
+
exports.getSelector = getSelector;
|
|
73
88
|
var constantPoints = constants_1.CONSTANT_POINTS.map(function (coords) {
|
|
74
89
|
return ellipticCurve_1.ec.curve.point(coords[0], coords[1]);
|
|
75
90
|
});
|
|
@@ -117,10 +132,10 @@ function calculateDeployTransactionHash(contractAddress, constructorCalldata, ve
|
|
|
117
132
|
return calculateTransactionHashCommon(constants_1.TransactionHashPrefix.DEPLOY, version, contractAddress, getSelectorFromName('constructor'), constructorCalldata, constants_1.ZERO, chainId);
|
|
118
133
|
}
|
|
119
134
|
exports.calculateDeployTransactionHash = calculateDeployTransactionHash;
|
|
120
|
-
function
|
|
121
|
-
return calculateTransactionHashCommon(constants_1.TransactionHashPrefix.INVOKE, version, contractAddress,
|
|
135
|
+
function calculateTransactionHash(contractAddress, version, calldata, maxFee, chainId, nonce) {
|
|
136
|
+
return calculateTransactionHashCommon(constants_1.TransactionHashPrefix.INVOKE, version, contractAddress, 0, calldata, maxFee, chainId, [nonce]);
|
|
122
137
|
}
|
|
123
|
-
exports.
|
|
138
|
+
exports.calculateTransactionHash = calculateTransactionHash;
|
|
124
139
|
function calculateContractAddressFromHash(salt, classHash, constructorCalldata, deployerAddress) {
|
|
125
140
|
var constructorCalldataHash = computeHashOnElements(constructorCalldata);
|
|
126
141
|
var CONTRACT_ADDRESS_PREFIX = (0, number_1.toFelt)('0x535441524b4e45545f434f4e54524143545f41444452455353'); // Equivalent to 'STARKNET_CONTRACT_ADDRESS'
|
package/dist/utils/merkle.js
CHANGED
|
@@ -27,6 +27,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
27
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
28
|
exports.proofMerklePath = exports.MerkleTree = void 0;
|
|
29
29
|
var hash_1 = require("./hash");
|
|
30
|
+
var number_1 = require("./number");
|
|
30
31
|
var MerkleTree = /** @class */ (function () {
|
|
31
32
|
function MerkleTree(leafHashes) {
|
|
32
33
|
this.branches = [];
|
|
@@ -52,7 +53,7 @@ var MerkleTree = /** @class */ (function () {
|
|
|
52
53
|
return this.build(newLeaves);
|
|
53
54
|
};
|
|
54
55
|
MerkleTree.hash = function (a, b) {
|
|
55
|
-
var _a = __read([a, b].sort(), 2), aSorted = _a[0], bSorted = _a[1];
|
|
56
|
+
var _a = __read([(0, number_1.toBN)(a), (0, number_1.toBN)(b)].sort(function (x, y) { return (x.gte(y) ? 1 : -1); }), 2), aSorted = _a[0], bSorted = _a[1];
|
|
56
57
|
return (0, hash_1.pedersen)([aSorted, bSorted]);
|
|
57
58
|
};
|
|
58
59
|
MerkleTree.prototype.getProof = function (leaf, branch, hashPath) {
|
package/dist/utils/number.d.ts
CHANGED
|
@@ -8,3 +8,8 @@ export declare function toFelt(num: BigNumberish): string;
|
|
|
8
8
|
export declare function assertInRange(input: BigNumberish, lowerBound: BigNumberish, upperBound: BigNumberish, inputName?: string): void;
|
|
9
9
|
export declare function bigNumberishArrayToDecimalStringArray(rawCalldata: BigNumberish[]): string[];
|
|
10
10
|
export declare function bigNumberishArrayToHexadecimalStringArray(rawCalldata: BigNumberish[]): string[];
|
|
11
|
+
export declare const isStringWholeNumber: (value: string) => boolean;
|
|
12
|
+
export declare const toHexString: (value: string) => string;
|
|
13
|
+
export declare function getDecimalString(value: string): string;
|
|
14
|
+
export declare function getHexString(value: string): string;
|
|
15
|
+
export declare function getHexStringArray(value: Array<string>): string[];
|
package/dist/utils/number.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.bigNumberishArrayToHexadecimalStringArray = exports.bigNumberishArrayToDecimalStringArray = exports.assertInRange = exports.toFelt = exports.hexToDecimalString = exports.toHex = exports.toBN = exports.isHex = void 0;
|
|
29
|
+
exports.getHexStringArray = exports.getHexString = exports.getDecimalString = exports.toHexString = exports.isStringWholeNumber = exports.bigNumberishArrayToHexadecimalStringArray = exports.bigNumberishArrayToDecimalStringArray = exports.assertInRange = exports.toFelt = exports.hexToDecimalString = exports.toHex = exports.toBN = exports.isHex = void 0;
|
|
30
30
|
var bn_js_1 = __importStar(require("bn.js"));
|
|
31
31
|
var minimalistic_assert_1 = __importDefault(require("minimalistic-assert"));
|
|
32
32
|
var encode_1 = require("./encode");
|
|
@@ -80,3 +80,31 @@ function bigNumberishArrayToHexadecimalStringArray(rawCalldata) {
|
|
|
80
80
|
return rawCalldata.map(function (x) { return toHex(toBN(x)); });
|
|
81
81
|
}
|
|
82
82
|
exports.bigNumberishArrayToHexadecimalStringArray = bigNumberishArrayToHexadecimalStringArray;
|
|
83
|
+
var isStringWholeNumber = function (value) { return /^\d+$/.test(value); };
|
|
84
|
+
exports.isStringWholeNumber = isStringWholeNumber;
|
|
85
|
+
var toHexString = function (value) { return toHex(toBN(value)); };
|
|
86
|
+
exports.toHexString = toHexString;
|
|
87
|
+
function getDecimalString(value) {
|
|
88
|
+
if (isHex(value)) {
|
|
89
|
+
return hexToDecimalString(value);
|
|
90
|
+
}
|
|
91
|
+
if ((0, exports.isStringWholeNumber)(value)) {
|
|
92
|
+
return value;
|
|
93
|
+
}
|
|
94
|
+
throw new Error("".concat(value, " need to be hex-string or whole-number-string"));
|
|
95
|
+
}
|
|
96
|
+
exports.getDecimalString = getDecimalString;
|
|
97
|
+
function getHexString(value) {
|
|
98
|
+
if (isHex(value)) {
|
|
99
|
+
return value;
|
|
100
|
+
}
|
|
101
|
+
if ((0, exports.isStringWholeNumber)(value)) {
|
|
102
|
+
return (0, exports.toHexString)(value);
|
|
103
|
+
}
|
|
104
|
+
throw new Error("".concat(value, " need to be hex-string or whole-number-string"));
|
|
105
|
+
}
|
|
106
|
+
exports.getHexString = getHexString;
|
|
107
|
+
function getHexStringArray(value) {
|
|
108
|
+
return value.map(function (el) { return getHexString(el); });
|
|
109
|
+
}
|
|
110
|
+
exports.getHexStringArray = getHexStringArray;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Map RPC Response to common interface response
|
|
3
3
|
* Intersection (sequencer response ∩ (∪ rpc responses))
|
|
4
4
|
*/
|
|
5
|
-
import { CallContractResponse,
|
|
5
|
+
import { CallContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionReceiptResponse, GetTransactionResponse } from '../../types';
|
|
6
6
|
import { RPC } from '../../types/api';
|
|
7
7
|
import { ResponseParser } from '.';
|
|
8
8
|
declare type RpcGetBlockResponse = RPC.GetBlockWithTxHashesResponse & {
|
|
@@ -14,14 +14,11 @@ declare type GetTransactionByHashResponse = RPC.GetTransactionByHashResponse & {
|
|
|
14
14
|
declare type TransactionReceipt = RPC.TransactionReceipt & {
|
|
15
15
|
[key: string]: any;
|
|
16
16
|
};
|
|
17
|
-
export declare class RPCResponseParser
|
|
17
|
+
export declare class RPCResponseParser implements Omit<ResponseParser, 'parseDeclareContractResponse' | 'parseDeployContractResponse' | 'parseInvokeFunctionResponse'> {
|
|
18
18
|
parseGetBlockResponse(res: RpcGetBlockResponse): GetBlockResponse;
|
|
19
19
|
parseGetTransactionResponse(res: GetTransactionByHashResponse): GetTransactionResponse;
|
|
20
20
|
parseGetTransactionReceiptResponse(res: TransactionReceipt): GetTransactionReceiptResponse;
|
|
21
21
|
parseFeeEstimateResponse(res: RPC.EstimateFeeResponse): EstimateFeeResponse;
|
|
22
22
|
parseCallContractResponse(res: Array<string>): CallContractResponse;
|
|
23
|
-
parseInvokeFunctionResponse(res: RPC.InvokedTransaction): InvokeFunctionResponse;
|
|
24
|
-
parseDeployContractResponse(res: RPC.DeployedTransaction): DeployContractResponse;
|
|
25
|
-
parseDeclareContractResponse(res: RPC.DeclaredTransaction): DeclareContractResponse;
|
|
26
23
|
}
|
|
27
24
|
export {};
|
|
@@ -1,27 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.RPCResponseParser = void 0;
|
|
19
4
|
var number_1 = require("../number");
|
|
20
|
-
var
|
|
21
|
-
var RPCResponseParser = /** @class */ (function (_super) {
|
|
22
|
-
__extends(RPCResponseParser, _super);
|
|
5
|
+
var RPCResponseParser = /** @class */ (function () {
|
|
23
6
|
function RPCResponseParser() {
|
|
24
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
25
7
|
}
|
|
26
8
|
RPCResponseParser.prototype.parseGetBlockResponse = function (res) {
|
|
27
9
|
return {
|
|
@@ -38,7 +20,6 @@ var RPCResponseParser = /** @class */ (function (_super) {
|
|
|
38
20
|
return {
|
|
39
21
|
calldata: res.calldata || [],
|
|
40
22
|
contract_address: res.contract_address,
|
|
41
|
-
entry_point_selector: res.entry_point_selector,
|
|
42
23
|
max_fee: res.max_fee,
|
|
43
24
|
nonce: res.nonce,
|
|
44
25
|
signature: res.signature || [],
|
|
@@ -69,23 +50,6 @@ var RPCResponseParser = /** @class */ (function (_super) {
|
|
|
69
50
|
result: res,
|
|
70
51
|
};
|
|
71
52
|
};
|
|
72
|
-
RPCResponseParser.prototype.parseInvokeFunctionResponse = function (res) {
|
|
73
|
-
return {
|
|
74
|
-
transaction_hash: res.transaction_hash,
|
|
75
|
-
};
|
|
76
|
-
};
|
|
77
|
-
RPCResponseParser.prototype.parseDeployContractResponse = function (res) {
|
|
78
|
-
return {
|
|
79
|
-
transaction_hash: res.transaction_hash,
|
|
80
|
-
contract_address: res.contract_address,
|
|
81
|
-
};
|
|
82
|
-
};
|
|
83
|
-
RPCResponseParser.prototype.parseDeclareContractResponse = function (res) {
|
|
84
|
-
return {
|
|
85
|
-
transaction_hash: res.transaction_hash,
|
|
86
|
-
class_hash: res.class_hash,
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
53
|
return RPCResponseParser;
|
|
90
|
-
}(
|
|
54
|
+
}());
|
|
91
55
|
exports.RPCResponseParser = RPCResponseParser;
|
|
@@ -35,17 +35,9 @@ var SequencerAPIResponseParser = /** @class */ (function (_super) {
|
|
|
35
35
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
36
36
|
}
|
|
37
37
|
SequencerAPIResponseParser.prototype.parseGetBlockResponse = function (res) {
|
|
38
|
-
return {
|
|
39
|
-
timestamp: res.timestamp,
|
|
40
|
-
block_hash: res.block_hash,
|
|
41
|
-
block_number: res.block_number,
|
|
42
|
-
new_root: res.state_root,
|
|
43
|
-
parent_hash: res.parent_block_hash,
|
|
44
|
-
status: res.status,
|
|
45
|
-
transactions: Object.values(res.transactions)
|
|
38
|
+
return __assign(__assign({}, res), { new_root: res.state_root, parent_hash: res.parent_block_hash, transactions: Object.values(res.transactions)
|
|
46
39
|
.map(function (value) { return 'transaction_hash' in value && value.transaction_hash; })
|
|
47
|
-
.filter(Boolean)
|
|
48
|
-
};
|
|
40
|
+
.filter(Boolean) });
|
|
49
41
|
};
|
|
50
42
|
SequencerAPIResponseParser.prototype.parseGetTransactionResponse = function (res) {
|
|
51
43
|
return {
|
|
@@ -66,15 +58,11 @@ var SequencerAPIResponseParser = /** @class */ (function (_super) {
|
|
|
66
58
|
};
|
|
67
59
|
};
|
|
68
60
|
SequencerAPIResponseParser.prototype.parseGetTransactionReceiptResponse = function (res) {
|
|
69
|
-
return {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
messages_sent: res.l2_to_l1_messages,
|
|
75
|
-
events: res.events,
|
|
76
|
-
l1_origin_message: undefined,
|
|
77
|
-
};
|
|
61
|
+
return __assign(__assign(__assign(__assign(__assign(__assign(__assign({ transaction_hash: res.transaction_hash, status: res.status, messages_sent: res.l2_to_l1_messages, events: res.events }, ('block_hash' in res && { block_hash: res.block_hash })), ('block_number' in res && { block_number: res.block_number })), ('actual_fee' in res && { actual_fee: res.actual_fee })), ('transaction_index' in res && { transaction_index: res.transaction_index })), ('execution_resources' in res && { execution_resources: res.execution_resources })), ('l1_to_l2_consumed_message' in res && {
|
|
62
|
+
l1_to_l2_consumed_message: res['l1_to_l2_consumed_message'],
|
|
63
|
+
})), ('transaction_failure_reason' in res && {
|
|
64
|
+
transaction_failure_reason: res.transaction_failure_reason,
|
|
65
|
+
}));
|
|
78
66
|
};
|
|
79
67
|
SequencerAPIResponseParser.prototype.parseFeeEstimateResponse = function (res) {
|
|
80
68
|
if ('overall_fee' in res) {
|
package/package.json
CHANGED
package/provider/default.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StarknetChainId } from '../constants';
|
|
2
|
-
import { Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation,
|
|
2
|
+
import { Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetailsWithNonce, InvokeFunctionResponse } from '../types';
|
|
3
3
|
import { BigNumberish } from '../utils/number';
|
|
4
4
|
import { ProviderInterface } from './interface';
|
|
5
5
|
import { RpcProviderOptions } from './rpc';
|
|
@@ -16,12 +16,13 @@ export declare class Provider implements ProviderInterface {
|
|
|
16
16
|
getChainId(): Promise<StarknetChainId>;
|
|
17
17
|
getBlock(blockIdentifier?: BlockIdentifier): Promise<GetBlockResponse>;
|
|
18
18
|
getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<ContractClass>;
|
|
19
|
-
getEstimateFee(invocation: Invocation,
|
|
19
|
+
getEstimateFee(invocation: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
|
|
20
|
+
getNonce(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
|
|
20
21
|
getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
|
|
21
22
|
getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
|
|
22
23
|
getTransactionReceipt(txHash: BigNumberish): Promise<GetTransactionReceiptResponse>;
|
|
23
24
|
callContract(request: Call, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
|
|
24
|
-
invokeFunction(functionInvocation: Invocation, details:
|
|
25
|
+
invokeFunction(functionInvocation: Invocation, details: InvocationsDetailsWithNonce): Promise<InvokeFunctionResponse>;
|
|
25
26
|
deployContract(payload: DeployContractPayload): Promise<DeployContractResponse>;
|
|
26
27
|
declareContract(payload: DeclareContractPayload): Promise<DeclareContractResponse>;
|
|
27
28
|
getCode(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<GetCodeResponse>;
|
package/provider/default.js
CHANGED
|
@@ -84,12 +84,18 @@ var Provider = /** @class */ (function () {
|
|
|
84
84
|
});
|
|
85
85
|
});
|
|
86
86
|
};
|
|
87
|
-
Provider.prototype.getEstimateFee = function (invocation,
|
|
87
|
+
Provider.prototype.getEstimateFee = function (invocation, invocationDetails, blockIdentifier) {
|
|
88
88
|
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
89
|
-
if (invocationDetails === void 0) { invocationDetails = {}; }
|
|
90
89
|
return __awaiter(this, void 0, void 0, function () {
|
|
91
90
|
return __generator(this, function (_a) {
|
|
92
|
-
return [2 /*return*/, this.provider.getEstimateFee(invocation,
|
|
91
|
+
return [2 /*return*/, this.provider.getEstimateFee(invocation, invocationDetails, blockIdentifier)];
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
Provider.prototype.getNonce = function (contractAddress, blockIdentifier) {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
97
|
+
return __generator(this, function (_a) {
|
|
98
|
+
return [2 /*return*/, this.provider.getNonce(contractAddress, blockIdentifier)];
|
|
93
99
|
});
|
|
94
100
|
});
|
|
95
101
|
};
|
package/provider/interface.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StarknetChainId } from '../constants';
|
|
2
|
-
import type { Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation,
|
|
2
|
+
import type { Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetailsWithNonce, InvokeFunctionResponse } from '../types';
|
|
3
3
|
import type { BigNumberish } from '../utils/number';
|
|
4
4
|
import { BlockIdentifier } from './utils';
|
|
5
5
|
export declare abstract class ProviderInterface {
|
|
@@ -37,6 +37,13 @@ export declare abstract class ProviderInterface {
|
|
|
37
37
|
* @returns Contract class of compiled contract
|
|
38
38
|
*/
|
|
39
39
|
abstract getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<ContractClass>;
|
|
40
|
+
/**
|
|
41
|
+
* Gets the nonce of a contract with respect to a specific block
|
|
42
|
+
*
|
|
43
|
+
* @param contractAddress - contract address
|
|
44
|
+
* @returns the hex nonce
|
|
45
|
+
*/
|
|
46
|
+
abstract getNonce(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
|
|
40
47
|
/**
|
|
41
48
|
* Gets the contract's storage variable at a specific key.
|
|
42
49
|
*
|
|
@@ -94,7 +101,7 @@ export declare abstract class ProviderInterface {
|
|
|
94
101
|
* - maxFee - optional maxFee
|
|
95
102
|
* @returns response from addTransaction
|
|
96
103
|
*/
|
|
97
|
-
abstract invokeFunction(invocation: Invocation, details
|
|
104
|
+
abstract invokeFunction(invocation: Invocation, details: InvocationsDetailsWithNonce): Promise<InvokeFunctionResponse>;
|
|
98
105
|
/**
|
|
99
106
|
* Estimates the fee for a given transaction
|
|
100
107
|
*
|
|
@@ -109,7 +116,7 @@ export declare abstract class ProviderInterface {
|
|
|
109
116
|
* - version - optional version
|
|
110
117
|
* @returns the estimated fee
|
|
111
118
|
*/
|
|
112
|
-
abstract getEstimateFee(invocation: Invocation,
|
|
119
|
+
abstract getEstimateFee(invocation: Invocation, details: InvocationsDetailsWithNonce, blockIdentifier: BlockIdentifier): Promise<EstimateFeeResponse>;
|
|
113
120
|
/**
|
|
114
121
|
* Wait for the transaction to be accepted
|
|
115
122
|
* @param txHash - transaction hash
|
package/provider/rpc.d.ts
CHANGED
|
@@ -1,46 +1,48 @@
|
|
|
1
1
|
import { StarknetChainId } from '../constants';
|
|
2
|
-
import { Call, CallContractResponse, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation,
|
|
2
|
+
import { Call, CallContractResponse, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetailsWithNonce, InvokeFunctionResponse } from '../types';
|
|
3
3
|
import { RPC } from '../types/api';
|
|
4
4
|
import { BigNumberish } from '../utils/number';
|
|
5
5
|
import { ProviderInterface } from './interface';
|
|
6
6
|
import { BlockIdentifier } from './utils';
|
|
7
7
|
export declare type RpcProviderOptions = {
|
|
8
8
|
nodeUrl: string;
|
|
9
|
+
retries?: number;
|
|
9
10
|
};
|
|
10
11
|
export declare class RpcProvider implements ProviderInterface {
|
|
11
12
|
nodeUrl: string;
|
|
12
13
|
chainId: StarknetChainId;
|
|
13
14
|
private responseParser;
|
|
15
|
+
private retries;
|
|
14
16
|
constructor(optionsOrProvider: RpcProviderOptions);
|
|
15
17
|
fetch(method: any, params: any): Promise<any>;
|
|
16
18
|
protected errorHandler(error: any): void;
|
|
17
|
-
protected fetchEndpoint<T extends keyof RPC.Methods>(method: T,
|
|
19
|
+
protected fetchEndpoint<T extends keyof RPC.Methods>(method: T, params?: RPC.Methods[T]['params']): Promise<RPC.Methods[T]['result']>;
|
|
18
20
|
getChainId(): Promise<any>;
|
|
19
21
|
getBlock(blockIdentifier?: BlockIdentifier): Promise<GetBlockResponse>;
|
|
20
22
|
getBlockHashAndNumber(): Promise<RPC.BlockHashAndNumber>;
|
|
21
23
|
getBlockWithTxHashes(blockIdentifier?: BlockIdentifier): Promise<RPC.GetBlockWithTxHashesResponse>;
|
|
22
24
|
getBlockWithTxs(blockIdentifier?: BlockIdentifier): Promise<RPC.GetBlockWithTxs>;
|
|
23
25
|
getClassHashAt(blockIdentifier: BlockIdentifier, contractAddress: RPC.ContractAddress): Promise<RPC.Felt>;
|
|
24
|
-
getNonce(contractAddress: string): Promise<
|
|
26
|
+
getNonce(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<RPC.Nonce>;
|
|
25
27
|
getPendingTransactions(): Promise<RPC.PendingTransactions>;
|
|
26
28
|
getProtocolVersion(): Promise<Error>;
|
|
27
29
|
getStateUpdate(blockIdentifier: BlockIdentifier): Promise<RPC.StateUpdate>;
|
|
28
30
|
getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
|
|
29
|
-
getTransaction(txHash:
|
|
30
|
-
getTransactionByHash(txHash:
|
|
31
|
+
getTransaction(txHash: string): Promise<GetTransactionResponse>;
|
|
32
|
+
getTransactionByHash(txHash: string): Promise<RPC.GetTransactionByHashResponse>;
|
|
31
33
|
getTransactionByBlockIdAndIndex(blockIdentifier: BlockIdentifier, index: number): Promise<RPC.GetTransactionByBlockIdAndIndex>;
|
|
32
|
-
getTransactionReceipt(txHash:
|
|
34
|
+
getTransactionReceipt(txHash: string): Promise<GetTransactionReceiptResponse>;
|
|
33
35
|
getClass(classHash: RPC.Felt): Promise<RPC.ContractClass>;
|
|
34
|
-
getClassAt(contractAddress: string, blockIdentifier: BlockIdentifier): Promise<
|
|
36
|
+
getClassAt(contractAddress: string, blockIdentifier: BlockIdentifier): Promise<RPC.ContractClass>;
|
|
35
37
|
getCode(_contractAddress: string, _blockIdentifier?: BlockIdentifier): Promise<GetCodeResponse>;
|
|
36
|
-
getEstimateFee(invocation: Invocation,
|
|
38
|
+
getEstimateFee(invocation: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
|
|
37
39
|
declareContract({ contract, version, }: DeclareContractPayload): Promise<DeclareContractResponse>;
|
|
38
40
|
deployContract({ contract, constructorCalldata, addressSalt, }: DeployContractPayload): Promise<DeployContractResponse>;
|
|
39
|
-
invokeFunction(functionInvocation: Invocation, details:
|
|
41
|
+
invokeFunction(functionInvocation: Invocation, details: InvocationsDetailsWithNonce): Promise<InvokeFunctionResponse>;
|
|
40
42
|
callContract(call: Call, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
|
|
41
43
|
traceTransaction(transactionHash: RPC.TransactionHash): Promise<RPC.Trace>;
|
|
42
44
|
traceBlockTransactions(blockHash: RPC.BlockHash): Promise<RPC.Traces>;
|
|
43
|
-
waitForTransaction(txHash:
|
|
45
|
+
waitForTransaction(txHash: string, retryInterval?: number): Promise<void>;
|
|
44
46
|
/**
|
|
45
47
|
* Gets the transaction count from a block.
|
|
46
48
|
*
|