@leofcoin/chain 1.5.63 → 1.5.65

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 +102 -61
  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 +57 -35
  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 +66 -51
  16. package/exports/workers/block-worker.js +1 -4
  17. package/exports/workers/machine-worker.js +57 -35
  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,31 @@
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
+ globalThis.DEBUG?.indexOf(target.split('/')[0]) !== -1
19
+ )
20
+ if (text) console.log('\x1b[34m\x1b[1m%s', `${target}: ${text}`, '\x1b[0m');
21
+ else console.log('\x1b[34m\x1b[1m%s', `${target}`, '\x1b[0m');
22
+ };
23
+
24
+ if (!globalThis.debug) {
25
+ globalThis.debug = debug$5;
26
+
27
+ globalThis.createDebugger = (target) => (text) => debug$5(target, text);
28
+ }
2
29
 
3
30
  const logger$1 = new Logger(version$1);
4
31
  const _constructorGuard = {};
@@ -506,7 +533,7 @@ var constants$1 = {
506
533
  FLAG_LOOSE: 0b010,
507
534
  };
508
535
 
509
- const debug$1 = (
536
+ const debug$4 = (
510
537
  typeof process === 'object' &&
511
538
  process.env &&
512
539
  process.env.NODE_DEBUG &&
@@ -514,7 +541,7 @@ const debug$1 = (
514
541
  ) ? (...args) => console.error('SEMVER', ...args)
515
542
  : () => {};
516
543
 
517
- var debug_1 = debug$1;
544
+ var debug_1 = debug$4;
518
545
 
519
546
  (function (module, exports) {
520
547
  const {
@@ -773,7 +800,7 @@ var identifiers$1 = {
773
800
  rcompareIdentifiers,
774
801
  };
775
802
 
776
- const debug = debug_1;
803
+ const debug$3 = debug_1;
777
804
  const { MAX_LENGTH, MAX_SAFE_INTEGER } = constants$1;
778
805
  const { safeRe: re$1, t: t$1 } = reExports;
779
806
 
@@ -800,7 +827,7 @@ let SemVer$d = class SemVer {
800
827
  )
801
828
  }
802
829
 
803
- debug('SemVer', version, options);
830
+ debug$3('SemVer', version, options);
804
831
  this.options = options;
805
832
  this.loose = !!options.loose;
806
833
  // this isn't actually relevant for versions, but keep it so that we
@@ -864,7 +891,7 @@ let SemVer$d = class SemVer {
864
891
  }
865
892
 
866
893
  compare (other) {
867
- debug('SemVer.compare', this.version, this.options, other);
894
+ debug$3('SemVer.compare', this.version, this.options, other);
868
895
  if (!(other instanceof SemVer)) {
869
896
  if (typeof other === 'string' && other === this.version) {
870
897
  return 0
@@ -909,7 +936,7 @@ let SemVer$d = class SemVer {
909
936
  do {
910
937
  const a = this.prerelease[i];
911
938
  const b = other.prerelease[i];
912
- debug('prerelease compare', i, a, b);
939
+ debug$3('prerelease compare', i, a, b);
913
940
  if (a === undefined && b === undefined) {
914
941
  return 0
915
942
  } else if (b === undefined) {
@@ -933,7 +960,7 @@ let SemVer$d = class SemVer {
933
960
  do {
934
961
  const a = this.build[i];
935
962
  const b = other.build[i];
936
- debug('prerelease compare', i, a, b);
963
+ debug$3('prerelease compare', i, a, b);
937
964
  if (a === undefined && b === undefined) {
938
965
  return 0
939
966
  } else if (b === undefined) {
@@ -3778,7 +3805,7 @@ class EasyWorker {
3778
3805
  this.worker = new Worker(url, {...options});
3779
3806
  } else {
3780
3807
  return new Promise(async (resolve, reject) => {
3781
- const {fork} = await import('./_polyfill-node.child_process-JsWeMPst.js').then(function (n) { return n._; });
3808
+ const {fork} = await import('./_polyfill-node.child_process-rc1HO9Xs.js').then(function (n) { return n._; });
3782
3809
  this.worker = fork(url, ['easy-worker-child'], options);
3783
3810
  resolve(this);
3784
3811
  })
@@ -3859,6 +3886,7 @@ const isResolveError = (error) => error.name === 'ResolveError';
3859
3886
  const isExecutionError = (error) => error.name === 'ExecutionError';
3860
3887
 
3861
3888
  // import State from './state'
3889
+ const debug$2 = globalThis.createDebugger('leofcoin/machine');
3862
3890
  class Machine {
3863
3891
  #contracts = {};
3864
3892
  #nonces = {};
@@ -3898,7 +3926,10 @@ class Machine {
3898
3926
  break;
3899
3927
  }
3900
3928
  case 'debug': {
3901
- globalThis.debug(data.message);
3929
+ debug$2(data.message);
3930
+ if (data.message.includes('loaded transactions for block:')) {
3931
+ pubsub.publish('block-loaded', data.message.replace('loaded transactions for block: ', '').split(' @')[0]);
3932
+ }
3902
3933
  break;
3903
3934
  }
3904
3935
  case 'error': {
@@ -3924,7 +3955,7 @@ class Machine {
3924
3955
  pubsub.subscribe('machine.ready', machineReady);
3925
3956
  let pre;
3926
3957
  try {
3927
- const importee = await import('./_polyfill-node.url-0PWARF9f.js');
3958
+ const importee = await import('./_polyfill-node.url-1q06MepH.js');
3928
3959
  const url = importee.default;
3929
3960
  if (url)
3930
3961
  pre = url.fileURLToPath(new URL('.', import.meta.url));
@@ -4173,6 +4204,7 @@ class Jobber {
4173
4204
  }
4174
4205
  }
4175
4206
 
4207
+ const debug$1 = globalThis.createDebugger('leofcoin/state');
4176
4208
  class State extends Contract {
4177
4209
  #resolveErrored;
4178
4210
  #lastResolvedTime;
@@ -4269,7 +4301,7 @@ class State extends Contract {
4269
4301
  this.#getLastTransactions = async () => {
4270
4302
  let lastTransactions = (await Promise.all((await this.blocks)
4271
4303
  .filter((block) => block.loaded)
4272
- .slice(-128)
4304
+ .slice(-24)
4273
4305
  .map((block) => this.#loadBlockTransactions(block.transactions)))).reduce((all, transactions) => [...all, ...transactions], []);
4274
4306
  return Promise.all(lastTransactions.map((transaction) => transaction.hash()));
4275
4307
  };
@@ -4327,10 +4359,15 @@ class State extends Contract {
4327
4359
  }
4328
4360
  }
4329
4361
  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);
4362
+ try {
4363
+ const hash = await message.hash();
4364
+ // await this.state.updateState(message)
4365
+ await globalThis.chainStore.put('lastBlock', hash);
4366
+ globalThis.pubsub.publish('lastBlock', message.encoded);
4367
+ }
4368
+ catch (error) {
4369
+ console.error(error);
4370
+ }
4334
4371
  }
4335
4372
  getLatestBlock() {
4336
4373
  // @ts-ignore
@@ -4366,7 +4403,7 @@ class State extends Contract {
4366
4403
  this.#totalSize += size;
4367
4404
  this.#blocks[index - 1] = { hash, ...block.decoded };
4368
4405
  this.#blockHashMap.set(hash, index);
4369
- globalThis.debug(`resolved block: ${hash} @${index} ${formatBytes(size)}`);
4406
+ debug$1(`resolved block: ${hash} @${index} ${formatBytes(size)}`);
4370
4407
  globalThis.pubsub.publish('block-resolved', { hash, index });
4371
4408
  this.#lastResolved = this.#blocks[index - 1];
4372
4409
  this.#lastResolvedTime = Date.now();
@@ -4504,7 +4541,7 @@ class State extends Contract {
4504
4541
  await this.resolveBlock(lastBlock.hash);
4505
4542
  console.log('ok');
4506
4543
  let blocksSynced = localIndex > 0 ? (localIndex > index ? localIndex - index : index + -localIndex) : index;
4507
- globalThis.debug(`synced ${blocksSynced} ${blocksSynced > 1 ? 'blocks' : 'block'}`);
4544
+ debug$1(`synced ${blocksSynced} ${blocksSynced > 1 ? 'blocks' : 'block'}`);
4508
4545
  const blocks = this.#blocks;
4509
4546
  const start = blocks.length - blocksSynced;
4510
4547
  if (this.#machine) {
@@ -4636,7 +4673,7 @@ class State extends Contract {
4636
4673
  this.#blocks[block.index - 1].loaded = true;
4637
4674
  await this.#machine.addLoadedBlock(block);
4638
4675
  // @ts-ignore
4639
- globalThis.debug(`loaded block: ${block.hash} @${block.index}`);
4676
+ debug$1(`loaded block: ${block.hash} @${block.index}`);
4640
4677
  globalThis.pubsub.publish('block-loaded', { ...block });
4641
4678
  }
4642
4679
  }
@@ -4647,7 +4684,7 @@ class State extends Contract {
4647
4684
  return new Promise(async (resolve, reject) => {
4648
4685
  const timeout = setTimeout(() => {
4649
4686
  resolve([{ index: 0, hash: '0x0' }]);
4650
- globalThis.debug('sync timed out');
4687
+ debug$1('sync timed out');
4651
4688
  }, this.requestTimeout);
4652
4689
  promises = await Promise.allSettled(promises);
4653
4690
  promises = promises.filter(({ status }) => status === 'fulfilled');
@@ -4731,7 +4768,7 @@ class VersionControl extends State {
4731
4768
  }
4732
4769
 
4733
4770
  globalThis.BigNumber = BigNumber;
4734
- const ignorelist = [];
4771
+ const debug = globalThis.createDebugger('leofcoin/chain');
4735
4772
  // check if browser or local
4736
4773
  class Chain extends VersionControl {
4737
4774
  #state;
@@ -4758,7 +4795,7 @@ class Chain extends VersionControl {
4758
4795
  const transaction = new TransactionMessage(message);
4759
4796
  await transaction.hash();
4760
4797
  // if (await transactionPoolStore.has(hash)) await transactionPoolStore.delete(hash)
4761
- console.log(transaction);
4798
+ debug(`added ${transaction}`);
4762
4799
  };
4763
4800
  // @ts-ignore
4764
4801
  return this.#init();
@@ -4881,7 +4918,6 @@ class Chain extends VersionControl {
4881
4918
  const transactionsToGet = [];
4882
4919
  for (const key of transactionsInPool) {
4883
4920
  !transactions.includes(key) &&
4884
- !ignorelist.includes(key) &&
4885
4921
  transactionsToGet.push(transactionPoolStore.put(key, await peernet.get(key, 'transaction')));
4886
4922
  }
4887
4923
  return Promise.all(transactionsToGet);
@@ -4890,7 +4926,10 @@ class Chain extends VersionControl {
4890
4926
  const peer = peernet.getConnection(peerId);
4891
4927
  // todo handle version changes
4892
4928
  // for now just do nothing if version doesn't match
4893
- console.log(`${peer.version}, ${this.version}`);
4929
+ debug(`peer connected with version ${peer.version}`);
4930
+ if (peer.version !== this.version) {
4931
+ debug(`versions don't match`);
4932
+ }
4894
4933
  if (!peer.version || peer.version !== this.version)
4895
4934
  return;
4896
4935
  const lastBlock = await this.#makeRequest(peer, 'lastBlock');
@@ -4949,7 +4988,7 @@ class Chain extends VersionControl {
4949
4988
  await globalThis.blockStore.put(hash, blockMessage.encoded);
4950
4989
  if ((await this.lastBlock).index < Number(blockMessage.decoded.index))
4951
4990
  await this.updateState(blockMessage);
4952
- globalThis.debug(`added block: ${hash}`);
4991
+ debug(`added block: ${hash}`);
4953
4992
  let promises = [];
4954
4993
  let contracts = [];
4955
4994
  for (let transaction of blockMessage.decoded.transactions) {
@@ -5007,16 +5046,41 @@ class Chain extends VersionControl {
5007
5046
  if ((await this.hasTransactionToHandle()) && !this.#runningEpoch && this.#participating)
5008
5047
  await this.#runEpoch();
5009
5048
  }
5049
+ async #handleTransaction(transaction, latestTransactions, block) {
5050
+ const hash = await transaction.hash();
5051
+ const doubleTransactions = [];
5052
+ if (latestTransactions.includes(hash)) {
5053
+ doubleTransactions.push(hash);
5054
+ }
5055
+ if (doubleTransactions.length > 0) {
5056
+ await globalThis.transactionPoolStore.delete(hash);
5057
+ await globalThis.peernet.publish('invalid-transaction', hash);
5058
+ return;
5059
+ }
5060
+ // if (timestamp + this.#slotTime > Date.now()) {
5061
+ try {
5062
+ const result = await this.#executeTransaction({ ...transaction.decoded, hash });
5063
+ block.transactions.push(transaction);
5064
+ block.fees = block.fees.add(await calculateFee(transaction.decoded));
5065
+ await globalThis.accountsStore.put(transaction.decoded.from, new TextEncoder().encode(String(transaction.decoded.nonce)));
5066
+ }
5067
+ catch (e) {
5068
+ console.log('vvvvvv');
5069
+ console.log({ e });
5070
+ console.log(hash);
5071
+ peernet.publish('invalid-transaction', hash);
5072
+ console.log(await globalThis.transactionPoolStore.keys());
5073
+ console.log(await globalThis.transactionPoolStore.has(e.hash));
5074
+ await globalThis.transactionPoolStore.delete(e.hash);
5075
+ console.log(await globalThis.transactionPoolStore.has(e.hash));
5076
+ }
5077
+ }
5010
5078
  // todo filter tx that need to wait on prev nonce
5011
5079
  async #createBlock(limit = this.transactionLimit) {
5012
5080
  // vote for transactions
5013
5081
  if ((await globalThis.transactionPoolStore.size()) === 0)
5014
5082
  return;
5015
5083
  let transactions = await globalThis.transactionPoolStore.values(this.transactionLimit);
5016
- for (const hash of await globalThis.transactionPoolStore.keys()) {
5017
- if (ignorelist.includes(hash))
5018
- await globalThis.transactionPoolStore.delete(hash);
5019
- }
5020
5084
  if (Object.keys(transactions)?.length === 0)
5021
5085
  return;
5022
5086
  const timestamp = Date.now();
@@ -5029,39 +5093,16 @@ class Chain extends VersionControl {
5029
5093
  reward: parseUnits('150'),
5030
5094
  index: 0
5031
5095
  };
5096
+ const latestTransactions = await this.machine.latestTransactions();
5032
5097
  // exclude failing tx
5033
5098
  transactions = await this.promiseTransactions(transactions);
5034
- transactions = transactions.sort((a, b) => a.nonce - b.nonce);
5035
- const latestTransactions = await this.machine.latestTransactions();
5036
- for (let transaction of transactions) {
5037
- const hash = await transaction.hash();
5038
- const doubleTransactions = [];
5039
- if (latestTransactions.includes(hash)) {
5040
- doubleTransactions.push(hash);
5041
- }
5042
- if (doubleTransactions.length > 0) {
5043
- await globalThis.transactionPoolStore.delete(hash);
5044
- await globalThis.peernet.publish('invalid-transaction', hash);
5045
- return;
5046
- }
5047
- // if (timestamp + this.#slotTime > Date.now()) {
5048
- try {
5049
- const result = await this.#executeTransaction({ ...transaction.decoded, hash });
5050
- block.transactions.push(transaction);
5051
- block.fees = block.fees.add(await calculateFee(transaction.decoded));
5052
- await globalThis.accountsStore.put(transaction.decoded.from, new TextEncoder().encode(String(transaction.decoded.nonce)));
5053
- }
5054
- catch (e) {
5055
- console.log('vvvvvv');
5056
- console.log({ e });
5057
- console.log(hash);
5058
- peernet.publish('invalid-transaction', hash);
5059
- console.log(await globalThis.transactionPoolStore.keys());
5060
- console.log(await globalThis.transactionPoolStore.has(e.hash));
5061
- await globalThis.transactionPoolStore.delete(e.hash);
5062
- console.log(await globalThis.transactionPoolStore.has(e.hash));
5063
- }
5064
- }
5099
+ const priority = transactions.filter((transaction) => transaction.priority);
5100
+ await Promise.all(priority
5101
+ .sort((a, b) => a.nonce - b.nonce)
5102
+ .map((transaction) => this.#handleTransaction(transaction, latestTransactions, block)));
5103
+ await Promise.all(transactions
5104
+ .filter((transaction) => !transaction.priority)
5105
+ .map((transaction) => this.#handleTransaction(transaction, latestTransactions, block)));
5065
5106
  // don't add empty block
5066
5107
  if (block.transactions.length === 0)
5067
5108
  return;
@@ -5128,7 +5169,7 @@ class Chain extends VersionControl {
5128
5169
  await globalThis.peernet.put(hash, blockMessage.encoded, 'block');
5129
5170
  await this.updateState(blockMessage);
5130
5171
  await this.machine.addLoadedBlock({ ...blockMessage.decoded, loaded: true, hash: await blockMessage.hash() });
5131
- globalThis.debug(`created block: ${hash} @${block.index}`);
5172
+ debug(`created block: ${hash} @${block.index}`);
5132
5173
  globalThis.peernet.publish('add-block', blockMessage.encoded);
5133
5174
  globalThis.pubsub.publish('add-block', blockMessage.decoded);
5134
5175
  }
@@ -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(),