starknet 3.7.0 → 3.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 +13 -0
- package/account/default.d.ts +11 -1
- package/account/default.js +30 -15
- package/contract/default.d.ts +12 -2
- package/contract/default.js +14 -19
- package/contract/interface.d.ts +21 -3
- package/dist/account/default.d.ts +5 -1
- package/dist/account/default.js +18 -11
- package/dist/contract/default.d.ts +6 -3
- package/dist/contract/default.js +10 -19
- package/dist/contract/interface.d.ts +9 -4
- package/dist/provider/default.d.ts +2 -2
- package/dist/provider/default.js +18 -19
- package/dist/provider/utils.d.ts +1 -2
- package/dist/provider/utils.js +7 -8
- package/dist/types/api.d.ts +3 -1
- package/package.json +1 -1
- package/provider/default.d.ts +4 -2
- package/provider/default.js +30 -27
- package/provider/utils.d.ts +1 -2
- package/provider/utils.js +7 -8
- package/src/account/default.ts +21 -9
- package/src/contract/default.ts +20 -18
- package/src/contract/interface.ts +21 -3
- package/src/provider/default.ts +18 -12
- package/src/provider/utils.ts +7 -8
- package/src/types/api.ts +3 -1
- package/types/api.d.ts +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
# [3.8.0](https://github.com/seanjameshan/starknet.js/compare/v3.7.0...v3.8.0) (2022-04-04)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
- getBlock should not default to pending block ([7a641b5](https://github.com/seanjameshan/starknet.js/commit/7a641b55c3c762dada70814bf509b147f0cd315e))
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
|
|
9
|
+
- complete interface ([39d2f05](https://github.com/seanjameshan/starknet.js/commit/39d2f0574691e4b37a6050831b4e548b07a8e3e3))
|
|
10
|
+
- default estimateFee to pending block ([719dda5](https://github.com/seanjameshan/starknet.js/commit/719dda5f33a2bed353bd1bf311a2baf3110d1654))
|
|
11
|
+
- default to pending block ([d3c1bdc](https://github.com/seanjameshan/starknet.js/commit/d3c1bdcdca996bce273673cf9c8220156e965863))
|
|
12
|
+
- pending as success ([9e79288](https://github.com/seanjameshan/starknet.js/commit/9e7928845cc1e7088ba9a8dc9ba8fb9311970440))
|
|
13
|
+
|
|
1
14
|
# [3.7.0](https://github.com/seanjameshan/starknet.js/compare/v3.6.0...v3.7.0) (2022-03-24)
|
|
2
15
|
|
|
3
16
|
### Features
|
package/account/default.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Provider } from '../provider';
|
|
2
|
+
import { BlockIdentifier } from '../provider/utils';
|
|
2
3
|
import { SignerInterface } from '../signer';
|
|
3
4
|
import {
|
|
4
5
|
Abi,
|
|
@@ -18,7 +19,16 @@ export declare class Account extends Provider implements AccountInterface {
|
|
|
18
19
|
private signer;
|
|
19
20
|
constructor(provider: Provider, address: string, keyPairOrSigner: KeyPair | SignerInterface);
|
|
20
21
|
getNonce(): Promise<string>;
|
|
21
|
-
estimateFee(
|
|
22
|
+
estimateFee(
|
|
23
|
+
calls: Call | Call[],
|
|
24
|
+
{
|
|
25
|
+
nonce: providedNonce,
|
|
26
|
+
blockIdentifier,
|
|
27
|
+
}?: {
|
|
28
|
+
nonce?: BigNumberish;
|
|
29
|
+
blockIdentifier?: BlockIdentifier;
|
|
30
|
+
}
|
|
31
|
+
): Promise<EstimateFeeResponse>;
|
|
22
32
|
/**
|
|
23
33
|
* Invoke execute function in account contract
|
|
24
34
|
*
|
package/account/default.js
CHANGED
|
@@ -234,24 +234,35 @@ var Account = /** @class */ (function (_super) {
|
|
|
234
234
|
});
|
|
235
235
|
});
|
|
236
236
|
};
|
|
237
|
-
Account.prototype.estimateFee = function (calls) {
|
|
237
|
+
Account.prototype.estimateFee = function (calls, _a) {
|
|
238
|
+
var _b = _a === void 0 ? {} : _a,
|
|
239
|
+
providedNonce = _b.nonce,
|
|
240
|
+
_c = _b.blockIdentifier,
|
|
241
|
+
blockIdentifier = _c === void 0 ? 'pending' : _c;
|
|
238
242
|
return __awaiter(this, void 0, void 0, function () {
|
|
239
|
-
var transactions, nonce, signerDetails, signature, calldata;
|
|
240
|
-
return __generator(this, function (
|
|
241
|
-
switch (
|
|
243
|
+
var transactions, nonce, _d, signerDetails, signature, calldata;
|
|
244
|
+
return __generator(this, function (_e) {
|
|
245
|
+
switch (_e.label) {
|
|
242
246
|
case 0:
|
|
243
247
|
transactions = Array.isArray(calls) ? calls : [calls];
|
|
244
|
-
return [
|
|
248
|
+
if (!(providedNonce !== null && providedNonce !== void 0)) return [3 /*break*/, 1];
|
|
249
|
+
_d = providedNonce;
|
|
250
|
+
return [3 /*break*/, 3];
|
|
245
251
|
case 1:
|
|
246
|
-
|
|
252
|
+
return [4 /*yield*/, this.getNonce()];
|
|
253
|
+
case 2:
|
|
254
|
+
_d = _e.sent();
|
|
255
|
+
_e.label = 3;
|
|
256
|
+
case 3:
|
|
257
|
+
nonce = _d;
|
|
247
258
|
signerDetails = {
|
|
248
259
|
walletAddress: this.address,
|
|
249
260
|
nonce: (0, number_1.toBN)(nonce),
|
|
250
261
|
maxFee: (0, number_1.toBN)('0'),
|
|
251
262
|
};
|
|
252
263
|
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails)];
|
|
253
|
-
case
|
|
254
|
-
signature =
|
|
264
|
+
case 4:
|
|
265
|
+
signature = _e.sent();
|
|
255
266
|
calldata = __spreadArray(
|
|
256
267
|
__spreadArray(
|
|
257
268
|
[],
|
|
@@ -263,12 +274,16 @@ var Account = /** @class */ (function (_super) {
|
|
|
263
274
|
);
|
|
264
275
|
return [
|
|
265
276
|
2 /*return*/,
|
|
266
|
-
this.fetchEndpoint(
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
277
|
+
this.fetchEndpoint(
|
|
278
|
+
'estimate_fee',
|
|
279
|
+
{ blockIdentifier: blockIdentifier },
|
|
280
|
+
{
|
|
281
|
+
contract_address: this.address,
|
|
282
|
+
entry_point_selector: (0, hash_1.getSelectorFromName)('__execute__'),
|
|
283
|
+
calldata: calldata,
|
|
284
|
+
signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature),
|
|
285
|
+
}
|
|
286
|
+
),
|
|
272
287
|
];
|
|
273
288
|
}
|
|
274
289
|
});
|
|
@@ -313,7 +328,7 @@ var Account = /** @class */ (function (_super) {
|
|
|
313
328
|
_e = _b;
|
|
314
329
|
return [3 /*break*/, 6];
|
|
315
330
|
case 4:
|
|
316
|
-
return [4 /*yield*/, this.estimateFee(transactions)];
|
|
331
|
+
return [4 /*yield*/, this.estimateFee(transactions, { nonce: nonce })];
|
|
317
332
|
case 5:
|
|
318
333
|
_e = _f.sent().amount;
|
|
319
334
|
_f.label = 6;
|
package/contract/default.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AccountInterface } from '../account';
|
|
2
2
|
import { ProviderInterface } from '../provider';
|
|
3
|
+
import { BlockIdentifier } from '../provider/utils';
|
|
3
4
|
import {
|
|
4
5
|
Abi,
|
|
5
6
|
AbiEntry,
|
|
@@ -9,6 +10,7 @@ import {
|
|
|
9
10
|
Calldata,
|
|
10
11
|
ContractFunction,
|
|
11
12
|
Invocation,
|
|
13
|
+
Overrides,
|
|
12
14
|
ParsedStruct,
|
|
13
15
|
Result,
|
|
14
16
|
StructAbi,
|
|
@@ -136,8 +138,16 @@ export declare class Contract implements ContractInterface {
|
|
|
136
138
|
* @return - parsed response corresponding to the abi
|
|
137
139
|
*/
|
|
138
140
|
protected parseResponse(method: string, response: string[]): Result;
|
|
139
|
-
invoke(method: string, args?: Array<any
|
|
140
|
-
call(
|
|
141
|
+
invoke(method: string, args?: Array<any>, options?: Overrides): Promise<AddTransactionResponse>;
|
|
142
|
+
call(
|
|
143
|
+
method: string,
|
|
144
|
+
args?: Array<any>,
|
|
145
|
+
{
|
|
146
|
+
blockIdentifier,
|
|
147
|
+
}?: {
|
|
148
|
+
blockIdentifier?: BlockIdentifier;
|
|
149
|
+
}
|
|
150
|
+
): Promise<Result>;
|
|
141
151
|
estimate(method: string, args?: Array<any>): Promise<import('../types').EstimateFeeResponse>;
|
|
142
152
|
populate(method: string, args?: Array<any>): Invocation;
|
|
143
153
|
}
|
package/contract/default.js
CHANGED
|
@@ -705,10 +705,13 @@ var Contract = /** @class */ (function () {
|
|
|
705
705
|
return acc;
|
|
706
706
|
}, []);
|
|
707
707
|
};
|
|
708
|
-
Contract.prototype.invoke = function (method, args) {
|
|
708
|
+
Contract.prototype.invoke = function (method, args, options) {
|
|
709
709
|
if (args === void 0) {
|
|
710
710
|
args = [];
|
|
711
711
|
}
|
|
712
|
+
if (options === void 0) {
|
|
713
|
+
options = {};
|
|
714
|
+
}
|
|
712
715
|
// ensure contract is connected
|
|
713
716
|
(0, minimalistic_assert_1.default)(
|
|
714
717
|
this.address !== null,
|
|
@@ -725,10 +728,6 @@ var Contract = /** @class */ (function () {
|
|
|
725
728
|
}
|
|
726
729
|
return acc;
|
|
727
730
|
}, 0);
|
|
728
|
-
var overrides = {};
|
|
729
|
-
if (args.length === inputsLength + 1 && Array.isArray(args[args.length - 1])) {
|
|
730
|
-
Object.assign(overrides, args.pop());
|
|
731
|
-
}
|
|
732
731
|
if (args.length !== inputsLength) {
|
|
733
732
|
throw Error(
|
|
734
733
|
'Invalid number of arguments, expected ' +
|
|
@@ -746,22 +745,25 @@ var Contract = /** @class */ (function () {
|
|
|
746
745
|
};
|
|
747
746
|
if ('execute' in this.providerOrAccount) {
|
|
748
747
|
return this.providerOrAccount.execute(invocation, undefined, {
|
|
749
|
-
maxFee:
|
|
750
|
-
nonce:
|
|
748
|
+
maxFee: options.maxFee,
|
|
749
|
+
nonce: options.nonce,
|
|
751
750
|
});
|
|
752
751
|
}
|
|
753
752
|
return this.providerOrAccount.invokeFunction(
|
|
754
|
-
__assign(__assign({}, invocation), { signature:
|
|
753
|
+
__assign(__assign({}, invocation), { signature: options.signature || [] })
|
|
755
754
|
);
|
|
756
755
|
};
|
|
757
|
-
Contract.prototype.call = function (method, args) {
|
|
756
|
+
Contract.prototype.call = function (method, args, _a) {
|
|
758
757
|
if (args === void 0) {
|
|
759
758
|
args = [];
|
|
760
759
|
}
|
|
760
|
+
var _b = _a === void 0 ? {} : _a,
|
|
761
|
+
_c = _b.blockIdentifier,
|
|
762
|
+
blockIdentifier = _c === void 0 ? 'pending' : _c;
|
|
761
763
|
return __awaiter(this, void 0, void 0, function () {
|
|
762
|
-
var inputs,
|
|
764
|
+
var inputs, calldata;
|
|
763
765
|
var _this = this;
|
|
764
|
-
return __generator(this, function (
|
|
766
|
+
return __generator(this, function (_d) {
|
|
765
767
|
// ensure contract is connected
|
|
766
768
|
(0,
|
|
767
769
|
minimalistic_assert_1.default)(this.address !== null, 'contract isnt connected to an address');
|
|
@@ -770,13 +772,6 @@ var Contract = /** @class */ (function () {
|
|
|
770
772
|
inputs = this.abi.find(function (abi) {
|
|
771
773
|
return abi.name === method;
|
|
772
774
|
}).inputs;
|
|
773
|
-
inputsLength = inputs.length;
|
|
774
|
-
options = {
|
|
775
|
-
blockIdentifier: null,
|
|
776
|
-
};
|
|
777
|
-
if (args.length === inputsLength + 1 && typeof args[args.length - 1] === 'object') {
|
|
778
|
-
Object.assign(options, args.pop());
|
|
779
|
-
}
|
|
780
775
|
calldata = this.compileCalldata(args, inputs);
|
|
781
776
|
return [
|
|
782
777
|
2 /*return*/,
|
|
@@ -787,7 +782,7 @@ var Contract = /** @class */ (function () {
|
|
|
787
782
|
calldata: calldata,
|
|
788
783
|
entrypoint: method,
|
|
789
784
|
},
|
|
790
|
-
|
|
785
|
+
{ blockIdentifier: blockIdentifier }
|
|
791
786
|
)
|
|
792
787
|
.then(function (x) {
|
|
793
788
|
return _this.parseResponse(method, x.result);
|
package/contract/interface.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { AccountInterface } from '../account';
|
|
2
2
|
import { ProviderInterface } from '../provider';
|
|
3
|
+
import { BlockIdentifier } from '../provider/utils';
|
|
3
4
|
import {
|
|
4
5
|
Abi,
|
|
5
6
|
AddTransactionResponse,
|
|
6
7
|
AsyncContractFunction,
|
|
7
8
|
ContractFunction,
|
|
8
9
|
Invocation,
|
|
10
|
+
Overrides,
|
|
9
11
|
Result,
|
|
10
12
|
} from '../types';
|
|
11
13
|
export declare abstract class ContractInterface {
|
|
@@ -52,7 +54,13 @@ export declare abstract class ContractInterface {
|
|
|
52
54
|
* @param args Array of the arguments for the call
|
|
53
55
|
* @returns Result of the call as an array with key value pars
|
|
54
56
|
*/
|
|
55
|
-
abstract call(
|
|
57
|
+
abstract call(
|
|
58
|
+
method: string,
|
|
59
|
+
args?: Array<any>,
|
|
60
|
+
options?: {
|
|
61
|
+
blockIdentifier?: BlockIdentifier;
|
|
62
|
+
}
|
|
63
|
+
): Promise<Result>;
|
|
56
64
|
/**
|
|
57
65
|
* Invokes a method on a contract
|
|
58
66
|
*
|
|
@@ -60,14 +68,24 @@ export declare abstract class ContractInterface {
|
|
|
60
68
|
* @param args Array of the arguments for the invoke
|
|
61
69
|
* @returns Add Transaction Response
|
|
62
70
|
*/
|
|
63
|
-
abstract invoke(
|
|
71
|
+
abstract invoke(
|
|
72
|
+
method: string,
|
|
73
|
+
args?: Array<any>,
|
|
74
|
+
options?: Overrides
|
|
75
|
+
): Promise<AddTransactionResponse>;
|
|
64
76
|
/**
|
|
65
77
|
* Calls a method on a contract
|
|
66
78
|
*
|
|
67
79
|
* @param method name of the method
|
|
68
80
|
* @param args Array of the arguments for the call
|
|
69
81
|
*/
|
|
70
|
-
abstract estimate(
|
|
82
|
+
abstract estimate(
|
|
83
|
+
method: string,
|
|
84
|
+
args?: Array<any>,
|
|
85
|
+
options?: {
|
|
86
|
+
blockIdentifier?: BlockIdentifier;
|
|
87
|
+
}
|
|
88
|
+
): Promise<any>;
|
|
71
89
|
/**
|
|
72
90
|
* Calls a method on a contract
|
|
73
91
|
*
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Provider } from '../provider';
|
|
2
|
+
import { BlockIdentifier } from '../provider/utils';
|
|
2
3
|
import { SignerInterface } from '../signer';
|
|
3
4
|
import { Abi, AddTransactionResponse, Call, EstimateFeeResponse, InvocationsDetails, KeyPair, Signature, Transaction } from '../types';
|
|
4
5
|
import { BigNumberish } from '../utils/number';
|
|
@@ -9,7 +10,10 @@ export declare class Account extends Provider implements AccountInterface {
|
|
|
9
10
|
private signer;
|
|
10
11
|
constructor(provider: Provider, address: string, keyPairOrSigner: KeyPair | SignerInterface);
|
|
11
12
|
getNonce(): Promise<string>;
|
|
12
|
-
estimateFee(calls: Call | Call[]
|
|
13
|
+
estimateFee(calls: Call | Call[], { nonce: providedNonce, blockIdentifier, }?: {
|
|
14
|
+
nonce?: BigNumberish;
|
|
15
|
+
blockIdentifier?: BlockIdentifier;
|
|
16
|
+
}): Promise<EstimateFeeResponse>;
|
|
13
17
|
/**
|
|
14
18
|
* Invoke execute function in account contract
|
|
15
19
|
*
|
package/dist/account/default.js
CHANGED
|
@@ -114,26 +114,33 @@ var Account = /** @class */ (function (_super) {
|
|
|
114
114
|
});
|
|
115
115
|
});
|
|
116
116
|
};
|
|
117
|
-
Account.prototype.estimateFee = function (calls) {
|
|
117
|
+
Account.prototype.estimateFee = function (calls, _a) {
|
|
118
|
+
var _b = _a === void 0 ? {} : _a, providedNonce = _b.nonce, _c = _b.blockIdentifier, blockIdentifier = _c === void 0 ? 'pending' : _c;
|
|
118
119
|
return __awaiter(this, void 0, void 0, function () {
|
|
119
|
-
var transactions, nonce, signerDetails, signature, calldata;
|
|
120
|
-
return __generator(this, function (
|
|
121
|
-
switch (
|
|
120
|
+
var transactions, nonce, _d, signerDetails, signature, calldata;
|
|
121
|
+
return __generator(this, function (_e) {
|
|
122
|
+
switch (_e.label) {
|
|
122
123
|
case 0:
|
|
123
124
|
transactions = Array.isArray(calls) ? calls : [calls];
|
|
124
|
-
return [
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
if (!(providedNonce !== null && providedNonce !== void 0)) return [3 /*break*/, 1];
|
|
126
|
+
_d = providedNonce;
|
|
127
|
+
return [3 /*break*/, 3];
|
|
128
|
+
case 1: return [4 /*yield*/, this.getNonce()];
|
|
129
|
+
case 2:
|
|
130
|
+
_d = (_e.sent());
|
|
131
|
+
_e.label = 3;
|
|
132
|
+
case 3:
|
|
133
|
+
nonce = _d;
|
|
127
134
|
signerDetails = {
|
|
128
135
|
walletAddress: this.address,
|
|
129
136
|
nonce: (0, number_1.toBN)(nonce),
|
|
130
137
|
maxFee: (0, number_1.toBN)('0'),
|
|
131
138
|
};
|
|
132
139
|
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails)];
|
|
133
|
-
case
|
|
134
|
-
signature =
|
|
140
|
+
case 4:
|
|
141
|
+
signature = _e.sent();
|
|
135
142
|
calldata = __spreadArray(__spreadArray([], __read((0, transaction_1.fromCallsToExecuteCalldata)(transactions)), false), [signerDetails.nonce.toString()], false);
|
|
136
|
-
return [2 /*return*/, this.fetchEndpoint('estimate_fee',
|
|
143
|
+
return [2 /*return*/, this.fetchEndpoint('estimate_fee', { blockIdentifier: blockIdentifier }, {
|
|
137
144
|
contract_address: this.address,
|
|
138
145
|
entry_point_selector: (0, hash_1.getSelectorFromName)('__execute__'),
|
|
139
146
|
calldata: calldata,
|
|
@@ -174,7 +181,7 @@ var Account = /** @class */ (function (_super) {
|
|
|
174
181
|
if (!((_b = transactionsDetail.maxFee) !== null && _b !== void 0)) return [3 /*break*/, 4];
|
|
175
182
|
_e = _b;
|
|
176
183
|
return [3 /*break*/, 6];
|
|
177
|
-
case 4: return [4 /*yield*/, this.estimateFee(transactions)];
|
|
184
|
+
case 4: return [4 /*yield*/, this.estimateFee(transactions, { nonce: nonce })];
|
|
178
185
|
case 5:
|
|
179
186
|
_e = (_f.sent()).amount;
|
|
180
187
|
_f.label = 6;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AccountInterface } from '../account';
|
|
2
2
|
import { ProviderInterface } from '../provider';
|
|
3
|
-
import {
|
|
3
|
+
import { BlockIdentifier } from '../provider/utils';
|
|
4
|
+
import { Abi, AbiEntry, AddTransactionResponse, Args, AsyncContractFunction, Calldata, ContractFunction, Invocation, Overrides, ParsedStruct, Result, StructAbi } from '../types';
|
|
4
5
|
import { BigNumberish } from '../utils/number';
|
|
5
6
|
import { ContractInterface } from './interface';
|
|
6
7
|
export declare class Contract implements ContractInterface {
|
|
@@ -114,8 +115,10 @@ export declare class Contract implements ContractInterface {
|
|
|
114
115
|
* @return - parsed response corresponding to the abi
|
|
115
116
|
*/
|
|
116
117
|
protected parseResponse(method: string, response: string[]): Result;
|
|
117
|
-
invoke(method: string, args?: Array<any
|
|
118
|
-
call(method: string, args?: Array<any
|
|
118
|
+
invoke(method: string, args?: Array<any>, options?: Overrides): Promise<AddTransactionResponse>;
|
|
119
|
+
call(method: string, args?: Array<any>, { blockIdentifier, }?: {
|
|
120
|
+
blockIdentifier?: BlockIdentifier;
|
|
121
|
+
}): Promise<Result>;
|
|
119
122
|
estimate(method: string, args?: Array<any>): Promise<import("../types").EstimateFeeResponse>;
|
|
120
123
|
populate(method: string, args?: Array<any>): Invocation;
|
|
121
124
|
}
|
package/dist/contract/default.js
CHANGED
|
@@ -550,8 +550,9 @@ var Contract = /** @class */ (function () {
|
|
|
550
550
|
return acc;
|
|
551
551
|
}, []);
|
|
552
552
|
};
|
|
553
|
-
Contract.prototype.invoke = function (method, args) {
|
|
553
|
+
Contract.prototype.invoke = function (method, args, options) {
|
|
554
554
|
if (args === void 0) { args = []; }
|
|
555
|
+
if (options === void 0) { options = {}; }
|
|
555
556
|
// ensure contract is connected
|
|
556
557
|
(0, minimalistic_assert_1.default)(this.address !== null, 'contract isnt connected to an address');
|
|
557
558
|
// validate method and args
|
|
@@ -563,10 +564,6 @@ var Contract = /** @class */ (function () {
|
|
|
563
564
|
}
|
|
564
565
|
return acc;
|
|
565
566
|
}, 0);
|
|
566
|
-
var overrides = {};
|
|
567
|
-
if (args.length === inputsLength + 1 && Array.isArray(args[args.length - 1])) {
|
|
568
|
-
Object.assign(overrides, args.pop());
|
|
569
|
-
}
|
|
570
567
|
if (args.length !== inputsLength) {
|
|
571
568
|
throw Error("Invalid number of arguments, expected " + inputsLength + " arguments, but got " + args.length);
|
|
572
569
|
}
|
|
@@ -579,37 +576,31 @@ var Contract = /** @class */ (function () {
|
|
|
579
576
|
};
|
|
580
577
|
if ('execute' in this.providerOrAccount) {
|
|
581
578
|
return this.providerOrAccount.execute(invocation, undefined, {
|
|
582
|
-
maxFee:
|
|
583
|
-
nonce:
|
|
579
|
+
maxFee: options.maxFee,
|
|
580
|
+
nonce: options.nonce,
|
|
584
581
|
});
|
|
585
582
|
}
|
|
586
|
-
return this.providerOrAccount.invokeFunction(__assign(__assign({}, invocation), { signature:
|
|
583
|
+
return this.providerOrAccount.invokeFunction(__assign(__assign({}, invocation), { signature: options.signature || [] }));
|
|
587
584
|
};
|
|
588
|
-
Contract.prototype.call = function (method, args) {
|
|
585
|
+
Contract.prototype.call = function (method, args, _a) {
|
|
589
586
|
if (args === void 0) { args = []; }
|
|
587
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.blockIdentifier, blockIdentifier = _c === void 0 ? 'pending' : _c;
|
|
590
588
|
return __awaiter(this, void 0, void 0, function () {
|
|
591
|
-
var inputs,
|
|
589
|
+
var inputs, calldata;
|
|
592
590
|
var _this = this;
|
|
593
|
-
return __generator(this, function (
|
|
591
|
+
return __generator(this, function (_d) {
|
|
594
592
|
// ensure contract is connected
|
|
595
593
|
(0, minimalistic_assert_1.default)(this.address !== null, 'contract isnt connected to an address');
|
|
596
594
|
// validate method and args
|
|
597
595
|
this.validateMethodAndArgs('CALL', method, args);
|
|
598
596
|
inputs = this.abi.find(function (abi) { return abi.name === method; }).inputs;
|
|
599
|
-
inputsLength = inputs.length;
|
|
600
|
-
options = {
|
|
601
|
-
blockIdentifier: null,
|
|
602
|
-
};
|
|
603
|
-
if (args.length === inputsLength + 1 && typeof args[args.length - 1] === 'object') {
|
|
604
|
-
Object.assign(options, args.pop());
|
|
605
|
-
}
|
|
606
597
|
calldata = this.compileCalldata(args, inputs);
|
|
607
598
|
return [2 /*return*/, this.providerOrAccount
|
|
608
599
|
.callContract({
|
|
609
600
|
contractAddress: this.address,
|
|
610
601
|
calldata: calldata,
|
|
611
602
|
entrypoint: method,
|
|
612
|
-
},
|
|
603
|
+
}, { blockIdentifier: blockIdentifier })
|
|
613
604
|
.then(function (x) { return _this.parseResponse(method, x.result); })];
|
|
614
605
|
});
|
|
615
606
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AccountInterface } from '../account';
|
|
2
2
|
import { ProviderInterface } from '../provider';
|
|
3
|
-
import {
|
|
3
|
+
import { BlockIdentifier } from '../provider/utils';
|
|
4
|
+
import { Abi, AddTransactionResponse, AsyncContractFunction, ContractFunction, Invocation, Overrides, Result } from '../types';
|
|
4
5
|
export declare abstract class ContractInterface {
|
|
5
6
|
abstract abi: Abi;
|
|
6
7
|
abstract address: string;
|
|
@@ -45,7 +46,9 @@ export declare abstract class ContractInterface {
|
|
|
45
46
|
* @param args Array of the arguments for the call
|
|
46
47
|
* @returns Result of the call as an array with key value pars
|
|
47
48
|
*/
|
|
48
|
-
abstract call(method: string, args?: Array<any
|
|
49
|
+
abstract call(method: string, args?: Array<any>, options?: {
|
|
50
|
+
blockIdentifier?: BlockIdentifier;
|
|
51
|
+
}): Promise<Result>;
|
|
49
52
|
/**
|
|
50
53
|
* Invokes a method on a contract
|
|
51
54
|
*
|
|
@@ -53,14 +56,16 @@ export declare abstract class ContractInterface {
|
|
|
53
56
|
* @param args Array of the arguments for the invoke
|
|
54
57
|
* @returns Add Transaction Response
|
|
55
58
|
*/
|
|
56
|
-
abstract invoke(method: string, args?: Array<any
|
|
59
|
+
abstract invoke(method: string, args?: Array<any>, options?: Overrides): Promise<AddTransactionResponse>;
|
|
57
60
|
/**
|
|
58
61
|
* Calls a method on a contract
|
|
59
62
|
*
|
|
60
63
|
* @param method name of the method
|
|
61
64
|
* @param args Array of the arguments for the call
|
|
62
65
|
*/
|
|
63
|
-
abstract estimate(method: string, args?: Array<any
|
|
66
|
+
abstract estimate(method: string, args?: Array<any>, options?: {
|
|
67
|
+
blockIdentifier?: BlockIdentifier;
|
|
68
|
+
}): Promise<any>;
|
|
64
69
|
/**
|
|
65
70
|
* Calls a method on a contract
|
|
66
71
|
*
|
|
@@ -36,8 +36,8 @@ export declare class Provider implements ProviderInterface {
|
|
|
36
36
|
* @param blockNumber
|
|
37
37
|
* @returns the result of the function on the smart contract.
|
|
38
38
|
*/
|
|
39
|
-
callContract({ contractAddress, entrypoint, calldata }: Call,
|
|
40
|
-
blockIdentifier
|
|
39
|
+
callContract({ contractAddress, entrypoint, calldata }: Call, { blockIdentifier }?: {
|
|
40
|
+
blockIdentifier?: BlockIdentifier;
|
|
41
41
|
}): Promise<CallContractResponse>;
|
|
42
42
|
/**
|
|
43
43
|
* Gets the block information
|
package/dist/provider/default.js
CHANGED
|
@@ -219,12 +219,12 @@ var Provider = /** @class */ (function () {
|
|
|
219
219
|
* @param blockNumber
|
|
220
220
|
* @returns the result of the function on the smart contract.
|
|
221
221
|
*/
|
|
222
|
-
Provider.prototype.callContract = function (_a,
|
|
223
|
-
var contractAddress = _a.contractAddress, entrypoint = _a.entrypoint,
|
|
224
|
-
|
|
222
|
+
Provider.prototype.callContract = function (_a, _b) {
|
|
223
|
+
var contractAddress = _a.contractAddress, entrypoint = _a.entrypoint, _c = _a.calldata, calldata = _c === void 0 ? [] : _c;
|
|
224
|
+
var _d = _b === void 0 ? {} : _b, _e = _d.blockIdentifier, blockIdentifier = _e === void 0 ? 'pending' : _e;
|
|
225
225
|
return __awaiter(this, void 0, void 0, function () {
|
|
226
|
-
return __generator(this, function (
|
|
227
|
-
return [2 /*return*/, this.fetchEndpoint('call_contract',
|
|
226
|
+
return __generator(this, function (_f) {
|
|
227
|
+
return [2 /*return*/, this.fetchEndpoint('call_contract', { blockIdentifier: blockIdentifier }, {
|
|
228
228
|
signature: [],
|
|
229
229
|
contract_address: contractAddress,
|
|
230
230
|
entry_point_selector: (0, hash_1.getSelectorFromName)(entrypoint),
|
|
@@ -261,7 +261,7 @@ var Provider = /** @class */ (function () {
|
|
|
261
261
|
* @returns Bytecode and ABI of compiled contract
|
|
262
262
|
*/
|
|
263
263
|
Provider.prototype.getCode = function (contractAddress, blockIdentifier) {
|
|
264
|
-
if (blockIdentifier === void 0) { blockIdentifier =
|
|
264
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
265
265
|
return __awaiter(this, void 0, void 0, function () {
|
|
266
266
|
return __generator(this, function (_a) {
|
|
267
267
|
return [2 /*return*/, this.fetchEndpoint('get_code', { blockIdentifier: blockIdentifier, contractAddress: contractAddress })];
|
|
@@ -281,7 +281,7 @@ var Provider = /** @class */ (function () {
|
|
|
281
281
|
* @returns the value of the storage variable
|
|
282
282
|
*/
|
|
283
283
|
Provider.prototype.getStorageAt = function (contractAddress, key, blockIdentifier) {
|
|
284
|
-
if (blockIdentifier === void 0) { blockIdentifier =
|
|
284
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
285
285
|
return __awaiter(this, void 0, void 0, function () {
|
|
286
286
|
return __generator(this, function (_a) {
|
|
287
287
|
return [2 /*return*/, this.fetchEndpoint('get_storage_at', { blockIdentifier: blockIdentifier, contractAddress: contractAddress, key: key })];
|
|
@@ -402,29 +402,28 @@ var Provider = /** @class */ (function () {
|
|
|
402
402
|
Provider.prototype.waitForTransaction = function (txHash, retryInterval) {
|
|
403
403
|
if (retryInterval === void 0) { retryInterval = 8000; }
|
|
404
404
|
return __awaiter(this, void 0, void 0, function () {
|
|
405
|
-
var onchain, res, message, error;
|
|
405
|
+
var onchain, res, successStates, errorStates, message, error;
|
|
406
406
|
return __generator(this, function (_a) {
|
|
407
407
|
switch (_a.label) {
|
|
408
408
|
case 0:
|
|
409
409
|
onchain = false;
|
|
410
|
-
|
|
410
|
+
_a.label = 1;
|
|
411
411
|
case 1:
|
|
412
|
-
|
|
413
|
-
_a.label = 2;
|
|
414
|
-
case 2:
|
|
415
|
-
if (!!onchain) return [3 /*break*/, 5];
|
|
412
|
+
if (!!onchain) return [3 /*break*/, 4];
|
|
416
413
|
// eslint-disable-next-line no-await-in-loop
|
|
417
414
|
return [4 /*yield*/, wait(retryInterval)];
|
|
418
|
-
case
|
|
415
|
+
case 2:
|
|
419
416
|
// eslint-disable-next-line no-await-in-loop
|
|
420
417
|
_a.sent();
|
|
421
418
|
return [4 /*yield*/, this.getTransactionStatus(txHash)];
|
|
422
|
-
case
|
|
419
|
+
case 3:
|
|
423
420
|
res = _a.sent();
|
|
424
|
-
|
|
421
|
+
successStates = ['ACCEPTED_ON_L1', 'ACCEPTED_ON_L2', 'PENDING'];
|
|
422
|
+
errorStates = ['REJECTED', 'NOT_RECEIVED'];
|
|
423
|
+
if (successStates.includes(res.tx_status)) {
|
|
425
424
|
onchain = true;
|
|
426
425
|
}
|
|
427
|
-
else if (
|
|
426
|
+
else if (errorStates.includes(res.tx_status)) {
|
|
428
427
|
message = res.tx_failure_reason
|
|
429
428
|
? res.tx_status + ": " + res.tx_failure_reason.code + "\n" + res.tx_failure_reason.error_message
|
|
430
429
|
: res.tx_status;
|
|
@@ -432,8 +431,8 @@ var Provider = /** @class */ (function () {
|
|
|
432
431
|
error.response = res;
|
|
433
432
|
throw error;
|
|
434
433
|
}
|
|
435
|
-
return [3 /*break*/,
|
|
436
|
-
case
|
|
434
|
+
return [3 /*break*/, 1];
|
|
435
|
+
case 4: return [2 /*return*/];
|
|
437
436
|
}
|
|
438
437
|
});
|
|
439
438
|
});
|
package/dist/provider/utils.d.ts
CHANGED
|
@@ -35,8 +35,7 @@ export declare function getBlockIdentifier(blockIdentifier: BlockIdentifier): Bl
|
|
|
35
35
|
*
|
|
36
36
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L164-L173)
|
|
37
37
|
*
|
|
38
|
-
* @param
|
|
39
|
-
* @param blockHash
|
|
38
|
+
* @param blockIdentifier
|
|
40
39
|
* @returns block identifier for API request
|
|
41
40
|
*/
|
|
42
41
|
export declare function getFormattedBlockIdentifier(blockIdentifier?: BlockIdentifier): string;
|
package/dist/provider/utils.js
CHANGED
|
@@ -36,6 +36,12 @@ exports.txIdentifier = txIdentifier;
|
|
|
36
36
|
* @returns block identifier object
|
|
37
37
|
*/
|
|
38
38
|
function getBlockIdentifier(blockIdentifier) {
|
|
39
|
+
if (blockIdentifier === null) {
|
|
40
|
+
return { type: 'BLOCK_NUMBER', data: null };
|
|
41
|
+
}
|
|
42
|
+
if (blockIdentifier === 'pending') {
|
|
43
|
+
return { type: 'BLOCK_NUMBER', data: 'pending' };
|
|
44
|
+
}
|
|
39
45
|
if (typeof blockIdentifier === 'number') {
|
|
40
46
|
return { type: 'BLOCK_NUMBER', data: blockIdentifier };
|
|
41
47
|
}
|
|
@@ -45,12 +51,6 @@ function getBlockIdentifier(blockIdentifier) {
|
|
|
45
51
|
if (typeof blockIdentifier === 'string' && !Number.isNaN(parseInt(blockIdentifier, 10))) {
|
|
46
52
|
return { type: 'BLOCK_NUMBER', data: parseInt(blockIdentifier, 10) };
|
|
47
53
|
}
|
|
48
|
-
if (blockIdentifier === null) {
|
|
49
|
-
return { type: 'BLOCK_NUMBER', data: null };
|
|
50
|
-
}
|
|
51
|
-
if (blockIdentifier === 'pending') {
|
|
52
|
-
return { type: 'BLOCK_NUMBER', data: 'pending' };
|
|
53
|
-
}
|
|
54
54
|
if (typeof blockIdentifier === 'string') {
|
|
55
55
|
throw new Error("Invalid block identifier: " + blockIdentifier);
|
|
56
56
|
}
|
|
@@ -62,8 +62,7 @@ exports.getBlockIdentifier = getBlockIdentifier;
|
|
|
62
62
|
*
|
|
63
63
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L164-L173)
|
|
64
64
|
*
|
|
65
|
-
* @param
|
|
66
|
-
* @param blockHash
|
|
65
|
+
* @param blockIdentifier
|
|
67
66
|
* @returns block identifier for API request
|
|
68
67
|
*/
|
|
69
68
|
function getFormattedBlockIdentifier(blockIdentifier) {
|
package/dist/types/api.d.ts
CHANGED
package/package.json
CHANGED
package/provider/default.d.ts
CHANGED
|
@@ -66,8 +66,10 @@ export declare class Provider implements ProviderInterface {
|
|
|
66
66
|
*/
|
|
67
67
|
callContract(
|
|
68
68
|
{ contractAddress, entrypoint, calldata }: Call,
|
|
69
|
-
|
|
70
|
-
blockIdentifier
|
|
69
|
+
{
|
|
70
|
+
blockIdentifier,
|
|
71
|
+
}?: {
|
|
72
|
+
blockIdentifier?: BlockIdentifier;
|
|
71
73
|
}
|
|
72
74
|
): Promise<CallContractResponse>;
|
|
73
75
|
/**
|
package/provider/default.js
CHANGED
|
@@ -343,24 +343,28 @@ var Provider = /** @class */ (function () {
|
|
|
343
343
|
* @param blockNumber
|
|
344
344
|
* @returns the result of the function on the smart contract.
|
|
345
345
|
*/
|
|
346
|
-
Provider.prototype.callContract = function (_a,
|
|
346
|
+
Provider.prototype.callContract = function (_a, _b) {
|
|
347
347
|
var contractAddress = _a.contractAddress,
|
|
348
348
|
entrypoint = _a.entrypoint,
|
|
349
|
-
|
|
350
|
-
calldata =
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
349
|
+
_c = _a.calldata,
|
|
350
|
+
calldata = _c === void 0 ? [] : _c;
|
|
351
|
+
var _d = _b === void 0 ? {} : _b,
|
|
352
|
+
_e = _d.blockIdentifier,
|
|
353
|
+
blockIdentifier = _e === void 0 ? 'pending' : _e;
|
|
354
354
|
return __awaiter(this, void 0, void 0, function () {
|
|
355
|
-
return __generator(this, function (
|
|
355
|
+
return __generator(this, function (_f) {
|
|
356
356
|
return [
|
|
357
357
|
2 /*return*/,
|
|
358
|
-
this.fetchEndpoint(
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
358
|
+
this.fetchEndpoint(
|
|
359
|
+
'call_contract',
|
|
360
|
+
{ blockIdentifier: blockIdentifier },
|
|
361
|
+
{
|
|
362
|
+
signature: [],
|
|
363
|
+
contract_address: contractAddress,
|
|
364
|
+
entry_point_selector: (0, hash_1.getSelectorFromName)(entrypoint),
|
|
365
|
+
calldata: calldata,
|
|
366
|
+
}
|
|
367
|
+
),
|
|
364
368
|
];
|
|
365
369
|
});
|
|
366
370
|
});
|
|
@@ -399,7 +403,7 @@ var Provider = /** @class */ (function () {
|
|
|
399
403
|
*/
|
|
400
404
|
Provider.prototype.getCode = function (contractAddress, blockIdentifier) {
|
|
401
405
|
if (blockIdentifier === void 0) {
|
|
402
|
-
blockIdentifier =
|
|
406
|
+
blockIdentifier = 'pending';
|
|
403
407
|
}
|
|
404
408
|
return __awaiter(this, void 0, void 0, function () {
|
|
405
409
|
return __generator(this, function (_a) {
|
|
@@ -427,7 +431,7 @@ var Provider = /** @class */ (function () {
|
|
|
427
431
|
*/
|
|
428
432
|
Provider.prototype.getStorageAt = function (contractAddress, key, blockIdentifier) {
|
|
429
433
|
if (blockIdentifier === void 0) {
|
|
430
|
-
blockIdentifier =
|
|
434
|
+
blockIdentifier = 'pending';
|
|
431
435
|
}
|
|
432
436
|
return __awaiter(this, void 0, void 0, function () {
|
|
433
437
|
return __generator(this, function (_a) {
|
|
@@ -586,28 +590,27 @@ var Provider = /** @class */ (function () {
|
|
|
586
590
|
retryInterval = 8000;
|
|
587
591
|
}
|
|
588
592
|
return __awaiter(this, void 0, void 0, function () {
|
|
589
|
-
var onchain, res, message, error;
|
|
593
|
+
var onchain, res, successStates, errorStates, message, error;
|
|
590
594
|
return __generator(this, function (_a) {
|
|
591
595
|
switch (_a.label) {
|
|
592
596
|
case 0:
|
|
593
597
|
onchain = false;
|
|
594
|
-
|
|
598
|
+
_a.label = 1;
|
|
595
599
|
case 1:
|
|
596
|
-
|
|
597
|
-
_a.label = 2;
|
|
598
|
-
case 2:
|
|
599
|
-
if (!!onchain) return [3 /*break*/, 5];
|
|
600
|
+
if (!!onchain) return [3 /*break*/, 4];
|
|
600
601
|
// eslint-disable-next-line no-await-in-loop
|
|
601
602
|
return [4 /*yield*/, wait(retryInterval)];
|
|
602
|
-
case
|
|
603
|
+
case 2:
|
|
603
604
|
// eslint-disable-next-line no-await-in-loop
|
|
604
605
|
_a.sent();
|
|
605
606
|
return [4 /*yield*/, this.getTransactionStatus(txHash)];
|
|
606
|
-
case
|
|
607
|
+
case 3:
|
|
607
608
|
res = _a.sent();
|
|
608
|
-
|
|
609
|
+
successStates = ['ACCEPTED_ON_L1', 'ACCEPTED_ON_L2', 'PENDING'];
|
|
610
|
+
errorStates = ['REJECTED', 'NOT_RECEIVED'];
|
|
611
|
+
if (successStates.includes(res.tx_status)) {
|
|
609
612
|
onchain = true;
|
|
610
|
-
} else if (
|
|
613
|
+
} else if (errorStates.includes(res.tx_status)) {
|
|
611
614
|
message = res.tx_failure_reason
|
|
612
615
|
? res.tx_status +
|
|
613
616
|
': ' +
|
|
@@ -619,8 +622,8 @@ var Provider = /** @class */ (function () {
|
|
|
619
622
|
error.response = res;
|
|
620
623
|
throw error;
|
|
621
624
|
}
|
|
622
|
-
return [3 /*break*/,
|
|
623
|
-
case
|
|
625
|
+
return [3 /*break*/, 1];
|
|
626
|
+
case 4:
|
|
624
627
|
return [2 /*return*/];
|
|
625
628
|
}
|
|
626
629
|
});
|
package/provider/utils.d.ts
CHANGED
|
@@ -37,8 +37,7 @@ export declare function getBlockIdentifier(blockIdentifier: BlockIdentifier): Bl
|
|
|
37
37
|
*
|
|
38
38
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L164-L173)
|
|
39
39
|
*
|
|
40
|
-
* @param
|
|
41
|
-
* @param blockHash
|
|
40
|
+
* @param blockIdentifier
|
|
42
41
|
* @returns block identifier for API request
|
|
43
42
|
*/
|
|
44
43
|
export declare function getFormattedBlockIdentifier(blockIdentifier?: BlockIdentifier): string;
|
package/provider/utils.js
CHANGED
|
@@ -39,6 +39,12 @@ exports.txIdentifier = txIdentifier;
|
|
|
39
39
|
* @returns block identifier object
|
|
40
40
|
*/
|
|
41
41
|
function getBlockIdentifier(blockIdentifier) {
|
|
42
|
+
if (blockIdentifier === null) {
|
|
43
|
+
return { type: 'BLOCK_NUMBER', data: null };
|
|
44
|
+
}
|
|
45
|
+
if (blockIdentifier === 'pending') {
|
|
46
|
+
return { type: 'BLOCK_NUMBER', data: 'pending' };
|
|
47
|
+
}
|
|
42
48
|
if (typeof blockIdentifier === 'number') {
|
|
43
49
|
return { type: 'BLOCK_NUMBER', data: blockIdentifier };
|
|
44
50
|
}
|
|
@@ -48,12 +54,6 @@ function getBlockIdentifier(blockIdentifier) {
|
|
|
48
54
|
if (typeof blockIdentifier === 'string' && !Number.isNaN(parseInt(blockIdentifier, 10))) {
|
|
49
55
|
return { type: 'BLOCK_NUMBER', data: parseInt(blockIdentifier, 10) };
|
|
50
56
|
}
|
|
51
|
-
if (blockIdentifier === null) {
|
|
52
|
-
return { type: 'BLOCK_NUMBER', data: null };
|
|
53
|
-
}
|
|
54
|
-
if (blockIdentifier === 'pending') {
|
|
55
|
-
return { type: 'BLOCK_NUMBER', data: 'pending' };
|
|
56
|
-
}
|
|
57
57
|
if (typeof blockIdentifier === 'string') {
|
|
58
58
|
throw new Error('Invalid block identifier: ' + blockIdentifier);
|
|
59
59
|
}
|
|
@@ -65,8 +65,7 @@ exports.getBlockIdentifier = getBlockIdentifier;
|
|
|
65
65
|
*
|
|
66
66
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L164-L173)
|
|
67
67
|
*
|
|
68
|
-
* @param
|
|
69
|
-
* @param blockHash
|
|
68
|
+
* @param blockIdentifier
|
|
70
69
|
* @returns block identifier for API request
|
|
71
70
|
*/
|
|
72
71
|
function getFormattedBlockIdentifier(blockIdentifier) {
|
package/src/account/default.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import assert from 'minimalistic-assert';
|
|
2
2
|
|
|
3
3
|
import { Provider } from '../provider';
|
|
4
|
+
import { BlockIdentifier } from '../provider/utils';
|
|
4
5
|
import { Signer, SignerInterface } from '../signer';
|
|
5
6
|
import {
|
|
6
7
|
Abi,
|
|
@@ -46,9 +47,15 @@ export class Account extends Provider implements AccountInterface {
|
|
|
46
47
|
return toHex(toBN(result[0]));
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
public async estimateFee(
|
|
50
|
+
public async estimateFee(
|
|
51
|
+
calls: Call | Call[],
|
|
52
|
+
{
|
|
53
|
+
nonce: providedNonce,
|
|
54
|
+
blockIdentifier = 'pending',
|
|
55
|
+
}: { nonce?: BigNumberish; blockIdentifier?: BlockIdentifier } = {}
|
|
56
|
+
): Promise<EstimateFeeResponse> {
|
|
50
57
|
const transactions = Array.isArray(calls) ? calls : [calls];
|
|
51
|
-
const nonce = await this.getNonce();
|
|
58
|
+
const nonce = providedNonce ?? (await this.getNonce());
|
|
52
59
|
const signerDetails = {
|
|
53
60
|
walletAddress: this.address,
|
|
54
61
|
nonce: toBN(nonce),
|
|
@@ -57,12 +64,16 @@ export class Account extends Provider implements AccountInterface {
|
|
|
57
64
|
const signature = await this.signer.signTransaction(transactions, signerDetails);
|
|
58
65
|
|
|
59
66
|
const calldata = [...fromCallsToExecuteCalldata(transactions), signerDetails.nonce.toString()];
|
|
60
|
-
return this.fetchEndpoint(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
67
|
+
return this.fetchEndpoint(
|
|
68
|
+
'estimate_fee',
|
|
69
|
+
{ blockIdentifier },
|
|
70
|
+
{
|
|
71
|
+
contract_address: this.address,
|
|
72
|
+
entry_point_selector: getSelectorFromName('__execute__'),
|
|
73
|
+
calldata,
|
|
74
|
+
signature: bigNumberishArrayToDecimalStringArray(signature),
|
|
75
|
+
}
|
|
76
|
+
);
|
|
66
77
|
}
|
|
67
78
|
|
|
68
79
|
/**
|
|
@@ -80,7 +91,8 @@ export class Account extends Provider implements AccountInterface {
|
|
|
80
91
|
): Promise<AddTransactionResponse> {
|
|
81
92
|
const transactions = Array.isArray(calls) ? calls : [calls];
|
|
82
93
|
const nonce = toBN(transactionsDetail.nonce ?? (await this.getNonce()));
|
|
83
|
-
const maxFee =
|
|
94
|
+
const maxFee =
|
|
95
|
+
transactionsDetail.maxFee ?? (await this.estimateFee(transactions, { nonce })).amount;
|
|
84
96
|
const signerDetails = {
|
|
85
97
|
walletAddress: this.address,
|
|
86
98
|
nonce,
|
package/src/contract/default.ts
CHANGED
|
@@ -3,6 +3,7 @@ import assert from 'minimalistic-assert';
|
|
|
3
3
|
|
|
4
4
|
import { AccountInterface } from '../account';
|
|
5
5
|
import { ProviderInterface, defaultProvider } from '../provider';
|
|
6
|
+
import { BlockIdentifier } from '../provider/utils';
|
|
6
7
|
import {
|
|
7
8
|
Abi,
|
|
8
9
|
AbiEntry,
|
|
@@ -528,7 +529,11 @@ export class Contract implements ContractInterface {
|
|
|
528
529
|
}, [] as Result);
|
|
529
530
|
}
|
|
530
531
|
|
|
531
|
-
public invoke(
|
|
532
|
+
public invoke(
|
|
533
|
+
method: string,
|
|
534
|
+
args: Array<any> = [],
|
|
535
|
+
options: Overrides = {}
|
|
536
|
+
): Promise<AddTransactionResponse> {
|
|
532
537
|
// ensure contract is connected
|
|
533
538
|
assert(this.address !== null, 'contract isnt connected to an address');
|
|
534
539
|
// validate method and args
|
|
@@ -542,11 +547,6 @@ export class Contract implements ContractInterface {
|
|
|
542
547
|
return acc;
|
|
543
548
|
}, 0);
|
|
544
549
|
|
|
545
|
-
const overrides: Overrides = {};
|
|
546
|
-
if (args.length === inputsLength + 1 && Array.isArray(args[args.length - 1])) {
|
|
547
|
-
Object.assign(overrides, args.pop());
|
|
548
|
-
}
|
|
549
|
-
|
|
550
550
|
if (args.length !== inputsLength) {
|
|
551
551
|
throw Error(
|
|
552
552
|
`Invalid number of arguments, expected ${inputsLength} arguments, but got ${args.length}`
|
|
@@ -562,31 +562,33 @@ export class Contract implements ContractInterface {
|
|
|
562
562
|
};
|
|
563
563
|
if ('execute' in this.providerOrAccount) {
|
|
564
564
|
return this.providerOrAccount.execute(invocation, undefined, {
|
|
565
|
-
maxFee:
|
|
566
|
-
nonce:
|
|
565
|
+
maxFee: options.maxFee,
|
|
566
|
+
nonce: options.nonce,
|
|
567
567
|
});
|
|
568
568
|
}
|
|
569
569
|
|
|
570
570
|
return this.providerOrAccount.invokeFunction({
|
|
571
571
|
...invocation,
|
|
572
|
-
signature:
|
|
572
|
+
signature: options.signature || [],
|
|
573
573
|
});
|
|
574
574
|
}
|
|
575
575
|
|
|
576
|
-
public async call(
|
|
576
|
+
public async call(
|
|
577
|
+
method: string,
|
|
578
|
+
args: Array<any> = [],
|
|
579
|
+
{
|
|
580
|
+
blockIdentifier = 'pending',
|
|
581
|
+
}: {
|
|
582
|
+
blockIdentifier?: BlockIdentifier;
|
|
583
|
+
} = {}
|
|
584
|
+
): Promise<Result> {
|
|
577
585
|
// ensure contract is connected
|
|
578
586
|
assert(this.address !== null, 'contract isnt connected to an address');
|
|
579
587
|
|
|
580
588
|
// validate method and args
|
|
581
589
|
this.validateMethodAndArgs('CALL', method, args);
|
|
582
590
|
const { inputs } = this.abi.find((abi) => abi.name === method) as FunctionAbi;
|
|
583
|
-
|
|
584
|
-
const options = {
|
|
585
|
-
blockIdentifier: null,
|
|
586
|
-
};
|
|
587
|
-
if (args.length === inputsLength + 1 && typeof args[args.length - 1] === 'object') {
|
|
588
|
-
Object.assign(options, args.pop());
|
|
589
|
-
}
|
|
591
|
+
|
|
590
592
|
// compile calldata
|
|
591
593
|
const calldata = this.compileCalldata(args, inputs);
|
|
592
594
|
return this.providerOrAccount
|
|
@@ -596,7 +598,7 @@ export class Contract implements ContractInterface {
|
|
|
596
598
|
calldata,
|
|
597
599
|
entrypoint: method,
|
|
598
600
|
},
|
|
599
|
-
|
|
601
|
+
{ blockIdentifier }
|
|
600
602
|
)
|
|
601
603
|
.then((x) => this.parseResponse(method, x.result));
|
|
602
604
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { AccountInterface } from '../account';
|
|
2
2
|
import { ProviderInterface } from '../provider';
|
|
3
|
+
import { BlockIdentifier } from '../provider/utils';
|
|
3
4
|
import {
|
|
4
5
|
Abi,
|
|
5
6
|
AddTransactionResponse,
|
|
6
7
|
AsyncContractFunction,
|
|
7
8
|
ContractFunction,
|
|
8
9
|
Invocation,
|
|
10
|
+
Overrides,
|
|
9
11
|
Result,
|
|
10
12
|
} from '../types';
|
|
11
13
|
|
|
@@ -57,7 +59,13 @@ export abstract class ContractInterface {
|
|
|
57
59
|
* @param args Array of the arguments for the call
|
|
58
60
|
* @returns Result of the call as an array with key value pars
|
|
59
61
|
*/
|
|
60
|
-
public abstract call(
|
|
62
|
+
public abstract call(
|
|
63
|
+
method: string,
|
|
64
|
+
args?: Array<any>,
|
|
65
|
+
options?: {
|
|
66
|
+
blockIdentifier?: BlockIdentifier;
|
|
67
|
+
}
|
|
68
|
+
): Promise<Result>;
|
|
61
69
|
|
|
62
70
|
/**
|
|
63
71
|
* Invokes a method on a contract
|
|
@@ -66,7 +74,11 @@ export abstract class ContractInterface {
|
|
|
66
74
|
* @param args Array of the arguments for the invoke
|
|
67
75
|
* @returns Add Transaction Response
|
|
68
76
|
*/
|
|
69
|
-
public abstract invoke(
|
|
77
|
+
public abstract invoke(
|
|
78
|
+
method: string,
|
|
79
|
+
args?: Array<any>,
|
|
80
|
+
options?: Overrides
|
|
81
|
+
): Promise<AddTransactionResponse>;
|
|
70
82
|
|
|
71
83
|
/**
|
|
72
84
|
* Calls a method on a contract
|
|
@@ -74,7 +86,13 @@ export abstract class ContractInterface {
|
|
|
74
86
|
* @param method name of the method
|
|
75
87
|
* @param args Array of the arguments for the call
|
|
76
88
|
*/
|
|
77
|
-
public abstract estimate(
|
|
89
|
+
public abstract estimate(
|
|
90
|
+
method: string,
|
|
91
|
+
args?: Array<any>,
|
|
92
|
+
options?: {
|
|
93
|
+
blockIdentifier?: BlockIdentifier;
|
|
94
|
+
}
|
|
95
|
+
): Promise<any>;
|
|
78
96
|
|
|
79
97
|
/**
|
|
80
98
|
* Calls a method on a contract
|
package/src/provider/default.ts
CHANGED
|
@@ -168,14 +168,18 @@ export class Provider implements ProviderInterface {
|
|
|
168
168
|
*/
|
|
169
169
|
public async callContract(
|
|
170
170
|
{ contractAddress, entrypoint, calldata = [] }: Call,
|
|
171
|
-
|
|
171
|
+
{ blockIdentifier = 'pending' }: { blockIdentifier?: BlockIdentifier } = {}
|
|
172
172
|
): Promise<CallContractResponse> {
|
|
173
|
-
return this.fetchEndpoint(
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
173
|
+
return this.fetchEndpoint(
|
|
174
|
+
'call_contract',
|
|
175
|
+
{ blockIdentifier },
|
|
176
|
+
{
|
|
177
|
+
signature: [],
|
|
178
|
+
contract_address: contractAddress,
|
|
179
|
+
entry_point_selector: getSelectorFromName(entrypoint),
|
|
180
|
+
calldata,
|
|
181
|
+
}
|
|
182
|
+
);
|
|
179
183
|
}
|
|
180
184
|
|
|
181
185
|
/**
|
|
@@ -203,7 +207,7 @@ export class Provider implements ProviderInterface {
|
|
|
203
207
|
*/
|
|
204
208
|
public async getCode(
|
|
205
209
|
contractAddress: string,
|
|
206
|
-
blockIdentifier: BlockIdentifier =
|
|
210
|
+
blockIdentifier: BlockIdentifier = 'pending'
|
|
207
211
|
): Promise<GetCodeResponse> {
|
|
208
212
|
return this.fetchEndpoint('get_code', { blockIdentifier, contractAddress });
|
|
209
213
|
}
|
|
@@ -223,7 +227,7 @@ export class Provider implements ProviderInterface {
|
|
|
223
227
|
public async getStorageAt(
|
|
224
228
|
contractAddress: string,
|
|
225
229
|
key: number,
|
|
226
|
-
blockIdentifier: BlockIdentifier =
|
|
230
|
+
blockIdentifier: BlockIdentifier = 'pending'
|
|
227
231
|
): Promise<object> {
|
|
228
232
|
return this.fetchEndpoint('get_storage_at', { blockIdentifier, contractAddress, key });
|
|
229
233
|
}
|
|
@@ -340,7 +344,6 @@ export class Provider implements ProviderInterface {
|
|
|
340
344
|
|
|
341
345
|
public async waitForTransaction(txHash: BigNumberish, retryInterval: number = 8000) {
|
|
342
346
|
let onchain = false;
|
|
343
|
-
await wait(retryInterval);
|
|
344
347
|
|
|
345
348
|
while (!onchain) {
|
|
346
349
|
// eslint-disable-next-line no-await-in-loop
|
|
@@ -348,9 +351,12 @@ export class Provider implements ProviderInterface {
|
|
|
348
351
|
// eslint-disable-next-line no-await-in-loop
|
|
349
352
|
const res = await this.getTransactionStatus(txHash);
|
|
350
353
|
|
|
351
|
-
|
|
354
|
+
const successStates = ['ACCEPTED_ON_L1', 'ACCEPTED_ON_L2', 'PENDING'];
|
|
355
|
+
const errorStates = ['REJECTED', 'NOT_RECEIVED'];
|
|
356
|
+
|
|
357
|
+
if (successStates.includes(res.tx_status)) {
|
|
352
358
|
onchain = true;
|
|
353
|
-
} else if (
|
|
359
|
+
} else if (errorStates.includes(res.tx_status)) {
|
|
354
360
|
const message = res.tx_failure_reason
|
|
355
361
|
? `${res.tx_status}: ${res.tx_failure_reason.code}\n${res.tx_failure_reason.error_message}`
|
|
356
362
|
: res.tx_status;
|
package/src/provider/utils.ts
CHANGED
|
@@ -43,6 +43,12 @@ type BlockIdentifierObject =
|
|
|
43
43
|
* @returns block identifier object
|
|
44
44
|
*/
|
|
45
45
|
export function getBlockIdentifier(blockIdentifier: BlockIdentifier): BlockIdentifierObject {
|
|
46
|
+
if (blockIdentifier === null) {
|
|
47
|
+
return { type: 'BLOCK_NUMBER', data: null };
|
|
48
|
+
}
|
|
49
|
+
if (blockIdentifier === 'pending') {
|
|
50
|
+
return { type: 'BLOCK_NUMBER', data: 'pending' };
|
|
51
|
+
}
|
|
46
52
|
if (typeof blockIdentifier === 'number') {
|
|
47
53
|
return { type: 'BLOCK_NUMBER', data: blockIdentifier };
|
|
48
54
|
}
|
|
@@ -52,12 +58,6 @@ export function getBlockIdentifier(blockIdentifier: BlockIdentifier): BlockIdent
|
|
|
52
58
|
if (typeof blockIdentifier === 'string' && !Number.isNaN(parseInt(blockIdentifier, 10))) {
|
|
53
59
|
return { type: 'BLOCK_NUMBER', data: parseInt(blockIdentifier, 10) };
|
|
54
60
|
}
|
|
55
|
-
if (blockIdentifier === null) {
|
|
56
|
-
return { type: 'BLOCK_NUMBER', data: null };
|
|
57
|
-
}
|
|
58
|
-
if (blockIdentifier === 'pending') {
|
|
59
|
-
return { type: 'BLOCK_NUMBER', data: 'pending' };
|
|
60
|
-
}
|
|
61
61
|
if (typeof blockIdentifier === 'string') {
|
|
62
62
|
throw new Error(`Invalid block identifier: ${blockIdentifier}`);
|
|
63
63
|
}
|
|
@@ -69,8 +69,7 @@ export function getBlockIdentifier(blockIdentifier: BlockIdentifier): BlockIdent
|
|
|
69
69
|
*
|
|
70
70
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L164-L173)
|
|
71
71
|
*
|
|
72
|
-
* @param
|
|
73
|
-
* @param blockHash
|
|
72
|
+
* @param blockIdentifier
|
|
74
73
|
* @returns block identifier for API request
|
|
75
74
|
*/
|
|
76
75
|
export function getFormattedBlockIdentifier(blockIdentifier: BlockIdentifier = null): string {
|
package/src/types/api.ts
CHANGED
package/types/api.d.ts
CHANGED