starknet 2.7.1 → 3.0.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/.eslintrc +3 -1
- package/CHANGELOG.md +47 -0
- package/CONTRIBUTING.md +1 -1
- package/README.md +18 -16
- package/__mocks__/typedDataExample.json +35 -0
- package/__tests__/account.test.ts +52 -87
- package/__tests__/accountContract.test.ts +160 -0
- package/__tests__/contract.test.ts +3 -1
- package/__tests__/jest.setup.ts +9 -0
- package/__tests__/provider.test.ts +16 -33
- package/__tests__/utils/address.test.ts +16 -0
- package/__tests__/utils/typedData.test.ts +1 -36
- package/account/default.d.ts +66 -0
- package/account/default.js +440 -0
- package/account/index.d.ts +2 -0
- package/account/index.js +27 -0
- package/account/interface.d.ts +83 -0
- package/account/interface.js +37 -0
- package/constants.d.ts +2 -0
- package/constants.js +4 -0
- package/contract.d.ts +6 -6
- package/contract.js +16 -14
- package/dist/account/default.d.ts +55 -0
- package/dist/account/default.js +272 -0
- package/dist/account/index.d.ts +2 -0
- package/dist/account/index.js +14 -0
- package/dist/account/interface.d.ts +69 -0
- package/dist/account/interface.js +27 -0
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +3 -1
- package/dist/contract.d.ts +6 -6
- package/dist/contract.js +9 -12
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/provider/default.d.ts +27 -16
- package/dist/provider/default.js +157 -100
- package/dist/provider/interface.d.ts +29 -32
- package/dist/provider/utils.d.ts +21 -5
- package/dist/provider/utils.js +53 -10
- package/dist/signer/default.d.ts +7 -31
- package/dist/signer/default.js +25 -121
- package/dist/signer/index.d.ts +1 -1
- package/dist/signer/index.js +1 -1
- package/dist/signer/interface.d.ts +17 -18
- package/dist/signer/interface.js +2 -20
- package/dist/{types.d.ts → types/api.d.ts} +72 -41
- package/dist/{types.js → types/api.js} +0 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +15 -0
- package/dist/types/lib.d.ts +57 -0
- package/dist/types/lib.js +2 -0
- package/dist/types/signer.d.ts +4 -0
- package/dist/types/signer.js +2 -0
- package/dist/utils/address.d.ts +2 -0
- package/dist/utils/address.js +22 -0
- package/dist/utils/number.d.ts +1 -0
- package/dist/utils/number.js +5 -1
- package/index.d.ts +2 -1
- package/index.js +2 -1
- package/package.json +8 -2
- package/provider/default.d.ts +45 -36
- package/provider/default.js +216 -201
- package/provider/interface.d.ts +36 -49
- package/provider/utils.d.ts +23 -8
- package/provider/utils.js +57 -11
- package/signer/default.d.ts +11 -31
- package/signer/default.js +52 -169
- package/signer/index.d.ts +1 -1
- package/signer/index.js +1 -1
- package/signer/interface.d.ts +21 -18
- package/signer/interface.js +3 -32
- package/src/account/default.ts +152 -0
- package/src/account/index.ts +2 -0
- package/src/account/interface.ts +91 -0
- package/src/constants.ts +2 -0
- package/src/contract.ts +17 -18
- package/src/index.ts +2 -1
- package/src/provider/default.ts +141 -110
- package/src/provider/interface.ts +36 -52
- package/src/provider/utils.ts +60 -13
- package/src/signer/default.ts +33 -76
- package/src/signer/index.ts +1 -1
- package/src/signer/interface.ts +21 -20
- package/src/types/api.ts +165 -0
- package/src/types/index.ts +3 -0
- package/src/types/lib.ts +73 -0
- package/src/types/signer.ts +5 -0
- package/src/utils/address.ts +23 -0
- package/src/utils/number.ts +4 -0
- package/types/api.d.ts +152 -0
- package/{types.js → types/api.js} +0 -0
- package/types/index.d.ts +3 -0
- package/types/index.js +28 -0
- package/types/lib.d.ts +64 -0
- package/types/lib.js +2 -0
- package/types/signer.d.ts +4 -0
- package/types/signer.js +2 -0
- package/utils/address.d.ts +2 -0
- package/utils/address.js +22 -0
- package/utils/number.d.ts +3 -0
- package/utils/number.js +8 -1
- package/__tests__/signer.test.ts +0 -119
- package/src/types.ts +0 -131
- package/types.d.ts +0 -116
package/provider/default.js
CHANGED
|
@@ -144,6 +144,28 @@ var __generator =
|
|
|
144
144
|
return { value: op[0] ? op[1] : void 0, done: true };
|
|
145
145
|
}
|
|
146
146
|
};
|
|
147
|
+
var __read =
|
|
148
|
+
(this && this.__read) ||
|
|
149
|
+
function (o, n) {
|
|
150
|
+
var m = typeof Symbol === 'function' && o[Symbol.iterator];
|
|
151
|
+
if (!m) return o;
|
|
152
|
+
var i = m.call(o),
|
|
153
|
+
r,
|
|
154
|
+
ar = [],
|
|
155
|
+
e;
|
|
156
|
+
try {
|
|
157
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
158
|
+
} catch (error) {
|
|
159
|
+
e = { error: error };
|
|
160
|
+
} finally {
|
|
161
|
+
try {
|
|
162
|
+
if (r && !r.done && (m = i['return'])) m.call(i);
|
|
163
|
+
} finally {
|
|
164
|
+
if (e) throw e.error;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return ar;
|
|
168
|
+
};
|
|
147
169
|
var __importDefault =
|
|
148
170
|
(this && this.__importDefault) ||
|
|
149
171
|
function (mod) {
|
|
@@ -162,6 +184,19 @@ function wait(delay) {
|
|
|
162
184
|
return setTimeout(res, delay);
|
|
163
185
|
});
|
|
164
186
|
}
|
|
187
|
+
function isEmptyQueryObject(obj) {
|
|
188
|
+
return (
|
|
189
|
+
obj === undefined ||
|
|
190
|
+
Object.keys(obj).length === 0 ||
|
|
191
|
+
(Object.keys(obj).length === 1 &&
|
|
192
|
+
Object.entries(obj).every(function (_a) {
|
|
193
|
+
var _b = __read(_a, 2),
|
|
194
|
+
k = _b[0],
|
|
195
|
+
v = _b[1];
|
|
196
|
+
return k === 'blockIdentifier' && v === null;
|
|
197
|
+
}))
|
|
198
|
+
);
|
|
199
|
+
}
|
|
165
200
|
var Provider = /** @class */ (function () {
|
|
166
201
|
function Provider(optionsOrProvider) {
|
|
167
202
|
if (optionsOrProvider === void 0) {
|
|
@@ -190,6 +225,83 @@ var Provider = /** @class */ (function () {
|
|
|
190
225
|
return 'https://alpha4.starknet.io';
|
|
191
226
|
}
|
|
192
227
|
};
|
|
228
|
+
Provider.prototype.getFetchUrl = function (endpoint) {
|
|
229
|
+
var gatewayUrlEndpoints = ['add_transaction'];
|
|
230
|
+
return gatewayUrlEndpoints.includes(endpoint) ? this.gatewayUrl : this.feederGatewayUrl;
|
|
231
|
+
};
|
|
232
|
+
Provider.prototype.getFetchMethod = function (endpoint) {
|
|
233
|
+
var postMethodEndpoints = ['add_transaction', 'call_contract'];
|
|
234
|
+
return postMethodEndpoints.includes(endpoint) ? 'POST' : 'GET';
|
|
235
|
+
};
|
|
236
|
+
Provider.prototype.getQueryString = function (query) {
|
|
237
|
+
if (isEmptyQueryObject(query)) {
|
|
238
|
+
return '';
|
|
239
|
+
}
|
|
240
|
+
var queryString = Object.entries(query)
|
|
241
|
+
.map(function (_a) {
|
|
242
|
+
var _b = __read(_a, 2),
|
|
243
|
+
key = _b[0],
|
|
244
|
+
value = _b[1];
|
|
245
|
+
if (key === 'blockIdentifier') {
|
|
246
|
+
return '' + (0, utils_1.getFormattedBlockIdentifier)(value);
|
|
247
|
+
}
|
|
248
|
+
return key + '=' + value;
|
|
249
|
+
})
|
|
250
|
+
.join('&');
|
|
251
|
+
return '?' + queryString;
|
|
252
|
+
};
|
|
253
|
+
Provider.prototype.getHeaders = function (method) {
|
|
254
|
+
if (method === 'POST') {
|
|
255
|
+
return {
|
|
256
|
+
'Content-Type': 'application/json',
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
return undefined;
|
|
260
|
+
};
|
|
261
|
+
// typesafe fetch
|
|
262
|
+
Provider.prototype.fetchEndpoint = function (endpoint) {
|
|
263
|
+
// typescript type magiuc to create a nice fitting function interface
|
|
264
|
+
var _a = []; // when both query and request are needed, we cant omit anything
|
|
265
|
+
for (
|
|
266
|
+
// typescript type magiuc to create a nice fitting function interface
|
|
267
|
+
var _i = 1; // when both query and request are needed, we cant omit anything
|
|
268
|
+
// typescript type magiuc to create a nice fitting function interface
|
|
269
|
+
_i < arguments.length; // when both query and request are needed, we cant omit anything
|
|
270
|
+
// typescript type magiuc to create a nice fitting function interface
|
|
271
|
+
_i++ // when both query and request are needed, we cant omit anything
|
|
272
|
+
) {
|
|
273
|
+
// typescript type magiuc to create a nice fitting function interface
|
|
274
|
+
_a[_i - 1] = arguments[_i]; // when both query and request are needed, we cant omit anything
|
|
275
|
+
}
|
|
276
|
+
// typescript type magiuc to create a nice fitting function interface
|
|
277
|
+
var _b = __read(_a, 2),
|
|
278
|
+
query = _b[0],
|
|
279
|
+
request = _b[1]; // when both query and request are needed, we cant omit anything
|
|
280
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
281
|
+
var baseUrl, method, queryString, headers, data;
|
|
282
|
+
return __generator(this, function (_c) {
|
|
283
|
+
switch (_c.label) {
|
|
284
|
+
case 0:
|
|
285
|
+
baseUrl = this.getFetchUrl(endpoint);
|
|
286
|
+
method = this.getFetchMethod(endpoint);
|
|
287
|
+
queryString = this.getQueryString(query);
|
|
288
|
+
headers = this.getHeaders(method);
|
|
289
|
+
return [
|
|
290
|
+
4 /*yield*/,
|
|
291
|
+
axios_1.default.request({
|
|
292
|
+
method: method,
|
|
293
|
+
url: (0, url_join_1.default)(baseUrl, endpoint, queryString),
|
|
294
|
+
data: (0, json_1.stringify)(request),
|
|
295
|
+
headers: headers,
|
|
296
|
+
}),
|
|
297
|
+
];
|
|
298
|
+
case 1:
|
|
299
|
+
data = _c.sent().data;
|
|
300
|
+
return [2 /*return*/, data];
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
};
|
|
193
305
|
/**
|
|
194
306
|
* Gets the smart contract address on the goerli testnet.
|
|
195
307
|
*
|
|
@@ -198,20 +310,8 @@ var Provider = /** @class */ (function () {
|
|
|
198
310
|
*/
|
|
199
311
|
Provider.prototype.getContractAddresses = function () {
|
|
200
312
|
return __awaiter(this, void 0, void 0, function () {
|
|
201
|
-
var data;
|
|
202
313
|
return __generator(this, function (_a) {
|
|
203
|
-
|
|
204
|
-
case 0:
|
|
205
|
-
return [
|
|
206
|
-
4 /*yield*/,
|
|
207
|
-
axios_1.default.get(
|
|
208
|
-
(0, url_join_1.default)(this.feederGatewayUrl, 'get_contract_addresses')
|
|
209
|
-
),
|
|
210
|
-
];
|
|
211
|
-
case 1:
|
|
212
|
-
data = _a.sent().data;
|
|
213
|
-
return [2 /*return*/, data];
|
|
214
|
-
}
|
|
314
|
+
return [2 /*return*/, this.fetchEndpoint('get_contract_addresses')];
|
|
215
315
|
});
|
|
216
316
|
});
|
|
217
317
|
};
|
|
@@ -225,34 +325,31 @@ var Provider = /** @class */ (function () {
|
|
|
225
325
|
* @param blockNumber
|
|
226
326
|
* @returns the result of the function on the smart contract.
|
|
227
327
|
*/
|
|
228
|
-
Provider.prototype.callContract = function (
|
|
229
|
-
|
|
230
|
-
|
|
328
|
+
Provider.prototype.callContract = function (_a, blockIdentifier) {
|
|
329
|
+
var contractAddress = _a.contractAddress,
|
|
330
|
+
entrypoint = _a.entrypoint,
|
|
331
|
+
_b = _a.calldata,
|
|
332
|
+
calldata = _b === void 0 ? [] : _b;
|
|
333
|
+
if (blockIdentifier === void 0) {
|
|
334
|
+
blockIdentifier = null;
|
|
231
335
|
}
|
|
232
336
|
return __awaiter(this, void 0, void 0, function () {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
__assign({ signature: [], calldata: [] }, invokeTransaction)
|
|
250
|
-
),
|
|
251
|
-
];
|
|
252
|
-
case 1:
|
|
253
|
-
data = _a.sent().data;
|
|
254
|
-
return [2 /*return*/, data];
|
|
255
|
-
}
|
|
337
|
+
return __generator(this, function (_c) {
|
|
338
|
+
return [
|
|
339
|
+
2 /*return*/,
|
|
340
|
+
this.fetchEndpoint(
|
|
341
|
+
'call_contract',
|
|
342
|
+
{
|
|
343
|
+
blockIdentifier: blockIdentifier,
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
signature: [],
|
|
347
|
+
contract_address: contractAddress,
|
|
348
|
+
entry_point_selector: (0, stark_1.getSelectorFromName)(entrypoint),
|
|
349
|
+
calldata: calldata,
|
|
350
|
+
}
|
|
351
|
+
),
|
|
352
|
+
];
|
|
256
353
|
});
|
|
257
354
|
});
|
|
258
355
|
};
|
|
@@ -265,33 +362,16 @@ var Provider = /** @class */ (function () {
|
|
|
265
362
|
* @param blockNumber
|
|
266
363
|
* @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
|
|
267
364
|
*/
|
|
268
|
-
Provider.prototype.getBlock = function (
|
|
269
|
-
if (
|
|
270
|
-
|
|
365
|
+
Provider.prototype.getBlock = function (blockIdentifier) {
|
|
366
|
+
if (blockIdentifier === void 0) {
|
|
367
|
+
blockIdentifier = null;
|
|
271
368
|
}
|
|
272
369
|
return __awaiter(this, void 0, void 0, function () {
|
|
273
|
-
var formattedBlockIdentifier, data;
|
|
274
370
|
return __generator(this, function (_a) {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
blockNumber
|
|
280
|
-
);
|
|
281
|
-
return [
|
|
282
|
-
4 /*yield*/,
|
|
283
|
-
axios_1.default.get(
|
|
284
|
-
(0, url_join_1.default)(
|
|
285
|
-
this.feederGatewayUrl,
|
|
286
|
-
'get_block',
|
|
287
|
-
formattedBlockIdentifier
|
|
288
|
-
)
|
|
289
|
-
),
|
|
290
|
-
];
|
|
291
|
-
case 1:
|
|
292
|
-
data = _a.sent().data;
|
|
293
|
-
return [2 /*return*/, data];
|
|
294
|
-
}
|
|
371
|
+
return [
|
|
372
|
+
2 /*return*/,
|
|
373
|
+
this.fetchEndpoint('get_block', { blockIdentifier: blockIdentifier }),
|
|
374
|
+
];
|
|
295
375
|
});
|
|
296
376
|
});
|
|
297
377
|
};
|
|
@@ -305,33 +385,19 @@ var Provider = /** @class */ (function () {
|
|
|
305
385
|
* @param blockNumber
|
|
306
386
|
* @returns Bytecode and ABI of compiled contract
|
|
307
387
|
*/
|
|
308
|
-
Provider.prototype.getCode = function (contractAddress,
|
|
309
|
-
if (
|
|
310
|
-
|
|
388
|
+
Provider.prototype.getCode = function (contractAddress, blockIdentifier) {
|
|
389
|
+
if (blockIdentifier === void 0) {
|
|
390
|
+
blockIdentifier = null;
|
|
311
391
|
}
|
|
312
392
|
return __awaiter(this, void 0, void 0, function () {
|
|
313
|
-
var formattedBlockIdentifier, data;
|
|
314
393
|
return __generator(this, function (_a) {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
4 /*yield*/,
|
|
323
|
-
axios_1.default.get(
|
|
324
|
-
(0, url_join_1.default)(
|
|
325
|
-
this.feederGatewayUrl,
|
|
326
|
-
'get_code',
|
|
327
|
-
'?contractAddress=' + contractAddress + '&' + formattedBlockIdentifier
|
|
328
|
-
)
|
|
329
|
-
),
|
|
330
|
-
];
|
|
331
|
-
case 1:
|
|
332
|
-
data = _a.sent().data;
|
|
333
|
-
return [2 /*return*/, data];
|
|
334
|
-
}
|
|
394
|
+
return [
|
|
395
|
+
2 /*return*/,
|
|
396
|
+
this.fetchEndpoint('get_code', {
|
|
397
|
+
blockIdentifier: blockIdentifier,
|
|
398
|
+
contractAddress: contractAddress,
|
|
399
|
+
}),
|
|
400
|
+
];
|
|
335
401
|
});
|
|
336
402
|
});
|
|
337
403
|
};
|
|
@@ -347,38 +413,20 @@ var Provider = /** @class */ (function () {
|
|
|
347
413
|
* @param blockNumber
|
|
348
414
|
* @returns the value of the storage variable
|
|
349
415
|
*/
|
|
350
|
-
Provider.prototype.getStorageAt = function (contractAddress, key,
|
|
351
|
-
if (
|
|
352
|
-
|
|
416
|
+
Provider.prototype.getStorageAt = function (contractAddress, key, blockIdentifier) {
|
|
417
|
+
if (blockIdentifier === void 0) {
|
|
418
|
+
blockIdentifier = null;
|
|
353
419
|
}
|
|
354
420
|
return __awaiter(this, void 0, void 0, function () {
|
|
355
|
-
var formattedBlockIdentifier, data;
|
|
356
421
|
return __generator(this, function (_a) {
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
axios_1.default.get(
|
|
366
|
-
(0, url_join_1.default)(
|
|
367
|
-
this.feederGatewayUrl,
|
|
368
|
-
'get_storage_at',
|
|
369
|
-
'?contractAddress=' +
|
|
370
|
-
contractAddress +
|
|
371
|
-
'&key=' +
|
|
372
|
-
key +
|
|
373
|
-
'&' +
|
|
374
|
-
formattedBlockIdentifier
|
|
375
|
-
)
|
|
376
|
-
),
|
|
377
|
-
];
|
|
378
|
-
case 1:
|
|
379
|
-
data = _a.sent().data;
|
|
380
|
-
return [2 /*return*/, data];
|
|
381
|
-
}
|
|
422
|
+
return [
|
|
423
|
+
2 /*return*/,
|
|
424
|
+
this.fetchEndpoint('get_storage_at', {
|
|
425
|
+
blockIdentifier: blockIdentifier,
|
|
426
|
+
contractAddress: contractAddress,
|
|
427
|
+
key: key,
|
|
428
|
+
}),
|
|
429
|
+
];
|
|
382
430
|
});
|
|
383
431
|
});
|
|
384
432
|
};
|
|
@@ -392,100 +440,67 @@ var Provider = /** @class */ (function () {
|
|
|
392
440
|
*/
|
|
393
441
|
Provider.prototype.getTransactionStatus = function (txHash) {
|
|
394
442
|
return __awaiter(this, void 0, void 0, function () {
|
|
395
|
-
var
|
|
443
|
+
var txHashHex;
|
|
396
444
|
return __generator(this, function (_a) {
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
axios_1.default.get(
|
|
403
|
-
(0, url_join_1.default)(
|
|
404
|
-
this.feederGatewayUrl,
|
|
405
|
-
'get_transaction_status',
|
|
406
|
-
'?transactionHash=' + (0, number_1.toHex)(txHashBn)
|
|
407
|
-
)
|
|
408
|
-
),
|
|
409
|
-
];
|
|
410
|
-
case 1:
|
|
411
|
-
data = _a.sent().data;
|
|
412
|
-
return [2 /*return*/, data];
|
|
413
|
-
}
|
|
445
|
+
txHashHex = (0, number_1.toHex)((0, number_1.toBN)(txHash));
|
|
446
|
+
return [
|
|
447
|
+
2 /*return*/,
|
|
448
|
+
this.fetchEndpoint('get_transaction_status', { transactionHash: txHashHex }),
|
|
449
|
+
];
|
|
414
450
|
});
|
|
415
451
|
});
|
|
416
452
|
};
|
|
417
453
|
/**
|
|
418
|
-
* Gets the transaction
|
|
454
|
+
* Gets the transaction receipt from a tx hash or tx id.
|
|
419
455
|
*
|
|
420
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/
|
|
456
|
+
* [Reference] (https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L104-L111)
|
|
421
457
|
*
|
|
422
458
|
* @param txHash
|
|
423
|
-
* @
|
|
459
|
+
* @param txId
|
|
460
|
+
* @returns the transaction receipt object
|
|
424
461
|
*/
|
|
425
|
-
Provider.prototype.
|
|
462
|
+
Provider.prototype.getTransactionReceipt = function (_a) {
|
|
463
|
+
var txHash = _a.txHash,
|
|
464
|
+
txId = _a.txId;
|
|
426
465
|
return __awaiter(this, void 0, void 0, function () {
|
|
427
|
-
var
|
|
428
|
-
return __generator(this, function (
|
|
429
|
-
switch (
|
|
466
|
+
var data;
|
|
467
|
+
return __generator(this, function (_b) {
|
|
468
|
+
switch (_b.label) {
|
|
430
469
|
case 0:
|
|
431
|
-
txHashBn = (0, number_1.toBN)(txHash);
|
|
432
470
|
return [
|
|
433
471
|
4 /*yield*/,
|
|
434
472
|
axios_1.default.get(
|
|
435
473
|
(0, url_join_1.default)(
|
|
436
474
|
this.feederGatewayUrl,
|
|
437
|
-
'
|
|
438
|
-
'?
|
|
475
|
+
'get_transaction_receipt',
|
|
476
|
+
'?' + (0, utils_1.txIdentifier)(txHash, txId)
|
|
439
477
|
)
|
|
440
478
|
),
|
|
441
479
|
];
|
|
442
480
|
case 1:
|
|
443
|
-
data =
|
|
481
|
+
data = _b.sent().data;
|
|
444
482
|
return [2 /*return*/, data];
|
|
445
483
|
}
|
|
446
484
|
});
|
|
447
485
|
});
|
|
448
486
|
};
|
|
449
487
|
/**
|
|
450
|
-
*
|
|
488
|
+
* Gets the transaction information from a tx id.
|
|
451
489
|
*
|
|
452
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/
|
|
490
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L54-L58)
|
|
453
491
|
*
|
|
454
|
-
* @param
|
|
455
|
-
* @returns
|
|
492
|
+
* @param txHash
|
|
493
|
+
* @returns the transacton object { transaction_id, status, transaction, block_number?, block_number?, transaction_index?, transaction_failure_reason? }
|
|
456
494
|
*/
|
|
457
|
-
Provider.prototype.
|
|
495
|
+
Provider.prototype.getTransaction = function (txHash) {
|
|
458
496
|
return __awaiter(this, void 0, void 0, function () {
|
|
459
|
-
var
|
|
497
|
+
var txHashHex;
|
|
460
498
|
return __generator(this, function (_a) {
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
contract_address_salt =
|
|
467
|
-
transaction.type === 'DEPLOY' &&
|
|
468
|
-
(0, number_1.toHex)((0, number_1.toBN)(transaction.contract_address_salt));
|
|
469
|
-
return [
|
|
470
|
-
4 /*yield*/,
|
|
471
|
-
axios_1.default.post(
|
|
472
|
-
(0, url_join_1.default)(this.gatewayUrl, 'add_transaction'),
|
|
473
|
-
(0, json_1.stringify)(
|
|
474
|
-
__assign(
|
|
475
|
-
__assign(
|
|
476
|
-
__assign({}, transaction),
|
|
477
|
-
Array.isArray(signature) && { signature: signature }
|
|
478
|
-
),
|
|
479
|
-
contract_address_salt && { contract_address_salt: contract_address_salt }
|
|
480
|
-
)
|
|
481
|
-
),
|
|
482
|
-
{ headers: { 'Content-Type': 'application/json' } }
|
|
483
|
-
),
|
|
484
|
-
];
|
|
485
|
-
case 1:
|
|
486
|
-
data = _a.sent().data;
|
|
487
|
-
return [2 /*return*/, data];
|
|
488
|
-
}
|
|
499
|
+
txHashHex = (0, number_1.toHex)((0, number_1.toBN)(txHash));
|
|
500
|
+
return [
|
|
501
|
+
2 /*return*/,
|
|
502
|
+
this.fetchEndpoint('get_transaction', { transactionHash: txHashHex }),
|
|
503
|
+
];
|
|
489
504
|
});
|
|
490
505
|
});
|
|
491
506
|
};
|
|
@@ -496,26 +511,26 @@ var Provider = /** @class */ (function () {
|
|
|
496
511
|
* @param address - (optional, defaults to a random address) the address where the contract should be deployed (alpha)
|
|
497
512
|
* @returns a confirmation of sending a transaction on the starknet contract
|
|
498
513
|
*/
|
|
499
|
-
Provider.prototype.deployContract = function (
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
if (addressSalt === void 0) {
|
|
504
|
-
addressSalt = (0, stark_1.randomAddress)();
|
|
505
|
-
}
|
|
506
|
-
var parsedContract = typeof contract === 'string' ? (0, json_1.parse)(contract) : contract;
|
|
514
|
+
Provider.prototype.deployContract = function (payload, _abi) {
|
|
515
|
+
var _a, _b;
|
|
516
|
+
var parsedContract =
|
|
517
|
+
typeof payload.contract === 'string' ? (0, json_1.parse)(payload.contract) : payload.contract;
|
|
507
518
|
var contractDefinition = __assign(__assign({}, parsedContract), {
|
|
508
519
|
program: (0, stark_1.compressProgram)(parsedContract.program),
|
|
509
520
|
});
|
|
510
|
-
return this.
|
|
521
|
+
return this.fetchEndpoint('add_transaction', undefined, {
|
|
511
522
|
type: 'DEPLOY',
|
|
512
|
-
contract_address_salt:
|
|
513
|
-
|
|
523
|
+
contract_address_salt:
|
|
524
|
+
(_a = payload.addressSalt) !== null && _a !== void 0 ? _a : (0, stark_1.randomAddress)(),
|
|
525
|
+
constructor_calldata: (0, number_1.bigNumberishArrayToDecimalStringArray)(
|
|
526
|
+
(_b = payload.constructorCalldata) !== null && _b !== void 0 ? _b : []
|
|
527
|
+
),
|
|
514
528
|
contract_definition: contractDefinition,
|
|
515
529
|
});
|
|
516
530
|
};
|
|
517
531
|
/**
|
|
518
532
|
* Invokes a function on starknet
|
|
533
|
+
* @deprecated This method wont be supported as soon as fees are mandatory
|
|
519
534
|
*
|
|
520
535
|
* @param contractAddress - target contract address for invoke
|
|
521
536
|
* @param entrypointSelector - target entrypoint selector for
|
|
@@ -523,18 +538,18 @@ var Provider = /** @class */ (function () {
|
|
|
523
538
|
* @param signature - (optional) signature to send along
|
|
524
539
|
* @returns response from addTransaction
|
|
525
540
|
*/
|
|
526
|
-
Provider.prototype.invokeFunction = function (
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
calldata,
|
|
530
|
-
signature
|
|
531
|
-
) {
|
|
532
|
-
return this.addTransaction({
|
|
541
|
+
Provider.prototype.invokeFunction = function (invocation, _abi) {
|
|
542
|
+
var _a, _b;
|
|
543
|
+
return this.fetchEndpoint('add_transaction', undefined, {
|
|
533
544
|
type: 'INVOKE_FUNCTION',
|
|
534
|
-
contract_address: contractAddress,
|
|
535
|
-
entry_point_selector:
|
|
536
|
-
calldata:
|
|
537
|
-
|
|
545
|
+
contract_address: invocation.contractAddress,
|
|
546
|
+
entry_point_selector: (0, stark_1.getSelectorFromName)(invocation.entrypoint),
|
|
547
|
+
calldata: (0, number_1.bigNumberishArrayToDecimalStringArray)(
|
|
548
|
+
(_a = invocation.calldata) !== null && _a !== void 0 ? _a : []
|
|
549
|
+
),
|
|
550
|
+
signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(
|
|
551
|
+
(_b = invocation.signature) !== null && _b !== void 0 ? _b : []
|
|
552
|
+
),
|
|
538
553
|
});
|
|
539
554
|
};
|
|
540
555
|
Provider.prototype.waitForTx = function (txHash, retryInterval) {
|