@leofcoin/chain 1.5.24 → 1.5.25

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/exports/chain.js CHANGED
@@ -12,7 +12,7 @@ const requestTimeout = 30000;
12
12
  const syncTimeout = 30000;
13
13
  class Protocol {
14
14
  constructor() {
15
- this.resolveTimeout = 30000;
15
+ this.resolveTimeout = 10000;
16
16
  }
17
17
  get limit() {
18
18
  return limit;
@@ -496,7 +496,7 @@ class Jobber {
496
496
  const timeout = setTimeout(() => {
497
497
  reject('timeout');
498
498
  }, this.timeout);
499
- this.stop = () => {
499
+ this.destroy = () => {
500
500
  clearTimeout(timeout);
501
501
  this.busy = false;
502
502
  resolve('stopped');
@@ -508,6 +508,7 @@ class Jobber {
508
508
  resolve(result);
509
509
  }
510
510
  catch (error) {
511
+ clearTimeout(timeout);
511
512
  reject(error);
512
513
  }
513
514
  });
@@ -521,6 +522,7 @@ class State extends Contract {
521
522
  #resolving;
522
523
  #resolveErrorCount;
523
524
  #syncState;
525
+ #chainState;
524
526
  #lastBlockInQue;
525
527
  #syncErrorCount;
526
528
  #blockHashMap;
@@ -530,6 +532,12 @@ class State extends Contract {
530
532
  #totalSize;
531
533
  #machine;
532
534
  #loaded;
535
+ get state() {
536
+ return {
537
+ sync: this.#syncState,
538
+ chain: this.#chainState
539
+ };
540
+ }
533
541
  get blockHashMap() {
534
542
  return this.#blockHashMap.entries();
535
543
  }
@@ -591,8 +599,10 @@ class State extends Contract {
591
599
  }
592
600
  constructor() {
593
601
  super();
602
+ this.#lastResolvedTime = 0;
594
603
  this.#resolving = false;
595
604
  this.#resolveErrorCount = 0;
605
+ this.#chainState = 'loading';
596
606
  this.#syncErrorCount = 0;
597
607
  this.#blockHashMap = new Map();
598
608
  this.#chainSyncing = false;
@@ -624,6 +634,15 @@ class State extends Contract {
624
634
  * {Number}
625
635
  */
626
636
  this.#totalTransactions = 0;
637
+ this.#chainStateHandler = () => {
638
+ return new globalThis.peernet.protos['peernet-response']({ response: this.#chainState });
639
+ };
640
+ this.#lastBlockHandler = async () => {
641
+ return new globalThis.peernet.protos['peernet-response']({ response: { hash: this.#lastBlock?.hash, index: this.#lastBlock?.index } });
642
+ };
643
+ this.#knownBlocksHandler = async () => {
644
+ return new globalThis.peernet.protos['peernet-response']({ response: { blocks: this.#blocks.map((block) => block.hash) } });
645
+ };
627
646
  this.#loadBlockTransactions = (transactions) => Promise.all(transactions.map((transaction) => new TransactionMessage(transaction)));
628
647
  this.#getLastTransactions = async () => {
629
648
  let lastTransactions = (await Promise.all(this.#blocks.filter(block => block.loaded).slice(-128)
@@ -644,12 +663,16 @@ class State extends Contract {
644
663
  await globalThis.blockStore.clear();
645
664
  await globalThis.transactionPoolStore.clear();
646
665
  }
666
+ #chainStateHandler;
667
+ #lastBlockHandler;
668
+ #knownBlocksHandler;
647
669
  async init() {
648
- this.jobber = new Jobber(30000);
670
+ this.jobber = new Jobber(this.resolveTimeout);
649
671
  if (super.init)
650
672
  await super.init();
651
- await globalThis.peernet.addRequestHandler('lastBlock', this.#lastBlockHandler.bind(this));
652
- await globalThis.peernet.addRequestHandler('knownBlocks', this.#knownBlocksHandler.bind(this));
673
+ await globalThis.peernet.addRequestHandler('lastBlock', this.#lastBlockHandler);
674
+ await globalThis.peernet.addRequestHandler('knownBlocks', this.#knownBlocksHandler);
675
+ await globalThis.peernet.addRequestHandler('chainState', this.#chainStateHandler);
653
676
  try {
654
677
  let localBlock;
655
678
  try {
@@ -704,12 +727,6 @@ class State extends Contract {
704
727
  await globalThis.chainStore.put('lastBlock', hash);
705
728
  globalThis.pubsub.publish('lastBlock', this.#lastBlock);
706
729
  }
707
- async #lastBlockHandler() {
708
- return new globalThis.peernet.protos['peernet-response']({ response: { hash: this.#lastBlock?.hash, index: this.#lastBlock?.index } });
709
- }
710
- async #knownBlocksHandler() {
711
- return new globalThis.peernet.protos['peernet-response']({ response: { blocks: this.#blocks.map((block) => block.hash) } });
712
- }
713
730
  getLatestBlock() {
714
731
  // @ts-ignore
715
732
  return this.#getLatestBlock();
@@ -750,8 +767,6 @@ class State extends Contract {
750
767
  this.#lastResolvedTime = Date.now();
751
768
  }
752
769
  catch (error) {
753
- this.#resolving = false;
754
- this.#chainSyncing = false;
755
770
  throw new ResolveError(`block: ${hash}@${index}`);
756
771
  }
757
772
  return;
@@ -764,6 +779,8 @@ class State extends Contract {
764
779
  if (this.#resolving)
765
780
  return 'already resolving';
766
781
  this.#resolving = true;
782
+ if (this.jobber.busy && this.jobber.destroy)
783
+ await this.jobber.destroy();
767
784
  try {
768
785
  await this.jobber.add(() => this.#resolveBlock(hash));
769
786
  this.#resolving = false;
@@ -773,6 +790,7 @@ class State extends Contract {
773
790
  catch (error) {
774
791
  console.log({ error });
775
792
  this.#resolveErrorCount += 1;
793
+ this.#resolving = false;
776
794
  if (this.#resolveErrorCount < 3)
777
795
  return this.resolveBlock(hash);
778
796
  this.#resolveErrorCount = 0;
@@ -781,8 +799,8 @@ class State extends Contract {
781
799
  }
782
800
  async resolveBlocks() {
783
801
  try {
784
- if (this.jobber.busy && this.jobber.stop) {
785
- await this.jobber.stop();
802
+ if (this.jobber.busy && this.jobber.destroy) {
803
+ await this.jobber.destroy();
786
804
  }
787
805
  }
788
806
  catch (error) {
@@ -798,10 +816,10 @@ class State extends Contract {
798
816
  }
799
817
  catch (error) {
800
818
  console.log(error);
819
+ this.#chainSyncing = false;
820
+ this.#syncState = 'errored';
801
821
  this.#resolveErrored = true;
802
- this.#resolveErrorCount += 1;
803
- this.#resolving = false;
804
- this.restoreChain();
822
+ return this.restoreChain();
805
823
  // console.log(e);
806
824
  }
807
825
  }
@@ -819,23 +837,25 @@ class State extends Contract {
819
837
  this.#resolveErrored = true;
820
838
  this.#resolveErrorCount += 1;
821
839
  this.#resolving = false;
822
- this.restoreChain();
840
+ return this.restoreChain();
823
841
  // console.log(e);
824
842
  }
825
843
  }
844
+ destroyResolveJob() {
845
+ }
826
846
  async syncChain(lastBlock) {
827
- if (!this.shouldSync) {
847
+ if (!this.shouldSync)
828
848
  return;
829
- }
849
+ this.#syncState;
850
+ this.#chainSyncing = true;
830
851
  try {
831
- if (this.jobber.busy && this.jobber.stop) {
832
- await this.jobber.stop();
852
+ if (this.jobber.busy && this.jobber.destroy) {
853
+ await this.jobber.destroy();
833
854
  }
834
855
  }
835
856
  catch (error) {
836
857
  console.error(error);
837
858
  }
838
- this.#chainSyncing = true;
839
859
  if (!lastBlock)
840
860
  lastBlock = await this.#getLatestBlock();
841
861
  console.log('starting sync');
@@ -850,7 +870,8 @@ class State extends Contract {
850
870
  return this.syncChain(lastBlock);
851
871
  this.#syncErrorCount = 0;
852
872
  this.#chainSyncing = false;
853
- return 'errored';
873
+ this.#syncState = 'errored';
874
+ return this.#syncState;
854
875
  }
855
876
  if (lastBlock.index === this.#lastBlockInQue?.index)
856
877
  this.#lastBlockInQue = undefined;
@@ -858,7 +879,8 @@ class State extends Contract {
858
879
  this.#chainSyncing = false;
859
880
  if (this.#lastBlockInQue)
860
881
  return this.syncChain(this.#lastBlockInQue);
861
- return 'synced';
882
+ this.#syncState = 'synced';
883
+ return this.#syncState;
862
884
  }
863
885
  async #syncChain(lastBlock) {
864
886
  try {
@@ -940,6 +962,7 @@ class State extends Contract {
940
962
  * @param {Block[]} blocks
941
963
  */
942
964
  async #loadBlocks(blocks) {
965
+ this.#chainState = 'loading';
943
966
  let poolTransactionKeys = await globalThis.transactionPoolStore.keys();
944
967
  for (const block of blocks) {
945
968
  if (block && !block.loaded) {
@@ -992,6 +1015,7 @@ class State extends Contract {
992
1015
  globalThis.pubsub.publish('block-loaded', { ...block });
993
1016
  }
994
1017
  }
1018
+ this.#chainState = 'loaded';
995
1019
  return true;
996
1020
  }
997
1021
  promiseRequests(promises) {
@@ -1022,9 +1046,12 @@ class State extends Contract {
1022
1046
  return true;
1023
1047
  }
1024
1048
  get shouldSync() {
1025
- if (this.canSync ||
1026
- this.#resolveErrored ||
1027
- !this.canSync && this.#lastResolvedTime + this.resolveTimeout > new Date().getTime())
1049
+ if (this.#chainSyncing)
1050
+ return false;
1051
+ if (this.#resolveErrored ||
1052
+ this.#syncState === 'errored' ||
1053
+ this.#syncState === 'connectionless' ||
1054
+ !this.canSync && this.#lastResolvedTime + this.resolveTimeout > Date.now())
1028
1055
  return true;
1029
1056
  return false;
1030
1057
  }
@@ -1207,31 +1234,36 @@ class Chain extends VersionControl {
1207
1234
  response = await new globalThis.peernet.protos['peernet-response'](new Uint8Array(Object.values(response)));
1208
1235
  return response.decoded.response;
1209
1236
  }
1237
+ async getPeerTransactionPool(peer) {
1238
+ const transactionsInPool = await this.#makeRequest(peer, 'transactionPool');
1239
+ // todo iterate vs getting all keys?
1240
+ const transactions = await globalThis.transactionPoolStore.keys();
1241
+ const transactionsToGet = [];
1242
+ for (const key of transactionsInPool) {
1243
+ !transactions.includes(key) &&
1244
+ !ignorelist.includes(key) &&
1245
+ transactionsToGet.push(transactionPoolStore.put(key, await peernet.get(key, 'transaction')));
1246
+ }
1247
+ return Promise.all(transactionsToGet);
1248
+ }
1210
1249
  async #peerConnected(peer) {
1211
1250
  // todo handle version changes
1212
1251
  // for now just do nothing if version doesn't match
1213
1252
  if (!peer.version || peer.version !== this.version)
1214
1253
  return;
1215
1254
  const lastBlock = await this.#makeRequest(peer, 'lastBlock');
1216
- let transactionsInPool = await this.#makeRequest(peer, 'transactionPool');
1217
- const transactions = await globalThis.transactionPoolStore.keys();
1218
- const transactionsToGet = [];
1219
- for (const key of transactionsInPool) {
1220
- if (!transactions.includes(key) && !ignorelist.includes(key))
1221
- transactionsToGet.push(transactionPoolStore.put(key, (await peernet.get(key, 'transaction'))));
1222
- }
1223
- await Promise.all(transactionsToGet);
1255
+ const higherThenCurrentLocal = lastBlock.index > this.lastBlock?.index;
1256
+ const peerTransactionPool = higherThenCurrentLocal && await this.getPeerTransactionPool(peer) || [];
1224
1257
  if (Object.keys(lastBlock).length > 0) {
1225
- if (!this.lastBlock || !this.blocks[this.blocks.length - 1]?.loaded || lastBlock && lastBlock.index > this.lastBlock?.index || !this.loaded && !this.resolving) {
1258
+ if (!this.lastBlock || higherThenCurrentLocal) {
1226
1259
  this.knownBlocks = await this.#makeRequest(peer, 'knownBlocks');
1227
1260
  await this.syncChain(lastBlock);
1228
- // if (await this.hasTransactionToHandle() && this.#participating) this.#runEpoch()
1229
1261
  }
1230
1262
  else if (!this.knownBlocks)
1231
1263
  this.knownBlocks = await this.#makeRequest(peer, 'knownBlocks');
1232
1264
  }
1233
- if (this.#participating)
1234
- this.#runEpoch();
1265
+ if (this.#participating && peerTransactionPool.length > 0)
1266
+ return this.#runEpoch();
1235
1267
  }
1236
1268
  #epochTimeout;
1237
1269
  async #transactionPoolHandler() {
@@ -1,7 +1,7 @@
1
1
  export default class Jobber {
2
2
  timeout: EpochTimeStamp;
3
3
  busy: boolean;
4
- stop: Function;
4
+ destroy: Function;
5
5
  constructor(timeout: any);
6
6
  add(fn: any): Promise<unknown>;
7
7
  }
@@ -4,10 +4,15 @@ import Machine from './machine.js';
4
4
  import Jobber from './jobs/jobber.js';
5
5
  import { BlockHash } from './types.js';
6
6
  declare type SyncState = 'syncing' | 'synced' | 'errored' | 'connectionless';
7
+ declare type ChainState = 'loading' | 'loaded';
7
8
  export default class State extends Contract {
8
9
  #private;
9
10
  knownBlocks: BlockHash[];
10
11
  jobber: Jobber;
12
+ get state(): {
13
+ sync: SyncState;
14
+ chain: ChainState;
15
+ };
11
16
  get blockHashMap(): IterableIterator<[any, any]>;
12
17
  get loaded(): boolean;
13
18
  get resolving(): boolean;
@@ -35,8 +40,9 @@ export default class State extends Contract {
35
40
  getLatestBlock(): Promise<BlockMessage['decoded']>;
36
41
  getAndPutBlock(hash: string): Promise<BlockMessage>;
37
42
  resolveBlock(hash: any): any;
38
- resolveBlocks(): Promise<void>;
39
- restoreChain(): Promise<void>;
43
+ resolveBlocks(): Promise<any>;
44
+ restoreChain(): any;
45
+ destroyResolveJob(): void;
40
46
  syncChain(lastBlock?: any): Promise<SyncState>;
41
47
  promiseRequests(promises: any): Promise<unknown>;
42
48
  get canSync(): boolean;
@@ -1,4 +1,4 @@
1
- import { E as EasyWorker, B as BigNumber, a as BlockMessage, f as formatBytes } from './worker-156dda16.js';
1
+ import { E as EasyWorker, B as BigNumber, a as BlockMessage, f as formatBytes } from './worker-0f66935f.js';
2
2
 
3
3
  const worker = new EasyWorker();
4
4
 
@@ -1,4 +1,4 @@
1
- import { E as EasyWorker, B as BigNumber, f as formatBytes, C as ContractMessage, a as BlockMessage } from './worker-156dda16.js';
1
+ import { E as EasyWorker, B as BigNumber, f as formatBytes, C as ContractMessage, a as BlockMessage } from './worker-0f66935f.js';
2
2
 
3
3
  var contractFactory = "237,198,141,3,53,89,84,113,119,88,110,55,76,101,103,89,119,65,109,100,117,75,88,119,116,83,52,118,52,100,97,114,113,66,84,81,82,76,90,106,50,57,117,106,112,114,98,104,52,119,121,76,106,112,56,50,87,106,173,5,99,108,97,115,115,32,70,97,99,116,111,114,121,123,35,110,97,109,101,61,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,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,105,115,82,101,103,105,115,116,101,114,101,100,40,97,100,100,114,101,115,115,41,123,114,101,116,117,114,110,32,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,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,34,104,97,115,82,111,108,101,34,44,91,109,115,103,46,115,101,110,100,101,114,44,34,79,87,78,69,82,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,34,97,108,114,101,97,100,121,32,114,101,103,105,115,116,101,114,101,100,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,2,91,93";
4
4
  var nativeToken = "237,198,141,3,53,89,84,113,119,88,110,55,76,101,103,89,119,65,109,100,117,75,88,119,116,83,52,118,52,100,97,114,113,66,84,81,82,76,90,106,50,57,117,106,112,114,98,104,52,119,121,76,106,112,56,50,87,106,163,26,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,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,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,34,79,87,78,69,82,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,34,79,87,78,69,82,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,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,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,34,79,87,78,69,82,34,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,78,111,116,32,97,108,108,111,119,101,100,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,34,79,87,78,69,82,34,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,78,111,116,32,97,108,108,111,119,101,100,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,34,110,97,109,101,32,117,110,100,101,102,105,110,101,100,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,34,115,121,109,98,111,108,32,117,110,100,101,102,105,110,101,100,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,34,77,73,78,84,34,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,110,111,116,32,97,108,108,111,119,101,100,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,34,66,85,82,78,34,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,110,111,116,32,97,108,108,111,119,101,100,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,34,97,109,111,117,110,116,32,101,120,99,101,101,100,115,32,98,97,108,97,110,99,101,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,34,48,120,48,48,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,34,48,120,48,48,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,34,48,120,48,48,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,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,34,65,114,116,79,110,108,105,110,101,34,44,34,65,82,84,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,2,91,93";
@@ -5500,6 +5500,8 @@ class TransactionMessage extends FormatInterface {
5500
5500
  return 'TransactionMessage';
5501
5501
  }
5502
5502
  constructor(buffer) {
5503
+ if (buffer instanceof TransactionMessage)
5504
+ return buffer;
5503
5505
  const name = 'transaction-message';
5504
5506
  super(buffer, proto$3, { name });
5505
5507
  }
@@ -5515,6 +5517,8 @@ class ValidatorMessage extends FormatInterface {
5515
5517
  return 'ValidatorMessage';
5516
5518
  }
5517
5519
  constructor(buffer) {
5520
+ if (buffer instanceof ValidatorMessage)
5521
+ return buffer;
5518
5522
  const name = 'validator-message';
5519
5523
  super(buffer, proto$2, { name });
5520
5524
  }
@@ -5535,6 +5539,8 @@ class BlockMessage extends FormatInterface {
5535
5539
  return 'BlockMessage';
5536
5540
  }
5537
5541
  constructor(buffer) {
5542
+ if (buffer instanceof BlockMessage)
5543
+ return buffer;
5538
5544
  const name = 'block-message';
5539
5545
  super(buffer, proto$1, { name });
5540
5546
  }
@@ -5582,6 +5588,8 @@ class ContractMessage extends FormatInterface {
5582
5588
  return 'ContractMessage';
5583
5589
  }
5584
5590
  constructor(buffer) {
5591
+ if (buffer instanceof ContractMessage)
5592
+ return buffer;
5585
5593
  super(buffer, proto, { name: 'contract-message' });
5586
5594
  }
5587
5595
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.5.24",
3
+ "version": "1.5.25",
4
4
  "description": "Official javascript implementation",
5
5
  "exports": {
6
6
  "./node": {
@@ -1,37 +0,0 @@
1
- import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-c27ce598.js';
2
- import './index-b3d08518.js';
3
-
4
- /**
5
- * @params {String} network
6
- * @return {object} { identity, accounts, config }
7
- */
8
- var index = async (password, network) => {
9
- if (!password)
10
- throw new Error('wallets need to be password protected.');
11
- let wallet = new MultiWallet(network);
12
- /**
13
- * @type {string}
14
- */
15
- let mnemonic = await wallet.generate(password);
16
- wallet = new MultiWallet(network);
17
- await wallet.recover(mnemonic, password, network);
18
- mnemonic = new Uint8Array(await encrypt(password, mnemonic));
19
- const multiWIF = new Uint8Array(await encrypt(password, await wallet.multiWIF));
20
- /**
21
- * @type {object}
22
- */
23
- const external = await wallet.account(1).external(1);
24
- const externalAddress = await external.address;
25
- const internal = await wallet.account(1).internal(1);
26
- const internalAddress = await internal.address;
27
- return {
28
- identity: {
29
- mnemonic: base58$1.encode(mnemonic),
30
- multiWIF: base58$1.encode(multiWIF),
31
- walletId: await external.id
32
- },
33
- accounts: [['main account', externalAddress, internalAddress]]
34
- };
35
- };
36
-
37
- export { index as default };