@leofcoin/chain 1.0.4

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.
Files changed (82) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/LICENSE +88 -0
  3. package/README.md +4 -0
  4. package/_node.js +1 -0
  5. package/chain.js +1468 -0
  6. package/demo/index.html +18 -0
  7. package/dist/browser/peernet.js +101516 -0
  8. package/dist/chain.browser.js +19879 -0
  9. package/dist/chain.browser.js.tmp-browserify-65536332430764332457 +0 -0
  10. package/dist/chain.browser.js.tmp-browserify-77283953363424018335 +0 -0
  11. package/dist/chain.browser.min.js +2 -0
  12. package/dist/chain.browser.min.js.LICENSE.txt +10 -0
  13. package/dist/chain.js +1468 -0
  14. package/dist/contracts/factory.js +1 -0
  15. package/dist/contracts/nameService.js +1 -0
  16. package/dist/contracts/nativeToken.js +1 -0
  17. package/dist/contracts/validators.js +1 -0
  18. package/dist/lib.browser.js +16966 -0
  19. package/dist/native.js +1 -0
  20. package/dist/node.browser.js +68961 -0
  21. package/dist/node.browser.min.js +2 -0
  22. package/dist/node.browser.min.js.LICENSE.txt +12 -0
  23. package/dist/node.js +1 -0
  24. package/dist/standards/token.js +1 -0
  25. package/dist/token/native.js +1 -0
  26. package/dist/token.js +1 -0
  27. package/examples/contracts/token.js +7 -0
  28. package/lib.js +1 -0
  29. package/package.json +46 -0
  30. package/plugins/bundle.js +18 -0
  31. package/rollup.config.js +151 -0
  32. package/src/addresses.json +6 -0
  33. package/src/apis/token.lfcc +17 -0
  34. package/src/bytecodes.json +6 -0
  35. package/src/chain.js +593 -0
  36. package/src/config/config.js +15 -0
  37. package/src/config/main.js +4 -0
  38. package/src/config/protocol.js +5 -0
  39. package/src/contracts/factory.js +59 -0
  40. package/src/contracts/nameService.js +108 -0
  41. package/src/contracts/nativeToken.js +7 -0
  42. package/src/contracts/powerToken.js +7 -0
  43. package/src/contracts/proxies/factoryProxy.js +12 -0
  44. package/src/contracts/proxies/nameServiceProxy.js +12 -0
  45. package/src/contracts/proxies/nativeTokenProxy.js +12 -0
  46. package/src/contracts/proxies/validatorsProxy.js +12 -0
  47. package/src/contracts/proxies/votingProxy.js +12 -0
  48. package/src/contracts/proxyManager.js +7 -0
  49. package/src/contracts/validators.js +119 -0
  50. package/src/fee/config.js +3 -0
  51. package/src/lib.js +67 -0
  52. package/src/machine.js +130 -0
  53. package/src/messages/block.js +14 -0
  54. package/src/messages/bw-request.js +14 -0
  55. package/src/messages/bw.js +14 -0
  56. package/src/messages/contract.js +13 -0
  57. package/src/messages/last-block-request.js +14 -0
  58. package/src/messages/last-block.js +14 -0
  59. package/src/messages/transaction.js +14 -0
  60. package/src/node.js +55 -0
  61. package/src/protos/block.proto.js +26 -0
  62. package/src/protos/bw-request.proto.js +5 -0
  63. package/src/protos/bw.proto.js +7 -0
  64. package/src/protos/contract.proto.js +7 -0
  65. package/src/protos/last-block-request.proto.js +5 -0
  66. package/src/protos/last-block.proto.js +7 -0
  67. package/src/protos/transaction.proto.js +11 -0
  68. package/src/standards/Proxy.js +42 -0
  69. package/src/standards/Voting.js +3 -0
  70. package/src/standards/initializer.js +10 -0
  71. package/src/standards/proxyManager.js +66 -0
  72. package/src/standards/roles.js +65 -0
  73. package/src/standards/token.js +137 -0
  74. package/src/state.js +26 -0
  75. package/src/transactions/validator.js +29 -0
  76. package/src/typer.js +19 -0
  77. package/src/utils/utils.js +16 -0
  78. package/test/chain.js +119 -0
  79. package/test/contracts/token.js +40 -0
  80. package/test/create-genesis.js +58 -0
  81. package/test/index.js +3 -0
  82. package/webpack.config.js +167 -0
package/dist/chain.js ADDED
@@ -0,0 +1,1468 @@
1
+ 'use strict';
2
+
3
+ var bignumber = require('@ethersproject/bignumber');
4
+ var units = require('@ethersproject/units');
5
+ var chalk = require('chalk');
6
+ require('vm');
7
+ var protons = require('protons');
8
+ var bs32 = require('@vandeurenglenn/base32');
9
+ var bs58 = require('@vandeurenglenn/base58');
10
+ var isHex = require('@vandeurenglenn/is-hex');
11
+ var varint = require('varint');
12
+ var createKeccakHash = require('keccak');
13
+
14
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
15
+
16
+ var chalk__default = /*#__PURE__*/_interopDefaultLegacy(chalk);
17
+ var protons__default = /*#__PURE__*/_interopDefaultLegacy(protons);
18
+ var bs32__default = /*#__PURE__*/_interopDefaultLegacy(bs32);
19
+ var bs58__default = /*#__PURE__*/_interopDefaultLegacy(bs58);
20
+ var isHex__default = /*#__PURE__*/_interopDefaultLegacy(isHex);
21
+ var varint__default = /*#__PURE__*/_interopDefaultLegacy(varint);
22
+ var createKeccakHash__default = /*#__PURE__*/_interopDefaultLegacy(createKeccakHash);
23
+
24
+ // import { promisify } from 'util'
25
+
26
+ const info = text => console.log(chalk__default["default"].blueBright(text));
27
+
28
+ const subinfo = text => console.log(chalk__default["default"].magentaBright(text));
29
+ // export const write = promisify(writeFile)
30
+ // export const read = promisify(readFile)
31
+
32
+ var proto$4 = `
33
+ message ContractMessage {
34
+ required string creator = 1;
35
+ required bytes contract = 2;
36
+ repeated string constructorParameters = 3;
37
+ }
38
+ `;
39
+
40
+ var codecs = {
41
+ // just a hash
42
+ 'disco-hash': {
43
+ codec: parseInt('30', 16),
44
+ hashAlg: 'dbl-keccak-256', // ,
45
+ // testnet: 'olivia'
46
+ },
47
+ 'peernet-peer-response': {
48
+ codec: parseInt('707072', 16),
49
+ hashAlg: 'keccak-256',
50
+ },
51
+ 'peernet-peer': {
52
+ codec: parseInt('7070', 16),
53
+ hashAlg: 'keccak-256',
54
+ },
55
+ 'peernet-dht': {
56
+ codec: parseInt('706468', 16),
57
+ hashAlg: 'keccak-256',
58
+ },
59
+ 'peernet-dht-response': {
60
+ codec: parseInt('706472', 16),
61
+ hashAlg: 'keccak-256',
62
+ },
63
+ // data
64
+ 'peernet-data': {
65
+ codec: parseInt('706461', 16),
66
+ hashAlg: 'keccak-256',
67
+ },
68
+ 'peernet-data-response': {
69
+ codec: parseInt('70646172', 16),
70
+ hashAlg: 'keccak-256',
71
+ },
72
+ // message
73
+ 'peernet-message': {
74
+ codec: parseInt('706d65', 16),
75
+ hashAlg: 'keccak-256',
76
+ },
77
+ // pubsub
78
+ 'peernet-ps': {
79
+ codec: parseInt('707073', 16),
80
+ hashAlg: 'keccak-256',
81
+ },
82
+ 'peernet-response': {
83
+ codec: parseInt('7072', 16),
84
+ hashAlg: 'keccak-256',
85
+ },
86
+ 'peernet-request': {
87
+ codec: parseInt('707271', 16),
88
+ hashAlg: 'keccak-256',
89
+ },
90
+ // normal block
91
+ 'leofcoin-block': {
92
+ codec: parseInt('6c62', 16),
93
+ hashAlg: 'dbl-keccak-512', // ,
94
+ // testnet: 'olivia'
95
+ },
96
+ 'leofcoin-tx': {
97
+ codec: parseInt('6c74', 16),
98
+ hashAlg: 'dbl-keccak-512', // ,
99
+ // testnet: 'olivia'
100
+ },
101
+ // itx
102
+ 'leofcoin-itx': {
103
+ codec: parseInt('6c69', 16),
104
+ hashAlg: 'keccak-512', // ,
105
+ // testnet: 'olivia'
106
+ },
107
+ // peer reputation
108
+ 'leofcoin-pr': {
109
+ codec: parseInt('6c70', 16),
110
+ hashAlg: 'keccak-256', // ,
111
+ // testnet: 'olivia'
112
+ },
113
+ // chat message
114
+ 'chat-message': {
115
+ codec: parseInt('636d', 16),
116
+ hashAlg: 'dbl-keccak-256',
117
+ },
118
+ };
119
+
120
+ class PeernetCodec {
121
+ get codecs() {
122
+ return {...globalThis.peernet.codecs, ...codecs}
123
+ }
124
+ constructor(buffer) {
125
+ if (buffer) {
126
+ if (buffer instanceof Uint8Array) {
127
+ const codec = varint__default["default"].decode(buffer);
128
+ const name = this.getCodecName(codec);
129
+ if (name) {
130
+ this.name = name;
131
+ this.encoded = buffer;
132
+ this.decode(buffer);
133
+ } else {
134
+ this.encode(buffer);
135
+ }
136
+ } else if (buffer instanceof ArrayBuffer) {
137
+ const encoded = new Uint8Array(buffer.byteLength);
138
+
139
+ for (let i = 0; i < buffer.byteLength; i++) {
140
+ encoded[i] = buffer[i];
141
+ }
142
+ this.encoded = encoded;
143
+ // this.encoded = new Uint8Array(buffer, buffer.byteOffset, buffer.byteLength)
144
+ this.decode(buffer);
145
+ return
146
+ }
147
+ if (typeof buffer === 'string') {
148
+ if (this.codecs[buffer]) this.fromName(buffer);
149
+ else if (isHex__default["default"](buffer)) this.fromHex(buffer);
150
+ else if (bs32__default["default"].isBase32(buffer)) this.fromBs32(buffer);
151
+ else if (bs58__default["default"].isBase58(buffer)) this.fromBs58(buffer);
152
+ else throw new Error(`unsupported string ${buffer}`)
153
+ }
154
+ if (!isNaN(buffer)) if (this.codecs[this.getCodecName(buffer)]) this.fromCodec(buffer);
155
+ }
156
+ }
157
+
158
+ fromEncoded(encoded) {
159
+ const codec = varint__default["default"].decode(encoded);
160
+ const name = this.getCodecName(codec);
161
+ this.name = name;
162
+ this.encoded = encoded;
163
+ this.decode(encoded);
164
+ }
165
+
166
+ fromHex(hex) {
167
+ this.encoded = Buffer.from(hex, 'hex');
168
+ this.decode();
169
+ }
170
+
171
+ fromBs32(input) {
172
+ this.encoded = bs32__default["default"].decode(input);
173
+ this.decode();
174
+ }
175
+
176
+ fromBs58(input) {
177
+ this.encoded = bs58__default["default"].decode(input);
178
+ this.decode();
179
+ }
180
+
181
+ getCodec(name) {
182
+ return this.codecs[name].codec
183
+ }
184
+
185
+ getCodecName(codec) {
186
+ return Object.keys(this.codecs).reduce((p, c) => {
187
+ const item = this.codecs[c];
188
+ if (item.codec === codec) return c;
189
+ else return p;
190
+ }, undefined)
191
+ }
192
+
193
+ getHashAlg(name) {
194
+ return this.codecs[name].hashAlg
195
+ }
196
+
197
+ fromCodec(codec) {
198
+ this.name = this.getCodecName(codec);
199
+ this.hashAlg = this.getHashAlg(this.name);
200
+
201
+ this.codec = this.getCodec(this.name);
202
+ this.codecBuffer = varint__default["default"].encode(codec);
203
+ }
204
+
205
+ fromName(name) {
206
+ const codec = this.getCodec(name);
207
+ this.name = name;
208
+ this.codec = codec;
209
+ this.hashAlg = this.getHashAlg(name);
210
+ this.codecBuffer = varint__default["default"].encode(codec);
211
+ }
212
+
213
+ toBs32() {
214
+ this.encode();
215
+ return bs32__default["default"].encode(this.encoded)
216
+ }
217
+
218
+ toBs58() {
219
+ this.encode();
220
+ return bs58__default["default"].encode(this.encoded)
221
+ }
222
+
223
+ toHex() {
224
+ return this.encoded.toString('hex')
225
+ }
226
+
227
+ decode() {
228
+ const codec = varint__default["default"].decode(this.encoded);
229
+ this.fromCodec(codec);
230
+ }
231
+
232
+ encode() {
233
+ const codec = varint__default["default"].encode(this.decoded);
234
+ this.encoded = codec;
235
+ return this.encoded
236
+ }
237
+ }
238
+
239
+ class PeernetHash {
240
+ constructor(buffer, options = {}) {
241
+ if (options.name) this.name = options.name;
242
+ else this.name = 'disco-hash';
243
+ if (options.codecs) this.codecs = options.codecs;
244
+ if (buffer) {
245
+ if (buffer instanceof Uint8Array) {
246
+ this.discoCodec = new PeernetCodec(buffer, this.codecs);
247
+ const name = this.discoCodec.name;
248
+
249
+ if (name) {
250
+ this.name = name;
251
+ this.decode(buffer);
252
+ } else {
253
+ this.encode(buffer);
254
+ }
255
+ }
256
+
257
+ if (typeof buffer === 'string') {
258
+ if (isHex__default["default"](buffer)) this.fromHex(buffer);
259
+ if (bs32__default["default"].isBase32(buffer)) this.fromBs32(buffer);
260
+ else if (bs58__default["default"].isBase58(buffer)) this.fromBs58(buffer);
261
+ else throw new Error(`unsupported string ${buffer}`)
262
+ } else if (typeof buffer === 'object') this.fromJSON(buffer);
263
+ }
264
+ }
265
+
266
+ get prefix() {
267
+ const length = this.length;
268
+ const uint8Array = new Uint8Array(length.length + this.discoCodec.codecBuffer.length);
269
+ uint8Array.set(length);
270
+ uint8Array.set(this.discoCodec.codecBuffer, length.length);
271
+
272
+ return uint8Array
273
+ }
274
+
275
+ get length() {
276
+ return varint__default["default"].encode(this.size)
277
+ }
278
+
279
+ get buffer() {
280
+ return this.hash
281
+ }
282
+
283
+ toHex() {
284
+ return this.hash.toString('hex')
285
+ }
286
+
287
+ fromHex(hex) {
288
+ return this.decode(Buffer.from(hex, 'hex'))
289
+ }
290
+
291
+ fromJSON(json) {
292
+ return this.encode(Buffer.from(JSON.stringify(json)))
293
+ }
294
+
295
+ toBs32() {
296
+ return bs32__default["default"].encode(this.hash)
297
+ }
298
+
299
+ fromBs32(bs) {
300
+ return this.decode(bs32__default["default"].decode(bs))
301
+ }
302
+
303
+ toBs58() {
304
+ return bs58__default["default"].encode(this.hash)
305
+ }
306
+
307
+ fromBs58(bs) {
308
+ return this.decode(bs58__default["default"].decode(bs))
309
+ }
310
+
311
+ toString(encoding = 'utf8') {
312
+ return this.hash.toString(encoding)
313
+ }
314
+
315
+ encode(buffer, name) {
316
+ if (!this.name && name) this.name = name;
317
+ if (!buffer) buffer = this.buffer;
318
+ this.discoCodec = new PeernetCodec(this.name, this.codecs);
319
+ this.discoCodec.fromName(this.name);
320
+ let hashAlg = this.discoCodec.hashAlg;
321
+ if (hashAlg.includes('dbl')) {
322
+ hashAlg = hashAlg.replace('dbl-', '');
323
+ buffer = createKeccakHash__default["default"](hashAlg.replace('-', '')).update(buffer).digest();
324
+ }
325
+ this.digest = createKeccakHash__default["default"](hashAlg.replace('-', '')).update(buffer).digest();
326
+ this.size = this.digest.length;
327
+
328
+ this.codec = this.discoCodec.encode();
329
+ this.codec = this.discoCodec.codecBuffer;
330
+ const uint8Array = new Uint8Array(this.digest.length + this.prefix.length);
331
+ uint8Array.set(this.prefix);
332
+ uint8Array.set(this.digest, this.prefix.length);
333
+
334
+ this.hash = uint8Array;
335
+
336
+ return this.hash
337
+ }
338
+
339
+ validate(buffer) {
340
+ if (Buffer.isBuffer(buffer)) {
341
+ const codec = varint__default["default"].decode(buffer);
342
+ if (this.codecs[codec]) {
343
+ this.decode(buffer);
344
+ } else {
345
+ this.encode(buffer);
346
+ }
347
+ }
348
+ if (typeof buffer === 'string') {
349
+ if (isHex__default["default"](buffer)) this.fromHex(buffer);
350
+ if (bs32__default["default"].test(buffer)) this.fromBs32(buffer);
351
+ }
352
+ if (typeof buffer === 'object') this.fromJSON(buffer);
353
+ }
354
+
355
+ decode(buffer) {
356
+ this.hash = buffer;
357
+ const codec = varint__default["default"].decode(buffer);
358
+
359
+ this.discoCodec = new PeernetCodec(codec, this.codecs);
360
+ // TODO: validate codec
361
+ buffer = buffer.slice(varint__default["default"].decode.bytes);
362
+ this.size = varint__default["default"].decode(buffer);
363
+ this.digest = buffer.slice(varint__default["default"].decode.bytes);
364
+ if (this.digest.length !== this.size) {
365
+ throw new Error(`hash length inconsistent: 0x${this.hash.toString('hex')}`)
366
+ }
367
+
368
+ // const discoCodec = new Codec(codec, this.codecs)
369
+
370
+ this.name = this.discoCodec.name;
371
+
372
+
373
+ this.size = this.digest.length;
374
+
375
+ return {
376
+ codec: this.codec,
377
+ name: this.name,
378
+ size: this.size,
379
+ length: this.length,
380
+ digest: this.digest,
381
+ }
382
+ }
383
+ }
384
+
385
+ class FormatInterface {
386
+ /**
387
+ * @param {Buffer|String|Object} buffer - data - The data needed to create the desired message
388
+ * @param {Object} proto - {encode, decode}
389
+ * @param {Object} options - {hashFormat, name}
390
+ */
391
+ constructor(buffer, proto, options = {}) {
392
+ this.protoEncode = proto.encode;
393
+ this.protoDecode = proto.decode;
394
+ this.hashFormat = options.hashFormat || 'bs32';
395
+ if (options.name) this.name = options.name;
396
+ if (buffer instanceof Uint8Array) this.fromUint8Array(buffer);
397
+ else if (buffer instanceof ArrayBuffer) this.fromArrayBuffer(buffer);
398
+ else if (buffer.name === options.name) return buffer
399
+ else if (buffer instanceof String) {
400
+ if (isHex__default["default"](buffer)) this.fromHex(buffer);
401
+ else if (bs32__default["default"].isBase32(buffer)) this.fromBs32(buffer);
402
+ else if (bs58__default["default"].isBase58(buffer)) this.fromBs58(buffer);
403
+ else throw new Error(`unsupported string ${buffer}`)
404
+ } else {
405
+ this.create(buffer);
406
+ }
407
+ }
408
+
409
+ /**
410
+ * @return {PeernetHash}
411
+ */
412
+ get peernetHash() {
413
+ return new PeernetHash(this.decoded, {name: this.name})
414
+ }
415
+
416
+ /**
417
+ * @return {peernetHash}
418
+ */
419
+ get hash() {
420
+ const upper = this.hashFormat.charAt(0).toUpperCase();
421
+ const format = `${upper}${this.hashFormat.substring(1, this.hashFormat.length)}`;
422
+ return this.peernetHash[`to${format}`]()
423
+ }
424
+
425
+ /**
426
+ * @return {Object}
427
+ */
428
+ decode() {
429
+ let encoded = this.encoded;
430
+ const discoCodec = new PeernetCodec(this.encoded);
431
+ encoded = encoded.slice(discoCodec.codecBuffer.length);
432
+ this.name = discoCodec.name;
433
+ this.decoded = this.protoDecode(encoded);
434
+ return this.decoded
435
+ }
436
+
437
+ /**
438
+ * @return {Buffer}
439
+ */
440
+ encode(decoded) {
441
+ if (!decoded) decoded = this.decoded;
442
+ const codec = new PeernetCodec(this.name);
443
+ const encoded = this.protoEncode(decoded);
444
+ const uint8Array = new Uint8Array(encoded.length + codec.codecBuffer.length);
445
+ uint8Array.set(codec.codecBuffer);
446
+ uint8Array.set(encoded, codec.codecBuffer.length);
447
+ this.encoded = uint8Array;
448
+ return this.encoded
449
+ }
450
+
451
+ hasCodec() {
452
+ if (!this.encoded) return false
453
+ const codec = new PeernetCodec(this.encoded);
454
+ if (codec.name) return true
455
+ }
456
+
457
+ fromUint8Array(buffer) {
458
+ this.encoded = buffer;
459
+ if (!this.hasCodec()) this.create(
460
+ JSON.parse(new TextDecoder().decode(this.encoded))
461
+ );
462
+ else this.decode();
463
+ }
464
+
465
+ fromArrayBuffer(buffer) {
466
+ this.encoded = new Uint8Array(buffer, buffer.byteOffset, buffer.byteLength);
467
+ if (!this.hasCodec()) this.create(
468
+ JSON.parse(new TextDecoder().decode(this.encoded))
469
+ );
470
+ else this.decode();
471
+ }
472
+
473
+ toString() {
474
+ return this.encoded.toString()
475
+ }
476
+
477
+ async toArray() {
478
+ const array = [];
479
+ for await (const value of this.encoded.values()) {
480
+ array.push(value);
481
+ }
482
+ return array
483
+ }
484
+
485
+ fromString(string) {
486
+ this.encoded = new Uint8Array(string.split(','));
487
+ this.decode();
488
+ }
489
+
490
+ fromArray(array) {
491
+ this.encoded = new Uint8Array([...array]);
492
+ this.decode();
493
+ }
494
+
495
+ /**
496
+ * @param {Buffer} encoded
497
+ */
498
+ fromEncoded(encoded) {
499
+ this.encoded = encoded;
500
+ this.decode();
501
+ }
502
+
503
+ /**
504
+ * @param {String} encoded
505
+ */
506
+ fromHex(encoded) {
507
+ this.encoded = Buffer.from(encoded, 'hex');
508
+ this.decode();
509
+ }
510
+
511
+ /**
512
+ * @param {String} encoded
513
+ */
514
+ fromBs32(encoded) {
515
+ this.encoded = bs32__default["default"].decode(encoded);
516
+ this.decode();
517
+ }
518
+
519
+ /**
520
+ * @param {String} encoded
521
+ */
522
+ fromBs58(encoded) {
523
+ this.encoded = bs58__default["default"].decode(encoded);
524
+ this.decode();
525
+ }
526
+
527
+ /**
528
+ * @return {String} encoded
529
+ */
530
+ toHex() {
531
+ if (!this.encoded) this.encode();
532
+ return this.encoded.toString('hex')
533
+ }
534
+
535
+ /**
536
+ * @return {String} encoded
537
+ */
538
+ toBs32() {
539
+ if (!this.encoded) this.encode();
540
+ return bs32__default["default"].encode(this.encoded)
541
+ }
542
+
543
+ /**
544
+ * @return {String} encoded
545
+ */
546
+ toBs58() {
547
+ if (!this.encoded) this.encode();
548
+ return bs58__default["default"].encode(this.encoded)
549
+ }
550
+
551
+ /**
552
+ * @param {Object} data
553
+ */
554
+ create(data) {
555
+ const decoded = {};
556
+ if (this.keys?.length > 0) {
557
+ for (const key of this.keys) {
558
+ Object.defineProperties(decoded, {
559
+ [key]: {
560
+ enumerable: true,
561
+ configurable: true,
562
+ set: (val) => value = data[key],
563
+ get: () => data[key]
564
+ }
565
+ });
566
+ }
567
+
568
+ this.decoded = decoded;
569
+ this.encode();
570
+ }
571
+ }
572
+ }
573
+
574
+ class ContractMessage$1 extends FormatInterface {
575
+ get keys() {
576
+ return ['creator', 'contract', 'constructorParameters']
577
+ }
578
+
579
+ constructor(buffer) {
580
+ super(buffer, protons__default["default"](proto$4).ContractMessage, {name: 'contract-message'});
581
+ }
582
+ }
583
+
584
+ var proto$3 = `
585
+
586
+ message TransactionMessage {
587
+ required uint64 timestamp = 1;
588
+ required string from = 2;
589
+ required string to = 3;
590
+ required uint64 nonce = 4;
591
+ required string method = 5;
592
+ repeated string params = 6;
593
+ }
594
+ `;
595
+
596
+ class TransactionMessage$1 extends FormatInterface {
597
+ get keys() {
598
+ return ['timestamp', 'from', 'to', 'nonce', 'method', 'params']
599
+ }
600
+
601
+ constructor(buffer) {
602
+ const name = 'transaction-message';
603
+ super(buffer, protons__default["default"](proto$3).TransactionMessage, {name});
604
+ }
605
+ }
606
+
607
+ var proto$2 = `
608
+ message ValidatorMessage {
609
+ required string address = 1;
610
+ required string reward = 2;
611
+ }
612
+
613
+ message Transaction {
614
+ required string hash = 1;
615
+ required uint64 timestamp = 2;
616
+ required string from = 3;
617
+ required string to = 4;
618
+ required uint64 nonce = 5;
619
+ required string method = 6;
620
+ repeated string params = 7;
621
+ }
622
+
623
+ message BlockMessage {
624
+ required uint64 index = 1;
625
+ required string previousHash = 3;
626
+ required uint64 timestamp = 4;
627
+ required uint64 reward = 5;
628
+ required string fees = 6;
629
+ repeated Transaction transactions = 7;
630
+ repeated ValidatorMessage validators = 8;
631
+ }
632
+ `;
633
+
634
+ class BlockMessage$1 extends FormatInterface {
635
+ get keys() {
636
+ return ['index', 'previousHash', 'timestamp', 'reward', 'fees', 'transactions', 'validators']
637
+ }
638
+
639
+ constructor(buffer) {
640
+ const name = 'block-message';
641
+ super(buffer, protons__default["default"](proto$2).BlockMessage, {name});
642
+ }
643
+ }
644
+
645
+ var proto$1 = `
646
+
647
+ message BWMessage {
648
+ required uint64 up = 1;
649
+ required uint64 down = 2;
650
+ }
651
+ `;
652
+
653
+ class BWMessage$1 extends FormatInterface {
654
+ get keys() {
655
+ return ['up', 'down']
656
+ }
657
+
658
+ constructor(buffer) {
659
+ const name = 'bw-message';
660
+ super(buffer, protons__default["default"](proto$1).BWMessage, {name});
661
+ }
662
+ }
663
+
664
+ var proto = `
665
+
666
+ message BWRequestMessage {
667
+ }
668
+ `;
669
+
670
+ class BWRequestMessage$1 extends FormatInterface {
671
+ get keys() {
672
+ return []
673
+ }
674
+
675
+ constructor(buffer) {
676
+ const name = 'bw-request-message';
677
+ super(buffer, protons__default["default"](proto).BWRequestMessage, {name});
678
+ }
679
+ }
680
+
681
+ var contractFactory$2 = "237,198,1,10,54,51,67,122,86,52,88,98,115,81,54,72,57,100,75,49,76,101,105,66,75,65,120,114,54,81,105,77,71,53,116,68,105,55,122,77,77,72,118,117,120,104,121,50,101,118,70,101,118,72,49,77,85,76,99,18,146,8,114,101,116,117,114,110,32,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,118,97,108,105,100,40,104,97,115,104,44,99,114,101,97,116,111,114,44,99,111,110,116,114,97,99,116,44,99,111,110,115,116,114,117,99,116,111,114,80,97,114,97,109,101,116,101,114,115,61,91,93,41,123,99,111,110,115,116,32,109,101,115,115,97,103,101,61,110,101,119,32,67,111,110,116,114,97,99,116,77,101,115,115,97,103,101,40,123,99,114,101,97,116,111,114,58,99,114,101,97,116,111,114,44,99,111,110,116,114,97,99,116,58,99,111,110,116,114,97,99,116,44,99,111,110,115,116,114,117,99,116,111,114,80,97,114,97,109,101,116,101,114,115,58,99,111,110,115,116,114,117,99,116,111,114,80,97,114,97,109,101,116,101,114,115,125,41,59,114,101,116,117,114,110,32,66,111,111,108,101,97,110,40,109,101,115,115,97,103,101,46,104,97,115,104,61,61,61,104,97,115,104,41,125,97,115,121,110,99,32,100,101,112,108,111,121,67,111,110,116,114,97,99,116,40,99,111,110,116,114,97,99,116,72,97,115,104,44,99,114,101,97,116,111,114,44,99,111,110,116,114,97,99,116,44,99,111,110,115,116,114,117,99,116,111,114,80,97,114,97,109,101,116,101,114,115,61,91,93,41,123,105,102,40,99,111,110,116,114,97,99,116,46,99,114,101,97,116,111,114,33,61,61,109,115,103,46,115,101,110,100,101,114,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,111,110,108,121,32,97,32,99,111,110,116,114,97,99,116,32,99,114,101,97,116,111,114,32,99,97,110,32,100,101,112,108,111,121,32,97,32,99,111,110,116,114,97,99,116,34,41,59,105,102,40,97,119,97,105,116,32,99,111,110,116,114,97,99,116,83,116,111,114,101,46,104,97,115,40,104,97,115,104,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,100,117,112,108,105,99,97,116,101,32,99,111,110,116,114,97,99,116,34,41,59,105,102,40,33,116,104,105,115,46,105,115,86,97,108,105,100,40,99,111,110,116,114,97,99,116,72,97,115,104,44,99,114,101,97,116,111,114,44,99,111,110,116,114,97,99,116,44,99,111,110,115,116,114,117,99,116,111,114,80,97,114,97,109,101,116,101,114,115,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,105,110,118,97,108,105,100,32,99,111,110,116,114,97,99,116,34,41,59,97,119,97,105,116,32,99,111,110,116,114,97,99,116,83,116,111,114,101,46,112,117,116,40,104,97,115,104,44,101,110,99,111,100,101,100,41,44,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,104,97,115,104,41,125,125,59,10";
682
+ var nativeToken$2 = "237,198,1,10,54,51,67,122,86,52,88,98,115,81,54,72,57,100,75,49,76,101,105,66,75,65,120,114,54,81,105,77,71,53,116,68,105,55,122,77,77,72,118,117,120,104,121,50,101,118,70,101,118,72,49,77,85,76,99,18,152,26,114,101,116,117,114,110,32,99,108,97,115,115,32,65,114,116,79,110,108,105,110,101,32,101,120,116,101,110,100,115,32,99,108,97,115,115,32,84,111,107,101,110,32,101,120,116,101,110,100,115,32,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,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,45,49,33,61,61,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,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,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,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,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,116,111,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,103,108,111,98,97,108,84,104,105,115,46,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,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,59,10";
683
+ var nameService$2 = "237,198,1,10,54,51,67,122,86,52,88,98,115,81,54,72,57,100,75,49,76,101,105,66,75,65,120,114,54,81,105,77,71,53,116,68,105,55,122,77,77,72,118,117,120,104,121,50,101,118,70,101,118,72,49,77,85,76,99,18,138,12,114,101,116,117,114,110,32,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,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,41,123,116,104,114,111,119,32,101,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,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,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,59,10,26,58,98,97,53,120,100,97,100,115,54,118,99,106,105,119,118,102,51,52,110,112,122,104,54,120,114,108,97,105,118,112,106,103,116,112,51,109,105,116,51,104,119,104,120,101,117,109,121,98,119,115,112,106,114,104,101,122,51,101,26,58,98,97,53,120,100,97,100,102,109,98,54,102,119,52,50,106,50,112,97,122,55,51,52,112,117,98,122,119,120,110,55,114,103,105,119,119,109,103,115,51,100,99,105,99,114,52,117,50,101,107,104,113,101,118,113,118,99,117,26,58,98,97,53,120,100,97,99,55,107,118,121,51,99,106,107,97,52,97,101,120,55,98,122,55,119,54,114,121,113,120,103,102,98,109,119,115,116,111,109,115,101,121,111,110,121,116,98,115,115,108,55,115,108,101,114,105,117,100,26,4,49,48,48,48";
684
+ var validators$2 = "237,198,1,10,54,51,67,122,86,52,88,98,115,81,54,72,57,100,75,49,76,101,105,66,75,65,120,114,54,81,105,77,71,53,116,68,105,55,122,77,77,72,118,117,120,104,121,50,101,118,70,101,118,72,49,77,85,76,99,18,215,16,114,101,116,117,114,110,32,99,108,97,115,115,32,86,97,108,105,100,97,116,111,114,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,118,97,108,105,100,97,116,111,114,115,61,123,125,59,35,111,119,110,101,114,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,111,119,110,101,114,58,116,104,105,115,46,35,111,119,110,101,114,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,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,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,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,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,111,119,110,101,114,61,109,115,103,46,115,101,110,100,101,114,44,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,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,40,110,101,119,32,68,97,116,101,41,46,103,101,116,84,105,109,101,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,111,119,110,101,114,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,111,119,110,101,114,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,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,116,32,97,110,32,111,119,110,101,114,34,41,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,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,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,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,109,115,103,46,115,101,110,100,101,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,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,40,110,101,119,32,68,97,116,101,41,46,103,101,116,84,105,109,101,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,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,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,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,109,115,103,46,115,101,110,100,101,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,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,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,33,49,41,44,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,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,59,10,26,58,98,97,53,120,100,97,100,102,109,98,54,102,119,52,50,106,50,112,97,122,55,51,52,112,117,98,122,119,120,110,55,114,103,105,119,119,109,103,115,51,100,99,105,99,114,52,117,50,101,107,104,113,101,118,113,118,99,117";
685
+ var bytecodes = {
686
+ contractFactory: contractFactory$2,
687
+ nativeToken: nativeToken$2,
688
+ nameService: nameService$2,
689
+ validators: validators$2
690
+ };
691
+
692
+ var contractFactory$1 = "ba5xdads6vcjiwvf34npzh6xrlaivpjgtp3mit3hwhxeumybwspjrhez3e";
693
+ var nativeToken$1 = "ba5xdadfmb6fw42j2paz734pubzwxn7rgiwwmgs3dcicr4u2ekhqevqvcu";
694
+ var nameService$1 = "ba5xdadsx73i3tkuk6q5bz4mm5zcgqipha3szmuixgit46albm2inuarp6";
695
+ var validators$1 = "ba5xdac7kvy3cjka4aex7bz7w6ryqxgfbmwstomseyonytbssl7sleriud";
696
+ var addresses = {
697
+ contractFactory: contractFactory$1,
698
+ nativeToken: nativeToken$1,
699
+ nameService: nameService$1,
700
+ validators: validators$1
701
+ };
702
+
703
+ const { contractFactory, nativeToken, nameService, validators } = addresses;
704
+
705
+ const contractFactoryMessage = new Uint8Array(bytecodes.contractFactory.split(','));
706
+ const nativeTokenMessage = new Uint8Array(bytecodes.nativeToken.split(','));
707
+
708
+ const nameServiceMessage = new Uint8Array(bytecodes.nameService.split(','));
709
+ const validatorsMessage = new Uint8Array(bytecodes.validators.split(','));
710
+
711
+ const calculateFee = transaction => {
712
+ // excluded from fees
713
+ if (transaction.decoded.to === validators) return 0
714
+ // fee per gb
715
+ let fee = transaction.encoded.length;
716
+ fee = fee / 1024;
717
+ fee = fee / 1000000;
718
+ const parts = String(fee).split('.');
719
+ let decimals = 0;
720
+ if (parts[1]) {
721
+ const potentional = parts[1].split('e');
722
+ parts[1] = potentional[0];
723
+ decimals = Number(potentional[1].replace(/\-|\+/g, '')) + Number(potentional[0].length);
724
+ }
725
+
726
+ return Number.parseFloat(fee.toString()).toFixed(decimals)
727
+ };
728
+
729
+ const calculateTransactionFee = transaction => {
730
+ transaction = new TransactionMessage$1(transaction);
731
+ return calculateFee(transaction)
732
+ };
733
+
734
+ var lib = {
735
+ nativeToken,
736
+ nameService,
737
+ contractFactory,
738
+ validators,
739
+ contractFactoryMessage,
740
+ nativeTokenMessage,
741
+ nameServiceMessage,
742
+ validatorsMessage,
743
+ TransactionMessage: TransactionMessage$1,
744
+ ContractMessage: ContractMessage$1,
745
+ BlockMessage: BlockMessage$1,
746
+ BWMessage: BWMessage$1,
747
+ BWRequestMessage: BWRequestMessage$1,
748
+ calculateFee,
749
+ calculateTransactionFee
750
+ };
751
+
752
+ // import State from './state'
753
+
754
+ class Machine {
755
+ #contracts = {}
756
+ #nonces = {}
757
+ constructor() {
758
+ return this.#init()
759
+ }
760
+
761
+ #createMessage(sender = peernet.id) {
762
+ return {
763
+ sender,
764
+ call: this.execute,
765
+ staticCall: this.get.bind(this)
766
+ }
767
+ }
768
+
769
+ async #init() {
770
+ // return
771
+ try {
772
+ let contracts = [
773
+ contractStore.get(lib.contractFactory),
774
+ contractStore.get(lib.nativeToken),
775
+ contractStore.get(lib.validators),
776
+ contractStore.get(lib.nameService)
777
+ ];
778
+
779
+ contracts = await Promise.all(contracts);
780
+ for (const contract of contracts) {
781
+ const message = new ContractMessage$1(new Uint8Array(contract.buffer, contract.buffer.byteOffset, contract.buffer.byteLength));
782
+ await this.#runContract(message);
783
+ }
784
+ } catch (e) {
785
+ console.log(e);
786
+ }
787
+ // const transactions = await transactionStore.get()
788
+ // console.log({transactions});
789
+ // for (const key of Object.keys(transactions)) {
790
+ // const message = new TransactionMessage(transactions[key])
791
+ // console.log({message});
792
+ // const {from, to, method, params} = message.decoded
793
+ // globalThis.msg = this.#createMessage(from)
794
+ //
795
+ // console.log({from, to, method, params});
796
+ // await this.execute(to, method, params)
797
+ // }
798
+ return this
799
+ }
800
+
801
+ async #runContract(contractMessage) {
802
+ const params = contractMessage.decoded.constructorParameters;
803
+ try {
804
+
805
+ const func = new Function(new TextDecoder().decode(contractMessage.decoded.contract));
806
+ const Contract = func();
807
+
808
+ globalThis.msg = this.#createMessage(contractMessage.decoded.creator);
809
+ // globalThis.msg = {sender: contractMessage.decoded.creator}
810
+ this.#contracts[contractMessage.hash] = new Contract(...params);
811
+ info(`loaded contract: ${contractMessage.hash}`);
812
+ subinfo(`size: ${Math.round((contractMessage.encoded.length / 1024) * 100) / 100} kb`);
813
+ } catch (e) {
814
+ console.log(e);
815
+ console.warn(`removing contract ${contractMessage.hash}`);
816
+ await contractStore.delete(contractMessage.hash, contractMessage.encoded);
817
+ }
818
+ }
819
+
820
+ /**
821
+ * @params {ContractMessage} - contractMessage
822
+ */
823
+ async addContract(contractMessage) {
824
+ if (!await contractStore.has(contractMessage.hash)) {
825
+ await contractStore.put(contractMessage.hash, contractMessage.encoded);
826
+ await this.#runContract(contractMessage);
827
+ return contractMessage.hash
828
+ }
829
+ throw new Error('duplicate contract')
830
+ }
831
+
832
+ async execute(contract, method, params) {
833
+ try {
834
+ let result;
835
+ // don't execute the method on a proxy
836
+ if (this.#contracts[contract].fallback) {
837
+ result = this.#contracts[contract].fallback(method, params);
838
+ } else {
839
+ result = await this.#contracts[contract][method](...params);
840
+ }
841
+
842
+ // this.#state.put(result)
843
+ return result
844
+ } catch (e) {
845
+ throw e
846
+ }
847
+ }
848
+
849
+ addJob(contract, method, params, from, nonce) {
850
+ if (!this.#nonces[from]) this.#nonces[from] = nonce;
851
+ if (nonce === this.#nonces[from] + 1) return this.#contracts[contract][method](...params)
852
+ // return setTimeout(() => {
853
+ // return this.addJob(contract, method, params, from, nonce)
854
+ // }, 50)
855
+ }
856
+
857
+ get(contract, method, params) {
858
+ let result;
859
+ if (params?.length > 0) {
860
+ result = this.#contracts[contract][method](...params);
861
+ } else {
862
+ result = this.#contracts[contract][method];
863
+ }
864
+ return result
865
+ }
866
+
867
+ async delete(hash) {
868
+ return contractStore.delete(hash)
869
+ }
870
+
871
+ async deleteAll() {
872
+ let hashes = await contractStore.get();
873
+ hashes = Object.keys(hashes).map(hash => this.delete(hash));
874
+ return Promise.all(hashes)
875
+ }
876
+ }
877
+
878
+ globalThis.BigNumber = bignumber.BigNumber;
879
+
880
+ const { ContractMessage, TransactionMessage, BlockMessage, BWMessage, BWRequestMessage } = lib;
881
+ // check if browser or local
882
+ class Chain {
883
+ #validators = []
884
+ #blocks = []
885
+ #machine
886
+ #runningEpoch = false
887
+ #lastBlock = {index: 0, previousHash: '0x0'}
888
+
889
+ constructor() {
890
+ return this.#init()
891
+ }
892
+
893
+ get lib() {
894
+ return lib
895
+ }
896
+
897
+ get lastBlock() {
898
+ return this.#lastBlock
899
+ }
900
+
901
+ get nativeToken() {
902
+ return lib.nativeToken
903
+ }
904
+
905
+ get validators() {
906
+ return [...this.#validators]
907
+ }
908
+
909
+ get blocks() {
910
+ return [...this.#blocks]
911
+ }
912
+
913
+ async hasTransactionToHandle() {
914
+ const size = await transactionPoolStore.size();
915
+ if (size > 0) return true
916
+ return false
917
+ }
918
+
919
+ async #runEpoch() {
920
+ const validators = await this.staticCall(lib.validators, 'validators');
921
+ if (!validators[peernet.id]?.active) return
922
+
923
+ this.#runningEpoch = true;
924
+ const start = new Date().getTime();
925
+ await this.#createBlock();
926
+ const end = new Date().getTime();
927
+ console.log((end - start) / 1000 + ' s');
928
+ if (await this.hasTransactionToHandle()) return this.#runEpoch()
929
+ this.#runningEpoch = false;
930
+ }
931
+
932
+ async #setup() {
933
+ await contractStore.put(lib.contractFactory, lib.contractFactoryMessage);
934
+ await contractStore.put(lib.nativeToken, lib.nativeTokenMessage);
935
+ await contractStore.put(lib.validators, lib.validatorsMessage);
936
+ await contractStore.put(lib.nameService, lib.nameServiceMessage);
937
+ console.log('handle native contracts');
938
+ // handle native contracts
939
+ }
940
+
941
+ async #sync() {
942
+ let promises = [];
943
+ for (const peer of peernet.connections) {
944
+ if (peer.peerId !== this.id) {
945
+ let data = new peernet.protos['peernet-request']({request: 'lastBlock'});
946
+
947
+ const node = await peernet.prepareMessage(id, data.encoded);
948
+ promises.push(peer.request(node.encoded));
949
+ }
950
+ }
951
+ // if (this.)
952
+
953
+ promises = await Promise.allSettled(promises);
954
+ promises = promises.reduce((set, c) => {
955
+ console.log({c});
956
+ if (c.index > set.index) {
957
+ set.index = c.index;
958
+ set.hash = c.hash;
959
+ }
960
+ return set
961
+ }, {index: 0, hash: '0x0'});
962
+ // get lastblock
963
+ }
964
+
965
+ async #init() {
966
+ // this.node = await new Node()
967
+ this.participants = [];
968
+ const initialized = await contractStore.has(lib.contractFactory);
969
+ if (!initialized) await this.#setup();
970
+
971
+ this.#machine = await new Machine();
972
+ this.utils = { BigNumber: bignumber.BigNumber, formatUnits: units.formatUnits, parseUnits: units.parseUnits };
973
+
974
+ try {
975
+ let localBlock = await chainStore.get('lastBlock');
976
+ localBlock = await peernet.get(new TextDecoder().decode(localBlock));
977
+ localBlock = new BlockMessage(localBlock);
978
+ this.#lastBlock = {...localBlock.decoded, hash: localBlock.hash};
979
+ // console.log(this.lastBlock.decoded.transactions);
980
+ } catch (e) {
981
+ await this.#sync();
982
+ // this.#setup()
983
+ }
984
+
985
+ await peernet.addRequestHandler('bw-request-message', () => {
986
+
987
+ return new BWMessage(peernet.client.bw) || { up: 0, down: 0 }
988
+ });
989
+
990
+ await peernet.addRequestHandler('lastBlock', this.#lastBlockHandler.bind(this));
991
+
992
+ peernet.subscribe('add-block', this.#addBlock.bind(this));
993
+
994
+ peernet.subscribe('add-transaction', async transaction => {
995
+ try {
996
+ transaction = new TransactionMessage(transaction);
997
+ await transactionPoolStore.put(transaction.hash, transaction.encoded);
998
+ if (await this.hasTransactionToHandle() && !this.#runningEpoch) return this.#runEpoch()
999
+ } catch (e) {
1000
+ throw Error('invalid transaction')
1001
+ }
1002
+ });
1003
+
1004
+ pubsub.subscribe('peer:connected', this.#peerConnected.bind(this));
1005
+
1006
+ // load local blocks
1007
+ await this.resolveBlocks();
1008
+ return this
1009
+ }
1010
+
1011
+ async #peerConnected(peer) {
1012
+ let node = new peernet.protos['peernet-request']({request: 'lastBlock'});
1013
+ node = await peernet.prepareMessage(peer.id, node.encoded);
1014
+ let response = await peer.request(node.encoded);
1015
+ response = new Uint8Array(Object.values(response));
1016
+ const proto = new globalThis.peernet.protos['peernet-message'](response);
1017
+ response = new globalThis.peernet.protos['peernet-response'](proto.decoded.data);
1018
+ let lastBlock = JSON.parse(new TextDecoder().decode(response.decoded.response));
1019
+
1020
+ if (!this.lastBlock || this.lastBlock.index < lastBlock.index) {
1021
+ // TODO: check if valid
1022
+ const localIndex = this.lastBlock ? this.lastBlock.index : 0;
1023
+ const index = lastBlock.index;
1024
+ await this.resolveBlock(lastBlock.hash);
1025
+ this.#lastBlock = this.#blocks[this.#blocks.length - 1];
1026
+ console.log({lastBlock: this.#lastBlock});
1027
+ console.log(this.#blocks);
1028
+ let blocksSynced = localIndex > 0 ? localIndex - index : index;
1029
+ blocksSynced += 1;
1030
+ info(`synced ${blocksSynced} ${blocksSynced > 1 ? 'blocks' : 'block'}`);
1031
+
1032
+ this.#blocks.length;
1033
+ (this.#blocks.length) - blocksSynced;
1034
+ await this.#loadBlocks(this.#blocks);
1035
+ const message = new BlockMessage(this.lastBlock);
1036
+ await blockStore.put(message.hash, message.encoded);
1037
+ await chainStore.put('lastBlock', new TextEncoder().encode(this.lastBlock.hash));
1038
+ }
1039
+ }
1040
+
1041
+ async #lastBlockHandler() {
1042
+ return new peernet.protos['peernet-response']({response: new TextEncoder().encode(JSON.stringify({ hash: this.lastBlock?.hash, index: this.lastBlock?.index }))})
1043
+ }
1044
+
1045
+ async resolveBlock(hash) {
1046
+ let block = await peernet.get(hash, 'block');
1047
+ if (!await peernet.has(hash, 'block')) await peernet.put(hash, block, 'block');
1048
+ block = await new BlockMessage(block);
1049
+ const size = block.encoded.length || block.encoded.byteLength;
1050
+ block = {...block.decoded, hash};
1051
+ this.#blocks[block.index] = block;
1052
+ console.log(`loaded block: ${hash} @${block.index} ${Math.round((size / 1024 / 1024) * 100) / 100} mb`);
1053
+ if (block.index !== 0) {
1054
+ return this.resolveBlock(block.previousHash)
1055
+ }
1056
+ }
1057
+
1058
+ async resolveBlocks() {
1059
+ try {
1060
+
1061
+ const localBlock = await chainStore.get('lastBlock');
1062
+ const hash = new TextDecoder().decode(localBlock);
1063
+ if (hash !== '0x0')
1064
+ await this.resolveBlock(new TextDecoder().decode(localBlock));
1065
+ this.#lastBlock = this.#blocks[this.#blocks.length - 1];
1066
+ await this.#loadBlocks(this.#blocks);
1067
+ } catch (e) {
1068
+ await chainStore.put('lastBlock', new TextEncoder().encode('0x0'));
1069
+ return this.resolveBlocks()
1070
+ // console.log(e);
1071
+ }
1072
+ }
1073
+
1074
+ async #loadBlocks(blocks) {
1075
+ for (const block of blocks) {
1076
+ if (!block.loaded) {
1077
+ for (const transaction of block.transactions) {
1078
+ try {
1079
+ await this.#machine.execute(transaction.to, transaction.method, transaction.params);
1080
+
1081
+ } catch (e) {
1082
+ console.log(e);
1083
+ }
1084
+ }
1085
+ block.loaded = true;
1086
+ // let message = await peernet.get(block.hash, 'block')
1087
+
1088
+ // const compressed = pako.deflate(message);
1089
+ // const result = pako.inflate(compressed);
1090
+ // console.log(result.length, compressed.length);
1091
+ //
1092
+ // console.log(result.length - compressed.length);
1093
+
1094
+ // message = new BlockMessage(message)
1095
+ // for (const transaction of message.decoded.transactions) {
1096
+ // try {
1097
+ // await this.#machine.execute(transaction.to, transaction.method, transaction.params)
1098
+ //
1099
+ // } catch (e) {
1100
+ // // console.log(e);
1101
+ // }
1102
+ // }
1103
+ // block.loaded = true
1104
+ }
1105
+ }
1106
+ }
1107
+
1108
+ async #executeTransaction({hash, from, to, method, params, nonce}) {
1109
+ try {
1110
+ let result = await this.#machine.execute(to, method, params, from, nonce);
1111
+ // if (!result) result = this.#machine.state
1112
+ pubsub.publish(`transaction.completed.${hash}`, {status: 'fulfilled', hash});
1113
+ return result ? result : 'no state change'
1114
+ } catch (e) {
1115
+ pubsub.publish(`transaction.completed.${hash}`, {status: 'fail', hash, error: e});
1116
+ throw e
1117
+ }
1118
+ }
1119
+
1120
+ async #addBlock(block) {
1121
+ const blockMessage = new BlockMessage(block);
1122
+ // if (!Buffer.isBuffer(block)) block = Buffer.from(block, 'hex')
1123
+ // const transactionJob = async transaction => {
1124
+ // try {
1125
+ // transaction = await transactionPoolStore.get(transaction)
1126
+ // } catch (e) {
1127
+ // try {
1128
+ // transaction = await peernet.get(transaction, 'transaction')
1129
+ // } catch (e) {
1130
+ // console.warn(`couldn't resolve ${transaction}`);
1131
+ // }
1132
+ // }
1133
+ // transaction = new TransactionMessage(transaction)
1134
+ // return transaction
1135
+ // }
1136
+ await Promise.all(blockMessage.decoded.transactions
1137
+ .map(transaction => transactionPoolStore.delete(transaction.hash)));
1138
+
1139
+ // let transactions = blockMessage.decoded.transactions.map(tx => transactionJob(tx))
1140
+ // transactions = await Promise.all(transactions)
1141
+ this.#lastBlock = {hash: blockMessage.hash, ...blockMessage.decoded};
1142
+ await blockStore.put(blockMessage.hash, blockMessage.encoded);
1143
+ await chainStore.put('lastBlock', new TextEncoder().encode(blockMessage.hash));
1144
+ info(`added block: ${blockMessage.hash}`);
1145
+ let promises = [];
1146
+ let contracts = [];
1147
+ for (let transaction of blockMessage.decoded.transactions) {
1148
+ // await transactionStore.put(transaction.hash, transaction.encoded)
1149
+ const index = contracts.indexOf(transaction.to);
1150
+ if (index === -1) contracts.push(transaction.to);
1151
+ promises.push(this.#executeTransaction(transaction));
1152
+ }
1153
+ try {
1154
+ promises = await Promise.allSettled(promises);
1155
+
1156
+ // todo finish state
1157
+ for (const contract of contracts) {
1158
+ const state = await this.#machine.get(contract, 'state');
1159
+ // await stateStore.put(contract, state)
1160
+ console.log(state);
1161
+ }
1162
+ } catch (e) {
1163
+ console.log(e);
1164
+ }
1165
+
1166
+ }
1167
+
1168
+
1169
+
1170
+ async participate() {
1171
+ // TODO: validate participant
1172
+ // hold min amount of 50k ART for 7 days
1173
+ // lock the 50k
1174
+ // introduce peer-reputation
1175
+ // peerReputation(peerId)
1176
+ // {bandwith: {up, down}, uptime}
1177
+ if (!await this.staticCall(lib.validators, 'has', [peernet.id])) await this.createTransactionFrom(peernet.id, lib.validators, 'addValidator', [peernet.id]);
1178
+ if (await this.hasTransactionToHandle() && !this.#runningEpoch) return this.#runEpoch()
1179
+ }
1180
+
1181
+ calculateFee(transaction) {
1182
+ // excluded from fees
1183
+ if (transaction.decoded.to === lib.validators) return 0
1184
+ // fee per gb
1185
+ return (transaction.encoded.length / 1024) / 1e-6
1186
+ }
1187
+
1188
+ async #createBlock() {
1189
+ let transactions = await transactionPoolStore.get();
1190
+
1191
+ if (Object.keys(transactions)?.length === 0 ) return
1192
+ let block = {
1193
+ transactions: [],
1194
+ validators: [],
1195
+ fees: 0
1196
+ };
1197
+
1198
+ let _transactions = [];
1199
+
1200
+ // exclude failing tx
1201
+ for (let transaction of Object.values(transactions)) {
1202
+ transaction = new TransactionMessage(new Uint8Array(transaction, transaction.byteOffset, transaction.byteLength));
1203
+
1204
+ block.fees += Number(lib.calculateFee(transaction));
1205
+ _transactions.push({...transaction.decoded, hash: transaction.hash });
1206
+ }
1207
+
1208
+ transactions = _transactions.sort((a, b) => a.nonce - b.nonce);
1209
+ _transactions = [];
1210
+ for (let transaction of transactions) {
1211
+ try {
1212
+ await this.#executeTransaction(transaction);
1213
+ _transactions.push(transaction);
1214
+ } catch (e) {
1215
+ transaction = new TransactionMessage(transaction);
1216
+ block.fees -= Number(lib.calculateFee(transaction));
1217
+ await transactionPoolStore.delete(transaction.hash);
1218
+
1219
+ }
1220
+ }
1221
+ transactions = _transactions;
1222
+ // don't add empty block
1223
+ if (transactions.length === 0) return
1224
+
1225
+ block.transactions = transactions;
1226
+ const validators = await this.staticCall(lib.validators, 'validators');
1227
+ console.log({validators});
1228
+ // block.validators = Object.keys(block.validators).reduce((set, key) => {
1229
+ // if (block.validators[key].active) {
1230
+ // push({
1231
+ // address: key
1232
+ // })
1233
+ // }
1234
+ // }, [])
1235
+ const peers = {};
1236
+ for (const entry of peernet.peerEntries) {
1237
+ peers[entry[0]] = entry[1];
1238
+ }
1239
+ for (const validator of Object.keys(validators)) {
1240
+ if (validators[validator].active) {
1241
+ const peer = peers[validator];
1242
+ if (peer && peer.connected) {
1243
+ let data = new BWRequestMessage();
1244
+ const node = await peernet.prepareMessage(validator, data.encoded);
1245
+ try {
1246
+ const bw = await peer.request(node.encoded);
1247
+ console.log(bw);
1248
+ block.validators.push({
1249
+ address: validator,
1250
+ bw: bw.up + bw.down
1251
+ });
1252
+ } catch(e) {
1253
+
1254
+ }
1255
+
1256
+ } else if (peernet.id === validator) {
1257
+ block.validators.push({
1258
+ address: peernet.id,
1259
+ bw: peernet.bw.up + peernet.bw.down
1260
+ });
1261
+
1262
+ }
1263
+ }
1264
+
1265
+ }
1266
+
1267
+ console.log(block.validators);
1268
+
1269
+ block.reward = 150;
1270
+ block.validators = block.validators.map(validator => {
1271
+ validator.reward = String(Number(block.fees) + block.reward / block.validators.length);
1272
+ delete validator.bw;
1273
+ return validator
1274
+ });
1275
+ // block.validators = lib.calculateValidatorReward(block.validators, block.fees)
1276
+
1277
+ block.index = this.lastBlock?.index;
1278
+ if (block.index === undefined) block.index = 0;
1279
+ else block.index += 1;
1280
+
1281
+ block.previousHash = this.lastBlock?.hash || '0x0';
1282
+ block.timestamp = new Date().getTime();
1283
+
1284
+ const parts = String(block.fees).split('.');
1285
+ let decimals = 0;
1286
+ if (parts[1]) {
1287
+ const potentional = parts[1].split('e');
1288
+ if (potentional[0] !== parts[1]) {
1289
+ parts[1] = potentional[0];
1290
+ decimals = Number(potentional[1]?.replace(/\-|\+/g, '')) + Number(potentional[0].length);
1291
+ } else {
1292
+ decimals = parts[1].length;
1293
+ }
1294
+
1295
+ }
1296
+ block.fees = Number.parseFloat(String(block.fees)).toFixed(decimals);
1297
+
1298
+ try {
1299
+ let blockMessage = new BlockMessage(block);
1300
+ this.#lastBlock = {...block, hash: blockMessage.hash};
1301
+ peernet.publish('add-block', blockMessage.encoded);
1302
+ this.#addBlock(blockMessage.encoded);
1303
+ } catch (e) {
1304
+ throw Error(`invalid block ${block}`)
1305
+ }
1306
+ // data = await this.#machine.execute(to, method, params)
1307
+ // transactionStore.put(message.hash, message.encoded)
1308
+ }
1309
+
1310
+ async getNonce(address) {
1311
+ let transactions = await transactionPoolStore.get();
1312
+ transactions = Object.keys(transactions).map(tx => new TransactionMessage(transactions[tx]));
1313
+ transactions = transactions.filter(tx => tx.decoded.from === address);
1314
+ transactions = transactions.map(tx => { return {...tx.decoded, hash: tx.hash} });
1315
+ if (this.lastBlock && transactions.length === 0) {
1316
+ let block = await peernet.get(this.lastBlock.hash);
1317
+ block = new BlockMessage(block);
1318
+
1319
+ // for (let tx of block.decoded?.transactions) {
1320
+ // tx = await peernet.get(tx, 'transaction')
1321
+ // transactions.push(new TransactionMessage(tx))
1322
+ // }
1323
+ transactions = transactions.filter(tx => tx.from === address);
1324
+ while (transactions.length === 0 && block.decoded.index !== 0) {
1325
+ block = await blockStore.get(block.decoded.previousHash);
1326
+ block = new BlockMessage(block);
1327
+ transactions = block.decoded.transactions.filter(tx => tx.from === address);
1328
+ }
1329
+
1330
+ }
1331
+ if (transactions.length === 0) return 0
1332
+
1333
+ transactions = transactions.sort((a, b) => a.timestamp - b.timestamp);
1334
+ return transactions[transactions.length - 1].nonce
1335
+ }
1336
+
1337
+ /**
1338
+ * whenever method = createContract params should hold the contract hash
1339
+ *
1340
+ * example: [hash]
1341
+ * createTransaction('0x0', 'createContract', [hash])
1342
+ */
1343
+ createTransaction(to, method, params, nonce) {
1344
+ return this.createTransactionFrom(peernet.id, to, method, params, nonce)
1345
+ }
1346
+ /**
1347
+ * every tx done is trough contracts so no need for amount
1348
+ * data is undefined when nothing is returned
1349
+ * error is thrown on error so undefined data doesn't mean there is an error...
1350
+ */
1351
+ async createTransactionFrom(from, to, method, params, nonce) {
1352
+ if (nonce === undefined) {
1353
+ nonce = await this.getNonce(from);
1354
+ nonce += 1;
1355
+ }
1356
+
1357
+ let data;
1358
+ let message = new TransactionMessage({timestamp: new Date().getTime(), from, to, nonce, method, params});
1359
+ try {
1360
+ // await transactionPoolStore.put(message.hash, new TextEncoder().encode(JSON.stringify({signature, message: message.encoded})))
1361
+ await transactionPoolStore.put(message.hash, message.encoded);
1362
+ peernet.publish('add-transaction', message.encoded);
1363
+ } catch (e) {
1364
+ throw e
1365
+ }
1366
+ const wait = () => new Promise((resolve, reject) => {
1367
+ const completed = result => {
1368
+ result.status === 'fulfilled' ? resolve(result.hash) : reject({hash: result.hash, error: result.error});
1369
+
1370
+ pubsub.unsubscribe(`transaction.completed.${message.hash}`, completed);
1371
+ };
1372
+ pubsub.subscribe(`transaction.completed.${message.hash}`, completed);
1373
+ });
1374
+
1375
+ if (await this.hasTransactionToHandle() && !this.#runningEpoch) this.#runEpoch();
1376
+ return {hash: message.hash, data, fee: lib.calculateFee(message), wait}
1377
+ }
1378
+
1379
+ async createContractMessage(creator, contract, constructorParameters = []) {
1380
+ return new ContractMessage({
1381
+ creator,
1382
+ contract,
1383
+ constructorParameters
1384
+ })
1385
+ }
1386
+
1387
+ async createContractAddress(creator, contract, constructorParameters = []) {
1388
+ return this.createContractMessage(creator, contract, constructorParameters)
1389
+ .hash
1390
+ }
1391
+
1392
+ /**
1393
+ *
1394
+ */
1395
+ async deployContract(contract, params = []) {
1396
+ globalThis.msg = {sender: peernet.id, call: this.call};
1397
+
1398
+ const hash = await this.createContractAddress(creator, contract, params);
1399
+
1400
+ try {
1401
+ const tx = await this.createTransactionFrom(peernet.id, lib.contractFactory, 'deployContract', [hash, creator, contract, constructorParameters]);
1402
+ } catch (e) {
1403
+ throw e
1404
+ }
1405
+ return this.#machine.addContract(message)
1406
+ }
1407
+
1408
+ #createMessage(sender = peernet.id) {
1409
+ return {
1410
+ sender: peernet.id,
1411
+ call: this.call,
1412
+ staticCall: this.staticCall,
1413
+ delegate: this.delegate,
1414
+ staticDelegate: this.staticDelegate
1415
+ }
1416
+ }
1417
+
1418
+ internalCall(sender, contract, method, params) {
1419
+ globalThis.msg = this.#createMessage(sender);
1420
+
1421
+ return this.#machine.execute(contract, method, params)
1422
+ }
1423
+
1424
+ call(contract, method, params) {
1425
+ globalThis.msg = this.#createMessage();
1426
+
1427
+ return this.#machine.execute(contract, method, params)
1428
+ }
1429
+
1430
+ staticCall(contract, method, params) {
1431
+ globalThis.msg = this.#createMessage();
1432
+ return this.#machine.get(contract, method, params)
1433
+ }
1434
+
1435
+ delegate(contract, method, params) {
1436
+ globalThis.msg = this.#createMessage();
1437
+
1438
+ return this.#machine.execute(contract, method, params)
1439
+ }
1440
+
1441
+ staticDelegate(contract, method, params) {
1442
+ globalThis.msg = this.#createMessage();
1443
+
1444
+ return this.#machine.get(contract, method, params)
1445
+ }
1446
+
1447
+ mint(to, amount) {
1448
+ return this.call(lib.nativeToken, 'mint', [to, amount])
1449
+ }
1450
+
1451
+ transfer(from, to, amount) {
1452
+ return this.call(lib.nativeToken, 'transfer', [from, to, amount])
1453
+ }
1454
+
1455
+ get balances() {
1456
+ return this.staticCall(lib.nativeToken, 'balances')
1457
+ }
1458
+
1459
+ deleteAll() {
1460
+ return this.#machine.deleteAll()
1461
+ }
1462
+
1463
+ lookup(name) {
1464
+ return this.call(lib.nameService, 'lookup', [name])
1465
+ }
1466
+ }
1467
+
1468
+ module.exports = Chain;