@leofcoin/chain 1.7.71 → 1.7.73

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.
@@ -1,4 +1,4 @@
1
- import { g as getDefaultExportFromCjs } from './identity-CQ_ieRiz-CTM-_kGF.js';
1
+ import { g as getDefaultExportFromCjs } from './identity--VAIVSMm-DTWL357I.js';
2
2
 
3
3
  var global;
4
4
  var hasRequiredGlobal;
@@ -43,6 +43,7 @@ function requireGlobal () {
43
43
  })();
44
44
  return global;
45
45
  }
46
+
46
47
  var version$1 = "1.0.35";
47
48
  var require$$0 = {
48
49
  version: version$1};
@@ -4219,7 +4219,10 @@ class Machine {
4219
4219
  }
4220
4220
  }
4221
4221
  else if (data.question === 'peers') {
4222
- this.worker.postMessage({ id: data.id, input: peernet.connections ? peernet.peers : [] });
4222
+ this.worker.postMessage({
4223
+ id: data.id,
4224
+ input: peernet.connections ? Object.entries(peernet.connections).map(([id, peer]) => peer.toJSON()) : []
4225
+ });
4223
4226
  }
4224
4227
  else {
4225
4228
  this.worker.postMessage({ id: data.id, input: data.input });
@@ -5392,6 +5395,10 @@ class Chain extends VersionControl {
5392
5395
  }
5393
5396
  async #invalidTransaction(hash) {
5394
5397
  hash = new TextDecoder().decode(hash);
5398
+ if (!(await globalThis.transactionPoolStore.has(hash))) {
5399
+ debug(`transaction ${hash} not in pool`);
5400
+ return;
5401
+ }
5395
5402
  console.log(`removing invalid transaction: ${hash}`);
5396
5403
  await globalThis.transactionPoolStore.delete(hash);
5397
5404
  }
@@ -5603,10 +5610,7 @@ class Chain extends VersionControl {
5603
5610
  console.log({ e });
5604
5611
  console.log(hash);
5605
5612
  peernet.publish('invalid-transaction', hash);
5606
- console.log(await globalThis.transactionPoolStore.keys());
5607
- console.log(await globalThis.transactionPoolStore.has(e.hash));
5608
5613
  await globalThis.transactionPoolStore.delete(e.hash);
5609
- console.log(await globalThis.transactionPoolStore.has(e.hash));
5610
5614
  }
5611
5615
  }
5612
5616
  // todo filter tx that need to wait on prev nonce
@@ -1,5 +1,5 @@
1
- import { L as LittlePubSub } from './node-browser-DcYcGvEF.js';
2
- import './identity-CQ_ieRiz-CTM-_kGF.js';
1
+ import { L as LittlePubSub } from './node-browser-BvxzAdLe.js';
2
+ import './identity--VAIVSMm-DTWL357I.js';
3
3
  import './index-DUfUgiQY.js';
4
4
 
5
5
  class Api {
@@ -210,7 +210,7 @@ class SocketRequestClient {
210
210
  const init = async () => {
211
211
  // @ts-ignore
212
212
  if (!globalThis.WebSocket && !this.#experimentalWebsocket)
213
- globalThis.WebSocket = (await import('./browser-DQJ6xf_F-BCS5wcAv.js').then(function (n) { return n.b; })).default.w3cwebsocket;
213
+ globalThis.WebSocket = (await import('./browser-BogfGRzB-D3fc2MzB.js').then(function (n) { return n.b; })).default.w3cwebsocket;
214
214
  const client = new WebSocket(this.#url, this.#protocol);
215
215
  if (this.#experimentalWebsocket) {
216
216
  client.addEventListener('error', this.onerror);
@@ -314,7 +314,7 @@ const iceServers = [
314
314
  credential: 'openrelayproject'
315
315
  }
316
316
  ];
317
- const SimplePeer = (await import('./index-CEwkDK9g-CHsuUR8y.js').then(function (n) { return n.i; })).default;
317
+ const SimplePeer = (await import('./index-Vgr1JQcP-DNJYAZ_u.js').then(function (n) { return n.i; })).default;
318
318
  class Peer extends SimplePeer {
319
319
  peerId;
320
320
  channelName;
@@ -391,6 +391,14 @@ class Peer extends SimplePeer {
391
391
  this.send(data, id);
392
392
  });
393
393
  }
394
+ toJSON() {
395
+ return {
396
+ peerId: this.peerId,
397
+ channelName: this.channelName,
398
+ version: this.version,
399
+ bw: this.bw
400
+ };
401
+ }
394
402
  }
395
403
 
396
404
  const debug = globalThis.createDebugger('@netpeer/swarm/client');
@@ -538,8 +546,8 @@ class Client {
538
546
  this.#connections[peerId].destroy();
539
547
  delete this.#connections[peerId];
540
548
  }
541
- // RTCPeerConnection
542
- this.#createRTCPeerConnection(peerId, star, version, true);
549
+ if (this.peerId !== peerId)
550
+ this.#createRTCPeerConnection(peerId, star, version, true);
543
551
  debug(`peer ${peerId} joined`);
544
552
  };
545
553
  #inComingSignal = async ({ from, signal, channelName, version }, star) => {
@@ -547,13 +555,28 @@ class Client {
547
555
  console.warn(`${from} joined using the wrong version.\nexpected: ${this.version} but got:${version}`);
548
556
  return;
549
557
  }
558
+ if (from === this.peerId) {
559
+ console.warn(`${from} tried to connect to itself.`);
560
+ return;
561
+ }
550
562
  let peer = this.#connections[from];
551
563
  if (!peer) {
552
564
  this.#createRTCPeerConnection(from, star, version);
553
565
  peer = this.#connections[from];
554
566
  }
555
- if (String(peer.channelName) !== String(channelName))
556
- console.warn(`channelNames don't match: got ${peer.channelName}, expected: ${channelName}`);
567
+ if (peer.connected) {
568
+ debug(`peer ${from} already connected`);
569
+ return;
570
+ }
571
+ if (String(peer.channelName) !== String(channelName)) {
572
+ console.warn(`channelNames don't match: got ${peer.channelName}, expected: ${channelName}. Recreating connection.`);
573
+ // Destroy the existing peer connection
574
+ peer.destroy();
575
+ delete this.#connections[from];
576
+ // Create a new peer connection with the correct configuration
577
+ this.#createRTCPeerConnection(from, star, version, false);
578
+ peer = this.#connections[from];
579
+ }
557
580
  peer.signal(signal);
558
581
  };
559
582
  #peerSignal = (peer, signal, star, version) => {