@leofcoin/chain 1.0.25 → 1.0.26

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 (131) hide show
  1. package/demo/151.browser.js +271 -0
  2. package/demo/205.browser.js +215 -0
  3. package/demo/427.browser.js +8092 -0
  4. package/demo/560.browser.js +3 -0
  5. package/demo/911.browser.js +11024 -0
  6. package/{dist → demo}/chain.browser.js +6765 -24141
  7. package/demo/index.html +4 -4
  8. package/demo/main.browser.js +8163 -0
  9. package/{dist → demo}/node.browser.js +3157 -2582
  10. package/{dist → demo}/pako.browser.js +0 -0
  11. package/demo/peernet-worker.browser.js +11330 -0
  12. package/demo/workers/machine-worker.js +12544 -0
  13. package/{dist → demo}/wrtc.browser.js +0 -0
  14. package/dist/chain.js +235 -138
  15. package/dist/module/chain.js +1189 -0
  16. package/dist/module/node.js +1 -0
  17. package/dist/module/workers/machine-worker.js +491 -0
  18. package/dist/node.js +1 -1
  19. package/package.json +11 -19
  20. package/rollup.config.js +87 -3
  21. package/src/chain.js +94 -61
  22. package/src/machine.js +96 -57
  23. package/src/node.js +2 -1
  24. package/src/workers/block-worker.js +71 -0
  25. package/src/workers/machine-worker.js +160 -0
  26. package/src/workers/pool-worker.js +37 -0
  27. package/src/workers/transaction-worker.js +26 -0
  28. package/test/chain.js +14 -14
  29. package/test/create-genesis.js +13 -5
  30. package/webpack.config.js +49 -6
  31. package/workers/block-worker.js +1 -0
  32. package/workers/machine-worker.js +1 -0
  33. package/workers/pool-worker.js +1 -0
  34. package/workers/transaction-worker.js +1 -0
  35. package/dist/protons.browser.js +0 -11429
  36. package/docs/@leofcoin/chain/1.0.22/chain.js.html +0 -891
  37. package/docs/@leofcoin/chain/1.0.22/contracts_factory.js.html +0 -182
  38. package/docs/@leofcoin/chain/1.0.22/contracts_nameService.js.html +0 -231
  39. package/docs/@leofcoin/chain/1.0.22/contracts_proxies_factoryProxy.js.html +0 -135
  40. package/docs/@leofcoin/chain/1.0.22/contracts_proxies_nameServiceProxy.js.html +0 -135
  41. package/docs/@leofcoin/chain/1.0.22/contracts_proxies_nativeTokenProxy.js.html +0 -135
  42. package/docs/@leofcoin/chain/1.0.22/contracts_proxies_validatorsProxy.js.html +0 -135
  43. package/docs/@leofcoin/chain/1.0.22/contracts_proxies_votingProxy.js.html +0 -135
  44. package/docs/@leofcoin/chain/1.0.22/contracts_validators.js.html +0 -242
  45. package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Bold-webfont.eot +0 -0
  46. package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Bold-webfont.svg +0 -1830
  47. package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Bold-webfont.woff +0 -0
  48. package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
  49. package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-BoldItalic-webfont.svg +0 -1830
  50. package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
  51. package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Italic-webfont.eot +0 -0
  52. package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Italic-webfont.svg +0 -1830
  53. package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Italic-webfont.woff +0 -0
  54. package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Light-webfont.eot +0 -0
  55. package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Light-webfont.svg +0 -1831
  56. package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Light-webfont.woff +0 -0
  57. package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-LightItalic-webfont.eot +0 -0
  58. package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-LightItalic-webfont.svg +0 -1835
  59. package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-LightItalic-webfont.woff +0 -0
  60. package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Regular-webfont.eot +0 -0
  61. package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Regular-webfont.svg +0 -1831
  62. package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Regular-webfont.woff +0 -0
  63. package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Semibold-webfont.eot +0 -0
  64. package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Semibold-webfont.svg +0 -1830
  65. package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Semibold-webfont.ttf +0 -0
  66. package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Semibold-webfont.woff +0 -0
  67. package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-SemiboldItalic-webfont.eot +0 -0
  68. package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-SemiboldItalic-webfont.svg +0 -1830
  69. package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-SemiboldItalic-webfont.ttf +0 -0
  70. package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-SemiboldItalic-webfont.woff +0 -0
  71. package/docs/@leofcoin/chain/1.0.22/global.html +0 -1805
  72. package/docs/@leofcoin/chain/1.0.22/icons/home.svg +0 -4
  73. package/docs/@leofcoin/chain/1.0.22/icons/search.svg +0 -4
  74. package/docs/@leofcoin/chain/1.0.22/index.html +0 -125
  75. package/docs/@leofcoin/chain/1.0.22/machine.js.html +0 -255
  76. package/docs/@leofcoin/chain/1.0.22/scripts/linenumber.js +0 -23
  77. package/docs/@leofcoin/chain/1.0.22/scripts/pagelocation.js +0 -89
  78. package/docs/@leofcoin/chain/1.0.22/standards_roles.js.html +0 -188
  79. package/docs/@leofcoin/chain/1.0.22/standards_token.js.html +0 -260
  80. package/docs/@leofcoin/chain/1.0.22/styles/collapse.css +0 -27
  81. package/docs/@leofcoin/chain/1.0.22/styles/jsdoc-default.css +0 -953
  82. package/docs/@leofcoin/chain/1.0.22/styles/prettify-jsdoc.css +0 -111
  83. package/docs/@leofcoin/chain/1.0.22/styles/prettify-tomorrow.css +0 -138
  84. package/docs/@leofcoin/chain/1.0.24/chain.js.html +0 -891
  85. package/docs/@leofcoin/chain/1.0.24/contracts_factory.js.html +0 -182
  86. package/docs/@leofcoin/chain/1.0.24/contracts_nameService.js.html +0 -231
  87. package/docs/@leofcoin/chain/1.0.24/contracts_proxies_factoryProxy.js.html +0 -135
  88. package/docs/@leofcoin/chain/1.0.24/contracts_proxies_nameServiceProxy.js.html +0 -135
  89. package/docs/@leofcoin/chain/1.0.24/contracts_proxies_nativeTokenProxy.js.html +0 -135
  90. package/docs/@leofcoin/chain/1.0.24/contracts_proxies_validatorsProxy.js.html +0 -135
  91. package/docs/@leofcoin/chain/1.0.24/contracts_proxies_votingProxy.js.html +0 -135
  92. package/docs/@leofcoin/chain/1.0.24/contracts_validators.js.html +0 -242
  93. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Bold-webfont.eot +0 -0
  94. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Bold-webfont.svg +0 -1830
  95. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Bold-webfont.woff +0 -0
  96. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
  97. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-BoldItalic-webfont.svg +0 -1830
  98. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
  99. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Italic-webfont.eot +0 -0
  100. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Italic-webfont.svg +0 -1830
  101. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Italic-webfont.woff +0 -0
  102. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Light-webfont.eot +0 -0
  103. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Light-webfont.svg +0 -1831
  104. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Light-webfont.woff +0 -0
  105. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-LightItalic-webfont.eot +0 -0
  106. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-LightItalic-webfont.svg +0 -1835
  107. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-LightItalic-webfont.woff +0 -0
  108. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Regular-webfont.eot +0 -0
  109. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Regular-webfont.svg +0 -1831
  110. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Regular-webfont.woff +0 -0
  111. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Semibold-webfont.eot +0 -0
  112. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Semibold-webfont.svg +0 -1830
  113. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Semibold-webfont.ttf +0 -0
  114. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Semibold-webfont.woff +0 -0
  115. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-SemiboldItalic-webfont.eot +0 -0
  116. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-SemiboldItalic-webfont.svg +0 -1830
  117. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-SemiboldItalic-webfont.ttf +0 -0
  118. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-SemiboldItalic-webfont.woff +0 -0
  119. package/docs/@leofcoin/chain/1.0.24/global.html +0 -1805
  120. package/docs/@leofcoin/chain/1.0.24/icons/home.svg +0 -4
  121. package/docs/@leofcoin/chain/1.0.24/icons/search.svg +0 -4
  122. package/docs/@leofcoin/chain/1.0.24/index.html +0 -125
  123. package/docs/@leofcoin/chain/1.0.24/machine.js.html +0 -255
  124. package/docs/@leofcoin/chain/1.0.24/scripts/linenumber.js +0 -23
  125. package/docs/@leofcoin/chain/1.0.24/scripts/pagelocation.js +0 -89
  126. package/docs/@leofcoin/chain/1.0.24/standards_roles.js.html +0 -188
  127. package/docs/@leofcoin/chain/1.0.24/standards_token.js.html +0 -260
  128. package/docs/@leofcoin/chain/1.0.24/styles/collapse.css +0 -27
  129. package/docs/@leofcoin/chain/1.0.24/styles/jsdoc-default.css +0 -953
  130. package/docs/@leofcoin/chain/1.0.24/styles/prettify-jsdoc.css +0 -111
  131. package/docs/@leofcoin/chain/1.0.24/styles/prettify-tomorrow.css +0 -138
@@ -0,0 +1,1189 @@
1
+ import { BigNumber, formatUnits, parseUnits } from '@leofcoin/utils';
2
+ import { FormatInterface } from '@leofcoin/codec-format-interface';
3
+ import _BN from 'bn.js';
4
+ import '@ethersproject/bytes';
5
+ import { Logger } from '@ethersproject/logger';
6
+ import '@ethersproject/bignumber';
7
+ import { MessageChannel } from 'worker_threads';
8
+ import { randomBytes } from 'crypto';
9
+ import 'path';
10
+ import { fork } from 'child_process';
11
+ import e from 'express';
12
+ import MultiWallet from '@leofcoin/multi-wallet';
13
+ import { CodecHash } from '@leofcoin/codec-format-interface/dist/index';
14
+ import bs32 from '@vandeurenglenn/base32';
15
+
16
+ var proto$4 = `
17
+ message ContractMessage {
18
+ required string creator = 1;
19
+ required bytes contract = 2;
20
+ repeated string constructorParameters = 3;
21
+ }
22
+ `;
23
+
24
+ class ContractMessage extends FormatInterface {
25
+ get keys() {
26
+ return ['creator', 'contract', 'constructorParameters']
27
+ }
28
+
29
+ get messageName() {
30
+ return 'ContractMessage'
31
+ }
32
+
33
+ constructor(buffer) {
34
+ super(buffer, proto$4, {name: 'contract-message'});
35
+ }
36
+ }
37
+
38
+ var proto$3 = `
39
+
40
+ message TransactionMessage {
41
+ required uint64 timestamp = 1;
42
+ required string from = 2;
43
+ required string to = 3;
44
+ required uint64 nonce = 4;
45
+ required string method = 5;
46
+ repeated string params = 6;
47
+ required string signature = 7;
48
+ }
49
+ `;
50
+
51
+ class TransactionMessage extends FormatInterface {
52
+ get keys() {
53
+ return ['timestamp', 'from', 'to', 'nonce', 'method', 'params', 'signature']
54
+ }
55
+
56
+ get messageName() {
57
+ return 'TransactionMessage'
58
+ }
59
+
60
+ constructor(buffer) {
61
+ const name = 'transaction-message';
62
+ super(buffer, proto$3, {name});
63
+ }
64
+ }
65
+
66
+ var proto$2 = `
67
+ message ValidatorMessage {
68
+ required string address = 1;
69
+ required string reward = 2;
70
+ }
71
+
72
+ message Transaction {
73
+ required string hash = 1;
74
+ required uint64 timestamp = 2;
75
+ required string from = 3;
76
+ required string to = 4;
77
+ required uint64 nonce = 5;
78
+ required string method = 6;
79
+ repeated string params = 7;
80
+ }
81
+
82
+ message BlockMessage {
83
+ required uint64 index = 1;
84
+ required string previousHash = 3;
85
+ required uint64 timestamp = 4;
86
+ required uint64 reward = 5;
87
+ required string fees = 6;
88
+ repeated Transaction transactions = 7;
89
+ repeated ValidatorMessage validators = 8;
90
+ }
91
+ `;
92
+
93
+ class BlockMessage extends FormatInterface {
94
+ get keys() {
95
+ return ['index', 'previousHash', 'timestamp', 'reward', 'fees', 'transactions', 'validators']
96
+ }
97
+
98
+ get messageName() {
99
+ return 'BlockMessage'
100
+ }
101
+
102
+ constructor(buffer) {
103
+ const name = 'block-message';
104
+ super(buffer, proto$2, {name});
105
+ }
106
+ }
107
+
108
+ var proto$1 = `
109
+
110
+ message BWMessage {
111
+ required uint64 up = 1;
112
+ required uint64 down = 2;
113
+ }
114
+ `;
115
+
116
+ class BWMessage extends FormatInterface {
117
+ get keys() {
118
+ return ['up', 'down']
119
+ }
120
+
121
+ get messageName() {
122
+ return 'BWMessage'
123
+ }
124
+
125
+ constructor(buffer) {
126
+ const name = 'bw-message';
127
+ super(buffer, proto$1, {name});
128
+ }
129
+ }
130
+
131
+ var proto = `
132
+
133
+ message BWRequestMessage {
134
+ }
135
+ `;
136
+
137
+ class BWRequestMessage extends FormatInterface {
138
+ get keys() {
139
+ return []
140
+ }
141
+
142
+ get messageName() {
143
+ return 'BWRequestMessage'
144
+ }
145
+
146
+ constructor(buffer) {
147
+ const name = 'bw-request-message';
148
+ super(buffer, proto, {name});
149
+ }
150
+ }
151
+
152
+ var contractFactory$2 = "ihny2gqhpxjlib2nann7q5ovaqs5uo7dufac3r4yomf36pt4d5yg6att6ew";
153
+ var nativeToken$2 = "ihny2gqhrx44niifti5zawfqclfklf7ewsf6z3rem2fmbxst6mxyyzahlm6";
154
+ var nameService$2 = "ihny2gqga2rfudkgb3xz7khj7p66p75ihciz6nyi55b42t26ihpszpwrora";
155
+ var validators$2 = "ihny2gqgy5jpkevwfoluwe2b2y7viqtcfrwgabipz3mkb7twnhjsqhdc2wt";
156
+ var addresses = {
157
+ contractFactory: contractFactory$2,
158
+ nativeToken: nativeToken$2,
159
+ nameService: nameService$2,
160
+ validators: validators$2
161
+ };
162
+
163
+ const contractFactory$1 = addresses.contractFactory;
164
+ const nameService$1 = addresses.nameService;
165
+ const nativeToken$1 = addresses.nativeToken;
166
+ const validators$1 = addresses.validators;
167
+
168
+ const version$1 = "bignumber/5.6.2";
169
+
170
+ _BN.BN;
171
+ new Logger(version$1);
172
+
173
+ const version = "units/5.6.1";
174
+
175
+ new Logger(version);
176
+
177
+ const byteFormats = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
178
+
179
+ const formatBytes = (bytes, decimals = 2) => {
180
+ if (bytes === 0) return '0 Bytes';
181
+ if (decimals < 0) decimals = 0;
182
+
183
+ const k = 1024;
184
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
185
+
186
+ return `${parseFloat((bytes / Math.pow(k, i)).toFixed(decimals))} ${byteFormats[i]}`
187
+ };
188
+
189
+ // import State from './state'
190
+ new MessageChannel();
191
+ class Machine {
192
+ #contracts = {}
193
+ #nonces = {}
194
+ constructor() {
195
+ return this.#init()
196
+ }
197
+
198
+ #createMessage(sender = peernet.id) {
199
+ return {
200
+ sender,
201
+ call: this.execute,
202
+ staticCall: this.get.bind(this)
203
+ }
204
+ }
205
+
206
+ async #onmessage(data) {
207
+ switch (data.type) {
208
+ case 'contractError':
209
+ console.warn(`removing contract ${await data.hash}`);
210
+ await contractStore.delete(await data.hash);
211
+ break
212
+
213
+ case 'executionError':
214
+ console.warn(`error executing transaction ${data.message}`);
215
+ pubsub.publish(e.id, {error: e.message});
216
+ break
217
+
218
+ case 'debug':
219
+ data.messages.forEach(message => debug(message));
220
+ break
221
+ case 'machine-ready':
222
+ pubsub.publish('machine.ready');
223
+ break
224
+ case 'response':
225
+ pubsub.publish(data.id, data.value);
226
+ break
227
+ }
228
+
229
+ }
230
+
231
+ async #init() {
232
+ return new Promise(async (resolve) => {
233
+ // this.worker = new Worker('./workers/machine-worker.js')
234
+ // this.worker.onmessage = this.#onmessage.bind(this)
235
+
236
+ pubsub.subscribe('machine.ready', () => {
237
+ resolve(this);
238
+ });
239
+ this.worker = fork('./workers/machine-worker.js', {serialization: 'advanced'});
240
+ this.worker.on('message', this.#onmessage.bind(this));
241
+ const blocks = await blockStore.values();
242
+ const contracts = await Promise.all([
243
+ contractStore.get(contractFactory$1),
244
+ contractStore.get(nativeToken$1),
245
+ contractStore.get(validators$1),
246
+ contractStore.get(nameService$1)
247
+ ]);
248
+
249
+ const message = {
250
+ type: 'init',
251
+ input: {
252
+ contracts,
253
+ blocks,
254
+ peerid: peernet.peerId
255
+ }
256
+ };
257
+ this.worker.send(message);
258
+ // this.worker.postMessage(message)
259
+ })
260
+ // return
261
+
262
+ }
263
+
264
+ async #runContract(contractMessage) {
265
+ const params = contractMessage.decoded.constructorParameters;
266
+ try {
267
+
268
+ const func = new Function(contractMessage.decoded.contract);
269
+ const Contract = func();
270
+
271
+ globalThis.msg = this.#createMessage(contractMessage.decoded.creator);
272
+ // globalThis.msg = {sender: contractMessage.decoded.creator}
273
+ this.#contracts[await contractMessage.hash] = await new Contract(...params);
274
+ debug(`loaded contract: ${await contractMessage.hash}`);
275
+ debug(`size: ${formatBytes(contractMessage.encoded.length)}`);
276
+ } catch (e) {
277
+ console.log(e);
278
+ console.warn(`removing contract ${await contractMessage.hash}`);
279
+ await contractStore.delete(await contractMessage.hash, contractMessage.encoded);
280
+ }
281
+ }
282
+ /**
283
+ * @params {ContractMessage} - contractMessage
284
+ */
285
+ async addContract(contractMessage) {
286
+ if (!await contractStore.has(contractMessage.hash)) {
287
+ await contractStore.put(contractMessage.hash, contractMessage.encoded);
288
+ await this.#runContract(contractMessage);
289
+ return contractMessage.hash
290
+ }
291
+ throw new Error('duplicate contract')
292
+ }
293
+
294
+ async execute(contract, method, params) {
295
+ return new Promise((resolve, reject) => {
296
+ const id = randomBytes(20).toString('hex');
297
+ const message = message => {
298
+ if (message?.error) reject(message.error);
299
+ else resolve(message);
300
+ };
301
+ pubsub.subscribe(id, message);
302
+ this.worker.send({
303
+ type: 'execute',
304
+ id,
305
+ input: {
306
+ contract,
307
+ method,
308
+ params
309
+ }
310
+ });
311
+ })
312
+
313
+ }
314
+
315
+ addJob(contract, method, params, from, nonce) {
316
+ if (!this.#nonces[from]) this.#nonces[from] = nonce;
317
+ if (nonce === this.#nonces[from] + 1) return this.#contracts[contract][method](...params)
318
+ // return setTimeout(() => {
319
+ // return this.addJob(contract, method, params, from, nonce)
320
+ // }, 50)
321
+ }
322
+
323
+ get(contract, method, params) {
324
+ return new Promise((resolve, reject) => {
325
+ const id = randomBytes(20).toString();
326
+ const message = message => {
327
+ resolve(message);
328
+ };
329
+ pubsub.subscribe(id, message);
330
+ this.worker.send({
331
+ type: 'get',
332
+ id,
333
+ input: {
334
+ contract,
335
+ method,
336
+ params
337
+ }
338
+ });
339
+ })
340
+ }
341
+
342
+ async delete(hash) {
343
+ return contractStore.delete(hash)
344
+ }
345
+
346
+ async deleteAll() {
347
+ let hashes = await contractStore.get();
348
+ hashes = Object.keys(hashes).map(hash => this.delete(hash));
349
+ return Promise.all(hashes)
350
+ }
351
+ }
352
+
353
+ var contractFactory = "237,198,141,3,123,34,99,114,101,97,116,111,114,34,58,34,51,67,122,86,53,69,121,74,118,54,84,86,69,97,88,71,116,114,101,69,70,84,70,83,69,74,109,97,75,66,100,118,83,113,116,88,112,88,87,52,114,55,98,119,87,66,119,56,119,83,89,86,106,71,34,44,34,99,111,110,116,114,97,99,116,34,58,34,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,92,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,92,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,92,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,92,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,92,34,100,117,112,108,105,99,97,116,101,32,99,111,110,116,114,97,99,116,92,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,92,34,105,110,118,97,108,105,100,32,99,111,110,116,114,97,99,116,92,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,92,110,34,44,34,99,111,110,115,116,114,117,99,116,111,114,80,97,114,97,109,101,116,101,114,115,34,58,91,93,125";
354
+ var nativeToken = "237,198,141,3,123,34,99,114,101,97,116,111,114,34,58,34,51,67,122,86,53,69,121,74,118,54,84,86,69,97,88,71,116,114,101,69,70,84,70,83,69,74,109,97,75,66,100,118,83,113,116,88,112,88,87,52,114,55,98,119,87,66,119,56,119,83,89,86,106,71,34,44,34,99,111,110,116,114,97,99,116,34,58,34,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,92,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,92,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,92,34,79,87,78,69,82,92,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,92,34,79,87,78,69,82,92,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,92,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,92,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,92,34,79,87,78,69,82,92,34,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,92,34,78,111,116,32,97,108,108,111,119,101,100,92,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,92,34,79,87,78,69,82,92,34,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,92,34,78,111,116,32,97,108,108,111,119,101,100,92,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,92,34,110,97,109,101,32,117,110,100,101,102,105,110,101,100,92,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,92,34,115,121,109,98,111,108,32,117,110,100,101,102,105,110,101,100,92,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,92,34,77,73,78,84,92,34,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,92,34,110,111,116,32,97,108,108,111,119,101,100,92,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,92,34,66,85,82,78,92,34,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,92,34,110,111,116,32,97,108,108,111,119,101,100,92,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,92,34,97,109,111,117,110,116,32,101,120,99,101,101,100,115,32,98,97,108,97,110,99,101,92,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,92,34,48,120,48,48,92,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,92,34,48,120,48,48,92,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,92,34,48,120,48,48,92,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,92,34,65,114,116,79,110,108,105,110,101,92,34,44,92,34,65,82,84,92,34,44,49,56,44,115,116,97,116,101,41,125,125,59,92,110,34,44,34,99,111,110,115,116,114,117,99,116,111,114,80,97,114,97,109,101,116,101,114,115,34,58,91,93,125";
355
+ var nameService = "237,198,141,3,123,34,99,114,101,97,116,111,114,34,58,34,51,67,122,86,53,69,121,74,118,54,84,86,69,97,88,71,116,114,101,69,70,84,70,83,69,74,109,97,75,66,100,118,83,113,116,88,112,88,87,52,114,55,98,119,87,66,119,56,119,83,89,86,106,71,34,44,34,99,111,110,116,114,97,99,116,34,58,34,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,92,34,65,114,116,79,110,108,105,110,101,78,97,109,101,83,101,114,118,105,99,101,92,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,92,34,110,111,32,111,119,110,101,114,92,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,92,34,110,111,32,111,119,110,101,114,92,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,92,34,110,111,32,111,119,110,101,114,92,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,92,34,98,97,108,97,110,99,101,79,102,92,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,92,34,112,114,105,99,101,32,101,120,99,101,101,100,115,32,98,97,108,97,110,99,101,92,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,92,34,116,114,97,110,115,102,101,114,92,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,92,34,110,111,116,32,97,32,111,119,110,101,114,92,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,92,34,110,111,116,32,97,32,111,119,110,101,114,92,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,92,110,34,44,34,99,111,110,115,116,114,117,99,116,111,114,80,97,114,97,109,101,116,101,114,115,34,58,91,34,105,104,110,121,50,103,113,104,112,120,106,108,105,98,50,110,97,110,110,55,113,53,111,118,97,113,115,53,117,111,55,100,117,102,97,99,51,114,52,121,111,109,102,51,54,112,116,52,100,53,121,103,54,97,116,116,54,101,119,34,44,34,105,104,110,121,50,103,113,104,114,120,52,52,110,105,105,102,116,105,53,122,97,119,102,113,99,108,102,107,108,102,55,101,119,115,102,54,122,51,114,101,109,50,102,109,98,120,115,116,54,109,120,121,121,122,97,104,108,109,54,34,44,34,105,104,110,121,50,103,113,103,121,53,106,112,107,101,118,119,102,111,108,117,119,101,50,98,50,121,55,118,105,113,116,99,102,114,119,103,97,98,105,112,122,51,109,107,98,55,116,119,110,104,106,115,113,104,100,99,50,119,116,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,125";
356
+ var validators = "237,198,141,3,123,34,99,114,101,97,116,111,114,34,58,34,51,67,122,86,53,69,121,74,118,54,84,86,69,97,88,71,116,114,101,69,70,84,70,83,69,74,109,97,75,66,100,118,83,113,116,88,112,88,87,52,114,55,98,119,87,66,119,56,119,83,89,86,106,71,34,44,34,99,111,110,116,114,97,99,116,34,58,34,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,92,34,65,114,116,79,110,108,105,110,101,86,97,108,105,100,97,116,111,114,115,92,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,92,34,110,111,116,32,97,110,32,111,119,110,101,114,92,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,92,34,110,111,116,32,97,110,32,111,119,110,101,114,92,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,92,34,97,108,114,101,97,100,121,32,97,32,118,97,108,105,100,97,116,111,114,92,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,92,34,98,97,108,97,110,99,101,79,102,92,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,92,34,118,97,108,105,100,97,116,111,114,32,110,111,116,32,102,111,117,110,100,92,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,92,34,118,97,108,105,100,97,116,111,114,32,110,111,116,32,102,111,117,110,100,92,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,92,34,98,97,108,97,110,99,101,79,102,92,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,92,110,34,44,34,99,111,110,115,116,114,117,99,116,111,114,80,97,114,97,109,101,116,101,114,115,34,58,91,34,105,104,110,121,50,103,113,104,114,120,52,52,110,105,105,102,116,105,53,122,97,119,102,113,99,108,102,107,108,102,55,101,119,115,102,54,122,51,114,101,109,50,102,109,98,120,115,116,54,109,120,121,121,122,97,104,108,109,54,34,93,125";
357
+ var bytecodes = {
358
+ contractFactory: contractFactory,
359
+ nativeToken: nativeToken,
360
+ nameService: nameService,
361
+ validators: validators
362
+ };
363
+
364
+ const contractFactoryMessage = bytecodes.contractFactory;
365
+ const nativeTokenMessage = bytecodes.nativeToken;
366
+
367
+ const nameServiceMessage = bytecodes.nameService;
368
+ const validatorsMessage = bytecodes.validators;
369
+
370
+ const createContractMessage = async (creator, contract, constructorParameters = []) => {
371
+ return new ContractMessage({
372
+ creator,
373
+ contract,
374
+ constructorParameters
375
+ })
376
+ };
377
+
378
+ const calculateFee = async transaction => {
379
+ // excluded from fees
380
+ if (transaction.to === validators$1) return 0
381
+ // fee per gb
382
+ transaction = await new TransactionMessage(transaction);
383
+ let fee = transaction.encoded.length;
384
+ fee = fee / 1024;
385
+ fee = fee / 1000000;
386
+ const parts = String(fee).split('.');
387
+ let decimals = 0;
388
+ if (parts[1]) {
389
+ const potentional = parts[1].split('e');
390
+ parts[1] = potentional[0];
391
+ decimals = Number(potentional[1].replace(/\-|\+/g, '')) + Number(potentional[0].length);
392
+ }
393
+
394
+ return Number.parseFloat(fee.toString()).toFixed(decimals)
395
+ };
396
+
397
+ globalThis.BigNumber = BigNumber;
398
+
399
+ // check if browser or local
400
+ class Chain {
401
+ #validators = []
402
+ #blocks = []
403
+ #machine
404
+ #runningEpoch = false
405
+ #lastBlock = {index: 0, previousHash: '0x0'}
406
+
407
+ constructor() {
408
+ return this.#init()
409
+ }
410
+
411
+ get lib() {
412
+ return lib
413
+ }
414
+
415
+ get lastBlock() {
416
+ return this.#lastBlock
417
+ }
418
+
419
+ get nativeToken() {
420
+ return addresses.nativeToken
421
+ }
422
+
423
+ get validators() {
424
+ return [...this.#validators]
425
+ }
426
+
427
+ get blocks() {
428
+ return [...this.#blocks]
429
+ }
430
+
431
+ async hasTransactionToHandle() {
432
+ const size = await transactionPoolStore.size();
433
+ console.log({size});
434
+ if (size > 0) return true
435
+ return false
436
+ }
437
+
438
+ async #runEpoch() {
439
+ this.#runningEpoch = true;
440
+ console.log('epoch');
441
+ const validators = await this.staticCall(addresses.validators, 'validators');
442
+ console.log(validators);
443
+ if (!validators[peernet.id]?.active) return
444
+ console.log('active');
445
+
446
+
447
+ const start = new Date().getTime();
448
+ try {
449
+ await this.#createBlock();
450
+ } catch (e) {
451
+ console.error(e);
452
+ }
453
+
454
+ const end = new Date().getTime();
455
+ console.log(((end - start) / 1000) + ' s');
456
+
457
+ if (await this.hasTransactionToHandle()) return this.#runEpoch()
458
+ this.#runningEpoch = false;
459
+ // if (await this.hasTransactionToHandle() && !this.#runningEpoch) return this.#runEpoch()
460
+ }
461
+
462
+ async #setup() {
463
+
464
+ const contracts = [{
465
+ address: addresses.contractFactory,
466
+ message: contractFactoryMessage
467
+ }, {
468
+ address: addresses.nativeToken,
469
+ message: nativeTokenMessage
470
+ }, {
471
+ address: addresses.validators,
472
+ message: validatorsMessage
473
+ }, {
474
+ address: addresses.nameService,
475
+ message: nameServiceMessage
476
+ }];
477
+
478
+ await Promise.all(contracts.map(async ({address, message}) => {
479
+ message = await new ContractMessage(message);
480
+ await contractStore.put(address, message.encoded);
481
+ }));
482
+ console.log('handle native contracts');
483
+ // handle native contracts
484
+ }
485
+
486
+ async #sync() {
487
+ let promises = [];
488
+ for (const peer of peernet.connections) {
489
+ if (peer.peerId !== this.id) {
490
+ let data = new peernet.protos['peernet-request']({request: 'lastBlock'});
491
+
492
+ const node = await peernet.prepareMessage(id, data.encoded);
493
+ promises.push(peer.request(node.encoded));
494
+ }
495
+ }
496
+ // if (this.)
497
+
498
+ promises = await Promise.allSettled(promises);
499
+ promises = promises.reduce((set, c) => {
500
+ if (c.index > set.index) {
501
+ set.index = c.index;
502
+ set.hash = c.hash;
503
+ }
504
+ return set
505
+ }, {index: 0, hash: '0x0'});
506
+ // get lastblock
507
+ console.log(promises.hash);
508
+ if (promises.hash && promises.hash !== '0x0') {
509
+ console.log('get');
510
+ let localBlock = await peernet.get(promises.hash);
511
+ console.log({localBlock});
512
+ }
513
+
514
+
515
+ }
516
+
517
+ async #init() {
518
+ // this.node = await new Node()
519
+ this.participants = [];
520
+ this.participating = false;
521
+ const initialized = await contractStore.has(addresses.contractFactory);
522
+ if (!initialized) await this.#setup();
523
+
524
+ this.#machine = await new Machine();
525
+ this.utils = { BigNumber, formatUnits, parseUnits };
526
+
527
+ await peernet.addRequestHandler('bw-request-message', () => {
528
+
529
+ return new BWMessage(peernet.client.bw) || { up: 0, down: 0 }
530
+ });
531
+
532
+ await peernet.addRequestHandler('lastBlock', this.#lastBlockHandler.bind(this));
533
+
534
+ peernet.subscribe('add-block', this.#addBlock.bind(this));
535
+
536
+ peernet.subscribe('add-transaction', this.#addTransaction.bind(this));
537
+
538
+ pubsub.subscribe('peer:connected', this.#peerConnected.bind(this));
539
+
540
+ try {
541
+ let localBlock = await chainStore.get('lastBlock');
542
+ localBlock = new TextDecoder().decode(localBlock);
543
+ if (localBlock && localBlock !== '0x0') {
544
+ localBlock = await peernet.get(localBlock);
545
+ localBlock = await new BlockMessage(localBlock);
546
+ this.#lastBlock = {...localBlock.decoded, hash: await localBlock.hash};
547
+ } else {
548
+ await this.#sync();
549
+ }
550
+
551
+ // console.log(this.lastBlock.decoded.transactions);
552
+ } catch (e) {
553
+ console.log({e});
554
+ await chainStore.put('lastBlock', '0x0');
555
+ await this.#sync();
556
+ // this.#setup()
557
+ }
558
+ // load local blocks
559
+ if (peernet.connections?.length > 1) await this.resolveBlocks();
560
+ return this
561
+ }
562
+
563
+ async #peerConnected(peer) {
564
+ let node = await new peernet.protos['peernet-request']({request: 'lastBlock'});
565
+ console.log(node);
566
+ node = await peernet.prepareMessage(node);
567
+ let response = await peer.request(node.encoded);
568
+ console.log({response});
569
+ response = await new globalThis.peernet.protos['peernet-response'](response);
570
+ let lastBlock = response.decoded.response;
571
+
572
+ if (!this.lastBlock || this.lastBlock.index < lastBlock.index) {
573
+ // TODO: check if valid
574
+ const localIndex = this.lastBlock ? this.lastBlock.index : 0;
575
+ const index = lastBlock.index;
576
+ await this.resolveBlock(lastBlock.hash);
577
+ this.#lastBlock = this.#blocks[this.#blocks.length - 1];
578
+ let blocksSynced = localIndex > 0 ? localIndex - index : index;
579
+ blocksSynced += 1;
580
+ debug(`synced ${blocksSynced} ${blocksSynced > 1 ? 'blocks' : 'block'}`);
581
+
582
+ this.#blocks.length;
583
+ (this.#blocks.length) - blocksSynced;
584
+ await this.#loadBlocks(this.#blocks);
585
+ const message = await new BlockMessage(this.lastBlock);
586
+ await blockStore.put(await message.hash, message.encoded);
587
+ await chainStore.put('lastBlock', this.lastBlock.hash);
588
+ }
589
+ }
590
+
591
+ #epochTimeout
592
+
593
+ async #addTransaction(transaction) {
594
+ try {
595
+ transaction = await new TransactionMessage(transaction);
596
+ const has = await transactionPoolStore.has(await transaction.hash);
597
+ if (!has) await transactionPoolStore.put(await transaction.hash, transaction.encoded);
598
+ if (this.participating && !this.#runningEpoch) this.#runEpoch();
599
+ } catch (e) {
600
+ throw Error('invalid transaction')
601
+ }
602
+ }
603
+
604
+ async #lastBlockHandler() {
605
+ return new peernet.protos['peernet-response']({response: { hash: this.lastBlock?.hash, index: this.lastBlock?.index }})
606
+ }
607
+
608
+ async resolveBlock(hash) {
609
+ if (!hash) throw new Error(`expected hash, got: ${hash}`)
610
+ let block = await peernet.get(hash, 'block');
611
+ if (!await peernet.has(hash, 'block')) await peernet.put(hash, block, 'block');
612
+ block = await new BlockMessage(block);
613
+ const size = block.encoded.length || block.encoded.byteLength;
614
+ block = {...block.decoded, hash};
615
+ this.#blocks[block.index] = block;
616
+ console.log(`loaded block: ${hash} @${block.index} ${formatBytes(size)}`);
617
+ if (block.index !== 0) {
618
+ return this.resolveBlock(block.previousHash)
619
+ }
620
+ }
621
+
622
+ async resolveBlocks() {
623
+ try {
624
+
625
+ const localBlock = await chainStore.get('lastBlock');
626
+ const hash = new TextDecoder().decode(localBlock);
627
+ if (hash && hash !== '0x0')
628
+ await this.resolveBlock(localBlock);
629
+ this.#lastBlock = this.#blocks[this.#blocks.length - 1];
630
+ await this.#loadBlocks(this.#blocks);
631
+ } catch (e) {
632
+ await chainStore.put('lastBlock', new TextEncoder().encode('0x0'));
633
+ return this.resolveBlocks()
634
+ // console.log(e);
635
+ }
636
+ }
637
+
638
+ async #loadBlocks(blocks) {
639
+ for (const block of blocks) {
640
+ if (!block.loaded) {
641
+ for (const transaction of block.transactions) {
642
+ try {
643
+ await this.#machine.execute(transaction.to, transaction.method, transaction.params);
644
+
645
+ } catch (e) {
646
+ console.log(e);
647
+ }
648
+ }
649
+ block.loaded = true;
650
+ // let message = await peernet.get(block.hash, 'block')
651
+
652
+ // const compressed = pako.deflate(message);
653
+ // const result = pako.inflate(compressed);
654
+ // console.log(result.length, compressed.length);
655
+ //
656
+ // console.log(result.length - compressed.length);
657
+
658
+ // message = new BlockMessage(message)
659
+ // for (const transaction of message.decoded.transactions) {
660
+ // try {
661
+ // await this.#machine.execute(transaction.to, transaction.method, transaction.params)
662
+ //
663
+ // } catch (e) {
664
+ // // console.log(e);
665
+ // }
666
+ // }
667
+ // block.loaded = true
668
+ }
669
+ }
670
+ }
671
+
672
+ async #executeTransaction({hash, from, to, method, params, nonce}) {
673
+ try {
674
+ let result = await this.#machine.execute(to, method, params, from, nonce);
675
+ // if (!result) result = this.#machine.state
676
+ pubsub.publish(`transaction.completed.${hash}`, {status: 'fulfilled', hash});
677
+ return result ? result : 'no state change'
678
+ } catch (e) {
679
+ console.log({e});
680
+ pubsub.publish(`transaction.completed.${hash}`, {status: 'fail', hash, error: e});
681
+ throw e
682
+ }
683
+ }
684
+
685
+ async #addBlock(block) {
686
+ const blockMessage = await new BlockMessage(block);
687
+ // if (!Buffer.isBuffer(block)) block = Buffer.from(block, 'hex')
688
+ // const transactionJob = async transaction => {
689
+ // try {
690
+ // transaction = await transactionPoolStore.get(transaction)
691
+ // } catch (e) {
692
+ // try {
693
+ // transaction = await peernet.get(transaction, 'transaction')
694
+ // } catch (e) {
695
+ // console.warn(`couldn't resolve ${transaction}`);
696
+ // }
697
+ // }
698
+ // transaction = new TransactionMessage(transaction)
699
+ // return transaction
700
+ // }
701
+ await Promise.all(blockMessage.decoded.transactions
702
+ .map(async transaction => transactionPoolStore.delete(await transaction.hash)));
703
+ const hash = await blockMessage.hash;
704
+ // let transactions = blockMessage.decoded.transactions.map(tx => transactionJob(tx))
705
+ // transactions = await Promise.all(transactions)
706
+ this.#lastBlock = { hash, ...blockMessage.decoded };
707
+ await blockStore.put(hash, blockMessage.encoded);
708
+ await chainStore.put('lastBlock', hash);
709
+ debug(`added block: ${hash}`);
710
+ let promises = [];
711
+ let contracts = [];
712
+ for (let transaction of blockMessage.decoded.transactions) {
713
+ // await transactionStore.put(transaction.hash, transaction.encoded)
714
+ const index = contracts.indexOf(transaction.to);
715
+ if (index === -1) contracts.push(transaction.to);
716
+ promises.push(this.#executeTransaction(transaction));
717
+ }
718
+ try {
719
+ promises = await Promise.allSettled(promises);
720
+ for (let transaction of blockMessage.decoded.transactions) {
721
+ await accountsStore.put(transaction.from, String(transaction.nonce));
722
+ }
723
+
724
+ // todo finish state
725
+ // for (const contract of contracts) {
726
+ // const state = await this.#machine.get(contract, 'state')
727
+ // // await stateStore.put(contract, state)
728
+ // console.log(state);
729
+ // }
730
+ pubsub.publish('block-processed', blockMessage.decoded);
731
+ } catch (e) {
732
+ console.log({e});
733
+ }
734
+
735
+ }
736
+
737
+ async #updateState() {
738
+
739
+ }
740
+
741
+
742
+
743
+ async participate() {
744
+ // TODO: validate participant
745
+ // hold min amount of 50k ART for 7 days
746
+ // lock the 50k
747
+ // introduce peer-reputation
748
+ // peerReputation(peerId)
749
+ // {bandwith: {up, down}, uptime}
750
+ this.participating = true;
751
+ if (!await this.staticCall(addresses.validators, 'has', [peernet.id])) await this.createTransactionFrom(peernet.id, addresses.validators, 'addValidator', [peernet.id]);
752
+ if (await this.hasTransactionToHandle() && !this.#runningEpoch) await this.#runEpoch();
753
+
754
+ // const runEpoch = () => setTimeout(async () => {
755
+ // if (await this.hasTransactionToHandle() && !this.#runningEpoch) await this.#runEpoch()
756
+ // runEpoch()
757
+ // }, 5000)
758
+ // runEpoch()
759
+ }
760
+
761
+ calculateFee(transaction) {
762
+ // excluded from fees
763
+ // if (transaction.decoded.to === addresses.validators) return 0
764
+ // fee per gb
765
+ return (transaction.encoded.length / 1024) / 1e-6
766
+ }
767
+
768
+ async getTransactions (transactions) {
769
+ return new Promise(async (resolve, reject) => {
770
+ let size = 0;
771
+ const _transactions = [];
772
+
773
+
774
+ await Promise.all(transactions
775
+ .map(async tx => {
776
+ tx = await new TransactionMessage(tx);
777
+ size += tx.encoded.length;
778
+ if (!formatBytes(size).includes('MB') || formatBytes(size).includes('MB') && Number(formatBytes(size).split(' MB')[0]) <= 0.75) _transactions.push({...tx.decoded, hash: await tx.hash});
779
+ else resolve(_transactions);
780
+ }));
781
+
782
+ return resolve(_transactions)
783
+ })
784
+
785
+ }
786
+
787
+ // todo filter tx that need to wait on prev nonce
788
+ async #createBlock(limit = 1800) {
789
+ // vote for transactions
790
+ if (await transactionPoolStore.size() === 0) return;
791
+
792
+ let transactions = await transactionPoolStore.values(limit);
793
+
794
+ if (Object.keys(transactions)?.length === 0 ) return
795
+
796
+ let block = {
797
+ transactions: [],
798
+ validators: [],
799
+ fees: 0
800
+ };
801
+
802
+ // exclude failing tx
803
+ transactions = await this.getTransactions(transactions.slice(0, transactions.length < 1800 ? transactions.length : 1800));
804
+
805
+ transactions = transactions.sort((a, b) => a.nonce - b.nonce);
806
+ for (let transaction of transactions) {
807
+ try {
808
+ await this.#executeTransaction(transaction);
809
+ block.transactions.push(transaction);
810
+ block.fees += Number(calculateFee(transaction));
811
+ await accountsStore.put(transaction.from, new TextEncoder().encode(String(transaction.nonce)));
812
+ } catch (e) {
813
+ console.log({e});
814
+ transaction = await new TransactionMessage(transaction);
815
+ await transactionPoolStore.delete(await transaction.hash);
816
+ }
817
+ }
818
+ // don't add empty block
819
+ if (block.transactions.length === 0) return
820
+ const validators = await this.staticCall(addresses.validators, 'validators');
821
+ console.log({validators});
822
+ // block.validators = Object.keys(block.validators).reduce((set, key) => {
823
+ // if (block.validators[key].active) {
824
+ // push({
825
+ // address: key
826
+ // })
827
+ // }
828
+ // }, [])
829
+ const peers = {};
830
+ for (const entry of peernet.peerEntries) {
831
+ peers[entry[0]] = entry[1];
832
+ }
833
+ for (const validator of Object.keys(validators)) {
834
+ if (validators[validator].active) {
835
+ const peer = peers[validator];
836
+ if (peer && peer.connected) {
837
+ let data = await new BWRequestMessage();
838
+ const node = await peernet.prepareMessage(validator, data.encoded);
839
+ try {
840
+ const bw = await peer.request(node.encoded);
841
+ console.log(bw);
842
+ block.validators.push({
843
+ address: validator,
844
+ bw: bw.up + bw.down
845
+ });
846
+ } catch(e) {
847
+
848
+ }
849
+
850
+ } else if (peernet.id === validator) {
851
+ block.validators.push({
852
+ address: peernet.id,
853
+ bw: peernet.bw.up + peernet.bw.down
854
+ });
855
+
856
+ }
857
+ }
858
+
859
+ }
860
+
861
+ console.log({validators: block.validators});
862
+
863
+ block.reward = 150;
864
+ block.validators = block.validators.map(validator => {
865
+ validator.reward = String(Number(block.fees) + block.reward / block.validators.length);
866
+ delete validator.bw;
867
+ return validator
868
+ });
869
+ // block.validators = calculateValidatorReward(block.validators, block.fees)
870
+
871
+ block.index = this.lastBlock?.index;
872
+ if (block.index === undefined) block.index = 0;
873
+ else block.index += 1;
874
+
875
+ block.previousHash = this.lastBlock?.hash || '0x0';
876
+ block.timestamp = new Date().getTime();
877
+
878
+ const parts = String(block.fees).split('.');
879
+ let decimals = 0;
880
+ if (parts[1]) {
881
+ const potentional = parts[1].split('e');
882
+ if (potentional[0] !== parts[1]) {
883
+ parts[1] = potentional[0];
884
+ decimals = Number(potentional[1]?.replace(/\-|\+/g, '')) + Number(potentional[0].length);
885
+ } else {
886
+ decimals = parts[1].length;
887
+ }
888
+
889
+ }
890
+ block.fees = Number.parseFloat(String(block.fees)).toFixed(decimals);
891
+
892
+ try {
893
+ let blockMessage = await new BlockMessage(block);
894
+ const hash = await blockMessage.hash;
895
+ await Promise.all(blockMessage.decoded.transactions
896
+ .map(async transaction => transactionPoolStore.delete(await transaction.hash)));
897
+
898
+ this.#lastBlock = { hash, ...blockMessage.decoded };
899
+ await blockStore.put(hash, blockMessage.encoded);
900
+ await chainStore.put('lastBlock', hash);
901
+ debug(`created block: ${hash}`);
902
+
903
+ peernet.publish('add-block', blockMessage.encoded);
904
+ this.#updateState(blockMessage);
905
+ } catch (e) {
906
+ console.log(e);
907
+ throw Error(`invalid block ${block}`)
908
+ }
909
+ // data = await this.#machine.execute(to, method, params)
910
+ // transactionStore.put(message.hash, message.encoded)
911
+ }
912
+
913
+ async promiseTransactions(transactions) {
914
+ transactions = await Promise.all(transactions.map(tx => new TransactionMessage(tx)));
915
+ return transactions
916
+ }
917
+
918
+ async promiseTransactionsContent(transactions) {
919
+ transactions = await Promise.all(transactions.map(tx => new Promise(async (resolve, reject) => {
920
+ resolve({ ...tx.decoded, hash: await tx.hash });
921
+ })));
922
+
923
+ return transactions
924
+ }
925
+
926
+ async #getNonceFallback(address) {
927
+ let transactions = await transactionPoolStore.values();
928
+ transactions = await this.promiseTransactions(transactions);
929
+ transactions = transactions.filter(tx => tx.decoded.from === address);
930
+ transactions = await this.promiseTransactionsContent(transactions);
931
+
932
+ if (this.lastBlock?.hash && transactions.length === 0 && this.lastBlock.hash !== '0x0') {
933
+
934
+ let block = await peernet.get(this.lastBlock.hash);
935
+ block = await new BlockMessage(block);
936
+
937
+ // for (let tx of block.decoded?.transactions) {
938
+ // tx = await peernet.get(tx, 'transaction')
939
+ // transactions.push(new TransactionMessage(tx))
940
+ // }
941
+ transactions = transactions.filter(tx => tx.from === address);
942
+ while (transactions.length === 0 && block.decoded.index !== 0 && block.decoded.previousHash !== '0x0') {
943
+ block = await blockStore.get(block.decoded.previousHash);
944
+ block = await new BlockMessage(block);
945
+ transactions = block.decoded.transactions.filter(tx => tx.from === address);
946
+ }
947
+
948
+ }
949
+ if (transactions.length === 0) return 0
950
+
951
+ transactions = transactions.sort((a, b) => a.timestamp - b.timestamp);
952
+ return transactions[transactions.length - 1].nonce
953
+ }
954
+
955
+ async getNonce(address) {
956
+ if (!await accountsStore.has(address)) {
957
+ const nonce = await this.#getNonceFallback(address);
958
+ await accountsStore.put(address, new TextEncoder().encode(String(nonce)));
959
+ }
960
+ let nonce = await accountsStore.get(address);
961
+ nonce = new TextDecoder().decode(nonce);
962
+ return Number(nonce)
963
+ }
964
+
965
+ /**
966
+ * whenever method = createContract params should hold the contract hash
967
+ *
968
+ * example: [hash]
969
+ * createTransaction('0x0', 'createContract', [hash])
970
+ *
971
+ * @param {String} to - the contract address for the contract to interact with
972
+ * @param {String} method - the method/function to run
973
+ * @param {Array} params - array of paramters to apply to the contract method
974
+ * @param {Number} nonce - total transaction count [optional]
975
+ */
976
+ async createTransaction(to, method, params, nonce, signature) {
977
+ return this.createTransactionFrom(peernet.id, to, method, params, nonce)
978
+ }
979
+
980
+
981
+
982
+ /**
983
+ *
984
+ * @param {Object} transaction {}
985
+ * @param {String} transaction.from address
986
+ * @param {String} transaction.to address
987
+ * @param {Object} transaction.params {}
988
+ * @param {String} transaction.params.method get, call
989
+ * @param {Buffer} transaction.params.data
990
+ * @returns
991
+ */
992
+ async createTransactionHash(transaction) {
993
+ // todo: validate
994
+ const peernetHash = await new CodecHash(transaction, {name: 'transaction-message'});
995
+ return peernetHash.digest
996
+ }
997
+
998
+ /**
999
+ * @params {object} transaction -
1000
+ * @params {object} wallet - any wallet/signer that supports sign(RAWtransaction)
1001
+ */
1002
+ async #signTransaction (transaction, wallet) {
1003
+ return wallet.sign(await this.createTransactionHash(transaction))
1004
+ }
1005
+
1006
+ async signTransaction(transaction, signer) {
1007
+ let identity = await walletStore.get('identity');
1008
+ identity = JSON.parse(new TextDecoder().decode(identity));
1009
+ const wallet = new MultiWallet(peernet.network);
1010
+ wallet.recover(identity.mnemonic);
1011
+ const account = wallet.account(0).external(0);
1012
+ transaction.signature = await this.#signTransaction(transaction, account);
1013
+ transaction.signature = bs32.encode(transaction.signature);
1014
+ return transaction
1015
+ }
1016
+
1017
+ /**
1018
+ *
1019
+ * @param {Object} transaction
1020
+ * @param {Address} transaction.from
1021
+ * @param {Address} transaction.to
1022
+ * @param {String} transaction.method
1023
+ * @param {Array} transaction.params
1024
+ * @param {Number} transaction.nonce
1025
+ *
1026
+ * @returns {Object} transaction
1027
+ */
1028
+ async createRawTransaction(transaction) {
1029
+ if (!transaction.from) transaction.from = peernet.id;
1030
+ transaction.timestamp = Date.now();
1031
+
1032
+ if (transaction.nonce === undefined) {
1033
+ transaction.nonce = await this.getNonce(transaction.from);
1034
+ transaction.nonce += 1;
1035
+ await accountsStore.put(transaction.from, new TextEncoder().encode(String(transaction.nonce)));
1036
+ } else {
1037
+ let nonce = await accountsStore.get(transaction.from);
1038
+ nonce = new TextDecoder().decode(nonce);
1039
+ if (transaction.nonce < nonce) throw Error(`a transaction with a higher nonce already exists`)
1040
+ if (transaction.nonce === nonce) throw Error(`a transaction with the same nonce already exists`)
1041
+ }
1042
+ return transaction
1043
+ }
1044
+ /**
1045
+ * every tx done is trough contracts so no need for amount
1046
+ * data is undefined when nothing is returned
1047
+ * error is thrown on error so undefined data doesn't mean there is an error...
1048
+ *
1049
+ * @param {String} from - the sender address
1050
+ * @param {String} to - the contract address for the contract to interact with
1051
+ * @param {String} method - the method/function to run
1052
+ * @param {Array} params - array of paramters to apply to the contract method
1053
+ * @param {Number} nonce - total transaction count [optional]
1054
+ */
1055
+ async createTransactionFrom(from, to, method, params, nonce) {
1056
+ try {
1057
+
1058
+ const rawTransaction = await this.createRawTransaction({from, to, nonce, method, params});
1059
+ const transaction = await this.signTransaction(rawTransaction, from);
1060
+ const message = await new TransactionMessage(transaction);
1061
+
1062
+ let data;
1063
+ // await transactionPoolStore.put(message.hash, new TextEncoder().encode(JSON.stringify({signature, message: message.encoded})))
1064
+ const wait = () => new Promise(async (resolve, reject) => {
1065
+ if (pubsub.subscribers[`transaction.completed.${await message.hash}`]) {
1066
+ const result = pubsub.subscribers[`transaction.completed.${await message.hash}`].value;
1067
+ result.status === 'fulfilled' ? resolve(await result.hash) : reject({hash: await result.hash, error: result.error});
1068
+ } else {
1069
+ const completed = async result => {
1070
+ result.status === 'fulfilled' ? resolve(await result.hash) : reject({hash: await result.hash, error: result.error});
1071
+
1072
+ setTimeout(async () => {
1073
+ pubsub.unsubscribe(`transaction.completed.${await message.hash}`, completed);
1074
+ }, 10000);
1075
+ };
1076
+ pubsub.subscribe(`transaction.completed.${await message.hash}`, completed);
1077
+ }
1078
+
1079
+
1080
+ });
1081
+
1082
+ await transactionPoolStore.put(await message.hash, message.encoded);
1083
+ peernet.publish('add-transaction', message.encoded);
1084
+ this.#addTransaction(message.encoded);
1085
+ return {hash: await message.hash, data, fee: await calculateFee(message.decoded), wait}
1086
+ } catch (e) {
1087
+ console.log(e);
1088
+ console.log(e);
1089
+ throw e
1090
+ }
1091
+
1092
+ }
1093
+
1094
+ async createContractMessage(creator, contract, constructorParameters = []) {
1095
+ return createContractMessage(creator, contract, constructorParameters = [])
1096
+ }
1097
+
1098
+ async createContractAddress(creator, contract, constructorParameters = []) {
1099
+ contract = await this.createContractMessage(creator, contract, constructorParameters);
1100
+ return contract.hash
1101
+ }
1102
+
1103
+ /**
1104
+ *
1105
+ * @param {String} contract - a contract string (see plugins/deployContract)
1106
+ */
1107
+ async deployContract(contract, params = []) {
1108
+ globalThis.msg = {sender: peernet.id, call: this.call};
1109
+
1110
+ const hash = await this.createContractAddress(creator, contract, params);
1111
+ console.log(hash);
1112
+ try {
1113
+ const tx = await this.createTransactionFrom(peernet.id, addresses.contractFactory, 'deployContract', [hash, creator, contract, constructorParameters]);
1114
+ } catch (e) {
1115
+ throw e
1116
+ }
1117
+ return this.#machine.addContract(message)
1118
+ }
1119
+
1120
+ #createMessage(sender = peernet.id) {
1121
+ return {
1122
+ sender: peernet.id,
1123
+ call: this.call,
1124
+ staticCall: this.staticCall,
1125
+ delegate: this.delegate,
1126
+ staticDelegate: this.staticDelegate
1127
+ }
1128
+ }
1129
+
1130
+ internalCall(sender, contract, method, params) {
1131
+ globalThis.msg = this.#createMessage(sender);
1132
+
1133
+ return this.#machine.execute(contract, method, params)
1134
+ }
1135
+
1136
+ call(contract, method, params) {
1137
+ globalThis.msg = this.#createMessage();
1138
+
1139
+ return this.#machine.execute(contract, method, params)
1140
+ }
1141
+
1142
+ staticCall(contract, method, params) {
1143
+ globalThis.msg = this.#createMessage();
1144
+ return this.#machine.get(contract, method, params)
1145
+ }
1146
+
1147
+ delegate(contract, method, params) {
1148
+ globalThis.msg = this.#createMessage();
1149
+
1150
+ return this.#machine.execute(contract, method, params)
1151
+ }
1152
+
1153
+ staticDelegate(contract, method, params) {
1154
+ globalThis.msg = this.#createMessage();
1155
+
1156
+ return this.#machine.get(contract, method, params)
1157
+ }
1158
+
1159
+ mint(to, amount) {
1160
+ return this.call(addresses.nativeToken, 'mint', [to, amount])
1161
+ }
1162
+
1163
+ transfer(from, to, amount) {
1164
+ return this.call(addresses.nativeToken, 'transfer', [from, to, amount])
1165
+ }
1166
+
1167
+ get balances() {
1168
+ return this.staticCall(addresses.nativeToken, 'balances')
1169
+ }
1170
+
1171
+ deleteAll() {
1172
+ return this.#machine.deleteAll()
1173
+ }
1174
+
1175
+ /**
1176
+ * lookup an address for a registered name using the builtin nameService
1177
+ * @check nameService
1178
+ *
1179
+ * @param {String} - contractName
1180
+ * @returns {String} - address
1181
+ *
1182
+ * @example chain.lookup('myCoolContractName') // qmqsfddfdgfg...
1183
+ */
1184
+ lookup(name) {
1185
+ return this.call(addresses.nameService, 'lookup', [name])
1186
+ }
1187
+ }
1188
+
1189
+ export { Chain as default };