starknet 4.5.0 → 4.7.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 +40 -0
- package/README.md +3 -1
- package/__tests__/account.test.ts +2 -5
- package/__tests__/contract.test.ts +0 -1
- package/__tests__/defaultProvider.test.ts +16 -10
- package/__tests__/rpcProvider.test.ts +107 -12
- package/__tests__/sequencerProvider.test.ts +10 -8
- package/__tests__/utils/ellipticalCurve.test.ts +7 -8
- package/__tests__/utils/utils.test.ts +17 -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 +24 -12
- package/dist/provider/rpc.js +167 -105
- package/dist/provider/sequencer.d.ts +4 -3
- package/dist/provider/sequencer.js +16 -7
- package/dist/provider/utils.d.ts +11 -35
- package/dist/provider/utils.js +52 -63
- 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 +395 -45
- package/dist/types/api/openrpc.js +21 -3
- package/dist/types/api/rpc.d.ts +34 -191
- package/dist/types/api/sequencer.d.ts +15 -4
- package/dist/types/lib.d.ts +10 -4
- package/dist/types/provider.d.ts +3 -2
- package/dist/utils/hash.d.ts +2 -2
- package/dist/utils/hash.js +5 -5
- package/dist/utils/responseParser/rpc.d.ts +6 -6
- package/dist/utils/responseParser/rpc.js +3 -39
- 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 +24 -12
- package/provider/rpc.js +167 -105
- package/provider/sequencer.d.ts +4 -3
- package/provider/sequencer.js +16 -7
- package/provider/utils.d.ts +11 -35
- package/provider/utils.js +52 -63
- 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 +152 -102
- package/src/provider/sequencer.ts +19 -10
- package/src/provider/utils.ts +43 -56
- package/src/signer/default.ts +8 -8
- package/src/signer/interface.ts +2 -2
- package/src/types/api/openrpc.ts +378 -53
- package/src/types/api/rpc.ts +33 -211
- package/src/types/api/sequencer.ts +17 -4
- package/src/types/lib.ts +7 -5
- package/src/types/provider.ts +3 -2
- package/src/utils/hash.ts +7 -6
- package/src/utils/responseParser/rpc.ts +13 -27
- package/types/api/openrpc.d.ts +395 -45
- package/types/api/openrpc.js +21 -3
- package/types/api/rpc.d.ts +34 -191
- package/types/api/sequencer.d.ts +15 -4
- package/types/lib.d.ts +10 -4
- package/types/provider.d.ts +3 -2
- package/utils/hash.d.ts +2 -2
- package/utils/hash.js +5 -5
- package/utils/responseParser/rpc.d.ts +6 -6
- package/utils/responseParser/rpc.js +3 -39
- package/www/docs/API/account.md +3 -3
- package/www/docs/API/contract.md +2 -2
- package/www/docs/API/provider.md +6 -0
- package/www/docs/API/utils.md +2 -2
package/provider/rpc.js
CHANGED
|
@@ -52,60 +52,52 @@ var RpcProvider = /** @class */ (function () {
|
|
|
52
52
|
function RpcProvider(optionsOrProvider) {
|
|
53
53
|
var _this = this;
|
|
54
54
|
this.responseParser = new rpc_1.RPCResponseParser();
|
|
55
|
-
var nodeUrl = optionsOrProvider.nodeUrl;
|
|
55
|
+
var nodeUrl = optionsOrProvider.nodeUrl, retries = optionsOrProvider.retries;
|
|
56
56
|
this.nodeUrl = nodeUrl;
|
|
57
|
+
this.retries = retries || 200;
|
|
57
58
|
this.getChainId().then(function (chainId) {
|
|
58
59
|
_this.chainId = chainId;
|
|
59
60
|
});
|
|
60
61
|
}
|
|
61
|
-
RpcProvider.prototype.
|
|
62
|
+
RpcProvider.prototype.fetch = function (method, params) {
|
|
63
|
+
return (0, fetchPonyfill_1.default)(this.nodeUrl, {
|
|
64
|
+
method: 'POST',
|
|
65
|
+
body: (0, json_1.stringify)({ method: method, jsonrpc: '2.0', params: params, id: 0 }),
|
|
66
|
+
headers: { 'Content-Type': 'application/json' },
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
RpcProvider.prototype.errorHandler = function (error) {
|
|
70
|
+
if (error) {
|
|
71
|
+
var code = error.code, message = error.message;
|
|
72
|
+
throw new Error("".concat(code, ": ").concat(message));
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
RpcProvider.prototype.fetchEndpoint = function (method, params) {
|
|
62
76
|
var _a;
|
|
63
77
|
return __awaiter(this, void 0, void 0, function () {
|
|
64
|
-
var
|
|
78
|
+
var rawResult, _b, error, result, error_1;
|
|
65
79
|
return __generator(this, function (_c) {
|
|
66
80
|
switch (_c.label) {
|
|
67
81
|
case 0:
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
jsonrpc: '2.0',
|
|
71
|
-
params: request,
|
|
72
|
-
id: 0,
|
|
73
|
-
};
|
|
74
|
-
_c.label = 1;
|
|
82
|
+
_c.trys.push([0, 3, , 4]);
|
|
83
|
+
return [4 /*yield*/, this.fetch(method, params)];
|
|
75
84
|
case 1:
|
|
76
|
-
_c.trys.push([1, 4, , 5]);
|
|
77
|
-
return [4 /*yield*/, (0, fetchPonyfill_1.default)(this.nodeUrl, {
|
|
78
|
-
method: 'POST',
|
|
79
|
-
body: (0, json_1.stringify)(requestData),
|
|
80
|
-
headers: {
|
|
81
|
-
'Content-Type': 'application/json',
|
|
82
|
-
},
|
|
83
|
-
})];
|
|
84
|
-
case 2:
|
|
85
85
|
rawResult = _c.sent();
|
|
86
86
|
return [4 /*yield*/, rawResult.json()];
|
|
87
|
-
case
|
|
87
|
+
case 2:
|
|
88
88
|
_b = _c.sent(), error = _b.error, result = _b.result;
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
return [2 /*return*/, result];
|
|
95
|
-
}
|
|
96
|
-
return [3 /*break*/, 5];
|
|
97
|
-
case 4:
|
|
89
|
+
this.errorHandler(error);
|
|
90
|
+
return [2 /*return*/, result];
|
|
91
|
+
case 3:
|
|
98
92
|
error_1 = _c.sent();
|
|
99
|
-
|
|
100
|
-
if (data === null || data === void 0 ? void 0 : data.message) {
|
|
101
|
-
throw new Error("".concat(data.code, ": ").concat(data.message));
|
|
102
|
-
}
|
|
93
|
+
this.errorHandler((_a = error_1 === null || error_1 === void 0 ? void 0 : error_1.response) === null || _a === void 0 ? void 0 : _a.data);
|
|
103
94
|
throw error_1;
|
|
104
|
-
case
|
|
95
|
+
case 4: return [2 /*return*/];
|
|
105
96
|
}
|
|
106
97
|
});
|
|
107
98
|
});
|
|
108
99
|
};
|
|
100
|
+
// Methods from Interface
|
|
109
101
|
RpcProvider.prototype.getChainId = function () {
|
|
110
102
|
return __awaiter(this, void 0, void 0, function () {
|
|
111
103
|
return __generator(this, function (_a) {
|
|
@@ -113,7 +105,7 @@ var RpcProvider = /** @class */ (function () {
|
|
|
113
105
|
});
|
|
114
106
|
});
|
|
115
107
|
};
|
|
116
|
-
//
|
|
108
|
+
// Methods from Interface
|
|
117
109
|
RpcProvider.prototype.getBlock = function (blockIdentifier) {
|
|
118
110
|
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
119
111
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -122,51 +114,97 @@ var RpcProvider = /** @class */ (function () {
|
|
|
122
114
|
});
|
|
123
115
|
});
|
|
124
116
|
};
|
|
117
|
+
RpcProvider.prototype.getBlockHashAndNumber = function () {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
119
|
+
return __generator(this, function (_a) {
|
|
120
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_blockHashAndNumber')];
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
};
|
|
125
124
|
RpcProvider.prototype.getBlockWithTxHashes = function (blockIdentifier) {
|
|
126
125
|
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
127
126
|
return __awaiter(this, void 0, void 0, function () {
|
|
128
|
-
var
|
|
127
|
+
var block_id;
|
|
129
128
|
return __generator(this, function (_a) {
|
|
130
|
-
|
|
131
|
-
return [2 /*return*/, this.fetchEndpoint('starknet_getBlockWithTxHashes',
|
|
132
|
-
blockIdentifierGetter.getIdentifier(),
|
|
133
|
-
])];
|
|
129
|
+
block_id = new utils_1.Block(blockIdentifier).identifier;
|
|
130
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getBlockWithTxHashes', { block_id: block_id })];
|
|
134
131
|
});
|
|
135
132
|
});
|
|
136
133
|
};
|
|
137
134
|
RpcProvider.prototype.getBlockWithTxs = function (blockIdentifier) {
|
|
138
135
|
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
139
136
|
return __awaiter(this, void 0, void 0, function () {
|
|
140
|
-
var
|
|
137
|
+
var block_id;
|
|
138
|
+
return __generator(this, function (_a) {
|
|
139
|
+
block_id = new utils_1.Block(blockIdentifier).identifier;
|
|
140
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getBlockWithTxs', { block_id: block_id })];
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
RpcProvider.prototype.getClassHashAt = function (blockIdentifier, contractAddress) {
|
|
145
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
146
|
+
var block_id;
|
|
147
|
+
return __generator(this, function (_a) {
|
|
148
|
+
block_id = new utils_1.Block(blockIdentifier).identifier;
|
|
149
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getClassHashAt', {
|
|
150
|
+
block_id: block_id,
|
|
151
|
+
contract_address: contractAddress,
|
|
152
|
+
})];
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
RpcProvider.prototype.getNonce = function (contractAddress, blockIdentifier) {
|
|
157
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
158
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
159
|
+
var block_id;
|
|
160
|
+
return __generator(this, function (_a) {
|
|
161
|
+
block_id = new utils_1.Block(blockIdentifier).identifier;
|
|
162
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getNonce', {
|
|
163
|
+
contract_address: contractAddress,
|
|
164
|
+
block_id: block_id,
|
|
165
|
+
})];
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
};
|
|
169
|
+
RpcProvider.prototype.getPendingTransactions = function () {
|
|
170
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
171
|
+
return __generator(this, function (_a) {
|
|
172
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_pendingTransactions')];
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
RpcProvider.prototype.getProtocolVersion = function () {
|
|
177
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
141
178
|
return __generator(this, function (_a) {
|
|
142
|
-
|
|
143
|
-
return [2 /*return*/, this.fetchEndpoint('starknet_getBlockWithTxs', [blockIdentifierGetter.getIdentifier()])];
|
|
179
|
+
throw new Error('Pathfinder does not implement this rpc 0.1.0 method');
|
|
144
180
|
});
|
|
145
181
|
});
|
|
146
182
|
};
|
|
147
|
-
RpcProvider.prototype.
|
|
183
|
+
RpcProvider.prototype.getStateUpdate = function (blockIdentifier) {
|
|
148
184
|
return __awaiter(this, void 0, void 0, function () {
|
|
185
|
+
var block_id;
|
|
149
186
|
return __generator(this, function (_a) {
|
|
150
|
-
|
|
187
|
+
block_id = new utils_1.Block(blockIdentifier).identifier;
|
|
188
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getStateUpdate', { block_id: block_id })];
|
|
151
189
|
});
|
|
152
190
|
});
|
|
153
191
|
};
|
|
154
192
|
RpcProvider.prototype.getStorageAt = function (contractAddress, key, blockIdentifier) {
|
|
155
193
|
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
156
194
|
return __awaiter(this, void 0, void 0, function () {
|
|
157
|
-
var parsedKey,
|
|
195
|
+
var parsedKey, block_id;
|
|
158
196
|
return __generator(this, function (_a) {
|
|
159
197
|
parsedKey = (0, number_1.toHex)((0, number_1.toBN)(key));
|
|
160
|
-
|
|
161
|
-
return [2 /*return*/, this.fetchEndpoint('starknet_getStorageAt',
|
|
162
|
-
contractAddress,
|
|
163
|
-
parsedKey,
|
|
164
|
-
|
|
165
|
-
|
|
198
|
+
block_id = new utils_1.Block(blockIdentifier).identifier;
|
|
199
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getStorageAt', {
|
|
200
|
+
contract_address: contractAddress,
|
|
201
|
+
key: parsedKey,
|
|
202
|
+
block_id: block_id,
|
|
203
|
+
})];
|
|
166
204
|
});
|
|
167
205
|
});
|
|
168
206
|
};
|
|
169
|
-
//
|
|
207
|
+
// Methods from Interface
|
|
170
208
|
RpcProvider.prototype.getTransaction = function (txHash) {
|
|
171
209
|
return __awaiter(this, void 0, void 0, function () {
|
|
172
210
|
return __generator(this, function (_a) {
|
|
@@ -177,51 +215,68 @@ var RpcProvider = /** @class */ (function () {
|
|
|
177
215
|
RpcProvider.prototype.getTransactionByHash = function (txHash) {
|
|
178
216
|
return __awaiter(this, void 0, void 0, function () {
|
|
179
217
|
return __generator(this, function (_a) {
|
|
180
|
-
return [2 /*return*/, this.fetchEndpoint('starknet_getTransactionByHash',
|
|
218
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getTransactionByHash', { transaction_hash: txHash })];
|
|
181
219
|
});
|
|
182
220
|
});
|
|
183
221
|
};
|
|
184
222
|
RpcProvider.prototype.getTransactionByBlockIdAndIndex = function (blockIdentifier, index) {
|
|
185
223
|
return __awaiter(this, void 0, void 0, function () {
|
|
224
|
+
var block_id;
|
|
186
225
|
return __generator(this, function (_a) {
|
|
187
|
-
|
|
226
|
+
block_id = new utils_1.Block(blockIdentifier).identifier;
|
|
227
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getTransactionByBlockIdAndIndex', { block_id: block_id, index: index })];
|
|
188
228
|
});
|
|
189
229
|
});
|
|
190
230
|
};
|
|
191
231
|
RpcProvider.prototype.getTransactionReceipt = function (txHash) {
|
|
192
232
|
return __awaiter(this, void 0, void 0, function () {
|
|
193
233
|
return __generator(this, function (_a) {
|
|
194
|
-
return [2 /*return*/, this.fetchEndpoint('starknet_getTransactionReceipt',
|
|
234
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getTransactionReceipt', { transaction_hash: txHash }).then(this.responseParser.parseGetTransactionReceiptResponse)];
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
};
|
|
238
|
+
RpcProvider.prototype.getClass = function (classHash) {
|
|
239
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
240
|
+
return __generator(this, function (_a) {
|
|
241
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getClass', { class_hash: classHash })];
|
|
195
242
|
});
|
|
196
243
|
});
|
|
197
244
|
};
|
|
198
245
|
RpcProvider.prototype.getClassAt = function (contractAddress, blockIdentifier) {
|
|
199
246
|
return __awaiter(this, void 0, void 0, function () {
|
|
200
|
-
var
|
|
247
|
+
var block_id;
|
|
201
248
|
return __generator(this, function (_a) {
|
|
202
|
-
|
|
203
|
-
return [2 /*return*/, this.fetchEndpoint('starknet_getClassAt',
|
|
204
|
-
|
|
205
|
-
contractAddress,
|
|
206
|
-
|
|
249
|
+
block_id = new utils_1.Block(blockIdentifier).identifier;
|
|
250
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getClassAt', {
|
|
251
|
+
block_id: block_id,
|
|
252
|
+
contract_address: contractAddress,
|
|
253
|
+
})];
|
|
207
254
|
});
|
|
208
255
|
});
|
|
209
256
|
};
|
|
210
|
-
RpcProvider.prototype.
|
|
257
|
+
RpcProvider.prototype.getCode = function (_contractAddress, _blockIdentifier) {
|
|
258
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
259
|
+
return __generator(this, function (_a) {
|
|
260
|
+
throw new Error('RPC 0.1.0 does not implement getCode function');
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
};
|
|
264
|
+
RpcProvider.prototype.getEstimateFee = function (invocation, invocationDetails, blockIdentifier) {
|
|
211
265
|
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
212
|
-
if (invocationDetails === void 0) { invocationDetails = {}; }
|
|
213
266
|
return __awaiter(this, void 0, void 0, function () {
|
|
267
|
+
var block_id;
|
|
214
268
|
return __generator(this, function (_a) {
|
|
215
|
-
|
|
216
|
-
|
|
269
|
+
block_id = new utils_1.Block(blockIdentifier).identifier;
|
|
270
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_estimateFee', {
|
|
271
|
+
request: {
|
|
217
272
|
contract_address: invocation.contractAddress,
|
|
218
|
-
entry_point_selector: (0, hash_1.getSelectorFromName)(invocation.entrypoint),
|
|
219
273
|
calldata: (0, provider_1.parseCalldata)(invocation.calldata),
|
|
220
274
|
signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(invocation.signature || []),
|
|
221
275
|
version: (0, number_1.toHex)((0, number_1.toBN)((invocationDetails === null || invocationDetails === void 0 ? void 0 : invocationDetails.version) || 0)),
|
|
276
|
+
max_fee: (0, number_1.toHex)((0, number_1.toBN)((invocationDetails === null || invocationDetails === void 0 ? void 0 : invocationDetails.maxFee) || 0)),
|
|
222
277
|
},
|
|
223
|
-
|
|
224
|
-
|
|
278
|
+
block_id: block_id,
|
|
279
|
+
}).then(this.responseParser.parseFeeEstimateResponse)];
|
|
225
280
|
});
|
|
226
281
|
});
|
|
227
282
|
};
|
|
@@ -231,14 +286,14 @@ var RpcProvider = /** @class */ (function () {
|
|
|
231
286
|
var contractDefinition;
|
|
232
287
|
return __generator(this, function (_b) {
|
|
233
288
|
contractDefinition = (0, provider_1.parseContract)(contract);
|
|
234
|
-
return [2 /*return*/, this.fetchEndpoint('starknet_addDeclareTransaction',
|
|
235
|
-
{
|
|
289
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_addDeclareTransaction', {
|
|
290
|
+
contract_class: {
|
|
236
291
|
program: contractDefinition.program,
|
|
237
292
|
entry_points_by_type: contractDefinition.entry_points_by_type,
|
|
238
293
|
abi: contractDefinition.abi, // rpc 2.0
|
|
239
294
|
},
|
|
240
|
-
(0, number_1.toHex)((0, number_1.toBN)(version || 0)),
|
|
241
|
-
|
|
295
|
+
version: (0, number_1.toHex)((0, number_1.toBN)(version || 0)),
|
|
296
|
+
})];
|
|
242
297
|
});
|
|
243
298
|
});
|
|
244
299
|
};
|
|
@@ -248,48 +303,50 @@ var RpcProvider = /** @class */ (function () {
|
|
|
248
303
|
var contractDefinition;
|
|
249
304
|
return __generator(this, function (_b) {
|
|
250
305
|
contractDefinition = (0, provider_1.parseContract)(contract);
|
|
251
|
-
return [2 /*return*/, this.fetchEndpoint('starknet_addDeployTransaction',
|
|
252
|
-
addressSalt !== null && addressSalt !== void 0 ? addressSalt : (0, stark_1.randomAddress)(),
|
|
253
|
-
(0, number_1.bigNumberishArrayToHexadecimalStringArray)(constructorCalldata !== null && constructorCalldata !== void 0 ? constructorCalldata : []),
|
|
254
|
-
{
|
|
306
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_addDeployTransaction', {
|
|
307
|
+
contract_address_salt: addressSalt !== null && addressSalt !== void 0 ? addressSalt : (0, stark_1.randomAddress)(),
|
|
308
|
+
constructor_calldata: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(constructorCalldata !== null && constructorCalldata !== void 0 ? constructorCalldata : []),
|
|
309
|
+
contract_definition: {
|
|
255
310
|
program: contractDefinition.program,
|
|
256
311
|
entry_points_by_type: contractDefinition.entry_points_by_type,
|
|
257
312
|
abi: contractDefinition.abi, // rpc 2.0
|
|
258
313
|
},
|
|
259
|
-
|
|
314
|
+
})];
|
|
260
315
|
});
|
|
261
316
|
});
|
|
262
317
|
};
|
|
263
318
|
RpcProvider.prototype.invokeFunction = function (functionInvocation, details) {
|
|
264
319
|
return __awaiter(this, void 0, void 0, function () {
|
|
265
320
|
return __generator(this, function (_a) {
|
|
266
|
-
return [2 /*return*/, this.fetchEndpoint('starknet_addInvokeTransaction',
|
|
267
|
-
{
|
|
321
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_addInvokeTransaction', {
|
|
322
|
+
function_invocation: {
|
|
268
323
|
contract_address: functionInvocation.contractAddress,
|
|
269
|
-
entry_point_selector: (0, hash_1.getSelectorFromName)(functionInvocation.entrypoint),
|
|
270
324
|
calldata: (0, provider_1.parseCalldata)(functionInvocation.calldata),
|
|
271
325
|
},
|
|
272
|
-
(0, number_1.bigNumberishArrayToHexadecimalStringArray)(functionInvocation.signature || []),
|
|
273
|
-
(0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
|
|
274
|
-
(0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
|
|
275
|
-
|
|
326
|
+
signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(functionInvocation.signature || []),
|
|
327
|
+
max_fee: (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
|
|
328
|
+
version: (0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
|
|
329
|
+
})];
|
|
276
330
|
});
|
|
277
331
|
});
|
|
278
332
|
};
|
|
333
|
+
// Methods from Interface
|
|
279
334
|
RpcProvider.prototype.callContract = function (call, blockIdentifier) {
|
|
280
335
|
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
281
336
|
return __awaiter(this, void 0, void 0, function () {
|
|
282
|
-
var result;
|
|
337
|
+
var block_id, result;
|
|
283
338
|
return __generator(this, function (_a) {
|
|
284
339
|
switch (_a.label) {
|
|
285
|
-
case 0:
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
340
|
+
case 0:
|
|
341
|
+
block_id = new utils_1.Block(blockIdentifier).identifier;
|
|
342
|
+
return [4 /*yield*/, this.fetchEndpoint('starknet_call', {
|
|
343
|
+
request: {
|
|
344
|
+
contract_address: call.contractAddress,
|
|
345
|
+
entry_point_selector: (0, hash_1.getSelectorFromName)(call.entrypoint),
|
|
346
|
+
calldata: (0, provider_1.parseCalldata)(call.calldata),
|
|
347
|
+
},
|
|
348
|
+
block_id: block_id,
|
|
349
|
+
})];
|
|
293
350
|
case 1:
|
|
294
351
|
result = _a.sent();
|
|
295
352
|
return [2 /*return*/, this.responseParser.parseCallContractResponse(result)];
|
|
@@ -297,22 +354,29 @@ var RpcProvider = /** @class */ (function () {
|
|
|
297
354
|
});
|
|
298
355
|
});
|
|
299
356
|
};
|
|
300
|
-
RpcProvider.prototype.
|
|
357
|
+
RpcProvider.prototype.traceTransaction = function (transactionHash) {
|
|
301
358
|
return __awaiter(this, void 0, void 0, function () {
|
|
302
359
|
return __generator(this, function (_a) {
|
|
303
|
-
|
|
360
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_traceTransaction', { transaction_hash: transactionHash })];
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
};
|
|
364
|
+
RpcProvider.prototype.traceBlockTransactions = function (blockHash) {
|
|
365
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
366
|
+
return __generator(this, function (_a) {
|
|
367
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_traceBlockTransactions', { block_hash: blockHash })];
|
|
304
368
|
});
|
|
305
369
|
});
|
|
306
370
|
};
|
|
307
371
|
RpcProvider.prototype.waitForTransaction = function (txHash, retryInterval) {
|
|
308
372
|
if (retryInterval === void 0) { retryInterval = 8000; }
|
|
309
373
|
return __awaiter(this, void 0, void 0, function () {
|
|
310
|
-
var
|
|
374
|
+
var retries, onchain, successStates, errorStates, res, message, error, error_2;
|
|
311
375
|
return __generator(this, function (_a) {
|
|
312
376
|
switch (_a.label) {
|
|
313
377
|
case 0:
|
|
378
|
+
retries = this.retries;
|
|
314
379
|
onchain = false;
|
|
315
|
-
retries = 100;
|
|
316
380
|
_a.label = 1;
|
|
317
381
|
case 1:
|
|
318
382
|
if (!!onchain) return [3 /*break*/, 7];
|
|
@@ -345,7 +409,7 @@ var RpcProvider = /** @class */ (function () {
|
|
|
345
409
|
throw error_2;
|
|
346
410
|
}
|
|
347
411
|
if (retries === 0) {
|
|
348
|
-
throw
|
|
412
|
+
throw new Error('waitForTransaction timedout with retries');
|
|
349
413
|
}
|
|
350
414
|
return [3 /*break*/, 6];
|
|
351
415
|
case 6:
|
|
@@ -368,12 +432,10 @@ var RpcProvider = /** @class */ (function () {
|
|
|
368
432
|
*/
|
|
369
433
|
RpcProvider.prototype.getTransactionCount = function (blockIdentifier) {
|
|
370
434
|
return __awaiter(this, void 0, void 0, function () {
|
|
371
|
-
var
|
|
435
|
+
var block_id;
|
|
372
436
|
return __generator(this, function (_a) {
|
|
373
|
-
|
|
374
|
-
return [2 /*return*/, this.fetchEndpoint('starknet_getBlockTransactionCount',
|
|
375
|
-
blockIdentifierGetter.getIdentifier(),
|
|
376
|
-
])];
|
|
437
|
+
block_id = new utils_1.Block(blockIdentifier).identifier;
|
|
438
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getBlockTransactionCount', { block_id: block_id })];
|
|
377
439
|
});
|
|
378
440
|
});
|
|
379
441
|
};
|
|
@@ -412,7 +474,7 @@ var RpcProvider = /** @class */ (function () {
|
|
|
412
474
|
RpcProvider.prototype.getEvents = function (eventFilter) {
|
|
413
475
|
return __awaiter(this, void 0, void 0, function () {
|
|
414
476
|
return __generator(this, function (_a) {
|
|
415
|
-
return [2 /*return*/, this.fetchEndpoint('starknet_getEvents',
|
|
477
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getEvents', { filter: eventFilter })];
|
|
416
478
|
});
|
|
417
479
|
});
|
|
418
480
|
};
|
package/provider/sequencer.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StarknetChainId } from '../constants';
|
|
2
|
-
import { Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation,
|
|
2
|
+
import { Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetailsWithNonce, InvokeFunctionResponse } from '../types';
|
|
3
3
|
import { GetContractAddressesResponse, GetTransactionStatusResponse, GetTransactionTraceResponse, Sequencer } from '../types/api';
|
|
4
4
|
import { BigNumberish } from '../utils/number';
|
|
5
5
|
import { ProviderInterface } from './interface';
|
|
@@ -30,14 +30,15 @@ export declare class SequencerProvider implements ProviderInterface {
|
|
|
30
30
|
getChainId(): Promise<StarknetChainId>;
|
|
31
31
|
callContract({ contractAddress, entrypoint: entryPointSelector, calldata }: Call, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
|
|
32
32
|
getBlock(blockIdentifier?: BlockIdentifier): Promise<GetBlockResponse>;
|
|
33
|
+
getNonce(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
|
|
33
34
|
getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
|
|
34
35
|
getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
|
|
35
36
|
getTransactionReceipt(txHash: BigNumberish): Promise<GetTransactionReceiptResponse>;
|
|
36
37
|
getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<ContractClass>;
|
|
37
|
-
invokeFunction(functionInvocation: Invocation, details:
|
|
38
|
+
invokeFunction(functionInvocation: Invocation, details: InvocationsDetailsWithNonce): Promise<InvokeFunctionResponse>;
|
|
38
39
|
deployContract({ contract, constructorCalldata, addressSalt, }: DeployContractPayload): Promise<DeployContractResponse>;
|
|
39
40
|
declareContract({ contract, }: DeclareContractPayload): Promise<DeclareContractResponse>;
|
|
40
|
-
getEstimateFee(invocation: Invocation,
|
|
41
|
+
getEstimateFee(invocation: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
|
|
41
42
|
getCode(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<Sequencer.GetCodeResponse>;
|
|
42
43
|
waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
43
44
|
/**
|
package/provider/sequencer.js
CHANGED
|
@@ -134,7 +134,8 @@ var SequencerProvider = /** @class */ (function () {
|
|
|
134
134
|
.map(function (_a) {
|
|
135
135
|
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
136
136
|
if (key === 'blockIdentifier') {
|
|
137
|
-
|
|
137
|
+
var block = new utils_1.Block(value);
|
|
138
|
+
return "".concat(block.queryIdentifier);
|
|
138
139
|
}
|
|
139
140
|
return "".concat(key, "=").concat(value);
|
|
140
141
|
})
|
|
@@ -256,6 +257,14 @@ var SequencerProvider = /** @class */ (function () {
|
|
|
256
257
|
});
|
|
257
258
|
});
|
|
258
259
|
};
|
|
260
|
+
SequencerProvider.prototype.getNonce = function (contractAddress, blockIdentifier) {
|
|
261
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
262
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
263
|
+
return __generator(this, function (_a) {
|
|
264
|
+
return [2 /*return*/, this.fetchEndpoint('get_nonce', { contractAddress: contractAddress, blockIdentifier: blockIdentifier })];
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
};
|
|
259
268
|
SequencerProvider.prototype.getStorageAt = function (contractAddress, key, blockIdentifier) {
|
|
260
269
|
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
261
270
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -306,11 +315,11 @@ var SequencerProvider = /** @class */ (function () {
|
|
|
306
315
|
return [2 /*return*/, this.fetchEndpoint('add_transaction', undefined, {
|
|
307
316
|
type: 'INVOKE_FUNCTION',
|
|
308
317
|
contract_address: functionInvocation.contractAddress,
|
|
309
|
-
entry_point_selector: (0, hash_1.getSelectorFromName)(functionInvocation.entrypoint),
|
|
310
318
|
calldata: (0, number_1.bigNumberishArrayToDecimalStringArray)((_a = functionInvocation.calldata) !== null && _a !== void 0 ? _a : []),
|
|
311
319
|
signature: (0, number_1.bigNumberishArrayToDecimalStringArray)((_b = functionInvocation.signature) !== null && _b !== void 0 ? _b : []),
|
|
320
|
+
nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
|
|
312
321
|
max_fee: (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
|
|
313
|
-
version: (0, number_1.toHex)((0, number_1.toBN)(details.version ||
|
|
322
|
+
version: (0, number_1.toHex)((0, number_1.toBN)(details.version || 1)),
|
|
314
323
|
}).then(this.responseParser.parseInvokeFunctionResponse)];
|
|
315
324
|
});
|
|
316
325
|
});
|
|
@@ -346,18 +355,18 @@ var SequencerProvider = /** @class */ (function () {
|
|
|
346
355
|
});
|
|
347
356
|
});
|
|
348
357
|
};
|
|
349
|
-
SequencerProvider.prototype.getEstimateFee = function (invocation,
|
|
358
|
+
SequencerProvider.prototype.getEstimateFee = function (invocation, invocationDetails, blockIdentifier) {
|
|
350
359
|
var _a;
|
|
351
360
|
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
352
|
-
if (invocationDetails === void 0) { invocationDetails = {}; }
|
|
353
361
|
return __awaiter(this, void 0, void 0, function () {
|
|
354
362
|
return __generator(this, function (_b) {
|
|
355
363
|
return [2 /*return*/, this.fetchEndpoint('estimate_fee', { blockIdentifier: blockIdentifier }, {
|
|
364
|
+
type: 'INVOKE_FUNCTION',
|
|
356
365
|
contract_address: invocation.contractAddress,
|
|
357
|
-
entry_point_selector: (0, hash_1.getSelectorFromName)(invocation.entrypoint),
|
|
358
366
|
calldata: (_a = invocation.calldata) !== null && _a !== void 0 ? _a : [],
|
|
359
367
|
signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(invocation.signature || []),
|
|
360
|
-
version: (0, number_1.toHex)((0, number_1.toBN)((invocationDetails === null || invocationDetails === void 0 ? void 0 : invocationDetails.version) ||
|
|
368
|
+
version: (0, number_1.toHex)((0, number_1.toBN)((invocationDetails === null || invocationDetails === void 0 ? void 0 : invocationDetails.version) || 1)),
|
|
369
|
+
nonce: (0, number_1.toHex)((0, number_1.toBN)(invocationDetails.nonce)),
|
|
361
370
|
}).then(this.responseParser.parseFeeEstimateResponse)];
|
|
362
371
|
});
|
|
363
372
|
});
|
package/provider/utils.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="bn.js" />
|
|
2
1
|
import type { BlockNumber } from '../types';
|
|
3
2
|
import { BigNumberish } from '../utils/number';
|
|
4
3
|
/**
|
|
@@ -17,38 +16,15 @@ export declare function formatHash(hashValue: BigNumberish): string;
|
|
|
17
16
|
*/
|
|
18
17
|
export declare function txIdentifier(txHash?: BigNumberish, txId?: BigNumberish): string;
|
|
19
18
|
export declare type BlockIdentifier = BlockNumber | BigNumberish;
|
|
20
|
-
declare
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
block_hash: string;
|
|
32
|
-
block_number?: undefined;
|
|
33
|
-
} | {
|
|
34
|
-
block_number: number;
|
|
35
|
-
block_hash?: undefined;
|
|
36
|
-
} | null;
|
|
19
|
+
export declare class Block {
|
|
20
|
+
hash: BlockIdentifier;
|
|
21
|
+
number: BlockIdentifier;
|
|
22
|
+
tag: BlockIdentifier;
|
|
23
|
+
private setIdentifier;
|
|
24
|
+
constructor(_identifier: BlockIdentifier);
|
|
25
|
+
get queryIdentifier(): any;
|
|
26
|
+
get identifier(): any;
|
|
27
|
+
set identifier(_identifier: BlockIdentifier);
|
|
28
|
+
valueOf: () => BlockIdentifier;
|
|
29
|
+
toString: () => BlockIdentifier;
|
|
37
30
|
}
|
|
38
|
-
/**
|
|
39
|
-
* Identifies the block to be queried.
|
|
40
|
-
*
|
|
41
|
-
* @param blockIdentifier - block identifier
|
|
42
|
-
* @returns block identifier object
|
|
43
|
-
*/
|
|
44
|
-
export declare function getBlockIdentifier(blockIdentifier: BlockIdentifier): BlockIdentifierObject;
|
|
45
|
-
/**
|
|
46
|
-
* Gets the block identifier for API request
|
|
47
|
-
*
|
|
48
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L164-L173)
|
|
49
|
-
*
|
|
50
|
-
* @param blockIdentifier
|
|
51
|
-
* @returns block identifier for API request
|
|
52
|
-
*/
|
|
53
|
-
export declare function getFormattedBlockIdentifier(blockIdentifier?: BlockIdentifier): string;
|
|
54
|
-
export {};
|