starknet 3.18.2 → 3.19.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 +53 -0
- package/__tests__/account.test.ts +11 -56
- package/__tests__/contract.test.ts +11 -49
- package/__tests__/defaultProvider.test.ts +321 -0
- package/__tests__/fixtures.ts +32 -11
- package/__tests__/rpcProvider.test.ts +17 -0
- package/__tests__/sequencerProvider.test.ts +45 -0
- package/account/default.d.ts +54 -77
- package/account/default.js +271 -596
- package/account/index.js +18 -31
- package/account/interface.d.ts +66 -95
- package/account/interface.js +20 -30
- package/constants.d.ts +17 -19
- package/constants.js +2038 -2059
- package/contract/contractFactory.d.ts +25 -29
- package/contract/contractFactory.js +94 -210
- package/contract/default.d.ts +117 -146
- package/contract/default.js +582 -776
- package/contract/index.js +19 -32
- package/contract/interface.d.ts +72 -92
- package/contract/interface.js +6 -5
- package/dist/account/default.d.ts +5 -9
- package/dist/account/default.js +35 -169
- package/dist/account/interface.d.ts +3 -15
- package/dist/contract/contractFactory.js +4 -4
- package/dist/contract/default.d.ts +3 -3
- package/dist/contract/default.js +3 -2
- package/dist/contract/interface.d.ts +2 -2
- package/dist/provider/default.d.ts +18 -134
- package/dist/provider/default.js +47 -411
- package/dist/provider/index.d.ts +2 -0
- package/dist/provider/index.js +2 -0
- package/dist/provider/interface.d.ts +45 -50
- package/dist/provider/rpc.d.ts +57 -0
- package/dist/provider/rpc.js +364 -0
- package/dist/provider/sequencer.d.ts +66 -0
- package/dist/provider/sequencer.js +443 -0
- package/dist/types/account.d.ts +2 -3
- package/dist/types/api/index.d.ts +16 -0
- package/dist/types/api/index.js +18 -0
- package/dist/types/api/rpc.d.ts +221 -0
- package/dist/types/{api.js → api/rpc.js} +0 -0
- package/dist/types/api/sequencer.d.ts +289 -0
- package/dist/types/api/sequencer.js +2 -0
- package/dist/types/index.d.ts +3 -1
- package/dist/types/index.js +15 -1
- package/dist/types/lib.d.ts +3 -1
- package/dist/types/provider.d.ts +86 -0
- package/dist/types/provider.js +2 -0
- package/dist/utils/provider.d.ts +4 -0
- package/dist/utils/provider.js +38 -0
- package/dist/utils/responseParser/index.d.ts +11 -0
- package/dist/utils/responseParser/index.js +9 -0
- package/dist/utils/responseParser/rpc.d.ts +13 -0
- package/dist/utils/responseParser/rpc.js +96 -0
- package/dist/utils/responseParser/sequencer.d.ts +13 -0
- package/dist/utils/responseParser/sequencer.js +124 -0
- package/index.js +42 -75
- package/package.json +1 -1
- package/provider/default.d.ts +21 -175
- package/provider/default.js +139 -704
- package/provider/errors.d.ts +4 -4
- package/provider/errors.js +30 -40
- package/provider/index.d.ts +2 -0
- package/provider/index.js +22 -33
- package/provider/interface.d.ts +104 -131
- package/provider/interface.js +6 -5
- package/provider/rpc.d.ts +57 -0
- package/provider/rpc.js +364 -0
- package/provider/sequencer.d.ts +66 -0
- package/provider/sequencer.js +443 -0
- package/provider/utils.d.ts +7 -9
- package/provider/utils.js +39 -44
- package/signer/default.d.ts +5 -9
- package/signer/default.js +72 -177
- package/signer/index.js +18 -31
- package/signer/interface.d.ts +29 -33
- package/signer/interface.js +6 -5
- package/src/account/default.ts +26 -146
- package/src/account/interface.ts +5 -20
- package/src/contract/contractFactory.ts +3 -6
- package/src/contract/default.ts +6 -4
- package/src/contract/interface.ts +2 -2
- package/src/provider/default.ts +63 -395
- package/src/provider/index.ts +2 -0
- package/src/provider/interface.ts +68 -63
- package/src/provider/rpc.ts +300 -0
- package/src/provider/sequencer.ts +384 -0
- package/src/types/account.ts +2 -3
- package/src/types/api/index.ts +17 -0
- package/src/types/api/rpc.ts +247 -0
- package/src/types/api/sequencer.ts +331 -0
- package/src/types/index.ts +3 -1
- package/src/types/lib.ts +3 -1
- package/src/types/provider.ts +108 -0
- package/src/utils/provider.ts +28 -0
- package/src/utils/responseParser/index.ts +28 -0
- package/src/utils/responseParser/rpc.ts +93 -0
- package/src/utils/responseParser/sequencer.ts +127 -0
- package/types/account.d.ts +5 -7
- package/types/account.js +2 -2
- package/types/api/index.d.ts +16 -0
- package/types/api/index.js +18 -0
- package/types/api/rpc.d.ts +221 -0
- package/types/api/rpc.js +2 -0
- package/types/api/sequencer.d.ts +289 -0
- package/types/api/sequencer.js +2 -0
- package/types/contract.d.ts +1 -1
- package/types/contract.js +2 -2
- package/types/index.d.ts +3 -1
- package/types/index.js +35 -34
- package/types/lib.d.ts +36 -41
- package/types/lib.js +2 -2
- package/types/provider.d.ts +86 -0
- package/types/provider.js +2 -0
- package/types/signer.d.ts +2 -2
- package/types/signer.js +2 -2
- package/utils/address.js +26 -37
- package/utils/ellipticCurve.d.ts +1 -6
- package/utils/ellipticCurve.js +73 -137
- package/utils/encode.js +49 -85
- package/utils/hash.d.ts +4 -31
- package/utils/hash.js +76 -141
- package/utils/json.d.ts +13 -45
- package/utils/json.js +15 -22
- package/utils/number.d.ts +2 -9
- package/utils/number.js +47 -81
- package/utils/provider.d.ts +4 -0
- package/utils/provider.js +38 -0
- package/utils/responseParser/index.d.ts +11 -0
- package/utils/responseParser/index.js +9 -0
- package/utils/responseParser/rpc.d.ts +13 -0
- package/utils/responseParser/rpc.js +96 -0
- package/utils/responseParser/sequencer.d.ts +13 -0
- package/utils/responseParser/sequencer.js +124 -0
- package/utils/shortString.js +13 -21
- package/utils/stark.d.ts +0 -1
- package/utils/stark.js +59 -93
- package/utils/transaction.d.ts +3 -6
- package/utils/transaction.js +50 -81
- package/utils/typedData/index.d.ts +3 -15
- package/utils/typedData/index.js +109 -175
- package/utils/typedData/types.d.ts +9 -9
- package/utils/typedData/types.js +2 -2
- package/utils/typedData/utils.js +6 -6
- package/utils/uint256.d.ts +5 -5
- package/utils/uint256.js +16 -26
- package/www/docs/API/account.md +3 -4
- package/www/docs/API/contract.md +2 -2
- package/www/docs/API/contractFactory.md +2 -2
- package/www/docs/API/provider.md +185 -74
- package/www/guides/account.md +1 -8
- package/www/guides/erc20.md +3 -0
- package/__tests__/provider.test.ts +0 -168
- package/dist/types/api.d.ts +0 -261
- package/src/types/api.ts +0 -303
- package/types/api.d.ts +0 -287
- package/types/api.js +0 -2
package/contract/default.js
CHANGED
|
@@ -1,846 +1,652 @@
|
|
|
1
|
-
|
|
2
|
-
var __assign =
|
|
3
|
-
|
|
4
|
-
function () {
|
|
5
|
-
__assign =
|
|
6
|
-
Object.assign ||
|
|
7
|
-
function (t) {
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
8
4
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
11
8
|
}
|
|
12
9
|
return t;
|
|
13
|
-
|
|
10
|
+
};
|
|
14
11
|
return __assign.apply(this, arguments);
|
|
15
|
-
|
|
16
|
-
var __awaiter =
|
|
17
|
-
|
|
18
|
-
function (thisArg, _arguments, P, generator) {
|
|
19
|
-
function adopt(value) {
|
|
20
|
-
return value instanceof P
|
|
21
|
-
? value
|
|
22
|
-
: new P(function (resolve) {
|
|
23
|
-
resolve(value);
|
|
24
|
-
});
|
|
25
|
-
}
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
26
15
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
reject(e);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function rejected(value) {
|
|
35
|
-
try {
|
|
36
|
-
step(generator['throw'](value));
|
|
37
|
-
} catch (e) {
|
|
38
|
-
reject(e);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function step(result) {
|
|
42
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
43
|
-
}
|
|
44
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
45
20
|
});
|
|
46
|
-
|
|
47
|
-
var __generator =
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
label: 0,
|
|
52
|
-
sent: function () {
|
|
53
|
-
if (t[0] & 1) throw t[1];
|
|
54
|
-
return t[1];
|
|
55
|
-
},
|
|
56
|
-
trys: [],
|
|
57
|
-
ops: [],
|
|
58
|
-
},
|
|
59
|
-
f,
|
|
60
|
-
y,
|
|
61
|
-
t,
|
|
62
|
-
g;
|
|
63
|
-
return (
|
|
64
|
-
(g = { next: verb(0), throw: verb(1), return: verb(2) }),
|
|
65
|
-
typeof Symbol === 'function' &&
|
|
66
|
-
(g[Symbol.iterator] = function () {
|
|
67
|
-
return this;
|
|
68
|
-
}),
|
|
69
|
-
g
|
|
70
|
-
);
|
|
71
|
-
function verb(n) {
|
|
72
|
-
return function (v) {
|
|
73
|
-
return step([n, v]);
|
|
74
|
-
};
|
|
75
|
-
}
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
76
26
|
function step(op) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
op[0]
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
break;
|
|
98
|
-
case 4:
|
|
99
|
-
_.label++;
|
|
100
|
-
return { value: op[1], done: false };
|
|
101
|
-
case 5:
|
|
102
|
-
_.label++;
|
|
103
|
-
y = op[1];
|
|
104
|
-
op = [0];
|
|
105
|
-
continue;
|
|
106
|
-
case 7:
|
|
107
|
-
op = _.ops.pop();
|
|
108
|
-
_.trys.pop();
|
|
109
|
-
continue;
|
|
110
|
-
default:
|
|
111
|
-
if (
|
|
112
|
-
!((t = _.trys), (t = t.length > 0 && t[t.length - 1])) &&
|
|
113
|
-
(op[0] === 6 || op[0] === 2)
|
|
114
|
-
) {
|
|
115
|
-
_ = 0;
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
|
|
119
|
-
_.label = op[1];
|
|
120
|
-
break;
|
|
121
|
-
}
|
|
122
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
123
|
-
_.label = t[1];
|
|
124
|
-
t = op;
|
|
125
|
-
break;
|
|
126
|
-
}
|
|
127
|
-
if (t && _.label < t[2]) {
|
|
128
|
-
_.label = t[2];
|
|
129
|
-
_.ops.push(op);
|
|
130
|
-
break;
|
|
131
|
-
}
|
|
132
|
-
if (t[2]) _.ops.pop();
|
|
133
|
-
_.trys.pop();
|
|
134
|
-
continue;
|
|
135
|
-
}
|
|
136
|
-
op = body.call(thisArg, _);
|
|
137
|
-
} catch (e) {
|
|
138
|
-
op = [6, e];
|
|
139
|
-
y = 0;
|
|
140
|
-
} finally {
|
|
141
|
-
f = t = 0;
|
|
142
|
-
}
|
|
143
|
-
if (op[0] & 5) throw op[1];
|
|
144
|
-
return { value: op[0] ? op[1] : void 0, done: true };
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (_) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
145
47
|
}
|
|
146
|
-
|
|
147
|
-
var __read =
|
|
148
|
-
|
|
149
|
-
function (o, n) {
|
|
150
|
-
var m = typeof Symbol === 'function' && o[Symbol.iterator];
|
|
48
|
+
};
|
|
49
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
50
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
151
51
|
if (!m) return o;
|
|
152
|
-
var i = m.call(o),
|
|
153
|
-
r,
|
|
154
|
-
ar = [],
|
|
155
|
-
e;
|
|
52
|
+
var i = m.call(o), r, ar = [], e;
|
|
156
53
|
try {
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
if (e) throw e.error;
|
|
165
|
-
}
|
|
54
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
55
|
+
}
|
|
56
|
+
catch (error) { e = { error: error }; }
|
|
57
|
+
finally {
|
|
58
|
+
try {
|
|
59
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
60
|
+
}
|
|
61
|
+
finally { if (e) throw e.error; }
|
|
166
62
|
}
|
|
167
63
|
return ar;
|
|
168
|
-
|
|
169
|
-
var __spreadArray =
|
|
170
|
-
|
|
171
|
-
function (to, from, pack) {
|
|
172
|
-
if (pack || arguments.length === 2)
|
|
173
|
-
for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
64
|
+
};
|
|
65
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
66
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
174
67
|
if (ar || !(i in from)) {
|
|
175
|
-
|
|
176
|
-
|
|
68
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
69
|
+
ar[i] = from[i];
|
|
177
70
|
}
|
|
178
|
-
|
|
71
|
+
}
|
|
179
72
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
180
|
-
|
|
181
|
-
var __importDefault =
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
};
|
|
186
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
73
|
+
};
|
|
74
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
75
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
76
|
+
};
|
|
77
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
187
78
|
exports.Contract = void 0;
|
|
188
|
-
var bn_js_1 = __importDefault(require(
|
|
189
|
-
var minimalistic_assert_1 = __importDefault(require(
|
|
190
|
-
var provider_1 = require(
|
|
191
|
-
var number_1 = require(
|
|
79
|
+
var bn_js_1 = __importDefault(require("bn.js"));
|
|
80
|
+
var minimalistic_assert_1 = __importDefault(require("minimalistic-assert"));
|
|
81
|
+
var provider_1 = require("../provider");
|
|
82
|
+
var number_1 = require("../utils/number");
|
|
192
83
|
function parseFelt(candidate) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
84
|
+
try {
|
|
85
|
+
return (0, number_1.toBN)(candidate);
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
88
|
+
throw Error('Couldnt parse felt');
|
|
89
|
+
}
|
|
198
90
|
}
|
|
199
91
|
/**
|
|
200
92
|
* Adds call methods to the contract
|
|
201
93
|
*
|
|
202
94
|
*/
|
|
203
95
|
function buildCall(contract, functionAbi) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
96
|
+
return function () {
|
|
97
|
+
var args = [];
|
|
98
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
99
|
+
args[_i] = arguments[_i];
|
|
100
|
+
}
|
|
101
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
102
|
+
return __generator(this, function (_a) {
|
|
103
|
+
return [2 /*return*/, contract.call(functionAbi.name, args)];
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
};
|
|
215
107
|
}
|
|
216
108
|
/**
|
|
217
109
|
* Adds invoke methods to the contract
|
|
218
110
|
*
|
|
219
111
|
*/
|
|
220
112
|
function buildInvoke(contract, functionAbi) {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}
|
|
226
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
227
|
-
var inputs, inputsLength, options;
|
|
228
|
-
return __generator(this, function (_a) {
|
|
229
|
-
inputs = functionAbi.inputs;
|
|
230
|
-
inputsLength = inputs.reduce(function (acc, input) {
|
|
231
|
-
if (!/_len$/.test(input.name)) {
|
|
232
|
-
return acc + 1;
|
|
233
|
-
}
|
|
234
|
-
return acc;
|
|
235
|
-
}, 0);
|
|
236
|
-
options = {};
|
|
237
|
-
if (inputsLength + 1 === args.length && typeof args[args.length - 1] === 'object') {
|
|
238
|
-
Object.assign(options, args.pop());
|
|
113
|
+
return function () {
|
|
114
|
+
var args = [];
|
|
115
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
116
|
+
args[_i] = arguments[_i];
|
|
239
117
|
}
|
|
240
|
-
return
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
118
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
119
|
+
var inputs, inputsLength, options;
|
|
120
|
+
return __generator(this, function (_a) {
|
|
121
|
+
inputs = functionAbi.inputs;
|
|
122
|
+
inputsLength = inputs.reduce(function (acc, input) {
|
|
123
|
+
if (!/_len$/.test(input.name)) {
|
|
124
|
+
return acc + 1;
|
|
125
|
+
}
|
|
126
|
+
return acc;
|
|
127
|
+
}, 0);
|
|
128
|
+
options = {};
|
|
129
|
+
if (inputsLength + 1 === args.length && typeof args[args.length - 1] === 'object') {
|
|
130
|
+
Object.assign(options, args.pop());
|
|
131
|
+
}
|
|
132
|
+
return [2 /*return*/, contract.invoke(functionAbi.name, args, options)];
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
};
|
|
244
136
|
}
|
|
245
137
|
/**
|
|
246
138
|
* Adds call/invoke methods to the contract
|
|
247
139
|
*
|
|
248
140
|
*/
|
|
249
141
|
function buildDefault(contract, functionAbi) {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
142
|
+
if (functionAbi.stateMutability === 'view') {
|
|
143
|
+
return buildCall(contract, functionAbi);
|
|
144
|
+
}
|
|
145
|
+
return buildInvoke(contract, functionAbi);
|
|
254
146
|
}
|
|
255
147
|
/**
|
|
256
148
|
* Adds populate for methods to the contract
|
|
257
149
|
*
|
|
258
150
|
*/
|
|
259
151
|
function buildPopulate(contract, functionAbi) {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
152
|
+
return function () {
|
|
153
|
+
var args = [];
|
|
154
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
155
|
+
args[_i] = arguments[_i];
|
|
156
|
+
}
|
|
157
|
+
return contract.populate(functionAbi.name, args);
|
|
158
|
+
};
|
|
267
159
|
}
|
|
268
160
|
/**
|
|
269
161
|
* Adds estimateFee for methods to the contract
|
|
270
162
|
*
|
|
271
163
|
*/
|
|
272
164
|
function buildEstimate(contract, functionAbi) {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
165
|
+
return function () {
|
|
166
|
+
var args = [];
|
|
167
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
168
|
+
args[_i] = arguments[_i];
|
|
169
|
+
}
|
|
170
|
+
return contract.estimate(functionAbi.name, args);
|
|
171
|
+
};
|
|
280
172
|
}
|
|
281
173
|
var Contract = /** @class */ (function () {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
Object.defineProperty(this, 'functions', {
|
|
306
|
-
enumerable: true,
|
|
307
|
-
value: {},
|
|
308
|
-
writable: false,
|
|
309
|
-
});
|
|
310
|
-
Object.defineProperty(this, 'callStatic', {
|
|
311
|
-
enumerable: true,
|
|
312
|
-
value: {},
|
|
313
|
-
writable: false,
|
|
314
|
-
});
|
|
315
|
-
Object.defineProperty(this, 'populateTransaction', {
|
|
316
|
-
enumerable: true,
|
|
317
|
-
value: {},
|
|
318
|
-
writable: false,
|
|
319
|
-
});
|
|
320
|
-
Object.defineProperty(this, 'estimateFee', {
|
|
321
|
-
enumerable: true,
|
|
322
|
-
value: {},
|
|
323
|
-
writable: false,
|
|
324
|
-
});
|
|
325
|
-
this.abi.forEach(function (abiElement) {
|
|
326
|
-
if (abiElement.type !== 'function') {
|
|
327
|
-
return;
|
|
328
|
-
}
|
|
329
|
-
var signature = abiElement.name;
|
|
330
|
-
if (!_this[signature]) {
|
|
331
|
-
Object.defineProperty(_this, signature, {
|
|
332
|
-
enumerable: true,
|
|
333
|
-
value: buildDefault(_this, abiElement),
|
|
334
|
-
writable: false,
|
|
174
|
+
/**
|
|
175
|
+
* Contract class to handle contract methods
|
|
176
|
+
*
|
|
177
|
+
* @param abi - Abi of the contract object
|
|
178
|
+
* @param address (optional) - address to connect to
|
|
179
|
+
* @param providerOrAccount (optional) - Provider or Account to attach to
|
|
180
|
+
*/
|
|
181
|
+
function Contract(abi, address, providerOrAccount) {
|
|
182
|
+
if (providerOrAccount === void 0) { providerOrAccount = provider_1.defaultProvider; }
|
|
183
|
+
var _this = this;
|
|
184
|
+
this.address = address;
|
|
185
|
+
this.providerOrAccount = providerOrAccount;
|
|
186
|
+
this.abi = abi;
|
|
187
|
+
this.structs = abi
|
|
188
|
+
.filter(function (abiEntry) { return abiEntry.type === 'struct'; })
|
|
189
|
+
.reduce(function (acc, abiEntry) {
|
|
190
|
+
var _a;
|
|
191
|
+
return (__assign(__assign({}, acc), (_a = {}, _a[abiEntry.name] = abiEntry, _a)));
|
|
192
|
+
}, {});
|
|
193
|
+
Object.defineProperty(this, 'functions', {
|
|
194
|
+
enumerable: true,
|
|
195
|
+
value: {},
|
|
196
|
+
writable: false,
|
|
335
197
|
});
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
value: buildDefault(_this, abiElement),
|
|
341
|
-
writable: false,
|
|
198
|
+
Object.defineProperty(this, 'callStatic', {
|
|
199
|
+
enumerable: true,
|
|
200
|
+
value: {},
|
|
201
|
+
writable: false,
|
|
342
202
|
});
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
value: buildCall(_this, abiElement),
|
|
348
|
-
writable: false,
|
|
203
|
+
Object.defineProperty(this, 'populateTransaction', {
|
|
204
|
+
enumerable: true,
|
|
205
|
+
value: {},
|
|
206
|
+
writable: false,
|
|
349
207
|
});
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
value: buildPopulate(_this, abiElement),
|
|
355
|
-
writable: false,
|
|
208
|
+
Object.defineProperty(this, 'estimateFee', {
|
|
209
|
+
enumerable: true,
|
|
210
|
+
value: {},
|
|
211
|
+
writable: false,
|
|
356
212
|
});
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
213
|
+
this.abi.forEach(function (abiElement) {
|
|
214
|
+
if (abiElement.type !== 'function') {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
var signature = abiElement.name;
|
|
218
|
+
if (!_this[signature]) {
|
|
219
|
+
Object.defineProperty(_this, signature, {
|
|
220
|
+
enumerable: true,
|
|
221
|
+
value: buildDefault(_this, abiElement),
|
|
222
|
+
writable: false,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
if (!_this.functions[signature]) {
|
|
226
|
+
Object.defineProperty(_this.functions, signature, {
|
|
227
|
+
enumerable: true,
|
|
228
|
+
value: buildDefault(_this, abiElement),
|
|
229
|
+
writable: false,
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
if (!_this.callStatic[signature]) {
|
|
233
|
+
Object.defineProperty(_this.callStatic, signature, {
|
|
234
|
+
enumerable: true,
|
|
235
|
+
value: buildCall(_this, abiElement),
|
|
236
|
+
writable: false,
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
if (!_this.populateTransaction[signature]) {
|
|
240
|
+
Object.defineProperty(_this.populateTransaction, signature, {
|
|
241
|
+
enumerable: true,
|
|
242
|
+
value: buildPopulate(_this, abiElement),
|
|
243
|
+
writable: false,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
if (!_this.estimateFee[signature]) {
|
|
247
|
+
Object.defineProperty(_this.estimateFee, signature, {
|
|
248
|
+
enumerable: true,
|
|
249
|
+
value: buildEstimate(_this, abiElement),
|
|
250
|
+
writable: false,
|
|
251
|
+
});
|
|
252
|
+
}
|
|
363
253
|
});
|
|
364
|
-
}
|
|
365
|
-
});
|
|
366
|
-
}
|
|
367
|
-
/**
|
|
368
|
-
* Saves the address of the contract deployed on network that will be used for interaction
|
|
369
|
-
*
|
|
370
|
-
* @param address - address of the contract
|
|
371
|
-
*/
|
|
372
|
-
Contract.prototype.attach = function (address) {
|
|
373
|
-
this.address = address;
|
|
374
|
-
};
|
|
375
|
-
/**
|
|
376
|
-
* Attaches to new Provider or Account
|
|
377
|
-
*
|
|
378
|
-
* @param providerOrAccount - new Provider or Account to attach to
|
|
379
|
-
*/
|
|
380
|
-
Contract.prototype.connect = function (providerOrAccount) {
|
|
381
|
-
this.providerOrAccount = providerOrAccount;
|
|
382
|
-
};
|
|
383
|
-
/**
|
|
384
|
-
* Resolves when contract is deployed on the network or when no deployment transaction is found
|
|
385
|
-
*
|
|
386
|
-
* @returns Promise that resolves when contract is deployed on the network or when no deployment transaction is found
|
|
387
|
-
* @throws When deployment fails
|
|
388
|
-
*/
|
|
389
|
-
Contract.prototype.deployed = function () {
|
|
390
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
391
|
-
return __generator(this, function (_a) {
|
|
392
|
-
switch (_a.label) {
|
|
393
|
-
case 0:
|
|
394
|
-
if (!this.deployTransactionHash) return [3 /*break*/, 2];
|
|
395
|
-
return [
|
|
396
|
-
4 /*yield*/,
|
|
397
|
-
this.providerOrAccount.waitForTransaction(this.deployTransactionHash),
|
|
398
|
-
];
|
|
399
|
-
case 1:
|
|
400
|
-
_a.sent();
|
|
401
|
-
this.deployTransactionHash = undefined;
|
|
402
|
-
_a.label = 2;
|
|
403
|
-
case 2:
|
|
404
|
-
return [2 /*return*/, this];
|
|
405
|
-
}
|
|
406
|
-
});
|
|
407
|
-
});
|
|
408
|
-
};
|
|
409
|
-
/**
|
|
410
|
-
* Validates if all arguments that are passed to the method are corresponding to the ones in the abi
|
|
411
|
-
*
|
|
412
|
-
* @param type - type of the method
|
|
413
|
-
* @param method - name of the method
|
|
414
|
-
* @param args - arguments that are passed to the method
|
|
415
|
-
*/
|
|
416
|
-
Contract.prototype.validateMethodAndArgs = function (type, method, args) {
|
|
417
|
-
var _this = this;
|
|
418
|
-
if (args === void 0) {
|
|
419
|
-
args = [];
|
|
420
254
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
)
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
args[argPosition].length === structMembersLength,
|
|
457
|
-
'arg should be of length '.concat(structMembersLength)
|
|
458
|
-
);
|
|
459
|
-
} else {
|
|
460
|
-
_this.structs[input.type].members.forEach(function (_a) {
|
|
461
|
-
var name = _a.name;
|
|
462
|
-
(0,
|
|
463
|
-
minimalistic_assert_1.default)(Object.keys(args[argPosition]).includes(name), 'arg should have a property '.concat(name));
|
|
464
|
-
});
|
|
465
|
-
}
|
|
466
|
-
argPosition += 1;
|
|
467
|
-
} else {
|
|
468
|
-
(0, minimalistic_assert_1.default)(
|
|
469
|
-
Array.isArray(args[argPosition]),
|
|
470
|
-
'arg '.concat(input.name, ' should be an Array')
|
|
471
|
-
);
|
|
472
|
-
if (input.type === 'felt*') {
|
|
473
|
-
args[argPosition].forEach(function (felt) {
|
|
474
|
-
(0,
|
|
475
|
-
minimalistic_assert_1.default)(typeof felt === 'string' || typeof felt === 'number' || felt instanceof bn_js_1.default, 'arg '.concat(input.name, ' should be an array of string, number or BigNumber'));
|
|
476
|
-
});
|
|
477
|
-
argPosition += 1;
|
|
478
|
-
} else if (/\(felt/.test(input.type)) {
|
|
479
|
-
var tupleLength = input.type.split(',').length;
|
|
480
|
-
(0, minimalistic_assert_1.default)(
|
|
481
|
-
args[argPosition].length === tupleLength,
|
|
482
|
-
'arg '.concat(input.name, ' should have ').concat(tupleLength, ' elements in tuple')
|
|
483
|
-
);
|
|
484
|
-
args[argPosition].forEach(function (felt) {
|
|
485
|
-
(0,
|
|
486
|
-
minimalistic_assert_1.default)(typeof felt === 'string' || typeof felt === 'number' || felt instanceof bn_js_1.default, 'arg '.concat(input.name, ' should be an array of string, number or BigNumber'));
|
|
487
|
-
});
|
|
488
|
-
argPosition += 1;
|
|
489
|
-
} else {
|
|
490
|
-
var arrayType_1 = input.type.replace('*', '');
|
|
491
|
-
args[argPosition].forEach(function (struct) {
|
|
492
|
-
_this.structs[arrayType_1].members.forEach(function (_a) {
|
|
493
|
-
var name = _a.name;
|
|
494
|
-
if (Array.isArray(struct)) {
|
|
495
|
-
var structMembersLength = _this.calculateStructMembers(arrayType_1);
|
|
496
|
-
(0, minimalistic_assert_1.default)(
|
|
497
|
-
struct.length === structMembersLength,
|
|
498
|
-
'arg should be of length '.concat(structMembersLength)
|
|
499
|
-
);
|
|
500
|
-
} else {
|
|
501
|
-
(0, minimalistic_assert_1.default)(
|
|
502
|
-
Object.keys(struct).includes(name),
|
|
503
|
-
'arg '.concat(input.name, ' should be an array of ').concat(arrayType_1)
|
|
504
|
-
);
|
|
505
|
-
}
|
|
255
|
+
/**
|
|
256
|
+
* Saves the address of the contract deployed on network that will be used for interaction
|
|
257
|
+
*
|
|
258
|
+
* @param address - address of the contract
|
|
259
|
+
*/
|
|
260
|
+
Contract.prototype.attach = function (address) {
|
|
261
|
+
this.address = address;
|
|
262
|
+
};
|
|
263
|
+
/**
|
|
264
|
+
* Attaches to new Provider or Account
|
|
265
|
+
*
|
|
266
|
+
* @param providerOrAccount - new Provider or Account to attach to
|
|
267
|
+
*/
|
|
268
|
+
Contract.prototype.connect = function (providerOrAccount) {
|
|
269
|
+
this.providerOrAccount = providerOrAccount;
|
|
270
|
+
};
|
|
271
|
+
/**
|
|
272
|
+
* Resolves when contract is deployed on the network or when no deployment transaction is found
|
|
273
|
+
*
|
|
274
|
+
* @returns Promise that resolves when contract is deployed on the network or when no deployment transaction is found
|
|
275
|
+
* @throws When deployment fails
|
|
276
|
+
*/
|
|
277
|
+
Contract.prototype.deployed = function () {
|
|
278
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
279
|
+
return __generator(this, function (_a) {
|
|
280
|
+
switch (_a.label) {
|
|
281
|
+
case 0:
|
|
282
|
+
if (!this.deployTransactionHash) return [3 /*break*/, 2];
|
|
283
|
+
return [4 /*yield*/, this.providerOrAccount.waitForTransaction(this.deployTransactionHash)];
|
|
284
|
+
case 1:
|
|
285
|
+
_a.sent();
|
|
286
|
+
this.deployTransactionHash = undefined;
|
|
287
|
+
_a.label = 2;
|
|
288
|
+
case 2: return [2 /*return*/, this];
|
|
289
|
+
}
|
|
506
290
|
});
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
291
|
+
});
|
|
292
|
+
};
|
|
293
|
+
/**
|
|
294
|
+
* Validates if all arguments that are passed to the method are corresponding to the ones in the abi
|
|
295
|
+
*
|
|
296
|
+
* @param type - type of the method
|
|
297
|
+
* @param method - name of the method
|
|
298
|
+
* @param args - arguments that are passed to the method
|
|
299
|
+
*/
|
|
300
|
+
Contract.prototype.validateMethodAndArgs = function (type, method, args) {
|
|
301
|
+
var _this = this;
|
|
302
|
+
if (args === void 0) { args = []; }
|
|
303
|
+
// ensure provided method exists
|
|
304
|
+
var invokeableFunctionNames = this.abi
|
|
305
|
+
.filter(function (abi) {
|
|
306
|
+
if (abi.type !== 'function')
|
|
307
|
+
return false;
|
|
308
|
+
var isView = abi.stateMutability === 'view';
|
|
309
|
+
return type === 'INVOKE' ? !isView : isView;
|
|
310
|
+
})
|
|
311
|
+
.map(function (abi) { return abi.name; });
|
|
312
|
+
(0, minimalistic_assert_1.default)(invokeableFunctionNames.includes(method), "".concat(type === 'INVOKE' ? 'invokeable' : 'viewable', " method not found in abi"));
|
|
313
|
+
// ensure args match abi type
|
|
314
|
+
var methodAbi = this.abi.find(function (abi) { return abi.name === method && abi.type === 'function'; });
|
|
315
|
+
var argPosition = 0;
|
|
316
|
+
methodAbi.inputs.forEach(function (input) {
|
|
317
|
+
if (/_len$/.test(input.name)) {
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
if (input.type === 'felt') {
|
|
321
|
+
(0, minimalistic_assert_1.default)(typeof args[argPosition] === 'string' ||
|
|
322
|
+
typeof args[argPosition] === 'number' ||
|
|
323
|
+
args[argPosition] instanceof bn_js_1.default, "arg ".concat(input.name, " should be a felt (string, number, BigNumber)"));
|
|
324
|
+
argPosition += 1;
|
|
325
|
+
}
|
|
326
|
+
else if (input.type in _this.structs && typeof args[argPosition] === 'object') {
|
|
327
|
+
if (Array.isArray(args[argPosition])) {
|
|
328
|
+
var structMembersLength = _this.calculateStructMembers(input.type);
|
|
329
|
+
(0, minimalistic_assert_1.default)(args[argPosition].length === structMembersLength, "arg should be of length ".concat(structMembersLength));
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
_this.structs[input.type].members.forEach(function (_a) {
|
|
333
|
+
var name = _a.name;
|
|
334
|
+
(0, minimalistic_assert_1.default)(Object.keys(args[argPosition]).includes(name), "arg should have a property ".concat(name));
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
argPosition += 1;
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
(0, minimalistic_assert_1.default)(Array.isArray(args[argPosition]), "arg ".concat(input.name, " should be an Array"));
|
|
341
|
+
if (input.type === 'felt*') {
|
|
342
|
+
args[argPosition].forEach(function (felt) {
|
|
343
|
+
(0, minimalistic_assert_1.default)(typeof felt === 'string' || typeof felt === 'number' || felt instanceof bn_js_1.default, "arg ".concat(input.name, " should be an array of string, number or BigNumber"));
|
|
344
|
+
});
|
|
345
|
+
argPosition += 1;
|
|
346
|
+
}
|
|
347
|
+
else if (/\(felt/.test(input.type)) {
|
|
348
|
+
var tupleLength = input.type.split(',').length;
|
|
349
|
+
(0, minimalistic_assert_1.default)(args[argPosition].length === tupleLength, "arg ".concat(input.name, " should have ").concat(tupleLength, " elements in tuple"));
|
|
350
|
+
args[argPosition].forEach(function (felt) {
|
|
351
|
+
(0, minimalistic_assert_1.default)(typeof felt === 'string' || typeof felt === 'number' || felt instanceof bn_js_1.default, "arg ".concat(input.name, " should be an array of string, number or BigNumber"));
|
|
352
|
+
});
|
|
353
|
+
argPosition += 1;
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
var arrayType_1 = input.type.replace('*', '');
|
|
357
|
+
args[argPosition].forEach(function (struct) {
|
|
358
|
+
_this.structs[arrayType_1].members.forEach(function (_a) {
|
|
359
|
+
var name = _a.name;
|
|
360
|
+
if (Array.isArray(struct)) {
|
|
361
|
+
var structMembersLength = _this.calculateStructMembers(arrayType_1);
|
|
362
|
+
(0, minimalistic_assert_1.default)(struct.length === structMembersLength, "arg should be of length ".concat(structMembersLength));
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
(0, minimalistic_assert_1.default)(Object.keys(struct).includes(name), "arg ".concat(input.name, " should be an array of ").concat(arrayType_1));
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
argPosition += 1;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
};
|
|
374
|
+
/**
|
|
375
|
+
* Deep parse of the object that has been passed to the method
|
|
376
|
+
*
|
|
377
|
+
* @param struct - struct that needs to be calculated
|
|
378
|
+
* @return {number} - number of members for the given struct
|
|
379
|
+
*/
|
|
380
|
+
Contract.prototype.calculateStructMembers = function (struct) {
|
|
381
|
+
var _this = this;
|
|
382
|
+
return this.structs[struct].members.reduce(function (acc, member) {
|
|
383
|
+
if (member.type === 'felt') {
|
|
384
|
+
return acc + 1;
|
|
385
|
+
}
|
|
386
|
+
return acc + _this.calculateStructMembers(member.type);
|
|
387
|
+
}, 0);
|
|
388
|
+
};
|
|
389
|
+
/**
|
|
390
|
+
* Deep parse of the object that has been passed to the method
|
|
391
|
+
*
|
|
392
|
+
* @param element - element that needs to be parsed
|
|
393
|
+
* @param type - name of the method
|
|
394
|
+
* @return {string | string[]} - parsed arguments in format that contract is expecting
|
|
395
|
+
*/
|
|
396
|
+
Contract.prototype.parseCalldataValue = function (element, type) {
|
|
397
|
+
var _this = this;
|
|
398
|
+
if (element === undefined) {
|
|
399
|
+
throw Error('Missing element in calldata');
|
|
561
400
|
}
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
};
|
|
567
|
-
/**
|
|
568
|
-
* Parse of the response elements that are converted to Object (Struct) by using the abi
|
|
569
|
-
*
|
|
570
|
-
* @param responseIterator - iterator of the response
|
|
571
|
-
* @param type - type of the struct
|
|
572
|
-
* @return {BigNumberish | ParsedStruct} - parsed arguments in format that contract is expecting
|
|
573
|
-
*/
|
|
574
|
-
Contract.prototype.parseResponseStruct = function (responseIterator, type) {
|
|
575
|
-
var _this = this;
|
|
576
|
-
// check the type of current element
|
|
577
|
-
if (type in this.structs && this.structs[type]) {
|
|
578
|
-
return this.structs[type].members.reduce(function (acc, el) {
|
|
579
|
-
// parse each member of the struct (member can felt or nested struct)
|
|
580
|
-
acc[el.name] = _this.parseResponseStruct(responseIterator, el.type);
|
|
581
|
-
return acc;
|
|
582
|
-
}, {});
|
|
583
|
-
}
|
|
584
|
-
return parseFelt(responseIterator.next().value);
|
|
585
|
-
};
|
|
586
|
-
/**
|
|
587
|
-
* Parse one field of the calldata by using input field from the abi for that method
|
|
588
|
-
*
|
|
589
|
-
* @param args - value of the field
|
|
590
|
-
* @param input - input(field) information from the abi that will be used to parse the data
|
|
591
|
-
* @return {string | string[]} - parsed arguments in format that contract is expecting
|
|
592
|
-
*/
|
|
593
|
-
Contract.prototype.parseCalldataField = function (argsIterator, input) {
|
|
594
|
-
var _this = this;
|
|
595
|
-
var name = input.name,
|
|
596
|
-
type = input.type;
|
|
597
|
-
var value = argsIterator.next().value;
|
|
598
|
-
var parsedCalldata = [];
|
|
599
|
-
switch (true) {
|
|
600
|
-
case /\*/.test(type):
|
|
601
|
-
if (Array.isArray(value)) {
|
|
602
|
-
parsedCalldata.push((0, number_1.toFelt)(value.length));
|
|
603
|
-
return value.reduce(function (acc, el) {
|
|
604
|
-
if (/felt/.test(type)) {
|
|
605
|
-
acc.push((0, number_1.toFelt)(el));
|
|
606
|
-
} else {
|
|
607
|
-
acc.push.apply(
|
|
608
|
-
acc,
|
|
609
|
-
__spreadArray(
|
|
610
|
-
[],
|
|
611
|
-
__read(_this.parseCalldataValue(el, type.replace('*', ''))),
|
|
612
|
-
false
|
|
613
|
-
)
|
|
614
|
-
);
|
|
401
|
+
if (Array.isArray(element)) {
|
|
402
|
+
var structMemberNum = this.calculateStructMembers(type);
|
|
403
|
+
if (element.length !== structMemberNum) {
|
|
404
|
+
throw Error('Missing element in calldata');
|
|
615
405
|
}
|
|
616
|
-
return
|
|
617
|
-
}, parsedCalldata);
|
|
406
|
+
return element.map(function (el) { return (0, number_1.toFelt)(el); });
|
|
618
407
|
}
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
408
|
+
// checking if the passed element is struct or element in struct
|
|
409
|
+
if (this.structs[type] && this.structs[type].members.length) {
|
|
410
|
+
// going through all the members of the struct and parsing the value
|
|
411
|
+
return this.structs[type].members.reduce(function (acc, member) {
|
|
412
|
+
// if the member of the struct is another struct this will return array of the felts if not it will be single felt
|
|
413
|
+
// TODO: refactor types so member name can be used as keyof ParsedStruct
|
|
414
|
+
/* @ts-ignore */
|
|
415
|
+
var parsedData = _this.parseCalldataValue(element[member.name], member.type);
|
|
416
|
+
if (typeof parsedData === 'string') {
|
|
417
|
+
acc.push(parsedData);
|
|
418
|
+
}
|
|
419
|
+
else {
|
|
420
|
+
acc.push.apply(acc, __spreadArray([], __read(parsedData), false));
|
|
421
|
+
}
|
|
422
|
+
return acc;
|
|
423
|
+
}, []);
|
|
627
424
|
}
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
}
|
|
647
|
-
var parsedData = _this.parseCalldataField(argsIterator, input);
|
|
648
|
-
if (Array.isArray(parsedData)) {
|
|
649
|
-
acc.push.apply(acc, __spreadArray([], __read(parsedData), false));
|
|
650
|
-
} else {
|
|
651
|
-
acc.push(parsedData);
|
|
652
|
-
}
|
|
653
|
-
return acc;
|
|
654
|
-
}, []);
|
|
655
|
-
};
|
|
656
|
-
/**
|
|
657
|
-
* Parse elements of the response and structuring them into one field by using output property from the abi for that method
|
|
658
|
-
*
|
|
659
|
-
* @param responseIterator - iterator of the response
|
|
660
|
-
* @param output - output(field) information from the abi that will be used to parse the data
|
|
661
|
-
* @return - parsed response corresponding to the abi structure of the field
|
|
662
|
-
*/
|
|
663
|
-
Contract.prototype.parseResponseField = function (responseIterator, output, parsedResult) {
|
|
664
|
-
var name = output.name,
|
|
665
|
-
type = output.type;
|
|
666
|
-
var parsedDataArr = [];
|
|
667
|
-
switch (true) {
|
|
668
|
-
case /_len$/.test(name):
|
|
669
|
-
return parseFelt(responseIterator.next().value).toNumber();
|
|
670
|
-
case /\(felt/.test(type):
|
|
671
|
-
return type.split(',').reduce(function (acc) {
|
|
672
|
-
acc.push(parseFelt(responseIterator.next().value));
|
|
673
|
-
return acc;
|
|
674
|
-
}, []);
|
|
675
|
-
case /\*/.test(type):
|
|
676
|
-
if (parsedResult && parsedResult[''.concat(name, '_len')]) {
|
|
677
|
-
var arrLen = parsedResult[''.concat(name, '_len')];
|
|
678
|
-
while (parsedDataArr.length < arrLen) {
|
|
679
|
-
parsedDataArr.push(
|
|
680
|
-
this.parseResponseStruct(responseIterator, output.type.replace('*', ''))
|
|
681
|
-
);
|
|
682
|
-
}
|
|
425
|
+
return (0, number_1.toFelt)(element);
|
|
426
|
+
};
|
|
427
|
+
/**
|
|
428
|
+
* Parse of the response elements that are converted to Object (Struct) by using the abi
|
|
429
|
+
*
|
|
430
|
+
* @param responseIterator - iterator of the response
|
|
431
|
+
* @param type - type of the struct
|
|
432
|
+
* @return {BigNumberish | ParsedStruct} - parsed arguments in format that contract is expecting
|
|
433
|
+
*/
|
|
434
|
+
Contract.prototype.parseResponseStruct = function (responseIterator, type) {
|
|
435
|
+
var _this = this;
|
|
436
|
+
// check the type of current element
|
|
437
|
+
if (type in this.structs && this.structs[type]) {
|
|
438
|
+
return this.structs[type].members.reduce(function (acc, el) {
|
|
439
|
+
// parse each member of the struct (member can felt or nested struct)
|
|
440
|
+
acc[el.name] = _this.parseResponseStruct(responseIterator, el.type);
|
|
441
|
+
return acc;
|
|
442
|
+
}, {});
|
|
683
443
|
}
|
|
684
|
-
return parsedDataArr;
|
|
685
|
-
case type in this.structs:
|
|
686
|
-
return this.parseResponseStruct(responseIterator, type);
|
|
687
|
-
default:
|
|
688
444
|
return parseFelt(responseIterator.next().value);
|
|
689
|
-
}
|
|
690
|
-
};
|
|
691
|
-
/**
|
|
692
|
-
* Parse elements of the response array and structuring them into response object
|
|
693
|
-
*
|
|
694
|
-
* @param method - method name
|
|
695
|
-
* @param response - response from the method
|
|
696
|
-
* @return - parsed response corresponding to the abi
|
|
697
|
-
*/
|
|
698
|
-
Contract.prototype.parseResponse = function (method, response) {
|
|
699
|
-
var _this = this;
|
|
700
|
-
var outputs = this.abi.find(function (abi) {
|
|
701
|
-
return abi.name === method;
|
|
702
|
-
}).outputs;
|
|
703
|
-
var responseIterator = response.flat()[Symbol.iterator]();
|
|
704
|
-
var resultObject = outputs.flat().reduce(function (acc, output) {
|
|
705
|
-
acc[output.name] = _this.parseResponseField(responseIterator, output, acc);
|
|
706
|
-
if (acc[output.name] && acc[''.concat(output.name, '_len')]) {
|
|
707
|
-
delete acc[''.concat(output.name, '_len')];
|
|
708
|
-
}
|
|
709
|
-
return acc;
|
|
710
|
-
}, {});
|
|
711
|
-
return Object.entries(resultObject).reduce(function (acc, _a) {
|
|
712
|
-
var _b = __read(_a, 2),
|
|
713
|
-
key = _b[0],
|
|
714
|
-
value = _b[1];
|
|
715
|
-
acc.push(value);
|
|
716
|
-
acc[key] = value;
|
|
717
|
-
return acc;
|
|
718
|
-
}, []);
|
|
719
|
-
};
|
|
720
|
-
Contract.prototype.invoke = function (method, args, options) {
|
|
721
|
-
if (args === void 0) {
|
|
722
|
-
args = [];
|
|
723
|
-
}
|
|
724
|
-
if (options === void 0) {
|
|
725
|
-
options = {};
|
|
726
|
-
}
|
|
727
|
-
// ensure contract is connected
|
|
728
|
-
(0, minimalistic_assert_1.default)(
|
|
729
|
-
this.address !== null,
|
|
730
|
-
'contract isnt connected to an address'
|
|
731
|
-
);
|
|
732
|
-
// validate method and args
|
|
733
|
-
this.validateMethodAndArgs('INVOKE', method, args);
|
|
734
|
-
var inputs = this.abi.find(function (abi) {
|
|
735
|
-
return abi.name === method;
|
|
736
|
-
}).inputs;
|
|
737
|
-
var inputsLength = inputs.reduce(function (acc, input) {
|
|
738
|
-
if (!/_len$/.test(input.name)) {
|
|
739
|
-
return acc + 1;
|
|
740
|
-
}
|
|
741
|
-
return acc;
|
|
742
|
-
}, 0);
|
|
743
|
-
if (args.length !== inputsLength) {
|
|
744
|
-
throw Error(
|
|
745
|
-
'Invalid number of arguments, expected '
|
|
746
|
-
.concat(inputsLength, ' arguments, but got ')
|
|
747
|
-
.concat(args.length)
|
|
748
|
-
);
|
|
749
|
-
}
|
|
750
|
-
// compile calldata
|
|
751
|
-
var calldata = this.compileCalldata(args, inputs);
|
|
752
|
-
var invocation = {
|
|
753
|
-
contractAddress: this.address,
|
|
754
|
-
calldata: calldata,
|
|
755
|
-
entrypoint: method,
|
|
756
445
|
};
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
446
|
+
/**
|
|
447
|
+
* Parse one field of the calldata by using input field from the abi for that method
|
|
448
|
+
*
|
|
449
|
+
* @param args - value of the field
|
|
450
|
+
* @param input - input(field) information from the abi that will be used to parse the data
|
|
451
|
+
* @return {string | string[]} - parsed arguments in format that contract is expecting
|
|
452
|
+
*/
|
|
453
|
+
Contract.prototype.parseCalldataField = function (argsIterator, input) {
|
|
454
|
+
var _this = this;
|
|
455
|
+
var name = input.name, type = input.type;
|
|
456
|
+
var value = argsIterator.next().value;
|
|
457
|
+
var parsedCalldata = [];
|
|
458
|
+
switch (true) {
|
|
459
|
+
case /\*/.test(type):
|
|
460
|
+
if (Array.isArray(value)) {
|
|
461
|
+
parsedCalldata.push((0, number_1.toFelt)(value.length));
|
|
462
|
+
return value.reduce(function (acc, el) {
|
|
463
|
+
if (/felt/.test(type)) {
|
|
464
|
+
acc.push((0, number_1.toFelt)(el));
|
|
465
|
+
}
|
|
466
|
+
else {
|
|
467
|
+
acc.push.apply(acc, __spreadArray([], __read(_this.parseCalldataValue(el, type.replace('*', ''))), false));
|
|
468
|
+
}
|
|
469
|
+
return acc;
|
|
470
|
+
}, parsedCalldata);
|
|
471
|
+
}
|
|
472
|
+
throw Error("Expected ".concat(name, " to be array"));
|
|
473
|
+
case type in this.structs:
|
|
474
|
+
return this.parseCalldataValue(value, type);
|
|
475
|
+
case /\(felt/.test(type):
|
|
476
|
+
if (Array.isArray(value)) {
|
|
477
|
+
return value.map(function (el) { return (0, number_1.toFelt)(el); });
|
|
478
|
+
}
|
|
479
|
+
throw Error("Expected ".concat(name, " to be array"));
|
|
480
|
+
default:
|
|
481
|
+
return (0, number_1.toFelt)(value);
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
/**
|
|
485
|
+
* Parse the calldata by using input fields from the abi for that method
|
|
486
|
+
*
|
|
487
|
+
* @param args - arguments passed the the method
|
|
488
|
+
* @param inputs - list of inputs(fields) that are in the abi
|
|
489
|
+
* @return {Calldata} - parsed arguments in format that contract is expecting
|
|
490
|
+
*/
|
|
491
|
+
Contract.prototype.compileCalldata = function (args, inputs) {
|
|
492
|
+
var _this = this;
|
|
493
|
+
var argsIterator = args[Symbol.iterator]();
|
|
494
|
+
return inputs.reduce(function (acc, input) {
|
|
495
|
+
if (/_len$/.test(input.name)) {
|
|
496
|
+
return acc;
|
|
497
|
+
}
|
|
498
|
+
var parsedData = _this.parseCalldataField(argsIterator, input);
|
|
499
|
+
if (Array.isArray(parsedData)) {
|
|
500
|
+
acc.push.apply(acc, __spreadArray([], __read(parsedData), false));
|
|
501
|
+
}
|
|
502
|
+
else {
|
|
503
|
+
acc.push(parsedData);
|
|
504
|
+
}
|
|
505
|
+
return acc;
|
|
506
|
+
}, []);
|
|
507
|
+
};
|
|
508
|
+
/**
|
|
509
|
+
* Parse elements of the response and structuring them into one field by using output property from the abi for that method
|
|
510
|
+
*
|
|
511
|
+
* @param responseIterator - iterator of the response
|
|
512
|
+
* @param output - output(field) information from the abi that will be used to parse the data
|
|
513
|
+
* @return - parsed response corresponding to the abi structure of the field
|
|
514
|
+
*/
|
|
515
|
+
Contract.prototype.parseResponseField = function (responseIterator, output, parsedResult) {
|
|
516
|
+
var name = output.name, type = output.type;
|
|
517
|
+
var parsedDataArr = [];
|
|
518
|
+
switch (true) {
|
|
519
|
+
case /_len$/.test(name):
|
|
520
|
+
return parseFelt(responseIterator.next().value).toNumber();
|
|
521
|
+
case /\(felt/.test(type):
|
|
522
|
+
return type.split(',').reduce(function (acc) {
|
|
523
|
+
acc.push(parseFelt(responseIterator.next().value));
|
|
524
|
+
return acc;
|
|
525
|
+
}, []);
|
|
526
|
+
case /\*/.test(type):
|
|
527
|
+
if (parsedResult && parsedResult["".concat(name, "_len")]) {
|
|
528
|
+
var arrLen = parsedResult["".concat(name, "_len")];
|
|
529
|
+
while (parsedDataArr.length < arrLen) {
|
|
530
|
+
parsedDataArr.push(this.parseResponseStruct(responseIterator, output.type.replace('*', '')));
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
return parsedDataArr;
|
|
534
|
+
case type in this.structs:
|
|
535
|
+
return this.parseResponseStruct(responseIterator, type);
|
|
536
|
+
default:
|
|
537
|
+
return parseFelt(responseIterator.next().value);
|
|
538
|
+
}
|
|
539
|
+
};
|
|
540
|
+
/**
|
|
541
|
+
* Parse elements of the response array and structuring them into response object
|
|
542
|
+
*
|
|
543
|
+
* @param method - method name
|
|
544
|
+
* @param response - response from the method
|
|
545
|
+
* @return - parsed response corresponding to the abi
|
|
546
|
+
*/
|
|
547
|
+
Contract.prototype.parseResponse = function (method, response) {
|
|
548
|
+
var _this = this;
|
|
549
|
+
var outputs = this.abi.find(function (abi) { return abi.name === method; }).outputs;
|
|
550
|
+
var responseIterator = response.flat()[Symbol.iterator]();
|
|
551
|
+
var resultObject = outputs.flat().reduce(function (acc, output) {
|
|
552
|
+
acc[output.name] = _this.parseResponseField(responseIterator, output, acc);
|
|
553
|
+
if (acc[output.name] && acc["".concat(output.name, "_len")]) {
|
|
554
|
+
delete acc["".concat(output.name, "_len")];
|
|
555
|
+
}
|
|
556
|
+
return acc;
|
|
557
|
+
}, {});
|
|
558
|
+
return Object.entries(resultObject).reduce(function (acc, _a) {
|
|
559
|
+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
560
|
+
acc.push(value);
|
|
561
|
+
acc[key] = value;
|
|
562
|
+
return acc;
|
|
563
|
+
}, []);
|
|
564
|
+
};
|
|
565
|
+
Contract.prototype.invoke = function (method, args, options) {
|
|
566
|
+
if (args === void 0) { args = []; }
|
|
567
|
+
if (options === void 0) { options = {}; }
|
|
814
568
|
// ensure contract is connected
|
|
815
|
-
(0,
|
|
816
|
-
minimalistic_assert_1.default)(this.address !== null, 'contract isnt connected to an address');
|
|
569
|
+
(0, minimalistic_assert_1.default)(this.address !== null, 'contract isnt connected to an address');
|
|
817
570
|
// validate method and args
|
|
818
571
|
this.validateMethodAndArgs('INVOKE', method, args);
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
572
|
+
var inputs = this.abi.find(function (abi) { return abi.name === method; }).inputs;
|
|
573
|
+
var inputsLength = inputs.reduce(function (acc, input) {
|
|
574
|
+
if (!/_len$/.test(input.name)) {
|
|
575
|
+
return acc + 1;
|
|
576
|
+
}
|
|
577
|
+
return acc;
|
|
578
|
+
}, 0);
|
|
579
|
+
if (args.length !== inputsLength) {
|
|
580
|
+
throw Error("Invalid number of arguments, expected ".concat(inputsLength, " arguments, but got ").concat(args.length));
|
|
825
581
|
}
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
582
|
+
// compile calldata
|
|
583
|
+
var calldata = this.compileCalldata(args, inputs);
|
|
584
|
+
var invocation = {
|
|
585
|
+
contractAddress: this.address,
|
|
586
|
+
calldata: calldata,
|
|
587
|
+
entrypoint: method,
|
|
588
|
+
};
|
|
589
|
+
if ('execute' in this.providerOrAccount) {
|
|
590
|
+
return this.providerOrAccount.execute(invocation, undefined, {
|
|
591
|
+
maxFee: options.maxFee,
|
|
592
|
+
nonce: options.nonce,
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
// eslint-disable-next-line no-console
|
|
596
|
+
console.warn("Invoking ".concat(method, " without an account. This will not work on a public node."));
|
|
597
|
+
return this.providerOrAccount.invokeFunction(__assign(__assign({}, invocation), { signature: options.signature || [] }));
|
|
598
|
+
};
|
|
599
|
+
Contract.prototype.call = function (method, args, _a) {
|
|
600
|
+
if (args === void 0) { args = []; }
|
|
601
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.blockIdentifier, blockIdentifier = _c === void 0 ? 'pending' : _c;
|
|
602
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
603
|
+
var inputs, calldata;
|
|
604
|
+
var _this = this;
|
|
605
|
+
return __generator(this, function (_d) {
|
|
606
|
+
// ensure contract is connected
|
|
607
|
+
(0, minimalistic_assert_1.default)(this.address !== null, 'contract isnt connected to an address');
|
|
608
|
+
// validate method and args
|
|
609
|
+
this.validateMethodAndArgs('CALL', method, args);
|
|
610
|
+
inputs = this.abi.find(function (abi) { return abi.name === method; }).inputs;
|
|
611
|
+
calldata = this.compileCalldata(args, inputs);
|
|
612
|
+
return [2 /*return*/, this.providerOrAccount
|
|
613
|
+
.callContract({
|
|
614
|
+
contractAddress: this.address,
|
|
615
|
+
calldata: calldata,
|
|
616
|
+
entrypoint: method,
|
|
617
|
+
}, blockIdentifier)
|
|
618
|
+
.then(function (x) { return _this.parseResponse(method, x.result); })];
|
|
619
|
+
});
|
|
620
|
+
});
|
|
621
|
+
};
|
|
622
|
+
Contract.prototype.estimate = function (method, args) {
|
|
623
|
+
if (args === void 0) { args = []; }
|
|
624
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
625
|
+
var invocation;
|
|
626
|
+
var _a;
|
|
627
|
+
return __generator(this, function (_b) {
|
|
628
|
+
// ensure contract is connected
|
|
629
|
+
(0, minimalistic_assert_1.default)(this.address !== null, 'contract isnt connected to an address');
|
|
630
|
+
// validate method and args
|
|
631
|
+
this.validateMethodAndArgs('INVOKE', method, args);
|
|
632
|
+
invocation = (_a = this.populateTransaction)[method].apply(_a, __spreadArray([], __read(args), false));
|
|
633
|
+
if ('estimateFee' in this.providerOrAccount) {
|
|
634
|
+
return [2 /*return*/, this.providerOrAccount.estimateFee(invocation)];
|
|
635
|
+
}
|
|
636
|
+
throw Error('Contract must be connected to the account contract to estimate');
|
|
637
|
+
});
|
|
638
|
+
});
|
|
639
|
+
};
|
|
640
|
+
Contract.prototype.populate = function (method, args) {
|
|
641
|
+
if (args === void 0) { args = []; }
|
|
642
|
+
var inputs = this.abi.find(function (abi) { return abi.name === method; }).inputs;
|
|
643
|
+
return {
|
|
644
|
+
contractAddress: this.address,
|
|
645
|
+
entrypoint: method,
|
|
646
|
+
calldata: this.compileCalldata(args, inputs),
|
|
647
|
+
signature: [],
|
|
648
|
+
};
|
|
842
649
|
};
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
})();
|
|
650
|
+
return Contract;
|
|
651
|
+
}());
|
|
846
652
|
exports.Contract = Contract;
|