@leofcoin/chain 1.7.30 → 1.7.32

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.
@@ -40,8 +40,6 @@ var _nodeResolve_empty$1 = /*#__PURE__*/Object.freeze({
40
40
 
41
41
  var require$$0 = /*@__PURE__*/getAugmentedNamespace(_nodeResolve_empty$1);
42
42
 
43
- bn.exports;
44
-
45
43
  (function (module) {
46
44
  (function (module, exports) {
47
45
 
package/exports/chain.js CHANGED
@@ -284,12 +284,15 @@ class Machine {
284
284
  },
285
285
  accounts: {},
286
286
  info: {
287
- nativeCalls: 0,
288
- nativeMints: 0,
289
- nativeBurns: 0,
290
- nativeTransfers: 0,
291
- totalTransactions: 0,
292
- totalBlocks: 0
287
+ nativeCalls: BigNumber.from(0),
288
+ nativeMints: BigNumber.from(0),
289
+ nativeBurns: BigNumber.from(0),
290
+ nativeTransfers: BigNumber.from(0),
291
+ totalBurnAmount: BigNumber.from(0),
292
+ totalMintAmount: BigNumber.from(0),
293
+ totalTransferAmount: BigNumber.from(0),
294
+ totalTransactions: BigNumber.from(0),
295
+ totalBlocks: BigNumber.from(0)
293
296
  }
294
297
  };
295
298
  this.wantList = [];
@@ -366,7 +369,8 @@ class Machine {
366
369
  }
367
370
  async updateState() {
368
371
  try {
369
- if ((await this.lastBlock).index > this.states.lastBlock.index) {
372
+ if ((await this.lastBlock).index > this.states.lastBlock.index ||
373
+ ((await this.lastBlock).hash !== this.states.lastBlock.hash && (await this.lastBlock).index === 0)) {
370
374
  // todo only get state for changed contracts
371
375
  const blocks = (await this.blocks).slice(this.states.lastBlock.index);
372
376
  let transactions = [];
@@ -470,21 +474,28 @@ class Machine {
470
474
  this.states.states = JSON.parse(new TextDecoder().decode(await stateStore.get('states')));
471
475
  try {
472
476
  this.states.accounts = JSON.parse(new TextDecoder().decode(await stateStore.get('accounts')));
473
- this.states.info = JSON.parse(new TextDecoder().decode(await stateStore.get('info')));
477
+ const info = JSON.parse(new TextDecoder().decode(await stateStore.get('info')));
478
+ for (const key in info) {
479
+ info[key] = BigNumber.from(info[key]);
480
+ }
481
+ this.states.info = info;
474
482
  }
475
- catch {
483
+ catch (error) {
484
+ console.error(error);
476
485
  this.states.accounts = {};
477
486
  // todo try fetching info from fully synced peer
478
487
  this.states.info = {
479
- nativeCalls: 0,
480
- nativeMints: 0,
481
- nativeBurns: 0,
482
- nativeTransfers: 0,
483
- totalTransactions: 0,
484
- totalBlocks: 0
488
+ nativeCalls: BigNumber.from(0),
489
+ nativeMints: BigNumber.from(0),
490
+ nativeBurns: BigNumber.from(0),
491
+ nativeTransfers: BigNumber.from(0),
492
+ totalBurnAmount: BigNumber.from(0),
493
+ totalMintAmount: BigNumber.from(0),
494
+ totalTransferAmount: BigNumber.from(0),
495
+ totalTransactions: BigNumber.from(0),
496
+ totalBlocks: BigNumber.from(0)
485
497
  };
486
498
  }
487
- console.log({ balances: this.states.states[addresses.nativeToken].balances });
488
499
  }
489
500
  const message = {
490
501
  type: 'init',
@@ -569,6 +580,7 @@ class Machine {
569
580
  type: 'execute',
570
581
  id,
571
582
  input: {
583
+ to: contract,
572
584
  contract,
573
585
  method,
574
586
  params: parameters
@@ -1460,6 +1472,9 @@ class Chain extends VersionControl {
1460
1472
  // })
1461
1473
  await globalThis.peernet.addRequestHandler('transactionPool', this.#transactionPoolHandler.bind(this));
1462
1474
  await globalThis.peernet.addRequestHandler('version', this.#versionHandler.bind(this));
1475
+ await globalThis.peernet.addRequestHandler('stateInfo', () => {
1476
+ return new globalThis.peernet.protos['peernet-response']({ response: this.#state.info });
1477
+ });
1463
1478
  globalThis.peernet.subscribe('add-block', this.#addBlock.bind(this));
1464
1479
  globalThis.peernet.subscribe('invalid-transaction', this.#invalidTransaction.bind(this));
1465
1480
  globalThis.peernet.subscribe('send-transaction', this.#sendTransaction.bind(this));
@@ -1520,10 +1535,10 @@ class Chain extends VersionControl {
1520
1535
  if (Object.keys(lastBlock).length > 0) {
1521
1536
  if (!this.lastBlock || higherThenCurrentLocal) {
1522
1537
  this.knownBlocks = await this.#makeRequest(peer, 'knownBlocks');
1538
+ const stateinfo = await this.#makeRequest(peer, 'stateInfo');
1523
1539
  await this.syncChain(lastBlock);
1540
+ this.#state.info = stateinfo;
1524
1541
  }
1525
- else if (!this.knownBlocks)
1526
- this.knownBlocks = await this.#makeRequest(peer, 'knownBlocks');
1527
1542
  }
1528
1543
  if (this.wantList.length > 0) {
1529
1544
  const promises = await Promise.allSettled(this.wantList.map((hash) => peernet.get(hash)));
@@ -1598,10 +1613,7 @@ class Chain extends VersionControl {
1598
1613
  // // await transactionStore.put(transaction.hash, transaction.encoded)
1599
1614
  // if (!contracts.includes(transaction.to)) {
1600
1615
  // contracts.push(transaction.to)
1601
- // // Todo: go trough all accounts
1602
- // //@ts-ignore
1603
- // promises.push(this.#executeTransaction(transaction))
1604
- // }
1616
+ // }
1605
1617
  // // Todo: go trough all accounts
1606
1618
  // //@ts-ignore
1607
1619
  // promises.push(this.#executeTransaction(transaction))
@@ -1,4 +1,5 @@
1
1
  import EasyWorker from '@vandeurenglenn/easy-worker';
2
+ import { BigNumber } from '@leofcoin/utils';
2
3
  export default class Machine {
3
4
  #private;
4
5
  worker: EasyWorker;
@@ -10,12 +11,15 @@ export default class Machine {
10
11
  };
11
12
  accounts: {};
12
13
  info: {
13
- nativeCalls: number;
14
- nativeMints: number;
15
- nativeBurns: number;
16
- nativeTransfers: number;
17
- totalTransactions: number;
18
- totalBlocks: number;
14
+ nativeCalls: BigNumber;
15
+ nativeMints: BigNumber;
16
+ nativeBurns: BigNumber;
17
+ nativeTransfers: BigNumber;
18
+ totalBurnAmount: BigNumber;
19
+ totalMintAmount: BigNumber;
20
+ totalTransferAmount: BigNumber;
21
+ totalTransactions: BigNumber;
22
+ totalBlocks: BigNumber;
19
23
  };
20
24
  };
21
25
  wantList: string[];
@@ -1,4 +1,4 @@
1
- import { E as EasyWorker, B as BigNumber, a as BlockMessage } from './worker-Botf--mj.js';
1
+ import { E as EasyWorker, B as BigNumber, a as BlockMessage } from './worker-Botf--mj-BUK2CMT9.js';
2
2
 
3
3
  const worker = new EasyWorker();
4
4