@leofcoin/chain 1.7.6 → 1.7.8
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-Ei0BXMlu-CUWm-sMO.js → browser-P2HFBJsB-D1PEhFyZ.js} +1 -1
- package/exports/browser/chain.js +47 -28
- package/exports/browser/{client-A009z8av-D7GxR0o2.js → client-5mPwJbpC-DcusxC0q.js} +3 -3
- package/exports/browser/{index-YQrIDBUQ-COx7Reww.js → index-00QxgDks-D31Jchhm.js} +422 -408
- package/exports/browser/{index-G74WLzL7-D5kDRHRC.js → index-fC0k-d_O-DQ-T8zrg.js} +1 -1
- package/exports/browser/{messages-lWRTai7t-C3uUT_S7.js → messages-rdtq6jgH-Cpp_3cR4.js} +1 -1
- package/exports/browser/{node-browser-Bjb6j0bF.js → node-browser-By4Fowr9.js} +4 -4
- package/exports/browser/node-browser.js +1 -1
- package/exports/chain.js +47 -28
- package/exports/state.d.ts +4 -0
- package/package.json +1 -1
package/exports/browser/chain.js
CHANGED
|
@@ -4793,38 +4793,46 @@ class State extends Contract {
|
|
|
4793
4793
|
let poolTransactionKeys = await globalThis.transactionPoolStore.keys();
|
|
4794
4794
|
for (const block of blocks) {
|
|
4795
4795
|
if (block && !block.loaded) {
|
|
4796
|
-
|
|
4797
|
-
this.#
|
|
4798
|
-
|
|
4799
|
-
|
|
4800
|
-
|
|
4801
|
-
|
|
4802
|
-
|
|
4803
|
-
|
|
4804
|
-
|
|
4805
|
-
|
|
4806
|
-
|
|
4807
|
-
|
|
4796
|
+
try {
|
|
4797
|
+
let transactions = await this.#loadBlockTransactions([...block.transactions] || []);
|
|
4798
|
+
const lastTransactions = await this.#getLastTransactions();
|
|
4799
|
+
let priority = [];
|
|
4800
|
+
for (const transaction of transactions) {
|
|
4801
|
+
const hash = await transaction.hash();
|
|
4802
|
+
if (lastTransactions.includes(hash)) {
|
|
4803
|
+
console.log('removing invalid block');
|
|
4804
|
+
await globalThis.blockStore.delete(await (await new BlockMessage(block)).hash());
|
|
4805
|
+
blocks.splice(block.index - 1, 1);
|
|
4806
|
+
return this.#loadBlocks(blocks);
|
|
4807
|
+
}
|
|
4808
|
+
if (transaction.decoded.priority)
|
|
4809
|
+
priority.push(transaction);
|
|
4810
|
+
if (poolTransactionKeys.includes(hash))
|
|
4811
|
+
await globalThis.transactionPoolStore.delete(hash);
|
|
4808
4812
|
}
|
|
4809
|
-
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
|
|
4813
|
+
// prority blocks execution from the rest so result in higher fees.
|
|
4814
|
+
if (priority.length > 0) {
|
|
4815
|
+
priority = priority.sort((a, b) => a.nonce - b.nonce);
|
|
4816
|
+
for (const transaction of priority) {
|
|
4817
|
+
await this.#_executeTransaction(transaction);
|
|
4818
|
+
}
|
|
4819
|
+
}
|
|
4820
|
+
transactions = transactions.filter((transaction) => !transaction.decoded.priority);
|
|
4821
|
+
await Promise.all(transactions.map((transaction) => this.#_executeTransaction(transaction)));
|
|
4822
|
+
this.#blocks[block.index].loaded = true;
|
|
4823
|
+
if (block.index === 0)
|
|
4824
|
+
this.#loaded = true;
|
|
4825
|
+
await this.#machine.addLoadedBlock(block);
|
|
4826
|
+
// @ts-ignore
|
|
4827
|
+
debug$1(`loaded block: ${block.hash} @${block.index}`);
|
|
4828
|
+
globalThis.pubsub.publish('block-loaded', { ...block });
|
|
4813
4829
|
}
|
|
4814
|
-
|
|
4815
|
-
|
|
4816
|
-
|
|
4817
|
-
|
|
4818
|
-
await this.#_executeTransaction(transaction);
|
|
4830
|
+
catch (error) {
|
|
4831
|
+
console.error(error);
|
|
4832
|
+
for (const transaction of block.transactions) {
|
|
4833
|
+
this.wantList.push(transaction);
|
|
4819
4834
|
}
|
|
4820
4835
|
}
|
|
4821
|
-
transactions = transactions.filter((transaction) => !transaction.decoded.priority);
|
|
4822
|
-
await Promise.all(transactions.map((transaction) => this.#_executeTransaction(transaction)));
|
|
4823
|
-
this.#blocks[block.index].loaded = true;
|
|
4824
|
-
await this.#machine.addLoadedBlock(block);
|
|
4825
|
-
// @ts-ignore
|
|
4826
|
-
debug$1(`loaded block: ${block.hash} @${block.index}`);
|
|
4827
|
-
globalThis.pubsub.publish('block-loaded', { ...block });
|
|
4828
4836
|
}
|
|
4829
4837
|
}
|
|
4830
4838
|
this.#chainState = 'loaded';
|
|
@@ -5097,6 +5105,17 @@ class Chain extends VersionControl {
|
|
|
5097
5105
|
else if (!this.knownBlocks)
|
|
5098
5106
|
this.knownBlocks = await this.#makeRequest(peer, 'knownBlocks');
|
|
5099
5107
|
}
|
|
5108
|
+
if (this.wantList.length > 0) {
|
|
5109
|
+
const promises = await Promise.allSettled(this.wantList.map((hash) => peernet.get(hash)));
|
|
5110
|
+
for (let i = 0; i < promises.length; i++) {
|
|
5111
|
+
const result = promises[i];
|
|
5112
|
+
if (result.status === 'fulfilled')
|
|
5113
|
+
this.wantList.splice(i, 1);
|
|
5114
|
+
}
|
|
5115
|
+
// todo trigger load instead?
|
|
5116
|
+
if (this.wantList.length === 0)
|
|
5117
|
+
await this.triggerSync();
|
|
5118
|
+
}
|
|
5100
5119
|
setTimeout(async () => {
|
|
5101
5120
|
const peerTransactionPool = (higherThenCurrentLocal && (await this.getPeerTransactionPool(peer))) || [];
|
|
5102
5121
|
if (this.#participating && peerTransactionPool.length > 0)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { L as LittlePubSub } from './node-browser-
|
|
1
|
+
import { L as LittlePubSub } from './node-browser-By4Fowr9.js';
|
|
2
2
|
import './index-XTbRdu6H.js';
|
|
3
3
|
|
|
4
4
|
class Api {
|
|
@@ -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-
|
|
209
|
+
globalThis.WebSocket = (await import('./browser-P2HFBJsB-D1PEhFyZ.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,7 +280,7 @@ const iceServers = [
|
|
|
280
280
|
credential: 'openrelayproject'
|
|
281
281
|
}
|
|
282
282
|
];
|
|
283
|
-
const SimplePeer = (await import('./index-
|
|
283
|
+
const SimplePeer = (await import('./index-00QxgDks-D31Jchhm.js').then(function (n) { return n.i; })).default;
|
|
284
284
|
class Peer extends SimplePeer {
|
|
285
285
|
peerId;
|
|
286
286
|
channelName;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as inherits_browserExports, c as commonjsGlobal, g as getDefaultExportFromCjs, r as require$$3 } from './node-browser-
|
|
1
|
+
import { i as inherits_browserExports, c as commonjsGlobal, g as getDefaultExportFromCjs, r as require$$3 } from './node-browser-By4Fowr9.js';
|
|
2
2
|
import './index-XTbRdu6H.js';
|
|
3
3
|
|
|
4
4
|
var browser$2 = {exports: {}};
|
|
@@ -3215,483 +3215,497 @@ var readableBrowser = {exports: {}};
|
|
|
3215
3215
|
|
|
3216
3216
|
var events = {exports: {}};
|
|
3217
3217
|
|
|
3218
|
-
var
|
|
3219
|
-
var ReflectApply = R && typeof R.apply === 'function'
|
|
3220
|
-
? R.apply
|
|
3221
|
-
: function ReflectApply(target, receiver, args) {
|
|
3222
|
-
return Function.prototype.apply.call(target, receiver, args);
|
|
3223
|
-
};
|
|
3218
|
+
var hasRequiredEvents;
|
|
3224
3219
|
|
|
3225
|
-
|
|
3226
|
-
if (
|
|
3227
|
-
|
|
3228
|
-
} else if (Object.getOwnPropertySymbols) {
|
|
3229
|
-
ReflectOwnKeys = function ReflectOwnKeys(target) {
|
|
3230
|
-
return Object.getOwnPropertyNames(target)
|
|
3231
|
-
.concat(Object.getOwnPropertySymbols(target));
|
|
3232
|
-
};
|
|
3233
|
-
} else {
|
|
3234
|
-
ReflectOwnKeys = function ReflectOwnKeys(target) {
|
|
3235
|
-
return Object.getOwnPropertyNames(target);
|
|
3236
|
-
};
|
|
3237
|
-
}
|
|
3220
|
+
function requireEvents () {
|
|
3221
|
+
if (hasRequiredEvents) return events.exports;
|
|
3222
|
+
hasRequiredEvents = 1;
|
|
3238
3223
|
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3224
|
+
var R = typeof Reflect === 'object' ? Reflect : null;
|
|
3225
|
+
var ReflectApply = R && typeof R.apply === 'function'
|
|
3226
|
+
? R.apply
|
|
3227
|
+
: function ReflectApply(target, receiver, args) {
|
|
3228
|
+
return Function.prototype.apply.call(target, receiver, args);
|
|
3229
|
+
};
|
|
3242
3230
|
|
|
3243
|
-
var
|
|
3244
|
-
|
|
3245
|
-
|
|
3231
|
+
var ReflectOwnKeys;
|
|
3232
|
+
if (R && typeof R.ownKeys === 'function') {
|
|
3233
|
+
ReflectOwnKeys = R.ownKeys;
|
|
3234
|
+
} else if (Object.getOwnPropertySymbols) {
|
|
3235
|
+
ReflectOwnKeys = function ReflectOwnKeys(target) {
|
|
3236
|
+
return Object.getOwnPropertyNames(target)
|
|
3237
|
+
.concat(Object.getOwnPropertySymbols(target));
|
|
3238
|
+
};
|
|
3239
|
+
} else {
|
|
3240
|
+
ReflectOwnKeys = function ReflectOwnKeys(target) {
|
|
3241
|
+
return Object.getOwnPropertyNames(target);
|
|
3242
|
+
};
|
|
3243
|
+
}
|
|
3246
3244
|
|
|
3247
|
-
function
|
|
3248
|
-
|
|
3249
|
-
}
|
|
3250
|
-
events.exports = EventEmitter;
|
|
3251
|
-
events.exports.once = once$2;
|
|
3245
|
+
function ProcessEmitWarning(warning) {
|
|
3246
|
+
if (console && console.warn) console.warn(warning);
|
|
3247
|
+
}
|
|
3252
3248
|
|
|
3253
|
-
|
|
3254
|
-
|
|
3249
|
+
var NumberIsNaN = Number.isNaN || function NumberIsNaN(value) {
|
|
3250
|
+
return value !== value;
|
|
3251
|
+
};
|
|
3255
3252
|
|
|
3256
|
-
EventEmitter
|
|
3257
|
-
EventEmitter.
|
|
3258
|
-
|
|
3253
|
+
function EventEmitter() {
|
|
3254
|
+
EventEmitter.init.call(this);
|
|
3255
|
+
}
|
|
3256
|
+
events.exports = EventEmitter;
|
|
3257
|
+
events.exports.once = once;
|
|
3259
3258
|
|
|
3260
|
-
//
|
|
3261
|
-
|
|
3262
|
-
var defaultMaxListeners = 10;
|
|
3259
|
+
// Backwards-compat with node 0.10.x
|
|
3260
|
+
EventEmitter.EventEmitter = EventEmitter;
|
|
3263
3261
|
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
}
|
|
3268
|
-
}
|
|
3262
|
+
EventEmitter.prototype._events = undefined;
|
|
3263
|
+
EventEmitter.prototype._eventsCount = 0;
|
|
3264
|
+
EventEmitter.prototype._maxListeners = undefined;
|
|
3269
3265
|
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
return defaultMaxListeners;
|
|
3274
|
-
},
|
|
3275
|
-
set: function(arg) {
|
|
3276
|
-
if (typeof arg !== 'number' || arg < 0 || NumberIsNaN(arg)) {
|
|
3277
|
-
throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + '.');
|
|
3278
|
-
}
|
|
3279
|
-
defaultMaxListeners = arg;
|
|
3280
|
-
}
|
|
3281
|
-
});
|
|
3266
|
+
// By default EventEmitters will print a warning if more than 10 listeners are
|
|
3267
|
+
// added to it. This is a useful default which helps finding memory leaks.
|
|
3268
|
+
var defaultMaxListeners = 10;
|
|
3282
3269
|
|
|
3283
|
-
|
|
3270
|
+
function checkListener(listener) {
|
|
3271
|
+
if (typeof listener !== 'function') {
|
|
3272
|
+
throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener);
|
|
3273
|
+
}
|
|
3274
|
+
}
|
|
3284
3275
|
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3276
|
+
Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
|
|
3277
|
+
enumerable: true,
|
|
3278
|
+
get: function() {
|
|
3279
|
+
return defaultMaxListeners;
|
|
3280
|
+
},
|
|
3281
|
+
set: function(arg) {
|
|
3282
|
+
if (typeof arg !== 'number' || arg < 0 || NumberIsNaN(arg)) {
|
|
3283
|
+
throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + '.');
|
|
3284
|
+
}
|
|
3285
|
+
defaultMaxListeners = arg;
|
|
3286
|
+
}
|
|
3287
|
+
});
|
|
3290
3288
|
|
|
3291
|
-
|
|
3292
|
-
};
|
|
3289
|
+
EventEmitter.init = function() {
|
|
3293
3290
|
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
}
|
|
3300
|
-
this._maxListeners = n;
|
|
3301
|
-
return this;
|
|
3302
|
-
};
|
|
3291
|
+
if (this._events === undefined ||
|
|
3292
|
+
this._events === Object.getPrototypeOf(this)._events) {
|
|
3293
|
+
this._events = Object.create(null);
|
|
3294
|
+
this._eventsCount = 0;
|
|
3295
|
+
}
|
|
3303
3296
|
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
return EventEmitter.defaultMaxListeners;
|
|
3307
|
-
return that._maxListeners;
|
|
3308
|
-
}
|
|
3297
|
+
this._maxListeners = this._maxListeners || undefined;
|
|
3298
|
+
};
|
|
3309
3299
|
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3300
|
+
// Obviously not all Emitters should be limited to 10. This function allows
|
|
3301
|
+
// that to be increased. Set to zero for unlimited.
|
|
3302
|
+
EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
|
|
3303
|
+
if (typeof n !== 'number' || n < 0 || NumberIsNaN(n)) {
|
|
3304
|
+
throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + '.');
|
|
3305
|
+
}
|
|
3306
|
+
this._maxListeners = n;
|
|
3307
|
+
return this;
|
|
3308
|
+
};
|
|
3313
3309
|
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3310
|
+
function _getMaxListeners(that) {
|
|
3311
|
+
if (that._maxListeners === undefined)
|
|
3312
|
+
return EventEmitter.defaultMaxListeners;
|
|
3313
|
+
return that._maxListeners;
|
|
3314
|
+
}
|
|
3318
3315
|
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
else if (!doError)
|
|
3323
|
-
return false;
|
|
3316
|
+
EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
|
|
3317
|
+
return _getMaxListeners(this);
|
|
3318
|
+
};
|
|
3324
3319
|
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
er = args[0];
|
|
3330
|
-
if (er instanceof Error) {
|
|
3331
|
-
// Note: The comments on the `throw` lines are intentional, they show
|
|
3332
|
-
// up in Node's output if this results in an unhandled exception.
|
|
3333
|
-
throw er; // Unhandled 'error' event
|
|
3334
|
-
}
|
|
3335
|
-
// At least give some kind of context to the user
|
|
3336
|
-
var err = new Error('Unhandled error.' + (er ? ' (' + er.message + ')' : ''));
|
|
3337
|
-
err.context = er;
|
|
3338
|
-
throw err; // Unhandled 'error' event
|
|
3339
|
-
}
|
|
3320
|
+
EventEmitter.prototype.emit = function emit(type) {
|
|
3321
|
+
var args = [];
|
|
3322
|
+
for (var i = 1; i < arguments.length; i++) args.push(arguments[i]);
|
|
3323
|
+
var doError = (type === 'error');
|
|
3340
3324
|
|
|
3341
|
-
|
|
3325
|
+
var events = this._events;
|
|
3326
|
+
if (events !== undefined)
|
|
3327
|
+
doError = (doError && events.error === undefined);
|
|
3328
|
+
else if (!doError)
|
|
3329
|
+
return false;
|
|
3342
3330
|
|
|
3343
|
-
|
|
3344
|
-
|
|
3331
|
+
// If there is no 'error' event listener then throw.
|
|
3332
|
+
if (doError) {
|
|
3333
|
+
var er;
|
|
3334
|
+
if (args.length > 0)
|
|
3335
|
+
er = args[0];
|
|
3336
|
+
if (er instanceof Error) {
|
|
3337
|
+
// Note: The comments on the `throw` lines are intentional, they show
|
|
3338
|
+
// up in Node's output if this results in an unhandled exception.
|
|
3339
|
+
throw er; // Unhandled 'error' event
|
|
3340
|
+
}
|
|
3341
|
+
// At least give some kind of context to the user
|
|
3342
|
+
var err = new Error('Unhandled error.' + (er ? ' (' + er.message + ')' : ''));
|
|
3343
|
+
err.context = er;
|
|
3344
|
+
throw err; // Unhandled 'error' event
|
|
3345
|
+
}
|
|
3345
3346
|
|
|
3346
|
-
|
|
3347
|
-
ReflectApply(handler, this, args);
|
|
3348
|
-
} else {
|
|
3349
|
-
var len = handler.length;
|
|
3350
|
-
var listeners = arrayClone(handler, len);
|
|
3351
|
-
for (var i = 0; i < len; ++i)
|
|
3352
|
-
ReflectApply(listeners[i], this, args);
|
|
3353
|
-
}
|
|
3347
|
+
var handler = events[type];
|
|
3354
3348
|
|
|
3355
|
-
|
|
3356
|
-
|
|
3349
|
+
if (handler === undefined)
|
|
3350
|
+
return false;
|
|
3357
3351
|
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3352
|
+
if (typeof handler === 'function') {
|
|
3353
|
+
ReflectApply(handler, this, args);
|
|
3354
|
+
} else {
|
|
3355
|
+
var len = handler.length;
|
|
3356
|
+
var listeners = arrayClone(handler, len);
|
|
3357
|
+
for (var i = 0; i < len; ++i)
|
|
3358
|
+
ReflectApply(listeners[i], this, args);
|
|
3359
|
+
}
|
|
3362
3360
|
|
|
3363
|
-
|
|
3361
|
+
return true;
|
|
3362
|
+
};
|
|
3364
3363
|
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
} else {
|
|
3370
|
-
// To avoid recursion in the case that type === "newListener"! Before
|
|
3371
|
-
// adding it to the listeners, first emit "newListener".
|
|
3372
|
-
if (events.newListener !== undefined) {
|
|
3373
|
-
target.emit('newListener', type,
|
|
3374
|
-
listener.listener ? listener.listener : listener);
|
|
3375
|
-
|
|
3376
|
-
// Re-assign `events` because a newListener handler could have caused the
|
|
3377
|
-
// this._events to be assigned to a new object
|
|
3378
|
-
events = target._events;
|
|
3379
|
-
}
|
|
3380
|
-
existing = events[type];
|
|
3381
|
-
}
|
|
3364
|
+
function _addListener(target, type, listener, prepend) {
|
|
3365
|
+
var m;
|
|
3366
|
+
var events;
|
|
3367
|
+
var existing;
|
|
3382
3368
|
|
|
3383
|
-
|
|
3384
|
-
// Optimize the case of one listener. Don't need the extra array object.
|
|
3385
|
-
existing = events[type] = listener;
|
|
3386
|
-
++target._eventsCount;
|
|
3387
|
-
} else {
|
|
3388
|
-
if (typeof existing === 'function') {
|
|
3389
|
-
// Adding the second element, need to change to array.
|
|
3390
|
-
existing = events[type] =
|
|
3391
|
-
prepend ? [listener, existing] : [existing, listener];
|
|
3392
|
-
// If we've already got an array, just append.
|
|
3393
|
-
} else if (prepend) {
|
|
3394
|
-
existing.unshift(listener);
|
|
3395
|
-
} else {
|
|
3396
|
-
existing.push(listener);
|
|
3397
|
-
}
|
|
3369
|
+
checkListener(listener);
|
|
3398
3370
|
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3371
|
+
events = target._events;
|
|
3372
|
+
if (events === undefined) {
|
|
3373
|
+
events = target._events = Object.create(null);
|
|
3374
|
+
target._eventsCount = 0;
|
|
3375
|
+
} else {
|
|
3376
|
+
// To avoid recursion in the case that type === "newListener"! Before
|
|
3377
|
+
// adding it to the listeners, first emit "newListener".
|
|
3378
|
+
if (events.newListener !== undefined) {
|
|
3379
|
+
target.emit('newListener', type,
|
|
3380
|
+
listener.listener ? listener.listener : listener);
|
|
3381
|
+
|
|
3382
|
+
// Re-assign `events` because a newListener handler could have caused the
|
|
3383
|
+
// this._events to be assigned to a new object
|
|
3384
|
+
events = target._events;
|
|
3385
|
+
}
|
|
3386
|
+
existing = events[type];
|
|
3387
|
+
}
|
|
3416
3388
|
|
|
3417
|
-
|
|
3418
|
-
|
|
3389
|
+
if (existing === undefined) {
|
|
3390
|
+
// Optimize the case of one listener. Don't need the extra array object.
|
|
3391
|
+
existing = events[type] = listener;
|
|
3392
|
+
++target._eventsCount;
|
|
3393
|
+
} else {
|
|
3394
|
+
if (typeof existing === 'function') {
|
|
3395
|
+
// Adding the second element, need to change to array.
|
|
3396
|
+
existing = events[type] =
|
|
3397
|
+
prepend ? [listener, existing] : [existing, listener];
|
|
3398
|
+
// If we've already got an array, just append.
|
|
3399
|
+
} else if (prepend) {
|
|
3400
|
+
existing.unshift(listener);
|
|
3401
|
+
} else {
|
|
3402
|
+
existing.push(listener);
|
|
3403
|
+
}
|
|
3419
3404
|
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3405
|
+
// Check for listener leak
|
|
3406
|
+
m = _getMaxListeners(target);
|
|
3407
|
+
if (m > 0 && existing.length > m && !existing.warned) {
|
|
3408
|
+
existing.warned = true;
|
|
3409
|
+
// No error code for this since it is a Warning
|
|
3410
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
3411
|
+
var w = new Error('Possible EventEmitter memory leak detected. ' +
|
|
3412
|
+
existing.length + ' ' + String(type) + ' listeners ' +
|
|
3413
|
+
'added. Use emitter.setMaxListeners() to ' +
|
|
3414
|
+
'increase limit');
|
|
3415
|
+
w.name = 'MaxListenersExceededWarning';
|
|
3416
|
+
w.emitter = target;
|
|
3417
|
+
w.type = type;
|
|
3418
|
+
w.count = existing.length;
|
|
3419
|
+
ProcessEmitWarning(w);
|
|
3420
|
+
}
|
|
3421
|
+
}
|
|
3423
3422
|
|
|
3424
|
-
|
|
3423
|
+
return target;
|
|
3424
|
+
}
|
|
3425
3425
|
|
|
3426
|
-
EventEmitter.prototype.
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
};
|
|
3426
|
+
EventEmitter.prototype.addListener = function addListener(type, listener) {
|
|
3427
|
+
return _addListener(this, type, listener, false);
|
|
3428
|
+
};
|
|
3430
3429
|
|
|
3431
|
-
|
|
3432
|
-
if (!this.fired) {
|
|
3433
|
-
this.target.removeListener(this.type, this.wrapFn);
|
|
3434
|
-
this.fired = true;
|
|
3435
|
-
if (arguments.length === 0)
|
|
3436
|
-
return this.listener.call(this.target);
|
|
3437
|
-
return this.listener.apply(this.target, arguments);
|
|
3438
|
-
}
|
|
3439
|
-
}
|
|
3430
|
+
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
|
|
3440
3431
|
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
state.wrapFn = wrapped;
|
|
3446
|
-
return wrapped;
|
|
3447
|
-
}
|
|
3432
|
+
EventEmitter.prototype.prependListener =
|
|
3433
|
+
function prependListener(type, listener) {
|
|
3434
|
+
return _addListener(this, type, listener, true);
|
|
3435
|
+
};
|
|
3448
3436
|
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3437
|
+
function onceWrapper() {
|
|
3438
|
+
if (!this.fired) {
|
|
3439
|
+
this.target.removeListener(this.type, this.wrapFn);
|
|
3440
|
+
this.fired = true;
|
|
3441
|
+
if (arguments.length === 0)
|
|
3442
|
+
return this.listener.call(this.target);
|
|
3443
|
+
return this.listener.apply(this.target, arguments);
|
|
3444
|
+
}
|
|
3445
|
+
}
|
|
3454
3446
|
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3447
|
+
function _onceWrap(target, type, listener) {
|
|
3448
|
+
var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };
|
|
3449
|
+
var wrapped = onceWrapper.bind(state);
|
|
3450
|
+
wrapped.listener = listener;
|
|
3451
|
+
state.wrapFn = wrapped;
|
|
3452
|
+
return wrapped;
|
|
3453
|
+
}
|
|
3461
3454
|
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3455
|
+
EventEmitter.prototype.once = function once(type, listener) {
|
|
3456
|
+
checkListener(listener);
|
|
3457
|
+
this.on(type, _onceWrap(this, type, listener));
|
|
3458
|
+
return this;
|
|
3459
|
+
};
|
|
3466
3460
|
|
|
3467
|
-
|
|
3461
|
+
EventEmitter.prototype.prependOnceListener =
|
|
3462
|
+
function prependOnceListener(type, listener) {
|
|
3463
|
+
checkListener(listener);
|
|
3464
|
+
this.prependListener(type, _onceWrap(this, type, listener));
|
|
3465
|
+
return this;
|
|
3466
|
+
};
|
|
3468
3467
|
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3468
|
+
// Emits a 'removeListener' event if and only if the listener was removed.
|
|
3469
|
+
EventEmitter.prototype.removeListener =
|
|
3470
|
+
function removeListener(type, listener) {
|
|
3471
|
+
var list, events, position, i, originalListener;
|
|
3472
3472
|
|
|
3473
|
-
|
|
3474
|
-
if (list === undefined)
|
|
3475
|
-
return this;
|
|
3473
|
+
checkListener(listener);
|
|
3476
3474
|
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
else {
|
|
3481
|
-
delete events[type];
|
|
3482
|
-
if (events.removeListener)
|
|
3483
|
-
this.emit('removeListener', type, list.listener || listener);
|
|
3484
|
-
}
|
|
3485
|
-
} else if (typeof list !== 'function') {
|
|
3486
|
-
position = -1;
|
|
3487
|
-
|
|
3488
|
-
for (i = list.length - 1; i >= 0; i--) {
|
|
3489
|
-
if (list[i] === listener || list[i].listener === listener) {
|
|
3490
|
-
originalListener = list[i].listener;
|
|
3491
|
-
position = i;
|
|
3492
|
-
break;
|
|
3493
|
-
}
|
|
3494
|
-
}
|
|
3475
|
+
events = this._events;
|
|
3476
|
+
if (events === undefined)
|
|
3477
|
+
return this;
|
|
3495
3478
|
|
|
3496
|
-
|
|
3497
|
-
|
|
3479
|
+
list = events[type];
|
|
3480
|
+
if (list === undefined)
|
|
3481
|
+
return this;
|
|
3498
3482
|
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3483
|
+
if (list === listener || list.listener === listener) {
|
|
3484
|
+
if (--this._eventsCount === 0)
|
|
3485
|
+
this._events = Object.create(null);
|
|
3486
|
+
else {
|
|
3487
|
+
delete events[type];
|
|
3488
|
+
if (events.removeListener)
|
|
3489
|
+
this.emit('removeListener', type, list.listener || listener);
|
|
3490
|
+
}
|
|
3491
|
+
} else if (typeof list !== 'function') {
|
|
3492
|
+
position = -1;
|
|
3493
|
+
|
|
3494
|
+
for (i = list.length - 1; i >= 0; i--) {
|
|
3495
|
+
if (list[i] === listener || list[i].listener === listener) {
|
|
3496
|
+
originalListener = list[i].listener;
|
|
3497
|
+
position = i;
|
|
3498
|
+
break;
|
|
3499
|
+
}
|
|
3500
|
+
}
|
|
3504
3501
|
|
|
3505
|
-
|
|
3506
|
-
|
|
3502
|
+
if (position < 0)
|
|
3503
|
+
return this;
|
|
3507
3504
|
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3505
|
+
if (position === 0)
|
|
3506
|
+
list.shift();
|
|
3507
|
+
else {
|
|
3508
|
+
spliceOne(list, position);
|
|
3509
|
+
}
|
|
3511
3510
|
|
|
3512
|
-
|
|
3513
|
-
|
|
3511
|
+
if (list.length === 1)
|
|
3512
|
+
events[type] = list[0];
|
|
3514
3513
|
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
function removeAllListeners(type) {
|
|
3519
|
-
var listeners, events, i;
|
|
3520
|
-
|
|
3521
|
-
events = this._events;
|
|
3522
|
-
if (events === undefined)
|
|
3523
|
-
return this;
|
|
3524
|
-
|
|
3525
|
-
// not listening for removeListener, no need to emit
|
|
3526
|
-
if (events.removeListener === undefined) {
|
|
3527
|
-
if (arguments.length === 0) {
|
|
3528
|
-
this._events = Object.create(null);
|
|
3529
|
-
this._eventsCount = 0;
|
|
3530
|
-
} else if (events[type] !== undefined) {
|
|
3531
|
-
if (--this._eventsCount === 0)
|
|
3532
|
-
this._events = Object.create(null);
|
|
3533
|
-
else
|
|
3534
|
-
delete events[type];
|
|
3535
|
-
}
|
|
3536
|
-
return this;
|
|
3537
|
-
}
|
|
3514
|
+
if (events.removeListener !== undefined)
|
|
3515
|
+
this.emit('removeListener', type, originalListener || listener);
|
|
3516
|
+
}
|
|
3538
3517
|
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
var keys = Object.keys(events);
|
|
3542
|
-
var key;
|
|
3543
|
-
for (i = 0; i < keys.length; ++i) {
|
|
3544
|
-
key = keys[i];
|
|
3545
|
-
if (key === 'removeListener') continue;
|
|
3546
|
-
this.removeAllListeners(key);
|
|
3547
|
-
}
|
|
3548
|
-
this.removeAllListeners('removeListener');
|
|
3549
|
-
this._events = Object.create(null);
|
|
3550
|
-
this._eventsCount = 0;
|
|
3551
|
-
return this;
|
|
3552
|
-
}
|
|
3518
|
+
return this;
|
|
3519
|
+
};
|
|
3553
3520
|
|
|
3554
|
-
|
|
3521
|
+
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
|
3522
|
+
|
|
3523
|
+
EventEmitter.prototype.removeAllListeners =
|
|
3524
|
+
function removeAllListeners(type) {
|
|
3525
|
+
var listeners, events, i;
|
|
3526
|
+
|
|
3527
|
+
events = this._events;
|
|
3528
|
+
if (events === undefined)
|
|
3529
|
+
return this;
|
|
3530
|
+
|
|
3531
|
+
// not listening for removeListener, no need to emit
|
|
3532
|
+
if (events.removeListener === undefined) {
|
|
3533
|
+
if (arguments.length === 0) {
|
|
3534
|
+
this._events = Object.create(null);
|
|
3535
|
+
this._eventsCount = 0;
|
|
3536
|
+
} else if (events[type] !== undefined) {
|
|
3537
|
+
if (--this._eventsCount === 0)
|
|
3538
|
+
this._events = Object.create(null);
|
|
3539
|
+
else
|
|
3540
|
+
delete events[type];
|
|
3541
|
+
}
|
|
3542
|
+
return this;
|
|
3543
|
+
}
|
|
3555
3544
|
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
|
|
3545
|
+
// emit removeListener for all listeners on all events
|
|
3546
|
+
if (arguments.length === 0) {
|
|
3547
|
+
var keys = Object.keys(events);
|
|
3548
|
+
var key;
|
|
3549
|
+
for (i = 0; i < keys.length; ++i) {
|
|
3550
|
+
key = keys[i];
|
|
3551
|
+
if (key === 'removeListener') continue;
|
|
3552
|
+
this.removeAllListeners(key);
|
|
3553
|
+
}
|
|
3554
|
+
this.removeAllListeners('removeListener');
|
|
3555
|
+
this._events = Object.create(null);
|
|
3556
|
+
this._eventsCount = 0;
|
|
3557
|
+
return this;
|
|
3558
|
+
}
|
|
3564
3559
|
|
|
3565
|
-
|
|
3566
|
-
};
|
|
3560
|
+
listeners = events[type];
|
|
3567
3561
|
|
|
3568
|
-
|
|
3569
|
-
|
|
3562
|
+
if (typeof listeners === 'function') {
|
|
3563
|
+
this.removeListener(type, listeners);
|
|
3564
|
+
} else if (listeners !== undefined) {
|
|
3565
|
+
// LIFO order
|
|
3566
|
+
for (i = listeners.length - 1; i >= 0; i--) {
|
|
3567
|
+
this.removeListener(type, listeners[i]);
|
|
3568
|
+
}
|
|
3569
|
+
}
|
|
3570
3570
|
|
|
3571
|
-
|
|
3572
|
-
|
|
3571
|
+
return this;
|
|
3572
|
+
};
|
|
3573
3573
|
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
return [];
|
|
3574
|
+
function _listeners(target, type, unwrap) {
|
|
3575
|
+
var events = target._events;
|
|
3577
3576
|
|
|
3578
|
-
|
|
3579
|
-
|
|
3577
|
+
if (events === undefined)
|
|
3578
|
+
return [];
|
|
3580
3579
|
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
3580
|
+
var evlistener = events[type];
|
|
3581
|
+
if (evlistener === undefined)
|
|
3582
|
+
return [];
|
|
3584
3583
|
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
};
|
|
3584
|
+
if (typeof evlistener === 'function')
|
|
3585
|
+
return unwrap ? [evlistener.listener || evlistener] : [evlistener];
|
|
3588
3586
|
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
}
|
|
3587
|
+
return unwrap ?
|
|
3588
|
+
unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
|
|
3589
|
+
}
|
|
3592
3590
|
|
|
3593
|
-
EventEmitter.
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
} else {
|
|
3597
|
-
return listenerCount.call(emitter, type);
|
|
3598
|
-
}
|
|
3599
|
-
};
|
|
3591
|
+
EventEmitter.prototype.listeners = function listeners(type) {
|
|
3592
|
+
return _listeners(this, type, true);
|
|
3593
|
+
};
|
|
3600
3594
|
|
|
3601
|
-
EventEmitter.prototype.
|
|
3602
|
-
|
|
3603
|
-
|
|
3595
|
+
EventEmitter.prototype.rawListeners = function rawListeners(type) {
|
|
3596
|
+
return _listeners(this, type, false);
|
|
3597
|
+
};
|
|
3604
3598
|
|
|
3605
|
-
|
|
3606
|
-
|
|
3599
|
+
EventEmitter.listenerCount = function(emitter, type) {
|
|
3600
|
+
if (typeof emitter.listenerCount === 'function') {
|
|
3601
|
+
return emitter.listenerCount(type);
|
|
3602
|
+
} else {
|
|
3603
|
+
return listenerCount.call(emitter, type);
|
|
3604
|
+
}
|
|
3605
|
+
};
|
|
3607
3606
|
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
return evlistener.length;
|
|
3612
|
-
}
|
|
3613
|
-
}
|
|
3607
|
+
EventEmitter.prototype.listenerCount = listenerCount;
|
|
3608
|
+
function listenerCount(type) {
|
|
3609
|
+
var events = this._events;
|
|
3614
3610
|
|
|
3615
|
-
|
|
3616
|
-
|
|
3611
|
+
if (events !== undefined) {
|
|
3612
|
+
var evlistener = events[type];
|
|
3617
3613
|
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
}
|
|
3614
|
+
if (typeof evlistener === 'function') {
|
|
3615
|
+
return 1;
|
|
3616
|
+
} else if (evlistener !== undefined) {
|
|
3617
|
+
return evlistener.length;
|
|
3618
|
+
}
|
|
3619
|
+
}
|
|
3621
3620
|
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
for (var i = 0; i < n; ++i)
|
|
3625
|
-
copy[i] = arr[i];
|
|
3626
|
-
return copy;
|
|
3627
|
-
}
|
|
3621
|
+
return 0;
|
|
3622
|
+
}
|
|
3628
3623
|
|
|
3629
|
-
function
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
list.pop();
|
|
3633
|
-
}
|
|
3624
|
+
EventEmitter.prototype.eventNames = function eventNames() {
|
|
3625
|
+
return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : [];
|
|
3626
|
+
};
|
|
3634
3627
|
|
|
3635
|
-
function
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
}
|
|
3628
|
+
function arrayClone(arr, n) {
|
|
3629
|
+
var copy = new Array(n);
|
|
3630
|
+
for (var i = 0; i < n; ++i)
|
|
3631
|
+
copy[i] = arr[i];
|
|
3632
|
+
return copy;
|
|
3633
|
+
}
|
|
3642
3634
|
|
|
3643
|
-
function
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
}
|
|
3635
|
+
function spliceOne(list, index) {
|
|
3636
|
+
for (; index + 1 < list.length; index++)
|
|
3637
|
+
list[index] = list[index + 1];
|
|
3638
|
+
list.pop();
|
|
3639
|
+
}
|
|
3649
3640
|
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
if (name !== 'error') {
|
|
3658
|
-
addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true });
|
|
3659
|
-
}
|
|
3660
|
-
});
|
|
3661
|
-
}
|
|
3641
|
+
function unwrapListeners(arr) {
|
|
3642
|
+
var ret = new Array(arr.length);
|
|
3643
|
+
for (var i = 0; i < ret.length; ++i) {
|
|
3644
|
+
ret[i] = arr[i].listener || arr[i];
|
|
3645
|
+
}
|
|
3646
|
+
return ret;
|
|
3647
|
+
}
|
|
3662
3648
|
|
|
3663
|
-
function
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3649
|
+
function once(emitter, name) {
|
|
3650
|
+
return new Promise(function (resolve, reject) {
|
|
3651
|
+
function errorListener(err) {
|
|
3652
|
+
emitter.removeListener(name, resolver);
|
|
3653
|
+
reject(err);
|
|
3654
|
+
}
|
|
3668
3655
|
|
|
3669
|
-
function
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3656
|
+
function resolver() {
|
|
3657
|
+
if (typeof emitter.removeListener === 'function') {
|
|
3658
|
+
emitter.removeListener('error', errorListener);
|
|
3659
|
+
}
|
|
3660
|
+
resolve([].slice.call(arguments));
|
|
3661
|
+
}
|
|
3662
|
+
eventTargetAgnosticAddListener(emitter, name, resolver, { once: true });
|
|
3663
|
+
if (name !== 'error') {
|
|
3664
|
+
addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true });
|
|
3665
|
+
}
|
|
3666
|
+
});
|
|
3667
|
+
}
|
|
3668
|
+
|
|
3669
|
+
function addErrorHandlerIfEventEmitter(emitter, handler, flags) {
|
|
3670
|
+
if (typeof emitter.on === 'function') {
|
|
3671
|
+
eventTargetAgnosticAddListener(emitter, 'error', handler, flags);
|
|
3672
|
+
}
|
|
3673
|
+
}
|
|
3674
|
+
|
|
3675
|
+
function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
|
|
3676
|
+
if (typeof emitter.on === 'function') {
|
|
3677
|
+
if (flags.once) {
|
|
3678
|
+
emitter.once(name, listener);
|
|
3679
|
+
} else {
|
|
3680
|
+
emitter.on(name, listener);
|
|
3681
|
+
}
|
|
3682
|
+
} else if (typeof emitter.addEventListener === 'function') {
|
|
3683
|
+
// EventTarget does not have `error` event semantics like Node
|
|
3684
|
+
// EventEmitters, we do not listen for `error` events here.
|
|
3685
|
+
emitter.addEventListener(name, function wrapListener(arg) {
|
|
3686
|
+
// IE does not have builtin `{ once: true }` support so we
|
|
3687
|
+
// have to do it manually.
|
|
3688
|
+
if (flags.once) {
|
|
3689
|
+
emitter.removeEventListener(name, wrapListener);
|
|
3690
|
+
}
|
|
3691
|
+
listener(arg);
|
|
3692
|
+
});
|
|
3693
|
+
} else {
|
|
3694
|
+
throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof emitter);
|
|
3695
|
+
}
|
|
3696
|
+
}
|
|
3697
|
+
return events.exports;
|
|
3690
3698
|
}
|
|
3691
3699
|
|
|
3692
|
-
var
|
|
3700
|
+
var streamBrowser;
|
|
3701
|
+
var hasRequiredStreamBrowser;
|
|
3693
3702
|
|
|
3694
|
-
|
|
3703
|
+
function requireStreamBrowser () {
|
|
3704
|
+
if (hasRequiredStreamBrowser) return streamBrowser;
|
|
3705
|
+
hasRequiredStreamBrowser = 1;
|
|
3706
|
+
streamBrowser = requireEvents().EventEmitter;
|
|
3707
|
+
return streamBrowser;
|
|
3708
|
+
}
|
|
3695
3709
|
|
|
3696
3710
|
var buffer_list;
|
|
3697
3711
|
var hasRequiredBuffer_list;
|
|
@@ -4229,7 +4243,7 @@ function require_stream_writable () {
|
|
|
4229
4243
|
/*</replacement>*/
|
|
4230
4244
|
|
|
4231
4245
|
/*<replacement>*/
|
|
4232
|
-
var Stream =
|
|
4246
|
+
var Stream = requireStreamBrowser();
|
|
4233
4247
|
/*</replacement>*/
|
|
4234
4248
|
|
|
4235
4249
|
var Buffer = buffer.Buffer;
|
|
@@ -5500,14 +5514,14 @@ function require_stream_readable () {
|
|
|
5500
5514
|
Readable.ReadableState = ReadableState;
|
|
5501
5515
|
|
|
5502
5516
|
/*<replacement>*/
|
|
5503
|
-
|
|
5517
|
+
requireEvents().EventEmitter;
|
|
5504
5518
|
var EElistenerCount = function EElistenerCount(emitter, type) {
|
|
5505
5519
|
return emitter.listeners(type).length;
|
|
5506
5520
|
};
|
|
5507
5521
|
/*</replacement>*/
|
|
5508
5522
|
|
|
5509
5523
|
/*<replacement>*/
|
|
5510
|
-
var Stream =
|
|
5524
|
+
var Stream = requireStreamBrowser();
|
|
5511
5525
|
/*</replacement>*/
|
|
5512
5526
|
|
|
5513
5527
|
var Buffer = buffer.Buffer;
|
|
@@ -27208,7 +27208,7 @@ class Identity {
|
|
|
27208
27208
|
this.selectedAccount = new TextDecoder().decode(selected);
|
|
27209
27209
|
}
|
|
27210
27210
|
else {
|
|
27211
|
-
const importee = await import(/* webpackChunkName: "generate-account" */ './index-
|
|
27211
|
+
const importee = await import(/* webpackChunkName: "generate-account" */ './index-fC0k-d_O-DQ-T8zrg.js');
|
|
27212
27212
|
const { identity, accounts } = await importee.default(password, this.network);
|
|
27213
27213
|
await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
|
|
27214
27214
|
await globalThis.walletStore.put('version', String(1));
|
|
@@ -27400,7 +27400,7 @@ class Peernet {
|
|
|
27400
27400
|
this.root = options.root;
|
|
27401
27401
|
const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
|
|
27402
27402
|
// FolderMessageResponse
|
|
27403
|
-
} = await import(/* webpackChunkName: "messages" */ './messages-
|
|
27403
|
+
} = await import(/* webpackChunkName: "messages" */ './messages-rdtq6jgH-Cpp_3cR4.js');
|
|
27404
27404
|
/**
|
|
27405
27405
|
* proto Object containing protos
|
|
27406
27406
|
* @type {Object}
|
|
@@ -27494,7 +27494,7 @@ class Peernet {
|
|
|
27494
27494
|
if (this.#starting || this.#started)
|
|
27495
27495
|
return;
|
|
27496
27496
|
this.#starting = true;
|
|
27497
|
-
const importee = await import('./client-
|
|
27497
|
+
const importee = await import('./client-5mPwJbpC-DcusxC0q.js');
|
|
27498
27498
|
/**
|
|
27499
27499
|
* @access public
|
|
27500
27500
|
* @type {PeernetClient}
|
|
@@ -27651,7 +27651,7 @@ class Peernet {
|
|
|
27651
27651
|
let providers = this.dht.providersFor(hash);
|
|
27652
27652
|
// walk the network to find a provider
|
|
27653
27653
|
let tries = 0;
|
|
27654
|
-
while ((!providers && tries < 3) || (Object.keys(providers).length === 0 && tries < 3)) {
|
|
27654
|
+
while ((!providers && tries < 3) || (providers && Object.keys(providers).length === 0 && tries < 3)) {
|
|
27655
27655
|
tries += 1;
|
|
27656
27656
|
await this.walk(hash);
|
|
27657
27657
|
providers = this.dht.providersFor(hash);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { N as default } from './node-browser-
|
|
1
|
+
export { N as default } from './node-browser-By4Fowr9.js';
|
|
2
2
|
import './index-XTbRdu6H.js';
|
package/exports/chain.js
CHANGED
|
@@ -1160,38 +1160,46 @@ class State extends Contract {
|
|
|
1160
1160
|
let poolTransactionKeys = await globalThis.transactionPoolStore.keys();
|
|
1161
1161
|
for (const block of blocks) {
|
|
1162
1162
|
if (block && !block.loaded) {
|
|
1163
|
-
|
|
1164
|
-
this.#
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1163
|
+
try {
|
|
1164
|
+
let transactions = await this.#loadBlockTransactions([...block.transactions] || []);
|
|
1165
|
+
const lastTransactions = await this.#getLastTransactions();
|
|
1166
|
+
let priority = [];
|
|
1167
|
+
for (const transaction of transactions) {
|
|
1168
|
+
const hash = await transaction.hash();
|
|
1169
|
+
if (lastTransactions.includes(hash)) {
|
|
1170
|
+
console.log('removing invalid block');
|
|
1171
|
+
await globalThis.blockStore.delete(await (await new BlockMessage(block)).hash());
|
|
1172
|
+
blocks.splice(block.index - 1, 1);
|
|
1173
|
+
return this.#loadBlocks(blocks);
|
|
1174
|
+
}
|
|
1175
|
+
if (transaction.decoded.priority)
|
|
1176
|
+
priority.push(transaction);
|
|
1177
|
+
if (poolTransactionKeys.includes(hash))
|
|
1178
|
+
await globalThis.transactionPoolStore.delete(hash);
|
|
1175
1179
|
}
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
+
// prority blocks execution from the rest so result in higher fees.
|
|
1181
|
+
if (priority.length > 0) {
|
|
1182
|
+
priority = priority.sort((a, b) => a.nonce - b.nonce);
|
|
1183
|
+
for (const transaction of priority) {
|
|
1184
|
+
await this.#_executeTransaction(transaction);
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
transactions = transactions.filter((transaction) => !transaction.decoded.priority);
|
|
1188
|
+
await Promise.all(transactions.map((transaction) => this.#_executeTransaction(transaction)));
|
|
1189
|
+
this.#blocks[block.index].loaded = true;
|
|
1190
|
+
if (block.index === 0)
|
|
1191
|
+
this.#loaded = true;
|
|
1192
|
+
await this.#machine.addLoadedBlock(block);
|
|
1193
|
+
// @ts-ignore
|
|
1194
|
+
debug$1(`loaded block: ${block.hash} @${block.index}`);
|
|
1195
|
+
globalThis.pubsub.publish('block-loaded', { ...block });
|
|
1180
1196
|
}
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
await this.#_executeTransaction(transaction);
|
|
1197
|
+
catch (error) {
|
|
1198
|
+
console.error(error);
|
|
1199
|
+
for (const transaction of block.transactions) {
|
|
1200
|
+
this.wantList.push(transaction);
|
|
1186
1201
|
}
|
|
1187
1202
|
}
|
|
1188
|
-
transactions = transactions.filter((transaction) => !transaction.decoded.priority);
|
|
1189
|
-
await Promise.all(transactions.map((transaction) => this.#_executeTransaction(transaction)));
|
|
1190
|
-
this.#blocks[block.index].loaded = true;
|
|
1191
|
-
await this.#machine.addLoadedBlock(block);
|
|
1192
|
-
// @ts-ignore
|
|
1193
|
-
debug$1(`loaded block: ${block.hash} @${block.index}`);
|
|
1194
|
-
globalThis.pubsub.publish('block-loaded', { ...block });
|
|
1195
1203
|
}
|
|
1196
1204
|
}
|
|
1197
1205
|
this.#chainState = 'loaded';
|
|
@@ -1464,6 +1472,17 @@ class Chain extends VersionControl {
|
|
|
1464
1472
|
else if (!this.knownBlocks)
|
|
1465
1473
|
this.knownBlocks = await this.#makeRequest(peer, 'knownBlocks');
|
|
1466
1474
|
}
|
|
1475
|
+
if (this.wantList.length > 0) {
|
|
1476
|
+
const promises = await Promise.allSettled(this.wantList.map((hash) => peernet.get(hash)));
|
|
1477
|
+
for (let i = 0; i < promises.length; i++) {
|
|
1478
|
+
const result = promises[i];
|
|
1479
|
+
if (result.status === 'fulfilled')
|
|
1480
|
+
this.wantList.splice(i, 1);
|
|
1481
|
+
}
|
|
1482
|
+
// todo trigger load instead?
|
|
1483
|
+
if (this.wantList.length === 0)
|
|
1484
|
+
await this.triggerSync();
|
|
1485
|
+
}
|
|
1467
1486
|
setTimeout(async () => {
|
|
1468
1487
|
const peerTransactionPool = (higherThenCurrentLocal && (await this.getPeerTransactionPool(peer))) || [];
|
|
1469
1488
|
if (this.#participating && peerTransactionPool.length > 0)
|
package/exports/state.d.ts
CHANGED
|
@@ -9,6 +9,10 @@ export default class State extends Contract {
|
|
|
9
9
|
#private;
|
|
10
10
|
knownBlocks: BlockHash[];
|
|
11
11
|
jobber: Jobber;
|
|
12
|
+
/**
|
|
13
|
+
* contains transactions we need before we can successfully load
|
|
14
|
+
*/
|
|
15
|
+
wantList: string[];
|
|
12
16
|
get state(): {
|
|
13
17
|
sync: SyncState;
|
|
14
18
|
chain: ChainState;
|