starknet 2.3.1 → 2.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 +43 -0
- package/__tests__/account.test.ts +3 -3
- package/__tests__/provider.test.ts +24 -13
- package/__tests__/signer.test.ts +17 -0
- package/__tests__/utils/ellipticalCurve.test.ts +1 -1
- package/__tests__/utils/typedData.test.ts +72 -0
- package/contract.d.ts +2 -2
- package/dist/contract.d.ts +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/dist/provider/default.d.ts +26 -22
- package/dist/provider/default.js +64 -47
- package/dist/provider/interface.d.ts +25 -21
- package/dist/provider/utils.d.ts +27 -0
- package/dist/provider/utils.js +37 -0
- package/dist/signer/default.d.ts +20 -3
- package/dist/signer/default.js +61 -20
- package/dist/signer/interface.d.ts +22 -3
- package/dist/types.d.ts +10 -7
- package/dist/utils/ellipticCurve.d.ts +8 -1
- package/dist/utils/ellipticCurve.js +48 -9
- package/dist/utils/stark.d.ts +2 -3
- package/dist/utils/typedData/index.d.ts +91 -0
- package/dist/utils/typedData/index.js +183 -0
- package/dist/utils/typedData/types.d.ts +82 -0
- package/dist/utils/typedData/types.js +47 -0
- package/dist/utils/typedData/utils.d.ts +24 -0
- package/dist/utils/typedData/utils.js +15 -0
- package/index.d.ts +1 -0
- package/index.js +3 -1
- package/package.json +3 -1
- package/provider/default.d.ts +40 -21
- package/provider/default.js +85 -53
- package/provider/interface.d.ts +37 -21
- package/provider/utils.d.ts +30 -0
- package/provider/utils.js +39 -0
- package/signer/default.d.ts +20 -3
- package/signer/default.js +60 -17
- package/signer/interface.d.ts +22 -3
- package/src/contract.ts +2 -2
- package/src/index.ts +1 -0
- package/src/provider/default.ts +65 -40
- package/src/provider/interface.ts +36 -21
- package/src/provider/utils.ts +38 -0
- package/src/signer/default.ts +49 -17
- package/src/signer/interface.ts +26 -3
- package/src/types.ts +16 -7
- package/src/utils/ellipticCurve.ts +31 -9
- package/src/utils/stark.ts +4 -4
- package/src/utils/typedData/index.ts +176 -0
- package/src/utils/typedData/types.ts +82 -0
- package/src/utils/typedData/utils.ts +13 -0
- package/types.d.ts +12 -8
- package/utils/ellipticCurve.d.ts +12 -1
- package/utils/ellipticCurve.js +72 -23
- package/utils/stark.d.ts +2 -3
- package/utils/typedData/index.d.ts +113 -0
- package/utils/typedData/index.js +247 -0
- package/utils/typedData/types.d.ts +103 -0
- package/utils/typedData/types.js +57 -0
- package/utils/typedData/utils.d.ts +27 -0
- package/utils/typedData/utils.js +15 -0
package/provider/default.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AddTransactionResponse,
|
|
3
|
+
BlockNumber,
|
|
3
4
|
CallContractResponse,
|
|
4
5
|
CallContractTransaction,
|
|
5
6
|
CompiledContract,
|
|
@@ -8,11 +9,12 @@ import {
|
|
|
8
9
|
GetContractAddressesResponse,
|
|
9
10
|
GetTransactionResponse,
|
|
10
11
|
GetTransactionStatusResponse,
|
|
12
|
+
Signature,
|
|
11
13
|
Transaction,
|
|
12
14
|
} from '../types';
|
|
13
15
|
import { BigNumberish } from '../utils/number';
|
|
14
16
|
import { ProviderInterface } from './interface';
|
|
15
|
-
declare type NetworkName = 'mainnet-alpha' | '
|
|
17
|
+
declare type NetworkName = 'mainnet-alpha' | 'goerli-alpha';
|
|
16
18
|
declare type ProviderOptions =
|
|
17
19
|
| {
|
|
18
20
|
network: NetworkName;
|
|
@@ -38,50 +40,67 @@ export declare class Provider implements ProviderInterface {
|
|
|
38
40
|
/**
|
|
39
41
|
* Calls a function on the StarkNet contract.
|
|
40
42
|
*
|
|
41
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/
|
|
43
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L25-L39)
|
|
42
44
|
*
|
|
43
|
-
* @param
|
|
44
|
-
* @param
|
|
45
|
+
* @param invokeTransaction - transaction to be invoked
|
|
46
|
+
* @param blockHash
|
|
47
|
+
* @param blockNumber
|
|
45
48
|
* @returns the result of the function on the smart contract.
|
|
46
49
|
*/
|
|
47
|
-
callContract(
|
|
50
|
+
callContract(
|
|
51
|
+
invokeTransaction: CallContractTransaction,
|
|
52
|
+
blockHash?: BigNumberish,
|
|
53
|
+
blockNumber?: BlockNumber
|
|
54
|
+
): Promise<CallContractResponse>;
|
|
48
55
|
/**
|
|
49
|
-
* Gets the block information
|
|
56
|
+
* Gets the block information
|
|
50
57
|
*
|
|
51
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/
|
|
58
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L41-L53)
|
|
52
59
|
*
|
|
53
|
-
* @param
|
|
54
|
-
* @
|
|
60
|
+
* @param blockHash
|
|
61
|
+
* @param blockNumber
|
|
62
|
+
* @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
|
|
55
63
|
*/
|
|
56
|
-
getBlock(
|
|
64
|
+
getBlock(blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<GetBlockResponse>;
|
|
57
65
|
/**
|
|
58
66
|
* Gets the code of the deployed contract.
|
|
59
67
|
*
|
|
60
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/
|
|
68
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L55-L68)
|
|
61
69
|
*
|
|
62
70
|
* @param contractAddress
|
|
63
|
-
* @param
|
|
71
|
+
* @param blockHash
|
|
72
|
+
* @param blockNumber
|
|
64
73
|
* @returns Bytecode and ABI of compiled contract
|
|
65
74
|
*/
|
|
66
|
-
getCode(
|
|
75
|
+
getCode(
|
|
76
|
+
contractAddress: string,
|
|
77
|
+
blockHash?: BigNumberish,
|
|
78
|
+
blockNumber?: BlockNumber
|
|
79
|
+
): Promise<GetCodeResponse>;
|
|
67
80
|
/**
|
|
68
81
|
* Gets the contract's storage variable at a specific key.
|
|
69
82
|
*
|
|
70
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/
|
|
83
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L70-L85)
|
|
71
84
|
*
|
|
72
85
|
* @param contractAddress
|
|
73
86
|
* @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
|
|
74
|
-
* @param
|
|
87
|
+
* @param blockHash
|
|
88
|
+
* @param blockNumber
|
|
75
89
|
* @returns the value of the storage variable
|
|
76
90
|
*/
|
|
77
|
-
getStorageAt(
|
|
91
|
+
getStorageAt(
|
|
92
|
+
contractAddress: string,
|
|
93
|
+
key: number,
|
|
94
|
+
blockHash?: BigNumberish,
|
|
95
|
+
blockNumber?: BlockNumber
|
|
96
|
+
): Promise<object>;
|
|
78
97
|
/**
|
|
79
98
|
* Gets the status of a transaction.
|
|
80
99
|
*
|
|
81
100
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L48-L52)
|
|
82
101
|
*
|
|
83
102
|
* @param txHash
|
|
84
|
-
* @returns the transaction status object {
|
|
103
|
+
* @returns the transaction status object { block_number, tx_status: NOT_RECEIVED | RECEIVED | PENDING | REJECTED | ACCEPTED_ONCHAIN }
|
|
85
104
|
*/
|
|
86
105
|
getTransactionStatus(txHash: BigNumberish): Promise<GetTransactionStatusResponse>;
|
|
87
106
|
/**
|
|
@@ -90,7 +109,7 @@ export declare class Provider implements ProviderInterface {
|
|
|
90
109
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L54-L58)
|
|
91
110
|
*
|
|
92
111
|
* @param txHash
|
|
93
|
-
* @returns the transacton object { transaction_id, status, transaction,
|
|
112
|
+
* @returns the transacton object { transaction_id, status, transaction, block_number?, block_number?, transaction_index?, transaction_failure_reason? }
|
|
94
113
|
*/
|
|
95
114
|
getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
|
|
96
115
|
/**
|
|
@@ -98,10 +117,10 @@ export declare class Provider implements ProviderInterface {
|
|
|
98
117
|
*
|
|
99
118
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
|
|
100
119
|
*
|
|
101
|
-
* @param
|
|
120
|
+
* @param transaction - transaction to be invoked
|
|
102
121
|
* @returns a confirmation of invoking a function on the starknet contract
|
|
103
122
|
*/
|
|
104
|
-
addTransaction(
|
|
123
|
+
addTransaction(transaction: Transaction): Promise<AddTransactionResponse>;
|
|
105
124
|
/**
|
|
106
125
|
* Deploys a given compiled contract (json) to starknet
|
|
107
126
|
*
|
|
@@ -127,7 +146,7 @@ export declare class Provider implements ProviderInterface {
|
|
|
127
146
|
contractAddress: string,
|
|
128
147
|
entrypointSelector: string,
|
|
129
148
|
calldata?: string[],
|
|
130
|
-
signature?:
|
|
149
|
+
signature?: Signature
|
|
131
150
|
): Promise<AddTransactionResponse>;
|
|
132
151
|
waitForTx(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
133
152
|
}
|
package/provider/default.js
CHANGED
|
@@ -156,6 +156,7 @@ var url_join_1 = __importDefault(require('url-join'));
|
|
|
156
156
|
var json_1 = require('../utils/json');
|
|
157
157
|
var number_1 = require('../utils/number');
|
|
158
158
|
var stark_1 = require('../utils/stark');
|
|
159
|
+
var utils_1 = require('./utils');
|
|
159
160
|
function wait(delay) {
|
|
160
161
|
return new Promise(function (res) {
|
|
161
162
|
return setTimeout(res, delay);
|
|
@@ -164,7 +165,7 @@ function wait(delay) {
|
|
|
164
165
|
var Provider = /** @class */ (function () {
|
|
165
166
|
function Provider(optionsOrProvider) {
|
|
166
167
|
if (optionsOrProvider === void 0) {
|
|
167
|
-
optionsOrProvider = { network: '
|
|
168
|
+
optionsOrProvider = { network: 'goerli-alpha' };
|
|
168
169
|
}
|
|
169
170
|
if (optionsOrProvider instanceof Provider) {
|
|
170
171
|
this.baseUrl = optionsOrProvider.baseUrl;
|
|
@@ -184,7 +185,7 @@ var Provider = /** @class */ (function () {
|
|
|
184
185
|
switch (name) {
|
|
185
186
|
case 'mainnet-alpha':
|
|
186
187
|
return 'https://alpha-mainnet.starknet.io';
|
|
187
|
-
case '
|
|
188
|
+
case 'goerli-alpha':
|
|
188
189
|
default:
|
|
189
190
|
return 'https://alpha4.starknet.io';
|
|
190
191
|
}
|
|
@@ -217,27 +218,35 @@ var Provider = /** @class */ (function () {
|
|
|
217
218
|
/**
|
|
218
219
|
* Calls a function on the StarkNet contract.
|
|
219
220
|
*
|
|
220
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/
|
|
221
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L25-L39)
|
|
221
222
|
*
|
|
222
|
-
* @param
|
|
223
|
-
* @param
|
|
223
|
+
* @param invokeTransaction - transaction to be invoked
|
|
224
|
+
* @param blockHash
|
|
225
|
+
* @param blockNumber
|
|
224
226
|
* @returns the result of the function on the smart contract.
|
|
225
227
|
*/
|
|
226
|
-
Provider.prototype.callContract = function (
|
|
228
|
+
Provider.prototype.callContract = function (invokeTransaction, blockHash, blockNumber) {
|
|
229
|
+
if (blockNumber === void 0) {
|
|
230
|
+
blockNumber = null;
|
|
231
|
+
}
|
|
227
232
|
return __awaiter(this, void 0, void 0, function () {
|
|
228
|
-
var data;
|
|
233
|
+
var formattedBlockIdentifier, data;
|
|
229
234
|
return __generator(this, function (_a) {
|
|
230
235
|
switch (_a.label) {
|
|
231
236
|
case 0:
|
|
237
|
+
formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(
|
|
238
|
+
blockHash,
|
|
239
|
+
blockNumber
|
|
240
|
+
);
|
|
232
241
|
return [
|
|
233
242
|
4 /*yield*/,
|
|
234
243
|
axios_1.default.post(
|
|
235
244
|
(0, url_join_1.default)(
|
|
236
245
|
this.feederGatewayUrl,
|
|
237
246
|
'call_contract',
|
|
238
|
-
|
|
247
|
+
formattedBlockIdentifier
|
|
239
248
|
),
|
|
240
|
-
__assign({ signature: [], calldata: [] },
|
|
249
|
+
__assign({ signature: [], calldata: [] }, invokeTransaction)
|
|
241
250
|
),
|
|
242
251
|
];
|
|
243
252
|
case 1:
|
|
@@ -248,26 +257,34 @@ var Provider = /** @class */ (function () {
|
|
|
248
257
|
});
|
|
249
258
|
};
|
|
250
259
|
/**
|
|
251
|
-
* Gets the block information
|
|
260
|
+
* Gets the block information
|
|
252
261
|
*
|
|
253
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/
|
|
262
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L41-L53)
|
|
254
263
|
*
|
|
255
|
-
* @param
|
|
256
|
-
* @
|
|
264
|
+
* @param blockHash
|
|
265
|
+
* @param blockNumber
|
|
266
|
+
* @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
|
|
257
267
|
*/
|
|
258
|
-
Provider.prototype.getBlock = function (
|
|
268
|
+
Provider.prototype.getBlock = function (blockHash, blockNumber) {
|
|
269
|
+
if (blockNumber === void 0) {
|
|
270
|
+
blockNumber = null;
|
|
271
|
+
}
|
|
259
272
|
return __awaiter(this, void 0, void 0, function () {
|
|
260
|
-
var data;
|
|
273
|
+
var formattedBlockIdentifier, data;
|
|
261
274
|
return __generator(this, function (_a) {
|
|
262
275
|
switch (_a.label) {
|
|
263
276
|
case 0:
|
|
277
|
+
formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(
|
|
278
|
+
blockHash,
|
|
279
|
+
blockNumber
|
|
280
|
+
);
|
|
264
281
|
return [
|
|
265
282
|
4 /*yield*/,
|
|
266
283
|
axios_1.default.get(
|
|
267
284
|
(0, url_join_1.default)(
|
|
268
285
|
this.feederGatewayUrl,
|
|
269
286
|
'get_block',
|
|
270
|
-
|
|
287
|
+
formattedBlockIdentifier
|
|
271
288
|
)
|
|
272
289
|
),
|
|
273
290
|
];
|
|
@@ -281,28 +298,33 @@ var Provider = /** @class */ (function () {
|
|
|
281
298
|
/**
|
|
282
299
|
* Gets the code of the deployed contract.
|
|
283
300
|
*
|
|
284
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/
|
|
301
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L55-L68)
|
|
285
302
|
*
|
|
286
303
|
* @param contractAddress
|
|
287
|
-
* @param
|
|
304
|
+
* @param blockHash
|
|
305
|
+
* @param blockNumber
|
|
288
306
|
* @returns Bytecode and ABI of compiled contract
|
|
289
307
|
*/
|
|
290
|
-
Provider.prototype.getCode = function (contractAddress,
|
|
308
|
+
Provider.prototype.getCode = function (contractAddress, blockHash, blockNumber) {
|
|
309
|
+
if (blockNumber === void 0) {
|
|
310
|
+
blockNumber = null;
|
|
311
|
+
}
|
|
291
312
|
return __awaiter(this, void 0, void 0, function () {
|
|
292
|
-
var data;
|
|
313
|
+
var formattedBlockIdentifier, data;
|
|
293
314
|
return __generator(this, function (_a) {
|
|
294
315
|
switch (_a.label) {
|
|
295
316
|
case 0:
|
|
317
|
+
formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(
|
|
318
|
+
blockHash,
|
|
319
|
+
blockNumber
|
|
320
|
+
);
|
|
296
321
|
return [
|
|
297
322
|
4 /*yield*/,
|
|
298
323
|
axios_1.default.get(
|
|
299
324
|
(0, url_join_1.default)(
|
|
300
325
|
this.feederGatewayUrl,
|
|
301
326
|
'get_code',
|
|
302
|
-
'?contractAddress=' +
|
|
303
|
-
contractAddress +
|
|
304
|
-
'&blockId=' +
|
|
305
|
-
(blockId !== null && blockId !== void 0 ? blockId : 'null')
|
|
327
|
+
'?contractAddress=' + contractAddress + '&' + formattedBlockIdentifier
|
|
306
328
|
)
|
|
307
329
|
),
|
|
308
330
|
];
|
|
@@ -317,19 +339,27 @@ var Provider = /** @class */ (function () {
|
|
|
317
339
|
/**
|
|
318
340
|
* Gets the contract's storage variable at a specific key.
|
|
319
341
|
*
|
|
320
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/
|
|
342
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L70-L85)
|
|
321
343
|
*
|
|
322
344
|
* @param contractAddress
|
|
323
345
|
* @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
|
|
324
|
-
* @param
|
|
346
|
+
* @param blockHash
|
|
347
|
+
* @param blockNumber
|
|
325
348
|
* @returns the value of the storage variable
|
|
326
349
|
*/
|
|
327
|
-
Provider.prototype.getStorageAt = function (contractAddress, key,
|
|
350
|
+
Provider.prototype.getStorageAt = function (contractAddress, key, blockHash, blockNumber) {
|
|
351
|
+
if (blockNumber === void 0) {
|
|
352
|
+
blockNumber = null;
|
|
353
|
+
}
|
|
328
354
|
return __awaiter(this, void 0, void 0, function () {
|
|
329
|
-
var data;
|
|
355
|
+
var formattedBlockIdentifier, data;
|
|
330
356
|
return __generator(this, function (_a) {
|
|
331
357
|
switch (_a.label) {
|
|
332
358
|
case 0:
|
|
359
|
+
formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(
|
|
360
|
+
blockHash,
|
|
361
|
+
blockNumber
|
|
362
|
+
);
|
|
333
363
|
return [
|
|
334
364
|
4 /*yield*/,
|
|
335
365
|
axios_1.default.get(
|
|
@@ -340,8 +370,8 @@ var Provider = /** @class */ (function () {
|
|
|
340
370
|
contractAddress +
|
|
341
371
|
'&key=' +
|
|
342
372
|
key +
|
|
343
|
-
'&
|
|
344
|
-
|
|
373
|
+
'&' +
|
|
374
|
+
formattedBlockIdentifier
|
|
345
375
|
)
|
|
346
376
|
),
|
|
347
377
|
];
|
|
@@ -358,7 +388,7 @@ var Provider = /** @class */ (function () {
|
|
|
358
388
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L48-L52)
|
|
359
389
|
*
|
|
360
390
|
* @param txHash
|
|
361
|
-
* @returns the transaction status object {
|
|
391
|
+
* @returns the transaction status object { block_number, tx_status: NOT_RECEIVED | RECEIVED | PENDING | REJECTED | ACCEPTED_ONCHAIN }
|
|
362
392
|
*/
|
|
363
393
|
Provider.prototype.getTransactionStatus = function (txHash) {
|
|
364
394
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -390,7 +420,7 @@ var Provider = /** @class */ (function () {
|
|
|
390
420
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L54-L58)
|
|
391
421
|
*
|
|
392
422
|
* @param txHash
|
|
393
|
-
* @returns the transacton object { transaction_id, status, transaction,
|
|
423
|
+
* @returns the transacton object { transaction_id, status, transaction, block_number?, block_number?, transaction_index?, transaction_failure_reason? }
|
|
394
424
|
*/
|
|
395
425
|
Provider.prototype.getTransaction = function (txHash) {
|
|
396
426
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -421,19 +451,21 @@ var Provider = /** @class */ (function () {
|
|
|
421
451
|
*
|
|
422
452
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
|
|
423
453
|
*
|
|
424
|
-
* @param
|
|
454
|
+
* @param transaction - transaction to be invoked
|
|
425
455
|
* @returns a confirmation of invoking a function on the starknet contract
|
|
426
456
|
*/
|
|
427
|
-
Provider.prototype.addTransaction = function (
|
|
457
|
+
Provider.prototype.addTransaction = function (transaction) {
|
|
428
458
|
return __awaiter(this, void 0, void 0, function () {
|
|
429
459
|
var signature, contract_address_salt, data;
|
|
430
460
|
return __generator(this, function (_a) {
|
|
431
461
|
switch (_a.label) {
|
|
432
462
|
case 0:
|
|
433
|
-
signature =
|
|
463
|
+
signature =
|
|
464
|
+
transaction.type === 'INVOKE_FUNCTION' &&
|
|
465
|
+
(0, stark_1.formatSignature)(transaction.signature);
|
|
434
466
|
contract_address_salt =
|
|
435
|
-
|
|
436
|
-
(0, number_1.toHex)((0, number_1.toBN)(
|
|
467
|
+
transaction.type === 'DEPLOY' &&
|
|
468
|
+
(0, number_1.toHex)((0, number_1.toBN)(transaction.contract_address_salt));
|
|
437
469
|
return [
|
|
438
470
|
4 /*yield*/,
|
|
439
471
|
axios_1.default.post(
|
|
@@ -441,7 +473,7 @@ var Provider = /** @class */ (function () {
|
|
|
441
473
|
(0, json_1.stringify)(
|
|
442
474
|
__assign(
|
|
443
475
|
__assign(
|
|
444
|
-
__assign({},
|
|
476
|
+
__assign({}, transaction),
|
|
445
477
|
Array.isArray(signature) && { signature: signature }
|
|
446
478
|
),
|
|
447
479
|
contract_address_salt && { contract_address_salt: contract_address_salt }
|
|
@@ -510,34 +542,34 @@ var Provider = /** @class */ (function () {
|
|
|
510
542
|
retryInterval = 8000;
|
|
511
543
|
}
|
|
512
544
|
return __awaiter(this, void 0, void 0, function () {
|
|
513
|
-
var onchain, res;
|
|
545
|
+
var onchain, res, error;
|
|
514
546
|
return __generator(this, function (_a) {
|
|
515
547
|
switch (_a.label) {
|
|
516
548
|
case 0:
|
|
517
549
|
onchain = false;
|
|
518
|
-
|
|
550
|
+
return [4 /*yield*/, wait(retryInterval)];
|
|
519
551
|
case 1:
|
|
520
|
-
|
|
552
|
+
_a.sent();
|
|
553
|
+
_a.label = 2;
|
|
554
|
+
case 2:
|
|
555
|
+
if (!!onchain) return [3 /*break*/, 5];
|
|
521
556
|
// eslint-disable-next-line no-await-in-loop
|
|
522
557
|
return [4 /*yield*/, wait(retryInterval)];
|
|
523
|
-
case
|
|
558
|
+
case 3:
|
|
524
559
|
// eslint-disable-next-line no-await-in-loop
|
|
525
560
|
_a.sent();
|
|
526
561
|
return [4 /*yield*/, this.getTransactionStatus(txHash)];
|
|
527
|
-
case
|
|
562
|
+
case 4:
|
|
528
563
|
res = _a.sent();
|
|
529
|
-
if (
|
|
530
|
-
res.tx_status === 'ACCEPTED_ONCHAIN' ||
|
|
531
|
-
(res.tx_status === 'PENDING' && res.block_hash !== 'pending') // This is needed as of today. In the future there will be a different status for pending transactions.
|
|
532
|
-
) {
|
|
564
|
+
if (res.tx_status === 'ACCEPTED_ON_L1' || res.tx_status === 'ACCEPTED_ON_L2') {
|
|
533
565
|
onchain = true;
|
|
534
|
-
} else if (res.tx_status === 'REJECTED') {
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
throw
|
|
566
|
+
} else if (res.tx_status === 'REJECTED' || res.tx_status === 'NOT_RECEIVED') {
|
|
567
|
+
error = Error(res.tx_status);
|
|
568
|
+
error.response = res;
|
|
569
|
+
throw error;
|
|
538
570
|
}
|
|
539
|
-
return [3 /*break*/,
|
|
540
|
-
case
|
|
571
|
+
return [3 /*break*/, 2];
|
|
572
|
+
case 5:
|
|
541
573
|
return [2 /*return*/];
|
|
542
574
|
}
|
|
543
575
|
});
|
package/provider/interface.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
AddTransactionResponse,
|
|
3
|
+
BlockNumber,
|
|
3
4
|
CallContractResponse,
|
|
4
5
|
CallContractTransaction,
|
|
5
6
|
CompiledContract,
|
|
@@ -8,6 +9,7 @@ import type {
|
|
|
8
9
|
GetContractAddressesResponse,
|
|
9
10
|
GetTransactionResponse,
|
|
10
11
|
GetTransactionStatusResponse,
|
|
12
|
+
Signature,
|
|
11
13
|
Transaction,
|
|
12
14
|
} from '../types';
|
|
13
15
|
import type { BigNumberish } from '../utils/number';
|
|
@@ -25,53 +27,67 @@ export declare abstract class ProviderInterface {
|
|
|
25
27
|
/**
|
|
26
28
|
* Calls a function on the StarkNet contract.
|
|
27
29
|
*
|
|
28
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/
|
|
30
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L25-L39)
|
|
29
31
|
*
|
|
30
|
-
* @param
|
|
31
|
-
* @param
|
|
32
|
+
* @param invokeTransaction - transaction to be invoked
|
|
33
|
+
* @param blockHash
|
|
34
|
+
* @param blockNumber
|
|
32
35
|
* @returns the result of the function on the smart contract.
|
|
33
36
|
*/
|
|
34
37
|
abstract callContract(
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
invokeTransaction: CallContractTransaction,
|
|
39
|
+
blockHash?: BigNumberish,
|
|
40
|
+
blockNumber?: BlockNumber
|
|
37
41
|
): Promise<CallContractResponse>;
|
|
38
42
|
/**
|
|
39
|
-
* Gets the block information
|
|
43
|
+
* Gets the block information
|
|
40
44
|
*
|
|
41
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/
|
|
45
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L41-L53)
|
|
42
46
|
*
|
|
43
|
-
* @param
|
|
44
|
-
* @
|
|
47
|
+
* @param blockHash
|
|
48
|
+
* @param blockNumber
|
|
49
|
+
* @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
|
|
45
50
|
*/
|
|
46
|
-
abstract getBlock(
|
|
51
|
+
abstract getBlock(blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<GetBlockResponse>;
|
|
47
52
|
/**
|
|
48
53
|
* Gets the code of the deployed contract.
|
|
49
54
|
*
|
|
50
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/
|
|
55
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L55-L68)
|
|
51
56
|
*
|
|
52
57
|
* @param contractAddress
|
|
53
|
-
* @param
|
|
58
|
+
* @param blockHash
|
|
59
|
+
* @param blockNumber
|
|
54
60
|
* @returns Bytecode and ABI of compiled contract
|
|
55
61
|
*/
|
|
56
|
-
abstract getCode(
|
|
62
|
+
abstract getCode(
|
|
63
|
+
contractAddress: string,
|
|
64
|
+
blockHash?: BigNumberish,
|
|
65
|
+
blockNumber?: BlockNumber
|
|
66
|
+
): Promise<GetCodeResponse>;
|
|
57
67
|
/**
|
|
58
68
|
* Gets the contract's storage variable at a specific key.
|
|
59
69
|
*
|
|
60
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/
|
|
70
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L70-L85)
|
|
61
71
|
*
|
|
62
72
|
* @param contractAddress
|
|
63
73
|
* @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
|
|
64
|
-
* @param
|
|
74
|
+
* @param blockHash
|
|
75
|
+
* @param blockNumber
|
|
65
76
|
* @returns the value of the storage variable
|
|
66
77
|
*/
|
|
67
|
-
abstract getStorageAt(
|
|
78
|
+
abstract getStorageAt(
|
|
79
|
+
contractAddress: string,
|
|
80
|
+
key: number,
|
|
81
|
+
blockHash?: BigNumberish,
|
|
82
|
+
blockNumber?: BlockNumber
|
|
83
|
+
): Promise<object>;
|
|
68
84
|
/**
|
|
69
85
|
* Gets the status of a transaction.
|
|
70
86
|
*
|
|
71
87
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L48-L52)
|
|
72
88
|
*
|
|
73
89
|
* @param txHash
|
|
74
|
-
* @returns the transaction status object {
|
|
90
|
+
* @returns the transaction status object { block_number, tx_status: NOT_RECEIVED | RECEIVED | PENDING | REJECTED | ACCEPTED_ONCHAIN }
|
|
75
91
|
*/
|
|
76
92
|
abstract getTransactionStatus(txHash: BigNumberish): Promise<GetTransactionStatusResponse>;
|
|
77
93
|
/**
|
|
@@ -80,7 +96,7 @@ export declare abstract class ProviderInterface {
|
|
|
80
96
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L54-L58)
|
|
81
97
|
*
|
|
82
98
|
* @param txHash
|
|
83
|
-
* @returns the transacton object { transaction_id, status, transaction,
|
|
99
|
+
* @returns the transacton object { transaction_id, status, transaction, block_number?, block_number?, transaction_index?, transaction_failure_reason? }
|
|
84
100
|
*/
|
|
85
101
|
abstract getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
|
|
86
102
|
/**
|
|
@@ -88,10 +104,10 @@ export declare abstract class ProviderInterface {
|
|
|
88
104
|
*
|
|
89
105
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
|
|
90
106
|
*
|
|
91
|
-
* @param
|
|
107
|
+
* @param transaction - transaction to be invoked
|
|
92
108
|
* @returns a confirmation of invoking a function on the starknet contract
|
|
93
109
|
*/
|
|
94
|
-
abstract addTransaction(
|
|
110
|
+
abstract addTransaction(transaction: Transaction): Promise<AddTransactionResponse>;
|
|
95
111
|
/**
|
|
96
112
|
* Deploys a given compiled contract (json) to starknet
|
|
97
113
|
*
|
|
@@ -117,7 +133,7 @@ export declare abstract class ProviderInterface {
|
|
|
117
133
|
contractAddress: string,
|
|
118
134
|
entrypointSelector: string,
|
|
119
135
|
calldata?: string[],
|
|
120
|
-
signature?:
|
|
136
|
+
signature?: Signature
|
|
121
137
|
): Promise<AddTransactionResponse>;
|
|
122
138
|
abstract waitForTx(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
123
139
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { BlockNumber } from '../types';
|
|
2
|
+
import { BigNumberish } from '../utils/number';
|
|
3
|
+
/**
|
|
4
|
+
* TODO
|
|
5
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L148-L153)
|
|
6
|
+
*
|
|
7
|
+
* @param hashValue
|
|
8
|
+
* @param hashField
|
|
9
|
+
*/
|
|
10
|
+
export declare function formatHash(): void;
|
|
11
|
+
/**
|
|
12
|
+
* TODO
|
|
13
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L156-L161)
|
|
14
|
+
* @param txHash
|
|
15
|
+
* @param txId
|
|
16
|
+
*/
|
|
17
|
+
export declare function txIdentifier(): void;
|
|
18
|
+
/**
|
|
19
|
+
* Gets the block identifier for API request
|
|
20
|
+
*
|
|
21
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L164-L173)
|
|
22
|
+
*
|
|
23
|
+
* @param blockNumber
|
|
24
|
+
* @param blockHash
|
|
25
|
+
* @returns block identifier for API request
|
|
26
|
+
*/
|
|
27
|
+
export declare function getFormattedBlockIdentifier(
|
|
28
|
+
blockHash?: BigNumberish,
|
|
29
|
+
blockNumber?: BlockNumber
|
|
30
|
+
): string;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
exports.getFormattedBlockIdentifier = exports.txIdentifier = exports.formatHash = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* TODO
|
|
6
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L148-L153)
|
|
7
|
+
*
|
|
8
|
+
* @param hashValue
|
|
9
|
+
* @param hashField
|
|
10
|
+
*/
|
|
11
|
+
function formatHash() {}
|
|
12
|
+
exports.formatHash = formatHash;
|
|
13
|
+
/**
|
|
14
|
+
* TODO
|
|
15
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L156-L161)
|
|
16
|
+
* @param txHash
|
|
17
|
+
* @param txId
|
|
18
|
+
*/
|
|
19
|
+
function txIdentifier() {}
|
|
20
|
+
exports.txIdentifier = txIdentifier;
|
|
21
|
+
/**
|
|
22
|
+
* Gets the block identifier for API request
|
|
23
|
+
*
|
|
24
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L164-L173)
|
|
25
|
+
*
|
|
26
|
+
* @param blockNumber
|
|
27
|
+
* @param blockHash
|
|
28
|
+
* @returns block identifier for API request
|
|
29
|
+
*/
|
|
30
|
+
function getFormattedBlockIdentifier(blockHash, blockNumber) {
|
|
31
|
+
if (blockNumber === void 0) {
|
|
32
|
+
blockNumber = null;
|
|
33
|
+
}
|
|
34
|
+
if (blockHash) {
|
|
35
|
+
return '?blockHash=' + blockHash;
|
|
36
|
+
}
|
|
37
|
+
return '?blockNumber=' + blockNumber;
|
|
38
|
+
}
|
|
39
|
+
exports.getFormattedBlockIdentifier = getFormattedBlockIdentifier;
|