@leofcoin/chain 1.4.45 → 1.4.47

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.
@@ -8064,7 +8064,11 @@ class Chain extends Contract {
8064
8064
  }
8065
8065
  return latest;
8066
8066
  }
8067
+ async #clearPool() {
8068
+ await globalThis.transactionPoolStore.clear();
8069
+ }
8067
8070
  async #init() {
8071
+ await this.#clearPool();
8068
8072
  // this.node = await new Node()
8069
8073
  this.#participants = [];
8070
8074
  this.#participating = false;
@@ -8317,7 +8321,7 @@ class Chain extends Contract {
8317
8321
  }
8318
8322
  catch (error) {
8319
8323
  console.log({ error });
8320
- globalThis.peernet.pubsub.publish('invalid-transaction', hash);
8324
+ globalThis.peernet.publish('invalid-transaction', hash);
8321
8325
  globalThis.pubsub.publish(`transaction.completed.${hash}`, { status: 'fail', hash, error: error });
8322
8326
  throw { error, hash, from, to, params, nonce };
8323
8327
  }
@@ -8414,8 +8418,16 @@ class Chain extends Contract {
8414
8418
  transactions = transactions.sort((a, b) => a.nonce - b.nonce);
8415
8419
  for (let transaction of transactions) {
8416
8420
  const hash = await transaction.hash();
8417
- const doubleTransaction = this.#blocks.filter(({ transaction }) => transaction.hash === hash);
8418
- if (doubleTransaction.length > 0) {
8421
+ const doubleTransactions = [];
8422
+ for (const block of this.#blocks) {
8423
+ for (const transaction of block.transactions) {
8424
+ if (transaction.hash === hash) {
8425
+ doubleTransactions.push(hash);
8426
+ }
8427
+ }
8428
+ }
8429
+ console.log();
8430
+ if (doubleTransactions.length > 0) {
8419
8431
  await globalThis.transactionPoolStore.delete(hash);
8420
8432
  await globalThis.peernet.publish('invalid-transaction', hash);
8421
8433
  }
@@ -1,4 +1,4 @@
1
- import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './node-browser-aa07a41d.js';
1
+ import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './node-browser-b64e2ed2.js';
2
2
  import './contract-f76383c3.js';
3
3
 
4
4
  function commonjsRequire(path) {
@@ -1,4 +1,4 @@
1
- import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-aa07a41d.js';
1
+ import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-b64e2ed2.js';
2
2
  import './contract-f76383c3.js';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { F as FormatInterface } from './node-browser-aa07a41d.js';
1
+ import { F as FormatInterface } from './node-browser-b64e2ed2.js';
2
2
  import './contract-f76383c3.js';
3
3
 
4
4
  var proto$b = {
@@ -6283,10 +6283,10 @@ const lastFetched = {
6283
6283
  timestamp: 0,
6284
6284
  },
6285
6285
  };
6286
+ const fetchedCoordinates = {};
6286
6287
  const getAddress = async () => {
6287
6288
  const { address } = lastFetched;
6288
- const now = Math.round(new Date().getTime() / 1000);
6289
- if (now - address.timestamp > 1200000) {
6289
+ if (address) {
6290
6290
  address.value = await fetch('https://icanhazip.com/');
6291
6291
  address.value = await address.value.text();
6292
6292
  address.timestamp = Math.round(new Date().getTime() / 1000);
@@ -6320,12 +6320,14 @@ class DhtEarth {
6320
6320
  * @return {Object} {latitude: lat, longitude: lon}
6321
6321
  */
6322
6322
  async getCoordinates(address) {
6323
- // const {address} = parseAddress(provider)
6324
- const request = `https://whereis.leofcoin.org/?ip=${address}`;
6325
- let response = await fetch(request);
6326
- response = await response.json();
6327
- const { lat, lon } = response;
6328
- return { latitude: lat, longitude: lon };
6323
+ if (!fetchedCoordinates[address]) {
6324
+ const request = `https://whereis.leofcoin.org/?ip=${address}`;
6325
+ let response = await fetch(request);
6326
+ response = await response.json();
6327
+ const { lat, lon } = response;
6328
+ fetchedCoordinates[address] = { latitude: lat, longitude: lon };
6329
+ }
6330
+ return fetchedCoordinates[address];
6329
6331
  }
6330
6332
  /**
6331
6333
  * @param {Object} peer
@@ -20265,7 +20267,7 @@ class Identity {
20265
20267
  globalThis.peernet.selectedAccount = new TextDecoder().decode(selected);
20266
20268
  }
20267
20269
  else {
20268
- const importee = await import(/* webpackChunkName: "generate-account" */ './index-2c2a9d47-00b5d0df.js');
20270
+ const importee = await import(/* webpackChunkName: "generate-account" */ './index-116df6d1-d144f080.js');
20269
20271
  const { identity, accounts } = await importee.default(password, this.network);
20270
20272
  await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
20271
20273
  await globalThis.walletStore.put('version', String(1));
@@ -20436,7 +20438,7 @@ class Peernet {
20436
20438
  this.root = options.root;
20437
20439
  const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
20438
20440
  // FolderMessageResponse
20439
- } = await import(/* webpackChunkName: "messages" */ './messages-6cc87ed7-c16a1408.js');
20441
+ } = await import(/* webpackChunkName: "messages" */ './messages-fab7583b-10480899.js');
20440
20442
  /**
20441
20443
  * proto Object containing protos
20442
20444
  * @type {Object}
@@ -20508,7 +20510,7 @@ class Peernet {
20508
20510
  if (this.#starting || this.#started)
20509
20511
  return;
20510
20512
  this.#starting = true;
20511
- const importee = await import('./client-e3216b03-fd2d3b03.js');
20513
+ const importee = await import('./client-bdab491d-5e9615c3.js');
20512
20514
  /**
20513
20515
  * @access public
20514
20516
  * @type {PeernetClient}
@@ -1,2 +1,2 @@
1
- export { N as default } from './node-browser-aa07a41d.js';
1
+ export { N as default } from './node-browser-b64e2ed2.js';
2
2
  import './contract-f76383c3.js';
package/exports/chain.js CHANGED
@@ -659,7 +659,11 @@ class Chain extends Contract {
659
659
  }
660
660
  return latest;
661
661
  }
662
+ async #clearPool() {
663
+ await globalThis.transactionPoolStore.clear();
664
+ }
662
665
  async #init() {
666
+ await this.#clearPool();
663
667
  // this.node = await new Node()
664
668
  this.#participants = [];
665
669
  this.#participating = false;
@@ -912,7 +916,7 @@ class Chain extends Contract {
912
916
  }
913
917
  catch (error) {
914
918
  console.log({ error });
915
- globalThis.peernet.pubsub.publish('invalid-transaction', hash);
919
+ globalThis.peernet.publish('invalid-transaction', hash);
916
920
  globalThis.pubsub.publish(`transaction.completed.${hash}`, { status: 'fail', hash, error: error });
917
921
  throw { error, hash, from, to, params, nonce };
918
922
  }
@@ -1009,8 +1013,16 @@ class Chain extends Contract {
1009
1013
  transactions = transactions.sort((a, b) => a.nonce - b.nonce);
1010
1014
  for (let transaction of transactions) {
1011
1015
  const hash = await transaction.hash();
1012
- const doubleTransaction = this.#blocks.filter(({ transaction }) => transaction.hash === hash);
1013
- if (doubleTransaction.length > 0) {
1016
+ const doubleTransactions = [];
1017
+ for (const block of this.#blocks) {
1018
+ for (const transaction of block.transactions) {
1019
+ if (transaction.hash === hash) {
1020
+ doubleTransactions.push(hash);
1021
+ }
1022
+ }
1023
+ }
1024
+ console.log();
1025
+ if (doubleTransactions.length > 0) {
1014
1026
  await globalThis.transactionPoolStore.delete(hash);
1015
1027
  await globalThis.peernet.publish('invalid-transaction', hash);
1016
1028
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.4.45",
3
+ "version": "1.4.47",
4
4
  "description": "Official javascript implementation",
5
5
  "exports": {
6
6
  "./node": "./exports/node.js",