@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.
package/dist/chain.js CHANGED
@@ -57,6 +57,142 @@ const formatBytes = (bytes, decimals = 2) => {
57
57
  return `${parseFloat((bytes / Math.pow(k, i)).toFixed(decimals))} ${byteFormats[i]}`
58
58
  };
59
59
 
60
+ var proto$4 = `
61
+ message ContractMessage {
62
+ required string creator = 1;
63
+ required bytes contract = 2;
64
+ repeated string constructorParameters = 3;
65
+ }
66
+ `;
67
+
68
+ class ContractMessage extends codecFormatInterface.FormatInterface {
69
+ get keys() {
70
+ return ['creator', 'contract', 'constructorParameters']
71
+ }
72
+
73
+ get messageName() {
74
+ return 'ContractMessage'
75
+ }
76
+
77
+ constructor(buffer) {
78
+ super(buffer, proto$4, {name: 'contract-message'});
79
+ }
80
+ }
81
+
82
+ var proto$3 = `
83
+
84
+ message TransactionMessage {
85
+ required uint64 timestamp = 1;
86
+ required string from = 2;
87
+ required string to = 3;
88
+ required uint64 nonce = 4;
89
+ required string method = 5;
90
+ repeated string params = 6;
91
+ required string signature = 7;
92
+ }
93
+ `;
94
+
95
+ class TransactionMessage extends codecFormatInterface.FormatInterface {
96
+ get keys() {
97
+ return ['timestamp', 'from', 'to', 'nonce', 'method', 'params', 'signature']
98
+ }
99
+
100
+ get messageName() {
101
+ return 'TransactionMessage'
102
+ }
103
+
104
+ constructor(buffer) {
105
+ const name = 'transaction-message';
106
+ super(buffer, proto$3, {name});
107
+ }
108
+ }
109
+
110
+ var proto$2 = `
111
+ message ValidatorMessage {
112
+ required string address = 1;
113
+ required string reward = 2;
114
+ }
115
+
116
+ message Transaction {
117
+ required string hash = 1;
118
+ required uint64 timestamp = 2;
119
+ required string from = 3;
120
+ required string to = 4;
121
+ required uint64 nonce = 5;
122
+ required string method = 6;
123
+ repeated string params = 7;
124
+ }
125
+
126
+ message BlockMessage {
127
+ required uint64 index = 1;
128
+ required string previousHash = 3;
129
+ required uint64 timestamp = 4;
130
+ required uint64 reward = 5;
131
+ required string fees = 6;
132
+ repeated Transaction transactions = 7;
133
+ repeated ValidatorMessage validators = 8;
134
+ }
135
+ `;
136
+
137
+ class BlockMessage extends codecFormatInterface.FormatInterface {
138
+ get keys() {
139
+ return ['index', 'previousHash', 'timestamp', 'reward', 'fees', 'transactions', 'validators']
140
+ }
141
+
142
+ get messageName() {
143
+ return 'BlockMessage'
144
+ }
145
+
146
+ constructor(buffer) {
147
+ const name = 'block-message';
148
+ super(buffer, proto$2, {name});
149
+ }
150
+ }
151
+
152
+ var proto$1 = `
153
+
154
+ message BWMessage {
155
+ required uint64 up = 1;
156
+ required uint64 down = 2;
157
+ }
158
+ `;
159
+
160
+ class BWMessage extends codecFormatInterface.FormatInterface {
161
+ get keys() {
162
+ return ['up', 'down']
163
+ }
164
+
165
+ get messageName() {
166
+ return 'BWMessage'
167
+ }
168
+
169
+ constructor(buffer) {
170
+ const name = 'bw-message';
171
+ super(buffer, proto$1, {name});
172
+ }
173
+ }
174
+
175
+ var proto = `
176
+
177
+ message BWRequestMessage {
178
+ }
179
+ `;
180
+
181
+ class BWRequestMessage extends codecFormatInterface.FormatInterface {
182
+ get keys() {
183
+ return []
184
+ }
185
+
186
+ get messageName() {
187
+ return 'BWRequestMessage'
188
+ }
189
+
190
+ constructor(buffer) {
191
+ const name = 'bw-request-message';
192
+ super(buffer, proto, {name});
193
+ }
194
+ }
195
+
60
196
  // import State from './state'
61
197
 
62
198
  class Machine {
@@ -161,18 +297,34 @@ class Machine {
161
297
  })
162
298
 
163
299
  }
300
+
164
301
  /**
165
- * @params {ContractMessage} - contractMessage
302
+ *
303
+ * @param {Address} contract
304
+ * @param {String} method
305
+ * @param {Array} parameters
306
+ * @returns Promise<message>
166
307
  */
167
- async addContract(contractMessage) {
168
- if (await contractStore.has(await contractMessage.hash)) throw new Error('duplicate contract')
169
-
170
- await contractStore.put(await contractMessage.hash, contractMessage.encoded);
171
- await this.#runContract(contractMessage);
172
- return contractMessage.hash
173
- }
174
-
175
308
  async execute(contract, method, parameters) {
309
+ try {
310
+ if (contract === contractFactory$1 && method === 'registerContract') {
311
+ if (this.#contracts[parameters[0]]) throw new Error(`duplicate contract @${parameters[0]}`)
312
+ let message;
313
+ if (!await contractStore.has(parameters[0])) {
314
+ message = await peernet.get(parameters[0], 'contract');
315
+ message = await new ContractMessage(message);
316
+ await contractStore.put(await message.hash, message.encoded);
317
+ }
318
+ if (!message) {
319
+ message = await contractStore.get(parameters[0]);
320
+ message = await new ContractMessage(message);
321
+ }
322
+ console.log(message);
323
+ if (!this.#contracts[await message.hash]) await this.#runContract(message);
324
+ }
325
+ } catch (error) {
326
+ throw new Error(`contract deployment failed for ${parameters[0]}\n${error.message}`)
327
+ }
176
328
  return new Promise((resolve, reject) => {
177
329
  const id = node_crypto.randomBytes(20).toString('hex');
178
330
  const onmessage = message => {
@@ -237,142 +389,6 @@ class Machine {
237
389
  }
238
390
  }
239
391
 
240
- var proto$4 = `
241
- message ContractMessage {
242
- required string creator = 1;
243
- required bytes contract = 2;
244
- repeated string constructorParameters = 3;
245
- }
246
- `;
247
-
248
- class ContractMessage extends codecFormatInterface.FormatInterface {
249
- get keys() {
250
- return ['creator', 'contract', 'constructorParameters']
251
- }
252
-
253
- get messageName() {
254
- return 'ContractMessage'
255
- }
256
-
257
- constructor(buffer) {
258
- super(buffer, proto$4, {name: 'contract-message'});
259
- }
260
- }
261
-
262
- var proto$3 = `
263
-
264
- message TransactionMessage {
265
- required uint64 timestamp = 1;
266
- required string from = 2;
267
- required string to = 3;
268
- required uint64 nonce = 4;
269
- required string method = 5;
270
- repeated string params = 6;
271
- required string signature = 7;
272
- }
273
- `;
274
-
275
- class TransactionMessage extends codecFormatInterface.FormatInterface {
276
- get keys() {
277
- return ['timestamp', 'from', 'to', 'nonce', 'method', 'params', 'signature']
278
- }
279
-
280
- get messageName() {
281
- return 'TransactionMessage'
282
- }
283
-
284
- constructor(buffer) {
285
- const name = 'transaction-message';
286
- super(buffer, proto$3, {name});
287
- }
288
- }
289
-
290
- var proto$2 = `
291
- message ValidatorMessage {
292
- required string address = 1;
293
- required string reward = 2;
294
- }
295
-
296
- message Transaction {
297
- required string hash = 1;
298
- required uint64 timestamp = 2;
299
- required string from = 3;
300
- required string to = 4;
301
- required uint64 nonce = 5;
302
- required string method = 6;
303
- repeated string params = 7;
304
- }
305
-
306
- message BlockMessage {
307
- required uint64 index = 1;
308
- required string previousHash = 3;
309
- required uint64 timestamp = 4;
310
- required uint64 reward = 5;
311
- required string fees = 6;
312
- repeated Transaction transactions = 7;
313
- repeated ValidatorMessage validators = 8;
314
- }
315
- `;
316
-
317
- class BlockMessage extends codecFormatInterface.FormatInterface {
318
- get keys() {
319
- return ['index', 'previousHash', 'timestamp', 'reward', 'fees', 'transactions', 'validators']
320
- }
321
-
322
- get messageName() {
323
- return 'BlockMessage'
324
- }
325
-
326
- constructor(buffer) {
327
- const name = 'block-message';
328
- super(buffer, proto$2, {name});
329
- }
330
- }
331
-
332
- var proto$1 = `
333
-
334
- message BWMessage {
335
- required uint64 up = 1;
336
- required uint64 down = 2;
337
- }
338
- `;
339
-
340
- class BWMessage extends codecFormatInterface.FormatInterface {
341
- get keys() {
342
- return ['up', 'down']
343
- }
344
-
345
- get messageName() {
346
- return 'BWMessage'
347
- }
348
-
349
- constructor(buffer) {
350
- const name = 'bw-message';
351
- super(buffer, proto$1, {name});
352
- }
353
- }
354
-
355
- var proto = `
356
-
357
- message BWRequestMessage {
358
- }
359
- `;
360
-
361
- class BWRequestMessage extends codecFormatInterface.FormatInterface {
362
- get keys() {
363
- return []
364
- }
365
-
366
- get messageName() {
367
- return 'BWRequestMessage'
368
- }
369
-
370
- constructor(buffer) {
371
- const name = 'bw-request-message';
372
- super(buffer, proto, {name});
373
- }
374
- }
375
-
376
392
  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";
377
393
  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";
378
394
  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";
@@ -467,7 +483,7 @@ class Chain {
467
483
  const validators = await this.staticCall(addresses.validators, 'validators');
468
484
  console.log(validators);
469
485
  if (!validators[peernet.selectedAccount]?.active) return
470
-
486
+ debug(`validator ${peernet.selectedAccount} active`);
471
487
  const start = Date.now();
472
488
  try {
473
489
  await this.#createBlock();
@@ -733,12 +749,15 @@ async resolveBlock(hash) {
733
749
  }
734
750
 
735
751
  async #executeTransaction({hash, from, to, method, params, nonce}) {
752
+ console.log(hash, from);
736
753
  try {
737
754
  let result = await this.#machine.execute(to, method, params, from, nonce);
738
755
  // if (!result) result = this.#machine.state
756
+ console.log({result});
739
757
  pubsub.publish(`transaction.completed.${hash}`, {status: 'fulfilled', hash});
740
758
  return result || 'no state change'
741
759
  } catch (error) {
760
+ console.log(error);
742
761
  pubsub.publish(`transaction.completed.${hash}`, {status: 'fail', hash, error: error});
743
762
  throw error
744
763
  }
@@ -874,7 +893,7 @@ async resolveBlock(hash) {
874
893
 
875
894
  // exclude failing tx
876
895
  transactions = await this.getTransactions(transactions.slice(0, transactions.length < 1800 ? transactions.length : 1800));
877
-
896
+ console.log(transactions);
878
897
  transactions = transactions.sort((a, b) => a.nonce - b.nonce);
879
898
  for (let transaction of transactions) {
880
899
  try {
@@ -882,7 +901,8 @@ async resolveBlock(hash) {
882
901
  block.transactions.push(transaction);
883
902
  block.fees += Number(calculateFee(transaction));
884
903
  await accountsStore.put(transaction.from, new TextEncoder().encode(String(transaction.nonce)));
885
- } catch {
904
+ } catch (error) {
905
+ console.log(error);
886
906
  transaction = await new TransactionMessage(transaction);
887
907
  await transactionPoolStore.delete(await transaction.hash);
888
908
  }
@@ -1053,7 +1073,7 @@ async resolveBlock(hash) {
1053
1073
 
1054
1074
  /**
1055
1075
  *
1056
- * @param {Object} transaction {}
1076
+ * @param {Transaction} transaction
1057
1077
  * @param {String} transaction.from address
1058
1078
  * @param {String} transaction.to address
1059
1079
  * @param {Object} transaction.params {}
@@ -1068,8 +1088,8 @@ async createTransactionHash(transaction) {
1068
1088
  }
1069
1089
 
1070
1090
  /**
1071
- * @params {object} transaction -
1072
- * @params {object} wallet - any wallet/signer that supports sign(RAWtransaction)
1091
+ * @param {Transaction} transaction
1092
+ * @param {object} wallet any wallet/signer that supports sign(RAWtransaction)
1073
1093
  */
1074
1094
  async #signTransaction (transaction, wallet) {
1075
1095
  return wallet.sign(await this.createTransactionHash(transaction))
@@ -1088,14 +1108,14 @@ async #signTransaction (transaction, wallet) {
1088
1108
 
1089
1109
  /**
1090
1110
  *
1091
- * @param {Object} transaction
1111
+ * @param {Transaction} transaction
1092
1112
  * @param {Address} transaction.from
1093
1113
  * @param {Address} transaction.to
1094
1114
  * @param {String} transaction.method
1095
1115
  * @param {Array} transaction.params
1096
1116
  * @param {Number} transaction.nonce
1097
1117
  *
1098
- * @returns {Object} transaction
1118
+ * @returns {RawTransaction} transaction
1099
1119
  */
1100
1120
  async createRawTransaction(transaction) {
1101
1121
  if (!transaction.from) transaction.from = peernet.selectedAccount;
@@ -1116,13 +1136,14 @@ async #signTransaction (transaction, wallet) {
1116
1136
  * data is undefined when nothing is returned
1117
1137
  * error is thrown on error so undefined data doesn't mean there is an error...
1118
1138
  *
1119
- * @param {String} from - the sender address
1120
- * @param {String} to - the contract address for the contract to interact with
1139
+ * @param {Address} from - the sender address
1140
+ * @param {Address} to - the contract address for the contract to interact with
1121
1141
  * @param {String} method - the method/function to run
1122
1142
  * @param {Array} params - array of paramters to apply to the contract method
1123
1143
  * @param {Number} nonce - total transaction count [optional]
1124
1144
  */
1125
1145
  async createTransactionFrom(from, to, method, parameters, nonce) {
1146
+
1126
1147
  try {
1127
1148
 
1128
1149
  const rawTransaction = await this.createRawTransaction({from, to, nonce, method, params: parameters});
@@ -1152,6 +1173,7 @@ async #signTransaction (transaction, wallet) {
1152
1173
  await transactionPoolStore.put(await message.hash, message.encoded);
1153
1174
  peernet.publish('add-transaction', message.encoded);
1154
1175
  this.#addTransaction(message.encoded);
1176
+ debug('creating tx');
1155
1177
  return {hash: await message.hash, data, fee: await calculateFee(message.decoded), wait}
1156
1178
  } catch (error) {
1157
1179
  console.log(error);
@@ -1160,10 +1182,24 @@ async #signTransaction (transaction, wallet) {
1160
1182
 
1161
1183
  }
1162
1184
 
1185
+ /**
1186
+ *
1187
+ * @param {Address} creator
1188
+ * @param {String} contract
1189
+ * @param {Array} constructorParameters
1190
+ * @returns lib.createContractMessage
1191
+ */
1163
1192
  async createContractMessage(creator, contract, constructorParameters = []) {
1164
- return createContractMessage(creator, contract, constructorParameters = [])
1193
+ return createContractMessage(creator, contract, constructorParameters)
1165
1194
  }
1166
1195
 
1196
+ /**
1197
+ *
1198
+ * @param {Address} creator
1199
+ * @param {String} contract
1200
+ * @param {Array} constructorParameters
1201
+ * @returns {Address}
1202
+ */
1167
1203
  async createContractAddress(creator, contract, constructorParameters = []) {
1168
1204
  contract = await this.createContractMessage(creator, contract, constructorParameters);
1169
1205
  return contract.hash
@@ -1175,16 +1211,21 @@ async #signTransaction (transaction, wallet) {
1175
1211
  * @param {Array} parameters
1176
1212
  * @returns
1177
1213
  */
1178
- async deployContract(contract, parameters = []) {
1179
- const message = await createContractMessage(peernet.selectedAccount, contract, parameters);
1214
+ async deployContract(contract, constructorParameters = []) {
1215
+ const message = await createContractMessage(peernet.selectedAccount, contract, constructorParameters);
1180
1216
  try {
1181
- await this.#machine.addContract(message);
1217
+ await contractStore.put(await message.hash, message.encoded);
1182
1218
  } catch (error) {
1183
1219
  throw error
1184
1220
  }
1185
1221
  return this.createTransactionFrom(peernet.selectedAccount, addresses.contractFactory, 'registerContract', [await message.hash])
1186
1222
  }
1187
1223
 
1224
+ /**
1225
+ *
1226
+ * @param {Address} sender
1227
+ * @returns {globalMessage}
1228
+ */
1188
1229
  #createMessage(sender = peernet.selectedAccount) {
1189
1230
  return {
1190
1231
  sender,
@@ -1195,12 +1236,27 @@ async #signTransaction (transaction, wallet) {
1195
1236
  }
1196
1237
  }
1197
1238
 
1239
+ /**
1240
+ *
1241
+ * @param {Address} sender
1242
+ * @param {Address} contract
1243
+ * @param {String} method
1244
+ * @param {Array} parameters
1245
+ * @returns
1246
+ */
1198
1247
  internalCall(sender, contract, method, parameters) {
1199
1248
  globalThis.msg = this.#createMessage(sender);
1200
1249
 
1201
1250
  return this.#machine.execute(contract, method, parameters)
1202
1251
  }
1203
1252
 
1253
+ /**
1254
+ *
1255
+ * @param {Address} contract
1256
+ * @param {String} method
1257
+ * @param {Array} parameters
1258
+ * @returns
1259
+ */
1204
1260
  call(contract, method, parameters) {
1205
1261
  globalThis.msg = this.#createMessage();
1206
1262