@leofcoin/chain 1.4.36 → 1.4.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/exports/browser/chain.js +122 -4324
  2. package/exports/browser/client-033977a1-60f68d3b.js +41066 -0
  3. package/exports/browser/contract-32687834.js +6071 -0
  4. package/exports/browser/{index-1ce30988-44319c80.js → index-123daa04-05013cc5.js} +2 -2
  5. package/exports/browser/{messages-e025829d-a0354268.js → messages-5ddc1083-1bd0ab64.js} +2 -2
  6. package/exports/browser/{node-browser-64b82fc8.js → node-browser-c95add6b.js} +60 -56
  7. package/exports/browser/node-browser.js +2 -2
  8. package/exports/browser/workers/block-worker.js +6069 -0
  9. package/exports/browser/workers/machine-worker.js +6279 -0
  10. package/exports/chain.js +104 -94
  11. package/exports/node.js +2 -1
  12. package/exports/typings/chain.d.ts +4 -2
  13. package/exports/typings/contract.d.ts +1 -0
  14. package/exports/typings/node.d.ts +1 -0
  15. package/exports/typings/transaction.d.ts +1 -1
  16. package/package.json +4 -2
  17. package/exports/browser/browser-10ffabe1-10ffabe1.js +0 -56
  18. package/exports/browser/browser-e1cd4e67-e1cd4e67.js +0 -198
  19. package/exports/browser/client-111c93a3-b0dcdc19.js +0 -612
  20. package/exports/browser/client-1d0234a7-df40059a.js +0 -624
  21. package/exports/browser/client-21cee984-77440b6b.js +0 -624
  22. package/exports/browser/contract-163f031f.js +0 -1859
  23. package/exports/browser/index-3d3f56ca-064d16ce.js +0 -37
  24. package/exports/browser/index-543bc6a3-be806e11.js +0 -37
  25. package/exports/browser/messages-48deb2c3-73e8ace1.js +0 -205
  26. package/exports/browser/messages-af41e873-479a93a8.js +0 -205
  27. package/exports/browser/node-browser-13cbe71a.js +0 -16881
  28. package/exports/browser/node-browser-63c7cb33.js +0 -16877
  29. package/exports/browser/pako.esm-aa674ebf-aa674ebf.js +0 -6876
  30. package/exports/browser/simple-peer-743c19fe-03a0830e.js +0 -7856
package/exports/chain.js CHANGED
@@ -448,11 +448,16 @@ class Contract extends Transaction {
448
448
  }
449
449
  return this.createTransactionFrom(peernet.selectedAccount, addresses.contractFactory, 'registerContract', [await message.hash()]);
450
450
  }
451
+ async deployContractMessage(message) {
452
+ }
451
453
  }
452
454
 
453
455
  globalThis.BigNumber = BigNumber;
454
456
  // check if browser or local
455
457
  class Chain extends Contract {
458
+ #state;
459
+ id;
460
+ utils;
456
461
  /** {Address[]} */
457
462
  #validators = [];
458
463
  /** {Block[]} */
@@ -534,7 +539,7 @@ class Chain extends Contract {
534
539
  return [...this.#blocks];
535
540
  }
536
541
  async hasTransactionToHandle() {
537
- const size = await transactionPoolStore.size();
542
+ const size = await globalThis.transactionPoolStore.size();
538
543
  if (size > 0)
539
544
  return true;
540
545
  return false;
@@ -544,7 +549,7 @@ class Chain extends Contract {
544
549
  console.log('epoch');
545
550
  const validators = await this.staticCall(addresses.validators, 'validators');
546
551
  console.log({ validators });
547
- if (!validators[globalThis.peernet.selectedAccount]?.active)
552
+ if (!validators[globalThis.globalThis.peernet.selectedAccount]?.active)
548
553
  return;
549
554
  const start = Date.now();
550
555
  try {
@@ -577,7 +582,7 @@ class Chain extends Contract {
577
582
  await Promise.all(contracts.map(async ({ address, message }) => {
578
583
  // console.log({message});
579
584
  message = await new ContractMessage(Uint8Array.from(message.split(',').map(string => Number(string))));
580
- await contractStore.put(address, message.encoded);
585
+ await globalThis.contractStore.put(address, message.encoded);
581
586
  }));
582
587
  console.log('handle native contracts');
583
588
  // handle native contracts
@@ -586,14 +591,14 @@ class Chain extends Contract {
586
591
  return new Promise(async (resolve, reject) => {
587
592
  const timeout = setTimeout(() => {
588
593
  resolve([{ index: 0, hash: '0x0' }]);
589
- debug('sync timed out');
594
+ globalThis.debug('sync timed out');
590
595
  }, 10_000);
591
596
  promises = await Promise.allSettled(promises);
592
597
  promises = promises.filter(({ status }) => status === 'fulfilled');
593
598
  clearTimeout(timeout);
594
599
  if (promises.length > 0) {
595
600
  promises = promises.map(async ({ value }) => {
596
- const node = await new peernet.protos['peernet-response'](value.result);
601
+ const node = await new globalThis.peernet.protos['peernet-response'](value.result);
597
602
  return { value: node.decoded.response, peer: value.peer };
598
603
  });
599
604
  promises = await Promise.all(promises);
@@ -609,9 +614,9 @@ class Chain extends Contract {
609
614
  }
610
615
  async #getLatestBlock() {
611
616
  let promises = [];
612
- let data = await new peernet.protos['peernet-request']({ request: 'lastBlock' });
613
- let node = await peernet.prepareMessage(data);
614
- for (const peer of peernet?.connections) {
617
+ let data = await new globalThis.peernet.protos['peernet-request']({ request: 'lastBlock' });
618
+ let node = await globalThis.peernet.prepareMessage(data);
619
+ for (const peer of globalThis.peernet?.connections) {
615
620
  if (peer.connected && peer.readyState === 'open' && peer.peerId !== this.id) {
616
621
  promises.push(async () => {
617
622
  try {
@@ -631,18 +636,18 @@ class Chain extends Contract {
631
636
  if (promises.length > 0)
632
637
  latest = promises[0].value;
633
638
  if (latest.hash && latest.hash !== '0x0') {
634
- let message = await peernet.get(latest.hash, 'block');
639
+ let message = await globalThis.peernet.get(latest.hash, 'block');
635
640
  message = await new BlockMessage(message);
636
641
  const hash = await message.hash();
637
642
  if (hash !== latest.hash)
638
643
  throw new Error('invalid block @getLatestBlock');
639
- let data = await new peernet.protos['peernet-request']({ request: 'knownBlocks' });
640
- let node = await peernet.prepareMessage(data);
644
+ let data = await new globalThis.peernet.protos['peernet-request']({ request: 'knownBlocks' });
645
+ let node = await globalThis.peernet.prepareMessage(data);
641
646
  const peer = promises[0].peer;
642
647
  latest = { ...message.decoded, hash };
643
648
  if (peer.connected && peer.readyState === 'open' && peer.peerId !== this.id) {
644
649
  let message = await peer.request(node);
645
- message = await new peernet.protos['peernet-response'](message);
650
+ message = await new globalThis.peernet.protos['peernet-response'](message);
646
651
  this.#knownBlocks = message.decoded.response;
647
652
  }
648
653
  }
@@ -652,33 +657,37 @@ class Chain extends Contract {
652
657
  // this.node = await new Node()
653
658
  this.#participants = [];
654
659
  this.#participating = false;
655
- const initialized = await contractStore.has(addresses.contractFactory);
660
+ const initialized = await globalThis.contractStore.has(addresses.contractFactory);
656
661
  if (!initialized)
657
662
  await this.#setup();
658
663
  this.utils = { BigNumber, formatUnits, parseUnits };
659
- this.state = new State();
660
- await peernet.addRequestHandler('bw-request-message', () => {
661
- return new BWMessage(peernet.client.bw) || { up: 0, down: 0 };
664
+ this.#state = new State();
665
+ await globalThis.peernet.addRequestHandler('bw-request-message', () => {
666
+ return new BWMessage(globalThis.peernet.client.bw) || { up: 0, down: 0 };
662
667
  });
663
- await peernet.addRequestHandler('lastBlock', this.#lastBlockHandler.bind(this));
664
- await peernet.addRequestHandler('knownBlocks', this.#knownBlocksHandler.bind(this));
665
- peernet.subscribe('add-block', this.#addBlock.bind(this));
666
- peernet.subscribe('add-transaction', this.#addTransaction.bind(this));
667
- peernet.subscribe('validator:timeout', this.#validatorTimeout.bind(this));
668
- pubsub.subscribe('peer:connected', this.#peerConnected.bind(this));
668
+ // await globalThis.peernet.addRequestHandler('peerId', () => {
669
+ // let node =
670
+ // globalThis.peernet.protos['peernet-response']({response: node.encoded})
671
+ // })
672
+ await globalThis.peernet.addRequestHandler('lastBlock', this.#lastBlockHandler.bind(this));
673
+ await globalThis.peernet.addRequestHandler('knownBlocks', this.#knownBlocksHandler.bind(this));
674
+ globalThis.peernet.subscribe('add-block', this.#addBlock.bind(this));
675
+ globalThis.peernet.subscribe('add-transaction', this.#addTransaction.bind(this));
676
+ globalThis.peernet.subscribe('validator:timeout', this.#validatorTimeout.bind(this));
677
+ globalThis.pubsub.subscribe('peer:connected', this.#peerConnected.bind(this));
669
678
  // todo some functions rely on state
670
679
  try {
671
680
  let localBlock;
672
681
  try {
673
- localBlock = await chainStore.get('lastBlock');
682
+ localBlock = await globalThis.chainStore.get('lastBlock');
674
683
  }
675
684
  catch {
676
- await chainStore.put('lastBlock', '0x0');
677
- localBlock = await chainStore.get('lastBlock');
685
+ await globalThis.chainStore.put('lastBlock', '0x0');
686
+ localBlock = await globalThis.chainStore.get('lastBlock');
678
687
  }
679
688
  localBlock = new TextDecoder().decode(localBlock);
680
689
  if (localBlock && localBlock !== '0x0') {
681
- localBlock = await peernet.get(localBlock, 'block');
690
+ localBlock = await globalThis.peernet.get(localBlock, 'block');
682
691
  localBlock = await new BlockMessage(localBlock);
683
692
  this.#lastBlock = { ...localBlock.decoded, hash: await localBlock.hash() };
684
693
  }
@@ -696,12 +705,12 @@ class Chain extends Contract {
696
705
  await this.resolveBlocks();
697
706
  this.#machine = await new Machine(this.#blocks);
698
707
  await this.#loadBlocks(this.#blocks);
699
- globalThis.pubsub.publish('chain:ready', true);
708
+ globalThis.globalThis.pubsub.publish('chain:ready', true);
700
709
  return this;
701
710
  }
702
711
  async #validatorTimeout(validatorInfo) {
703
712
  setTimeout(() => {
704
- this.#jail.splice(this.jail.indexOf(validatorInfo.address), 1);
713
+ this.#jail.splice(this.#jail.indexOf(validatorInfo.address), 1);
705
714
  }, validatorInfo.timeout);
706
715
  this.#jail.push(validatorInfo.address);
707
716
  }
@@ -712,7 +721,7 @@ class Chain extends Contract {
712
721
  if (this.#knownBlocks?.length === Number(lastBlock.index) + 1) {
713
722
  let promises = [];
714
723
  promises = await Promise.allSettled(this.#knownBlocks.map(async (address) => {
715
- const has = await peernet.has(address, 'block');
724
+ const has = await globalThis.peernet.has(address, 'block');
716
725
  return { has, address };
717
726
  }));
718
727
  promises = promises.filter(({ status, value }) => status === 'fulfilled' && !value.has);
@@ -724,53 +733,58 @@ class Chain extends Contract {
724
733
  const index = lastBlock.index;
725
734
  await this.resolveBlock(lastBlock.hash);
726
735
  let blocksSynced = localIndex > 0 ? (localIndex > index ? localIndex - index : index - localIndex) : index;
727
- debug(`synced ${blocksSynced} ${blocksSynced > 1 ? 'blocks' : 'block'}`);
736
+ globalThis.debug(`synced ${blocksSynced} ${blocksSynced > 1 ? 'blocks' : 'block'}`);
728
737
  const start = (this.#blocks.length - blocksSynced) - 1;
729
- await this.#loadBlocks(this.blocks.slice(start));
738
+ if (this.#machine)
739
+ await this.#loadBlocks(this.blocks.slice(start));
730
740
  await this.#updateState(new BlockMessage(this.#blocks[this.#blocks.length - 1]));
731
741
  }
732
742
  this.#chainSyncing = false;
733
743
  }
734
744
  async #peerConnected(peer) {
735
- let node = await new peernet.protos['peernet-request']({ request: 'lastBlock' });
736
- node = await peernet.prepareMessage(node);
745
+ let node = await new globalThis.peernet.protos['peernet-request']({ request: 'lastBlock' });
746
+ node = await globalThis.peernet.prepareMessage(node);
737
747
  let response = await peer.request(node.encoded);
738
- response = await new globalThis.peernet.protos['peernet-response'](response);
748
+ response = await new globalThis.globalThis.peernet.protos['peernet-response'](new Uint8Array(Object.values(response)));
739
749
  let lastBlock = response.decoded.response;
740
750
  // try catch known blocks
741
- node = await new peernet.protos['peernet-request']({ request: 'knownBlocks' });
742
- node = await peernet.prepareMessage(node);
751
+ node = await new globalThis.peernet.protos['peernet-request']({ request: 'knownBlocks' });
752
+ node = await globalThis.peernet.prepareMessage(node);
743
753
  response = await peer.request(node.encoded);
744
- response = await new globalThis.peernet.protos['peernet-response'](response);
754
+ response = await new globalThis.globalThis.peernet.protos['peernet-response'](new Uint8Array(Object.values(response)));
745
755
  this.#knownBlocks = response.decoded.response;
746
756
  this.#syncChain(lastBlock);
747
757
  }
748
758
  #epochTimeout;
749
759
  async #lastBlockHandler() {
750
- return new peernet.protos['peernet-response']({ response: { hash: this.#lastBlock?.hash, index: this.#lastBlock?.index } });
760
+ return new globalThis.peernet.protos['peernet-response']({ response: { hash: this.#lastBlock?.hash, index: this.#lastBlock?.index } });
751
761
  }
752
762
  async #knownBlocksHandler() {
753
- return new peernet.protos['peernet-response']({ response: { blocks: this.#blocks.map((block) => block.hash) } });
763
+ return new globalThis.peernet.protos['peernet-response']({ response: { blocks: this.#blocks.map((block) => block.hash) } });
754
764
  }
755
765
  async getAndPutBlock(hash) {
756
- let block = await peernet.get(hash, 'block');
766
+ let block = await globalThis.peernet.get(hash, 'block');
757
767
  block = await new BlockMessage(block);
758
768
  const { index } = block.decoded;
759
769
  if (this.#blocks[index] && this.#blocks[index].hash !== block.hash)
760
770
  throw `invalid block ${hash} @${index}`;
761
- if (!await peernet.has(hash, 'block'))
762
- await peernet.put(hash, block.encoded, 'block');
771
+ if (!await globalThis.peernet.has(hash, 'block'))
772
+ await globalThis.peernet.put(hash, block.encoded, 'block');
763
773
  return block;
764
774
  }
765
775
  async resolveBlock(hash) {
766
776
  if (!hash)
767
777
  throw new Error(`expected hash, got: ${hash}`);
778
+ if (hash === '0x0')
779
+ return;
768
780
  const index = this.#blockHashMap.get(hash);
769
781
  if (this.#blocks[index]) {
770
782
  if (this.#blocks[index].previousHash !== '0x0') {
771
- return this.resolveBlock(this.#blocks[index]);
783
+ return this.resolveBlock(this.#blocks[index].previousHash);
784
+ }
785
+ else {
786
+ return;
772
787
  }
773
- return;
774
788
  }
775
789
  try {
776
790
  const block = await this.getAndPutBlock(hash);
@@ -790,14 +804,14 @@ class Chain extends Contract {
790
804
  }
791
805
  async resolveBlocks() {
792
806
  try {
793
- const localBlock = await chainStore.get('lastBlock');
807
+ const localBlock = await globalThis.chainStore.get('lastBlock');
794
808
  const hash = new TextDecoder().decode(localBlock);
795
809
  if (hash && hash !== '0x0')
796
810
  await this.resolveBlock(hash);
797
811
  this.#lastBlock = this.#blocks[this.#blocks.length - 1];
798
812
  }
799
813
  catch {
800
- await chainStore.put('lastBlock', new TextEncoder().encode('0x0'));
814
+ await globalThis.chainStore.put('lastBlock', new TextEncoder().encode('0x0'));
801
815
  return this.resolveBlocks();
802
816
  // console.log(e);
803
817
  }
@@ -828,7 +842,7 @@ class Chain extends Contract {
828
842
  }
829
843
  }
830
844
  this.#blocks[block.index].loaded = true;
831
- debug(`loaded block: ${block.hash} @${block.index}`);
845
+ globalThis.debug(`loaded block: ${block.hash} @${block.index}`);
832
846
  }
833
847
  }
834
848
  }
@@ -836,25 +850,24 @@ class Chain extends Contract {
836
850
  try {
837
851
  let result = await this.#machine.execute(to, method, params, from, nonce);
838
852
  // if (!result) result = this.#machine.state
839
- pubsub.publish(`transaction.completed.${hash}`, { status: 'fulfilled', hash });
853
+ globalThis.pubsub.publish(`transaction.completed.${hash}`, { status: 'fulfilled', hash });
840
854
  return result || 'no state change';
841
855
  }
842
856
  catch (error) {
843
857
  console.log(error);
844
- pubsub.publish(`transaction.completed.${hash}`, { status: 'fail', hash, error: error });
858
+ globalThis.pubsub.publish(`transaction.completed.${hash}`, { status: 'fail', hash, error: error });
845
859
  throw error;
846
860
  }
847
861
  }
848
862
  async #addBlock(block) {
849
- // console.log(block);
850
863
  const blockMessage = await new BlockMessage(block);
851
864
  await Promise.all(blockMessage.decoded.transactions
852
- .map(async (transaction) => transactionPoolStore.delete(transaction.hash)));
865
+ .map(async (transaction) => globalThis.transactionPoolStore.delete(transaction.hash)));
853
866
  const hash = await blockMessage.hash();
854
- await blockStore.put(hash, blockMessage.encoded);
867
+ await globalThis.blockStore.put(hash, blockMessage.encoded);
855
868
  if (this.lastBlock.index < blockMessage.decoded.index)
856
869
  await this.#updateState(blockMessage);
857
- debug(`added block: ${hash}`);
870
+ globalThis.debug(`added block: ${hash}`);
858
871
  let promises = [];
859
872
  let contracts = [];
860
873
  for (let transaction of blockMessage.decoded.transactions) {
@@ -868,10 +881,10 @@ class Chain extends Contract {
868
881
  try {
869
882
  promises = await Promise.allSettled(promises);
870
883
  for (let transaction of blockMessage.decoded.transactions) {
871
- pubsub.publish('transaction-processed', transaction);
872
- if (transaction.to === peernet.selectedAccount)
873
- pubsub.publish('account-transaction-processed', transaction);
874
- await accountsStore.put(transaction.from, String(transaction.nonce));
884
+ globalThis.pubsub.publish('transaction-processed', transaction);
885
+ if (transaction.to === globalThis.peernet.selectedAccount)
886
+ globalThis.pubsub.publish('account-transaction-processed', transaction);
887
+ await globalThis.accountsStore.put(transaction.from, String(transaction.nonce));
875
888
  }
876
889
  // todo finish state
877
890
  // for (const contract of contracts) {
@@ -879,7 +892,7 @@ class Chain extends Contract {
879
892
  // // await stateStore.put(contract, state)
880
893
  // console.log(state);
881
894
  // }
882
- pubsub.publish('block-processed', blockMessage.decoded);
895
+ globalThis.pubsub.publish('block-processed', blockMessage.decoded);
883
896
  }
884
897
  catch (error) {
885
898
  console.log({ e: error });
@@ -889,7 +902,7 @@ class Chain extends Contract {
889
902
  const hash = await message.hash();
890
903
  this.#lastBlock = { hash, ...message.decoded };
891
904
  // await this.state.updateState(message)
892
- await chainStore.put('lastBlock', hash);
905
+ await globalThis.chainStore.put('lastBlock', hash);
893
906
  }
894
907
  async participate(address) {
895
908
  // TODO: validate participant
@@ -908,7 +921,7 @@ class Chain extends Contract {
908
921
  nonce: (await this.getNonce(address)) + 1,
909
922
  timestamp: Date.now()
910
923
  };
911
- const transaction = await signTransaction(rawTransaction, peernet.identity);
924
+ const transaction = await signTransaction(rawTransaction, globalThis.peernet.identity);
912
925
  await this.sendTransaction(transaction);
913
926
  }
914
927
  if (await this.hasTransactionToHandle() && !this.#runningEpoch)
@@ -917,15 +930,19 @@ class Chain extends Contract {
917
930
  // todo filter tx that need to wait on prev nonce
918
931
  async #createBlock(limit = 1800) {
919
932
  // vote for transactions
920
- if (await transactionPoolStore.size() === 0)
933
+ if (await globalThis.transactionPoolStore.size() === 0)
921
934
  return;
922
- let transactions = await transactionPoolStore.values(this.transactionLimit);
935
+ let transactions = await globalThis.transactionPoolStore.values(this.transactionLimit);
923
936
  if (Object.keys(transactions)?.length === 0)
924
937
  return;
925
938
  let block = {
926
939
  transactions: [],
927
940
  validators: [],
928
- fees: BigNumber.from(0)
941
+ fees: BigNumber.from(0),
942
+ timestamp: Date.now(),
943
+ previousHash: '',
944
+ reward: parseUnits('150'),
945
+ index: 0
929
946
  };
930
947
  // exclude failing tx
931
948
  transactions = await this.promiseTransactions(transactions);
@@ -935,11 +952,11 @@ class Chain extends Contract {
935
952
  try {
936
953
  await this.#executeTransaction({ ...transaction.decoded, hash });
937
954
  block.transactions.push({ hash, ...transaction.decoded });
938
- block.fees += Number(calculateFee(transaction.decoded));
939
- await accountsStore.put(transaction.decoded.from, new TextEncoder().encode(String(transaction.decoded.nonce)));
955
+ block.fees = block.fees.add(await calculateFee(transaction.decoded));
956
+ await globalThis.accountsStore.put(transaction.decoded.from, new TextEncoder().encode(String(transaction.decoded.nonce)));
940
957
  }
941
958
  catch (e) {
942
- await transactionPoolStore.delete(hash);
959
+ await globalThis.transactionPoolStore.delete(hash);
943
960
  }
944
961
  }
945
962
  // don't add empty block
@@ -955,7 +972,7 @@ class Chain extends Contract {
955
972
  // }
956
973
  // }, [])
957
974
  const peers = {};
958
- for (const entry of peernet.peerEntries) {
975
+ for (const entry of globalThis.peernet.peerEntries) {
959
976
  peers[entry[0]] = entry[1];
960
977
  }
961
978
  for (const validator of Object.keys(validators)) {
@@ -963,7 +980,7 @@ class Chain extends Contract {
963
980
  const peer = peers[validator];
964
981
  if (peer && peer.connected) {
965
982
  let data = await new BWRequestMessage();
966
- const node = await peernet.prepareMessage(validator, data.encoded);
983
+ const node = await globalThis.peernet.prepareMessage(validator, data.encoded);
967
984
  try {
968
985
  const bw = await peer.request(node.encoded);
969
986
  console.log({ bw });
@@ -974,21 +991,24 @@ class Chain extends Contract {
974
991
  }
975
992
  catch { }
976
993
  }
977
- else if (peernet.selectedAccount === validator) {
994
+ else if (globalThis.peernet.selectedAccount === validator) {
978
995
  block.validators.push({
979
- address: peernet.selectedAccount,
980
- bw: peernet.bw.up + peernet.bw.down
996
+ address: globalThis.peernet.selectedAccount,
997
+ bw: globalThis.peernet.bw.up + globalThis.peernet.bw.down
981
998
  });
982
999
  }
983
1000
  }
984
1001
  }
985
1002
  console.log({ validators: block.validators });
986
- block.reward = 150;
987
1003
  block.validators = block.validators.map(validator => {
988
- validator.reward = String(Number(block.fees) + block.reward / block.validators.length);
1004
+ validator.reward = block.fees;
1005
+ validator.reward = validator.reward.add(block.reward);
1006
+ validator.reward = validator.reward.div(block.validators.length);
1007
+ validator.reward = validator.reward.toString();
989
1008
  delete validator.bw;
990
1009
  return validator;
991
1010
  });
1011
+ console.log({ validators: block.validators });
992
1012
  // block.validators = calculateValidatorReward(block.validators, block.fees)
993
1013
  block.index = this.lastBlock?.index;
994
1014
  if (block.index === undefined)
@@ -997,29 +1017,19 @@ class Chain extends Contract {
997
1017
  block.index += 1;
998
1018
  block.previousHash = this.lastBlock?.hash || '0x0';
999
1019
  block.timestamp = Date.now();
1000
- const parts = String(block.fees).split('.');
1001
- let decimals = 0;
1002
- if (parts[1]) {
1003
- const potentional = parts[1].split('e');
1004
- if (potentional[0] === parts[1]) {
1005
- decimals = parts[1].length;
1006
- }
1007
- else {
1008
- parts[1] = potentional[0];
1009
- decimals = Number(potentional[1]?.replace(/[+-]/g, '')) + Number(potentional[0].length);
1010
- }
1011
- }
1012
- block.fees = Number.parseFloat(String(block.fees)).toFixed(decimals);
1020
+ block.reward = block.reward.toString();
1021
+ block.fees = block.fees.toString();
1013
1022
  try {
1014
1023
  await Promise.all(block.transactions
1015
- .map(async (transaction) => transactionPoolStore.delete(transaction.hash)));
1024
+ .map(async (transaction) => globalThis.transactionPoolStore.delete(transaction.hash)));
1016
1025
  let blockMessage = await new BlockMessage(block);
1026
+ blockMessage = await new BlockMessage(blockMessage.encoded);
1017
1027
  const hash = await blockMessage.hash();
1018
- await peernet.put(hash, blockMessage.encoded, 'block');
1028
+ await globalThis.peernet.put(hash, blockMessage.encoded, 'block');
1019
1029
  await this.#updateState(blockMessage);
1020
- debug(`created block: ${hash}`);
1021
- peernet.publish('add-block', blockMessage.encoded);
1022
- pubsub.publish('add-block', blockMessage.decoded);
1030
+ globalThis.debug(`created block: ${hash}`);
1031
+ globalThis.peernet.publish('add-block', blockMessage.encoded);
1032
+ globalThis.pubsub.publish('add-block', blockMessage.decoded);
1023
1033
  }
1024
1034
  catch (error) {
1025
1035
  throw new Error(`invalid block ${block}`);
@@ -1031,9 +1041,9 @@ class Chain extends Contract {
1031
1041
  try {
1032
1042
  transaction = await new TransactionMessage(transaction);
1033
1043
  const hash = await transaction.hash();
1034
- const has = await transactionPoolStore.has(hash);
1044
+ const has = await globalThis.transactionPoolStore.has(hash);
1035
1045
  if (!has)
1036
- await transactionPoolStore.put(hash, transaction.encoded);
1046
+ await globalThis.transactionPoolStore.put(hash, transaction.encoded);
1037
1047
  if (this.#participating && !this.#runningEpoch)
1038
1048
  this.#runEpoch();
1039
1049
  }
@@ -1066,7 +1076,7 @@ class Chain extends Contract {
1066
1076
  * @param {Address} sender
1067
1077
  * @returns {globalMessage}
1068
1078
  */
1069
- #createMessage(sender = globalThis.peernet.selectedAccount) {
1079
+ #createMessage(sender = globalThis.globalThis.peernet.selectedAccount) {
1070
1080
  return {
1071
1081
  sender,
1072
1082
  call: this.call,
package/exports/node.js CHANGED
@@ -12,7 +12,8 @@ class Node {
12
12
  network: 'leofcoin:peach',
13
13
  networkName: 'leofcoin:peach',
14
14
  networkVersion: 'peach',
15
- stars: networks.leofcoin.peach.stars
15
+ stars: networks.leofcoin.peach.stars,
16
+ autoStart: false
16
17
  }, password) {
17
18
  this.#node = globalThis.Peernet ? await new globalThis.Peernet(config, password) : await new Peernet(config, password);
18
19
  await nodeConfig(config);
@@ -3,6 +3,8 @@ import Contract from './contract.js';
3
3
  import { BigNumberish } from '@ethersproject/bignumber';
4
4
  export default class Chain extends Contract {
5
5
  #private;
6
+ id: string;
7
+ utils: {};
6
8
  constructor();
7
9
  get nativeMints(): number;
8
10
  get nativeBurns(): number;
@@ -38,14 +40,14 @@ export default class Chain extends Contract {
38
40
  sendTransaction(transaction: any): Promise<{
39
41
  hash: any;
40
42
  data: any;
41
- fee: string | 0;
43
+ fee: any;
42
44
  wait: Promise<unknown>;
43
45
  message: any;
44
46
  }>;
45
47
  addContract(transaction: any, contractMessage: any): Promise<{
46
48
  hash: any;
47
49
  data: any;
48
- fee: string | 0;
50
+ fee: any;
49
51
  wait: Promise<unknown>;
50
52
  message: any;
51
53
  }>;
@@ -25,5 +25,6 @@ export default class Contract extends Transaction {
25
25
  * @returns
26
26
  */
27
27
  deployContract(contract: string, constructorParameters?: any[]): Promise<any>;
28
+ deployContractMessage(message: any): Promise<void>;
28
29
  }
29
30
  import Transaction from "./transaction.js";
@@ -6,5 +6,6 @@ export default class Node {
6
6
  networkName: string;
7
7
  networkVersion: string;
8
8
  stars: any;
9
+ autoStart: boolean;
9
10
  }, password: string): Promise<this>;
10
11
  }
@@ -40,7 +40,7 @@ export default class Transaction extends Protocol {
40
40
  sendTransaction(message: any): Promise<{
41
41
  hash: any;
42
42
  data: any;
43
- fee: string | 0;
43
+ fee: any;
44
44
  wait: Promise<unknown>;
45
45
  message: any;
46
46
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.4.36",
3
+ "version": "1.4.37",
4
4
  "description": "Official javascript implementation",
5
5
  "exports": {
6
6
  "./node": "./exports/node.js",
@@ -45,7 +45,9 @@
45
45
  "eslint": "^8.28.0",
46
46
  "eslint-plugin-unicorn": "^45.0.0",
47
47
  "open": "^8.4.0",
48
+ "rimraf": "^4.4.0",
48
49
  "rollup": "^3.12.0",
50
+ "rollup-plugin-modify": "^3.0.0",
49
51
  "tape": "^5.5.2",
50
52
  "tslib": "^2.4.1"
51
53
  },
@@ -56,7 +58,7 @@
56
58
  "@leofcoin/messages": "^1.2.0",
57
59
  "@leofcoin/multi-wallet": "^2.1.1",
58
60
  "@leofcoin/networks": "^1.0.0",
59
- "@leofcoin/peernet": "^1.1.2",
61
+ "@leofcoin/peernet": "^1.1.12",
60
62
  "@leofcoin/peernet-swarm": "^1.0.0",
61
63
  "@leofcoin/storage": "^3.0.6",
62
64
  "@leofcoin/utils": "^1.1.4",
@@ -1,56 +0,0 @@
1
- function _mergeNamespaces(n, m) {
2
- m.forEach(function (e) {
3
- e && typeof e !== 'string' && !Array.isArray(e) && Object.keys(e).forEach(function (k) {
4
- if (k !== 'default' && !(k in n)) {
5
- var d = Object.getOwnPropertyDescriptor(e, k);
6
- Object.defineProperty(n, k, d.get ? d : {
7
- enumerable: true,
8
- get: function () { return e[k]; }
9
- });
10
- }
11
- });
12
- });
13
- return Object.freeze(n);
14
- }
15
-
16
- var browser$1 = {};
17
-
18
- var MediaStream = browser$1.MediaStream = window.MediaStream;
19
- var MediaStreamTrack = browser$1.MediaStreamTrack = window.MediaStreamTrack;
20
- var RTCDataChannel = browser$1.RTCDataChannel = window.RTCDataChannel;
21
- var RTCDataChannelEvent = browser$1.RTCDataChannelEvent = window.RTCDataChannelEvent;
22
- var RTCDtlsTransport = browser$1.RTCDtlsTransport = window.RTCDtlsTransport;
23
- var RTCIceCandidate = browser$1.RTCIceCandidate = window.RTCIceCandidate;
24
- var RTCIceTransport = browser$1.RTCIceTransport = window.RTCIceTransport;
25
- var RTCPeerConnection = browser$1.RTCPeerConnection = window.RTCPeerConnection;
26
- var RTCPeerConnectionIceEvent = browser$1.RTCPeerConnectionIceEvent = window.RTCPeerConnectionIceEvent;
27
- var RTCRtpReceiver = browser$1.RTCRtpReceiver = window.RTCRtpReceiver;
28
- var RTCRtpSender = browser$1.RTCRtpSender = window.RTCRtpSender;
29
- var RTCRtpTransceiver = browser$1.RTCRtpTransceiver = window.RTCRtpTransceiver;
30
- var RTCSctpTransport = browser$1.RTCSctpTransport = window.RTCSctpTransport;
31
- var RTCSessionDescription = browser$1.RTCSessionDescription = window.RTCSessionDescription;
32
- var getUserMedia = browser$1.getUserMedia = window.getUserMedia;
33
- var mediaDevices = browser$1.mediaDevices = navigator.mediaDevices;
34
-
35
- var browser = /*#__PURE__*/_mergeNamespaces({
36
- __proto__: null,
37
- MediaStream: MediaStream,
38
- MediaStreamTrack: MediaStreamTrack,
39
- RTCDataChannel: RTCDataChannel,
40
- RTCDataChannelEvent: RTCDataChannelEvent,
41
- RTCDtlsTransport: RTCDtlsTransport,
42
- RTCIceCandidate: RTCIceCandidate,
43
- RTCIceTransport: RTCIceTransport,
44
- RTCPeerConnection: RTCPeerConnection,
45
- RTCPeerConnectionIceEvent: RTCPeerConnectionIceEvent,
46
- RTCRtpReceiver: RTCRtpReceiver,
47
- RTCRtpSender: RTCRtpSender,
48
- RTCRtpTransceiver: RTCRtpTransceiver,
49
- RTCSctpTransport: RTCSctpTransport,
50
- RTCSessionDescription: RTCSessionDescription,
51
- default: browser$1,
52
- getUserMedia: getUserMedia,
53
- mediaDevices: mediaDevices
54
- }, [browser$1]);
55
-
56
- export { browser as b };