@leofcoin/chain 1.0.22 → 1.0.25

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 (94) hide show
  1. package/dist/chain.browser.js +26539 -9161
  2. package/dist/chain.js +474 -118
  3. package/dist/node.browser.js +3603 -3912
  4. package/dist/node.js +1 -1
  5. package/dist/protons.browser.js +7818 -175
  6. package/dist/wrtc.browser.js +1 -1
  7. package/docs/@leofcoin/chain/1.0.22/chain.js.html +377 -223
  8. package/docs/@leofcoin/chain/1.0.22/contracts_factory.js.html +123 -123
  9. package/docs/@leofcoin/chain/1.0.22/contracts_nameService.js.html +123 -123
  10. package/docs/@leofcoin/chain/1.0.22/contracts_proxies_factoryProxy.js.html +123 -123
  11. package/docs/@leofcoin/chain/1.0.22/contracts_proxies_nameServiceProxy.js.html +123 -123
  12. package/docs/@leofcoin/chain/1.0.22/contracts_proxies_nativeTokenProxy.js.html +123 -123
  13. package/docs/@leofcoin/chain/1.0.22/contracts_proxies_validatorsProxy.js.html +123 -123
  14. package/docs/@leofcoin/chain/1.0.22/contracts_proxies_votingProxy.js.html +123 -123
  15. package/docs/@leofcoin/chain/1.0.22/contracts_validators.js.html +123 -123
  16. package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Bold-webfont.svg +1829 -1829
  17. package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-BoldItalic-webfont.svg +1829 -1829
  18. package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Italic-webfont.svg +1829 -1829
  19. package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Light-webfont.svg +1830 -1830
  20. package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-LightItalic-webfont.svg +1834 -1834
  21. package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Regular-webfont.svg +1830 -1830
  22. package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Semibold-webfont.svg +1829 -1829
  23. package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-SemiboldItalic-webfont.svg +1829 -1829
  24. package/docs/@leofcoin/chain/1.0.22/global.html +1804 -1152
  25. package/docs/@leofcoin/chain/1.0.22/icons/home.svg +3 -3
  26. package/docs/@leofcoin/chain/1.0.22/icons/search.svg +3 -3
  27. package/docs/@leofcoin/chain/1.0.22/index.html +124 -124
  28. package/docs/@leofcoin/chain/1.0.22/machine.js.html +133 -129
  29. package/docs/@leofcoin/chain/1.0.22/scripts/linenumber.js +23 -23
  30. package/docs/@leofcoin/chain/1.0.22/scripts/pagelocation.js +89 -89
  31. package/docs/@leofcoin/chain/1.0.22/standards_roles.js.html +123 -123
  32. package/docs/@leofcoin/chain/1.0.22/standards_token.js.html +123 -123
  33. package/docs/@leofcoin/chain/1.0.22/styles/collapse.css +27 -27
  34. package/docs/@leofcoin/chain/1.0.22/styles/jsdoc-default.css +953 -953
  35. package/docs/@leofcoin/chain/1.0.22/styles/prettify-jsdoc.css +111 -111
  36. package/docs/@leofcoin/chain/1.0.22/styles/prettify-tomorrow.css +138 -138
  37. package/docs/@leofcoin/chain/1.0.24/chain.js.html +891 -0
  38. package/docs/@leofcoin/chain/1.0.24/contracts_factory.js.html +182 -0
  39. package/docs/@leofcoin/chain/1.0.24/contracts_nameService.js.html +231 -0
  40. package/docs/@leofcoin/chain/1.0.24/contracts_proxies_factoryProxy.js.html +135 -0
  41. package/docs/@leofcoin/chain/1.0.24/contracts_proxies_nameServiceProxy.js.html +135 -0
  42. package/docs/@leofcoin/chain/1.0.24/contracts_proxies_nativeTokenProxy.js.html +135 -0
  43. package/docs/@leofcoin/chain/1.0.24/contracts_proxies_validatorsProxy.js.html +135 -0
  44. package/docs/@leofcoin/chain/1.0.24/contracts_proxies_votingProxy.js.html +135 -0
  45. package/docs/@leofcoin/chain/1.0.24/contracts_validators.js.html +242 -0
  46. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Bold-webfont.eot +0 -0
  47. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Bold-webfont.svg +1830 -0
  48. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Bold-webfont.woff +0 -0
  49. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
  50. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-BoldItalic-webfont.svg +1830 -0
  51. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
  52. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Italic-webfont.eot +0 -0
  53. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Italic-webfont.svg +1830 -0
  54. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Italic-webfont.woff +0 -0
  55. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Light-webfont.eot +0 -0
  56. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Light-webfont.svg +1831 -0
  57. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Light-webfont.woff +0 -0
  58. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-LightItalic-webfont.eot +0 -0
  59. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-LightItalic-webfont.svg +1835 -0
  60. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-LightItalic-webfont.woff +0 -0
  61. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Regular-webfont.eot +0 -0
  62. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Regular-webfont.svg +1831 -0
  63. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Regular-webfont.woff +0 -0
  64. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Semibold-webfont.eot +0 -0
  65. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Semibold-webfont.svg +1830 -0
  66. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Semibold-webfont.ttf +0 -0
  67. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Semibold-webfont.woff +0 -0
  68. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-SemiboldItalic-webfont.eot +0 -0
  69. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-SemiboldItalic-webfont.svg +1830 -0
  70. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-SemiboldItalic-webfont.ttf +0 -0
  71. package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-SemiboldItalic-webfont.woff +0 -0
  72. package/docs/@leofcoin/chain/1.0.24/global.html +1805 -0
  73. package/docs/@leofcoin/chain/1.0.24/icons/home.svg +4 -0
  74. package/docs/@leofcoin/chain/1.0.24/icons/search.svg +4 -0
  75. package/docs/@leofcoin/chain/1.0.24/index.html +125 -0
  76. package/docs/@leofcoin/chain/1.0.24/machine.js.html +255 -0
  77. package/docs/@leofcoin/chain/1.0.24/scripts/linenumber.js +23 -0
  78. package/docs/@leofcoin/chain/1.0.24/scripts/pagelocation.js +89 -0
  79. package/docs/@leofcoin/chain/1.0.24/standards_roles.js.html +188 -0
  80. package/docs/@leofcoin/chain/1.0.24/standards_token.js.html +260 -0
  81. package/docs/@leofcoin/chain/1.0.24/styles/collapse.css +27 -0
  82. package/docs/@leofcoin/chain/1.0.24/styles/jsdoc-default.css +953 -0
  83. package/docs/@leofcoin/chain/1.0.24/styles/prettify-jsdoc.css +111 -0
  84. package/docs/@leofcoin/chain/1.0.24/styles/prettify-tomorrow.css +138 -0
  85. package/package.json +7 -5
  86. package/rollup.config.js +1 -2
  87. package/src/chain.js +254 -100
  88. package/src/config/config.js +11 -12
  89. package/src/machine.js +10 -6
  90. package/src/node.js +2 -34
  91. package/src/state.js +8 -3
  92. package/src/transactions/transaction.js +3 -0
  93. package/test/chain.js +39 -60
  94. package/webpack.config.js +3 -3
package/dist/chain.js CHANGED
@@ -2,8 +2,178 @@
2
2
 
3
3
  var utils = require('@leofcoin/utils');
4
4
  require('vm');
5
+ var codecFormatInterface = require('@leofcoin/codec-format-interface');
6
+ require('@ethersproject/bignumber');
7
+ require('@ethersproject/units');
5
8
  var messages = require('@leofcoin/messages');
6
- var lib$1 = require('@leofcoin/lib');
9
+ var addresses$1 = require('@leofcoin/addresses');
10
+ var MultiWallet = require('@leofcoin/multi-wallet');
11
+ var index = require('@leofcoin/codec-format-interface/dist/index');
12
+ var bs32 = require('@vandeurenglenn/base32');
13
+
14
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
15
+
16
+ var MultiWallet__default = /*#__PURE__*/_interopDefaultLegacy(MultiWallet);
17
+ var bs32__default = /*#__PURE__*/_interopDefaultLegacy(bs32);
18
+
19
+ var proto$4 = `
20
+ message ContractMessage {
21
+ required string creator = 1;
22
+ required bytes contract = 2;
23
+ repeated string constructorParameters = 3;
24
+ }
25
+ `;
26
+
27
+ class ContractMessage extends codecFormatInterface.FormatInterface {
28
+ get keys() {
29
+ return ['creator', 'contract', 'constructorParameters']
30
+ }
31
+
32
+ get messageName() {
33
+ return 'ContractMessage'
34
+ }
35
+
36
+ constructor(buffer) {
37
+ super(buffer, proto$4, {name: 'contract-message'});
38
+ }
39
+ }
40
+
41
+ var proto$3 = `
42
+
43
+ message TransactionMessage {
44
+ required uint64 timestamp = 1;
45
+ required string from = 2;
46
+ required string to = 3;
47
+ required uint64 nonce = 4;
48
+ required string method = 5;
49
+ repeated string params = 6;
50
+ required string signature = 7;
51
+ }
52
+ `;
53
+
54
+ class TransactionMessage extends codecFormatInterface.FormatInterface {
55
+ get keys() {
56
+ return ['timestamp', 'from', 'to', 'nonce', 'method', 'params', 'signature']
57
+ }
58
+
59
+ get messageName() {
60
+ return 'TransactionMessage'
61
+ }
62
+
63
+ constructor(buffer) {
64
+ const name = 'transaction-message';
65
+ super(buffer, proto$3, {name});
66
+ }
67
+ }
68
+
69
+ var proto$2 = `
70
+ message ValidatorMessage {
71
+ required string address = 1;
72
+ required string reward = 2;
73
+ }
74
+
75
+ message Transaction {
76
+ required string hash = 1;
77
+ required uint64 timestamp = 2;
78
+ required string from = 3;
79
+ required string to = 4;
80
+ required uint64 nonce = 5;
81
+ required string method = 6;
82
+ repeated string params = 7;
83
+ }
84
+
85
+ message BlockMessage {
86
+ required uint64 index = 1;
87
+ required string previousHash = 3;
88
+ required uint64 timestamp = 4;
89
+ required uint64 reward = 5;
90
+ required string fees = 6;
91
+ repeated Transaction transactions = 7;
92
+ repeated ValidatorMessage validators = 8;
93
+ }
94
+ `;
95
+
96
+ class BlockMessage extends codecFormatInterface.FormatInterface {
97
+ get keys() {
98
+ return ['index', 'previousHash', 'timestamp', 'reward', 'fees', 'transactions', 'validators']
99
+ }
100
+
101
+ get messageName() {
102
+ return 'BlockMessage'
103
+ }
104
+
105
+ constructor(buffer) {
106
+ const name = 'block-message';
107
+ super(buffer, proto$2, {name});
108
+ }
109
+ }
110
+
111
+ var proto$1 = `
112
+
113
+ message BWMessage {
114
+ required uint64 up = 1;
115
+ required uint64 down = 2;
116
+ }
117
+ `;
118
+
119
+ class BWMessage extends codecFormatInterface.FormatInterface {
120
+ get keys() {
121
+ return ['up', 'down']
122
+ }
123
+
124
+ get messageName() {
125
+ return 'BWMessage'
126
+ }
127
+
128
+ constructor(buffer) {
129
+ const name = 'bw-message';
130
+ super(buffer, proto$1, {name});
131
+ }
132
+ }
133
+
134
+ var proto = `
135
+
136
+ message BWRequestMessage {
137
+ }
138
+ `;
139
+
140
+ class BWRequestMessage extends codecFormatInterface.FormatInterface {
141
+ get keys() {
142
+ return []
143
+ }
144
+
145
+ get messageName() {
146
+ return 'BWRequestMessage'
147
+ }
148
+
149
+ constructor(buffer) {
150
+ const name = 'bw-request-message';
151
+ super(buffer, proto, {name});
152
+ }
153
+ }
154
+
155
+ var contractFactory$1 = "ba5xdac4ybttixammtscsptfsvtqwnzuaw5p6eghn2sh7tf5dskqtdghjc";
156
+ var nativeToken$1 = "ba5xdad2t57fpdadkrumwht32uwcdubjppq6z2vkwomgowfjpzmjbn2wo2";
157
+ var nameService$1 = "ba5xdadb3f2jptnup2j6ev6usz4vs6p5vo7vst5hj7r4ddkhdxpnvebxvh";
158
+ var validators$1 = "ba5xdacicpruzh4lu6je5mfn42f6s4y7tboxosyrspxmner5wjma5bvntn";
159
+ var addresses = {
160
+ contractFactory: contractFactory$1,
161
+ nativeToken: nativeToken$1,
162
+ nameService: nameService$1,
163
+ validators: validators$1
164
+ };
165
+
166
+ const byteFormats = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
167
+
168
+ const formatBytes = (bytes, decimals = 2) => {
169
+ if (bytes === 0) return '0 Bytes';
170
+ if (decimals < 0) decimals = 0;
171
+
172
+ const k = 1024;
173
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
174
+
175
+ return `${parseFloat((bytes / Math.pow(k, i)).toFixed(decimals))} ${byteFormats[i]}`
176
+ };
7
177
 
8
178
  // import State from './state'
9
179
 
@@ -26,15 +196,18 @@ class Machine {
26
196
  // return
27
197
  try {
28
198
  let contracts = [
29
- contractStore.get(lib$1.contractFactory),
30
- contractStore.get(lib$1.nativeToken),
31
- contractStore.get(lib$1.validators),
32
- contractStore.get(lib$1.nameService)
199
+ contractStore.get(contractFactory$1),
200
+ contractStore.get(nativeToken$1),
201
+ contractStore.get(validators$1),
202
+ contractStore.get(nameService$1)
33
203
  ];
34
204
 
35
205
  contracts = await Promise.all(contracts);
206
+ console.log(contracts);
36
207
  for (const contract of contracts) {
37
- const message = await new messages.ContractMessage(new Uint8Array(contract.buffer, contract.buffer.byteOffset, contract.buffer.byteLength));
208
+
209
+ const message = await new ContractMessage(new Uint8Array(contract.buffer, contract.buffer.byteOffset, contract.buffer.byteLength));
210
+ console.log(message);
38
211
  await this.#runContract(message);
39
212
  }
40
213
  } catch (e) {
@@ -55,6 +228,7 @@ console.log(e);
55
228
  }
56
229
 
57
230
  async #runContract(contractMessage) {
231
+ console.log(contractMessage);
58
232
  const params = contractMessage.decoded.constructorParameters;
59
233
  try {
60
234
 
@@ -63,16 +237,15 @@ console.log(e);
63
237
 
64
238
  globalThis.msg = this.#createMessage(contractMessage.decoded.creator);
65
239
  // globalThis.msg = {sender: contractMessage.decoded.creator}
66
- this.#contracts[contractMessage.hash] = new Contract(...params);
67
- debug(`loaded contract: ${contractMessage.hash}`);
68
- debug(`size: ${Math.round((contractMessage.encoded.length / 1024) * 100) / 100} kb`);
240
+ this.#contracts[await contractMessage.hash] = await new Contract(...params);
241
+ debug(`loaded contract: ${await contractMessage.hash}`);
242
+ debug(`size: ${formatBytes(contractMessage.encoded.length)}`);
69
243
  } catch (e) {
70
244
  console.log(e);
71
245
  console.warn(`removing contract ${contractMessage.hash}`);
72
246
  await contractStore.delete(contractMessage.hash, contractMessage.encoded);
73
247
  }
74
248
  }
75
-
76
249
  /**
77
250
  * @params {ContractMessage} - contractMessage
78
251
  */
@@ -131,6 +304,42 @@ console.log(e);
131
304
  }
132
305
  }
133
306
 
307
+ var contractFactory = "237,198,1,10,54,51,67,122,86,50,109,72,55,122,115,71,66,119,54,122,122,71,99,53,69,102,111,109,116,76,78,114,116,75,78,51,103,78,90,77,98,69,99,112,89,118,83,82,75,115,52,106,85,90,68,116,118,71,121,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";
308
+ var nativeToken = "237,198,1,10,54,51,67,122,86,50,109,72,55,122,115,71,66,119,54,122,122,71,99,53,69,102,111,109,116,76,78,114,116,75,78,51,103,78,90,77,98,69,99,112,89,118,83,82,75,115,52,106,85,90,68,116,118,71,121,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";
309
+ var nameService = "237,198,1,10,54,51,67,122,86,50,109,72,55,122,115,71,66,119,54,122,122,71,99,53,69,102,111,109,116,76,78,114,116,75,78,51,103,78,90,77,98,69,99,112,89,118,83,82,75,115,52,106,85,90,68,116,118,71,121,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,99,52,121,98,116,116,105,120,97,109,109,116,115,99,115,112,116,102,115,118,116,113,119,110,122,117,97,119,53,112,54,101,103,104,110,50,115,104,55,116,102,53,100,115,107,113,116,100,103,104,106,99,26,58,98,97,53,120,100,97,100,50,116,53,55,102,112,100,97,100,107,114,117,109,119,104,116,51,50,117,119,99,100,117,98,106,112,112,113,54,122,50,118,107,119,111,109,103,111,119,102,106,112,122,109,106,98,110,50,119,111,50,26,58,98,97,53,120,100,97,99,105,99,112,114,117,122,104,52,108,117,54,106,101,53,109,102,110,52,50,102,54,115,52,121,55,116,98,111,120,111,115,121,114,115,112,120,109,110,101,114,53,119,106,109,97,53,98,118,110,116,110,26,17,48,46,48,48,48,48,48,48,48,48,48,48,48,48,48,48,49";
310
+ var validators = "237,198,1,10,54,51,67,122,86,50,109,72,55,122,115,71,66,119,54,122,122,71,99,53,69,102,111,109,116,76,78,114,116,75,78,51,103,78,90,77,98,69,99,112,89,118,83,82,75,115,52,106,85,90,68,116,118,71,121,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,50,116,53,55,102,112,100,97,100,107,114,117,109,119,104,116,51,50,117,119,99,100,117,98,106,112,112,113,54,122,50,118,107,119,111,109,103,111,119,102,106,112,122,109,106,98,110,50,119,111,50";
311
+ var bytecodes = {
312
+ contractFactory: contractFactory,
313
+ nativeToken: nativeToken,
314
+ nameService: nameService,
315
+ validators: validators
316
+ };
317
+
318
+ const contractFactoryMessage = new Uint8Array(bytecodes.contractFactory.split(','));
319
+ const nativeTokenMessage = new Uint8Array(bytecodes.nativeToken.split(','));
320
+
321
+ const nameServiceMessage = new Uint8Array(bytecodes.nameService.split(','));
322
+ const validatorsMessage = new Uint8Array(bytecodes.validators.split(','));
323
+
324
+ const calculateFee = async transaction => {
325
+ // excluded from fees
326
+ if (transaction.to === addresses$1.validators) return 0
327
+ // fee per gb
328
+ transaction = await new messages.TransactionMessage(transaction);
329
+ let fee = transaction.encoded.length;
330
+ fee = fee / 1024;
331
+ fee = fee / 1000000;
332
+ const parts = String(fee).split('.');
333
+ let decimals = 0;
334
+ if (parts[1]) {
335
+ const potentional = parts[1].split('e');
336
+ parts[1] = potentional[0];
337
+ decimals = Number(potentional[1].replace(/\-|\+/g, '')) + Number(potentional[0].length);
338
+ }
339
+
340
+ return Number.parseFloat(fee.toString()).toFixed(decimals)
341
+ };
342
+
134
343
  globalThis.BigNumber = utils.BigNumber;
135
344
 
136
345
  // check if browser or local
@@ -154,7 +363,7 @@ class Chain {
154
363
  }
155
364
 
156
365
  get nativeToken() {
157
- return lib.nativeToken
366
+ return addresses.nativeToken
158
367
  }
159
368
 
160
369
  get validators() {
@@ -167,28 +376,39 @@ class Chain {
167
376
 
168
377
  async hasTransactionToHandle() {
169
378
  const size = await transactionPoolStore.size();
379
+ console.log({size});
170
380
  if (size > 0) return true
171
381
  return false
172
382
  }
173
383
 
174
384
  async #runEpoch() {
175
- const validators = await this.staticCall(lib.validators, 'validators');
385
+ this.#runningEpoch = true;
386
+ console.log('epoch');
387
+ const validators = await this.staticCall(addresses.validators, 'validators');
176
388
  if (!validators[peernet.id]?.active) return
389
+ console.log('active');
177
390
 
178
- this.#runningEpoch = true;
391
+
179
392
  const start = new Date().getTime();
180
- await this.#createBlock();
393
+ try {
394
+ await this.#createBlock();
395
+ } catch (e) {
396
+ console.error(e);
397
+ }
398
+
181
399
  const end = new Date().getTime();
182
- console.log((end - start) / 1000 + ' s');
400
+ console.log(((end - start) / 1000) + ' s');
401
+
183
402
  if (await this.hasTransactionToHandle()) return this.#runEpoch()
184
403
  this.#runningEpoch = false;
404
+ // if (await this.hasTransactionToHandle() && !this.#runningEpoch) return this.#runEpoch()
185
405
  }
186
406
 
187
407
  async #setup() {
188
- await contractStore.put(lib.contractFactory, lib.contractFactoryMessage);
189
- await contractStore.put(lib.nativeToken, lib.nativeTokenMessage);
190
- await contractStore.put(lib.validators, lib.validatorsMessage);
191
- await contractStore.put(lib.nameService, lib.nameServiceMessage);
408
+ await contractStore.put(addresses.contractFactory, contractFactoryMessage);
409
+ await contractStore.put(addresses.nativeToken, nativeTokenMessage);
410
+ await contractStore.put(addresses.validators, validatorsMessage);
411
+ await contractStore.put(addresses.nameService, nameServiceMessage);
192
412
  console.log('handle native contracts');
193
413
  // handle native contracts
194
414
  }
@@ -207,7 +427,6 @@ class Chain {
207
427
 
208
428
  promises = await Promise.allSettled(promises);
209
429
  promises = promises.reduce((set, c) => {
210
- console.log({c});
211
430
  if (c.index > set.index) {
212
431
  set.index = c.index;
213
432
  set.hash = c.hash;
@@ -220,7 +439,8 @@ class Chain {
220
439
  async #init() {
221
440
  // this.node = await new Node()
222
441
  this.participants = [];
223
- const initialized = await contractStore.has(lib.contractFactory);
442
+ this.participating = false;
443
+ const initialized = await contractStore.has(addresses.contractFactory);
224
444
  if (!initialized) await this.#setup();
225
445
 
226
446
  this.#machine = await new Machine();
@@ -229,8 +449,8 @@ class Chain {
229
449
  try {
230
450
  let localBlock = await chainStore.get('lastBlock');
231
451
  localBlock = await peernet.get(new TextDecoder().decode(localBlock));
232
- localBlock = await await new lib$1.BlockMessage(localBlock);
233
- this.#lastBlock = {...localBlock.decoded, hash: localBlock.hash};
452
+ localBlock = await await new BlockMessage(localBlock);
453
+ this.#lastBlock = {...localBlock.decoded, hash: await localBlock.hash};
234
454
  // console.log(this.lastBlock.decoded.transactions);
235
455
  } catch (e) {
236
456
  await this.#sync();
@@ -239,22 +459,14 @@ class Chain {
239
459
 
240
460
  await peernet.addRequestHandler('bw-request-message', () => {
241
461
 
242
- return new lib$1.BWMessage(peernet.client.bw) || { up: 0, down: 0 }
462
+ return new BWMessage(peernet.client.bw) || { up: 0, down: 0 }
243
463
  });
244
464
 
245
465
  await peernet.addRequestHandler('lastBlock', this.#lastBlockHandler.bind(this));
246
466
 
247
467
  peernet.subscribe('add-block', this.#addBlock.bind(this));
248
468
 
249
- peernet.subscribe('add-transaction', async transaction => {
250
- try {
251
- transaction = await new lib$1.TransactionMessage(transaction);
252
- await transactionPoolStore.put(transaction.hash, transaction.encoded);
253
- if (await this.hasTransactionToHandle() && !this.#runningEpoch) return this.#runEpoch()
254
- } catch (e) {
255
- throw Error('invalid transaction')
256
- }
257
- });
469
+ peernet.subscribe('add-transaction', this.#addTransaction.bind(this));
258
470
 
259
471
  pubsub.subscribe('peer:connected', this.#peerConnected.bind(this));
260
472
 
@@ -287,28 +499,41 @@ class Chain {
287
499
  this.#blocks.length;
288
500
  (this.#blocks.length) - blocksSynced;
289
501
  await this.#loadBlocks(this.#blocks);
290
- const message = await new lib$1.BlockMessage(this.lastBlock);
291
- await blockStore.put(message.hash, message.encoded);
502
+ const message = await new BlockMessage(this.lastBlock);
503
+ await blockStore.put(await message.hash, message.encoded);
292
504
  await chainStore.put('lastBlock', new TextEncoder().encode(this.lastBlock.hash));
293
505
  }
294
506
  }
295
507
 
296
- async #lastBlockHandler() {
297
- return new peernet.protos['peernet-response']({response: new TextEncoder().encode(JSON.stringify({ hash: this.lastBlock?.hash, index: this.lastBlock?.index }))})
298
- }
508
+ #epochTimeout
299
509
 
300
- async resolveBlock(hash) {
301
- let block = await peernet.get(hash, 'block');
302
- if (!await peernet.has(hash, 'block')) await peernet.put(hash, block, 'block');
303
- block = await new lib$1.BlockMessage(block);
304
- const size = block.encoded.length || block.encoded.byteLength;
305
- block = {...block.decoded, hash};
306
- this.#blocks[block.index] = block;
307
- console.log(`loaded block: ${hash} @${block.index} ${Math.round((size / 1024 / 1024) * 100) / 100} mb`);
308
- if (block.index !== 0) {
309
- return this.resolveBlock(block.previousHash)
310
- }
510
+ async #addTransaction(transaction) {
511
+ try {
512
+ transaction = await new TransactionMessage(transaction);
513
+ const has = await transactionPoolStore.has(await transaction.hash);
514
+ if (!has) await transactionPoolStore.put(await transaction.hash, transaction.encoded);
515
+ if (this.participating && !this.#runningEpoch) this.#runEpoch();
516
+ } catch (e) {
517
+ throw Error('invalid transaction')
311
518
  }
519
+ }
520
+
521
+ async #lastBlockHandler() {
522
+ return new peernet.protos['peernet-response']({response: new TextEncoder().encode(JSON.stringify({ hash: this.lastBlock?.hash, index: this.lastBlock?.index }))})
523
+ }
524
+
525
+ async resolveBlock(hash) {
526
+ let block = await peernet.get(hash, 'block');
527
+ if (!await peernet.has(hash, 'block')) await peernet.put(hash, block, 'block');
528
+ block = await new BlockMessage(block);
529
+ const size = block.encoded.length || block.encoded.byteLength;
530
+ block = {...block.decoded, hash};
531
+ this.#blocks[block.index] = block;
532
+ console.log(`loaded block: ${hash} @${block.index} ${formatBytes(size)}`);
533
+ if (block.index !== 0) {
534
+ return this.resolveBlock(block.previousHash)
535
+ }
536
+ }
312
537
 
313
538
  async resolveBlocks() {
314
539
  try {
@@ -373,7 +598,7 @@ class Chain {
373
598
  }
374
599
 
375
600
  async #addBlock(block) {
376
- const blockMessage = await new lib$1.BlockMessage(block);
601
+ const blockMessage = await new BlockMessage(block);
377
602
  // if (!Buffer.isBuffer(block)) block = Buffer.from(block, 'hex')
378
603
  // const transactionJob = async transaction => {
379
604
  // try {
@@ -389,14 +614,14 @@ class Chain {
389
614
  // return transaction
390
615
  // }
391
616
  await Promise.all(blockMessage.decoded.transactions
392
- .map(transaction => transactionPoolStore.delete(transaction.hash)));
393
-
617
+ .map(async transaction => transactionPoolStore.delete(await transaction.hash)));
618
+ const hash = await blockMessage.hash;
394
619
  // let transactions = blockMessage.decoded.transactions.map(tx => transactionJob(tx))
395
620
  // transactions = await Promise.all(transactions)
396
- this.#lastBlock = {hash: blockMessage.hash, ...blockMessage.decoded};
397
- await blockStore.put(blockMessage.hash, blockMessage.encoded);
398
- await chainStore.put('lastBlock', new TextEncoder().encode(blockMessage.hash));
399
- debug(`added block: ${blockMessage.hash}`);
621
+ this.#lastBlock = { hash, ...blockMessage.decoded };
622
+ await blockStore.put(hash, blockMessage.encoded);
623
+ await chainStore.put('lastBlock', new TextEncoder().encode(hash));
624
+ debug(`added block: ${hash}`);
400
625
  let promises = [];
401
626
  let contracts = [];
402
627
  for (let transaction of blockMessage.decoded.transactions) {
@@ -407,7 +632,10 @@ class Chain {
407
632
  }
408
633
  try {
409
634
  promises = await Promise.allSettled(promises);
410
-
635
+ for (let transaction of blockMessage.decoded.transactions) {
636
+ await accountsStore.put(transaction.from, new TextEncoder().encode(String(transaction.nonce)));
637
+ }
638
+
411
639
  // todo finish state
412
640
  // for (const contract of contracts) {
413
641
  // const state = await this.#machine.get(contract, 'state')
@@ -421,6 +649,10 @@ class Chain {
421
649
 
422
650
  }
423
651
 
652
+ async #updateState() {
653
+
654
+ }
655
+
424
656
 
425
657
 
426
658
  async participate() {
@@ -430,56 +662,72 @@ class Chain {
430
662
  // introduce peer-reputation
431
663
  // peerReputation(peerId)
432
664
  // {bandwith: {up, down}, uptime}
433
- if (!await this.staticCall(lib.validators, 'has', [peernet.id])) await this.createTransactionFrom(peernet.id, lib.validators, 'addValidator', [peernet.id]);
434
- if (await this.hasTransactionToHandle() && !this.#runningEpoch) return this.#runEpoch()
665
+ this.participating = true;
666
+ if (!await this.staticCall(addresses.validators, 'has', [peernet.id])) await this.createTransactionFrom(peernet.id, addresses.validators, 'addValidator', [peernet.id]);
667
+ if (await this.hasTransactionToHandle() && !this.#runningEpoch) await this.#runEpoch();
668
+
669
+ // const runEpoch = () => setTimeout(async () => {
670
+ // if (await this.hasTransactionToHandle() && !this.#runningEpoch) await this.#runEpoch()
671
+ // runEpoch()
672
+ // }, 5000)
673
+ // runEpoch()
435
674
  }
436
675
 
437
676
  calculateFee(transaction) {
438
677
  // excluded from fees
439
- if (transaction.decoded.to === lib.validators) return 0
678
+ // if (transaction.decoded.to === addresses.validators) return 0
440
679
  // fee per gb
441
680
  return (transaction.encoded.length / 1024) / 1e-6
442
681
  }
443
682
 
683
+ async getTransactions (transactions) {
684
+ return new Promise(async (resolve, reject) => {
685
+ let size = 0;
686
+ const _transactions = [];
687
+ const promises = await Promise.all(Object.values(transactions)
688
+ .map(tx => new TransactionMessage(new Uint8Array(tx, tx.byteOffset, tx.byteLength))));
689
+
690
+ for (let transaction of promises) {
691
+ size += transaction.encoded.length;
692
+ if ((size / 1024) / 1024 <= 1.15 ) _transactions.push({...transaction.decoded, hash: await transaction.hash });
693
+ else return resolve(_transactions)
694
+
695
+ }
696
+ return resolve(_transactions)
697
+ })
698
+
699
+ }
444
700
  async #createBlock() {
445
701
  let transactions = await transactionPoolStore.get();
446
702
 
447
703
  if (Object.keys(transactions)?.length === 0 ) return
704
+
448
705
  let block = {
449
706
  transactions: [],
450
707
  validators: [],
451
708
  fees: 0
452
709
  };
453
710
 
454
- let _transactions = [];
455
-
456
711
  // exclude failing tx
457
- for (let transaction of Object.values(transactions)) {
458
- transaction = await new lib$1.TransactionMessage(new Uint8Array(transaction, transaction.byteOffset, transaction.byteLength));
712
+ transactions = await this.getTransactions(transactions);
459
713
 
460
- block.fees += Number(lib.calculateFee(transaction));
461
- _transactions.push({...transaction.decoded, hash: transaction.hash });
462
- }
463
-
464
- transactions = _transactions.sort((a, b) => a.nonce - b.nonce);
465
- _transactions = [];
466
- for (let transaction of transactions) {
714
+ transactions = transactions.sort((a, b) => a.nonce - b.nonce);
715
+ for (let transaction of transactions) {
467
716
  try {
468
717
  await this.#executeTransaction(transaction);
469
- _transactions.push(transaction);
718
+ block.transactions.push(transaction);
719
+ block.fees += Number(calculateFee(transaction));
720
+ await accountsStore.put(transaction.from, new TextEncoder().encode(String(transaction.nonce)));
470
721
  } catch (e) {
471
- transaction = await new lib$1.TransactionMessage(transaction);
472
- block.fees -= Number(lib.calculateFee(transaction));
473
- await transactionPoolStore.delete(transaction.hash);
474
-
722
+ console.error(e);
723
+ transaction = await new TransactionMessage(transaction);
724
+ await transactionPoolStore.delete(await transaction.hash);
725
+ console.log(e);
475
726
  }
476
727
  }
477
- transactions = _transactions;
478
728
  // don't add empty block
479
- if (transactions.length === 0) return
480
-
481
- block.transactions = transactions;
482
- const validators = await this.staticCall(lib.validators, 'validators');
729
+ if (block.transactions.length === 0) return
730
+ const validators = await this.staticCall(addresses.validators, 'validators');
483
731
  console.log({validators});
484
732
  // block.validators = Object.keys(block.validators).reduce((set, key) => {
485
733
  // if (block.validators[key].active) {
@@ -496,7 +744,7 @@ class Chain {
496
744
  if (validators[validator].active) {
497
745
  const peer = peers[validator];
498
746
  if (peer && peer.connected) {
499
- let data = await new lib$1.BWRequestMessage();
747
+ let data = await new BWRequestMessage();
500
748
  const node = await peernet.prepareMessage(validator, data.encoded);
501
749
  try {
502
750
  const bw = await peer.request(node.encoded);
@@ -520,7 +768,7 @@ class Chain {
520
768
 
521
769
  }
522
770
 
523
- console.log(block.validators);
771
+ console.log({validators: block.validators});
524
772
 
525
773
  block.reward = 150;
526
774
  block.validators = block.validators.map(validator => {
@@ -528,7 +776,7 @@ class Chain {
528
776
  delete validator.bw;
529
777
  return validator
530
778
  });
531
- // block.validators = lib.calculateValidatorReward(block.validators, block.fees)
779
+ // block.validators = calculateValidatorReward(block.validators, block.fees)
532
780
 
533
781
  block.index = this.lastBlock?.index;
534
782
  if (block.index === undefined) block.index = 0;
@@ -552,25 +800,48 @@ class Chain {
552
800
  block.fees = Number.parseFloat(String(block.fees)).toFixed(decimals);
553
801
 
554
802
  try {
555
- let blockMessage = await new lib$1.BlockMessage(block);
556
- this.#lastBlock = {...block, hash: blockMessage.hash};
803
+ let blockMessage = await new BlockMessage(block);
804
+ const hash = await blockMessage.hash;
805
+ await Promise.all(blockMessage.decoded.transactions
806
+ .map(async transaction => transactionPoolStore.delete(await transaction.hash)));
807
+
808
+ this.#lastBlock = { hash, ...blockMessage.decoded };
809
+ await blockStore.put(hash, blockMessage.encoded);
810
+ await chainStore.put('lastBlock', new TextEncoder().encode(hash));
811
+ debug(`created block: ${hash}`);
812
+
557
813
  peernet.publish('add-block', blockMessage.encoded);
558
- this.#addBlock(blockMessage.encoded);
814
+ this.#updateState(blockMessage);
559
815
  } catch (e) {
816
+ console.log(e);
560
817
  throw Error(`invalid block ${block}`)
561
818
  }
562
819
  // data = await this.#machine.execute(to, method, params)
563
820
  // transactionStore.put(message.hash, message.encoded)
564
821
  }
565
822
 
566
- async getNonce(address) {
823
+ async promiseTransactions(transactions) {
824
+ transactions = await Promise.all(transactions.map(tx => new TransactionMessage(tx)));
825
+ return transactions
826
+ }
827
+
828
+ async promiseTransactionsContent(transactions) {
829
+ transactions = await Promise.all(transactions.map(tx => new Promise(async (resolve, reject) => {
830
+ resolve({ ...tx.decoded, hash: await tx.hash });
831
+ })));
832
+
833
+ return transactions
834
+ }
835
+
836
+ async #getNonceFallback(address) {
567
837
  let transactions = await transactionPoolStore.get();
568
- transactions = Object.keys(transactions).map(async tx => await new lib$1.TransactionMessage(transactions[tx]));
838
+ transactions = await this.promiseTransactions(Object.values(transactions));
569
839
  transactions = transactions.filter(tx => tx.decoded.from === address);
570
- transactions = transactions.map(tx => { return {...tx.decoded, hash: tx.hash} });
840
+ transactions = await this.promiseTransactionsContent(transactions);
841
+
571
842
  if (this.lastBlock && transactions.length === 0) {
572
843
  let block = await peernet.get(this.lastBlock.hash);
573
- block = await new lib$1.BlockMessage(block);
844
+ block = await new BlockMessage(block);
574
845
 
575
846
  // for (let tx of block.decoded?.transactions) {
576
847
  // tx = await peernet.get(tx, 'transaction')
@@ -579,7 +850,7 @@ class Chain {
579
850
  transactions = transactions.filter(tx => tx.from === address);
580
851
  while (transactions.length === 0 && block.decoded.index !== 0) {
581
852
  block = await blockStore.get(block.decoded.previousHash);
582
- block = await new lib$1.BlockMessage(block);
853
+ block = await new BlockMessage(block);
583
854
  transactions = block.decoded.transactions.filter(tx => tx.from === address);
584
855
  }
585
856
 
@@ -590,6 +861,16 @@ class Chain {
590
861
  return transactions[transactions.length - 1].nonce
591
862
  }
592
863
 
864
+ async getNonce(address) {
865
+ if (!await accountsStore.has(address)) {
866
+ const nonce = await this.#getNonceFallback(address);
867
+ await accountsStore.put(address, new TextEncoder().encode(String(nonce)));
868
+ }
869
+ let nonce = await accountsStore.get(address);
870
+ nonce = new TextDecoder().decode(nonce);
871
+ return Number(nonce)
872
+ }
873
+
593
874
  /**
594
875
  * whenever method = createContract params should hold the contract hash
595
876
  *
@@ -601,9 +882,74 @@ class Chain {
601
882
  * @param {Array} params - array of paramters to apply to the contract method
602
883
  * @param {Number} nonce - total transaction count [optional]
603
884
  */
604
- createTransaction(to, method, params, nonce) {
885
+ async createTransaction(to, method, params, nonce, signature) {
605
886
  return this.createTransactionFrom(peernet.id, to, method, params, nonce)
606
887
  }
888
+
889
+
890
+
891
+ /**
892
+ *
893
+ * @param {Object} transaction {}
894
+ * @param {String} transaction.from address
895
+ * @param {String} transaction.to address
896
+ * @param {Object} transaction.params {}
897
+ * @param {String} transaction.params.method get, call
898
+ * @param {Buffer} transaction.params.data
899
+ * @returns
900
+ */
901
+ async createTransactionHash(transaction) {
902
+ // todo: validate
903
+ const peernetHash = await new index.CodecHash(transaction, {name: 'transaction-message'});
904
+ return peernetHash.digest
905
+ }
906
+
907
+ /**
908
+ * @params {object} transaction -
909
+ * @params {object} wallet - any wallet/signer that supports sign(RAWtransaction)
910
+ */
911
+ async #signTransaction (transaction, wallet) {
912
+ return wallet.sign(await this.createTransactionHash(transaction))
913
+ }
914
+
915
+ async signTransaction(transaction, signer) {
916
+ let identity = await walletStore.get('identity');
917
+ identity = JSON.parse(new TextDecoder().decode(identity));
918
+ const wallet = new MultiWallet__default["default"](peernet.network);
919
+ wallet.recover(identity.mnemonic);
920
+ wallet.account(0).external(0);
921
+ transaction.signature = await this.#signTransaction(transaction, wallet);
922
+ transaction.signature = bs32__default["default"].encode(transaction.signature);
923
+ return transaction
924
+ }
925
+
926
+ /**
927
+ *
928
+ * @param {Object} transaction
929
+ * @param {Address} transaction.from
930
+ * @param {Address} transaction.to
931
+ * @param {String} transaction.method
932
+ * @param {Array} transaction.params
933
+ * @param {Number} transaction.nonce
934
+ *
935
+ * @returns {Object} transaction
936
+ */
937
+ async createRawTransaction(transaction) {
938
+ if (!transaction.from) transaction.from = peernet.id;
939
+ transaction.timestamp = Date.now();
940
+
941
+ if (transaction.nonce === undefined) {
942
+ transaction.nonce = await this.getNonce(transaction.from);
943
+ transaction.nonce += 1;
944
+ await accountsStore.put(transaction.from, new TextEncoder().encode(String(transaction.nonce)));
945
+ } else {
946
+ let nonce = await accountsStore.get(transaction.from);
947
+ nonce = new TextDecoder().decode(nonce);
948
+ if (transaction.nonce < nonce) throw Error(`a transaction with a higher nonce already exists`)
949
+ if (transaction.nonce === nonce) throw Error(`a transaction with the same nonce already exists`)
950
+ }
951
+ return transaction
952
+ }
607
953
  /**
608
954
  * every tx done is trough contracts so no need for amount
609
955
  * data is undefined when nothing is returned
@@ -616,35 +962,45 @@ class Chain {
616
962
  * @param {Number} nonce - total transaction count [optional]
617
963
  */
618
964
  async createTransactionFrom(from, to, method, params, nonce) {
619
- if (nonce === undefined) {
620
- nonce = await this.getNonce(from);
621
- nonce += 1;
622
- }
623
-
624
- let data;
625
- let message = await new lib$1.TransactionMessage({timestamp: new Date().getTime(), from, to, nonce, method, params});
626
965
  try {
966
+
967
+ const rawTransaction = await this.createRawTransaction({from, to, nonce, method, params});
968
+ const transaction = await this.signTransaction(rawTransaction, from);
969
+ const message = await new TransactionMessage(transaction);
970
+
971
+ let data;
627
972
  // await transactionPoolStore.put(message.hash, new TextEncoder().encode(JSON.stringify({signature, message: message.encoded})))
628
- await transactionPoolStore.put(message.hash, message.encoded);
973
+ const wait = () => new Promise(async (resolve, reject) => {
974
+ if (pubsub.subscribers[`transaction.completed.${await message.hash}`]) {
975
+ const result = pubsub.subscribers[`transaction.completed.${await message.hash}`].value;
976
+ result.status === 'fulfilled' ? resolve(await result.hash) : reject({hash: await result.hash, error: result.error});
977
+ } else {
978
+ const completed = async result => {
979
+ result.status === 'fulfilled' ? resolve(await result.hash) : reject({hash: await result.hash, error: result.error});
980
+
981
+ setTimeout(async () => {
982
+ pubsub.unsubscribe(`transaction.completed.${await message.hash}`, completed);
983
+ }, 10000);
984
+ };
985
+ pubsub.subscribe(`transaction.completed.${await message.hash}`, completed);
986
+ }
987
+
988
+
989
+ });
990
+
991
+ await transactionPoolStore.put(await message.hash, message.encoded);
629
992
  peernet.publish('add-transaction', message.encoded);
993
+ this.#addTransaction(message.encoded);
994
+ return {hash: await message.hash, data, fee: await calculateFee(message.decoded), wait}
630
995
  } catch (e) {
996
+ console.log(e);
631
997
  throw e
632
998
  }
633
- const wait = () => new Promise((resolve, reject) => {
634
- const completed = result => {
635
- result.status === 'fulfilled' ? resolve(result.hash) : reject({hash: result.hash, error: result.error});
636
-
637
- pubsub.unsubscribe(`transaction.completed.${message.hash}`, completed);
638
- };
639
- pubsub.subscribe(`transaction.completed.${message.hash}`, completed);
640
- });
641
-
642
- if (await this.hasTransactionToHandle() && !this.#runningEpoch) this.#runEpoch();
643
- return {hash: message.hash, data, fee: lib.calculateFee(message), wait}
999
+
644
1000
  }
645
1001
 
646
1002
  async createContractMessage(creator, contract, constructorParameters = []) {
647
- return new lib$1.ContractMessage({
1003
+ return new ContractMessage({
648
1004
  creator,
649
1005
  contract,
650
1006
  constructorParameters
@@ -666,7 +1022,7 @@ class Chain {
666
1022
  const hash = await this.createContractAddress(creator, contract, params);
667
1023
 
668
1024
  try {
669
- const tx = await this.createTransactionFrom(peernet.id, lib.contractFactory, 'deployContract', [hash, creator, contract, constructorParameters]);
1025
+ const tx = await this.createTransactionFrom(peernet.id, addresses.contractFactory, 'deployContract', [hash, creator, contract, constructorParameters]);
670
1026
  } catch (e) {
671
1027
  throw e
672
1028
  }
@@ -713,15 +1069,15 @@ class Chain {
713
1069
  }
714
1070
 
715
1071
  mint(to, amount) {
716
- return this.call(lib.nativeToken, 'mint', [to, amount])
1072
+ return this.call(addresses.nativeToken, 'mint', [to, amount])
717
1073
  }
718
1074
 
719
1075
  transfer(from, to, amount) {
720
- return this.call(lib.nativeToken, 'transfer', [from, to, amount])
1076
+ return this.call(addresses.nativeToken, 'transfer', [from, to, amount])
721
1077
  }
722
1078
 
723
1079
  get balances() {
724
- return this.staticCall(lib.nativeToken, 'balances')
1080
+ return this.staticCall(addresses.nativeToken, 'balances')
725
1081
  }
726
1082
 
727
1083
  deleteAll() {
@@ -738,7 +1094,7 @@ class Chain {
738
1094
  * @example chain.lookup('myCoolContractName') // qmqsfddfdgfg...
739
1095
  */
740
1096
  lookup(name) {
741
- return this.call(lib.nameService, 'lookup', [name])
1097
+ return this.call(addresses.nameService, 'lookup', [name])
742
1098
  }
743
1099
  }
744
1100