@leofcoin/chain 1.4.91 → 1.4.93

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.
@@ -6081,4 +6081,4 @@ class RawTransactionMessage extends FormatInterface {
6081
6081
  }
6082
6082
  }
6083
6083
 
6084
- export { BigNumber as B, ContractMessage as C, Logger as L, RawTransactionMessage as R, TransactionMessage as T, ValidatorMessage as V, arrayify as a, isBytes as b, BlockMessage as c, BWMessage as d, BWRequestMessage as e, getDefaultExportFromCjs as g, hexZeroPad as h, isBigNumberish as i, toBase58 as t, version as v };
6084
+ export { BigNumber as B, ContractMessage as C, Logger as L, RawTransactionMessage as R, TransactionMessage as T, ValidatorMessage as V, arrayify as a, isBytes as b, BlockMessage as c, BWMessage as d, BWRequestMessage as e, hexZeroPad as h, isBigNumberish as i, toBase58 as t, version as v };
@@ -1,5 +1,5 @@
1
- import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-e89e6592.js';
2
- import './index-fd1bc5f0.js';
1
+ import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-b56b946d.js';
2
+ import './index-b32f624f.js';
3
3
 
4
4
  /**
5
5
  * @params {String} network
@@ -1,5 +1,5 @@
1
- import { F as FormatInterface } from './node-browser-e89e6592.js';
2
- import './index-fd1bc5f0.js';
1
+ import { F as FormatInterface } from './node-browser-b56b946d.js';
2
+ import './index-b32f624f.js';
3
3
 
4
4
  var proto$b = {
5
5
  data: new Uint8Array(),
@@ -1,4 +1,4 @@
1
- import { C as ContractMessage, T as TransactionMessage, c as BlockMessage, d as BWMessage, e as BWRequestMessage, V as ValidatorMessage } from './index-fd1bc5f0.js';
1
+ import { C as ContractMessage, T as TransactionMessage, c as BlockMessage, d as BWMessage, e as BWRequestMessage, V as ValidatorMessage } from './index-b32f624f.js';
2
2
 
3
3
  var nodeConfig = async (config = {
4
4
  network: 'leofcoin:peach',
@@ -20166,7 +20166,7 @@ class Identity {
20166
20166
  globalThis.peernet.selectedAccount = new TextDecoder().decode(selected);
20167
20167
  }
20168
20168
  else {
20169
- const importee = await import(/* webpackChunkName: "generate-account" */ './index-ed6cbdf7-cced6308.js');
20169
+ const importee = await import(/* webpackChunkName: "generate-account" */ './index-ed6cbdf7-8662153e.js');
20170
20170
  const { identity, accounts } = await importee.default(password, this.network);
20171
20171
  await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
20172
20172
  await globalThis.walletStore.put('version', String(1));
@@ -20345,7 +20345,7 @@ class Peernet {
20345
20345
  this.root = options.root;
20346
20346
  const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
20347
20347
  // FolderMessageResponse
20348
- } = await import(/* webpackChunkName: "messages" */ './messages-35d069e1-0b6352ff.js');
20348
+ } = await import(/* webpackChunkName: "messages" */ './messages-35d069e1-7ad3a4bb.js');
20349
20349
  /**
20350
20350
  * proto Object containing protos
20351
20351
  * @type {Object}
@@ -20873,15 +20873,26 @@ class Peernet {
20873
20873
  }
20874
20874
  globalThis.Peernet = Peernet;
20875
20875
 
20876
+ // todo only one star needed, no need to have one for each network
20877
+ // unless we change anything to the star protocoll
20878
+ // version diferences should be handled in the chain
20879
+ // maybe a good way to handle could be in p2pt-swarm
20876
20880
  var networks = {
20877
20881
  leofcoin: {
20878
20882
  mainnet: {
20879
- port: 33333,
20880
- stars: ['wss://mainnet.leofcoin.org'] // todo webrtc and bittorent stars
20883
+ // ports don't really matter since it is favorable to have it begind a ngninx proxy but if we change something to the proto it's easier maybe?
20884
+ port: 44444,
20885
+ // todo a versionhash would be nice to have as a double check?
20886
+ versionHash: '0',
20887
+ // a short description identifying the version
20888
+ description: 'Main net current version',
20889
+ stars: ['wss://star.leofcoin.org'] // todo webrtc and bittorent stars
20881
20890
  },
20882
20891
  peach: {
20883
20892
  port: 44444,
20884
- stars: ['wss://peach.leofcoin.org'] // todo webrtc and bittorent stars
20893
+ description: 'Main testnet: latest step before merging into main',
20894
+ versionHash: '1',
20895
+ stars: ['wss://star.leofcoin.org'] // todo webrtc and bittorent stars
20885
20896
  }
20886
20897
  }
20887
20898
  };
@@ -1,2 +1,2 @@
1
- export { N as default } from './node-browser-e89e6592.js';
2
- import './index-fd1bc5f0.js';
1
+ export { N as default } from './node-browser-b56b946d.js';
2
+ import './index-b32f624f.js';
package/exports/chain.js CHANGED
@@ -2,7 +2,6 @@ import { formatBytes, BigNumber, formatUnits, parseUnits } from '@leofcoin/utils
2
2
  import { TransactionMessage, BlockMessage, ContractMessage, BWMessage, BWRequestMessage } from '@leofcoin/messages';
3
3
  import addresses, { contractFactory, nativeToken, validators, nameService } from '@leofcoin/addresses';
4
4
  import { calculateFee, createContractMessage, contractFactoryMessage, nativeTokenMessage, validatorsMessage, nameServiceMessage, signTransaction } from '@leofcoin/lib';
5
- import PQueue from 'p-queue';
6
5
  import { randombytes } from '@leofcoin/crypto';
7
6
  import EasyWorker from '@vandeurenglenn/easy-worker';
8
7
 
@@ -11,8 +10,9 @@ const transactionLimit = 1800;
11
10
  const requestTimeout = 30000;
12
11
  const syncTimeout = 30000;
13
12
  class Protocol {
14
- version;
15
- resolveTimeout = 30000;
13
+ constructor() {
14
+ this.resolveTimeout = 30000;
15
+ }
16
16
  get limit() {
17
17
  return limit;
18
18
  }
@@ -254,11 +254,12 @@ class Contract extends Transaction {
254
254
 
255
255
  // import State from './state'
256
256
  class Machine {
257
- worker;
258
- #contracts = {};
259
- #nonces = {};
260
- lastBlock = { index: 0, hash: '0x0', previousHash: '0x0' };
257
+ #contracts;
258
+ #nonces;
261
259
  constructor(blocks) {
260
+ this.#contracts = {};
261
+ this.#nonces = {};
262
+ this.lastBlock = { index: 0, hash: '0x0', previousHash: '0x0' };
262
263
  // @ts-ignore
263
264
  return this.#init(blocks);
264
265
  }
@@ -472,10 +473,8 @@ class Machine {
472
473
  }
473
474
 
474
475
  class Jobber {
475
- timeout;
476
- busy = false;
477
- stop;
478
476
  constructor(timeout) {
477
+ this.busy = false;
479
478
  this.timeout = timeout;
480
479
  }
481
480
  add(fn) {
@@ -497,24 +496,22 @@ class Jobber {
497
496
  }
498
497
  }
499
498
 
500
- new PQueue({ concurrency: 1, throwOnTimeout: true });
501
499
  class State extends Contract {
502
500
  #resolveErrored;
503
501
  #lastResolvedTime;
504
502
  #lastResolved;
505
- #resolving = false;
506
- #resolveErrorCount = 0;
503
+ #resolving;
504
+ #resolveErrorCount;
507
505
  #syncState;
508
506
  #lastBlockInQue;
509
- #syncErrorCount = 0;
510
- #blockHashMap = new Map();
511
- #chainSyncing = false;
512
- #lastBlock = { index: 0, hash: '0x0', previousHash: '0x0' };
513
- #blocks = [];
514
- knownBlocks = [];
515
- #totalSize = 0;
507
+ #syncErrorCount;
508
+ #blockHashMap;
509
+ #chainSyncing;
510
+ #lastBlock;
511
+ #blocks;
512
+ #totalSize;
516
513
  #machine;
517
- #loaded = false;
514
+ #loaded;
518
515
  get blockHashMap() {
519
516
  return this.#blockHashMap.entries();
520
517
  }
@@ -527,26 +524,26 @@ class State extends Contract {
527
524
  /**
528
525
  * amount the native token has been iteracted with
529
526
  */
530
- #nativeCalls = 0;
527
+ #nativeCalls;
531
528
  /**
532
529
  * amount the native token has been iteracted with
533
530
  */
534
- #nativeTransfers = 0;
531
+ #nativeTransfers;
535
532
  /**
536
533
  * amount of native token burned
537
534
  * {Number}
538
535
  */
539
- #nativeBurns = 0;
536
+ #nativeBurns;
540
537
  /**
541
538
  * amount of native tokens minted
542
539
  * {Number}
543
540
  */
544
- #nativeMints = 0;
541
+ #nativeMints;
545
542
  /**
546
543
  * total amount of transactions
547
544
  * {Number}
548
545
  */
549
- #totalTransactions = 0;
546
+ #totalTransactions;
550
547
  get nativeMints() {
551
548
  return this.#nativeMints;
552
549
  }
@@ -576,6 +573,46 @@ class State extends Contract {
576
573
  }
577
574
  constructor() {
578
575
  super();
576
+ this.#resolving = false;
577
+ this.#resolveErrorCount = 0;
578
+ this.#syncErrorCount = 0;
579
+ this.#blockHashMap = new Map();
580
+ this.#chainSyncing = false;
581
+ this.#lastBlock = { index: 0, hash: '0x0', previousHash: '0x0' };
582
+ this.#blocks = [];
583
+ this.knownBlocks = [];
584
+ this.#totalSize = 0;
585
+ this.#loaded = false;
586
+ /**
587
+ * amount the native token has been iteracted with
588
+ */
589
+ this.#nativeCalls = 0;
590
+ /**
591
+ * amount the native token has been iteracted with
592
+ */
593
+ this.#nativeTransfers = 0;
594
+ /**
595
+ * amount of native token burned
596
+ * {Number}
597
+ */
598
+ this.#nativeBurns = 0;
599
+ /**
600
+ * amount of native tokens minted
601
+ * {Number}
602
+ */
603
+ this.#nativeMints = 0;
604
+ /**
605
+ * total amount of transactions
606
+ * {Number}
607
+ */
608
+ this.#totalTransactions = 0;
609
+ this.#loadBlockTransactions = (transactions) => Promise.all(transactions.map((transaction) => new TransactionMessage(transaction)));
610
+ this.#getLastTransactions = async () => {
611
+ let lastTransactions = (await Promise.all(this.#blocks.filter(block => block.loaded).slice(-128)
612
+ .map(block => this.#loadBlockTransactions(block.transactions))))
613
+ .reduce((all, transactions) => [...all, ...transactions], []);
614
+ return Promise.all(lastTransactions.map(transaction => transaction.hash()));
615
+ };
579
616
  }
580
617
  async init() {
581
618
  this.jobber = new Jobber(30000);
@@ -739,7 +776,6 @@ class State extends Contract {
739
776
  catch (error) {
740
777
  console.error(error);
741
778
  }
742
- // await queue.clear()
743
779
  this.#chainSyncing = true;
744
780
  if (!lastBlock)
745
781
  lastBlock = await this.#getLatestBlock();
@@ -836,13 +872,8 @@ class State extends Contract {
836
872
  }
837
873
  return latest;
838
874
  }
839
- #loadBlockTransactions = (transactions) => Promise.all(transactions.map((transaction) => new TransactionMessage(transaction)));
840
- #getLastTransactions = async () => {
841
- let lastTransactions = (await Promise.all(this.#blocks.filter(block => block.loaded).slice(-128)
842
- .map(block => this.#loadBlockTransactions(block.transactions))))
843
- .reduce((all, transactions) => [...all, ...transactions], []);
844
- return Promise.all(lastTransactions.map(transaction => transaction.hash()));
845
- };
875
+ #loadBlockTransactions;
876
+ #getLastTransactions;
846
877
  /**
847
878
  *
848
879
  * @param {Block[]} blocks
@@ -854,14 +885,15 @@ class State extends Contract {
854
885
  if (block.index === 0)
855
886
  this.#loaded = true;
856
887
  const transactions = await this.#loadBlockTransactions([...block.transactions] || []);
888
+ const lastTransactions = await this.#getLastTransactions();
857
889
  for (const transaction of transactions) {
858
- const lastTransactions = await this.#getLastTransactions();
859
890
  const hash = await transaction.hash();
860
891
  if (poolTransactionKeys.includes(hash))
861
892
  await globalThis.transactionPoolStore.delete(hash);
862
893
  if (lastTransactions.includes(hash)) {
863
894
  console.log('removing invalid block');
864
895
  await globalThis.blockStore.delete(await (await new BlockMessage(block)).hash());
896
+ blocks.splice(block.index - 1);
865
897
  return this.#loadBlocks(blocks);
866
898
  }
867
899
  try {
@@ -937,18 +969,25 @@ const ignorelist = ['BA5XUACBBBAT653LT3GHP2Z5SUHVCA42BP6IBFBJACHOZIHHR4DUPG2XMB'
937
969
  // check if browser or local
938
970
  class Chain extends State {
939
971
  #state;
940
- #slotTime = 10000;
941
- id;
942
- utils = {};
972
+ #slotTime;
943
973
  /** {Address[]} */
944
- #validators = [];
974
+ #validators;
945
975
  /** {Boolean} */
946
- #runningEpoch = false;
947
- #participants = [];
948
- #participating = false;
949
- #jail = [];
976
+ #runningEpoch;
977
+ #participants;
978
+ #participating;
979
+ #jail;
950
980
  constructor() {
951
981
  super();
982
+ this.#slotTime = 10000;
983
+ this.utils = {};
984
+ /** {Address[]} */
985
+ this.#validators = [];
986
+ /** {Boolean} */
987
+ this.#runningEpoch = false;
988
+ this.#participants = [];
989
+ this.#participating = false;
990
+ this.#jail = [];
952
991
  // @ts-ignore
953
992
  return this.#init();
954
993
  }
@@ -1192,7 +1231,7 @@ class Chain extends State {
1192
1231
  await this.#runEpoch();
1193
1232
  }
1194
1233
  // todo filter tx that need to wait on prev nonce
1195
- async #createBlock(limit = 1800) {
1234
+ async #createBlock(limit = this.transactionLimit) {
1196
1235
  // vote for transactions
1197
1236
  if (await globalThis.transactionPoolStore.size() === 0)
1198
1237
  return;
@@ -1249,6 +1288,7 @@ class Chain extends State {
1249
1288
  console.log(await globalThis.transactionPoolStore.has(e.hash));
1250
1289
  }
1251
1290
  }
1291
+ console.log(block.transactions.length);
1252
1292
  // don't add empty block
1253
1293
  if (block.transactions.length === 0)
1254
1294
  return;
package/exports/node.js CHANGED
@@ -18,6 +18,7 @@ class Node {
18
18
  this.#node = globalThis.Peernet ? await new globalThis.Peernet(config, password) : await new Peernet(config, password);
19
19
  await nodeConfig(config);
20
20
  globalThis.pubsub.subscribe('chain:ready', () => {
21
+ // when autostart is false the node will only be started after the chain is ready (this is here so we can just use node for communication)
21
22
  if (!this.#node.autoStart)
22
23
  this.#node.start();
23
24
  });
@@ -1,11 +1,13 @@
1
1
  import { BlockMessage } from '@leofcoin/messages';
2
2
  import Contract from './contract.js';
3
3
  import Machine from './machine.js';
4
+ import Jobber from './jobs/jobber.js';
4
5
  import { BlockHash } from './types.js';
5
6
  declare type SyncState = 'syncing' | 'synced' | 'errored' | 'connectionless';
6
7
  export default class State extends Contract {
7
8
  #private;
8
9
  knownBlocks: BlockHash[];
10
+ jobber: Jobber;
9
11
  get blockHashMap(): IterableIterator<[any, any]>;
10
12
  get loaded(): boolean;
11
13
  get resolving(): boolean;
@@ -1,2 +1,22 @@
1
1
  export type Address = base58String;
2
2
  export type BlockHash = base58String;
3
+ interface Transaction {
4
+ to: Address;
5
+ from: Address;
6
+ method: String;
7
+ params: string[];
8
+ nonce: Number;
9
+ }
10
+ interface RawTransaction extends Transaction {
11
+ timestamp: Number;
12
+ }
13
+ export declare type BlockInMemory = {
14
+ index: number;
15
+ transactions: RawTransaction[];
16
+ loaded?: Boolean;
17
+ };
18
+ export declare type RawBlock = {
19
+ index: number;
20
+ transactions: RawTransaction[];
21
+ };
22
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.4.91",
3
+ "version": "1.4.93",
4
4
  "description": "Official javascript implementation",
5
5
  "exports": {
6
6
  "./node": "./exports/node.js",
@@ -22,12 +22,7 @@
22
22
  "demo": "jsproject --serve ./ --port 5478 --open demo",
23
23
  "test": "node --openssl-legacy-provider test",
24
24
  "pack": "webpack",
25
- "build": "wireit"
26
- },
27
- "wireit": {
28
- "build": {
29
- "command": "rollup -c --silent error --cache true"
30
- }
25
+ "build": "rollup -c"
31
26
  },
32
27
  "np": {
33
28
  "yarn": false,