@leofcoin/chain 1.5.62 → 1.5.64

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 (21) hide show
  1. package/exports/browser/{_polyfill-node.child_process-JsWeMPst.js → _polyfill-node.child_process-rc1HO9Xs.js} +46 -47
  2. package/exports/browser/{_polyfill-node.url-0PWARF9f.js → _polyfill-node.url-1q06MepH.js} +1 -1
  3. package/exports/browser/{browser-dc41c03f-8RoAu8QY.js → browser-1GyRaZxg-C9SpI6hG.js} +2 -2
  4. package/exports/browser/chain.js +98 -62
  5. package/exports/browser/{client-f193279c-xoTAp1Bg.js → client-UOCjJBGl-pbv-pTHd.js} +18 -14
  6. package/exports/browser/{index-fd97ecae-DMIypRPM.js → index-K4Kwju30-vS3fNpxy.js} +2 -2
  7. package/exports/browser/{index-81687e93-rKzKdyEa.js → index-ub31QSed-EMPr2oeb.js} +2 -2
  8. package/exports/browser/{messages-cccb78db-bQaa1gST.js → messages-guyZfse6-JeAlT5Nb.js} +2 -2
  9. package/exports/browser/{node-browser-cqEqYlW7.js → node-browser-0Ly80awM.js} +625 -609
  10. package/exports/browser/node-browser.js +2 -2
  11. package/exports/browser/workers/block-worker.js +1 -4
  12. package/exports/browser/workers/machine-worker.js +61 -34
  13. package/exports/browser/workers/{worker-Suy0gj0S.js → worker-hbo9s9AT.js} +47 -59
  14. package/exports/chain.d.ts +1 -0
  15. package/exports/chain.js +63 -52
  16. package/exports/workers/block-worker.js +1 -4
  17. package/exports/workers/machine-worker.js +61 -34
  18. package/exports/workers/{worker-Suy0gj0S.js → worker-hbo9s9AT.js} +47 -59
  19. package/package.json +4 -3
  20. /package/exports/browser/{browser-2c73e2ef-AyxSBUXj.js → browser-AyxSBUXj-AyxSBUXj.js} +0 -0
  21. /package/exports/browser/{qr-scanner-worker.min-c002e984-RaSiJc_R.js → qr-scanner-worker.min-RaSiJc_R-RaSiJc_R.js} +0 -0
@@ -14499,56 +14499,55 @@ class ValidatorMessage extends FormatInterface {
14499
14499
  }
14500
14500
 
14501
14501
  var proto$4 = {
14502
- index: Number(),
14503
- previousHash: String(),
14504
- timestamp: Number(),
14505
- reward: BigNumber.from(0),
14506
- fees: BigNumber.from(0),
14507
- transactions: new Uint8Array(),
14508
- validators: new Uint8Array()
14502
+ index: Number(),
14503
+ previousHash: String(),
14504
+ timestamp: Number(),
14505
+ reward: BigNumber.from(0),
14506
+ fees: BigNumber.from(0),
14507
+ transactions: new Uint8Array(),
14508
+ validators: new Uint8Array()
14509
14509
  };
14510
14510
 
14511
14511
  class BlockMessage extends FormatInterface {
14512
- get messageName() {
14513
- return 'BlockMessage';
14514
- }
14515
- constructor(buffer) {
14516
- if (buffer instanceof BlockMessage)
14517
- return buffer;
14518
- const name = 'block-message';
14519
- super(buffer, proto$4, { name });
14520
- }
14521
- encode(decoded) {
14522
- decoded = decoded || this.decoded;
14523
- const validators = [];
14524
- const transactions = [];
14525
- for (const validator of decoded.validators) {
14526
- if (validator instanceof ValidatorMessage)
14527
- validators.push(validator.encode());
14528
- else
14529
- validators.push(new ValidatorMessage(validator).encode());
14530
- }
14531
- for (const transaction of decoded.transactions) {
14532
- if (transaction instanceof TransactionMessage)
14533
- transactions.push(transaction.encode());
14534
- else
14535
- transactions.push(new TransactionMessage(transaction).encode());
14536
- }
14537
- return super.encode({
14538
- ...decoded,
14539
- validators: index$5(validators),
14540
- transactions: index$5(transactions)
14541
- });
14542
- }
14543
- decode(encoded) {
14544
- encoded = encoded || this.encoded;
14545
- super.decode(encoded);
14546
- // @ts-ignore
14547
- this.decoded.transactions = index$4(this.decoded.transactions).map((transaction) => new TransactionMessage(transaction).decoded);
14548
- // @ts-ignore
14549
- this.decoded.validators = index$4(this.decoded.validators).map((validator) => new ValidatorMessage(validator).decoded);
14550
- return this.decoded;
14551
- }
14512
+ get messageName() {
14513
+ return 'BlockMessage'
14514
+ }
14515
+ constructor(buffer) {
14516
+ if (buffer instanceof BlockMessage) return buffer
14517
+ const name = 'block-message';
14518
+ super(buffer, proto$4, { name });
14519
+ }
14520
+ encode(decoded) {
14521
+ decoded = decoded || this.decoded;
14522
+ const validators = [];
14523
+ const transactions = [];
14524
+ for (const validator of decoded.validators) {
14525
+ if (validator instanceof ValidatorMessage) validators.push(validator.encode());
14526
+ else validators.push(new ValidatorMessage(validator).encode());
14527
+ }
14528
+ for (const transaction of decoded.transactions) {
14529
+ if (transaction instanceof TransactionMessage) transactions.push(transaction.encode());
14530
+ else transactions.push(new TransactionMessage(transaction).encode());
14531
+ }
14532
+ return super.encode({
14533
+ ...decoded,
14534
+ validators: index$5(validators),
14535
+ transactions: index$5(transactions)
14536
+ })
14537
+ }
14538
+ decode(encoded) {
14539
+ encoded = encoded || this.encoded;
14540
+ super.decode(encoded);
14541
+ // @ts-ignore
14542
+ this.decoded.transactions = index$4(this.decoded.transactions).map(
14543
+ (transaction) => new TransactionMessage(transaction).decoded
14544
+ );
14545
+ // @ts-ignore
14546
+ this.decoded.validators = index$4(this.decoded.validators).map(
14547
+ (validator) => new ValidatorMessage(validator).decoded
14548
+ );
14549
+ return this.decoded
14550
+ }
14552
14551
  }
14553
14552
 
14554
14553
  var proto$3 = {
@@ -1,4 +1,4 @@
1
- import { g as global } from './_polyfill-node.child_process-JsWeMPst.js';
1
+ import { g as global } from './_polyfill-node.child_process-rc1HO9Xs.js';
2
2
 
3
3
  /*! https://mths.be/punycode v1.4.1 by @mathias */
4
4
 
@@ -1,5 +1,5 @@
1
- import { g as getDefaultExportFromCjs } from './node-browser-cqEqYlW7.js';
2
- import './_polyfill-node.child_process-JsWeMPst.js';
1
+ import { g as getDefaultExportFromCjs } from './node-browser-0Ly80awM.js';
2
+ import './_polyfill-node.child_process-rc1HO9Xs.js';
3
3
 
4
4
  var global;
5
5
  var hasRequiredGlobal;
@@ -1,4 +1,30 @@
1
- import { c as BigNumber, L as Logger, v as version$1, h as hexZeroPad, i as isBigNumberish, d as arrayify, e as isBytes, T as TransactionMessage, t as toBase58, C as ContractMessage, R as RawTransactionMessage, f as getDefaultExportFromCjs, B as BlockMessage, a as BWMessage, b as BWRequestMessage } from './_polyfill-node.child_process-JsWeMPst.js';
1
+ import { c as BigNumber, L as Logger, v as version$1, h as hexZeroPad, i as isBigNumberish, d as arrayify, e as isBytes, T as TransactionMessage, t as toBase58, C as ContractMessage, R as RawTransactionMessage, f as getDefaultExportFromCjs, B as BlockMessage, a as BWMessage, b as BWRequestMessage } from './_polyfill-node.child_process-rc1HO9Xs.js';
2
+
3
+ if (!globalThis.DEBUG) {
4
+ let DEBUG = [];
5
+ if (globalThis.localStorage) {
6
+ DEBUG = globalThis.localStorage.getItem('DEBUG');
7
+ globalThis.DEBUG = DEBUG ? DEBUG.split(',') : [DEBUG];
8
+ }
9
+ }
10
+
11
+ const debug$5 = (target, text) => {
12
+ if (!globalThis.DEBUG && globalThis.DEBUG.length === 0) return;
13
+ if (
14
+ globalThis.DEBUG === 'true' ||
15
+ globalThis.DEBUG === true ||
16
+ globalThis.DEBUG?.indexOf(target) !== -1 ||
17
+ globalThis.DEBUG?.indexOf('*') !== -1
18
+ )
19
+ if (text) console.log('\x1b[34m\x1b[1m%s', `${target}: ${text}`, '\x1b[0m');
20
+ else console.log('\x1b[34m\x1b[1m%s', `${target}`, '\x1b[0m');
21
+ };
22
+
23
+ if (!globalThis.debug) {
24
+ globalThis.debug = debug$5;
25
+
26
+ globalThis.createDebugger = (target) => (text) => debug$5(target, text);
27
+ }
2
28
 
3
29
  const logger$1 = new Logger(version$1);
4
30
  const _constructorGuard = {};
@@ -506,7 +532,7 @@ var constants$1 = {
506
532
  FLAG_LOOSE: 0b010,
507
533
  };
508
534
 
509
- const debug$1 = (
535
+ const debug$4 = (
510
536
  typeof process === 'object' &&
511
537
  process.env &&
512
538
  process.env.NODE_DEBUG &&
@@ -514,7 +540,7 @@ const debug$1 = (
514
540
  ) ? (...args) => console.error('SEMVER', ...args)
515
541
  : () => {};
516
542
 
517
- var debug_1 = debug$1;
543
+ var debug_1 = debug$4;
518
544
 
519
545
  (function (module, exports) {
520
546
  const {
@@ -773,7 +799,7 @@ var identifiers$1 = {
773
799
  rcompareIdentifiers,
774
800
  };
775
801
 
776
- const debug = debug_1;
802
+ const debug$3 = debug_1;
777
803
  const { MAX_LENGTH, MAX_SAFE_INTEGER } = constants$1;
778
804
  const { safeRe: re$1, t: t$1 } = reExports;
779
805
 
@@ -800,7 +826,7 @@ let SemVer$d = class SemVer {
800
826
  )
801
827
  }
802
828
 
803
- debug('SemVer', version, options);
829
+ debug$3('SemVer', version, options);
804
830
  this.options = options;
805
831
  this.loose = !!options.loose;
806
832
  // this isn't actually relevant for versions, but keep it so that we
@@ -864,7 +890,7 @@ let SemVer$d = class SemVer {
864
890
  }
865
891
 
866
892
  compare (other) {
867
- debug('SemVer.compare', this.version, this.options, other);
893
+ debug$3('SemVer.compare', this.version, this.options, other);
868
894
  if (!(other instanceof SemVer)) {
869
895
  if (typeof other === 'string' && other === this.version) {
870
896
  return 0
@@ -909,7 +935,7 @@ let SemVer$d = class SemVer {
909
935
  do {
910
936
  const a = this.prerelease[i];
911
937
  const b = other.prerelease[i];
912
- debug('prerelease compare', i, a, b);
938
+ debug$3('prerelease compare', i, a, b);
913
939
  if (a === undefined && b === undefined) {
914
940
  return 0
915
941
  } else if (b === undefined) {
@@ -933,7 +959,7 @@ let SemVer$d = class SemVer {
933
959
  do {
934
960
  const a = this.build[i];
935
961
  const b = other.build[i];
936
- debug('prerelease compare', i, a, b);
962
+ debug$3('prerelease compare', i, a, b);
937
963
  if (a === undefined && b === undefined) {
938
964
  return 0
939
965
  } else if (b === undefined) {
@@ -3778,7 +3804,7 @@ class EasyWorker {
3778
3804
  this.worker = new Worker(url, {...options});
3779
3805
  } else {
3780
3806
  return new Promise(async (resolve, reject) => {
3781
- const {fork} = await import('./_polyfill-node.child_process-JsWeMPst.js').then(function (n) { return n._; });
3807
+ const {fork} = await import('./_polyfill-node.child_process-rc1HO9Xs.js').then(function (n) { return n._; });
3782
3808
  this.worker = fork(url, ['easy-worker-child'], options);
3783
3809
  resolve(this);
3784
3810
  })
@@ -3859,6 +3885,7 @@ const isResolveError = (error) => error.name === 'ResolveError';
3859
3885
  const isExecutionError = (error) => error.name === 'ExecutionError';
3860
3886
 
3861
3887
  // import State from './state'
3888
+ const debug$2 = globalThis.createDebugger('leofcoin/machine');
3862
3889
  class Machine {
3863
3890
  #contracts = {};
3864
3891
  #nonces = {};
@@ -3898,7 +3925,7 @@ class Machine {
3898
3925
  break;
3899
3926
  }
3900
3927
  case 'debug': {
3901
- globalThis.debug(data.message);
3928
+ debug$2(data.message);
3902
3929
  break;
3903
3930
  }
3904
3931
  case 'error': {
@@ -3924,7 +3951,7 @@ class Machine {
3924
3951
  pubsub.subscribe('machine.ready', machineReady);
3925
3952
  let pre;
3926
3953
  try {
3927
- const importee = await import('./_polyfill-node.url-0PWARF9f.js');
3954
+ const importee = await import('./_polyfill-node.url-1q06MepH.js');
3928
3955
  const url = importee.default;
3929
3956
  if (url)
3930
3957
  pre = url.fileURLToPath(new URL('.', import.meta.url));
@@ -4173,6 +4200,7 @@ class Jobber {
4173
4200
  }
4174
4201
  }
4175
4202
 
4203
+ const debug$1 = globalThis.createDebugger('leofcoin/state');
4176
4204
  class State extends Contract {
4177
4205
  #resolveErrored;
4178
4206
  #lastResolvedTime;
@@ -4269,7 +4297,7 @@ class State extends Contract {
4269
4297
  this.#getLastTransactions = async () => {
4270
4298
  let lastTransactions = (await Promise.all((await this.blocks)
4271
4299
  .filter((block) => block.loaded)
4272
- .slice(-128)
4300
+ .slice(-24)
4273
4301
  .map((block) => this.#loadBlockTransactions(block.transactions)))).reduce((all, transactions) => [...all, ...transactions], []);
4274
4302
  return Promise.all(lastTransactions.map((transaction) => transaction.hash()));
4275
4303
  };
@@ -4327,10 +4355,15 @@ class State extends Contract {
4327
4355
  }
4328
4356
  }
4329
4357
  async updateState(message) {
4330
- const hash = await message.hash();
4331
- // await this.state.updateState(message)
4332
- await globalThis.chainStore.put('lastBlock', hash);
4333
- globalThis.pubsub.publish('lastBlock', message.encoded);
4358
+ try {
4359
+ const hash = await message.hash();
4360
+ // await this.state.updateState(message)
4361
+ await globalThis.chainStore.put('lastBlock', hash);
4362
+ globalThis.pubsub.publish('lastBlock', message.encoded);
4363
+ }
4364
+ catch (error) {
4365
+ console.error(error);
4366
+ }
4334
4367
  }
4335
4368
  getLatestBlock() {
4336
4369
  // @ts-ignore
@@ -4366,7 +4399,7 @@ class State extends Contract {
4366
4399
  this.#totalSize += size;
4367
4400
  this.#blocks[index - 1] = { hash, ...block.decoded };
4368
4401
  this.#blockHashMap.set(hash, index);
4369
- globalThis.debug(`resolved block: ${hash} @${index} ${formatBytes(size)}`);
4402
+ debug$1(`resolved block: ${hash} @${index} ${formatBytes(size)}`);
4370
4403
  globalThis.pubsub.publish('block-resolved', { hash, index });
4371
4404
  this.#lastResolved = this.#blocks[index - 1];
4372
4405
  this.#lastResolvedTime = Date.now();
@@ -4504,7 +4537,7 @@ class State extends Contract {
4504
4537
  await this.resolveBlock(lastBlock.hash);
4505
4538
  console.log('ok');
4506
4539
  let blocksSynced = localIndex > 0 ? (localIndex > index ? localIndex - index : index + -localIndex) : index;
4507
- globalThis.debug(`synced ${blocksSynced} ${blocksSynced > 1 ? 'blocks' : 'block'}`);
4540
+ debug$1(`synced ${blocksSynced} ${blocksSynced > 1 ? 'blocks' : 'block'}`);
4508
4541
  const blocks = this.#blocks;
4509
4542
  const start = blocks.length - blocksSynced;
4510
4543
  if (this.#machine) {
@@ -4636,7 +4669,7 @@ class State extends Contract {
4636
4669
  this.#blocks[block.index - 1].loaded = true;
4637
4670
  await this.#machine.addLoadedBlock(block);
4638
4671
  // @ts-ignore
4639
- globalThis.debug(`loaded block: ${block.hash} @${block.index}`);
4672
+ debug$1(`loaded block: ${block.hash} @${block.index}`);
4640
4673
  globalThis.pubsub.publish('block-loaded', { ...block });
4641
4674
  }
4642
4675
  }
@@ -4647,7 +4680,7 @@ class State extends Contract {
4647
4680
  return new Promise(async (resolve, reject) => {
4648
4681
  const timeout = setTimeout(() => {
4649
4682
  resolve([{ index: 0, hash: '0x0' }]);
4650
- globalThis.debug('sync timed out');
4683
+ debug$1('sync timed out');
4651
4684
  }, this.requestTimeout);
4652
4685
  promises = await Promise.allSettled(promises);
4653
4686
  promises = promises.filter(({ status }) => status === 'fulfilled');
@@ -4731,7 +4764,7 @@ class VersionControl extends State {
4731
4764
  }
4732
4765
 
4733
4766
  globalThis.BigNumber = BigNumber;
4734
- const ignorelist = [];
4767
+ const debug = globalThis.createDebugger('leofcoin/chain');
4735
4768
  // check if browser or local
4736
4769
  class Chain extends VersionControl {
4737
4770
  #state;
@@ -4758,7 +4791,7 @@ class Chain extends VersionControl {
4758
4791
  const transaction = new TransactionMessage(message);
4759
4792
  await transaction.hash();
4760
4793
  // if (await transactionPoolStore.has(hash)) await transactionPoolStore.delete(hash)
4761
- console.log(transaction);
4794
+ debug(`added ${transaction}`);
4762
4795
  };
4763
4796
  // @ts-ignore
4764
4797
  return this.#init();
@@ -4881,7 +4914,6 @@ class Chain extends VersionControl {
4881
4914
  const transactionsToGet = [];
4882
4915
  for (const key of transactionsInPool) {
4883
4916
  !transactions.includes(key) &&
4884
- !ignorelist.includes(key) &&
4885
4917
  transactionsToGet.push(transactionPoolStore.put(key, await peernet.get(key, 'transaction')));
4886
4918
  }
4887
4919
  return Promise.all(transactionsToGet);
@@ -4890,7 +4922,10 @@ class Chain extends VersionControl {
4890
4922
  const peer = peernet.getConnection(peerId);
4891
4923
  // todo handle version changes
4892
4924
  // for now just do nothing if version doesn't match
4893
- console.log(`${peer.version}, ${this.version}`);
4925
+ debug(`peer connected with version ${peer.version}`);
4926
+ if (peer.version !== this.version) {
4927
+ debug(`versions don't match`);
4928
+ }
4894
4929
  if (!peer.version || peer.version !== this.version)
4895
4930
  return;
4896
4931
  const lastBlock = await this.#makeRequest(peer, 'lastBlock');
@@ -4933,7 +4968,6 @@ class Chain extends VersionControl {
4933
4968
  }
4934
4969
  }
4935
4970
  async #addBlock(block) {
4936
- console.log({ block });
4937
4971
  const blockMessage = await new BlockMessage(block);
4938
4972
  const hash = await blockMessage.hash();
4939
4973
  await Promise.all(blockMessage.decoded.transactions
@@ -4950,7 +4984,7 @@ class Chain extends VersionControl {
4950
4984
  await globalThis.blockStore.put(hash, blockMessage.encoded);
4951
4985
  if ((await this.lastBlock).index < Number(blockMessage.decoded.index))
4952
4986
  await this.updateState(blockMessage);
4953
- globalThis.debug(`added block: ${hash}`);
4987
+ debug(`added block: ${hash}`);
4954
4988
  let promises = [];
4955
4989
  let contracts = [];
4956
4990
  for (let transaction of blockMessage.decoded.transactions) {
@@ -5008,16 +5042,41 @@ class Chain extends VersionControl {
5008
5042
  if ((await this.hasTransactionToHandle()) && !this.#runningEpoch && this.#participating)
5009
5043
  await this.#runEpoch();
5010
5044
  }
5045
+ async #handleTransaction(transaction, latestTransactions, block) {
5046
+ const hash = await transaction.hash();
5047
+ const doubleTransactions = [];
5048
+ if (latestTransactions.includes(hash)) {
5049
+ doubleTransactions.push(hash);
5050
+ }
5051
+ if (doubleTransactions.length > 0) {
5052
+ await globalThis.transactionPoolStore.delete(hash);
5053
+ await globalThis.peernet.publish('invalid-transaction', hash);
5054
+ return;
5055
+ }
5056
+ // if (timestamp + this.#slotTime > Date.now()) {
5057
+ try {
5058
+ const result = await this.#executeTransaction({ ...transaction.decoded, hash });
5059
+ block.transactions.push(transaction);
5060
+ block.fees = block.fees.add(await calculateFee(transaction.decoded));
5061
+ await globalThis.accountsStore.put(transaction.decoded.from, new TextEncoder().encode(String(transaction.decoded.nonce)));
5062
+ }
5063
+ catch (e) {
5064
+ console.log('vvvvvv');
5065
+ console.log({ e });
5066
+ console.log(hash);
5067
+ peernet.publish('invalid-transaction', hash);
5068
+ console.log(await globalThis.transactionPoolStore.keys());
5069
+ console.log(await globalThis.transactionPoolStore.has(e.hash));
5070
+ await globalThis.transactionPoolStore.delete(e.hash);
5071
+ console.log(await globalThis.transactionPoolStore.has(e.hash));
5072
+ }
5073
+ }
5011
5074
  // todo filter tx that need to wait on prev nonce
5012
5075
  async #createBlock(limit = this.transactionLimit) {
5013
5076
  // vote for transactions
5014
5077
  if ((await globalThis.transactionPoolStore.size()) === 0)
5015
5078
  return;
5016
5079
  let transactions = await globalThis.transactionPoolStore.values(this.transactionLimit);
5017
- for (const hash of await globalThis.transactionPoolStore.keys()) {
5018
- if (ignorelist.includes(hash))
5019
- await globalThis.transactionPoolStore.delete(hash);
5020
- }
5021
5080
  if (Object.keys(transactions)?.length === 0)
5022
5081
  return;
5023
5082
  const timestamp = Date.now();
@@ -5030,39 +5089,16 @@ class Chain extends VersionControl {
5030
5089
  reward: parseUnits('150'),
5031
5090
  index: 0
5032
5091
  };
5092
+ const latestTransactions = await this.machine.latestTransactions();
5033
5093
  // exclude failing tx
5034
5094
  transactions = await this.promiseTransactions(transactions);
5035
- transactions = transactions.sort((a, b) => a.nonce - b.nonce);
5036
- const latestTransactions = await this.machine.latestTransactions();
5037
- for (let transaction of transactions) {
5038
- const hash = await transaction.hash();
5039
- const doubleTransactions = [];
5040
- if (latestTransactions.includes(hash)) {
5041
- doubleTransactions.push(hash);
5042
- }
5043
- if (doubleTransactions.length > 0) {
5044
- await globalThis.transactionPoolStore.delete(hash);
5045
- await globalThis.peernet.publish('invalid-transaction', hash);
5046
- return;
5047
- }
5048
- // if (timestamp + this.#slotTime > Date.now()) {
5049
- try {
5050
- const result = await this.#executeTransaction({ ...transaction.decoded, hash });
5051
- block.transactions.push(transaction);
5052
- block.fees = block.fees.add(await calculateFee(transaction.decoded));
5053
- await globalThis.accountsStore.put(transaction.decoded.from, new TextEncoder().encode(String(transaction.decoded.nonce)));
5054
- }
5055
- catch (e) {
5056
- console.log('vvvvvv');
5057
- console.log({ e });
5058
- console.log(hash);
5059
- peernet.publish('invalid-transaction', hash);
5060
- console.log(await globalThis.transactionPoolStore.keys());
5061
- console.log(await globalThis.transactionPoolStore.has(e.hash));
5062
- await globalThis.transactionPoolStore.delete(e.hash);
5063
- console.log(await globalThis.transactionPoolStore.has(e.hash));
5064
- }
5065
- }
5095
+ const priority = transactions.filter((transaction) => transaction.priority);
5096
+ await Promise.all(priority
5097
+ .sort((a, b) => a.nonce - b.nonce)
5098
+ .map((transaction) => this.#handleTransaction(transaction, latestTransactions, block)));
5099
+ await Promise.all(transactions
5100
+ .filter((transaction) => !transaction.priority)
5101
+ .map((transaction) => this.#handleTransaction(transaction, latestTransactions, block)));
5066
5102
  // don't add empty block
5067
5103
  if (block.transactions.length === 0)
5068
5104
  return;
@@ -5129,7 +5165,7 @@ class Chain extends VersionControl {
5129
5165
  await globalThis.peernet.put(hash, blockMessage.encoded, 'block');
5130
5166
  await this.updateState(blockMessage);
5131
5167
  await this.machine.addLoadedBlock({ ...blockMessage.decoded, loaded: true, hash: await blockMessage.hash() });
5132
- globalThis.debug(`created block: ${hash} @${block.index}`);
5168
+ debug(`created block: ${hash} @${block.index}`);
5133
5169
  globalThis.peernet.publish('add-block', blockMessage.encoded);
5134
5170
  globalThis.pubsub.publish('add-block', blockMessage.decoded);
5135
5171
  }
@@ -1,5 +1,5 @@
1
- import { L as LittlePubSub } from './node-browser-cqEqYlW7.js';
2
- import './_polyfill-node.child_process-JsWeMPst.js';
1
+ import { L as LittlePubSub } from './node-browser-0Ly80awM.js';
2
+ import './_polyfill-node.child_process-rc1HO9Xs.js';
3
3
 
4
4
  class Api {
5
5
  _pubsub;
@@ -206,7 +206,7 @@ class SocketRequestClient {
206
206
  const init = async () => {
207
207
  // @ts-ignore
208
208
  if (!globalThis.WebSocket)
209
- globalThis.WebSocket = (await import('./browser-dc41c03f-8RoAu8QY.js').then(function (n) { return n.b; })).default.w3cwebsocket;
209
+ globalThis.WebSocket = (await import('./browser-1GyRaZxg-C9SpI6hG.js').then(function (n) { return n.b; })).default.w3cwebsocket;
210
210
  const client = new WebSocket(this.#url, this.#protocol);
211
211
  client.onmessage = this.onmessage;
212
212
  client.onerror = this.onerror;
@@ -280,12 +280,15 @@ const iceServers = [
280
280
  credential: 'openrelayproject'
281
281
  }
282
282
  ];
283
- const SimplePeer = (await import('./index-fd97ecae-DMIypRPM.js').then(function (n) { return n.i; })).default;
283
+ const SimplePeer = (await import('./index-K4Kwju30-vS3fNpxy.js').then(function (n) { return n.i; })).default;
284
284
  class Peer extends SimplePeer {
285
285
  peerId;
286
286
  channelName;
287
287
  version;
288
288
  bw = { up: 0, down: 0 };
289
+ get connected() {
290
+ return super.connected;
291
+ }
289
292
  constructor(options) {
290
293
  const { from, to, initiator, trickle, config, version } = options;
291
294
  const channelName = initiator ? `${from}:${to}` : `${to}:${from}`;
@@ -356,6 +359,7 @@ class Peer extends SimplePeer {
356
359
  }
357
360
  }
358
361
 
362
+ const debug = globalThis.createDebugger('@peernet/swarm/client');
359
363
  class Client {
360
364
  #peerId;
361
365
  #connections = {};
@@ -404,7 +408,7 @@ class Client {
404
408
  async _init() {
405
409
  // reconnectJob()
406
410
  if (!globalThis.RTCPeerConnection)
407
- globalThis.wrtc = (await import('./browser-2c73e2ef-AyxSBUXj.js').then(function (n) { return n.b; })).default;
411
+ globalThis.wrtc = (await import('./browser-AyxSBUXj-AyxSBUXj.js').then(function (n) { return n.b; })).default;
408
412
  for (const star of this.starsConfig) {
409
413
  try {
410
414
  const client = new SocketRequestClient(star, this.networkVersion);
@@ -421,16 +425,16 @@ class Client {
421
425
  throw new Error(`No star available to connect`);
422
426
  }
423
427
  }
424
- if (globalThis.navigator) {
425
- globalThis.addEventListener('beforeunload', async () => this.close());
426
- }
427
- else {
428
+ if (globalThis.process?.versions?.node) {
428
429
  process.on('SIGINT', async () => {
429
430
  process.stdin.resume();
430
431
  await this.close();
431
432
  process.exit();
432
433
  });
433
434
  }
435
+ else {
436
+ globalThis.addEventListener('beforeunload', async () => this.close());
437
+ }
434
438
  }
435
439
  setupStarListeners(star) {
436
440
  star.pubsub.subscribe('peer:joined', (id) => this.#peerJoined(id, star));
@@ -470,7 +474,7 @@ class Client {
470
474
  }
471
475
  }
472
476
  }
473
- globalThis.debug(`star ${id} left`);
477
+ debug(`star ${id} left`);
474
478
  };
475
479
  #peerLeft = (peer, star) => {
476
480
  const id = peer.peerId || peer;
@@ -478,7 +482,7 @@ class Client {
478
482
  this.#connections[id].destroy();
479
483
  delete this.#connections[id];
480
484
  }
481
- globalThis.debug(`peer ${id} left`);
485
+ debug(`peer ${id} left`);
482
486
  };
483
487
  #createRTCPeerConnection = (peerId, star, version, initiator = false) => {
484
488
  const peer = new Peer({
@@ -502,7 +506,7 @@ class Client {
502
506
  }
503
507
  // RTCPeerConnection
504
508
  this.#createRTCPeerConnection(peerId, star, version, true);
505
- globalThis.debug(`peer ${peerId} joined`);
509
+ debug(`peer ${peerId} joined`);
506
510
  };
507
511
  #inComingSignal = async ({ from, signal, channelName, version }, star) => {
508
512
  if (version !== this.version) {
@@ -538,10 +542,10 @@ class Client {
538
542
  peer.destroy();
539
543
  delete this.#connections[peer.peerId];
540
544
  }
541
- globalThis.debug(`closed ${peer.peerId}'s connection`);
545
+ debug(`closed ${peer.peerId}'s connection`);
542
546
  };
543
547
  #peerConnect = (peer) => {
544
- globalThis.debug(`${peer.peerId} connected`);
548
+ debug(`${peer.peerId} connected`);
545
549
  globalThis.pubsub.publishVerbose(this.#connectEvent, peer.peerId);
546
550
  };
547
551
  #noticeMessage = (message, id, from, peer) => {
@@ -1,5 +1,5 @@
1
- import { i as inherits_browserExports, c as commonjsGlobal, g as getDefaultExportFromCjs, r as require$$3 } from './node-browser-cqEqYlW7.js';
2
- import './_polyfill-node.child_process-JsWeMPst.js';
1
+ import { i as inherits_browserExports, c as commonjsGlobal, g as getDefaultExportFromCjs, r as require$$3 } from './node-browser-0Ly80awM.js';
2
+ import './_polyfill-node.child_process-rc1HO9Xs.js';
3
3
 
4
4
  var browser$2 = {exports: {}};
5
5
 
@@ -1,5 +1,5 @@
1
- import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-cqEqYlW7.js';
2
- import './_polyfill-node.child_process-JsWeMPst.js';
1
+ import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-0Ly80awM.js';
2
+ import './_polyfill-node.child_process-rc1HO9Xs.js';
3
3
 
4
4
  /**
5
5
  * @params {String} network
@@ -1,5 +1,5 @@
1
- import { F as FormatInterface } from './node-browser-cqEqYlW7.js';
2
- import './_polyfill-node.child_process-JsWeMPst.js';
1
+ import { F as FormatInterface } from './node-browser-0Ly80awM.js';
2
+ import './_polyfill-node.child_process-rc1HO9Xs.js';
3
3
 
4
4
  var proto$b = {
5
5
  data: new Uint8Array(),