@leofcoin/chain 1.5.39 → 1.5.41
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.
- package/exports/browser/browser-2c73e2ef-2c73e2ef.js +25 -0
- package/exports/browser/chain.js +3038 -10
- package/exports/browser/{index-34c93510-db72e006.js → index-7dedefe5-b92d7eab.js} +2 -2
- package/exports/browser/{index-526fd466.js → index-c3bd3090.js} +1 -1
- package/exports/browser/{messages-b7f41cba-61105b71.js → messages-7cab2a51-aba26369.js} +2 -2
- package/exports/browser/{node-browser-e7da3b14.js → node-browser-ccc3409e.js} +316 -76
- package/exports/browser/node-browser.js +2 -2
- package/exports/chain.js +12 -9
- package/exports/node-browser.d.ts +1 -0
- package/exports/node.d.ts +1 -0
- package/exports/node.js +1 -0
- package/exports/version-control.d.ts +1 -0
- package/package.json +1 -1
- package/exports/browser/client-493cbd83-493cbd83.js +0 -10783
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-
|
|
2
|
-
import './index-
|
|
1
|
+
import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-ccc3409e.js';
|
|
2
|
+
import './index-c3bd3090.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @params {String} network
|
|
@@ -12630,4 +12630,4 @@ class RawTransactionMessage extends FormatInterface {
|
|
|
12630
12630
|
}
|
|
12631
12631
|
}
|
|
12632
12632
|
|
|
12633
|
-
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 };
|
|
12633
|
+
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 };
|
|
@@ -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-
|
|
1
|
+
import { C as ContractMessage, T as TransactionMessage, c as BlockMessage, d as BWMessage, e as BWRequestMessage, V as ValidatorMessage } from './index-c3bd3090.js';
|
|
2
2
|
|
|
3
3
|
var nodeConfig = async (config = {
|
|
4
4
|
network: 'leofcoin:peach',
|
|
@@ -27178,7 +27178,7 @@ class Identity {
|
|
|
27178
27178
|
this.selectedAccount = new TextDecoder().decode(selected);
|
|
27179
27179
|
}
|
|
27180
27180
|
else {
|
|
27181
|
-
const importee = await import(/* webpackChunkName: "generate-account" */ './index-
|
|
27181
|
+
const importee = await import(/* webpackChunkName: "generate-account" */ './index-7dedefe5-b92d7eab.js');
|
|
27182
27182
|
const { identity, accounts } = await importee.default(password, this.network);
|
|
27183
27183
|
await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
|
|
27184
27184
|
await globalThis.walletStore.put('version', String(1));
|
|
@@ -27254,17 +27254,18 @@ class Peernet {
|
|
|
27254
27254
|
autoStart = true;
|
|
27255
27255
|
#starting = false;
|
|
27256
27256
|
#started = false;
|
|
27257
|
-
#connections = {};
|
|
27258
27257
|
requestProtos = {};
|
|
27259
27258
|
_messageHandler;
|
|
27260
27259
|
_peerHandler;
|
|
27261
27260
|
protos;
|
|
27261
|
+
version;
|
|
27262
27262
|
/**
|
|
27263
27263
|
* @access public
|
|
27264
27264
|
* @param {Object} options
|
|
27265
27265
|
* @param {String} options.network - desired network
|
|
27266
27266
|
* @param {String} options.stars - star list for selected network (these should match, don't mix networks)
|
|
27267
27267
|
* @param {String} options.root - path to root directory
|
|
27268
|
+
* @param {String} options.version - path to root directory
|
|
27268
27269
|
* @param {String} options.storePrefix - prefix for datatores (lfc)
|
|
27269
27270
|
*
|
|
27270
27271
|
* @return {Promise} instance of Peernet
|
|
@@ -27279,6 +27280,7 @@ class Peernet {
|
|
|
27279
27280
|
this.network = options.network || 'leofcoin';
|
|
27280
27281
|
this.autoStart = options.autoStart === undefined ? true : options.autoStart;
|
|
27281
27282
|
this.stars = options.stars;
|
|
27283
|
+
this.version = options.version;
|
|
27282
27284
|
const parts = this.network.split(':');
|
|
27283
27285
|
this.networkVersion = options.networkVersion || parts.length > 1 ? parts[1] : 'mainnet';
|
|
27284
27286
|
if (!options.storePrefix)
|
|
@@ -27343,13 +27345,10 @@ class Peernet {
|
|
|
27343
27345
|
* @return {Array} peerId
|
|
27344
27346
|
*/
|
|
27345
27347
|
get peers() {
|
|
27346
|
-
return Object.entries(this
|
|
27348
|
+
return Object.entries(this.client?.connections);
|
|
27347
27349
|
}
|
|
27348
27350
|
get connections() {
|
|
27349
|
-
return
|
|
27350
|
-
}
|
|
27351
|
-
get peerEntries() {
|
|
27352
|
-
return Object.values(this.#connections);
|
|
27351
|
+
return this.client?.connections || {};
|
|
27353
27352
|
}
|
|
27354
27353
|
/**
|
|
27355
27354
|
* @return {String} id - peerId
|
|
@@ -27370,7 +27369,7 @@ class Peernet {
|
|
|
27370
27369
|
this.root = options.root;
|
|
27371
27370
|
const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
|
|
27372
27371
|
// FolderMessageResponse
|
|
27373
|
-
} = await import(/* webpackChunkName: "messages" */ './messages-
|
|
27372
|
+
} = await import(/* webpackChunkName: "messages" */ './messages-7cab2a51-aba26369.js');
|
|
27374
27373
|
/**
|
|
27375
27374
|
* proto Object containing protos
|
|
27376
27375
|
* @type {Object}
|
|
@@ -27404,80 +27403,321 @@ class Peernet {
|
|
|
27404
27403
|
await this.identity.load(password);
|
|
27405
27404
|
this._peerHandler = new PeerDiscovery(this.id);
|
|
27406
27405
|
this.peerId = this.id;
|
|
27407
|
-
this.addRequestHandler('handshake', () => {
|
|
27408
|
-
|
|
27409
|
-
|
|
27410
|
-
|
|
27411
|
-
})
|
|
27412
|
-
pubsub.subscribe('peer:discovered', async (peer) => {
|
|
27413
|
-
|
|
27414
|
-
|
|
27415
|
-
|
|
27416
|
-
|
|
27417
|
-
|
|
27418
|
-
|
|
27419
|
-
|
|
27420
|
-
|
|
27421
|
-
|
|
27422
|
-
|
|
27423
|
-
|
|
27424
|
-
|
|
27425
|
-
|
|
27426
|
-
|
|
27427
|
-
|
|
27428
|
-
|
|
27429
|
-
|
|
27430
|
-
|
|
27431
|
-
|
|
27432
|
-
|
|
27433
|
-
}
|
|
27434
|
-
|
|
27406
|
+
// this.addRequestHandler('handshake', () => {
|
|
27407
|
+
// return new peernet.protos['peernet-response']({
|
|
27408
|
+
// response: { peerId: this.id }
|
|
27409
|
+
// })
|
|
27410
|
+
// })
|
|
27411
|
+
// pubsub.subscribe('peer:discovered', async (peer) => {
|
|
27412
|
+
// // console.log(peer);
|
|
27413
|
+
// if (this.requestProtos['version'] && !peer.version) {
|
|
27414
|
+
// let data = await new globalThis.peernet.protos['peernet-request']({
|
|
27415
|
+
// request: 'version'
|
|
27416
|
+
// })
|
|
27417
|
+
// let node = await globalThis.peernet.prepareMessage(data)
|
|
27418
|
+
// let response = await peer.request(node.encoded)
|
|
27419
|
+
// response = await new globalThis.peernet.protos['peernet-response'](new Uint8Array(Object.values(response)))
|
|
27420
|
+
// peer.version = response.decoded.response.version
|
|
27421
|
+
// }
|
|
27422
|
+
// if (!peer.peerId) {
|
|
27423
|
+
// let data = await new globalThis.peernet.protos['peernet-request']({
|
|
27424
|
+
// request: 'handshake'
|
|
27425
|
+
// })
|
|
27426
|
+
// let node = await globalThis.peernet.prepareMessage(data)
|
|
27427
|
+
// let response = await peer.request(node.encoded)
|
|
27428
|
+
// response = await new globalThis.peernet.protos['peernet-response'](new Uint8Array(Object.values(response)))
|
|
27429
|
+
// // todo: response.decoded should be the response and not response.peerId
|
|
27430
|
+
// // todo: ignore above and remove discover completly
|
|
27431
|
+
// response.decoded.response.peerId
|
|
27432
|
+
// }
|
|
27433
|
+
// this.connections[peer.peerId] = peer
|
|
27434
|
+
// pubsub.publish('peer:connected', peer)
|
|
27435
|
+
// todo: cleanup discovered
|
|
27436
|
+
// })
|
|
27437
|
+
// pubsub.subscribe('peer:left', this.#peerLeft.bind(this))
|
|
27435
27438
|
/**
|
|
27436
27439
|
* converts data -> message -> proto
|
|
27437
27440
|
* @see DataHandler
|
|
27438
27441
|
*/
|
|
27439
27442
|
pubsub.subscribe('peer:data', dataHandler);
|
|
27443
|
+
// // todo: remove below, already handles in the swarm
|
|
27444
|
+
// if (globalThis.navigator) {
|
|
27445
|
+
// globalThis.addEventListener('beforeunload', async () => this.client.close())
|
|
27446
|
+
// } else {
|
|
27447
|
+
// process.on('SIGTERM', async () => {
|
|
27448
|
+
// process.stdin.resume()
|
|
27449
|
+
// try {
|
|
27450
|
+
// await this.client.close()
|
|
27451
|
+
// } catch (error) {
|
|
27452
|
+
// // @ts-ignore
|
|
27453
|
+
// await this.client.close()
|
|
27454
|
+
// }
|
|
27455
|
+
// process.exit()
|
|
27456
|
+
// })
|
|
27457
|
+
// }
|
|
27458
|
+
if (this.autoStart)
|
|
27459
|
+
await this.start();
|
|
27460
|
+
return this;
|
|
27461
|
+
}
|
|
27462
|
+
async start() {
|
|
27463
|
+
if (this.#starting || this.#started)
|
|
27464
|
+
return;
|
|
27465
|
+
this.#starting = true;
|
|
27466
|
+
const importee = class Client {
|
|
27467
|
+
#peerId;
|
|
27468
|
+
#connections = {};
|
|
27469
|
+
#stars = {};
|
|
27470
|
+
#connectEvent = 'peer:connected';
|
|
27471
|
+
id;
|
|
27472
|
+
networkVersion;
|
|
27473
|
+
starsConfig;
|
|
27474
|
+
socketClient;
|
|
27475
|
+
messageSize = 262144;
|
|
27476
|
+
version;
|
|
27477
|
+
#messagesToHandle = {};
|
|
27478
|
+
get peerId() {
|
|
27479
|
+
return this.#peerId;
|
|
27480
|
+
}
|
|
27481
|
+
get connections() {
|
|
27482
|
+
return { ...this.#connections };
|
|
27483
|
+
}
|
|
27484
|
+
get peers() {
|
|
27485
|
+
return Object.entries(this.#connections);
|
|
27486
|
+
}
|
|
27487
|
+
getPeer(peerId) {
|
|
27488
|
+
return this.#connections[peerId];
|
|
27489
|
+
}
|
|
27490
|
+
/**
|
|
27491
|
+
*
|
|
27492
|
+
* @param options {object}
|
|
27493
|
+
* @param options.peerId {string}
|
|
27494
|
+
* @param options.networkVersion {string}
|
|
27495
|
+
* @param options.version {string}
|
|
27496
|
+
* @param options.stars {string[]}
|
|
27497
|
+
* @param options.connectEvent {string} defaults to peer:connected, can be renamed to handle different protocols, like peer:discovered (setup peer props before fireing the connect event)
|
|
27498
|
+
*/
|
|
27499
|
+
constructor(options) {
|
|
27500
|
+
const { peerId, networkVersion, version, connectEvent, stars } = {
|
|
27501
|
+
...defaultOptions,
|
|
27502
|
+
...options
|
|
27503
|
+
};
|
|
27504
|
+
this.#peerId = peerId;
|
|
27505
|
+
this.networkVersion = networkVersion;
|
|
27506
|
+
this.version = version;
|
|
27507
|
+
this.#connectEvent = connectEvent;
|
|
27508
|
+
this.starsConfig = stars;
|
|
27509
|
+
this._init();
|
|
27510
|
+
}
|
|
27511
|
+
async _init() {
|
|
27512
|
+
// reconnectJob()
|
|
27513
|
+
if (!globalThis.RTCPeerConnection)
|
|
27514
|
+
globalThis.wrtc = (await import('./browser-2c73e2ef-2c73e2ef.js').then(function (n) { return n.b; })).default;
|
|
27515
|
+
for (const star of this.starsConfig) {
|
|
27516
|
+
try {
|
|
27517
|
+
const client = new SocketRequestClient(star, this.networkVersion);
|
|
27518
|
+
this.#stars[star] = await client.init();
|
|
27519
|
+
this.setupStarListeners(this.#stars[star]);
|
|
27520
|
+
this.#stars[star].send({
|
|
27521
|
+
url: 'join',
|
|
27522
|
+
params: { version: this.version, peerId: this.peerId }
|
|
27523
|
+
});
|
|
27524
|
+
}
|
|
27525
|
+
catch (e) {
|
|
27526
|
+
if (this.starsConfig.indexOf(star) === this.starsConfig.length - 1 &&
|
|
27527
|
+
!this.socketClient)
|
|
27528
|
+
throw new Error(`No star available to connect`);
|
|
27529
|
+
}
|
|
27530
|
+
}
|
|
27440
27531
|
if (globalThis.navigator) {
|
|
27441
|
-
globalThis.addEventListener('beforeunload', async () => this.
|
|
27532
|
+
globalThis.addEventListener('beforeunload', async () => this.close());
|
|
27442
27533
|
}
|
|
27443
27534
|
else {
|
|
27444
|
-
process.on('
|
|
27535
|
+
process.on('SIGINT', async () => {
|
|
27445
27536
|
process.stdin.resume();
|
|
27446
|
-
|
|
27447
|
-
await this.client.destroy();
|
|
27448
|
-
}
|
|
27449
|
-
catch (error) {
|
|
27450
|
-
// @ts-ignore
|
|
27451
|
-
await this.client.close();
|
|
27452
|
-
}
|
|
27537
|
+
await this.close();
|
|
27453
27538
|
process.exit();
|
|
27454
27539
|
});
|
|
27455
27540
|
}
|
|
27456
|
-
if (this.autoStart)
|
|
27457
|
-
await this.start();
|
|
27458
|
-
return this;
|
|
27459
27541
|
}
|
|
27460
|
-
|
|
27461
|
-
|
|
27542
|
+
setupStarListeners(star) {
|
|
27543
|
+
star.pubsub.subscribe('peer:joined', (id) => this.#peerJoined(id, star));
|
|
27544
|
+
star.pubsub.subscribe('peer:left', (id) => this.#peerLeft(id, star));
|
|
27545
|
+
star.pubsub.subscribe('star:joined', this.#starJoined);
|
|
27546
|
+
star.pubsub.subscribe('star:left', this.#starLeft);
|
|
27547
|
+
star.pubsub.subscribe('signal', (message) => this.#inComingSignal(message, star));
|
|
27548
|
+
}
|
|
27549
|
+
#starJoined = (id) => {
|
|
27550
|
+
if (this.#stars[id]) {
|
|
27551
|
+
this.#stars[id].close(0);
|
|
27552
|
+
delete this.#stars[id];
|
|
27553
|
+
}
|
|
27554
|
+
console.log(`star ${id} joined`);
|
|
27555
|
+
};
|
|
27556
|
+
#starLeft = async (id) => {
|
|
27557
|
+
if (this.#stars[id]) {
|
|
27558
|
+
this.#stars[id].close(0);
|
|
27559
|
+
delete this.#stars[id];
|
|
27560
|
+
}
|
|
27561
|
+
if (Object.keys(this.#stars).length === 0) {
|
|
27562
|
+
for (const star of this.starsConfig) {
|
|
27563
|
+
try {
|
|
27564
|
+
const socketClient = await new SocketRequestClient(star, this.networkVersion).init();
|
|
27565
|
+
if (!socketClient?.client?.OPEN)
|
|
27566
|
+
return;
|
|
27567
|
+
this.#stars[star] = socketClient;
|
|
27568
|
+
this.#stars[star].send({
|
|
27569
|
+
url: 'join',
|
|
27570
|
+
params: { peerId: this.peerId, version: this.version }
|
|
27571
|
+
});
|
|
27572
|
+
this.setupStarListeners(socketClient);
|
|
27573
|
+
}
|
|
27574
|
+
catch (e) {
|
|
27575
|
+
if (this.starsConfig.indexOf(star) === this.starsConfig.length - 1)
|
|
27576
|
+
throw new Error(`No star available to connect`);
|
|
27577
|
+
}
|
|
27578
|
+
}
|
|
27579
|
+
}
|
|
27580
|
+
globalThis.debug(`star ${id} left`);
|
|
27581
|
+
};
|
|
27582
|
+
#peerLeft(peer, star) {
|
|
27583
|
+
const id = peer.peerId || peer;
|
|
27584
|
+
if (this.#connections[id]) {
|
|
27585
|
+
this.#connections[id].destroy();
|
|
27586
|
+
delete this.#connections[id];
|
|
27587
|
+
}
|
|
27588
|
+
globalThis.debug(`peer ${id} left`);
|
|
27589
|
+
}
|
|
27590
|
+
#createRTCPeerConnection = (peerId, star, version, initiator = false) => {
|
|
27591
|
+
const peer = new Peer({
|
|
27592
|
+
initiator: initiator,
|
|
27593
|
+
from: this.peerId,
|
|
27594
|
+
to: peerId,
|
|
27595
|
+
version
|
|
27596
|
+
});
|
|
27597
|
+
peer.on('signal', (signal) => this.#peerSignal(peer, signal, star));
|
|
27598
|
+
peer.on('connect', () => this.#peerConnect(peer));
|
|
27599
|
+
peer.on('close', () => this.#peerClose(peer));
|
|
27600
|
+
peer.on('data', (data) => this.#peerData(peer, data));
|
|
27601
|
+
peer.on('error', (error) => this.#peerError(peer, error));
|
|
27602
|
+
this.#connections[peerId] = peer;
|
|
27603
|
+
};
|
|
27604
|
+
#peerJoined = async ({ peerId, version }, star) => {
|
|
27605
|
+
// check if peer rejoined before the previous connection closed
|
|
27606
|
+
if (this.#connections[peerId]) {
|
|
27607
|
+
if (this.#connections[peerId].connected)
|
|
27608
|
+
this.#connections[peerId].destroy();
|
|
27609
|
+
delete this.#connections[peerId];
|
|
27610
|
+
}
|
|
27611
|
+
// RTCPeerConnection
|
|
27612
|
+
this.#createRTCPeerConnection(peerId, star, version, true);
|
|
27613
|
+
globalThis.debug(`peer ${peerId} joined`);
|
|
27614
|
+
};
|
|
27615
|
+
#inComingSignal = async ({ from, signal, channelName, version }, star) => {
|
|
27616
|
+
if (version !== this.version) {
|
|
27617
|
+
console.warn(`${from} joined using the wrong version.\nexpected: ${this.version} but got:${version}`);
|
|
27462
27618
|
return;
|
|
27463
|
-
|
|
27464
|
-
|
|
27619
|
+
}
|
|
27620
|
+
let peer = this.#connections[from];
|
|
27621
|
+
if (!peer) {
|
|
27622
|
+
this.#createRTCPeerConnection(from, star, version);
|
|
27623
|
+
peer = this.#connections[from];
|
|
27624
|
+
}
|
|
27625
|
+
if (String(peer.channelName) !== String(channelName))
|
|
27626
|
+
console.warn(`channelNames don't match: got ${peer.channelName}, expected: ${channelName}`);
|
|
27627
|
+
peer.signal(signal);
|
|
27628
|
+
};
|
|
27629
|
+
#peerSignal = (peer, signal, star) => {
|
|
27630
|
+
let client = this.#stars[star];
|
|
27631
|
+
if (!client)
|
|
27632
|
+
client = this.#stars[Object.keys(this.#stars)[0]];
|
|
27633
|
+
client.send({
|
|
27634
|
+
url: 'signal',
|
|
27635
|
+
params: {
|
|
27636
|
+
from: this.peerId,
|
|
27637
|
+
to: peer.peerId,
|
|
27638
|
+
channelName: peer.channelName,
|
|
27639
|
+
version: this.version,
|
|
27640
|
+
signal
|
|
27641
|
+
}
|
|
27642
|
+
});
|
|
27643
|
+
};
|
|
27644
|
+
#peerClose = (peer) => {
|
|
27645
|
+
if (this.#connections[peer.peerId]) {
|
|
27646
|
+
this.#connections[peer.peerId].destroy();
|
|
27647
|
+
delete this.#connections[peer.peerId];
|
|
27648
|
+
}
|
|
27649
|
+
globalThis.debug(`closed ${peer.peerId}'s connection`);
|
|
27650
|
+
};
|
|
27651
|
+
#peerConnect = (peer) => {
|
|
27652
|
+
globalThis.debug(`${peer.peerId} connected`);
|
|
27653
|
+
globalThis.pubsub.publish(this.#connectEvent, peer.peerId);
|
|
27654
|
+
};
|
|
27655
|
+
#noticeMessage = (message, id) => {
|
|
27656
|
+
if (globalThis.pubsub.subscribers[id]) {
|
|
27657
|
+
globalThis.pubsub.publish(id, new Uint8Array(message));
|
|
27658
|
+
}
|
|
27659
|
+
else {
|
|
27660
|
+
globalThis.pubsub.publish('peer:data', new Uint8Array(message));
|
|
27661
|
+
}
|
|
27662
|
+
};
|
|
27663
|
+
#peerData = (peer, data) => {
|
|
27664
|
+
const { id, size, chunk } = JSON.parse(new TextDecoder().decode(data));
|
|
27665
|
+
peer.bw.down += size;
|
|
27666
|
+
if (size <= MAX_MESSAGE_SIZE) {
|
|
27667
|
+
this.#noticeMessage(chunk, id);
|
|
27668
|
+
}
|
|
27669
|
+
else {
|
|
27670
|
+
if (!this.#messagesToHandle[id])
|
|
27671
|
+
this.#messagesToHandle[id] = [];
|
|
27672
|
+
this.#messagesToHandle[id] = [
|
|
27673
|
+
...this.#messagesToHandle[id],
|
|
27674
|
+
...Object.values(chunk)
|
|
27675
|
+
];
|
|
27676
|
+
if (this.#messagesToHandle[id].length === Number(size)) {
|
|
27677
|
+
this.#noticeMessage(this.#messagesToHandle[id], id);
|
|
27678
|
+
delete this.#messagesToHandle[id];
|
|
27679
|
+
}
|
|
27680
|
+
}
|
|
27681
|
+
};
|
|
27682
|
+
#peerError = (peer, error) => {
|
|
27683
|
+
console.warn(`Connection error: ${error.message}`);
|
|
27684
|
+
peer.destroy();
|
|
27685
|
+
};
|
|
27686
|
+
async close() {
|
|
27687
|
+
for (const star in this.#stars) {
|
|
27688
|
+
if (this.#stars[star].connectionState() === 'open')
|
|
27689
|
+
await this.#stars[star].send({ url: 'leave', params: this.peerId });
|
|
27690
|
+
}
|
|
27691
|
+
const promises = [
|
|
27692
|
+
Object.values(this.#connections).map((connection) => connection.destroy()),
|
|
27693
|
+
Object.values(this.#stars).map((connection) => connection.close(0))
|
|
27694
|
+
];
|
|
27695
|
+
await Promise.allSettled(promises);
|
|
27696
|
+
}
|
|
27697
|
+
};
|
|
27465
27698
|
/**
|
|
27466
27699
|
* @access public
|
|
27467
27700
|
* @type {PeernetClient}
|
|
27468
27701
|
*/
|
|
27469
|
-
|
|
27702
|
+
console.log(this.stars);
|
|
27703
|
+
this.client = new importee.default({
|
|
27704
|
+
peerId: this.id,
|
|
27705
|
+
networkVersion: this.networkVersion,
|
|
27706
|
+
version: this.version,
|
|
27707
|
+
stars: this.stars
|
|
27708
|
+
});
|
|
27470
27709
|
this.#started = true;
|
|
27471
27710
|
this.#starting = false;
|
|
27472
27711
|
}
|
|
27473
|
-
|
|
27474
|
-
|
|
27475
|
-
|
|
27476
|
-
|
|
27477
|
-
|
|
27478
|
-
|
|
27479
|
-
|
|
27480
|
-
}
|
|
27712
|
+
// todo: remove, handled in swarm now
|
|
27713
|
+
// #peerLeft(peer: SwarmPeer) {
|
|
27714
|
+
// for (const [id, _peer] of Object.entries(this.connections)) {
|
|
27715
|
+
// if (_peer.id === peer.id && this.connections[id] && !this.connections[id].connected) {
|
|
27716
|
+
// delete this.connections[id]
|
|
27717
|
+
// this.removePeer(_peer)
|
|
27718
|
+
// }
|
|
27719
|
+
// }
|
|
27720
|
+
// }
|
|
27481
27721
|
addRequestHandler(name, method) {
|
|
27482
27722
|
this.requestProtos[name] = method;
|
|
27483
27723
|
}
|
|
@@ -27581,7 +27821,7 @@ class Peernet {
|
|
|
27581
27821
|
this.dht.addProvider(peerInfo, proto.decoded.hash);
|
|
27582
27822
|
};
|
|
27583
27823
|
let walks = [];
|
|
27584
|
-
for (const [peerId, peer] of Object.entries(this
|
|
27824
|
+
for (const [peerId, peer] of Object.entries(this.connections)) {
|
|
27585
27825
|
if (peerId !== this.id) {
|
|
27586
27826
|
walks.push(walk(peer, peerId));
|
|
27587
27827
|
}
|
|
@@ -27648,7 +27888,7 @@ class Peernet {
|
|
|
27648
27888
|
if (!closestPeer || !closestPeer.id)
|
|
27649
27889
|
return this.requestData(hash, store?.name || store);
|
|
27650
27890
|
const id = closestPeer.id;
|
|
27651
|
-
const peer = this
|
|
27891
|
+
const peer = this.connections[id];
|
|
27652
27892
|
if (peer?.connected) {
|
|
27653
27893
|
let data = await new globalThis.peernet.protos['peernet-data']({
|
|
27654
27894
|
hash,
|
|
@@ -27662,7 +27902,7 @@ class Peernet {
|
|
|
27662
27902
|
const promises = [];
|
|
27663
27903
|
const providers = await this.providersFor(hash, store);
|
|
27664
27904
|
for (const provider of Object.values(providers)) {
|
|
27665
|
-
const peer = this
|
|
27905
|
+
const peer = this.connections[provider.id];
|
|
27666
27906
|
if (peer)
|
|
27667
27907
|
promises.push(peer.request(node.encoded));
|
|
27668
27908
|
}
|
|
@@ -27876,7 +28116,7 @@ class Peernet {
|
|
|
27876
28116
|
// globalSub.publish(topic, data)
|
|
27877
28117
|
const id = Math.random().toString(36).slice(-12);
|
|
27878
28118
|
data = await new globalThis.peernet.protos['peernet-ps']({ data, topic });
|
|
27879
|
-
for (const [peerId, peer] of Object.entries(this
|
|
28119
|
+
for (const [peerId, peer] of Object.entries(this.connections)) {
|
|
27880
28120
|
if (peerId !== this.id) {
|
|
27881
28121
|
const node = await this.prepareMessage(data);
|
|
27882
28122
|
this.sendMessage(peer, id, node.encoded);
|
|
@@ -27898,16 +28138,15 @@ class Peernet {
|
|
|
27898
28138
|
}
|
|
27899
28139
|
async removePeer(peer) {
|
|
27900
28140
|
console.log('removepeer', peer.id);
|
|
27901
|
-
|
|
27902
|
-
await this.client.
|
|
27903
|
-
if (this.client.peers[id]) {
|
|
27904
|
-
|
|
27905
|
-
|
|
27906
|
-
|
|
27907
|
-
|
|
27908
|
-
|
|
27909
|
-
|
|
27910
|
-
}
|
|
28141
|
+
peer.id;
|
|
28142
|
+
// await this.client.connections(peer)
|
|
28143
|
+
// if (this.client.peers[id]) {
|
|
28144
|
+
// for (const connection of Object.keys(this.client.peers[id])) {
|
|
28145
|
+
// // if (this.client.peers[id][connection].connected === false) delete this.client.peers[id][connection]
|
|
28146
|
+
// // @ts-ignore
|
|
28147
|
+
// if (this.client.peers[id][connection].connected) return this.client.emit('peerconnect', connection)
|
|
28148
|
+
// }
|
|
28149
|
+
// }
|
|
27911
28150
|
}
|
|
27912
28151
|
get Buffer() {
|
|
27913
28152
|
return Buffer;
|
|
@@ -27949,6 +28188,7 @@ class Node {
|
|
|
27949
28188
|
network: 'leofcoin:peach',
|
|
27950
28189
|
networkName: 'leofcoin:peach',
|
|
27951
28190
|
networkVersion: 'peach',
|
|
28191
|
+
version: '1.2.0',
|
|
27952
28192
|
stars: networks.leofcoin.peach.stars
|
|
27953
28193
|
}, password) {
|
|
27954
28194
|
this.#node = globalThis.Peernet
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { N as default } from './node-browser-
|
|
2
|
-
import './index-
|
|
1
|
+
export { N as default } from './node-browser-ccc3409e.js';
|
|
2
|
+
import './index-c3bd3090.js';
|
package/exports/chain.js
CHANGED
|
@@ -2,6 +2,7 @@ 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, signTransaction, contractFactoryMessage, nativeTokenMessage, validatorsMessage, nameServiceMessage } from '@leofcoin/lib';
|
|
5
|
+
import semver from 'semver';
|
|
5
6
|
import { randombytes } from '@leofcoin/crypto';
|
|
6
7
|
import EasyWorker from '@vandeurenglenn/easy-worker';
|
|
7
8
|
import { ContractDeploymentError, ExecutionError, isResolveError, ResolveError, isExecutionError } from '@leofcoin/errors';
|
|
@@ -1106,9 +1107,13 @@ class VersionControl extends State {
|
|
|
1106
1107
|
constructor(config) {
|
|
1107
1108
|
super(config);
|
|
1108
1109
|
}
|
|
1110
|
+
#currentVersion;
|
|
1111
|
+
async #setCurrentVersion() {
|
|
1112
|
+
this.version = this.#currentVersion;
|
|
1113
|
+
await globalThis.chainStore.put('version', this.version);
|
|
1114
|
+
}
|
|
1109
1115
|
async init() {
|
|
1110
1116
|
super.init && (await super.init());
|
|
1111
|
-
console.log('init');
|
|
1112
1117
|
try {
|
|
1113
1118
|
const version = await globalThis.chainStore.get('version');
|
|
1114
1119
|
this.version = new TextDecoder().decode(version);
|
|
@@ -1119,18 +1124,16 @@ class VersionControl extends State {
|
|
|
1119
1124
|
* in the future we want newer nodes to handle the new changes and still confirm old version transactions
|
|
1120
1125
|
* unless there is a security issue!
|
|
1121
1126
|
*/
|
|
1122
|
-
if (this.version
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
await globalThis.chainStore.put('version', this.version);
|
|
1127
|
+
if (semver.compare(this.#currentVersion, this.version) === 1) {
|
|
1128
|
+
// await this.clearAll()
|
|
1129
|
+
this.#setCurrentVersion();
|
|
1126
1130
|
}
|
|
1127
1131
|
// if (version)
|
|
1128
1132
|
}
|
|
1129
1133
|
catch (e) {
|
|
1130
1134
|
console.log(e);
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
await globalThis.chainStore.put('version', this.version);
|
|
1135
|
+
// await this.clearAll()
|
|
1136
|
+
this.#setCurrentVersion();
|
|
1134
1137
|
}
|
|
1135
1138
|
}
|
|
1136
1139
|
}
|
|
@@ -1469,7 +1472,7 @@ class Chain extends VersionControl {
|
|
|
1469
1472
|
// }
|
|
1470
1473
|
// }, [])
|
|
1471
1474
|
const peers = {};
|
|
1472
|
-
for (const entry of globalThis.peernet.
|
|
1475
|
+
for (const entry of globalThis.peernet.peers) {
|
|
1473
1476
|
peers[entry[0]] = entry[1];
|
|
1474
1477
|
}
|
|
1475
1478
|
for (const validator of Object.keys(validators)) {
|
package/exports/node.d.ts
CHANGED
package/exports/node.js
CHANGED