@leofcoin/chain 1.6.11 → 1.6.12

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.
@@ -117,6 +117,10 @@ let nativeMints = 0;
117
117
  let nativeTransfers = 0;
118
118
  let totalTransactions = 0;
119
119
 
120
+ let totalBurnAmount = 0;
121
+ let totalMintAmount = 0;
122
+ let totalTransferAmount = 0;
123
+
120
124
  let blocks = [];
121
125
  let contracts = {};
122
126
  const _ = {};
@@ -223,9 +227,18 @@ const _executeTransaction = async (transaction) => {
223
227
  await _.execute({ contract: to, method, params });
224
228
  if (to === nativeToken$2) {
225
229
  nativeCalls += 1;
226
- if (method === 'burn') nativeBurns += 1;
227
- if (method === 'mint') nativeMints += 1;
228
- if (method === 'transfer') nativeTransfers += 1;
230
+ if (method === 'burn') {
231
+ nativeBurns += 1;
232
+ totalBurnAmount += params[0];
233
+ }
234
+ if (method === 'mint') {
235
+ nativeMints += 1;
236
+ totalMintAmount += params[0];
237
+ }
238
+ if (method === 'transfer') {
239
+ nativeTransfers += 1;
240
+ totalTransferAmount += params[0];
241
+ }
229
242
  }
230
243
  totalTransactions += 1;
231
244
 
@@ -241,10 +254,19 @@ const _executeTransaction = async (transaction) => {
241
254
  };
242
255
 
243
256
  _.init = async (message) => {
244
- let { peerid, fromState, state } = message;
257
+ let { peerid, fromState, state, info } = message;
245
258
  globalThis.peerid = peerid;
246
259
  console.log({ fromState });
247
260
  if (fromState) {
261
+ nativeCalls = info.nativeCalls;
262
+ nativeBurns = info.nativeBurns;
263
+ nativeMints = info.nativeMints;
264
+ nativeTransfers = info.nativeTransfers;
265
+ totalTransactions = info.totalTransactions;
266
+ totalBurnAmount = info.totalBurnAmount;
267
+ totalMintAmount = info.totalMintAmount;
268
+ totalTransferAmount = info.totalTransferAmount;
269
+
248
270
  lastBlock = message.lastBlock;
249
271
  const setState = async (address, state) => {
250
272
  const contractBytes = await resolveContract(address);
@@ -418,6 +440,15 @@ worker.onmessage(({ id, type, input }) => {
418
440
  case 'nativeTransfers':
419
441
  respond(id, nativeTransfers);
420
442
  break
443
+ case 'totalBurnAmount':
444
+ respond(id, totalBurnAmount);
445
+ break
446
+ case 'totalMintAmount':
447
+ respond(id, totalMintAmount);
448
+ break
449
+ case 'totalTransferAmount':
450
+ respond(id, totalTransferAmount);
451
+ break
421
452
  case 'totalTransfers':
422
453
  respond(id, totalTransfers);
423
454
  break
package/exports/chain.js CHANGED
@@ -282,7 +282,15 @@ class Machine {
282
282
  index: 0,
283
283
  hash: ''
284
284
  },
285
- accounts: {}
285
+ accounts: {},
286
+ info: {
287
+ nativeCalls: 0,
288
+ nativeMints: 0,
289
+ nativeBurns: 0,
290
+ nativeTransfers: 0,
291
+ totalTransactions: 0,
292
+ totalBlocks: 0
293
+ }
286
294
  };
287
295
  // @ts-ignore
288
296
  return this.#init(blocks);
@@ -376,7 +384,18 @@ class Machine {
376
384
  const tasks = [
377
385
  stateStore.put('lastBlock', JSON.stringify(await this.lastBlock)),
378
386
  stateStore.put('states', JSON.stringify(state)),
379
- stateStore.put('accounts', JSON.stringify(accounts))
387
+ stateStore.put('accounts', JSON.stringify(accounts)),
388
+ stateStore.put('info', JSON.stringify({
389
+ nativeCalls: this.nativeCalls,
390
+ nativeMints: this.nativeMints,
391
+ nativeBurns: this.nativeBurns,
392
+ nativeTransfers: this.nativeTransfers,
393
+ totalTransactions: this.totalTransactions,
394
+ totalBurnAmount: this.totalBurnAmount,
395
+ totaMintAmount: this.totaMintAmount,
396
+ totalTransferAmount: this.totalTransferAmount,
397
+ totalBlocks: await blockStore.length
398
+ }))
380
399
  // accountsStore.clear()
381
400
  ];
382
401
  await Promise.all(tasks);
@@ -415,9 +434,19 @@ class Machine {
415
434
  this.states.states = JSON.parse(new TextDecoder().decode(await stateStore.get('states')));
416
435
  try {
417
436
  this.states.accounts = JSON.parse(new TextDecoder().decode(await stateStore.get('accounts')));
437
+ this.states.info = JSON.parse(new TextDecoder().decode(await stateStore.get('info')));
418
438
  }
419
439
  catch {
420
440
  this.states.accounts = {};
441
+ // todo try fetching info from fully synced peer
442
+ this.states.info = {
443
+ nativeCalls: 0,
444
+ nativeMints: 0,
445
+ nativeBurns: 0,
446
+ nativeTransfers: 0,
447
+ totalTransactions: 0,
448
+ totalBlocks: 0
449
+ };
421
450
  }
422
451
  console.log({ balances: this.states.states[addresses.nativeToken].balances });
423
452
  }
@@ -428,6 +457,7 @@ class Machine {
428
457
  fromState: this.states.lastBlock.index > 0,
429
458
  lastBlock: this.states.lastBlock,
430
459
  state: this.states.states,
460
+ info: this.states.info,
431
461
  // @ts-ignore
432
462
  peerid: peernet.peerId
433
463
  }
@@ -593,6 +623,15 @@ class Machine {
593
623
  get totalBlocks() {
594
624
  return this.#askWorker('totalBlocks');
595
625
  }
626
+ get totalBurnAmount() {
627
+ return this.#askWorker('totalBurnAmount');
628
+ }
629
+ get totaMintAmount() {
630
+ return this.#askWorker('totaMintAmount');
631
+ }
632
+ get totalTransferAmount() {
633
+ return this.#askWorker('totalTransferAmount');
634
+ }
596
635
  getBlocks(from, to) {
597
636
  return this.#askWorker('blocks', { from, to });
598
637
  }
@@ -1418,9 +1457,11 @@ class Chain extends VersionControl {
1418
1457
  else if (!this.knownBlocks)
1419
1458
  this.knownBlocks = await this.#makeRequest(peer, 'knownBlocks');
1420
1459
  }
1421
- const peerTransactionPool = (higherThenCurrentLocal && (await this.getPeerTransactionPool(peer))) || [];
1422
- if (this.#participating && peerTransactionPool.length > 0)
1423
- return this.#runEpoch();
1460
+ setTimeout(async () => {
1461
+ const peerTransactionPool = (higherThenCurrentLocal && (await this.getPeerTransactionPool(peer))) || [];
1462
+ if (this.#participating && peerTransactionPool.length > 0)
1463
+ return this.#runEpoch();
1464
+ }, 3000);
1424
1465
  }
1425
1466
  #epochTimeout;
1426
1467
  async #transactionPoolHandler() {
@@ -9,6 +9,14 @@ export default class Machine {
9
9
  hash: string;
10
10
  };
11
11
  accounts: {};
12
+ info: {
13
+ nativeCalls: number;
14
+ nativeMints: number;
15
+ nativeBurns: number;
16
+ nativeTransfers: number;
17
+ totalTransactions: number;
18
+ totalBlocks: number;
19
+ };
12
20
  };
13
21
  constructor(blocks: any);
14
22
  updateState(): Promise<void>;
@@ -30,6 +38,9 @@ export default class Machine {
30
38
  get blocks(): Promise<[]>;
31
39
  get lastBlock(): Promise<any>;
32
40
  get totalBlocks(): Promise<any>;
41
+ get totalBurnAmount(): Promise<any>;
42
+ get totaMintAmount(): Promise<any>;
43
+ get totalTransferAmount(): Promise<any>;
33
44
  getBlocks(from?: any, to?: any): Promise<[]>;
34
45
  getBlock(index: any): Promise<any>;
35
46
  addLoadedBlock(block: any): Promise<any>;
@@ -117,6 +117,10 @@ let nativeMints = 0;
117
117
  let nativeTransfers = 0;
118
118
  let totalTransactions = 0;
119
119
 
120
+ let totalBurnAmount = 0;
121
+ let totalMintAmount = 0;
122
+ let totalTransferAmount = 0;
123
+
120
124
  let blocks = [];
121
125
  let contracts = {};
122
126
  const _ = {};
@@ -223,9 +227,18 @@ const _executeTransaction = async (transaction) => {
223
227
  await _.execute({ contract: to, method, params });
224
228
  if (to === nativeToken$2) {
225
229
  nativeCalls += 1;
226
- if (method === 'burn') nativeBurns += 1;
227
- if (method === 'mint') nativeMints += 1;
228
- if (method === 'transfer') nativeTransfers += 1;
230
+ if (method === 'burn') {
231
+ nativeBurns += 1;
232
+ totalBurnAmount += params[0];
233
+ }
234
+ if (method === 'mint') {
235
+ nativeMints += 1;
236
+ totalMintAmount += params[0];
237
+ }
238
+ if (method === 'transfer') {
239
+ nativeTransfers += 1;
240
+ totalTransferAmount += params[0];
241
+ }
229
242
  }
230
243
  totalTransactions += 1;
231
244
 
@@ -241,10 +254,19 @@ const _executeTransaction = async (transaction) => {
241
254
  };
242
255
 
243
256
  _.init = async (message) => {
244
- let { peerid, fromState, state } = message;
257
+ let { peerid, fromState, state, info } = message;
245
258
  globalThis.peerid = peerid;
246
259
  console.log({ fromState });
247
260
  if (fromState) {
261
+ nativeCalls = info.nativeCalls;
262
+ nativeBurns = info.nativeBurns;
263
+ nativeMints = info.nativeMints;
264
+ nativeTransfers = info.nativeTransfers;
265
+ totalTransactions = info.totalTransactions;
266
+ totalBurnAmount = info.totalBurnAmount;
267
+ totalMintAmount = info.totalMintAmount;
268
+ totalTransferAmount = info.totalTransferAmount;
269
+
248
270
  lastBlock = message.lastBlock;
249
271
  const setState = async (address, state) => {
250
272
  const contractBytes = await resolveContract(address);
@@ -418,6 +440,15 @@ worker.onmessage(({ id, type, input }) => {
418
440
  case 'nativeTransfers':
419
441
  respond(id, nativeTransfers);
420
442
  break
443
+ case 'totalBurnAmount':
444
+ respond(id, totalBurnAmount);
445
+ break
446
+ case 'totalMintAmount':
447
+ respond(id, totalMintAmount);
448
+ break
449
+ case 'totalTransferAmount':
450
+ respond(id, totalTransferAmount);
451
+ break
421
452
  case 'totalTransfers':
422
453
  respond(id, totalTransfers);
423
454
  break
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.6.11",
3
+ "version": "1.6.12",
4
4
  "description": "Official javascript implementation",
5
5
  "private": false,
6
6
  "exports": {
@@ -55,25 +55,25 @@
55
55
  "@rollup/plugin-node-resolve": "^15.2.3",
56
56
  "@rollup/plugin-typescript": "^11.1.6",
57
57
  "@types/semver": "^7.5.8",
58
- "@vandeurenglenn/debug": "^1.2.2",
59
- "rollup": "^4.12.1",
58
+ "@vandeurenglenn/debug": "^1.2.3",
59
+ "rollup": "^4.16.4",
60
60
  "rollup-plugin-modify": "^3.0.0",
61
61
  "tape": "^5.7.5",
62
62
  "tslib": "^2.6.2"
63
63
  },
64
64
  "dependencies": {
65
- "@leofcoin/addresses": "^1.0.22",
65
+ "@leofcoin/addresses": "^1.0.23",
66
66
  "@leofcoin/contracts": "^0.1.9",
67
- "@leofcoin/crypto": "^0.2.11",
68
- "@leofcoin/errors": "^1.0.6",
69
- "@leofcoin/lib": "^1.2.42",
70
- "@leofcoin/messages": "^1.4.12",
71
- "@leofcoin/multi-wallet": "^3.1.7",
72
- "@leofcoin/networks": "^1.1.5",
67
+ "@leofcoin/crypto": "^0.2.12",
68
+ "@leofcoin/errors": "^1.0.7",
69
+ "@leofcoin/lib": "^1.2.43",
70
+ "@leofcoin/messages": "^1.4.13",
71
+ "@leofcoin/multi-wallet": "^3.1.8",
72
+ "@leofcoin/networks": "^1.1.6",
73
73
  "@leofcoin/peernet": "^1.1.77",
74
- "@leofcoin/storage": "^3.5.24",
75
- "@leofcoin/utils": "^1.1.17",
76
- "@leofcoin/workers": "^1.4.18",
74
+ "@leofcoin/storage": "^3.5.28",
75
+ "@leofcoin/utils": "^1.1.18",
76
+ "@leofcoin/workers": "^1.4.19",
77
77
  "@vandeurenglenn/base58": "^1.1.9",
78
78
  "@vandeurenglenn/easy-worker": "^1.0.2",
79
79
  "semver": "^7.6.0"