@leofcoin/chain 1.5.29 → 1.5.30
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/exports/chain.js +2 -1
- package/package.json +1 -1
- package/exports/browser/browser-store.js +0 -451
- package/exports/browser/chain.js +0 -2189
- package/exports/browser/client-d602421d-d602421d.js +0 -10751
- package/exports/browser/index-055d5584.js +0 -5717
- package/exports/browser/index-329e0324-f8858eb6.js +0 -37
- package/exports/browser/messages-000b7f84-2f945543.js +0 -225
- package/exports/browser/node-browser-ccafb3fc.js +0 -20989
- package/exports/browser/node-browser.js +0 -2
- package/exports/browser/password-4357020e.js +0 -3
- package/exports/browser/qr-scanner-worker.min-c002e984-c002e984.js +0 -100
- package/exports/browser/workers/block-worker.js +0 -33
- package/exports/browser/workers/machine-worker.js +0 -234
- package/exports/browser/workers/worker-5b02efbe.js +0 -5684
- package/exports/workers/block-worker.js +0 -33
- package/exports/workers/machine-worker.js +0 -234
- package/exports/workers/worker-5b02efbe.js +0 -5684
package/exports/browser/chain.js
DELETED
|
@@ -1,2189 +0,0 @@
|
|
|
1
|
-
import { B as BigNumber, L as Logger, v as version$1, h as hexZeroPad, i as isBigNumberish, a as arrayify, b as isBytes, T as TransactionMessage, t as toBase58, C as ContractMessage, R as RawTransactionMessage, c as BlockMessage, d as BWMessage, e as BWRequestMessage } from './index-055d5584.js';
|
|
2
|
-
|
|
3
|
-
const logger$1 = new Logger(version$1);
|
|
4
|
-
const _constructorGuard = {};
|
|
5
|
-
const Zero = BigNumber.from(0);
|
|
6
|
-
const NegativeOne = BigNumber.from(-1);
|
|
7
|
-
function throwFault(message, fault, operation, value) {
|
|
8
|
-
const params = { fault: fault, operation: operation };
|
|
9
|
-
if (value !== undefined) {
|
|
10
|
-
params.value = value;
|
|
11
|
-
}
|
|
12
|
-
return logger$1.throwError(message, Logger.errors.NUMERIC_FAULT, params);
|
|
13
|
-
}
|
|
14
|
-
// Constant to pull zeros from for multipliers
|
|
15
|
-
let zeros = "0";
|
|
16
|
-
while (zeros.length < 256) {
|
|
17
|
-
zeros += zeros;
|
|
18
|
-
}
|
|
19
|
-
// Returns a string "1" followed by decimal "0"s
|
|
20
|
-
function getMultiplier(decimals) {
|
|
21
|
-
if (typeof (decimals) !== "number") {
|
|
22
|
-
try {
|
|
23
|
-
decimals = BigNumber.from(decimals).toNumber();
|
|
24
|
-
}
|
|
25
|
-
catch (e) { }
|
|
26
|
-
}
|
|
27
|
-
if (typeof (decimals) === "number" && decimals >= 0 && decimals <= 256 && !(decimals % 1)) {
|
|
28
|
-
return ("1" + zeros.substring(0, decimals));
|
|
29
|
-
}
|
|
30
|
-
return logger$1.throwArgumentError("invalid decimal size", "decimals", decimals);
|
|
31
|
-
}
|
|
32
|
-
function formatFixed(value, decimals) {
|
|
33
|
-
if (decimals == null) {
|
|
34
|
-
decimals = 0;
|
|
35
|
-
}
|
|
36
|
-
const multiplier = getMultiplier(decimals);
|
|
37
|
-
// Make sure wei is a big number (convert as necessary)
|
|
38
|
-
value = BigNumber.from(value);
|
|
39
|
-
const negative = value.lt(Zero);
|
|
40
|
-
if (negative) {
|
|
41
|
-
value = value.mul(NegativeOne);
|
|
42
|
-
}
|
|
43
|
-
let fraction = value.mod(multiplier).toString();
|
|
44
|
-
while (fraction.length < multiplier.length - 1) {
|
|
45
|
-
fraction = "0" + fraction;
|
|
46
|
-
}
|
|
47
|
-
// Strip training 0
|
|
48
|
-
fraction = fraction.match(/^([0-9]*[1-9]|0)(0*)/)[1];
|
|
49
|
-
const whole = value.div(multiplier).toString();
|
|
50
|
-
if (multiplier.length === 1) {
|
|
51
|
-
value = whole;
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
value = whole + "." + fraction;
|
|
55
|
-
}
|
|
56
|
-
if (negative) {
|
|
57
|
-
value = "-" + value;
|
|
58
|
-
}
|
|
59
|
-
return value;
|
|
60
|
-
}
|
|
61
|
-
function parseFixed(value, decimals) {
|
|
62
|
-
if (decimals == null) {
|
|
63
|
-
decimals = 0;
|
|
64
|
-
}
|
|
65
|
-
const multiplier = getMultiplier(decimals);
|
|
66
|
-
if (typeof (value) !== "string" || !value.match(/^-?[0-9.]+$/)) {
|
|
67
|
-
logger$1.throwArgumentError("invalid decimal value", "value", value);
|
|
68
|
-
}
|
|
69
|
-
// Is it negative?
|
|
70
|
-
const negative = (value.substring(0, 1) === "-");
|
|
71
|
-
if (negative) {
|
|
72
|
-
value = value.substring(1);
|
|
73
|
-
}
|
|
74
|
-
if (value === ".") {
|
|
75
|
-
logger$1.throwArgumentError("missing value", "value", value);
|
|
76
|
-
}
|
|
77
|
-
// Split it into a whole and fractional part
|
|
78
|
-
const comps = value.split(".");
|
|
79
|
-
if (comps.length > 2) {
|
|
80
|
-
logger$1.throwArgumentError("too many decimal points", "value", value);
|
|
81
|
-
}
|
|
82
|
-
let whole = comps[0], fraction = comps[1];
|
|
83
|
-
if (!whole) {
|
|
84
|
-
whole = "0";
|
|
85
|
-
}
|
|
86
|
-
if (!fraction) {
|
|
87
|
-
fraction = "0";
|
|
88
|
-
}
|
|
89
|
-
// Trim trailing zeros
|
|
90
|
-
while (fraction[fraction.length - 1] === "0") {
|
|
91
|
-
fraction = fraction.substring(0, fraction.length - 1);
|
|
92
|
-
}
|
|
93
|
-
// Check the fraction doesn't exceed our decimals size
|
|
94
|
-
if (fraction.length > multiplier.length - 1) {
|
|
95
|
-
throwFault("fractional component exceeds decimals", "underflow", "parseFixed");
|
|
96
|
-
}
|
|
97
|
-
// If decimals is 0, we have an empty string for fraction
|
|
98
|
-
if (fraction === "") {
|
|
99
|
-
fraction = "0";
|
|
100
|
-
}
|
|
101
|
-
// Fully pad the string with zeros to get to wei
|
|
102
|
-
while (fraction.length < multiplier.length - 1) {
|
|
103
|
-
fraction += "0";
|
|
104
|
-
}
|
|
105
|
-
const wholeValue = BigNumber.from(whole);
|
|
106
|
-
const fractionValue = BigNumber.from(fraction);
|
|
107
|
-
let wei = (wholeValue.mul(multiplier)).add(fractionValue);
|
|
108
|
-
if (negative) {
|
|
109
|
-
wei = wei.mul(NegativeOne);
|
|
110
|
-
}
|
|
111
|
-
return wei;
|
|
112
|
-
}
|
|
113
|
-
class FixedFormat {
|
|
114
|
-
constructor(constructorGuard, signed, width, decimals) {
|
|
115
|
-
if (constructorGuard !== _constructorGuard) {
|
|
116
|
-
logger$1.throwError("cannot use FixedFormat constructor; use FixedFormat.from", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
117
|
-
operation: "new FixedFormat"
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
this.signed = signed;
|
|
121
|
-
this.width = width;
|
|
122
|
-
this.decimals = decimals;
|
|
123
|
-
this.name = (signed ? "" : "u") + "fixed" + String(width) + "x" + String(decimals);
|
|
124
|
-
this._multiplier = getMultiplier(decimals);
|
|
125
|
-
Object.freeze(this);
|
|
126
|
-
}
|
|
127
|
-
static from(value) {
|
|
128
|
-
if (value instanceof FixedFormat) {
|
|
129
|
-
return value;
|
|
130
|
-
}
|
|
131
|
-
if (typeof (value) === "number") {
|
|
132
|
-
value = `fixed128x${value}`;
|
|
133
|
-
}
|
|
134
|
-
let signed = true;
|
|
135
|
-
let width = 128;
|
|
136
|
-
let decimals = 18;
|
|
137
|
-
if (typeof (value) === "string") {
|
|
138
|
-
if (value === "fixed") ;
|
|
139
|
-
else if (value === "ufixed") {
|
|
140
|
-
signed = false;
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
const match = value.match(/^(u?)fixed([0-9]+)x([0-9]+)$/);
|
|
144
|
-
if (!match) {
|
|
145
|
-
logger$1.throwArgumentError("invalid fixed format", "format", value);
|
|
146
|
-
}
|
|
147
|
-
signed = (match[1] !== "u");
|
|
148
|
-
width = parseInt(match[2]);
|
|
149
|
-
decimals = parseInt(match[3]);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
else if (value) {
|
|
153
|
-
const check = (key, type, defaultValue) => {
|
|
154
|
-
if (value[key] == null) {
|
|
155
|
-
return defaultValue;
|
|
156
|
-
}
|
|
157
|
-
if (typeof (value[key]) !== type) {
|
|
158
|
-
logger$1.throwArgumentError("invalid fixed format (" + key + " not " + type + ")", "format." + key, value[key]);
|
|
159
|
-
}
|
|
160
|
-
return value[key];
|
|
161
|
-
};
|
|
162
|
-
signed = check("signed", "boolean", signed);
|
|
163
|
-
width = check("width", "number", width);
|
|
164
|
-
decimals = check("decimals", "number", decimals);
|
|
165
|
-
}
|
|
166
|
-
if (width % 8) {
|
|
167
|
-
logger$1.throwArgumentError("invalid fixed format width (not byte aligned)", "format.width", width);
|
|
168
|
-
}
|
|
169
|
-
if (decimals > 80) {
|
|
170
|
-
logger$1.throwArgumentError("invalid fixed format (decimals too large)", "format.decimals", decimals);
|
|
171
|
-
}
|
|
172
|
-
return new FixedFormat(_constructorGuard, signed, width, decimals);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
class FixedNumber {
|
|
176
|
-
constructor(constructorGuard, hex, value, format) {
|
|
177
|
-
if (constructorGuard !== _constructorGuard) {
|
|
178
|
-
logger$1.throwError("cannot use FixedNumber constructor; use FixedNumber.from", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
179
|
-
operation: "new FixedFormat"
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
this.format = format;
|
|
183
|
-
this._hex = hex;
|
|
184
|
-
this._value = value;
|
|
185
|
-
this._isFixedNumber = true;
|
|
186
|
-
Object.freeze(this);
|
|
187
|
-
}
|
|
188
|
-
_checkFormat(other) {
|
|
189
|
-
if (this.format.name !== other.format.name) {
|
|
190
|
-
logger$1.throwArgumentError("incompatible format; use fixedNumber.toFormat", "other", other);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
addUnsafe(other) {
|
|
194
|
-
this._checkFormat(other);
|
|
195
|
-
const a = parseFixed(this._value, this.format.decimals);
|
|
196
|
-
const b = parseFixed(other._value, other.format.decimals);
|
|
197
|
-
return FixedNumber.fromValue(a.add(b), this.format.decimals, this.format);
|
|
198
|
-
}
|
|
199
|
-
subUnsafe(other) {
|
|
200
|
-
this._checkFormat(other);
|
|
201
|
-
const a = parseFixed(this._value, this.format.decimals);
|
|
202
|
-
const b = parseFixed(other._value, other.format.decimals);
|
|
203
|
-
return FixedNumber.fromValue(a.sub(b), this.format.decimals, this.format);
|
|
204
|
-
}
|
|
205
|
-
mulUnsafe(other) {
|
|
206
|
-
this._checkFormat(other);
|
|
207
|
-
const a = parseFixed(this._value, this.format.decimals);
|
|
208
|
-
const b = parseFixed(other._value, other.format.decimals);
|
|
209
|
-
return FixedNumber.fromValue(a.mul(b).div(this.format._multiplier), this.format.decimals, this.format);
|
|
210
|
-
}
|
|
211
|
-
divUnsafe(other) {
|
|
212
|
-
this._checkFormat(other);
|
|
213
|
-
const a = parseFixed(this._value, this.format.decimals);
|
|
214
|
-
const b = parseFixed(other._value, other.format.decimals);
|
|
215
|
-
return FixedNumber.fromValue(a.mul(this.format._multiplier).div(b), this.format.decimals, this.format);
|
|
216
|
-
}
|
|
217
|
-
floor() {
|
|
218
|
-
const comps = this.toString().split(".");
|
|
219
|
-
if (comps.length === 1) {
|
|
220
|
-
comps.push("0");
|
|
221
|
-
}
|
|
222
|
-
let result = FixedNumber.from(comps[0], this.format);
|
|
223
|
-
const hasFraction = !comps[1].match(/^(0*)$/);
|
|
224
|
-
if (this.isNegative() && hasFraction) {
|
|
225
|
-
result = result.subUnsafe(ONE.toFormat(result.format));
|
|
226
|
-
}
|
|
227
|
-
return result;
|
|
228
|
-
}
|
|
229
|
-
ceiling() {
|
|
230
|
-
const comps = this.toString().split(".");
|
|
231
|
-
if (comps.length === 1) {
|
|
232
|
-
comps.push("0");
|
|
233
|
-
}
|
|
234
|
-
let result = FixedNumber.from(comps[0], this.format);
|
|
235
|
-
const hasFraction = !comps[1].match(/^(0*)$/);
|
|
236
|
-
if (!this.isNegative() && hasFraction) {
|
|
237
|
-
result = result.addUnsafe(ONE.toFormat(result.format));
|
|
238
|
-
}
|
|
239
|
-
return result;
|
|
240
|
-
}
|
|
241
|
-
// @TODO: Support other rounding algorithms
|
|
242
|
-
round(decimals) {
|
|
243
|
-
if (decimals == null) {
|
|
244
|
-
decimals = 0;
|
|
245
|
-
}
|
|
246
|
-
// If we are already in range, we're done
|
|
247
|
-
const comps = this.toString().split(".");
|
|
248
|
-
if (comps.length === 1) {
|
|
249
|
-
comps.push("0");
|
|
250
|
-
}
|
|
251
|
-
if (decimals < 0 || decimals > 80 || (decimals % 1)) {
|
|
252
|
-
logger$1.throwArgumentError("invalid decimal count", "decimals", decimals);
|
|
253
|
-
}
|
|
254
|
-
if (comps[1].length <= decimals) {
|
|
255
|
-
return this;
|
|
256
|
-
}
|
|
257
|
-
const factor = FixedNumber.from("1" + zeros.substring(0, decimals), this.format);
|
|
258
|
-
const bump = BUMP.toFormat(this.format);
|
|
259
|
-
return this.mulUnsafe(factor).addUnsafe(bump).floor().divUnsafe(factor);
|
|
260
|
-
}
|
|
261
|
-
isZero() {
|
|
262
|
-
return (this._value === "0.0" || this._value === "0");
|
|
263
|
-
}
|
|
264
|
-
isNegative() {
|
|
265
|
-
return (this._value[0] === "-");
|
|
266
|
-
}
|
|
267
|
-
toString() { return this._value; }
|
|
268
|
-
toHexString(width) {
|
|
269
|
-
if (width == null) {
|
|
270
|
-
return this._hex;
|
|
271
|
-
}
|
|
272
|
-
if (width % 8) {
|
|
273
|
-
logger$1.throwArgumentError("invalid byte width", "width", width);
|
|
274
|
-
}
|
|
275
|
-
const hex = BigNumber.from(this._hex).fromTwos(this.format.width).toTwos(width).toHexString();
|
|
276
|
-
return hexZeroPad(hex, width / 8);
|
|
277
|
-
}
|
|
278
|
-
toUnsafeFloat() { return parseFloat(this.toString()); }
|
|
279
|
-
toFormat(format) {
|
|
280
|
-
return FixedNumber.fromString(this._value, format);
|
|
281
|
-
}
|
|
282
|
-
static fromValue(value, decimals, format) {
|
|
283
|
-
// If decimals looks more like a format, and there is no format, shift the parameters
|
|
284
|
-
if (format == null && decimals != null && !isBigNumberish(decimals)) {
|
|
285
|
-
format = decimals;
|
|
286
|
-
decimals = null;
|
|
287
|
-
}
|
|
288
|
-
if (decimals == null) {
|
|
289
|
-
decimals = 0;
|
|
290
|
-
}
|
|
291
|
-
if (format == null) {
|
|
292
|
-
format = "fixed";
|
|
293
|
-
}
|
|
294
|
-
return FixedNumber.fromString(formatFixed(value, decimals), FixedFormat.from(format));
|
|
295
|
-
}
|
|
296
|
-
static fromString(value, format) {
|
|
297
|
-
if (format == null) {
|
|
298
|
-
format = "fixed";
|
|
299
|
-
}
|
|
300
|
-
const fixedFormat = FixedFormat.from(format);
|
|
301
|
-
const numeric = parseFixed(value, fixedFormat.decimals);
|
|
302
|
-
if (!fixedFormat.signed && numeric.lt(Zero)) {
|
|
303
|
-
throwFault("unsigned value cannot be negative", "overflow", "value", value);
|
|
304
|
-
}
|
|
305
|
-
let hex = null;
|
|
306
|
-
if (fixedFormat.signed) {
|
|
307
|
-
hex = numeric.toTwos(fixedFormat.width).toHexString();
|
|
308
|
-
}
|
|
309
|
-
else {
|
|
310
|
-
hex = numeric.toHexString();
|
|
311
|
-
hex = hexZeroPad(hex, fixedFormat.width / 8);
|
|
312
|
-
}
|
|
313
|
-
const decimal = formatFixed(numeric, fixedFormat.decimals);
|
|
314
|
-
return new FixedNumber(_constructorGuard, hex, decimal, fixedFormat);
|
|
315
|
-
}
|
|
316
|
-
static fromBytes(value, format) {
|
|
317
|
-
if (format == null) {
|
|
318
|
-
format = "fixed";
|
|
319
|
-
}
|
|
320
|
-
const fixedFormat = FixedFormat.from(format);
|
|
321
|
-
if (arrayify(value).length > fixedFormat.width / 8) {
|
|
322
|
-
throw new Error("overflow");
|
|
323
|
-
}
|
|
324
|
-
let numeric = BigNumber.from(value);
|
|
325
|
-
if (fixedFormat.signed) {
|
|
326
|
-
numeric = numeric.fromTwos(fixedFormat.width);
|
|
327
|
-
}
|
|
328
|
-
const hex = numeric.toTwos((fixedFormat.signed ? 0 : 1) + fixedFormat.width).toHexString();
|
|
329
|
-
const decimal = formatFixed(numeric, fixedFormat.decimals);
|
|
330
|
-
return new FixedNumber(_constructorGuard, hex, decimal, fixedFormat);
|
|
331
|
-
}
|
|
332
|
-
static from(value, format) {
|
|
333
|
-
if (typeof (value) === "string") {
|
|
334
|
-
return FixedNumber.fromString(value, format);
|
|
335
|
-
}
|
|
336
|
-
if (isBytes(value)) {
|
|
337
|
-
return FixedNumber.fromBytes(value, format);
|
|
338
|
-
}
|
|
339
|
-
try {
|
|
340
|
-
return FixedNumber.fromValue(value, 0, format);
|
|
341
|
-
}
|
|
342
|
-
catch (error) {
|
|
343
|
-
// Allow NUMERIC_FAULT to bubble up
|
|
344
|
-
if (error.code !== Logger.errors.INVALID_ARGUMENT) {
|
|
345
|
-
throw error;
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
return logger$1.throwArgumentError("invalid FixedNumber value", "value", value);
|
|
349
|
-
}
|
|
350
|
-
static isFixedNumber(value) {
|
|
351
|
-
return !!(value && value._isFixedNumber);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
const ONE = FixedNumber.from(1);
|
|
355
|
-
const BUMP = FixedNumber.from("0.5");
|
|
356
|
-
|
|
357
|
-
const version = "units/5.7.0";
|
|
358
|
-
|
|
359
|
-
const logger = new Logger(version);
|
|
360
|
-
const names = [
|
|
361
|
-
"wei",
|
|
362
|
-
"kwei",
|
|
363
|
-
"mwei",
|
|
364
|
-
"gwei",
|
|
365
|
-
"szabo",
|
|
366
|
-
"finney",
|
|
367
|
-
"ether",
|
|
368
|
-
];
|
|
369
|
-
function formatUnits(value, unitName) {
|
|
370
|
-
if (typeof (unitName) === "string") {
|
|
371
|
-
const index = names.indexOf(unitName);
|
|
372
|
-
if (index !== -1) {
|
|
373
|
-
unitName = 3 * index;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
return formatFixed(value, (unitName != null) ? unitName : 18);
|
|
377
|
-
}
|
|
378
|
-
function parseUnits(value, unitName) {
|
|
379
|
-
if (typeof (value) !== "string") {
|
|
380
|
-
logger.throwArgumentError("value must be a string", "value", value);
|
|
381
|
-
}
|
|
382
|
-
if (typeof (unitName) === "string") {
|
|
383
|
-
const index = names.indexOf(unitName);
|
|
384
|
-
if (index !== -1) {
|
|
385
|
-
unitName = 3 * index;
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
return parseFixed(value, (unitName != null) ? unitName : 18);
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
const byteFormats = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
392
|
-
const formatBytes = (bytes, decimals = 2) => {
|
|
393
|
-
if (bytes === 0)
|
|
394
|
-
return '0 Bytes';
|
|
395
|
-
if (decimals < 0)
|
|
396
|
-
decimals = 0;
|
|
397
|
-
const k = 1024;
|
|
398
|
-
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
399
|
-
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(decimals))} ${byteFormats[i]}`;
|
|
400
|
-
};
|
|
401
|
-
|
|
402
|
-
var contractFactory$1 = "IHNY2GQGYO6BDXHHL2KHK3KQU353HPCARUVAP2UVWH4EUVV4JXT373KSVF2";
|
|
403
|
-
var nativeToken$1 = "IHNY2GQH3C44RRUDM4XLG67KHHS3UER7L6NULDHH6ACVOAVTLAGBRLB5BSJ";
|
|
404
|
-
var nameService$1 = "IHNY2GQH5BUXSQTSUP32R7TFOPN3HDWKL4TT2G7MJANULBRN7WHZ4ANG4DH";
|
|
405
|
-
var validators$1 = "IHNY2GQHFKTVEBJGRT6XGHR434KWLGDHOVEI4OB6UK7QUKCNOICMVTXRWTS";
|
|
406
|
-
var addresses$1 = {
|
|
407
|
-
contractFactory: contractFactory$1,
|
|
408
|
-
nativeToken: nativeToken$1,
|
|
409
|
-
nameService: nameService$1,
|
|
410
|
-
validators: validators$1
|
|
411
|
-
};
|
|
412
|
-
|
|
413
|
-
const contractFactory$2 = addresses$1.contractFactory;
|
|
414
|
-
const nameService$2 = addresses$1.nameService;
|
|
415
|
-
const nativeToken$2 = addresses$1.nativeToken;
|
|
416
|
-
const validators$2 = addresses$1.validators;
|
|
417
|
-
var addresses = {
|
|
418
|
-
contractFactory: contractFactory$2,
|
|
419
|
-
nameService: nameService$2,
|
|
420
|
-
nativeToken: nativeToken$2,
|
|
421
|
-
validators: validators$2
|
|
422
|
-
};
|
|
423
|
-
|
|
424
|
-
var contractFactory = "237,198,141,3,53,89,84,113,119,88,110,55,76,101,103,89,119,65,109,100,117,75,88,119,116,83,52,118,52,100,97,114,113,66,84,81,82,76,90,106,50,57,117,106,112,114,98,104,52,119,121,76,106,112,56,50,87,106,173,5,99,108,97,115,115,32,70,97,99,116,111,114,121,123,35,110,97,109,101,61,34,65,114,116,79,110,108,105,110,101,67,111,110,116,114,97,99,116,70,97,99,116,111,114,121,34,59,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,61,48,59,35,99,111,110,116,114,97,99,116,115,61,91,93,59,99,111,110,115,116,114,117,99,116,111,114,40,115,116,97,116,101,41,123,115,116,97,116,101,38,38,40,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,61,115,116,97,116,101,46,99,111,110,116,114,97,99,116,115,44,116,104,105,115,46,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,61,115,116,97,116,101,46,116,111,116,97,108,67,111,110,116,114,97,99,116,115,41,125,103,101,116,32,115,116,97,116,101,40,41,123,114,101,116,117,114,110,123,116,111,116,97,108,67,111,110,116,114,97,99,116,115,58,116,104,105,115,46,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,44,99,111,110,116,114,97,99,116,115,58,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,125,125,103,101,116,32,110,97,109,101,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,110,97,109,101,125,103,101,116,32,99,111,110,116,114,97,99,116,115,40,41,123,114,101,116,117,114,110,91,46,46,46,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,93,125,103,101,116,32,116,111,116,97,108,67,111,110,116,114,97,99,116,115,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,125,105,115,82,101,103,105,115,116,101,114,101,100,40,97,100,100,114,101,115,115,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,46,105,110,99,108,117,100,101,115,40,97,100,100,114,101,115,115,41,125,97,115,121,110,99,32,114,101,103,105,115,116,101,114,67,111,110,116,114,97,99,116,40,97,100,100,114,101,115,115,41,123,105,102,40,97,119,97,105,116,32,109,115,103,46,115,116,97,116,105,99,67,97,108,108,40,97,100,100,114,101,115,115,44,34,104,97,115,82,111,108,101,34,44,91,109,115,103,46,115,101,110,100,101,114,44,34,79,87,78,69,82,34,93,41,44,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,46,105,110,99,108,117,100,101,115,40,97,100,100,114,101,115,115,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,97,108,114,101,97,100,121,32,114,101,103,105,115,116,101,114,101,100,34,41,59,116,104,105,115,46,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,43,61,49,44,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,46,112,117,115,104,40,97,100,100,114,101,115,115,41,125,125,114,101,116,117,114,110,32,70,97,99,116,111,114,121,59,2,91,93";
|
|
425
|
-
var nativeToken = "237,198,141,3,53,89,84,113,119,88,110,55,76,101,103,89,119,65,109,100,117,75,88,119,116,83,52,118,52,100,97,114,113,66,84,81,82,76,90,106,50,57,117,106,112,114,98,104,52,119,121,76,106,112,56,50,87,106,163,26,99,108,97,115,115,32,82,111,108,101,115,123,35,114,111,108,101,115,61,123,79,87,78,69,82,58,91,93,44,77,73,78,84,58,91,93,44,66,85,82,78,58,91,93,125,59,99,111,110,115,116,114,117,99,116,111,114,40,114,111,108,101,115,41,123,105,102,40,114,111,108,101,115,41,123,105,102,40,33,40,114,111,108,101,115,32,105,110,115,116,97,110,99,101,111,102,32,79,98,106,101,99,116,41,41,116,104,114,111,119,32,110,101,119,32,84,121,112,101,69,114,114,111,114,40,34,101,120,112,101,99,116,101,100,32,114,111,108,101,115,32,116,111,32,98,101,32,97,110,32,111,98,106,101,99,116,34,41,59,116,104,105,115,46,35,114,111,108,101,115,61,123,46,46,46,114,111,108,101,115,44,46,46,46,116,104,105,115,46,35,114,111,108,101,115,125,125,101,108,115,101,32,116,104,105,115,46,35,103,114,97,110,116,82,111,108,101,40,109,115,103,46,115,101,110,100,101,114,44,34,79,87,78,69,82,34,41,125,103,101,116,32,115,116,97,116,101,40,41,123,114,101,116,117,114,110,123,114,111,108,101,115,58,116,104,105,115,46,114,111,108,101,115,125,125,103,101,116,32,114,111,108,101,115,40,41,123,114,101,116,117,114,110,123,46,46,46,116,104,105,115,46,35,114,111,108,101,115,125,125,104,97,115,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,123,114,101,116,117,114,110,33,33,116,104,105,115,46,35,114,111,108,101,115,91,114,111,108,101,93,38,38,116,104,105,115,46,35,114,111,108,101,115,91,114,111,108,101,93,46,105,110,99,108,117,100,101,115,40,97,100,100,114,101,115,115,41,125,35,103,114,97,110,116,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,123,105,102,40,116,104,105,115,46,104,97,115,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,96,36,123,114,111,108,101,125,32,114,111,108,101,32,97,108,114,101,97,100,121,32,103,114,97,110,116,101,100,32,102,111,114,32,36,123,97,100,100,114,101,115,115,125,96,41,59,116,104,105,115,46,35,114,111,108,101,115,91,114,111,108,101,93,46,112,117,115,104,40,97,100,100,114,101,115,115,41,125,35,114,101,118,111,107,101,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,123,105,102,40,33,116,104,105,115,46,104,97,115,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,96,36,123,114,111,108,101,125,32,114,111,108,101,32,97,108,114,101,97,100,121,32,114,101,118,111,107,101,100,32,102,111,114,32,36,123,97,100,100,114,101,115,115,125,96,41,59,105,102,40,34,79,87,78,69,82,34,61,61,61,114,111,108,101,38,38,49,61,61,61,116,104,105,115,46,35,114,111,108,101,115,91,114,111,108,101,93,46,108,101,110,103,116,104,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,97,116,108,101,97,115,116,32,111,110,101,32,111,119,110,101,114,32,105,115,32,110,101,101,100,101,100,33,34,41,59,116,104,105,115,46,35,114,111,108,101,115,91,114,111,108,101,93,46,115,112,108,105,99,101,40,116,104,105,115,46,35,114,111,108,101,115,91,114,111,108,101,93,46,105,110,100,101,120,79,102,40,97,100,100,114,101,115,115,41,41,125,103,114,97,110,116,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,123,105,102,40,33,116,104,105,115,46,104,97,115,82,111,108,101,40,97,100,100,114,101,115,115,44,34,79,87,78,69,82,34,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,78,111,116,32,97,108,108,111,119,101,100,34,41,59,116,104,105,115,46,35,103,114,97,110,116,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,125,114,101,118,111,107,101,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,123,105,102,40,33,116,104,105,115,46,104,97,115,82,111,108,101,40,97,100,100,114,101,115,115,44,34,79,87,78,69,82,34,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,78,111,116,32,97,108,108,111,119,101,100,34,41,59,116,104,105,115,46,35,114,101,118,111,107,101,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,125,125,99,108,97,115,115,32,84,111,107,101,110,32,101,120,116,101,110,100,115,32,82,111,108,101,115,123,35,110,97,109,101,59,35,115,121,109,98,111,108,59,35,104,111,108,100,101,114,115,61,48,59,35,98,97,108,97,110,99,101,115,61,123,125,59,35,97,112,112,114,111,118,97,108,115,61,123,125,59,35,100,101,99,105,109,97,108,115,61,49,56,59,35,116,111,116,97,108,83,117,112,112,108,121,61,66,105,103,78,117,109,98,101,114,46,102,114,111,109,40,48,41,59,99,111,110,115,116,114,117,99,116,111,114,40,110,97,109,101,44,115,121,109,98,111,108,44,100,101,99,105,109,97,108,115,61,49,56,44,115,116,97,116,101,41,123,105,102,40,33,110,97,109,101,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,110,97,109,101,32,117,110,100,101,102,105,110,101,100,34,41,59,105,102,40,33,115,121,109,98,111,108,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,115,121,109,98,111,108,32,117,110,100,101,102,105,110,101,100,34,41,59,115,117,112,101,114,40,115,116,97,116,101,63,46,114,111,108,101,115,41,44,116,104,105,115,46,35,110,97,109,101,61,110,97,109,101,44,116,104,105,115,46,35,115,121,109,98,111,108,61,115,121,109,98,111,108,44,116,104,105,115,46,35,100,101,99,105,109,97,108,115,61,100,101,99,105,109,97,108,115,125,103,101,116,32,115,116,97,116,101,40,41,123,114,101,116,117,114,110,123,46,46,46,115,117,112,101,114,46,115,116,97,116,101,44,104,111,108,100,101,114,115,58,116,104,105,115,46,104,111,108,100,101,114,115,44,98,97,108,97,110,99,101,115,58,116,104,105,115,46,98,97,108,97,110,99,101,115,44,97,112,112,114,111,118,97,108,115,58,123,46,46,46,116,104,105,115,46,35,97,112,112,114,111,118,97,108,115,125,44,116,111,116,97,108,83,117,112,112,108,121,58,116,104,105,115,46,116,111,116,97,108,83,117,112,112,108,121,125,125,103,101,116,32,116,111,116,97,108,83,117,112,112,108,121,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,116,111,116,97,108,83,117,112,112,108,121,125,103,101,116,32,110,97,109,101,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,110,97,109,101,125,103,101,116,32,115,121,109,98,111,108,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,115,121,109,98,111,108,125,103,101,116,32,104,111,108,100,101,114,115,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,104,111,108,100,101,114,115,125,103,101,116,32,98,97,108,97,110,99,101,115,40,41,123,114,101,116,117,114,110,123,46,46,46,116,104,105,115,46,35,98,97,108,97,110,99,101,115,125,125,109,105,110,116,40,116,111,44,97,109,111,117,110,116,41,123,105,102,40,33,116,104,105,115,46,104,97,115,82,111,108,101,40,109,115,103,46,115,101,110,100,101,114,44,34,77,73,78,84,34,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,110,111,116,32,97,108,108,111,119,101,100,34,41,59,116,104,105,115,46,35,116,111,116,97,108,83,117,112,112,108,121,61,116,104,105,115,46,35,116,111,116,97,108,83,117,112,112,108,121,46,97,100,100,40,97,109,111,117,110,116,41,44,116,104,105,115,46,35,105,110,99,114,101,97,115,101,66,97,108,97,110,99,101,40,116,111,44,97,109,111,117,110,116,41,125,98,117,114,110,40,102,114,111,109,44,97,109,111,117,110,116,41,123,105,102,40,33,116,104,105,115,46,104,97,115,82,111,108,101,40,109,115,103,46,115,101,110,100,101,114,44,34,66,85,82,78,34,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,110,111,116,32,97,108,108,111,119,101,100,34,41,59,116,104,105,115,46,35,116,111,116,97,108,83,117,112,112,108,121,61,116,104,105,115,46,35,116,111,116,97,108,83,117,112,112,108,121,46,115,117,98,40,97,109,111,117,110,116,41,44,116,104,105,115,46,35,100,101,99,114,101,97,115,101,66,97,108,97,110,99,101,40,102,114,111,109,44,97,109,111,117,110,116,41,125,35,98,101,102,111,114,101,84,114,97,110,115,102,101,114,40,102,114,111,109,44,116,111,44,97,109,111,117,110,116,41,123,105,102,40,33,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,102,114,111,109,93,124,124,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,102,114,111,109,93,60,97,109,111,117,110,116,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,97,109,111,117,110,116,32,101,120,99,101,101,100,115,32,98,97,108,97,110,99,101,34,41,125,35,117,112,100,97,116,101,72,111,108,100,101,114,115,40,97,100,100,114,101,115,115,44,112,114,101,118,105,111,117,115,66,97,108,97,110,99,101,41,123,34,48,120,48,48,34,61,61,61,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,97,100,100,114,101,115,115,93,46,116,111,72,101,120,83,116,114,105,110,103,40,41,63,116,104,105,115,46,35,104,111,108,100,101,114,115,45,61,49,58,34,48,120,48,48,34,33,61,61,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,97,100,100,114,101,115,115,93,46,116,111,72,101,120,83,116,114,105,110,103,40,41,38,38,34,48,120,48,48,34,61,61,61,112,114,101,118,105,111,117,115,66,97,108,97,110,99,101,46,116,111,72,101,120,83,116,114,105,110,103,40,41,38,38,40,116,104,105,115,46,35,104,111,108,100,101,114,115,43,61,49,41,125,35,105,110,99,114,101,97,115,101,66,97,108,97,110,99,101,40,97,100,100,114,101,115,115,44,97,109,111,117,110,116,41,123,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,97,100,100,114,101,115,115,93,124,124,40,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,97,100,100,114,101,115,115,93,61,66,105,103,78,117,109,98,101,114,46,102,114,111,109,40,48,41,41,59,99,111,110,115,116,32,112,114,101,118,105,111,117,115,66,97,108,97,110,99,101,61,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,97,100,100,114,101,115,115,93,59,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,97,100,100,114,101,115,115,93,61,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,97,100,100,114,101,115,115,93,46,97,100,100,40,97,109,111,117,110,116,41,44,116,104,105,115,46,35,117,112,100,97,116,101,72,111,108,100,101,114,115,40,97,100,100,114,101,115,115,44,112,114,101,118,105,111,117,115,66,97,108,97,110,99,101,41,125,35,100,101,99,114,101,97,115,101,66,97,108,97,110,99,101,40,97,100,100,114,101,115,115,44,97,109,111,117,110,116,41,123,99,111,110,115,116,32,112,114,101,118,105,111,117,115,66,97,108,97,110,99,101,61,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,97,100,100,114,101,115,115,93,59,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,97,100,100,114,101,115,115,93,61,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,97,100,100,114,101,115,115,93,46,115,117,98,40,97,109,111,117,110,116,41,44,116,104,105,115,46,35,117,112,100,97,116,101,72,111,108,100,101,114,115,40,97,100,100,114,101,115,115,44,112,114,101,118,105,111,117,115,66,97,108,97,110,99,101,41,125,98,97,108,97,110,99,101,79,102,40,97,100,100,114,101,115,115,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,97,100,100,114,101,115,115,93,125,115,101,116,65,112,112,114,111,118,97,108,40,111,112,101,114,97,116,111,114,44,97,109,111,117,110,116,41,123,99,111,110,115,116,32,111,119,110,101,114,61,109,115,103,46,115,101,110,100,101,114,59,116,104,105,115,46,35,97,112,112,114,111,118,97,108,115,91,111,119,110,101,114,93,124,124,40,116,104,105,115,46,35,97,112,112,114,111,118,97,108,115,91,111,119,110,101,114,93,61,123,125,41,44,116,104,105,115,46,35,97,112,112,114,111,118,97,108,115,91,111,119,110,101,114,93,91,111,112,101,114,97,116,111,114,93,61,97,109,111,117,110,116,125,97,112,112,114,111,118,101,100,40,111,119,110,101,114,44,111,112,101,114,97,116,111,114,44,97,109,111,117,110,116,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,97,112,112,114,111,118,97,108,115,91,111,119,110,101,114,93,91,111,112,101,114,97,116,111,114,93,61,61,61,97,109,111,117,110,116,125,116,114,97,110,115,102,101,114,40,102,114,111,109,44,116,111,44,97,109,111,117,110,116,41,123,97,109,111,117,110,116,61,66,105,103,78,117,109,98,101,114,46,102,114,111,109,40,97,109,111,117,110,116,41,44,116,104,105,115,46,35,98,101,102,111,114,101,84,114,97,110,115,102,101,114,40,102,114,111,109,44,116,111,44,97,109,111,117,110,116,41,44,116,104,105,115,46,35,100,101,99,114,101,97,115,101,66,97,108,97,110,99,101,40,102,114,111,109,44,97,109,111,117,110,116,41,44,116,104,105,115,46,35,105,110,99,114,101,97,115,101,66,97,108,97,110,99,101,40,116,111,44,97,109,111,117,110,116,41,125,125,99,108,97,115,115,32,65,114,116,79,110,108,105,110,101,32,101,120,116,101,110,100,115,32,84,111,107,101,110,123,99,111,110,115,116,114,117,99,116,111,114,40,115,116,97,116,101,41,123,115,117,112,101,114,40,34,65,114,116,79,110,108,105,110,101,34,44,34,65,82,84,34,44,49,56,44,115,116,97,116,101,41,125,125,114,101,116,117,114,110,32,65,114,116,79,110,108,105,110,101,59,2,91,93";
|
|
426
|
-
var nameService = "237,198,141,3,53,89,84,113,119,88,110,55,76,101,103,89,119,65,109,100,117,75,88,119,116,83,52,118,52,100,97,114,113,66,84,81,82,76,90,106,50,57,117,106,112,114,98,104,52,119,121,76,106,112,56,50,87,106,131,13,99,108,97,115,115,32,78,97,109,101,83,101,114,118,105,99,101,123,35,110,97,109,101,61,34,65,114,116,79,110,108,105,110,101,78,97,109,101,83,101,114,118,105,99,101,34,59,35,111,119,110,101,114,59,35,112,114,105,99,101,61,48,59,35,114,101,103,105,115,116,114,121,61,123,125,59,35,99,117,114,114,101,110,99,121,59,103,101,116,32,110,97,109,101,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,110,97,109,101,125,103,101,116,32,114,101,103,105,115,116,114,121,40,41,123,114,101,116,117,114,110,123,46,46,46,116,104,105,115,46,35,114,101,103,105,115,116,114,121,125,125,103,101,116,32,115,116,97,116,101,40,41,123,114,101,116,117,114,110,123,111,119,110,101,114,58,116,104,105,115,46,35,111,119,110,101,114,44,114,101,103,105,115,116,114,121,58,116,104,105,115,46,35,114,101,103,105,115,116,114,121,44,99,117,114,114,101,110,99,121,58,116,104,105,115,46,35,99,117,114,114,101,110,99,121,44,112,114,105,99,101,58,116,104,105,115,46,35,112,114,105,99,101,125,125,99,111,110,115,116,114,117,99,116,111,114,40,102,97,99,116,111,114,121,65,100,100,114,101,115,115,44,99,117,114,114,101,110,99,121,44,118,97,108,105,100,97,116,111,114,65,100,100,114,101,115,115,44,112,114,105,99,101,44,115,116,97,116,101,41,123,115,116,97,116,101,63,40,116,104,105,115,46,35,111,119,110,101,114,61,115,116,97,116,101,46,111,119,110,101,114,44,116,104,105,115,46,35,114,101,103,105,115,116,114,121,61,115,116,97,116,101,46,114,101,103,105,115,116,114,121,44,116,104,105,115,46,35,99,117,114,114,101,110,99,121,61,115,116,97,116,101,46,99,117,114,114,101,110,99,121,44,116,104,105,115,46,35,112,114,105,99,101,61,115,116,97,116,101,46,112,114,105,99,101,41,58,40,116,104,105,115,46,35,111,119,110,101,114,61,109,115,103,46,115,101,110,100,101,114,44,116,104,105,115,46,35,112,114,105,99,101,61,112,114,105,99,101,44,116,104,105,115,46,35,114,101,103,105,115,116,114,121,46,65,114,116,79,110,108,105,110,101,67,111,110,116,114,97,99,116,70,97,99,116,111,114,121,61,123,111,119,110,101,114,58,109,115,103,46,115,101,110,100,101,114,44,97,100,100,114,101,115,115,58,102,97,99,116,111,114,121,65,100,100,114,101,115,115,125,44,116,104,105,115,46,35,114,101,103,105,115,116,114,121,46,65,114,116,79,110,108,105,110,101,84,111,107,101,110,61,123,111,119,110,101,114,58,109,115,103,46,115,101,110,100,101,114,44,97,100,100,114,101,115,115,58,99,117,114,114,101,110,99,121,125,44,116,104,105,115,46,35,114,101,103,105,115,116,114,121,46,65,114,116,79,110,108,105,110,101,86,97,108,105,100,97,116,111,114,115,61,123,111,119,110,101,114,58,109,115,103,46,115,101,110,100,101,114,44,97,100,100,114,101,115,115,58,118,97,108,105,100,97,116,111,114,65,100,100,114,101,115,115,125,44,116,104,105,115,46,35,99,117,114,114,101,110,99,121,61,99,117,114,114,101,110,99,121,41,125,99,104,97,110,103,101,79,119,110,101,114,40,111,119,110,101,114,41,123,105,102,40,109,115,103,46,115,101,110,100,101,114,33,61,61,116,104,105,115,46,35,111,119,110,101,114,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,110,111,32,111,119,110,101,114,34,41,59,116,104,105,115,46,35,111,119,110,101,114,61,111,119,110,101,114,125,99,104,97,110,103,101,80,114,105,99,101,40,112,114,105,99,101,41,123,105,102,40,109,115,103,46,115,101,110,100,101,114,33,61,61,116,104,105,115,46,35,111,119,110,101,114,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,110,111,32,111,119,110,101,114,34,41,59,116,104,105,115,46,35,112,114,105,99,101,61,112,114,105,99,101,125,99,104,97,110,103,101,67,117,114,114,101,110,99,121,40,99,117,114,114,101,110,99,121,41,123,105,102,40,109,115,103,46,115,101,110,100,101,114,33,61,61,116,104,105,115,46,35,111,119,110,101,114,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,110,111,32,111,119,110,101,114,34,41,59,116,104,105,115,46,35,99,117,114,114,101,110,99,121,61,99,117,114,114,101,110,99,121,125,97,115,121,110,99,32,112,117,114,99,104,97,115,101,78,97,109,101,40,110,97,109,101,44,97,100,100,114,101,115,115,41,123,105,102,40,97,119,97,105,116,32,109,115,103,46,99,97,108,108,40,116,104,105,115,46,35,99,117,114,114,101,110,99,121,44,34,98,97,108,97,110,99,101,79,102,34,44,91,109,115,103,46,115,101,110,100,101,114,93,41,60,116,104,105,115,46,35,112,114,105,99,101,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,112,114,105,99,101,32,101,120,99,101,101,100,115,32,98,97,108,97,110,99,101,34,41,59,116,114,121,123,97,119,97,105,116,32,109,115,103,46,99,97,108,108,40,116,104,105,115,46,35,99,117,114,114,101,110,99,121,44,34,116,114,97,110,115,102,101,114,34,44,91,109,115,103,46,115,101,110,100,101,114,44,116,104,105,115,46,35,111,119,110,101,114,44,116,104,105,115,46,35,112,114,105,99,101,93,41,125,99,97,116,99,104,40,101,114,114,111,114,41,123,116,104,114,111,119,32,101,114,114,111,114,125,116,104,105,115,46,35,114,101,103,105,115,116,114,121,91,110,97,109,101,93,61,123,111,119,110,101,114,58,109,115,103,46,115,101,110,100,101,114,44,97,100,100,114,101,115,115,58,97,100,100,114,101,115,115,125,125,108,111,111,107,117,112,40,110,97,109,101,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,114,101,103,105,115,116,114,121,91,110,97,109,101,93,125,116,114,97,110,115,102,101,114,79,119,110,101,114,115,104,105,112,40,110,97,109,101,44,116,111,41,123,105,102,40,109,115,103,46,115,101,110,100,101,114,33,61,61,116,104,105,115,46,35,114,101,103,105,115,116,114,121,91,110,97,109,101,93,46,111,119,110,101,114,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,110,111,116,32,97,32,111,119,110,101,114,34,41,59,116,104,105,115,46,35,114,101,103,105,115,116,114,121,91,110,97,109,101,93,46,111,119,110,101,114,61,116,111,125,99,104,97,110,103,101,65,100,100,114,101,115,115,40,110,97,109,101,44,97,100,100,114,101,115,115,41,123,105,102,40,109,115,103,46,115,101,110,100,101,114,33,61,61,116,104,105,115,46,35,114,101,103,105,115,116,114,121,91,110,97,109,101,93,46,111,119,110,101,114,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,110,111,116,32,97,32,111,119,110,101,114,34,41,59,116,104,105,115,46,35,114,101,103,105,115,116,114,121,91,110,97,109,101,93,46,97,100,100,114,101,115,115,61,97,100,100,114,101,115,115,125,125,114,101,116,117,114,110,32,78,97,109,101,83,101,114,118,105,99,101,59,212,1,91,34,73,72,78,89,50,71,81,71,89,79,54,66,68,88,72,72,76,50,75,72,75,51,75,81,85,51,53,51,72,80,67,65,82,85,86,65,80,50,85,86,87,72,52,69,85,86,86,52,74,88,84,51,55,51,75,83,86,70,50,34,44,34,73,72,78,89,50,71,81,72,51,67,52,52,82,82,85,68,77,52,88,76,71,54,55,75,72,72,83,51,85,69,82,55,76,54,78,85,76,68,72,72,54,65,67,86,79,65,86,84,76,65,71,66,82,76,66,53,66,83,74,34,44,34,73,72,78,89,50,71,81,72,70,75,84,86,69,66,74,71,82,84,54,88,71,72,82,52,51,52,75,87,76,71,68,72,79,86,69,73,52,79,66,54,85,75,55,81,85,75,67,78,79,73,67,77,86,84,88,82,87,84,83,34,44,34,49,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,34,93";
|
|
427
|
-
var validators = "237,198,141,3,53,89,84,113,119,88,110,55,76,101,103,89,119,65,109,100,117,75,88,119,116,83,52,118,52,100,97,114,113,66,84,81,82,76,90,106,50,57,117,106,112,114,98,104,52,119,121,76,106,112,56,50,87,106,164,28,99,108,97,115,115,32,82,111,108,101,115,123,35,114,111,108,101,115,61,123,79,87,78,69,82,58,91,93,44,77,73,78,84,58,91,93,44,66,85,82,78,58,91,93,125,59,99,111,110,115,116,114,117,99,116,111,114,40,114,111,108,101,115,41,123,105,102,40,114,111,108,101,115,41,123,105,102,40,33,40,114,111,108,101,115,32,105,110,115,116,97,110,99,101,111,102,32,79,98,106,101,99,116,41,41,116,104,114,111,119,32,110,101,119,32,84,121,112,101,69,114,114,111,114,40,34,101,120,112,101,99,116,101,100,32,114,111,108,101,115,32,116,111,32,98,101,32,97,110,32,111,98,106,101,99,116,34,41,59,116,104,105,115,46,35,114,111,108,101,115,61,123,46,46,46,114,111,108,101,115,44,46,46,46,116,104,105,115,46,35,114,111,108,101,115,125,125,101,108,115,101,32,116,104,105,115,46,35,103,114,97,110,116,82,111,108,101,40,109,115,103,46,115,101,110,100,101,114,44,34,79,87,78,69,82,34,41,125,103,101,116,32,115,116,97,116,101,40,41,123,114,101,116,117,114,110,123,114,111,108,101,115,58,116,104,105,115,46,114,111,108,101,115,125,125,103,101,116,32,114,111,108,101,115,40,41,123,114,101,116,117,114,110,123,46,46,46,116,104,105,115,46,35,114,111,108,101,115,125,125,104,97,115,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,123,114,101,116,117,114,110,33,33,116,104,105,115,46,35,114,111,108,101,115,91,114,111,108,101,93,38,38,116,104,105,115,46,35,114,111,108,101,115,91,114,111,108,101,93,46,105,110,99,108,117,100,101,115,40,97,100,100,114,101,115,115,41,125,35,103,114,97,110,116,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,123,105,102,40,116,104,105,115,46,104,97,115,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,96,36,123,114,111,108,101,125,32,114,111,108,101,32,97,108,114,101,97,100,121,32,103,114,97,110,116,101,100,32,102,111,114,32,36,123,97,100,100,114,101,115,115,125,96,41,59,116,104,105,115,46,35,114,111,108,101,115,91,114,111,108,101,93,46,112,117,115,104,40,97,100,100,114,101,115,115,41,125,35,114,101,118,111,107,101,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,123,105,102,40,33,116,104,105,115,46,104,97,115,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,96,36,123,114,111,108,101,125,32,114,111,108,101,32,97,108,114,101,97,100,121,32,114,101,118,111,107,101,100,32,102,111,114,32,36,123,97,100,100,114,101,115,115,125,96,41,59,105,102,40,34,79,87,78,69,82,34,61,61,61,114,111,108,101,38,38,49,61,61,61,116,104,105,115,46,35,114,111,108,101,115,91,114,111,108,101,93,46,108,101,110,103,116,104,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,97,116,108,101,97,115,116,32,111,110,101,32,111,119,110,101,114,32,105,115,32,110,101,101,100,101,100,33,34,41,59,116,104,105,115,46,35,114,111,108,101,115,91,114,111,108,101,93,46,115,112,108,105,99,101,40,116,104,105,115,46,35,114,111,108,101,115,91,114,111,108,101,93,46,105,110,100,101,120,79,102,40,97,100,100,114,101,115,115,41,41,125,103,114,97,110,116,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,123,105,102,40,33,116,104,105,115,46,104,97,115,82,111,108,101,40,97,100,100,114,101,115,115,44,34,79,87,78,69,82,34,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,78,111,116,32,97,108,108,111,119,101,100,34,41,59,116,104,105,115,46,35,103,114,97,110,116,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,125,114,101,118,111,107,101,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,123,105,102,40,33,116,104,105,115,46,104,97,115,82,111,108,101,40,97,100,100,114,101,115,115,44,34,79,87,78,69,82,34,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,78,111,116,32,97,108,108,111,119,101,100,34,41,59,116,104,105,115,46,35,114,101,118,111,107,101,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,125,125,99,108,97,115,115,32,86,97,108,105,100,97,116,111,114,115,32,101,120,116,101,110,100,115,32,82,111,108,101,115,123,35,110,97,109,101,61,34,65,114,116,79,110,108,105,110,101,86,97,108,105,100,97,116,111,114,115,34,59,35,116,111,116,97,108,86,97,108,105,100,97,116,111,114,115,61,48,59,35,97,99,116,105,118,101,86,97,108,105,100,97,116,111,114,115,61,48,59,35,118,97,108,105,100,97,116,111,114,115,61,123,125,59,35,99,117,114,114,101,110,99,121,59,35,109,105,110,105,109,117,109,66,97,108,97,110,99,101,59,103,101,116,32,115,116,97,116,101,40,41,123,114,101,116,117,114,110,123,46,46,46,115,117,112,101,114,46,115,116,97,116,101,44,109,105,110,105,109,117,109,66,97,108,97,110,99,101,58,116,104,105,115,46,35,109,105,110,105,109,117,109,66,97,108,97,110,99,101,44,99,117,114,114,101,110,99,121,58,116,104,105,115,46,35,99,117,114,114,101,110,99,121,44,116,111,116,97,108,86,97,108,105,100,97,116,111,114,115,58,116,104,105,115,46,35,116,111,116,97,108,86,97,108,105,100,97,116,111,114,115,44,97,99,116,105,118,101,86,97,108,105,100,97,116,111,114,115,58,116,104,105,115,46,35,97,99,116,105,118,101,86,97,108,105,100,97,116,111,114,115,44,118,97,108,105,100,97,116,111,114,115,58,116,104,105,115,46,35,118,97,108,105,100,97,116,111,114,115,125,125,99,111,110,115,116,114,117,99,116,111,114,40,116,111,107,101,110,65,100,100,114,101,115,115,44,115,116,97,116,101,41,123,115,117,112,101,114,40,115,116,97,116,101,63,46,114,111,108,101,115,41,44,115,116,97,116,101,63,40,116,104,105,115,46,35,109,105,110,105,109,117,109,66,97,108,97,110,99,101,61,115,116,97,116,101,46,109,105,110,105,109,117,109,66,97,108,97,110,99,101,44,116,104,105,115,46,35,99,117,114,114,101,110,99,121,61,115,116,97,116,101,46,99,117,114,114,101,110,99,121,44,116,104,105,115,46,35,116,111,116,97,108,86,97,108,105,100,97,116,111,114,115,61,115,116,97,116,101,46,116,111,116,97,108,86,97,108,105,100,97,116,111,114,115,44,116,104,105,115,46,35,97,99,116,105,118,101,86,97,108,105,100,97,116,111,114,115,61,115,116,97,116,101,46,97,99,116,105,118,101,86,97,108,105,100,97,116,111,114,115,44,116,104,105,115,46,35,118,97,108,105,100,97,116,111,114,115,61,115,116,97,116,101,46,118,97,108,105,100,97,116,111,114,115,41,58,40,116,104,105,115,46,35,109,105,110,105,109,117,109,66,97,108,97,110,99,101,61,53,101,52,44,116,104,105,115,46,35,99,117,114,114,101,110,99,121,61,116,111,107,101,110,65,100,100,114,101,115,115,44,116,104,105,115,46,35,116,111,116,97,108,86,97,108,105,100,97,116,111,114,115,43,61,49,44,116,104,105,115,46,35,97,99,116,105,118,101,86,97,108,105,100,97,116,111,114,115,43,61,49,44,116,104,105,115,46,35,118,97,108,105,100,97,116,111,114,115,91,109,115,103,46,115,101,110,100,101,114,93,61,123,102,105,114,115,116,83,101,101,110,58,68,97,116,101,46,110,111,119,40,41,44,108,97,115,116,83,101,101,110,58,68,97,116,101,46,110,111,119,40,41,44,97,99,116,105,118,101,58,33,48,125,41,125,103,101,116,32,110,97,109,101,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,110,97,109,101,125,103,101,116,32,99,117,114,114,101,110,99,121,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,99,117,114,114,101,110,99,121,125,103,101,116,32,118,97,108,105,100,97,116,111,114,115,40,41,123,114,101,116,117,114,110,123,46,46,46,116,104,105,115,46,35,118,97,108,105,100,97,116,111,114,115,125,125,103,101,116,32,116,111,116,97,108,86,97,108,105,100,97,116,111,114,115,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,116,111,116,97,108,86,97,108,105,100,97,116,111,114,115,125,103,101,116,32,109,105,110,105,109,117,109,66,97,108,97,110,99,101,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,109,105,110,105,109,117,109,66,97,108,97,110,99,101,125,99,104,97,110,103,101,67,117,114,114,101,110,99,121,40,99,117,114,114,101,110,99,121,41,123,105,102,40,33,116,104,105,115,46,104,97,115,82,111,108,101,40,109,115,103,46,115,101,110,100,101,114,44,34,79,87,78,69,82,34,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,110,111,116,32,97,110,32,111,119,110,101,114,34,41,59,116,104,105,115,46,35,99,117,114,114,101,110,99,121,61,99,117,114,114,101,110,99,121,125,104,97,115,40,118,97,108,105,100,97,116,111,114,41,123,114,101,116,117,114,110,32,66,111,111,108,101,97,110,40,118,111,105,100,32,48,33,61,61,116,104,105,115,46,35,118,97,108,105,100,97,116,111,114,115,91,118,97,108,105,100,97,116,111,114,93,41,125,35,105,115,65,108,108,111,119,101,100,40,97,100,100,114,101,115,115,41,123,105,102,40,109,115,103,46,115,101,110,100,101,114,33,61,61,97,100,100,114,101,115,115,38,38,33,116,104,105,115,46,104,97,115,82,111,108,101,40,109,115,103,46,115,101,110,100,101,114,44,34,79,87,78,69,82,34,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,115,101,110,100,101,114,32,105,115,32,110,111,116,32,116,104,101,32,118,97,108,105,100,97,116,111,114,32,111,114,32,111,119,110,101,114,34,41,59,114,101,116,117,114,110,33,48,125,97,115,121,110,99,32,97,100,100,86,97,108,105,100,97,116,111,114,40,118,97,108,105,100,97,116,111,114,41,123,105,102,40,116,104,105,115,46,35,105,115,65,108,108,111,119,101,100,40,118,97,108,105,100,97,116,111,114,41,44,116,104,105,115,46,104,97,115,40,118,97,108,105,100,97,116,111,114,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,97,108,114,101,97,100,121,32,97,32,118,97,108,105,100,97,116,111,114,34,41,59,99,111,110,115,116,32,98,97,108,97,110,99,101,61,97,119,97,105,116,32,109,115,103,46,115,116,97,116,105,99,67,97,108,108,40,116,104,105,115,46,99,117,114,114,101,110,99,121,44,34,98,97,108,97,110,99,101,79,102,34,44,91,118,97,108,105,100,97,116,111,114,93,41,59,105,102,40,98,97,108,97,110,99,101,60,116,104,105,115,46,109,105,110,105,109,117,109,66,97,108,97,110,99,101,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,96,98,97,108,97,110,99,101,32,116,111,32,108,111,119,33,32,103,111,116,58,32,36,123,98,97,108,97,110,99,101,125,32,110,101,101,100,58,32,36,123,116,104,105,115,46,35,109,105,110,105,109,117,109,66,97,108,97,110,99,101,125,96,41,59,116,104,105,115,46,35,116,111,116,97,108,86,97,108,105,100,97,116,111,114,115,43,61,49,44,116,104,105,115,46,35,97,99,116,105,118,101,86,97,108,105,100,97,116,111,114,115,43,61,49,44,116,104,105,115,46,35,118,97,108,105,100,97,116,111,114,115,91,118,97,108,105,100,97,116,111,114,93,61,123,102,105,114,115,116,83,101,101,110,58,68,97,116,101,46,110,111,119,40,41,44,108,97,115,116,83,101,101,110,58,68,97,116,101,46,110,111,119,40,41,44,97,99,116,105,118,101,58,33,48,125,125,114,101,109,111,118,101,86,97,108,105,100,97,116,111,114,40,118,97,108,105,100,97,116,111,114,41,123,105,102,40,116,104,105,115,46,35,105,115,65,108,108,111,119,101,100,40,118,97,108,105,100,97,116,111,114,41,44,33,116,104,105,115,46,104,97,115,40,118,97,108,105,100,97,116,111,114,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,118,97,108,105,100,97,116,111,114,32,110,111,116,32,102,111,117,110,100,34,41,59,116,104,105,115,46,35,116,111,116,97,108,86,97,108,105,100,97,116,111,114,115,45,61,49,44,116,104,105,115,46,35,118,97,108,105,100,97,116,111,114,115,91,118,97,108,105,100,97,116,111,114,93,46,97,99,116,105,118,101,38,38,40,116,104,105,115,46,35,97,99,116,105,118,101,86,97,108,105,100,97,116,111,114,115,45,61,49,41,44,100,101,108,101,116,101,32,116,104,105,115,46,35,118,97,108,105,100,97,116,111,114,115,91,118,97,108,105,100,97,116,111,114,93,125,97,115,121,110,99,32,117,112,100,97,116,101,86,97,108,105,100,97,116,111,114,40,118,97,108,105,100,97,116,111,114,44,97,99,116,105,118,101,41,123,105,102,40,116,104,105,115,46,35,105,115,65,108,108,111,119,101,100,40,118,97,108,105,100,97,116,111,114,41,44,33,116,104,105,115,46,104,97,115,40,118,97,108,105,100,97,116,111,114,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,118,97,108,105,100,97,116,111,114,32,110,111,116,32,102,111,117,110,100,34,41,59,99,111,110,115,116,32,98,97,108,97,110,99,101,61,97,119,97,105,116,32,109,115,103,46,115,116,97,116,105,99,67,97,108,108,40,116,104,105,115,46,99,117,114,114,101,110,99,121,44,34,98,97,108,97,110,99,101,79,102,34,44,91,118,97,108,105,100,97,116,111,114,93,41,59,105,102,40,98,97,108,97,110,99,101,60,116,104,105,115,46,109,105,110,105,109,117,109,66,97,108,97,110,99,101,38,38,97,99,116,105,118,101,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,96,98,97,108,97,110,99,101,32,116,111,32,108,111,119,33,32,103,111,116,58,32,36,123,98,97,108,97,110,99,101,125,32,110,101,101,100,58,32,36,123,116,104,105,115,46,35,109,105,110,105,109,117,109,66,97,108,97,110,99,101,125,96,41,59,105,102,40,116,104,105,115,46,35,118,97,108,105,100,97,116,111,114,115,91,118,97,108,105,100,97,116,111,114,93,46,97,99,116,105,118,101,61,61,61,97,99,116,105,118,101,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,97,108,114,101,97,100,121,32,34,43,40,97,99,116,105,118,101,63,34,97,99,116,105,118,97,116,101,100,34,58,34,100,101,97,99,116,105,118,97,116,101,100,34,41,41,59,97,99,116,105,118,101,63,116,104,105,115,46,35,97,99,116,105,118,101,86,97,108,105,100,97,116,111,114,115,43,61,49,58,116,104,105,115,46,35,97,99,116,105,118,101,86,97,108,105,100,97,116,111,114,115,45,61,49,44,116,104,105,115,46,35,118,97,108,105,100,97,116,111,114,115,91,118,97,108,105,100,97,116,111,114,93,46,97,99,116,105,118,101,61,97,99,116,105,118,101,125,125,114,101,116,117,114,110,32,86,97,108,105,100,97,116,111,114,115,59,63,91,34,73,72,78,89,50,71,81,72,51,67,52,52,82,82,85,68,77,52,88,76,71,54,55,75,72,72,83,51,85,69,82,55,76,54,78,85,76,68,72,72,54,65,67,86,79,65,86,84,76,65,71,66,82,76,66,53,66,83,74,34,93";
|
|
428
|
-
var bytecodes = {
|
|
429
|
-
contractFactory: contractFactory,
|
|
430
|
-
nativeToken: nativeToken,
|
|
431
|
-
nameService: nameService,
|
|
432
|
-
validators: validators
|
|
433
|
-
};
|
|
434
|
-
|
|
435
|
-
const contractFactoryMessage = bytecodes.contractFactory;
|
|
436
|
-
const nativeTokenMessage = bytecodes.nativeToken;
|
|
437
|
-
const nameServiceMessage = bytecodes.nameService;
|
|
438
|
-
const validatorsMessage = bytecodes.validators;
|
|
439
|
-
const createContractMessage = async (creator, contract, constructorParameters = []) => {
|
|
440
|
-
return new ContractMessage({
|
|
441
|
-
creator,
|
|
442
|
-
contract,
|
|
443
|
-
constructorParameters
|
|
444
|
-
});
|
|
445
|
-
};
|
|
446
|
-
const calculateFee = async (transaction, format = false) => {
|
|
447
|
-
// excluded from fees
|
|
448
|
-
if (transaction.to === validators$2)
|
|
449
|
-
return 0;
|
|
450
|
-
transaction = await new TransactionMessage(transaction);
|
|
451
|
-
let fee = parseUnits(String(transaction.encoded.length));
|
|
452
|
-
// fee per gb
|
|
453
|
-
fee = fee.div(1073741824);
|
|
454
|
-
// fee = fee.div(1000000)
|
|
455
|
-
return format ? formatUnits(fee.toString()) : fee;
|
|
456
|
-
};
|
|
457
|
-
const createTransactionHash = async (transaction) => {
|
|
458
|
-
const isRawTransactionMessage = transaction instanceof RawTransactionMessage;
|
|
459
|
-
let message;
|
|
460
|
-
if (!isRawTransactionMessage)
|
|
461
|
-
message = await new RawTransactionMessage(transaction instanceof TransactionMessage ? transaction.decoded : transaction);
|
|
462
|
-
else
|
|
463
|
-
message = transaction;
|
|
464
|
-
return (await message.peernetHash).digest;
|
|
465
|
-
};
|
|
466
|
-
const signTransaction = async (transaction, wallet) => {
|
|
467
|
-
const signature = toBase58(await wallet.sign(await createTransactionHash(transaction)));
|
|
468
|
-
return { ...transaction, signature };
|
|
469
|
-
};
|
|
470
|
-
|
|
471
|
-
const limit = 1800;
|
|
472
|
-
const transactionLimit = 1800;
|
|
473
|
-
const requestTimeout = 30000;
|
|
474
|
-
const syncTimeout = 30000;
|
|
475
|
-
class Protocol {
|
|
476
|
-
constructor() {
|
|
477
|
-
this.resolveTimeout = 10000;
|
|
478
|
-
}
|
|
479
|
-
get limit() {
|
|
480
|
-
return limit;
|
|
481
|
-
}
|
|
482
|
-
get transactionLimit() {
|
|
483
|
-
return transactionLimit;
|
|
484
|
-
}
|
|
485
|
-
get requestTimeout() {
|
|
486
|
-
return requestTimeout;
|
|
487
|
-
}
|
|
488
|
-
get syncTimeout() {
|
|
489
|
-
return syncTimeout;
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
class Transaction extends Protocol {
|
|
494
|
-
constructor() {
|
|
495
|
-
super();
|
|
496
|
-
}
|
|
497
|
-
/**
|
|
498
|
-
*
|
|
499
|
-
* @param {Address[]} transactions
|
|
500
|
-
* @returns transactions to include
|
|
501
|
-
*/
|
|
502
|
-
async getTransactions(transactions) {
|
|
503
|
-
return new Promise(async (resolve, reject) => {
|
|
504
|
-
let size = 0;
|
|
505
|
-
const _transactions = [];
|
|
506
|
-
await Promise.all(transactions.map(async (tx) => {
|
|
507
|
-
tx = await new TransactionMessage(tx);
|
|
508
|
-
size += tx.encoded.length;
|
|
509
|
-
if (!formatBytes(size).includes('MB') ||
|
|
510
|
-
(formatBytes(size).includes('MB') && Number(formatBytes(size).split(' MB')[0]) <= 0.75))
|
|
511
|
-
_transactions.push({ ...tx.decoded, hash: await tx.hash() });
|
|
512
|
-
else
|
|
513
|
-
resolve(_transactions);
|
|
514
|
-
}));
|
|
515
|
-
return resolve(_transactions);
|
|
516
|
-
});
|
|
517
|
-
}
|
|
518
|
-
/**
|
|
519
|
-
*
|
|
520
|
-
* @param {Transaction[]} transactions An array containing Transactions
|
|
521
|
-
* @returns {TransactionMessage}
|
|
522
|
-
*/
|
|
523
|
-
async promiseTransactions(transactions) {
|
|
524
|
-
transactions = await Promise.all(transactions.map((tx) => new TransactionMessage(tx.encoded || tx)));
|
|
525
|
-
return transactions;
|
|
526
|
-
}
|
|
527
|
-
/**
|
|
528
|
-
*
|
|
529
|
-
* @param {Transaction[]} transactions An array containing Transactions
|
|
530
|
-
* @returns {Object} {transaction.decoded, transaction.hash}
|
|
531
|
-
*/
|
|
532
|
-
async promiseTransactionsContent(transactions) {
|
|
533
|
-
transactions = await Promise.all(transactions.map((tx) => new Promise(async (resolve, reject) => {
|
|
534
|
-
resolve({ ...tx.decoded, hash: await tx.hash() });
|
|
535
|
-
})));
|
|
536
|
-
return transactions;
|
|
537
|
-
}
|
|
538
|
-
/**
|
|
539
|
-
* When a nonce isn't found for an address fallback to just checking the transactionnPoolStore
|
|
540
|
-
* @param {Address} address
|
|
541
|
-
* @returns {Number} nonce
|
|
542
|
-
*/
|
|
543
|
-
async #getNonceFallback(address) {
|
|
544
|
-
let transactions = await globalThis.transactionPoolStore.values();
|
|
545
|
-
transactions = await this.promiseTransactions(transactions);
|
|
546
|
-
transactions = transactions.filter((tx) => tx.decoded.from === address);
|
|
547
|
-
transactions = await this.promiseTransactionsContent(transactions);
|
|
548
|
-
// @ts-ignore
|
|
549
|
-
if (this.lastBlock?.hash && transactions.length === 0 && this.lastBlock.hash !== '0x0') {
|
|
550
|
-
// @ts-ignore
|
|
551
|
-
let block = await peernet.get(this.lastBlock.hash, 'block');
|
|
552
|
-
block = await new BlockMessage(block);
|
|
553
|
-
// for (let tx of block.decoded?.transactions) {
|
|
554
|
-
// tx = await peernet.get(tx, 'transaction')
|
|
555
|
-
// transactions.push(new TransactionMessage(tx))
|
|
556
|
-
// }
|
|
557
|
-
transactions = transactions.filter((tx) => tx.from === address);
|
|
558
|
-
while (transactions.length === 0 && block.decoded.index !== 0 && block.decoded.previousHash !== '0x0') {
|
|
559
|
-
block = await globalThis.blockStore.get(block.decoded.previousHash);
|
|
560
|
-
block = await new BlockMessage(block);
|
|
561
|
-
transactions = block.decoded.transactions.filter((tx) => tx.from === address);
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
if (transactions.length === 0)
|
|
565
|
-
return 0;
|
|
566
|
-
transactions = transactions.sort((a, b) => a.timestamp - b.timestamp);
|
|
567
|
-
return transactions[transactions.length - 1].nonce;
|
|
568
|
-
}
|
|
569
|
-
/**
|
|
570
|
-
* Get amount of transactions by address
|
|
571
|
-
* @param {Address} address The address to get the nonce for
|
|
572
|
-
* @returns {Number} nonce
|
|
573
|
-
*/
|
|
574
|
-
async getNonce(address) {
|
|
575
|
-
if (!(await globalThis.accountsStore.has(address))) {
|
|
576
|
-
const nonce = await this.#getNonceFallback(address);
|
|
577
|
-
await globalThis.accountsStore.put(address, new TextEncoder().encode(String(nonce)));
|
|
578
|
-
}
|
|
579
|
-
// todo: are those in the pool in cluded also ? they need to be included!!!
|
|
580
|
-
let nonce = await globalThis.accountsStore.get(address);
|
|
581
|
-
nonce = new TextDecoder().decode(nonce);
|
|
582
|
-
let transactions = await globalThis.transactionPoolStore.values();
|
|
583
|
-
transactions = await this.promiseTransactions(transactions);
|
|
584
|
-
transactions = transactions.filter((tx) => tx.decoded.from === address);
|
|
585
|
-
transactions = await this.promiseTransactionsContent(transactions);
|
|
586
|
-
for (const transaction of transactions) {
|
|
587
|
-
if (transaction.nonce > nonce)
|
|
588
|
-
nonce = transaction.nonce;
|
|
589
|
-
}
|
|
590
|
-
return Number(nonce);
|
|
591
|
-
}
|
|
592
|
-
async validateNonce(address, nonce) {
|
|
593
|
-
let previousNonce = await globalThis.accountsStore.get(address);
|
|
594
|
-
previousNonce = Number(new TextDecoder().decode(previousNonce));
|
|
595
|
-
if (previousNonce > nonce)
|
|
596
|
-
throw new Error(`a transaction with a higher nonce already exists`);
|
|
597
|
-
if (previousNonce === nonce)
|
|
598
|
-
throw new Error(`a transaction with the same nonce already exists`);
|
|
599
|
-
let transactions = await globalThis.transactionPoolStore.values();
|
|
600
|
-
transactions = await this.promiseTransactions(transactions);
|
|
601
|
-
transactions = transactions.filter((tx) => tx.decoded.from === address);
|
|
602
|
-
for (const transaction of transactions) {
|
|
603
|
-
if (transaction.decoded.nonce > nonce)
|
|
604
|
-
throw new Error(`a transaction with a higher nonce already exists`);
|
|
605
|
-
if (transaction.decoded.nonce === nonce)
|
|
606
|
-
throw new Error(`a transaction with the same nonce already exists`);
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
isTransactionMessage(message) {
|
|
610
|
-
if (message instanceof TransactionMessage)
|
|
611
|
-
return true;
|
|
612
|
-
return false;
|
|
613
|
-
}
|
|
614
|
-
async createTransactionMessage(transaction, signature) {
|
|
615
|
-
return new TransactionMessage({ ...transaction, signature });
|
|
616
|
-
}
|
|
617
|
-
async createTransaction(transaction) {
|
|
618
|
-
return {
|
|
619
|
-
from: transaction.from,
|
|
620
|
-
to: transaction.to,
|
|
621
|
-
method: transaction.method,
|
|
622
|
-
params: transaction.params,
|
|
623
|
-
timestamp: transaction.timestamp || Date.now(),
|
|
624
|
-
nonce: transaction.nonce || (await this.getNonce(transaction.from)) + 1
|
|
625
|
-
};
|
|
626
|
-
}
|
|
627
|
-
async sendTransaction(message) {
|
|
628
|
-
if (!this.isTransactionMessage(message))
|
|
629
|
-
message = await new TransactionMessage(message);
|
|
630
|
-
if (!message.decoded.signature)
|
|
631
|
-
throw new Error(`transaction not signed`);
|
|
632
|
-
if (message.decoded.nonce === undefined)
|
|
633
|
-
throw new Error(`nonce required`);
|
|
634
|
-
await this.validateNonce(message.decoded.from, message.decoded.nonce);
|
|
635
|
-
// todo check if signature is valid
|
|
636
|
-
const hash = await message.hash();
|
|
637
|
-
try {
|
|
638
|
-
let data;
|
|
639
|
-
const wait = new Promise(async (resolve, reject) => {
|
|
640
|
-
if (pubsub.subscribers[`transaction.completed.${hash}`]) {
|
|
641
|
-
const result = pubsub.subscribers[`transaction.completed.${hash}`].value;
|
|
642
|
-
if (result.status !== 'fulfilled') {
|
|
643
|
-
await transactionPoolStore.delete(hash);
|
|
644
|
-
}
|
|
645
|
-
result.status === 'fulfilled' ? resolve(result.hash) : reject({ hash: result.hash, error: result.error });
|
|
646
|
-
}
|
|
647
|
-
else {
|
|
648
|
-
const completed = async (result) => {
|
|
649
|
-
if (result.status !== 'fulfilled') {
|
|
650
|
-
await transactionPoolStore.delete(hash);
|
|
651
|
-
}
|
|
652
|
-
result.status === 'fulfilled' ? resolve(result.hash) : reject({ hash: result.hash, error: result.error });
|
|
653
|
-
setTimeout(async () => {
|
|
654
|
-
pubsub.unsubscribe(`transaction.completed.${hash}`, completed);
|
|
655
|
-
}, 10000);
|
|
656
|
-
};
|
|
657
|
-
pubsub.subscribe(`transaction.completed.${hash}`, completed);
|
|
658
|
-
}
|
|
659
|
-
});
|
|
660
|
-
await globalThis.transactionPoolStore.put(hash, message.encoded);
|
|
661
|
-
// debug(`Added ${hash} to the transaction pool`)
|
|
662
|
-
peernet.publish('add-transaction', message.encoded);
|
|
663
|
-
return { hash, data, fee: await calculateFee(message.decoded), wait, message };
|
|
664
|
-
}
|
|
665
|
-
catch (error) {
|
|
666
|
-
console.log('remo');
|
|
667
|
-
await transactionPoolStore.delete(hash);
|
|
668
|
-
throw error;
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
/**
|
|
674
|
-
* @extends {Transaction}
|
|
675
|
-
*/
|
|
676
|
-
class Contract extends Transaction {
|
|
677
|
-
constructor() {
|
|
678
|
-
super();
|
|
679
|
-
}
|
|
680
|
-
async init() { }
|
|
681
|
-
/**
|
|
682
|
-
*
|
|
683
|
-
* @param {Address} creator
|
|
684
|
-
* @param {String} contract
|
|
685
|
-
* @param {Array} constructorParameters
|
|
686
|
-
* @returns lib.createContractMessage
|
|
687
|
-
*/
|
|
688
|
-
async createContractMessage(creator, contract, constructorParameters = []) {
|
|
689
|
-
return createContractMessage(creator, contract, constructorParameters);
|
|
690
|
-
}
|
|
691
|
-
/**
|
|
692
|
-
*
|
|
693
|
-
* @param {Address} creator
|
|
694
|
-
* @param {String} contract
|
|
695
|
-
* @param {Array} constructorParameters
|
|
696
|
-
* @returns {Address}
|
|
697
|
-
*/
|
|
698
|
-
async createContractAddress(creator, contract, constructorParameters = []) {
|
|
699
|
-
contract = await this.createContractMessage(creator, contract, constructorParameters);
|
|
700
|
-
return contract.hash();
|
|
701
|
-
}
|
|
702
|
-
/**
|
|
703
|
-
*
|
|
704
|
-
* @param {String} contract
|
|
705
|
-
* @param {Array} parameters
|
|
706
|
-
* @returns
|
|
707
|
-
*/
|
|
708
|
-
async deployContract(signer, contract, constructorParameters = []) {
|
|
709
|
-
const message = await createContractMessage(await signer.address, contract, constructorParameters);
|
|
710
|
-
return this.deployContractMessage(signer, message);
|
|
711
|
-
}
|
|
712
|
-
async deployContractMessage(signer, message) {
|
|
713
|
-
try {
|
|
714
|
-
await globalThis.contractStore.put(await message.hash(), message.encoded);
|
|
715
|
-
}
|
|
716
|
-
catch (error) {
|
|
717
|
-
throw error;
|
|
718
|
-
}
|
|
719
|
-
let transaction = {
|
|
720
|
-
from: await signer.address,
|
|
721
|
-
to: addresses.contractFactory,
|
|
722
|
-
method: 'registerContract',
|
|
723
|
-
params: [await message.hash()]
|
|
724
|
-
};
|
|
725
|
-
transaction = await signTransaction(await this.createTransaction(transaction), signer);
|
|
726
|
-
return this.sendTransaction(transaction);
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
const randombytes = (strength) => crypto.getRandomValues(new Uint8Array(strength));
|
|
731
|
-
|
|
732
|
-
class EasyWorker {
|
|
733
|
-
#messageEvent = 'message'
|
|
734
|
-
#errorEvent = 'error'
|
|
735
|
-
#isBrowser = false
|
|
736
|
-
#isWorker = false
|
|
737
|
-
|
|
738
|
-
get isWorker() {
|
|
739
|
-
return this.#isWorker
|
|
740
|
-
}
|
|
741
|
-
constructor(url, options) {
|
|
742
|
-
return this.#init(url, options)
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
#init(url, options = {}) {
|
|
746
|
-
if (url) {
|
|
747
|
-
if (globalThis.Worker) {
|
|
748
|
-
this.#isBrowser = true;
|
|
749
|
-
this.worker = new Worker(url, {...options});
|
|
750
|
-
} else {
|
|
751
|
-
return new Promise(async (resolve, reject) => {
|
|
752
|
-
const {fork} = await import('child_process');
|
|
753
|
-
this.worker = fork(url, ['easy-worker-child'], options);
|
|
754
|
-
resolve(this);
|
|
755
|
-
})
|
|
756
|
-
}
|
|
757
|
-
} else {
|
|
758
|
-
this.#isWorker = true;
|
|
759
|
-
if (globalThis.process?.argv[2] === 'easy-worker-child') {
|
|
760
|
-
this.worker = process;
|
|
761
|
-
} else {
|
|
762
|
-
this.#isBrowser = true;
|
|
763
|
-
this.worker = globalThis;
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
return this
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
onmessage(fn) {
|
|
771
|
-
if (this.#isBrowser) this.worker.onmessage = ({data}) => fn(data);
|
|
772
|
-
else this.worker.on(this.#messageEvent, fn);
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
postMessage(message) {
|
|
776
|
-
if (this.#isBrowser) this.worker.postMessage(message);
|
|
777
|
-
else this.worker.send(message);
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
terminate() {
|
|
781
|
-
if (this.#isBrowser) this.worker.terminate();
|
|
782
|
-
else this.worker.kill();
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
onerror(fn) {
|
|
786
|
-
if (this.#isBrowser) this.worker.onerror = fn;
|
|
787
|
-
else this.worker.on(this.#errorEvent, fn);
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
/**
|
|
791
|
-
*
|
|
792
|
-
* @param {*} data
|
|
793
|
-
* @returns {Promise} resolves result onmessage & rejects on error
|
|
794
|
-
*/
|
|
795
|
-
once(data) {
|
|
796
|
-
return new Promise((resolve, reject) => {
|
|
797
|
-
this.onmessage(message => {
|
|
798
|
-
resolve(message);
|
|
799
|
-
this.terminate();
|
|
800
|
-
});
|
|
801
|
-
this.onerror(error => {
|
|
802
|
-
reject(error);
|
|
803
|
-
this.terminate();
|
|
804
|
-
});
|
|
805
|
-
this.postMessage(data);
|
|
806
|
-
})
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
class LeofcoinError extends Error {
|
|
811
|
-
#message;
|
|
812
|
-
constructor(message, options) {
|
|
813
|
-
super(message, options);
|
|
814
|
-
this.#message = message;
|
|
815
|
-
}
|
|
816
|
-
get message() {
|
|
817
|
-
return `${this.name}: ${this.#message}`;
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
class ResolveError extends LeofcoinError {
|
|
821
|
-
name = 'ResolveError';
|
|
822
|
-
}
|
|
823
|
-
class ExecutionError extends LeofcoinError {
|
|
824
|
-
name = 'ExecutionError';
|
|
825
|
-
}
|
|
826
|
-
class ContractDeploymentError extends LeofcoinError {
|
|
827
|
-
name = 'ContractDeploymentError';
|
|
828
|
-
}
|
|
829
|
-
const isResolveError = (error) => error.name === 'ResolveError';
|
|
830
|
-
const isExecutionError = (error) => error.name === 'ExecutionError';
|
|
831
|
-
|
|
832
|
-
// import State from './state'
|
|
833
|
-
class Machine {
|
|
834
|
-
#contracts;
|
|
835
|
-
#nonces;
|
|
836
|
-
constructor(blocks) {
|
|
837
|
-
this.#contracts = {};
|
|
838
|
-
this.#nonces = {};
|
|
839
|
-
this.lastBlock = { index: 0, hash: '0x0', previousHash: '0x0' };
|
|
840
|
-
// @ts-ignore
|
|
841
|
-
return this.#init(blocks);
|
|
842
|
-
}
|
|
843
|
-
#createMessage(sender = peernet.selectedAccount) {
|
|
844
|
-
return {
|
|
845
|
-
sender,
|
|
846
|
-
call: this.execute,
|
|
847
|
-
staticCall: this.get.bind(this)
|
|
848
|
-
};
|
|
849
|
-
}
|
|
850
|
-
async #onmessage(data) {
|
|
851
|
-
switch (data.type) {
|
|
852
|
-
case 'contractError': {
|
|
853
|
-
console.warn(`removing contract ${await data.hash()}`);
|
|
854
|
-
// @ts-ignore
|
|
855
|
-
await contractStore.delete(await data.hash());
|
|
856
|
-
break;
|
|
857
|
-
}
|
|
858
|
-
case 'initError': {
|
|
859
|
-
console.error(`init error: ${data.message}`);
|
|
860
|
-
break;
|
|
861
|
-
}
|
|
862
|
-
case 'executionError': {
|
|
863
|
-
// console.warn(`error executing transaction ${data.message}`);
|
|
864
|
-
pubsub.publish(data.id, { error: data.message });
|
|
865
|
-
break;
|
|
866
|
-
}
|
|
867
|
-
case 'debug': {
|
|
868
|
-
for (const message of data.messages)
|
|
869
|
-
globalThis.debug(message);
|
|
870
|
-
break;
|
|
871
|
-
}
|
|
872
|
-
case 'machine-ready': {
|
|
873
|
-
this.lastBlock = data.lastBlock;
|
|
874
|
-
pubsub.publish('machine.ready', true);
|
|
875
|
-
break;
|
|
876
|
-
}
|
|
877
|
-
case 'response': {
|
|
878
|
-
pubsub.publish(data.id, data.value || false);
|
|
879
|
-
break;
|
|
880
|
-
}
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
async #init(blocks) {
|
|
884
|
-
return new Promise(async (resolve) => {
|
|
885
|
-
const machineReady = () => {
|
|
886
|
-
pubsub.unsubscribe('machine.ready', machineReady);
|
|
887
|
-
resolve(this);
|
|
888
|
-
};
|
|
889
|
-
pubsub.subscribe('machine.ready', machineReady);
|
|
890
|
-
let pre;
|
|
891
|
-
try {
|
|
892
|
-
const importee = await import('url');
|
|
893
|
-
const url = importee.default;
|
|
894
|
-
if (url)
|
|
895
|
-
pre = url.fileURLToPath(new URL('.', import.meta.url));
|
|
896
|
-
}
|
|
897
|
-
catch {
|
|
898
|
-
// browser env
|
|
899
|
-
pre = './';
|
|
900
|
-
}
|
|
901
|
-
this.worker = await new EasyWorker(pre + 'workers/machine-worker.js', {
|
|
902
|
-
serialization: 'advanced',
|
|
903
|
-
type: 'module'
|
|
904
|
-
});
|
|
905
|
-
this.worker.onmessage(this.#onmessage.bind(this));
|
|
906
|
-
// const blocks = await blockStore.values()
|
|
907
|
-
const contracts = await Promise.all([
|
|
908
|
-
globalThis.contractStore.get(contractFactory$2),
|
|
909
|
-
globalThis.contractStore.get(nativeToken$2),
|
|
910
|
-
globalThis.contractStore.get(validators$2),
|
|
911
|
-
globalThis.contractStore.get(nameService$2)
|
|
912
|
-
]);
|
|
913
|
-
const message = {
|
|
914
|
-
type: 'init',
|
|
915
|
-
input: {
|
|
916
|
-
contracts,
|
|
917
|
-
blocks,
|
|
918
|
-
// @ts-ignore
|
|
919
|
-
peerid: peernet.peerId
|
|
920
|
-
}
|
|
921
|
-
};
|
|
922
|
-
this.worker.postMessage(message);
|
|
923
|
-
});
|
|
924
|
-
}
|
|
925
|
-
async #runContract(contractMessage) {
|
|
926
|
-
const hash = await contractMessage.hash();
|
|
927
|
-
return new Promise((resolve, reject) => {
|
|
928
|
-
// @ts-ignore
|
|
929
|
-
const id = randombytes(20).toString('hex');
|
|
930
|
-
const onmessage = (message) => {
|
|
931
|
-
pubsub.unsubscribe(id, onmessage);
|
|
932
|
-
if (message?.error)
|
|
933
|
-
reject(message.error);
|
|
934
|
-
else
|
|
935
|
-
resolve(message);
|
|
936
|
-
};
|
|
937
|
-
pubsub.subscribe(id, onmessage);
|
|
938
|
-
this.worker.postMessage({
|
|
939
|
-
type: 'run',
|
|
940
|
-
id,
|
|
941
|
-
input: {
|
|
942
|
-
decoded: contractMessage.decoded,
|
|
943
|
-
encoded: contractMessage.encoded,
|
|
944
|
-
hash
|
|
945
|
-
}
|
|
946
|
-
});
|
|
947
|
-
});
|
|
948
|
-
}
|
|
949
|
-
/**
|
|
950
|
-
*
|
|
951
|
-
* @param {Address} contract
|
|
952
|
-
* @param {String} method
|
|
953
|
-
* @param {Array} parameters
|
|
954
|
-
* @returns Promise<message>
|
|
955
|
-
*/
|
|
956
|
-
async execute(contract, method, parameters) {
|
|
957
|
-
try {
|
|
958
|
-
if (contract === contractFactory$2 && method === 'registerContract') {
|
|
959
|
-
if (await this.has(parameters[0]))
|
|
960
|
-
throw new Error(`duplicate contract @${parameters[0]}`);
|
|
961
|
-
let message;
|
|
962
|
-
if (!(await globalThis.contractStore.has(parameters[0]))) {
|
|
963
|
-
message = await peernet.get(parameters[0], 'contract');
|
|
964
|
-
message = await new ContractMessage(message);
|
|
965
|
-
await globalThis.contractStore.put(await message.hash(), message.encoded);
|
|
966
|
-
}
|
|
967
|
-
if (!message) {
|
|
968
|
-
message = await globalThis.contractStore.get(parameters[0]);
|
|
969
|
-
message = await new ContractMessage(message);
|
|
970
|
-
}
|
|
971
|
-
if (!(await this.has(await message.hash())))
|
|
972
|
-
await this.#runContract(message);
|
|
973
|
-
}
|
|
974
|
-
}
|
|
975
|
-
catch (error) {
|
|
976
|
-
throw new ContractDeploymentError(`contract deployment failed for ${parameters[0]}\n${error.message}`);
|
|
977
|
-
}
|
|
978
|
-
return new Promise((resolve, reject) => {
|
|
979
|
-
// @ts-ignore
|
|
980
|
-
const id = randombytes(20).toString('hex');
|
|
981
|
-
const onmessage = (message) => {
|
|
982
|
-
pubsub.unsubscribe(id, onmessage);
|
|
983
|
-
if (message?.error)
|
|
984
|
-
reject(new ExecutionError(message.error));
|
|
985
|
-
else
|
|
986
|
-
resolve(message);
|
|
987
|
-
};
|
|
988
|
-
pubsub.subscribe(id, onmessage);
|
|
989
|
-
this.worker.postMessage({
|
|
990
|
-
type: 'execute',
|
|
991
|
-
id,
|
|
992
|
-
input: {
|
|
993
|
-
contract,
|
|
994
|
-
method,
|
|
995
|
-
params: parameters
|
|
996
|
-
}
|
|
997
|
-
});
|
|
998
|
-
});
|
|
999
|
-
}
|
|
1000
|
-
get(contract, method, parameters) {
|
|
1001
|
-
return new Promise((resolve, reject) => {
|
|
1002
|
-
const id = randombytes(20).toString();
|
|
1003
|
-
const onmessage = (message) => {
|
|
1004
|
-
pubsub.unsubscribe(id, onmessage);
|
|
1005
|
-
resolve(message);
|
|
1006
|
-
};
|
|
1007
|
-
pubsub.subscribe(id, onmessage);
|
|
1008
|
-
this.worker.postMessage({
|
|
1009
|
-
type: 'get',
|
|
1010
|
-
id,
|
|
1011
|
-
input: {
|
|
1012
|
-
contract,
|
|
1013
|
-
method,
|
|
1014
|
-
params: parameters
|
|
1015
|
-
}
|
|
1016
|
-
});
|
|
1017
|
-
});
|
|
1018
|
-
}
|
|
1019
|
-
async has(address) {
|
|
1020
|
-
return new Promise((resolve, reject) => {
|
|
1021
|
-
// @ts-ignore
|
|
1022
|
-
const id = randombytes(20).toString('hex');
|
|
1023
|
-
const onmessage = (message) => {
|
|
1024
|
-
pubsub.unsubscribe(id, onmessage);
|
|
1025
|
-
if (message?.error)
|
|
1026
|
-
reject(message.error);
|
|
1027
|
-
else
|
|
1028
|
-
resolve(message);
|
|
1029
|
-
};
|
|
1030
|
-
pubsub.subscribe(id, onmessage);
|
|
1031
|
-
this.worker.postMessage({
|
|
1032
|
-
type: 'has',
|
|
1033
|
-
id,
|
|
1034
|
-
input: {
|
|
1035
|
-
address
|
|
1036
|
-
}
|
|
1037
|
-
});
|
|
1038
|
-
});
|
|
1039
|
-
}
|
|
1040
|
-
async delete(hash) {
|
|
1041
|
-
return globalThis.contractStore.delete(hash);
|
|
1042
|
-
}
|
|
1043
|
-
/**
|
|
1044
|
-
*
|
|
1045
|
-
* @returns Promise
|
|
1046
|
-
*/
|
|
1047
|
-
async deleteAll() {
|
|
1048
|
-
let hashes = await globalThis.contractStore.keys();
|
|
1049
|
-
hashes = Object.keys(hashes).map((hash) => this.delete(hash));
|
|
1050
|
-
return Promise.all(hashes);
|
|
1051
|
-
}
|
|
1052
|
-
}
|
|
1053
|
-
|
|
1054
|
-
class Jobber {
|
|
1055
|
-
constructor(timeout) {
|
|
1056
|
-
this.busy = false;
|
|
1057
|
-
this.timeout = timeout;
|
|
1058
|
-
}
|
|
1059
|
-
add(fn) {
|
|
1060
|
-
this.busy = true;
|
|
1061
|
-
return new Promise(async (resolve, reject) => {
|
|
1062
|
-
const timeout = setTimeout(() => {
|
|
1063
|
-
reject('timeout');
|
|
1064
|
-
}, this.timeout);
|
|
1065
|
-
this.destroy = () => {
|
|
1066
|
-
clearTimeout(timeout);
|
|
1067
|
-
this.busy = false;
|
|
1068
|
-
resolve('stopped');
|
|
1069
|
-
};
|
|
1070
|
-
try {
|
|
1071
|
-
const result = await fn();
|
|
1072
|
-
clearTimeout(timeout);
|
|
1073
|
-
this.busy = false;
|
|
1074
|
-
resolve(result);
|
|
1075
|
-
}
|
|
1076
|
-
catch (error) {
|
|
1077
|
-
clearTimeout(timeout);
|
|
1078
|
-
reject(error);
|
|
1079
|
-
}
|
|
1080
|
-
});
|
|
1081
|
-
}
|
|
1082
|
-
}
|
|
1083
|
-
|
|
1084
|
-
class State extends Contract {
|
|
1085
|
-
#resolveErrored;
|
|
1086
|
-
#lastResolvedTime;
|
|
1087
|
-
#lastResolved;
|
|
1088
|
-
#resolving;
|
|
1089
|
-
#resolveErrorCount;
|
|
1090
|
-
#syncState;
|
|
1091
|
-
#chainState;
|
|
1092
|
-
#lastBlockInQue;
|
|
1093
|
-
#syncErrorCount;
|
|
1094
|
-
#blockHashMap;
|
|
1095
|
-
#chainSyncing;
|
|
1096
|
-
#lastBlock;
|
|
1097
|
-
#blocks;
|
|
1098
|
-
#totalSize;
|
|
1099
|
-
#machine;
|
|
1100
|
-
#loaded;
|
|
1101
|
-
get state() {
|
|
1102
|
-
return {
|
|
1103
|
-
sync: this.#syncState,
|
|
1104
|
-
chain: this.#chainState
|
|
1105
|
-
};
|
|
1106
|
-
}
|
|
1107
|
-
get blockHashMap() {
|
|
1108
|
-
return this.#blockHashMap.entries();
|
|
1109
|
-
}
|
|
1110
|
-
get loaded() {
|
|
1111
|
-
return this.#loaded;
|
|
1112
|
-
}
|
|
1113
|
-
get resolving() {
|
|
1114
|
-
return this.#resolving;
|
|
1115
|
-
}
|
|
1116
|
-
/**
|
|
1117
|
-
* amount the native token has been iteracted with
|
|
1118
|
-
*/
|
|
1119
|
-
#nativeCalls;
|
|
1120
|
-
/**
|
|
1121
|
-
* amount the native token has been iteracted with
|
|
1122
|
-
*/
|
|
1123
|
-
#nativeTransfers;
|
|
1124
|
-
/**
|
|
1125
|
-
* amount of native token burned
|
|
1126
|
-
* {Number}
|
|
1127
|
-
*/
|
|
1128
|
-
#nativeBurns;
|
|
1129
|
-
/**
|
|
1130
|
-
* amount of native tokens minted
|
|
1131
|
-
* {Number}
|
|
1132
|
-
*/
|
|
1133
|
-
#nativeMints;
|
|
1134
|
-
/**
|
|
1135
|
-
* total amount of transactions
|
|
1136
|
-
* {Number}
|
|
1137
|
-
*/
|
|
1138
|
-
#totalTransactions;
|
|
1139
|
-
get nativeMints() {
|
|
1140
|
-
return this.#nativeMints;
|
|
1141
|
-
}
|
|
1142
|
-
get nativeBurns() {
|
|
1143
|
-
return this.#nativeBurns;
|
|
1144
|
-
}
|
|
1145
|
-
get nativeTransfers() {
|
|
1146
|
-
return this.#nativeTransfers;
|
|
1147
|
-
}
|
|
1148
|
-
get totalTransactions() {
|
|
1149
|
-
return this.#totalTransactions;
|
|
1150
|
-
}
|
|
1151
|
-
get nativeCalls() {
|
|
1152
|
-
return this.#nativeCalls;
|
|
1153
|
-
}
|
|
1154
|
-
get blocks() {
|
|
1155
|
-
return [...this.#blocks];
|
|
1156
|
-
}
|
|
1157
|
-
get lastBlock() {
|
|
1158
|
-
return this.#lastBlock;
|
|
1159
|
-
}
|
|
1160
|
-
get totalSize() {
|
|
1161
|
-
return this.#totalSize;
|
|
1162
|
-
}
|
|
1163
|
-
get machine() {
|
|
1164
|
-
return this.#machine;
|
|
1165
|
-
}
|
|
1166
|
-
constructor() {
|
|
1167
|
-
super();
|
|
1168
|
-
this.#lastResolvedTime = 0;
|
|
1169
|
-
this.#resolving = false;
|
|
1170
|
-
this.#resolveErrorCount = 0;
|
|
1171
|
-
this.#chainState = 'loading';
|
|
1172
|
-
this.#syncErrorCount = 0;
|
|
1173
|
-
this.#blockHashMap = new Map();
|
|
1174
|
-
this.#chainSyncing = false;
|
|
1175
|
-
this.#lastBlock = { index: 0, hash: '0x0', previousHash: '0x0' };
|
|
1176
|
-
this.#blocks = [];
|
|
1177
|
-
this.knownBlocks = [];
|
|
1178
|
-
this.#totalSize = 0;
|
|
1179
|
-
this.#loaded = false;
|
|
1180
|
-
/**
|
|
1181
|
-
* amount the native token has been iteracted with
|
|
1182
|
-
*/
|
|
1183
|
-
this.#nativeCalls = 0;
|
|
1184
|
-
/**
|
|
1185
|
-
* amount the native token has been iteracted with
|
|
1186
|
-
*/
|
|
1187
|
-
this.#nativeTransfers = 0;
|
|
1188
|
-
/**
|
|
1189
|
-
* amount of native token burned
|
|
1190
|
-
* {Number}
|
|
1191
|
-
*/
|
|
1192
|
-
this.#nativeBurns = 0;
|
|
1193
|
-
/**
|
|
1194
|
-
* amount of native tokens minted
|
|
1195
|
-
* {Number}
|
|
1196
|
-
*/
|
|
1197
|
-
this.#nativeMints = 0;
|
|
1198
|
-
/**
|
|
1199
|
-
* total amount of transactions
|
|
1200
|
-
* {Number}
|
|
1201
|
-
*/
|
|
1202
|
-
this.#totalTransactions = 0;
|
|
1203
|
-
this.#chainStateHandler = () => {
|
|
1204
|
-
return new globalThis.peernet.protos['peernet-response']({
|
|
1205
|
-
response: this.#chainState
|
|
1206
|
-
});
|
|
1207
|
-
};
|
|
1208
|
-
this.#lastBlockHandler = async () => {
|
|
1209
|
-
return new globalThis.peernet.protos['peernet-response']({
|
|
1210
|
-
response: { hash: this.#lastBlock?.hash, index: this.#lastBlock?.index }
|
|
1211
|
-
});
|
|
1212
|
-
};
|
|
1213
|
-
this.#knownBlocksHandler = async () => {
|
|
1214
|
-
return new globalThis.peernet.protos['peernet-response']({
|
|
1215
|
-
response: { blocks: this.#blocks.map((block) => block.hash) }
|
|
1216
|
-
});
|
|
1217
|
-
};
|
|
1218
|
-
this.#loadBlockTransactions = (transactions) => Promise.all(transactions.map((transaction) => new TransactionMessage(transaction)));
|
|
1219
|
-
this.#getLastTransactions = async () => {
|
|
1220
|
-
let lastTransactions = (await Promise.all(this.#blocks
|
|
1221
|
-
.filter((block) => block.loaded)
|
|
1222
|
-
.slice(-128)
|
|
1223
|
-
.map((block) => this.#loadBlockTransactions(block.transactions)))).reduce((all, transactions) => [...all, ...transactions], []);
|
|
1224
|
-
return Promise.all(lastTransactions.map((transaction) => transaction.hash()));
|
|
1225
|
-
};
|
|
1226
|
-
}
|
|
1227
|
-
async clearPool() {
|
|
1228
|
-
await globalThis.transactionPoolStore.clear();
|
|
1229
|
-
}
|
|
1230
|
-
/**
|
|
1231
|
-
* drastic measurement, removes everything!
|
|
1232
|
-
*/
|
|
1233
|
-
async clearAll() {
|
|
1234
|
-
await globalThis.accountsStore.clear();
|
|
1235
|
-
await globalThis.chainStore.clear();
|
|
1236
|
-
await globalThis.blockStore.clear();
|
|
1237
|
-
await globalThis.transactionPoolStore.clear();
|
|
1238
|
-
}
|
|
1239
|
-
#chainStateHandler;
|
|
1240
|
-
#lastBlockHandler;
|
|
1241
|
-
#knownBlocksHandler;
|
|
1242
|
-
async init() {
|
|
1243
|
-
this.jobber = new Jobber(this.resolveTimeout);
|
|
1244
|
-
if (super.init)
|
|
1245
|
-
await super.init();
|
|
1246
|
-
await globalThis.peernet.addRequestHandler('lastBlock', this.#lastBlockHandler);
|
|
1247
|
-
await globalThis.peernet.addRequestHandler('knownBlocks', this.#knownBlocksHandler);
|
|
1248
|
-
await globalThis.peernet.addRequestHandler('chainState', this.#chainStateHandler);
|
|
1249
|
-
try {
|
|
1250
|
-
let localBlock;
|
|
1251
|
-
try {
|
|
1252
|
-
localBlock = await globalThis.chainStore.get('lastBlock');
|
|
1253
|
-
}
|
|
1254
|
-
catch {
|
|
1255
|
-
await globalThis.chainStore.put('lastBlock', '0x0');
|
|
1256
|
-
localBlock = await globalThis.chainStore.get('lastBlock');
|
|
1257
|
-
}
|
|
1258
|
-
localBlock = new TextDecoder().decode(localBlock);
|
|
1259
|
-
if (localBlock && localBlock !== '0x0') {
|
|
1260
|
-
localBlock = await globalThis.peernet.get(localBlock, 'block');
|
|
1261
|
-
localBlock = await new BlockMessage(localBlock);
|
|
1262
|
-
this.#lastBlock = {
|
|
1263
|
-
...localBlock.decoded,
|
|
1264
|
-
hash: await localBlock.hash()
|
|
1265
|
-
};
|
|
1266
|
-
}
|
|
1267
|
-
else {
|
|
1268
|
-
if (globalThis.peernet?.connections.length > 0) {
|
|
1269
|
-
const latestBlock = await this.#getLatestBlock();
|
|
1270
|
-
await this.#syncChain(latestBlock);
|
|
1271
|
-
}
|
|
1272
|
-
}
|
|
1273
|
-
}
|
|
1274
|
-
catch (error) {
|
|
1275
|
-
console.log({ e: error });
|
|
1276
|
-
console.log({ e: error });
|
|
1277
|
-
}
|
|
1278
|
-
globalThis.pubsub.publish('lastBlock', this.lastBlock);
|
|
1279
|
-
// load local blocks
|
|
1280
|
-
try {
|
|
1281
|
-
this.knownBlocks = await blockStore.keys();
|
|
1282
|
-
}
|
|
1283
|
-
catch (error) {
|
|
1284
|
-
console.error(error);
|
|
1285
|
-
throw error;
|
|
1286
|
-
}
|
|
1287
|
-
try {
|
|
1288
|
-
await this.resolveBlocks();
|
|
1289
|
-
this.#machine = await new Machine(this.#blocks);
|
|
1290
|
-
await this.#loadBlocks(this.#blocks);
|
|
1291
|
-
}
|
|
1292
|
-
catch (error) {
|
|
1293
|
-
if (isResolveError(error)) {
|
|
1294
|
-
console.error(error);
|
|
1295
|
-
}
|
|
1296
|
-
console.log(error);
|
|
1297
|
-
}
|
|
1298
|
-
}
|
|
1299
|
-
async updateState(message) {
|
|
1300
|
-
const hash = await message.hash();
|
|
1301
|
-
this.#lastBlock = { hash, ...message.decoded };
|
|
1302
|
-
// await this.state.updateState(message)
|
|
1303
|
-
await globalThis.chainStore.put('lastBlock', hash);
|
|
1304
|
-
globalThis.pubsub.publish('lastBlock', this.#lastBlock);
|
|
1305
|
-
}
|
|
1306
|
-
getLatestBlock() {
|
|
1307
|
-
// @ts-ignore
|
|
1308
|
-
return this.#getLatestBlock();
|
|
1309
|
-
}
|
|
1310
|
-
async getAndPutBlock(hash) {
|
|
1311
|
-
// todo peernet resolves undefined blocks....
|
|
1312
|
-
let block = await globalThis.peernet.get(hash, 'block');
|
|
1313
|
-
if (block !== undefined) {
|
|
1314
|
-
block = await new BlockMessage(block);
|
|
1315
|
-
const { index } = block.decoded;
|
|
1316
|
-
if (this.#blocks[index - 1] && this.#blocks[index - 1].hash !== block.hash)
|
|
1317
|
-
throw `invalid block ${hash} @${index}`;
|
|
1318
|
-
if (!(await globalThis.peernet.has(hash)))
|
|
1319
|
-
await globalThis.peernet.put(hash, block.encoded, 'block');
|
|
1320
|
-
}
|
|
1321
|
-
return block;
|
|
1322
|
-
}
|
|
1323
|
-
async #resolveBlock(hash) {
|
|
1324
|
-
let index = this.#blockHashMap.get(hash);
|
|
1325
|
-
if (this.#blocks[index - 1]) {
|
|
1326
|
-
if (this.#blocks[index - 1].previousHash !== '0x0') {
|
|
1327
|
-
return this.resolveBlock(this.#blocks[index - 1].previousHash);
|
|
1328
|
-
}
|
|
1329
|
-
else {
|
|
1330
|
-
return;
|
|
1331
|
-
}
|
|
1332
|
-
}
|
|
1333
|
-
try {
|
|
1334
|
-
const block = await this.getAndPutBlock(hash);
|
|
1335
|
-
index = block.decoded.index;
|
|
1336
|
-
const size = block.encoded.length > 0 ? block.encoded.length : block.encoded.byteLength;
|
|
1337
|
-
this.#totalSize += size;
|
|
1338
|
-
this.#blocks[index - 1] = { hash, ...block.decoded };
|
|
1339
|
-
this.#blockHashMap.set(hash, index);
|
|
1340
|
-
globalThis.debug(`resolved block: ${hash} @${index} ${formatBytes(size)}`);
|
|
1341
|
-
globalThis.pubsub.publish('block-resolved', { hash, index });
|
|
1342
|
-
this.#lastResolved = this.#blocks[index - 1];
|
|
1343
|
-
this.#lastResolvedTime = Date.now();
|
|
1344
|
-
}
|
|
1345
|
-
catch (error) {
|
|
1346
|
-
throw new ResolveError(`block: ${hash}@${index}`);
|
|
1347
|
-
}
|
|
1348
|
-
return;
|
|
1349
|
-
}
|
|
1350
|
-
async resolveBlock(hash) {
|
|
1351
|
-
if (!hash)
|
|
1352
|
-
throw new Error(`expected hash, got: ${hash}`);
|
|
1353
|
-
if (hash === '0x0')
|
|
1354
|
-
return;
|
|
1355
|
-
if (this.#resolving)
|
|
1356
|
-
return 'already resolving';
|
|
1357
|
-
this.#resolving = true;
|
|
1358
|
-
if (this.jobber.busy && this.jobber.destroy)
|
|
1359
|
-
await this.jobber.destroy();
|
|
1360
|
-
try {
|
|
1361
|
-
await this.jobber.add(() => this.#resolveBlock(hash));
|
|
1362
|
-
this.#resolving = false;
|
|
1363
|
-
if (!this.#blockHashMap.has(this.#lastResolved.previousHash) && this.#lastResolved.previousHash !== '0x0')
|
|
1364
|
-
return this.resolveBlock(this.#lastResolved.previousHash);
|
|
1365
|
-
}
|
|
1366
|
-
catch (error) {
|
|
1367
|
-
console.log({ error });
|
|
1368
|
-
this.#resolveErrorCount += 1;
|
|
1369
|
-
this.#resolving = false;
|
|
1370
|
-
if (this.#resolveErrorCount < 3)
|
|
1371
|
-
return this.resolveBlock(hash);
|
|
1372
|
-
this.#resolveErrorCount = 0;
|
|
1373
|
-
throw new ResolveError(`block: ${hash}`, { cause: error });
|
|
1374
|
-
}
|
|
1375
|
-
}
|
|
1376
|
-
async resolveBlocks() {
|
|
1377
|
-
try {
|
|
1378
|
-
if (this.jobber.busy && this.jobber.destroy) {
|
|
1379
|
-
await this.jobber.destroy();
|
|
1380
|
-
}
|
|
1381
|
-
}
|
|
1382
|
-
catch (error) {
|
|
1383
|
-
console.error(error);
|
|
1384
|
-
}
|
|
1385
|
-
try {
|
|
1386
|
-
const localBlock = await globalThis.chainStore.get('lastBlock');
|
|
1387
|
-
const hash = new TextDecoder().decode(localBlock);
|
|
1388
|
-
if (hash && hash !== '0x0') {
|
|
1389
|
-
await this.resolveBlock(hash);
|
|
1390
|
-
this.#lastBlock = this.#blocks[this.#blocks.length - 1];
|
|
1391
|
-
}
|
|
1392
|
-
}
|
|
1393
|
-
catch (error) {
|
|
1394
|
-
console.log(error);
|
|
1395
|
-
this.#chainSyncing = false;
|
|
1396
|
-
this.#syncState = 'errored';
|
|
1397
|
-
this.#resolveErrored = true;
|
|
1398
|
-
return this.restoreChain();
|
|
1399
|
-
// console.log(e);
|
|
1400
|
-
}
|
|
1401
|
-
}
|
|
1402
|
-
async restoreChain() {
|
|
1403
|
-
try {
|
|
1404
|
-
const { hash } = await this.#getLatestBlock();
|
|
1405
|
-
await globalThis.chainStore.put('lastBlock', hash);
|
|
1406
|
-
if (hash && hash !== '0x0') {
|
|
1407
|
-
await this.resolveBlock(hash);
|
|
1408
|
-
this.#lastBlock = this.#blocks[this.#blocks.length - 1];
|
|
1409
|
-
}
|
|
1410
|
-
}
|
|
1411
|
-
catch (error) {
|
|
1412
|
-
console.log(error);
|
|
1413
|
-
this.#resolveErrored = true;
|
|
1414
|
-
this.#resolveErrorCount += 1;
|
|
1415
|
-
this.#resolving = false;
|
|
1416
|
-
return this.restoreChain();
|
|
1417
|
-
// console.log(e);
|
|
1418
|
-
}
|
|
1419
|
-
}
|
|
1420
|
-
async syncChain(lastBlock) {
|
|
1421
|
-
console.log('check if can sync');
|
|
1422
|
-
if (!this.shouldSync)
|
|
1423
|
-
return;
|
|
1424
|
-
console.log('starting sync');
|
|
1425
|
-
this.#syncState = 'syncing';
|
|
1426
|
-
this.#chainSyncing = true;
|
|
1427
|
-
try {
|
|
1428
|
-
if (this.jobber.busy && this.jobber.destroy) {
|
|
1429
|
-
await this.jobber.destroy();
|
|
1430
|
-
}
|
|
1431
|
-
}
|
|
1432
|
-
catch (error) {
|
|
1433
|
-
console.error(error);
|
|
1434
|
-
}
|
|
1435
|
-
if (!lastBlock)
|
|
1436
|
-
lastBlock = await this.#getLatestBlock();
|
|
1437
|
-
console.log('starting sync');
|
|
1438
|
-
if (globalThis.peernet.connections.length === 0)
|
|
1439
|
-
return 'connectionless';
|
|
1440
|
-
try {
|
|
1441
|
-
await this.#syncChain(lastBlock);
|
|
1442
|
-
}
|
|
1443
|
-
catch (error) {
|
|
1444
|
-
this.#syncErrorCount += 1;
|
|
1445
|
-
if (this.#syncErrorCount < 3)
|
|
1446
|
-
return this.syncChain(lastBlock);
|
|
1447
|
-
this.#syncErrorCount = 0;
|
|
1448
|
-
this.#chainSyncing = false;
|
|
1449
|
-
this.#syncState = 'errored';
|
|
1450
|
-
return this.#syncState;
|
|
1451
|
-
}
|
|
1452
|
-
if (lastBlock.index === this.#lastBlockInQue?.index)
|
|
1453
|
-
this.#lastBlockInQue = undefined;
|
|
1454
|
-
this.#syncErrorCount = 0;
|
|
1455
|
-
this.#chainSyncing = false;
|
|
1456
|
-
if (this.#lastBlockInQue)
|
|
1457
|
-
return this.syncChain(this.#lastBlockInQue);
|
|
1458
|
-
this.#syncState = 'synced';
|
|
1459
|
-
return this.#syncState;
|
|
1460
|
-
}
|
|
1461
|
-
async #syncChain(lastBlock) {
|
|
1462
|
-
try {
|
|
1463
|
-
if (this.knownBlocks?.length === Number(lastBlock.index) + 1) {
|
|
1464
|
-
let promises = [];
|
|
1465
|
-
promises = await Promise.allSettled(this.knownBlocks.map(async (address) => {
|
|
1466
|
-
const has = await globalThis.peernet.has(address);
|
|
1467
|
-
return { has, address };
|
|
1468
|
-
}));
|
|
1469
|
-
promises = promises.filter(({ status, value }) => status === 'fulfilled' && !value.has);
|
|
1470
|
-
await Promise.allSettled(promises.map(({ value }) => this.getAndPutBlock(value.address)));
|
|
1471
|
-
}
|
|
1472
|
-
if (!this.#lastBlock || Number(this.#lastBlock.index) < Number(lastBlock.index)) {
|
|
1473
|
-
// TODO: check if valid
|
|
1474
|
-
const localIndex = this.#lastBlock ? this.lastBlock.index : 0;
|
|
1475
|
-
const index = lastBlock.index;
|
|
1476
|
-
await this.resolveBlock(lastBlock.hash);
|
|
1477
|
-
console.log('ok');
|
|
1478
|
-
let blocksSynced = localIndex > 0 ? (localIndex > index ? localIndex - index : index + -localIndex) : index;
|
|
1479
|
-
globalThis.debug(`synced ${blocksSynced} ${blocksSynced > 1 ? 'blocks' : 'block'}`);
|
|
1480
|
-
const start = this.#blocks.length - blocksSynced;
|
|
1481
|
-
if (this.#machine)
|
|
1482
|
-
await this.#loadBlocks(this.blocks.slice(start));
|
|
1483
|
-
await this.updateState(new BlockMessage(this.#blocks[this.#blocks.length - 1]));
|
|
1484
|
-
}
|
|
1485
|
-
}
|
|
1486
|
-
catch (error) {
|
|
1487
|
-
console.log(error);
|
|
1488
|
-
throw error;
|
|
1489
|
-
}
|
|
1490
|
-
}
|
|
1491
|
-
async #getLatestBlock() {
|
|
1492
|
-
let promises = [];
|
|
1493
|
-
let data = await new globalThis.peernet.protos['peernet-request']({
|
|
1494
|
-
request: 'lastBlock'
|
|
1495
|
-
});
|
|
1496
|
-
let node = await globalThis.peernet.prepareMessage(data);
|
|
1497
|
-
for (const peer of globalThis.peernet?.connections) {
|
|
1498
|
-
// @ts-ignore
|
|
1499
|
-
if (peer.connected && peer.version === this.version) {
|
|
1500
|
-
const task = async () => {
|
|
1501
|
-
try {
|
|
1502
|
-
const result = await peer.request(node.encoded);
|
|
1503
|
-
return { result: Uint8Array.from(Object.values(result)), peer };
|
|
1504
|
-
}
|
|
1505
|
-
catch (error) {
|
|
1506
|
-
throw error;
|
|
1507
|
-
}
|
|
1508
|
-
};
|
|
1509
|
-
promises.push(task());
|
|
1510
|
-
}
|
|
1511
|
-
}
|
|
1512
|
-
// @ts-ignore
|
|
1513
|
-
promises = await this.promiseRequests(promises);
|
|
1514
|
-
let latest = { index: 0, hash: '0x0', previousHash: '0x0' };
|
|
1515
|
-
promises = promises.sort((a, b) => b.index - a.index);
|
|
1516
|
-
if (promises.length > 0)
|
|
1517
|
-
latest = promises[0].value;
|
|
1518
|
-
if (latest.hash && latest.hash !== '0x0') {
|
|
1519
|
-
let message = await globalThis.peernet.get(latest.hash, 'block');
|
|
1520
|
-
message = await new BlockMessage(message);
|
|
1521
|
-
const hash = await message.hash();
|
|
1522
|
-
if (hash !== latest.hash)
|
|
1523
|
-
throw new Error('invalid block @getLatestBlock');
|
|
1524
|
-
latest = { ...message.decoded, hash };
|
|
1525
|
-
const peer = promises[0].peer;
|
|
1526
|
-
if (peer.connected && peer.version === this.version) {
|
|
1527
|
-
let data = await new globalThis.peernet.protos['peernet-request']({
|
|
1528
|
-
request: 'knownBlocks'
|
|
1529
|
-
});
|
|
1530
|
-
let node = await globalThis.peernet.prepareMessage(data);
|
|
1531
|
-
let message = await peer.request(node);
|
|
1532
|
-
message = await new globalThis.peernet.protos['peernet-response'](message);
|
|
1533
|
-
this.knownBlocks = message.decoded.response;
|
|
1534
|
-
}
|
|
1535
|
-
}
|
|
1536
|
-
return latest;
|
|
1537
|
-
}
|
|
1538
|
-
#loadBlockTransactions;
|
|
1539
|
-
#getLastTransactions;
|
|
1540
|
-
/**
|
|
1541
|
-
*
|
|
1542
|
-
* @param {Block[]} blocks
|
|
1543
|
-
*/
|
|
1544
|
-
async #loadBlocks(blocks) {
|
|
1545
|
-
this.#chainState = 'loading';
|
|
1546
|
-
let poolTransactionKeys = await globalThis.transactionPoolStore.keys();
|
|
1547
|
-
for (const block of blocks) {
|
|
1548
|
-
if (block && !block.loaded) {
|
|
1549
|
-
if (block.index === 0)
|
|
1550
|
-
this.#loaded = true;
|
|
1551
|
-
const transactions = await this.#loadBlockTransactions([...block.transactions] || []);
|
|
1552
|
-
const lastTransactions = await this.#getLastTransactions();
|
|
1553
|
-
for (const transaction of transactions) {
|
|
1554
|
-
const hash = await transaction.hash();
|
|
1555
|
-
if (poolTransactionKeys.includes(hash))
|
|
1556
|
-
await globalThis.transactionPoolStore.delete(hash);
|
|
1557
|
-
if (lastTransactions.includes(hash)) {
|
|
1558
|
-
console.log('removing invalid block');
|
|
1559
|
-
await globalThis.blockStore.delete(await (await new BlockMessage(block)).hash());
|
|
1560
|
-
blocks.splice(block.index - 1, 1);
|
|
1561
|
-
return this.#loadBlocks(blocks);
|
|
1562
|
-
}
|
|
1563
|
-
try {
|
|
1564
|
-
await this.#machine.execute(transaction.decoded.to, transaction.decoded.method, transaction.decoded.params);
|
|
1565
|
-
await globalThis.accountsStore.put(transaction.decoded.from, String(transaction.decoded.nonce));
|
|
1566
|
-
if (transaction.decoded.to === nativeToken$2) {
|
|
1567
|
-
this.#nativeCalls += 1;
|
|
1568
|
-
if (transaction.decoded.method === 'burn')
|
|
1569
|
-
this.#nativeBurns += 1;
|
|
1570
|
-
if (transaction.decoded.method === 'mint')
|
|
1571
|
-
this.#nativeMints += 1;
|
|
1572
|
-
if (transaction.decoded.method === 'transfer')
|
|
1573
|
-
this.#nativeTransfers += 1;
|
|
1574
|
-
}
|
|
1575
|
-
this.#totalTransactions += 1;
|
|
1576
|
-
}
|
|
1577
|
-
catch (error) {
|
|
1578
|
-
console.log(error);
|
|
1579
|
-
await globalThis.transactionPoolStore.delete(hash);
|
|
1580
|
-
console.log('removing invalid transaction');
|
|
1581
|
-
if (isExecutionError(error)) {
|
|
1582
|
-
console.log(`removing invalid block ${block.index}`);
|
|
1583
|
-
await globalThis.blockStore.delete(await (await new BlockMessage(block)).hash());
|
|
1584
|
-
const deletedBlock = blocks.splice(block.index, 1);
|
|
1585
|
-
console.log(`removed block ${deletedBlock[0].index}`);
|
|
1586
|
-
return this.#loadBlocks(blocks);
|
|
1587
|
-
}
|
|
1588
|
-
console.log(error);
|
|
1589
|
-
return false;
|
|
1590
|
-
}
|
|
1591
|
-
}
|
|
1592
|
-
this.#blocks[block.index - 1].loaded = true;
|
|
1593
|
-
// @ts-ignore
|
|
1594
|
-
globalThis.debug(`loaded block: ${block.hash} @${block.index}`);
|
|
1595
|
-
globalThis.pubsub.publish('block-loaded', { ...block });
|
|
1596
|
-
}
|
|
1597
|
-
}
|
|
1598
|
-
this.#chainState = 'loaded';
|
|
1599
|
-
return true;
|
|
1600
|
-
}
|
|
1601
|
-
promiseRequests(promises) {
|
|
1602
|
-
return new Promise(async (resolve, reject) => {
|
|
1603
|
-
const timeout = setTimeout(() => {
|
|
1604
|
-
resolve([{ index: 0, hash: '0x0' }]);
|
|
1605
|
-
globalThis.debug('sync timed out');
|
|
1606
|
-
}, this.requestTimeout);
|
|
1607
|
-
promises = await Promise.allSettled(promises);
|
|
1608
|
-
promises = promises.filter(({ status }) => status === 'fulfilled');
|
|
1609
|
-
clearTimeout(timeout);
|
|
1610
|
-
if (promises.length > 0) {
|
|
1611
|
-
promises = promises.map(async ({ value }) => {
|
|
1612
|
-
const node = await new globalThis.peernet.protos['peernet-response'](value.result);
|
|
1613
|
-
return { value: node.decoded.response, peer: value.peer };
|
|
1614
|
-
});
|
|
1615
|
-
promises = await Promise.all(promises);
|
|
1616
|
-
resolve(promises);
|
|
1617
|
-
}
|
|
1618
|
-
else {
|
|
1619
|
-
resolve([]);
|
|
1620
|
-
}
|
|
1621
|
-
});
|
|
1622
|
-
}
|
|
1623
|
-
get canSync() {
|
|
1624
|
-
if (this.#chainSyncing)
|
|
1625
|
-
return false;
|
|
1626
|
-
return true;
|
|
1627
|
-
}
|
|
1628
|
-
get shouldSync() {
|
|
1629
|
-
if (this.#chainSyncing)
|
|
1630
|
-
return false;
|
|
1631
|
-
if (this.#resolveErrored ||
|
|
1632
|
-
this.#syncState === 'errored' ||
|
|
1633
|
-
this.#syncState === 'connectionless' ||
|
|
1634
|
-
this.#lastResolvedTime + this.resolveTimeout > Date.now())
|
|
1635
|
-
return true;
|
|
1636
|
-
return false;
|
|
1637
|
-
}
|
|
1638
|
-
async triggerSync() {
|
|
1639
|
-
const latest = await this.#getLatestBlock();
|
|
1640
|
-
return this.syncChain(latest);
|
|
1641
|
-
}
|
|
1642
|
-
async triggerLoad() {
|
|
1643
|
-
if (this.#blocks.length > 0) {
|
|
1644
|
-
this.#machine = await new Machine(this.#blocks);
|
|
1645
|
-
}
|
|
1646
|
-
}
|
|
1647
|
-
}
|
|
1648
|
-
|
|
1649
|
-
class VersionControl extends State {
|
|
1650
|
-
constructor() {
|
|
1651
|
-
super();
|
|
1652
|
-
}
|
|
1653
|
-
async init() {
|
|
1654
|
-
super.init && (await super.init());
|
|
1655
|
-
console.log('init');
|
|
1656
|
-
try {
|
|
1657
|
-
const version = await globalThis.chainStore.get('version');
|
|
1658
|
-
this.version = new TextDecoder().decode(version);
|
|
1659
|
-
console.log(this.version);
|
|
1660
|
-
/**
|
|
1661
|
-
* protocol version control!
|
|
1662
|
-
* note v1 and 1.1 delete everything because of big changes, this is not what we want in the future
|
|
1663
|
-
* in the future we want newer nodes to handle the new changes and still confirm old version transactions
|
|
1664
|
-
* unless there is a security issue!
|
|
1665
|
-
*/
|
|
1666
|
-
if (this.version !== '1.1.1') {
|
|
1667
|
-
this.version = '1.1.1';
|
|
1668
|
-
await this.clearAll();
|
|
1669
|
-
await globalThis.chainStore.put('version', this.version);
|
|
1670
|
-
}
|
|
1671
|
-
// if (version)
|
|
1672
|
-
}
|
|
1673
|
-
catch (e) {
|
|
1674
|
-
console.log(e);
|
|
1675
|
-
this.version = '1.1.1';
|
|
1676
|
-
await this.clearAll();
|
|
1677
|
-
await globalThis.chainStore.put('version', this.version);
|
|
1678
|
-
}
|
|
1679
|
-
}
|
|
1680
|
-
}
|
|
1681
|
-
|
|
1682
|
-
globalThis.BigNumber = BigNumber;
|
|
1683
|
-
const ignorelist = [];
|
|
1684
|
-
// check if browser or local
|
|
1685
|
-
class Chain extends VersionControl {
|
|
1686
|
-
#state;
|
|
1687
|
-
#slotTime;
|
|
1688
|
-
/** {Address[]} */
|
|
1689
|
-
#validators;
|
|
1690
|
-
/** {Boolean} */
|
|
1691
|
-
#runningEpoch;
|
|
1692
|
-
#participants;
|
|
1693
|
-
#participating;
|
|
1694
|
-
#jail;
|
|
1695
|
-
constructor() {
|
|
1696
|
-
super();
|
|
1697
|
-
this.#slotTime = 10000;
|
|
1698
|
-
this.utils = {};
|
|
1699
|
-
/** {Address[]} */
|
|
1700
|
-
this.#validators = [];
|
|
1701
|
-
/** {Boolean} */
|
|
1702
|
-
this.#runningEpoch = false;
|
|
1703
|
-
this.#participants = [];
|
|
1704
|
-
this.#participating = false;
|
|
1705
|
-
this.#jail = [];
|
|
1706
|
-
// @ts-ignore
|
|
1707
|
-
return this.#init();
|
|
1708
|
-
}
|
|
1709
|
-
get nativeToken() {
|
|
1710
|
-
return addresses.nativeToken;
|
|
1711
|
-
}
|
|
1712
|
-
get validators() {
|
|
1713
|
-
return [...this.#validators];
|
|
1714
|
-
}
|
|
1715
|
-
async hasTransactionToHandle() {
|
|
1716
|
-
const size = await globalThis.transactionPoolStore.size();
|
|
1717
|
-
if (size > 0)
|
|
1718
|
-
return true;
|
|
1719
|
-
return false;
|
|
1720
|
-
}
|
|
1721
|
-
async #runEpoch() {
|
|
1722
|
-
this.#runningEpoch = true;
|
|
1723
|
-
console.log('epoch');
|
|
1724
|
-
const validators = await this.staticCall(addresses.validators, 'validators');
|
|
1725
|
-
console.log({ validators });
|
|
1726
|
-
if (!validators[peernet.selectedAccount]?.active)
|
|
1727
|
-
return;
|
|
1728
|
-
const start = Date.now();
|
|
1729
|
-
try {
|
|
1730
|
-
await this.#createBlock();
|
|
1731
|
-
}
|
|
1732
|
-
catch (error) {
|
|
1733
|
-
console.error(error);
|
|
1734
|
-
}
|
|
1735
|
-
const end = Date.now();
|
|
1736
|
-
console.log((end - start) / 1000 + ' s');
|
|
1737
|
-
if (await this.hasTransactionToHandle())
|
|
1738
|
-
return this.#runEpoch();
|
|
1739
|
-
this.#runningEpoch = false;
|
|
1740
|
-
// if (await this.hasTransactionToHandle() && !this.#runningEpoch) return this.#runEpoch()
|
|
1741
|
-
}
|
|
1742
|
-
async #setup() {
|
|
1743
|
-
const contracts = [
|
|
1744
|
-
{
|
|
1745
|
-
address: addresses.contractFactory,
|
|
1746
|
-
message: contractFactoryMessage
|
|
1747
|
-
},
|
|
1748
|
-
{
|
|
1749
|
-
address: addresses.nativeToken,
|
|
1750
|
-
message: nativeTokenMessage
|
|
1751
|
-
},
|
|
1752
|
-
{
|
|
1753
|
-
address: addresses.validators,
|
|
1754
|
-
message: validatorsMessage
|
|
1755
|
-
},
|
|
1756
|
-
{
|
|
1757
|
-
address: addresses.nameService,
|
|
1758
|
-
message: nameServiceMessage
|
|
1759
|
-
}
|
|
1760
|
-
];
|
|
1761
|
-
await Promise.all(contracts.map(async ({ address, message }) => {
|
|
1762
|
-
// @ts-ignore
|
|
1763
|
-
message = await new ContractMessage(Uint8Array.from(message.split(',').map((string) => Number(string))));
|
|
1764
|
-
// @ts-ignore
|
|
1765
|
-
await globalThis.contractStore.put(address, message.encoded);
|
|
1766
|
-
}));
|
|
1767
|
-
console.log('handle native contracts');
|
|
1768
|
-
// handle native contracts
|
|
1769
|
-
}
|
|
1770
|
-
async #init() {
|
|
1771
|
-
// this.node = await new Node()
|
|
1772
|
-
this.#participants = [];
|
|
1773
|
-
this.#participating = false;
|
|
1774
|
-
const initialized = await globalThis.contractStore.has(addresses.contractFactory);
|
|
1775
|
-
if (!initialized)
|
|
1776
|
-
await this.#setup();
|
|
1777
|
-
this.utils = { BigNumber, formatUnits, parseUnits };
|
|
1778
|
-
// this.#state = new State()
|
|
1779
|
-
// todo some functions rely on state
|
|
1780
|
-
await super.init();
|
|
1781
|
-
await globalThis.peernet.addRequestHandler('bw-request-message', () => {
|
|
1782
|
-
return new BWMessage(globalThis.peernet.client.bw) || { up: 0, down: 0 };
|
|
1783
|
-
});
|
|
1784
|
-
// await globalThis.peernet.addRequestHandler('peerId', () => {
|
|
1785
|
-
// let node =
|
|
1786
|
-
// globalThis.peernet.protos['peernet-response']({response: node.encoded})
|
|
1787
|
-
// })
|
|
1788
|
-
await globalThis.peernet.addRequestHandler('transactionPool', this.#transactionPoolHandler.bind(this));
|
|
1789
|
-
await globalThis.peernet.addRequestHandler('version', this.#versionHandler.bind(this));
|
|
1790
|
-
globalThis.peernet.subscribe('add-block', this.#addBlock.bind(this));
|
|
1791
|
-
globalThis.peernet.subscribe('invalid-transaction', this.#invalidTransaction.bind(this));
|
|
1792
|
-
globalThis.peernet.subscribe('send-transaction', this.#sendTransaction.bind(this));
|
|
1793
|
-
globalThis.peernet.subscribe('add-transaction', this.#addTransaction.bind(this));
|
|
1794
|
-
globalThis.peernet.subscribe('validator:timeout', this.#validatorTimeout.bind(this));
|
|
1795
|
-
globalThis.pubsub.subscribe('peer:connected', this.#peerConnected.bind(this));
|
|
1796
|
-
globalThis.pubsub.publish('chain:ready', true);
|
|
1797
|
-
return this;
|
|
1798
|
-
}
|
|
1799
|
-
async #invalidTransaction(hash) {
|
|
1800
|
-
await globalThis.transactionPoolStore.delete(hash);
|
|
1801
|
-
console.log(`removed invalid transaction: ${hash}`);
|
|
1802
|
-
}
|
|
1803
|
-
async #validatorTimeout(validatorInfo) {
|
|
1804
|
-
setTimeout(() => {
|
|
1805
|
-
this.#jail.splice(this.#jail.indexOf(validatorInfo.address), 1);
|
|
1806
|
-
}, validatorInfo.timeout);
|
|
1807
|
-
this.#jail.push(validatorInfo.address);
|
|
1808
|
-
}
|
|
1809
|
-
#addTransaction(message) {
|
|
1810
|
-
console.log({ message });
|
|
1811
|
-
}
|
|
1812
|
-
async #prepareRequest(request) {
|
|
1813
|
-
let node = await new globalThis.peernet.protos['peernet-request']({ request });
|
|
1814
|
-
return globalThis.peernet.prepareMessage(node);
|
|
1815
|
-
}
|
|
1816
|
-
async #makeRequest(peer, request) {
|
|
1817
|
-
const node = await this.#prepareRequest(request);
|
|
1818
|
-
let response = await peer.request(node.encoded);
|
|
1819
|
-
response = await new globalThis.peernet.protos['peernet-response'](new Uint8Array(Object.values(response)));
|
|
1820
|
-
return response.decoded.response;
|
|
1821
|
-
}
|
|
1822
|
-
async getPeerTransactionPool(peer) {
|
|
1823
|
-
const transactionsInPool = await this.#makeRequest(peer, 'transactionPool');
|
|
1824
|
-
// todo iterate vs getting all keys?
|
|
1825
|
-
const transactions = await globalThis.transactionPoolStore.keys();
|
|
1826
|
-
const transactionsToGet = [];
|
|
1827
|
-
for (const key of transactionsInPool) {
|
|
1828
|
-
!transactions.includes(key) &&
|
|
1829
|
-
!ignorelist.includes(key) &&
|
|
1830
|
-
transactionsToGet.push(transactionPoolStore.put(key, await peernet.get(key, 'transaction')));
|
|
1831
|
-
}
|
|
1832
|
-
return Promise.all(transactionsToGet);
|
|
1833
|
-
}
|
|
1834
|
-
async #peerConnected(peer) {
|
|
1835
|
-
// todo handle version changes
|
|
1836
|
-
// for now just do nothing if version doesn't match
|
|
1837
|
-
console.log(`${peer.version}, ${this.version}`);
|
|
1838
|
-
if (!peer.version || peer.version !== this.version)
|
|
1839
|
-
return;
|
|
1840
|
-
const lastBlock = await this.#makeRequest(peer, 'lastBlock');
|
|
1841
|
-
console.log(lastBlock);
|
|
1842
|
-
const higherThenCurrentLocal = !this.lastBlock?.index ? true : lastBlock.index > this.lastBlock?.index;
|
|
1843
|
-
const peerTransactionPool = (higherThenCurrentLocal && (await this.getPeerTransactionPool(peer))) || [];
|
|
1844
|
-
console.log(this.lastBlock);
|
|
1845
|
-
if (Object.keys(lastBlock).length > 0) {
|
|
1846
|
-
if (!this.lastBlock || higherThenCurrentLocal) {
|
|
1847
|
-
this.knownBlocks = await this.#makeRequest(peer, 'knownBlocks');
|
|
1848
|
-
await this.syncChain(lastBlock);
|
|
1849
|
-
}
|
|
1850
|
-
else if (!this.knownBlocks)
|
|
1851
|
-
this.knownBlocks = await this.#makeRequest(peer, 'knownBlocks');
|
|
1852
|
-
}
|
|
1853
|
-
if (this.#participating && peerTransactionPool.length > 0)
|
|
1854
|
-
return this.#runEpoch();
|
|
1855
|
-
}
|
|
1856
|
-
#epochTimeout;
|
|
1857
|
-
async #transactionPoolHandler() {
|
|
1858
|
-
const pool = await globalThis.transactionPoolStore.keys();
|
|
1859
|
-
return new globalThis.peernet.protos['peernet-response']({ response: pool });
|
|
1860
|
-
}
|
|
1861
|
-
async #versionHandler() {
|
|
1862
|
-
return new globalThis.peernet.protos['peernet-response']({ response: { version: this.version } });
|
|
1863
|
-
}
|
|
1864
|
-
async #executeTransaction({ hash, from, to, method, params, nonce }) {
|
|
1865
|
-
try {
|
|
1866
|
-
let result = await this.machine.execute(to, method, params);
|
|
1867
|
-
// await accountsStore.put(to, nonce)
|
|
1868
|
-
await transactionPoolStore.delete(hash);
|
|
1869
|
-
// if (!result) result = this.machine.state
|
|
1870
|
-
globalThis.pubsub.publish(`transaction.completed.${hash}`, { status: 'fulfilled', hash });
|
|
1871
|
-
return result || 'no state change';
|
|
1872
|
-
}
|
|
1873
|
-
catch (error) {
|
|
1874
|
-
await transactionPoolStore.delete(hash);
|
|
1875
|
-
globalThis.peernet.publish('invalid-transaction', hash);
|
|
1876
|
-
globalThis.pubsub.publish(`transaction.completed.${hash}`, { status: 'fail', hash, error: error });
|
|
1877
|
-
throw { error, hash, from, to, params, nonce };
|
|
1878
|
-
}
|
|
1879
|
-
}
|
|
1880
|
-
async #addBlock(block) {
|
|
1881
|
-
const blockMessage = await new BlockMessage(block);
|
|
1882
|
-
await Promise.all(blockMessage.decoded.transactions
|
|
1883
|
-
// @ts-ignore
|
|
1884
|
-
.map(async (transaction) => transactionPoolStore.delete(transaction.hash)));
|
|
1885
|
-
const hash = await blockMessage.hash();
|
|
1886
|
-
await globalThis.blockStore.put(hash, blockMessage.encoded);
|
|
1887
|
-
if (this.lastBlock.index < Number(blockMessage.decoded.index))
|
|
1888
|
-
await this.updateState(blockMessage);
|
|
1889
|
-
globalThis.debug(`added block: ${hash}`);
|
|
1890
|
-
let promises = [];
|
|
1891
|
-
let contracts = [];
|
|
1892
|
-
for (let transaction of blockMessage.decoded.transactions) {
|
|
1893
|
-
// await transactionStore.put(transaction.hash, transaction.encoded)
|
|
1894
|
-
// @ts-ignore
|
|
1895
|
-
const index = contracts.indexOf(transaction.to);
|
|
1896
|
-
// @ts-ignore
|
|
1897
|
-
if (index === -1)
|
|
1898
|
-
contracts.push(transaction.to);
|
|
1899
|
-
// Todo: go trough all accounts
|
|
1900
|
-
// @ts-ignore
|
|
1901
|
-
promises.push(this.#executeTransaction(transaction));
|
|
1902
|
-
}
|
|
1903
|
-
try {
|
|
1904
|
-
promises = await Promise.allSettled(promises);
|
|
1905
|
-
for (let transaction of blockMessage.decoded.transactions) {
|
|
1906
|
-
globalThis.pubsub.publish('transaction-processed', transaction);
|
|
1907
|
-
if (transaction.to === globalThis.peernet.selectedAccount)
|
|
1908
|
-
globalThis.pubsub.publish('account-transaction-processed', transaction);
|
|
1909
|
-
await globalThis.accountsStore.put(transaction.from, String(transaction.nonce));
|
|
1910
|
-
}
|
|
1911
|
-
// todo finish state
|
|
1912
|
-
// for (const contract of contracts) {
|
|
1913
|
-
// const state = await this.machine.get(contract, 'state')
|
|
1914
|
-
// // await stateStore.put(contract, state)
|
|
1915
|
-
// console.log(state);
|
|
1916
|
-
// }
|
|
1917
|
-
globalThis.pubsub.publish('block-processed', blockMessage.decoded);
|
|
1918
|
-
}
|
|
1919
|
-
catch (error) {
|
|
1920
|
-
console.log(error.hash);
|
|
1921
|
-
console.log('errrrr');
|
|
1922
|
-
await transactionPoolStore.delete(error.hash);
|
|
1923
|
-
}
|
|
1924
|
-
}
|
|
1925
|
-
async participate(address) {
|
|
1926
|
-
// TODO: validate participant
|
|
1927
|
-
// hold min amount of 50k ART for 7 days
|
|
1928
|
-
// lock the 50k
|
|
1929
|
-
// introduce peer-reputation
|
|
1930
|
-
// peerReputation(peerId)
|
|
1931
|
-
// {bandwith: {up, down}, uptime}
|
|
1932
|
-
this.#participating = true;
|
|
1933
|
-
if (!(await this.staticCall(addresses.validators, 'has', [address]))) {
|
|
1934
|
-
const rawTransaction = {
|
|
1935
|
-
from: address,
|
|
1936
|
-
to: addresses.validators,
|
|
1937
|
-
method: 'addValidator',
|
|
1938
|
-
params: [address],
|
|
1939
|
-
nonce: (await this.getNonce(address)) + 1,
|
|
1940
|
-
timestamp: Date.now()
|
|
1941
|
-
};
|
|
1942
|
-
const transaction = await signTransaction(rawTransaction, globalThis.peernet.identity);
|
|
1943
|
-
await this.sendTransaction(transaction);
|
|
1944
|
-
}
|
|
1945
|
-
if ((await this.hasTransactionToHandle()) && !this.#runningEpoch && this.#participating)
|
|
1946
|
-
await this.#runEpoch();
|
|
1947
|
-
}
|
|
1948
|
-
// todo filter tx that need to wait on prev nonce
|
|
1949
|
-
async #createBlock(limit = this.transactionLimit) {
|
|
1950
|
-
// vote for transactions
|
|
1951
|
-
if ((await globalThis.transactionPoolStore.size()) === 0)
|
|
1952
|
-
return;
|
|
1953
|
-
let transactions = await globalThis.transactionPoolStore.values(this.transactionLimit);
|
|
1954
|
-
for (const hash of await globalThis.transactionPoolStore.keys()) {
|
|
1955
|
-
if (ignorelist.includes(hash))
|
|
1956
|
-
await globalThis.transactionPoolStore.delete(hash);
|
|
1957
|
-
}
|
|
1958
|
-
if (Object.keys(transactions)?.length === 0)
|
|
1959
|
-
return;
|
|
1960
|
-
const timestamp = Date.now();
|
|
1961
|
-
let block = {
|
|
1962
|
-
transactions: [],
|
|
1963
|
-
validators: [],
|
|
1964
|
-
fees: BigNumber.from(0),
|
|
1965
|
-
timestamp,
|
|
1966
|
-
previousHash: '',
|
|
1967
|
-
reward: parseUnits('150'),
|
|
1968
|
-
index: 0
|
|
1969
|
-
};
|
|
1970
|
-
// exclude failing tx
|
|
1971
|
-
transactions = await this.promiseTransactions(transactions);
|
|
1972
|
-
transactions = transactions.sort((a, b) => a.nonce - b.nonce);
|
|
1973
|
-
for (let transaction of transactions) {
|
|
1974
|
-
const hash = await transaction.hash();
|
|
1975
|
-
const doubleTransactions = [];
|
|
1976
|
-
for (const block of this.blocks) {
|
|
1977
|
-
for (const transaction of block.transactions) {
|
|
1978
|
-
if (transaction.hash === hash) {
|
|
1979
|
-
doubleTransactions.push(hash);
|
|
1980
|
-
}
|
|
1981
|
-
}
|
|
1982
|
-
}
|
|
1983
|
-
if (doubleTransactions.length > 0) {
|
|
1984
|
-
await globalThis.transactionPoolStore.delete(hash);
|
|
1985
|
-
await globalThis.peernet.publish('invalid-transaction', hash);
|
|
1986
|
-
return;
|
|
1987
|
-
}
|
|
1988
|
-
// if (timestamp + this.#slotTime > Date.now()) {
|
|
1989
|
-
try {
|
|
1990
|
-
const result = await this.#executeTransaction({ ...transaction.decoded, hash });
|
|
1991
|
-
block.transactions.push(transaction);
|
|
1992
|
-
block.fees = block.fees.add(await calculateFee(transaction.decoded));
|
|
1993
|
-
await globalThis.accountsStore.put(transaction.decoded.from, new TextEncoder().encode(String(transaction.decoded.nonce)));
|
|
1994
|
-
}
|
|
1995
|
-
catch (e) {
|
|
1996
|
-
console.log('vvvvvv');
|
|
1997
|
-
console.log({ e });
|
|
1998
|
-
console.log(hash);
|
|
1999
|
-
peernet.publish('invalid-transaction', hash);
|
|
2000
|
-
console.log(await globalThis.transactionPoolStore.keys());
|
|
2001
|
-
console.log(await globalThis.transactionPoolStore.has(e.hash));
|
|
2002
|
-
await globalThis.transactionPoolStore.delete(e.hash);
|
|
2003
|
-
console.log(await globalThis.transactionPoolStore.has(e.hash));
|
|
2004
|
-
}
|
|
2005
|
-
}
|
|
2006
|
-
// don't add empty block
|
|
2007
|
-
if (block.transactions.length === 0)
|
|
2008
|
-
return;
|
|
2009
|
-
const validators = await this.staticCall(addresses.validators, 'validators');
|
|
2010
|
-
// block.validators = Object.keys(block.validators).reduce((set, key) => {
|
|
2011
|
-
// if (block.validators[key].active) {
|
|
2012
|
-
// push({
|
|
2013
|
-
// address: key
|
|
2014
|
-
// })
|
|
2015
|
-
// }
|
|
2016
|
-
// }, [])
|
|
2017
|
-
const peers = {};
|
|
2018
|
-
for (const entry of globalThis.peernet.peerEntries) {
|
|
2019
|
-
peers[entry[0]] = entry[1];
|
|
2020
|
-
}
|
|
2021
|
-
for (const validator of Object.keys(validators)) {
|
|
2022
|
-
if (validators[validator].active) {
|
|
2023
|
-
const peer = peers[validator];
|
|
2024
|
-
if (peer && peer.connected && peer.version === this.version) {
|
|
2025
|
-
let data = await new BWRequestMessage();
|
|
2026
|
-
const node = await globalThis.peernet.prepareMessage(data.encoded);
|
|
2027
|
-
try {
|
|
2028
|
-
const bw = await peer.request(node.encoded);
|
|
2029
|
-
block.validators.push({
|
|
2030
|
-
address: validator,
|
|
2031
|
-
bw: bw.up + bw.down
|
|
2032
|
-
});
|
|
2033
|
-
}
|
|
2034
|
-
catch { }
|
|
2035
|
-
}
|
|
2036
|
-
else if (globalThis.peernet.selectedAccount === validator) {
|
|
2037
|
-
block.validators.push({
|
|
2038
|
-
address: globalThis.peernet.selectedAccount,
|
|
2039
|
-
bw: globalThis.peernet.bw.up + globalThis.peernet.bw.down
|
|
2040
|
-
});
|
|
2041
|
-
}
|
|
2042
|
-
}
|
|
2043
|
-
}
|
|
2044
|
-
block.validators = block.validators.map((validator) => {
|
|
2045
|
-
validator.reward = block.fees;
|
|
2046
|
-
validator.reward = validator.reward.add(block.reward);
|
|
2047
|
-
validator.reward = validator.reward.div(block.validators.length);
|
|
2048
|
-
delete validator.bw;
|
|
2049
|
-
return validator;
|
|
2050
|
-
});
|
|
2051
|
-
// block.validators = calculateValidatorReward(block.validators, block.fees)
|
|
2052
|
-
block.index = this.lastBlock?.index;
|
|
2053
|
-
if (block.index === undefined)
|
|
2054
|
-
block.index = 0;
|
|
2055
|
-
else
|
|
2056
|
-
block.index += 1;
|
|
2057
|
-
block.previousHash = this.lastBlock?.hash || '0x0';
|
|
2058
|
-
// block.timestamp = Date.now()
|
|
2059
|
-
// block.reward = block.reward.toString()
|
|
2060
|
-
// block.fees = block.fees.toString()
|
|
2061
|
-
try {
|
|
2062
|
-
block.transactions = await Promise.all(block.transactions.map(async (transaction) => {
|
|
2063
|
-
await globalThis.transactionPoolStore.delete(await transaction.hash());
|
|
2064
|
-
return transaction.decoded;
|
|
2065
|
-
}));
|
|
2066
|
-
let blockMessage = await new BlockMessage(block);
|
|
2067
|
-
const hash = await blockMessage.hash();
|
|
2068
|
-
await globalThis.peernet.put(hash, blockMessage.encoded, 'block');
|
|
2069
|
-
await this.updateState(blockMessage);
|
|
2070
|
-
globalThis.debug(`created block: ${hash}`);
|
|
2071
|
-
globalThis.peernet.publish('add-block', blockMessage.encoded);
|
|
2072
|
-
globalThis.pubsub.publish('add-block', blockMessage.decoded);
|
|
2073
|
-
}
|
|
2074
|
-
catch (error) {
|
|
2075
|
-
console.log(error);
|
|
2076
|
-
console.log('eeeee');
|
|
2077
|
-
throw new Error(`invalid block ${block}`);
|
|
2078
|
-
}
|
|
2079
|
-
// data = await this.machine.execute(to, method, params)
|
|
2080
|
-
// transactionStore.put(message.hash, message.encoded)
|
|
2081
|
-
}
|
|
2082
|
-
async #sendTransaction(transaction) {
|
|
2083
|
-
transaction = await new TransactionMessage(transaction.encoded || transaction);
|
|
2084
|
-
const hash = await transaction.hash();
|
|
2085
|
-
try {
|
|
2086
|
-
const has = await globalThis.transactionPoolStore.has(hash);
|
|
2087
|
-
if (!has) {
|
|
2088
|
-
await globalThis.transactionPoolStore.put(hash, transaction.encoded);
|
|
2089
|
-
}
|
|
2090
|
-
if (this.#participating && !this.#runningEpoch)
|
|
2091
|
-
this.#runEpoch();
|
|
2092
|
-
}
|
|
2093
|
-
catch (e) {
|
|
2094
|
-
console.log(e);
|
|
2095
|
-
console.log('rrrrr');
|
|
2096
|
-
globalThis.peernet.publish('invalid-transaction', hash);
|
|
2097
|
-
throw new Error('invalid transaction');
|
|
2098
|
-
}
|
|
2099
|
-
}
|
|
2100
|
-
/**
|
|
2101
|
-
* every tx done is trough contracts so no need for amount
|
|
2102
|
-
* data is undefined when nothing is returned
|
|
2103
|
-
* error is thrown on error so undefined data doesn't mean there is an error...
|
|
2104
|
-
**/
|
|
2105
|
-
async sendTransaction(transaction) {
|
|
2106
|
-
const transactionMessage = await new TransactionMessage({ ...transaction });
|
|
2107
|
-
const event = await super.sendTransaction(transactionMessage);
|
|
2108
|
-
this.#sendTransaction(transactionMessage.encoded);
|
|
2109
|
-
globalThis.peernet.publish('send-transaction', transactionMessage.encoded);
|
|
2110
|
-
return event;
|
|
2111
|
-
}
|
|
2112
|
-
async addContract(transaction, contractMessage) {
|
|
2113
|
-
const hash = await contractMessage.hash();
|
|
2114
|
-
const has = await this.staticCall(addresses.contractFactory, 'isRegistered', [hash]);
|
|
2115
|
-
if (has)
|
|
2116
|
-
throw new Error('contract exists');
|
|
2117
|
-
const tx = await this.sendTransaction(transaction);
|
|
2118
|
-
await tx.wait;
|
|
2119
|
-
return tx;
|
|
2120
|
-
}
|
|
2121
|
-
/**
|
|
2122
|
-
*
|
|
2123
|
-
* @param {Address} sender
|
|
2124
|
-
* @returns {globalMessage}
|
|
2125
|
-
*/
|
|
2126
|
-
#createMessage(sender = globalThis.peernet.selectedAccount) {
|
|
2127
|
-
return {
|
|
2128
|
-
sender,
|
|
2129
|
-
call: this.call,
|
|
2130
|
-
staticCall: this.staticCall
|
|
2131
|
-
};
|
|
2132
|
-
}
|
|
2133
|
-
/**
|
|
2134
|
-
*
|
|
2135
|
-
* @param {Address} sender
|
|
2136
|
-
* @param {Address} contract
|
|
2137
|
-
* @param {String} method
|
|
2138
|
-
* @param {Array} parameters
|
|
2139
|
-
* @returns
|
|
2140
|
-
*/
|
|
2141
|
-
internalCall(sender, contract, method, parameters) {
|
|
2142
|
-
globalThis.msg = this.#createMessage(sender);
|
|
2143
|
-
return this.machine.execute(contract, method, parameters);
|
|
2144
|
-
}
|
|
2145
|
-
/**
|
|
2146
|
-
*
|
|
2147
|
-
* @param {Address} contract
|
|
2148
|
-
* @param {String} method
|
|
2149
|
-
* @param {Array} parameters
|
|
2150
|
-
* @returns
|
|
2151
|
-
*/
|
|
2152
|
-
call(contract, method, parameters) {
|
|
2153
|
-
globalThis.msg = this.#createMessage();
|
|
2154
|
-
return this.machine.execute(contract, method, parameters);
|
|
2155
|
-
}
|
|
2156
|
-
staticCall(contract, method, parameters) {
|
|
2157
|
-
globalThis.msg = this.#createMessage();
|
|
2158
|
-
return this.machine.get(contract, method, parameters);
|
|
2159
|
-
}
|
|
2160
|
-
mint(to, amount) {
|
|
2161
|
-
return this.call(addresses.nativeToken, 'mint', [to, amount]);
|
|
2162
|
-
}
|
|
2163
|
-
transfer(from, to, amount) {
|
|
2164
|
-
return this.call(addresses.nativeToken, 'transfer', [from, to, amount]);
|
|
2165
|
-
}
|
|
2166
|
-
get balances() {
|
|
2167
|
-
return this.staticCall(addresses.nativeToken, 'balances');
|
|
2168
|
-
}
|
|
2169
|
-
get contracts() {
|
|
2170
|
-
return this.staticCall(addresses.contractFactory, 'contracts');
|
|
2171
|
-
}
|
|
2172
|
-
deleteAll() {
|
|
2173
|
-
return this.machine.deleteAll();
|
|
2174
|
-
}
|
|
2175
|
-
/**
|
|
2176
|
-
* lookup an address for a registered name using the builtin nameService
|
|
2177
|
-
* @check nameService
|
|
2178
|
-
*
|
|
2179
|
-
* @param {String} - contractName
|
|
2180
|
-
* @returns {String} - address
|
|
2181
|
-
*
|
|
2182
|
-
* @example chain.lookup('myCoolContractName') // qmqsfddfdgfg...
|
|
2183
|
-
*/
|
|
2184
|
-
lookup(name) {
|
|
2185
|
-
return this.call(addresses.nameService, 'lookup', [name]);
|
|
2186
|
-
}
|
|
2187
|
-
}
|
|
2188
|
-
|
|
2189
|
-
export { Chain as default };
|