@leofcoin/chain 1.5.44 → 1.5.46
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-dc41c03f-30a79cee.js +188 -0
- package/exports/browser/chain.js +689 -664
- package/exports/browser/client-f193279c-98f2aeaa.js +601 -0
- package/exports/browser/{index-2836cc96-40ed5df4.js → index-81687e93-18fab48d.js} +1 -1
- package/exports/browser/index-fd97ecae-c859300d.js +7876 -0
- package/exports/browser/{messages-554d2a85-ce06f6eb.js → messages-cccb78db-116bfaa7.js} +1 -1
- package/exports/browser/{node-browser-77f8d4c5.js → node-browser-c75c189a.js} +80 -293
- package/exports/browser/node-browser.js +1 -1
- package/exports/browser/workers/block-worker.js +4 -2
- package/exports/browser/workers/machine-worker.js +34 -14
- package/exports/chain.js +16 -8
- package/exports/workers/block-worker.js +4 -2
- package/exports/workers/machine-worker.js +34 -14
- package/package.json +1 -1
|
@@ -102,58 +102,62 @@ globalThis.debug = text => {
|
|
|
102
102
|
if (globalThis.DEBUG) console.log('\x1b[34m\x1b[1m%s', text, '\x1b[0m'); // bright blue
|
|
103
103
|
};
|
|
104
104
|
|
|
105
|
-
class LittlePubSub {
|
|
106
|
-
subscribers = {};
|
|
107
|
-
verbose;
|
|
108
|
-
constructor(verbose) {
|
|
109
|
-
this.verbose = verbose;
|
|
110
|
-
}
|
|
111
|
-
_handleContext(handler, context) {
|
|
112
|
-
if (typeof context === 'undefined') {
|
|
113
|
-
context = handler;
|
|
114
|
-
}
|
|
115
|
-
return context;
|
|
116
|
-
}
|
|
117
|
-
hasSubscribers(event) {
|
|
118
|
-
return this.subscribers[event] ? true : false;
|
|
119
|
-
}
|
|
120
|
-
subscribe(event, handler, context) {
|
|
121
|
-
if (!this.hasSubscribers(event))
|
|
122
|
-
this.subscribers[event] = { handlers: [], value: undefined };
|
|
123
|
-
context = this._handleContext(handler, context);
|
|
124
|
-
this.subscribers[event].handlers.push(handler.bind(context));
|
|
125
|
-
}
|
|
126
|
-
unsubscribe(event, handler, context) {
|
|
127
|
-
if (!this.hasSubscribers(event))
|
|
128
|
-
return;
|
|
129
|
-
context = this._handleContext(handler, context);
|
|
130
|
-
const index = this.subscribers[event].handlers.indexOf(handler.bind(context));
|
|
131
|
-
this.subscribers[event].handlers.splice(index);
|
|
132
|
-
if (this.subscribers[event].handlers.length === 0)
|
|
133
|
-
delete this.subscribers[event];
|
|
134
|
-
}
|
|
135
|
-
publish(event, value) {
|
|
136
|
-
// always set value even when having no subscribers
|
|
137
|
-
if (!this.hasSubscribers(event))
|
|
138
|
-
this.subscribers[event] = {
|
|
139
|
-
handlers: []
|
|
140
|
-
};
|
|
141
|
-
const oldValue = this.subscribers[event]?.value;
|
|
142
|
-
this.
|
|
143
|
-
|
|
144
|
-
for (const handler of this.subscribers[event].handlers) {
|
|
145
|
-
handler(value, oldValue);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
105
|
+
class LittlePubSub {
|
|
106
|
+
subscribers = {};
|
|
107
|
+
verbose;
|
|
108
|
+
constructor(verbose) {
|
|
109
|
+
this.verbose = verbose;
|
|
110
|
+
}
|
|
111
|
+
_handleContext(handler, context) {
|
|
112
|
+
if (typeof context === 'undefined') {
|
|
113
|
+
context = handler;
|
|
114
|
+
}
|
|
115
|
+
return context;
|
|
116
|
+
}
|
|
117
|
+
hasSubscribers(event) {
|
|
118
|
+
return this.subscribers[event] ? true : false;
|
|
119
|
+
}
|
|
120
|
+
subscribe(event, handler, context) {
|
|
121
|
+
if (!this.hasSubscribers(event))
|
|
122
|
+
this.subscribers[event] = { handlers: [], value: undefined };
|
|
123
|
+
context = this._handleContext(handler, context);
|
|
124
|
+
this.subscribers[event].handlers.push(handler.bind(context));
|
|
125
|
+
}
|
|
126
|
+
unsubscribe(event, handler, context) {
|
|
127
|
+
if (!this.hasSubscribers(event))
|
|
128
|
+
return;
|
|
129
|
+
context = this._handleContext(handler, context);
|
|
130
|
+
const index = this.subscribers[event].handlers.indexOf(handler.bind(context));
|
|
131
|
+
this.subscribers[event].handlers.splice(index);
|
|
132
|
+
if (this.subscribers[event].handlers.length === 0)
|
|
133
|
+
delete this.subscribers[event];
|
|
134
|
+
}
|
|
135
|
+
publish(event, value, verbose) {
|
|
136
|
+
// always set value even when having no subscribers
|
|
137
|
+
if (!this.hasSubscribers(event))
|
|
138
|
+
this.subscribers[event] = {
|
|
139
|
+
handlers: []
|
|
140
|
+
};
|
|
141
|
+
const oldValue = this.subscribers[event]?.value;
|
|
142
|
+
if (this.verbose || verbose || oldValue !== value) {
|
|
143
|
+
this.subscribers[event].value = value;
|
|
144
|
+
for (const handler of this.subscribers[event].handlers) {
|
|
145
|
+
handler(value, oldValue);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
publishVerbose(event, value) {
|
|
150
|
+
this.publish(event, value, true);
|
|
151
|
+
}
|
|
152
|
+
once(event) {
|
|
153
|
+
return new Promise((resolve) => {
|
|
154
|
+
const cb = (value) => {
|
|
155
|
+
resolve(value);
|
|
156
|
+
this.unsubscribe(event, cb);
|
|
157
|
+
};
|
|
158
|
+
this.subscribe(event, cb);
|
|
159
|
+
});
|
|
160
|
+
}
|
|
157
161
|
}
|
|
158
162
|
|
|
159
163
|
// base-x encoding / decoding
|
|
@@ -790,7 +794,7 @@ var _nodeResolve_empty$1 = /*#__PURE__*/Object.freeze({
|
|
|
790
794
|
default: _nodeResolve_empty
|
|
791
795
|
});
|
|
792
796
|
|
|
793
|
-
var require$$
|
|
797
|
+
var require$$3 = /*@__PURE__*/getAugmentedNamespace(_nodeResolve_empty$1);
|
|
794
798
|
|
|
795
799
|
(function (module) {
|
|
796
800
|
(function (module, exports) {
|
|
@@ -847,7 +851,7 @@ var require$$0$1 = /*@__PURE__*/getAugmentedNamespace(_nodeResolve_empty$1);
|
|
|
847
851
|
if (typeof window !== 'undefined' && typeof window.Buffer !== 'undefined') {
|
|
848
852
|
Buffer = window.Buffer;
|
|
849
853
|
} else {
|
|
850
|
-
Buffer = require$$
|
|
854
|
+
Buffer = require$$3.Buffer;
|
|
851
855
|
}
|
|
852
856
|
} catch (e) {
|
|
853
857
|
}
|
|
@@ -13557,7 +13561,7 @@ var bn = {exports: {}};
|
|
|
13557
13561
|
if (typeof window !== 'undefined' && typeof window.Buffer !== 'undefined') {
|
|
13558
13562
|
Buffer = window.Buffer;
|
|
13559
13563
|
} else {
|
|
13560
|
-
Buffer = require$$
|
|
13564
|
+
Buffer = require$$3.Buffer;
|
|
13561
13565
|
}
|
|
13562
13566
|
} catch (e) {
|
|
13563
13567
|
}
|
|
@@ -17201,7 +17205,7 @@ if (typeof self === 'object') {
|
|
|
17201
17205
|
} else {
|
|
17202
17206
|
// Node.js or Web worker with no crypto support
|
|
17203
17207
|
try {
|
|
17204
|
-
var crypto$1 = require$$
|
|
17208
|
+
var crypto$1 = require$$3;
|
|
17205
17209
|
if (typeof crypto$1.randomBytes !== 'function')
|
|
17206
17210
|
throw new Error('Not supported');
|
|
17207
17211
|
|
|
@@ -27178,7 +27182,7 @@ class Identity {
|
|
|
27178
27182
|
this.selectedAccount = new TextDecoder().decode(selected);
|
|
27179
27183
|
}
|
|
27180
27184
|
else {
|
|
27181
|
-
const importee = await import(/* webpackChunkName: "generate-account" */ './index-
|
|
27185
|
+
const importee = await import(/* webpackChunkName: "generate-account" */ './index-81687e93-18fab48d.js');
|
|
27182
27186
|
const { identity, accounts } = await importee.default(password, this.network);
|
|
27183
27187
|
await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
|
|
27184
27188
|
await globalThis.walletStore.put('version', String(1));
|
|
@@ -27369,7 +27373,7 @@ class Peernet {
|
|
|
27369
27373
|
this.root = options.root;
|
|
27370
27374
|
const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
|
|
27371
27375
|
// FolderMessageResponse
|
|
27372
|
-
} = await import(/* webpackChunkName: "messages" */ './messages-
|
|
27376
|
+
} = await import(/* webpackChunkName: "messages" */ './messages-cccb78db-116bfaa7.js');
|
|
27373
27377
|
/**
|
|
27374
27378
|
* proto Object containing protos
|
|
27375
27379
|
* @type {Object}
|
|
@@ -27463,238 +27467,7 @@ class Peernet {
|
|
|
27463
27467
|
if (this.#starting || this.#started)
|
|
27464
27468
|
return;
|
|
27465
27469
|
this.#starting = true;
|
|
27466
|
-
const importee =
|
|
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
|
-
}
|
|
27531
|
-
if (globalThis.navigator) {
|
|
27532
|
-
globalThis.addEventListener('beforeunload', async () => this.close());
|
|
27533
|
-
}
|
|
27534
|
-
else {
|
|
27535
|
-
process.on('SIGINT', async () => {
|
|
27536
|
-
process.stdin.resume();
|
|
27537
|
-
await this.close();
|
|
27538
|
-
process.exit();
|
|
27539
|
-
});
|
|
27540
|
-
}
|
|
27541
|
-
}
|
|
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, this.version));
|
|
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}`);
|
|
27618
|
-
return;
|
|
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, version) => {
|
|
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,
|
|
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
|
-
};
|
|
27470
|
+
const importee = await import('./client-f193279c-98f2aeaa.js');
|
|
27698
27471
|
/**
|
|
27699
27472
|
* @access public
|
|
27700
27473
|
* @type {PeernetClient}
|
|
@@ -27725,9 +27498,23 @@ class Peernet {
|
|
|
27725
27498
|
if (peer.connected) {
|
|
27726
27499
|
await peer.send(data, id);
|
|
27727
27500
|
this.bw.up += data.length;
|
|
27501
|
+
return id;
|
|
27502
|
+
}
|
|
27503
|
+
else {
|
|
27504
|
+
return new Promise((resolve, reject) => {
|
|
27505
|
+
const onError = (error) => {
|
|
27506
|
+
this.removePeer(peer);
|
|
27507
|
+
reject(error);
|
|
27508
|
+
};
|
|
27509
|
+
peer.once('error', onError);
|
|
27510
|
+
peer.once('connect', async () => {
|
|
27511
|
+
await peer.send(data, id);
|
|
27512
|
+
this.bw.up += data.length;
|
|
27513
|
+
peer.removeListener('error', onError);
|
|
27514
|
+
resolve(id);
|
|
27515
|
+
});
|
|
27516
|
+
});
|
|
27728
27517
|
}
|
|
27729
|
-
else
|
|
27730
|
-
this.removePeer(peer);
|
|
27731
27518
|
}
|
|
27732
27519
|
async handleDHT(peer, id, proto) {
|
|
27733
27520
|
let { hash, store } = proto.decoded;
|
|
@@ -28213,4 +28000,4 @@ class Node {
|
|
|
28213
28000
|
}
|
|
28214
28001
|
}
|
|
28215
28002
|
|
|
28216
|
-
export { FormatInterface as F, MultiWallet as M, Node as N, base58$1 as b, encrypt as e };
|
|
28003
|
+
export { FormatInterface as F, LittlePubSub as L, MultiWallet as M, Node as N, base58$1 as b, commonjsGlobal as c, encrypt as e, getDefaultExportFromCjs as g, inherits_browserExports as i, require$$3 as r };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { N as default } from './node-browser-
|
|
1
|
+
export { N as default } from './node-browser-c75c189a.js';
|
|
2
2
|
import './index-c3bd3090.js';
|
|
@@ -16,9 +16,11 @@ const run = async (blocks) => {
|
|
|
16
16
|
// todo: tx worker or nah?
|
|
17
17
|
await block.encode();
|
|
18
18
|
const size = block.encoded.length || block.encoded.byteLength;
|
|
19
|
-
|
|
19
|
+
const hash = await block.hash();
|
|
20
|
+
const index = block.decoded.index;
|
|
21
|
+
console.log(`loaded block: ${hash} @${index} ${formatBytes(size)}`);
|
|
20
22
|
// todo we don't want this, need shared state
|
|
21
|
-
resolve(block.decoded);
|
|
23
|
+
resolve({ ...block.decoded, blockInfo: { hash, size, index } });
|
|
22
24
|
})
|
|
23
25
|
)
|
|
24
26
|
);
|
|
@@ -112,27 +112,47 @@ const _init = async ({ contracts, blocks, peerid }) => {
|
|
|
112
112
|
pre = './';
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
|
|
115
|
+
let _worker = await new EasyWorker(pre + './block-worker.js', {
|
|
116
116
|
serialization: 'advanced',
|
|
117
117
|
type: 'module'
|
|
118
118
|
});
|
|
119
|
-
blocks = await _worker.once(
|
|
120
|
-
|
|
119
|
+
blocks = await _worker.once(blocks);
|
|
120
|
+
console.log({ blocks });
|
|
121
|
+
_worker = null;
|
|
121
122
|
// blocks = unique(globalThis.blocks ? globalThis : [], blocks)
|
|
122
123
|
// for (let i = 0; i < blocks.length; i++) {
|
|
123
124
|
|
|
124
125
|
// }
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
126
|
+
for (const block of blocks) {
|
|
127
|
+
try {
|
|
128
|
+
await Promise.all(
|
|
129
|
+
block.transactions.map(async (message) => {
|
|
130
|
+
if (!block.loaded) {
|
|
131
|
+
const { from, to, method, params } = message;
|
|
132
|
+
globalThis.msg = createMessage(from);
|
|
133
|
+
|
|
134
|
+
try {
|
|
135
|
+
await execute(to, method, params);
|
|
136
|
+
} catch (error) {
|
|
137
|
+
throw error
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
})
|
|
141
|
+
);
|
|
142
|
+
block.loaded = true;
|
|
143
|
+
worker.postMessage({
|
|
144
|
+
type: 'debug',
|
|
145
|
+
message: `loaded transactions for block: ${block.blockInfo.hash} @${block.blockInfo.index} ${formatBytes(
|
|
146
|
+
block.blockInfo.size
|
|
147
|
+
)}`
|
|
148
|
+
});
|
|
149
|
+
} catch (error) {
|
|
150
|
+
worker.postMessage({
|
|
151
|
+
type: 'error',
|
|
152
|
+
message: error.message
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
136
156
|
|
|
137
157
|
if (blocks.length > 0) {
|
|
138
158
|
lastBlock = blocks[blocks.length - 1];
|
package/exports/chain.js
CHANGED
|
@@ -201,7 +201,8 @@ class Transaction extends Protocol {
|
|
|
201
201
|
await globalThis.transactionPoolStore.put(hash, message.encoded);
|
|
202
202
|
// debug(`Added ${hash} to the transaction pool`)
|
|
203
203
|
peernet.publish('add-transaction', message.encoded);
|
|
204
|
-
|
|
204
|
+
const fee = await calculateFee(message.decoded);
|
|
205
|
+
return { hash, data, fee, wait, message };
|
|
205
206
|
}
|
|
206
207
|
catch (error) {
|
|
207
208
|
console.log('remo');
|
|
@@ -304,8 +305,11 @@ class Machine {
|
|
|
304
305
|
break;
|
|
305
306
|
}
|
|
306
307
|
case 'debug': {
|
|
307
|
-
|
|
308
|
-
|
|
308
|
+
globalThis.debug(data.message);
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
case 'error': {
|
|
312
|
+
console.error(data.message);
|
|
309
313
|
break;
|
|
310
314
|
}
|
|
311
315
|
case 'machine-ready': {
|
|
@@ -726,7 +730,7 @@ class State extends Contract {
|
|
|
726
730
|
try {
|
|
727
731
|
await this.resolveBlocks();
|
|
728
732
|
this.#machine = await new Machine(this.#blocks);
|
|
729
|
-
await this.#loadBlocks(this.#blocks)
|
|
733
|
+
// await this.#loadBlocks(this.#blocks)
|
|
730
734
|
}
|
|
731
735
|
catch (error) {
|
|
732
736
|
if (isResolveError(error)) {
|
|
@@ -1165,6 +1169,13 @@ class Chain extends VersionControl {
|
|
|
1165
1169
|
this.#participants = [];
|
|
1166
1170
|
this.#participating = false;
|
|
1167
1171
|
this.#jail = [];
|
|
1172
|
+
this.#addTransaction = async (message) => {
|
|
1173
|
+
const transaction = new TransactionMessage(message);
|
|
1174
|
+
const hash = await transaction.hash();
|
|
1175
|
+
if (await transactionPool.has(hash))
|
|
1176
|
+
await transactionPool.delete(hash);
|
|
1177
|
+
console.log(transaction);
|
|
1178
|
+
};
|
|
1168
1179
|
// @ts-ignore
|
|
1169
1180
|
return this.#init();
|
|
1170
1181
|
}
|
|
@@ -1268,9 +1279,7 @@ class Chain extends VersionControl {
|
|
|
1268
1279
|
}, validatorInfo.timeout);
|
|
1269
1280
|
this.#jail.push(validatorInfo.address);
|
|
1270
1281
|
}
|
|
1271
|
-
#addTransaction
|
|
1272
|
-
console.log({ message });
|
|
1273
|
-
}
|
|
1282
|
+
#addTransaction;
|
|
1274
1283
|
async #prepareRequest(request) {
|
|
1275
1284
|
let node = await new globalThis.peernet.protos['peernet-request']({ request });
|
|
1276
1285
|
return globalThis.peernet.prepareMessage(node);
|
|
@@ -1295,7 +1304,6 @@ class Chain extends VersionControl {
|
|
|
1295
1304
|
}
|
|
1296
1305
|
async #peerConnected(peerId) {
|
|
1297
1306
|
const peer = peernet.getConnection(peerId);
|
|
1298
|
-
console.log({ peer });
|
|
1299
1307
|
// todo handle version changes
|
|
1300
1308
|
// for now just do nothing if version doesn't match
|
|
1301
1309
|
console.log(`${peer.version}, ${this.version}`);
|
|
@@ -16,9 +16,11 @@ const run = async (blocks) => {
|
|
|
16
16
|
// todo: tx worker or nah?
|
|
17
17
|
await block.encode();
|
|
18
18
|
const size = block.encoded.length || block.encoded.byteLength;
|
|
19
|
-
|
|
19
|
+
const hash = await block.hash();
|
|
20
|
+
const index = block.decoded.index;
|
|
21
|
+
console.log(`loaded block: ${hash} @${index} ${formatBytes(size)}`);
|
|
20
22
|
// todo we don't want this, need shared state
|
|
21
|
-
resolve(block.decoded);
|
|
23
|
+
resolve({ ...block.decoded, blockInfo: { hash, size, index } });
|
|
22
24
|
})
|
|
23
25
|
)
|
|
24
26
|
);
|
|
@@ -112,27 +112,47 @@ const _init = async ({ contracts, blocks, peerid }) => {
|
|
|
112
112
|
pre = './';
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
|
|
115
|
+
let _worker = await new EasyWorker(pre + 'block-worker.js', {
|
|
116
116
|
serialization: 'advanced',
|
|
117
117
|
type: 'module'
|
|
118
118
|
});
|
|
119
|
-
blocks = await _worker.once(
|
|
120
|
-
|
|
119
|
+
blocks = await _worker.once(blocks);
|
|
120
|
+
console.log({ blocks });
|
|
121
|
+
_worker = null;
|
|
121
122
|
// blocks = unique(globalThis.blocks ? globalThis : [], blocks)
|
|
122
123
|
// for (let i = 0; i < blocks.length; i++) {
|
|
123
124
|
|
|
124
125
|
// }
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
126
|
+
for (const block of blocks) {
|
|
127
|
+
try {
|
|
128
|
+
await Promise.all(
|
|
129
|
+
block.transactions.map(async (message) => {
|
|
130
|
+
if (!block.loaded) {
|
|
131
|
+
const { from, to, method, params } = message;
|
|
132
|
+
globalThis.msg = createMessage(from);
|
|
133
|
+
|
|
134
|
+
try {
|
|
135
|
+
await execute(to, method, params);
|
|
136
|
+
} catch (error) {
|
|
137
|
+
throw error
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
})
|
|
141
|
+
);
|
|
142
|
+
block.loaded = true;
|
|
143
|
+
worker.postMessage({
|
|
144
|
+
type: 'debug',
|
|
145
|
+
message: `loaded transactions for block: ${block.blockInfo.hash} @${block.blockInfo.index} ${formatBytes(
|
|
146
|
+
block.blockInfo.size
|
|
147
|
+
)}`
|
|
148
|
+
});
|
|
149
|
+
} catch (error) {
|
|
150
|
+
worker.postMessage({
|
|
151
|
+
type: 'error',
|
|
152
|
+
message: error.message
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
136
156
|
|
|
137
157
|
if (blocks.length > 0) {
|
|
138
158
|
lastBlock = blocks[blocks.length - 1];
|