@leofcoin/chain 1.3.8 → 1.3.10

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.
@@ -48,6 +48,142 @@ const formatBytes = (bytes, decimals = 2) => {
48
48
  return `${parseFloat((bytes / Math.pow(k, i)).toFixed(decimals))} ${byteFormats[i]}`
49
49
  };
50
50
 
51
+ var proto$4 = `
52
+ message ContractMessage {
53
+ required string creator = 1;
54
+ required bytes contract = 2;
55
+ repeated string constructorParameters = 3;
56
+ }
57
+ `;
58
+
59
+ class ContractMessage extends FormatInterface {
60
+ get keys() {
61
+ return ['creator', 'contract', 'constructorParameters']
62
+ }
63
+
64
+ get messageName() {
65
+ return 'ContractMessage'
66
+ }
67
+
68
+ constructor(buffer) {
69
+ super(buffer, proto$4, {name: 'contract-message'});
70
+ }
71
+ }
72
+
73
+ var proto$3 = `
74
+
75
+ message TransactionMessage {
76
+ required uint64 timestamp = 1;
77
+ required string from = 2;
78
+ required string to = 3;
79
+ required uint64 nonce = 4;
80
+ required string method = 5;
81
+ repeated string params = 6;
82
+ required string signature = 7;
83
+ }
84
+ `;
85
+
86
+ class TransactionMessage extends FormatInterface {
87
+ get keys() {
88
+ return ['timestamp', 'from', 'to', 'nonce', 'method', 'params', 'signature']
89
+ }
90
+
91
+ get messageName() {
92
+ return 'TransactionMessage'
93
+ }
94
+
95
+ constructor(buffer) {
96
+ const name = 'transaction-message';
97
+ super(buffer, proto$3, {name});
98
+ }
99
+ }
100
+
101
+ var proto$2 = `
102
+ message ValidatorMessage {
103
+ required string address = 1;
104
+ required string reward = 2;
105
+ }
106
+
107
+ message Transaction {
108
+ required string hash = 1;
109
+ required uint64 timestamp = 2;
110
+ required string from = 3;
111
+ required string to = 4;
112
+ required uint64 nonce = 5;
113
+ required string method = 6;
114
+ repeated string params = 7;
115
+ }
116
+
117
+ message BlockMessage {
118
+ required uint64 index = 1;
119
+ required string previousHash = 3;
120
+ required uint64 timestamp = 4;
121
+ required uint64 reward = 5;
122
+ required string fees = 6;
123
+ repeated Transaction transactions = 7;
124
+ repeated ValidatorMessage validators = 8;
125
+ }
126
+ `;
127
+
128
+ class BlockMessage extends FormatInterface {
129
+ get keys() {
130
+ return ['index', 'previousHash', 'timestamp', 'reward', 'fees', 'transactions', 'validators']
131
+ }
132
+
133
+ get messageName() {
134
+ return 'BlockMessage'
135
+ }
136
+
137
+ constructor(buffer) {
138
+ const name = 'block-message';
139
+ super(buffer, proto$2, {name});
140
+ }
141
+ }
142
+
143
+ var proto$1 = `
144
+
145
+ message BWMessage {
146
+ required uint64 up = 1;
147
+ required uint64 down = 2;
148
+ }
149
+ `;
150
+
151
+ class BWMessage extends FormatInterface {
152
+ get keys() {
153
+ return ['up', 'down']
154
+ }
155
+
156
+ get messageName() {
157
+ return 'BWMessage'
158
+ }
159
+
160
+ constructor(buffer) {
161
+ const name = 'bw-message';
162
+ super(buffer, proto$1, {name});
163
+ }
164
+ }
165
+
166
+ var proto = `
167
+
168
+ message BWRequestMessage {
169
+ }
170
+ `;
171
+
172
+ class BWRequestMessage extends FormatInterface {
173
+ get keys() {
174
+ return []
175
+ }
176
+
177
+ get messageName() {
178
+ return 'BWRequestMessage'
179
+ }
180
+
181
+ constructor(buffer) {
182
+ const name = 'bw-request-message';
183
+ super(buffer, proto, {name});
184
+ }
185
+ }
186
+
51
187
  // import State from './state'
52
188
 
53
189
  class Machine {
@@ -152,18 +288,34 @@ class Machine {
152
288
  })
153
289
 
154
290
  }
291
+
155
292
  /**
156
- * @params {ContractMessage} - contractMessage
293
+ *
294
+ * @param {Address} contract
295
+ * @param {String} method
296
+ * @param {Array} parameters
297
+ * @returns Promise<message>
157
298
  */
158
- async addContract(contractMessage) {
159
- if (await contractStore.has(await contractMessage.hash)) throw new Error('duplicate contract')
160
-
161
- await contractStore.put(await contractMessage.hash, contractMessage.encoded);
162
- await this.#runContract(contractMessage);
163
- return contractMessage.hash
164
- }
165
-
166
299
  async execute(contract, method, parameters) {
300
+ try {
301
+ if (contract === contractFactory$1 && method === 'registerContract') {
302
+ if (this.#contracts[parameters[0]]) throw new Error(`duplicate contract @${parameters[0]}`)
303
+ let message;
304
+ if (!await contractStore.has(parameters[0])) {
305
+ message = await peernet.get(parameters[0], 'contract');
306
+ message = await new ContractMessage(message);
307
+ await contractStore.put(await message.hash, message.encoded);
308
+ }
309
+ if (!message) {
310
+ message = await contractStore.get(parameters[0]);
311
+ message = await new ContractMessage(message);
312
+ }
313
+ console.log(message);
314
+ if (!this.#contracts[await message.hash]) await this.#runContract(message);
315
+ }
316
+ } catch (error) {
317
+ throw new Error(`contract deployment failed for ${parameters[0]}\n${error.message}`)
318
+ }
167
319
  return new Promise((resolve, reject) => {
168
320
  const id = randomBytes(20).toString('hex');
169
321
  const onmessage = message => {
@@ -228,142 +380,6 @@ class Machine {
228
380
  }
229
381
  }
230
382
 
231
- var proto$4 = `
232
- message ContractMessage {
233
- required string creator = 1;
234
- required bytes contract = 2;
235
- repeated string constructorParameters = 3;
236
- }
237
- `;
238
-
239
- class ContractMessage extends FormatInterface {
240
- get keys() {
241
- return ['creator', 'contract', 'constructorParameters']
242
- }
243
-
244
- get messageName() {
245
- return 'ContractMessage'
246
- }
247
-
248
- constructor(buffer) {
249
- super(buffer, proto$4, {name: 'contract-message'});
250
- }
251
- }
252
-
253
- var proto$3 = `
254
-
255
- message TransactionMessage {
256
- required uint64 timestamp = 1;
257
- required string from = 2;
258
- required string to = 3;
259
- required uint64 nonce = 4;
260
- required string method = 5;
261
- repeated string params = 6;
262
- required string signature = 7;
263
- }
264
- `;
265
-
266
- class TransactionMessage extends FormatInterface {
267
- get keys() {
268
- return ['timestamp', 'from', 'to', 'nonce', 'method', 'params', 'signature']
269
- }
270
-
271
- get messageName() {
272
- return 'TransactionMessage'
273
- }
274
-
275
- constructor(buffer) {
276
- const name = 'transaction-message';
277
- super(buffer, proto$3, {name});
278
- }
279
- }
280
-
281
- var proto$2 = `
282
- message ValidatorMessage {
283
- required string address = 1;
284
- required string reward = 2;
285
- }
286
-
287
- message Transaction {
288
- required string hash = 1;
289
- required uint64 timestamp = 2;
290
- required string from = 3;
291
- required string to = 4;
292
- required uint64 nonce = 5;
293
- required string method = 6;
294
- repeated string params = 7;
295
- }
296
-
297
- message BlockMessage {
298
- required uint64 index = 1;
299
- required string previousHash = 3;
300
- required uint64 timestamp = 4;
301
- required uint64 reward = 5;
302
- required string fees = 6;
303
- repeated Transaction transactions = 7;
304
- repeated ValidatorMessage validators = 8;
305
- }
306
- `;
307
-
308
- class BlockMessage extends FormatInterface {
309
- get keys() {
310
- return ['index', 'previousHash', 'timestamp', 'reward', 'fees', 'transactions', 'validators']
311
- }
312
-
313
- get messageName() {
314
- return 'BlockMessage'
315
- }
316
-
317
- constructor(buffer) {
318
- const name = 'block-message';
319
- super(buffer, proto$2, {name});
320
- }
321
- }
322
-
323
- var proto$1 = `
324
-
325
- message BWMessage {
326
- required uint64 up = 1;
327
- required uint64 down = 2;
328
- }
329
- `;
330
-
331
- class BWMessage extends FormatInterface {
332
- get keys() {
333
- return ['up', 'down']
334
- }
335
-
336
- get messageName() {
337
- return 'BWMessage'
338
- }
339
-
340
- constructor(buffer) {
341
- const name = 'bw-message';
342
- super(buffer, proto$1, {name});
343
- }
344
- }
345
-
346
- var proto = `
347
-
348
- message BWRequestMessage {
349
- }
350
- `;
351
-
352
- class BWRequestMessage extends FormatInterface {
353
- get keys() {
354
- return []
355
- }
356
-
357
- get messageName() {
358
- return 'BWRequestMessage'
359
- }
360
-
361
- constructor(buffer) {
362
- const name = 'bw-request-message';
363
- super(buffer, proto, {name});
364
- }
365
- }
366
-
367
383
  var contractFactory = "237,198,141,3,123,34,99,114,101,97,116,111,114,34,58,34,56,71,85,107,103,52,120,87,113,109,110,83,56,75,101,122,56,107,54,68,115,82,120,90,66,68,97,54,114,71,74,109,104,107,122,67,75,113,78,75,102,85,110,103,90,122,109,54,97,81,34,44,34,99,111,110,116,114,97,99,116,34,58,34,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,97,115,121,110,99,32,114,101,103,105,115,116,101,114,67,111,110,116,114,97,99,116,40,97,100,100,114,101,115,115,41,123,105,102,40,97,119,97,105,116,32,109,115,103,46,115,116,97,116,105,99,67,97,108,108,40,97,100,100,114,101,115,115,44,92,34,104,97,115,82,111,108,101,92,34,44,91,109,115,103,46,115,101,110,100,101,114,44,92,34,79,87,78,69,82,92,34,93,41,44,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,46,105,110,99,108,117,100,101,115,40,97,100,100,114,101,115,115,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,92,34,97,108,114,101,97,100,121,32,114,101,103,105,115,116,101,114,101,100,92,34,41,59,116,104,105,115,46,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,43,61,49,44,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,46,112,117,115,104,40,97,100,100,114,101,115,115,41,125,125,114,101,116,117,114,110,32,70,97,99,116,111,114,121,59,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";
368
384
  var nativeToken = "237,198,141,3,123,34,99,114,101,97,116,111,114,34,58,34,56,71,85,107,103,52,120,87,113,109,110,83,56,75,101,122,56,107,54,68,115,82,120,90,66,68,97,54,114,71,74,109,104,107,122,67,75,113,78,75,102,85,110,103,90,122,109,54,97,81,34,44,34,99,111,110,116,114,97,99,116,34,58,34,99,108,97,115,115,32,82,111,108,101,115,123,35,114,111,108,101,115,61,123,79,87,78,69,82,58,91,93,44,77,73,78,84,58,91,93,44,66,85,82,78,58,91,93,125,59,99,111,110,115,116,114,117,99,116,111,114,40,114,111,108,101,115,41,123,105,102,40,114,111,108,101,115,41,123,105,102,40,33,40,114,111,108,101,115,32,105,110,115,116,97,110,99,101,111,102,32,79,98,106,101,99,116,41,41,116,104,114,111,119,32,110,101,119,32,84,121,112,101,69,114,114,111,114,40,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,116,104,105,115,46,35,114,111,108,101,115,91,114,111,108,101,93,46,105,110,99,108,117,100,101,115,40,97,100,100,114,101,115,115,41,125,35,103,114,97,110,116,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,123,105,102,40,116,104,105,115,46,104,97,115,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,96,36,123,114,111,108,101,125,32,114,111,108,101,32,97,108,114,101,97,100,121,32,103,114,97,110,116,101,100,32,102,111,114,32,36,123,97,100,100,114,101,115,115,125,96,41,59,116,104,105,115,46,35,114,111,108,101,115,91,114,111,108,101,93,46,112,117,115,104,40,97,100,100,114,101,115,115,41,125,35,114,101,118,111,107,101,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,123,105,102,40,33,116,104,105,115,46,104,97,115,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,96,36,123,114,111,108,101,125,32,114,111,108,101,32,97,108,114,101,97,100,121,32,114,101,118,111,107,101,100,32,102,111,114,32,36,123,97,100,100,114,101,115,115,125,96,41,59,105,102,40,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,99,108,97,115,115,32,84,111,107,101,110,32,101,120,116,101,110,100,115,32,82,111,108,101,115,123,35,110,97,109,101,59,35,115,121,109,98,111,108,59,35,104,111,108,100,101,114,115,61,48,59,35,98,97,108,97,110,99,101,115,61,123,125,59,35,97,112,112,114,111,118,97,108,115,61,123,125,59,35,100,101,99,105,109,97,108,115,61,49,56,59,35,116,111,116,97,108,83,117,112,112,108,121,61,66,105,103,78,117,109,98,101,114,46,102,114,111,109,40,48,41,59,99,111,110,115,116,114,117,99,116,111,114,40,110,97,109,101,44,115,121,109,98,111,108,44,100,101,99,105,109,97,108,115,61,49,56,44,115,116,97,116,101,41,123,105,102,40,33,110,97,109,101,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,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,102,114,111,109,44,97,109,111,117,110,116,41,123,105,102,40,33,116,104,105,115,46,104,97,115,82,111,108,101,40,109,115,103,46,115,101,110,100,101,114,44,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,102,114,111,109,44,97,109,111,117,110,116,41,125,35,98,101,102,111,114,101,84,114,97,110,115,102,101,114,40,102,114,111,109,44,116,111,44,97,109,111,117,110,116,41,123,105,102,40,33,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,102,114,111,109,93,124,124,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,102,114,111,109,93,60,97,109,111,117,110,116,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,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,99,108,97,115,115,32,65,114,116,79,110,108,105,110,101,32,101,120,116,101,110,100,115,32,84,111,107,101,110,123,99,111,110,115,116,114,117,99,116,111,114,40,115,116,97,116,101,41,123,115,117,112,101,114,40,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,114,101,116,117,114,110,32,65,114,116,79,110,108,105,110,101,59,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";
369
385
  var nameService = "237,198,141,3,123,34,99,114,101,97,116,111,114,34,58,34,56,71,85,107,103,52,120,87,113,109,110,83,56,75,101,122,56,107,54,68,115,82,120,90,66,68,97,54,114,71,74,109,104,107,122,67,75,113,78,75,102,85,110,103,90,122,109,54,97,81,34,44,34,99,111,110,116,114,97,99,116,34,58,34,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,114,114,111,114,41,123,116,104,114,111,119,32,101,114,114,111,114,125,116,104,105,115,46,35,114,101,103,105,115,116,114,121,91,110,97,109,101,93,61,123,111,119,110,101,114,58,109,115,103,46,115,101,110,100,101,114,44,97,100,100,114,101,115,115,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,114,101,116,117,114,110,32,78,97,109,101,83,101,114,118,105,99,101,59,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,103,54,99,54,109,119,121,53,109,104,98,114,115,53,117,108,107,107,111,122,115,103,119,116,107,53,118,117,122,53,107,114,106,105,100,111,117,121,52,109,98,119,102,100,98,106,110,98,109,107,122,122,34,44,34,105,104,110,121,50,103,113,104,111,111,99,107,121,103,55,121,103,52,110,53,98,112,120,117,108,100,97,104,102,97,118,112,113,110,109,112,111,101,50,98,110,52,105,118,110,120,109,107,55,114,101,100,99,50,108,116,119,107,98,34,44,34,105,104,110,121,50,103,113,104,52,101,50,112,114,52,112,98,116,112,107,97,109,104,106,51,104,116,115,118,117,111,121,100,121,51,119,111,116,97,117,100,111,101,97,107,116,103,99,100,119,109,111,105,106,54,54,112,101,99,112,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";
@@ -458,7 +474,7 @@ class Chain {
458
474
  const validators = await this.staticCall(addresses.validators, 'validators');
459
475
  console.log(validators);
460
476
  if (!validators[peernet.selectedAccount]?.active) return
461
-
477
+ debug(`validator ${peernet.selectedAccount} active`);
462
478
  const start = Date.now();
463
479
  try {
464
480
  await this.#createBlock();
@@ -724,12 +740,15 @@ async resolveBlock(hash) {
724
740
  }
725
741
 
726
742
  async #executeTransaction({hash, from, to, method, params, nonce}) {
743
+ console.log(hash, from);
727
744
  try {
728
745
  let result = await this.#machine.execute(to, method, params, from, nonce);
729
746
  // if (!result) result = this.#machine.state
747
+ console.log({result});
730
748
  pubsub.publish(`transaction.completed.${hash}`, {status: 'fulfilled', hash});
731
749
  return result || 'no state change'
732
750
  } catch (error) {
751
+ console.log(error);
733
752
  pubsub.publish(`transaction.completed.${hash}`, {status: 'fail', hash, error: error});
734
753
  throw error
735
754
  }
@@ -865,7 +884,7 @@ async resolveBlock(hash) {
865
884
 
866
885
  // exclude failing tx
867
886
  transactions = await this.getTransactions(transactions.slice(0, transactions.length < 1800 ? transactions.length : 1800));
868
-
887
+ console.log(transactions);
869
888
  transactions = transactions.sort((a, b) => a.nonce - b.nonce);
870
889
  for (let transaction of transactions) {
871
890
  try {
@@ -873,7 +892,8 @@ async resolveBlock(hash) {
873
892
  block.transactions.push(transaction);
874
893
  block.fees += Number(calculateFee(transaction));
875
894
  await accountsStore.put(transaction.from, new TextEncoder().encode(String(transaction.nonce)));
876
- } catch {
895
+ } catch (error) {
896
+ console.log(error);
877
897
  transaction = await new TransactionMessage(transaction);
878
898
  await transactionPoolStore.delete(await transaction.hash);
879
899
  }
@@ -1044,7 +1064,7 @@ async resolveBlock(hash) {
1044
1064
 
1045
1065
  /**
1046
1066
  *
1047
- * @param {Object} transaction {}
1067
+ * @param {Transaction} transaction
1048
1068
  * @param {String} transaction.from address
1049
1069
  * @param {String} transaction.to address
1050
1070
  * @param {Object} transaction.params {}
@@ -1059,8 +1079,8 @@ async createTransactionHash(transaction) {
1059
1079
  }
1060
1080
 
1061
1081
  /**
1062
- * @params {object} transaction -
1063
- * @params {object} wallet - any wallet/signer that supports sign(RAWtransaction)
1082
+ * @param {Transaction} transaction
1083
+ * @param {object} wallet any wallet/signer that supports sign(RAWtransaction)
1064
1084
  */
1065
1085
  async #signTransaction (transaction, wallet) {
1066
1086
  return wallet.sign(await this.createTransactionHash(transaction))
@@ -1079,14 +1099,14 @@ async #signTransaction (transaction, wallet) {
1079
1099
 
1080
1100
  /**
1081
1101
  *
1082
- * @param {Object} transaction
1102
+ * @param {Transaction} transaction
1083
1103
  * @param {Address} transaction.from
1084
1104
  * @param {Address} transaction.to
1085
1105
  * @param {String} transaction.method
1086
1106
  * @param {Array} transaction.params
1087
1107
  * @param {Number} transaction.nonce
1088
1108
  *
1089
- * @returns {Object} transaction
1109
+ * @returns {RawTransaction} transaction
1090
1110
  */
1091
1111
  async createRawTransaction(transaction) {
1092
1112
  if (!transaction.from) transaction.from = peernet.selectedAccount;
@@ -1107,13 +1127,14 @@ async #signTransaction (transaction, wallet) {
1107
1127
  * data is undefined when nothing is returned
1108
1128
  * error is thrown on error so undefined data doesn't mean there is an error...
1109
1129
  *
1110
- * @param {String} from - the sender address
1111
- * @param {String} to - the contract address for the contract to interact with
1130
+ * @param {Address} from - the sender address
1131
+ * @param {Address} to - the contract address for the contract to interact with
1112
1132
  * @param {String} method - the method/function to run
1113
1133
  * @param {Array} params - array of paramters to apply to the contract method
1114
1134
  * @param {Number} nonce - total transaction count [optional]
1115
1135
  */
1116
1136
  async createTransactionFrom(from, to, method, parameters, nonce) {
1137
+
1117
1138
  try {
1118
1139
 
1119
1140
  const rawTransaction = await this.createRawTransaction({from, to, nonce, method, params: parameters});
@@ -1143,6 +1164,7 @@ async #signTransaction (transaction, wallet) {
1143
1164
  await transactionPoolStore.put(await message.hash, message.encoded);
1144
1165
  peernet.publish('add-transaction', message.encoded);
1145
1166
  this.#addTransaction(message.encoded);
1167
+ debug('creating tx');
1146
1168
  return {hash: await message.hash, data, fee: await calculateFee(message.decoded), wait}
1147
1169
  } catch (error) {
1148
1170
  console.log(error);
@@ -1151,10 +1173,24 @@ async #signTransaction (transaction, wallet) {
1151
1173
 
1152
1174
  }
1153
1175
 
1176
+ /**
1177
+ *
1178
+ * @param {Address} creator
1179
+ * @param {String} contract
1180
+ * @param {Array} constructorParameters
1181
+ * @returns lib.createContractMessage
1182
+ */
1154
1183
  async createContractMessage(creator, contract, constructorParameters = []) {
1155
- return createContractMessage(creator, contract, constructorParameters = [])
1184
+ return createContractMessage(creator, contract, constructorParameters)
1156
1185
  }
1157
1186
 
1187
+ /**
1188
+ *
1189
+ * @param {Address} creator
1190
+ * @param {String} contract
1191
+ * @param {Array} constructorParameters
1192
+ * @returns {Address}
1193
+ */
1158
1194
  async createContractAddress(creator, contract, constructorParameters = []) {
1159
1195
  contract = await this.createContractMessage(creator, contract, constructorParameters);
1160
1196
  return contract.hash
@@ -1166,16 +1202,21 @@ async #signTransaction (transaction, wallet) {
1166
1202
  * @param {Array} parameters
1167
1203
  * @returns
1168
1204
  */
1169
- async deployContract(contract, parameters = []) {
1170
- const message = await createContractMessage(peernet.selectedAccount, contract, parameters);
1205
+ async deployContract(contract, constructorParameters = []) {
1206
+ const message = await createContractMessage(peernet.selectedAccount, contract, constructorParameters);
1171
1207
  try {
1172
- await this.#machine.addContract(message);
1208
+ await contractStore.put(await message.hash, message.encoded);
1173
1209
  } catch (error) {
1174
1210
  throw error
1175
1211
  }
1176
1212
  return this.createTransactionFrom(peernet.selectedAccount, addresses.contractFactory, 'registerContract', [await message.hash])
1177
1213
  }
1178
1214
 
1215
+ /**
1216
+ *
1217
+ * @param {Address} sender
1218
+ * @returns {globalMessage}
1219
+ */
1179
1220
  #createMessage(sender = peernet.selectedAccount) {
1180
1221
  return {
1181
1222
  sender,
@@ -1186,12 +1227,27 @@ async #signTransaction (transaction, wallet) {
1186
1227
  }
1187
1228
  }
1188
1229
 
1230
+ /**
1231
+ *
1232
+ * @param {Address} sender
1233
+ * @param {Address} contract
1234
+ * @param {String} method
1235
+ * @param {Array} parameters
1236
+ * @returns
1237
+ */
1189
1238
  internalCall(sender, contract, method, parameters) {
1190
1239
  globalThis.msg = this.#createMessage(sender);
1191
1240
 
1192
1241
  return this.#machine.execute(contract, method, parameters)
1193
1242
  }
1194
1243
 
1244
+ /**
1245
+ *
1246
+ * @param {Address} contract
1247
+ * @param {String} method
1248
+ * @param {Array} parameters
1249
+ * @returns
1250
+ */
1195
1251
  call(contract, method, parameters) {
1196
1252
  globalThis.msg = this.#createMessage();
1197
1253
 
@@ -543,7 +543,7 @@ const tasks = async (e) => {
543
543
  });
544
544
  } catch (e) {
545
545
  worker.postMessage({
546
- type: 'fetchError',
546
+ type: 'runError',
547
547
  message: e.message,
548
548
  id
549
549
  });