@leofcoin/chain 1.4.92 → 1.4.93
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/chain.js +84 -879
- package/exports/browser/{index-fd1bc5f0.js → index-b32f624f.js} +1 -1
- package/exports/browser/{index-ed6cbdf7-cced6308.js → index-ed6cbdf7-8662153e.js} +2 -2
- package/exports/browser/{messages-35d069e1-0b6352ff.js → messages-35d069e1-7ad3a4bb.js} +2 -2
- package/exports/browser/{node-browser-e89e6592.js → node-browser-b56b946d.js} +17 -6
- package/exports/browser/node-browser.js +2 -2
- package/exports/chain.js +83 -44
- package/exports/node.js +1 -0
- package/exports/types/state.d.ts +2 -0
- package/package.json +2 -7
package/exports/browser/chain.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as BigNumber, L as Logger, v as version$1, h as hexZeroPad, i as isBigNumberish, a as arrayify, b as isBytes, C as ContractMessage, T as TransactionMessage, t as toBase58, R as RawTransactionMessage,
|
|
1
|
+
import { B as BigNumber, L as Logger, v as version$1, h as hexZeroPad, i as isBigNumberish, a as arrayify, b as isBytes, C as ContractMessage, T as TransactionMessage, t as toBase58, R as RawTransactionMessage, c as BlockMessage, d as BWMessage, e as BWRequestMessage } from './index-b32f624f.js';
|
|
2
2
|
|
|
3
3
|
const logger$1 = new Logger(version$1);
|
|
4
4
|
const _constructorGuard = {};
|
|
@@ -471,848 +471,14 @@ const signTransaction = async (transaction, wallet) => {
|
|
|
471
471
|
return signedTransaction;
|
|
472
472
|
};
|
|
473
473
|
|
|
474
|
-
var eventemitter3 = {exports: {}};
|
|
475
|
-
|
|
476
|
-
(function (module) {
|
|
477
|
-
|
|
478
|
-
var has = Object.prototype.hasOwnProperty
|
|
479
|
-
, prefix = '~';
|
|
480
|
-
|
|
481
|
-
/**
|
|
482
|
-
* Constructor to create a storage for our `EE` objects.
|
|
483
|
-
* An `Events` instance is a plain object whose properties are event names.
|
|
484
|
-
*
|
|
485
|
-
* @constructor
|
|
486
|
-
* @private
|
|
487
|
-
*/
|
|
488
|
-
function Events() {}
|
|
489
|
-
|
|
490
|
-
//
|
|
491
|
-
// We try to not inherit from `Object.prototype`. In some engines creating an
|
|
492
|
-
// instance in this way is faster than calling `Object.create(null)` directly.
|
|
493
|
-
// If `Object.create(null)` is not supported we prefix the event names with a
|
|
494
|
-
// character to make sure that the built-in object properties are not
|
|
495
|
-
// overridden or used as an attack vector.
|
|
496
|
-
//
|
|
497
|
-
if (Object.create) {
|
|
498
|
-
Events.prototype = Object.create(null);
|
|
499
|
-
|
|
500
|
-
//
|
|
501
|
-
// This hack is needed because the `__proto__` property is still inherited in
|
|
502
|
-
// some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.
|
|
503
|
-
//
|
|
504
|
-
if (!new Events().__proto__) prefix = false;
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
/**
|
|
508
|
-
* Representation of a single event listener.
|
|
509
|
-
*
|
|
510
|
-
* @param {Function} fn The listener function.
|
|
511
|
-
* @param {*} context The context to invoke the listener with.
|
|
512
|
-
* @param {Boolean} [once=false] Specify if the listener is a one-time listener.
|
|
513
|
-
* @constructor
|
|
514
|
-
* @private
|
|
515
|
-
*/
|
|
516
|
-
function EE(fn, context, once) {
|
|
517
|
-
this.fn = fn;
|
|
518
|
-
this.context = context;
|
|
519
|
-
this.once = once || false;
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
/**
|
|
523
|
-
* Add a listener for a given event.
|
|
524
|
-
*
|
|
525
|
-
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
|
|
526
|
-
* @param {(String|Symbol)} event The event name.
|
|
527
|
-
* @param {Function} fn The listener function.
|
|
528
|
-
* @param {*} context The context to invoke the listener with.
|
|
529
|
-
* @param {Boolean} once Specify if the listener is a one-time listener.
|
|
530
|
-
* @returns {EventEmitter}
|
|
531
|
-
* @private
|
|
532
|
-
*/
|
|
533
|
-
function addListener(emitter, event, fn, context, once) {
|
|
534
|
-
if (typeof fn !== 'function') {
|
|
535
|
-
throw new TypeError('The listener must be a function');
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
var listener = new EE(fn, context || emitter, once)
|
|
539
|
-
, evt = prefix ? prefix + event : event;
|
|
540
|
-
|
|
541
|
-
if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
|
|
542
|
-
else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
|
|
543
|
-
else emitter._events[evt] = [emitter._events[evt], listener];
|
|
544
|
-
|
|
545
|
-
return emitter;
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
/**
|
|
549
|
-
* Clear event by name.
|
|
550
|
-
*
|
|
551
|
-
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
|
|
552
|
-
* @param {(String|Symbol)} evt The Event name.
|
|
553
|
-
* @private
|
|
554
|
-
*/
|
|
555
|
-
function clearEvent(emitter, evt) {
|
|
556
|
-
if (--emitter._eventsCount === 0) emitter._events = new Events();
|
|
557
|
-
else delete emitter._events[evt];
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
/**
|
|
561
|
-
* Minimal `EventEmitter` interface that is molded against the Node.js
|
|
562
|
-
* `EventEmitter` interface.
|
|
563
|
-
*
|
|
564
|
-
* @constructor
|
|
565
|
-
* @public
|
|
566
|
-
*/
|
|
567
|
-
function EventEmitter() {
|
|
568
|
-
this._events = new Events();
|
|
569
|
-
this._eventsCount = 0;
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
/**
|
|
573
|
-
* Return an array listing the events for which the emitter has registered
|
|
574
|
-
* listeners.
|
|
575
|
-
*
|
|
576
|
-
* @returns {Array}
|
|
577
|
-
* @public
|
|
578
|
-
*/
|
|
579
|
-
EventEmitter.prototype.eventNames = function eventNames() {
|
|
580
|
-
var names = []
|
|
581
|
-
, events
|
|
582
|
-
, name;
|
|
583
|
-
|
|
584
|
-
if (this._eventsCount === 0) return names;
|
|
585
|
-
|
|
586
|
-
for (name in (events = this._events)) {
|
|
587
|
-
if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
if (Object.getOwnPropertySymbols) {
|
|
591
|
-
return names.concat(Object.getOwnPropertySymbols(events));
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
return names;
|
|
595
|
-
};
|
|
596
|
-
|
|
597
|
-
/**
|
|
598
|
-
* Return the listeners registered for a given event.
|
|
599
|
-
*
|
|
600
|
-
* @param {(String|Symbol)} event The event name.
|
|
601
|
-
* @returns {Array} The registered listeners.
|
|
602
|
-
* @public
|
|
603
|
-
*/
|
|
604
|
-
EventEmitter.prototype.listeners = function listeners(event) {
|
|
605
|
-
var evt = prefix ? prefix + event : event
|
|
606
|
-
, handlers = this._events[evt];
|
|
607
|
-
|
|
608
|
-
if (!handlers) return [];
|
|
609
|
-
if (handlers.fn) return [handlers.fn];
|
|
610
|
-
|
|
611
|
-
for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
|
|
612
|
-
ee[i] = handlers[i].fn;
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
return ee;
|
|
616
|
-
};
|
|
617
|
-
|
|
618
|
-
/**
|
|
619
|
-
* Return the number of listeners listening to a given event.
|
|
620
|
-
*
|
|
621
|
-
* @param {(String|Symbol)} event The event name.
|
|
622
|
-
* @returns {Number} The number of listeners.
|
|
623
|
-
* @public
|
|
624
|
-
*/
|
|
625
|
-
EventEmitter.prototype.listenerCount = function listenerCount(event) {
|
|
626
|
-
var evt = prefix ? prefix + event : event
|
|
627
|
-
, listeners = this._events[evt];
|
|
628
|
-
|
|
629
|
-
if (!listeners) return 0;
|
|
630
|
-
if (listeners.fn) return 1;
|
|
631
|
-
return listeners.length;
|
|
632
|
-
};
|
|
633
|
-
|
|
634
|
-
/**
|
|
635
|
-
* Calls each of the listeners registered for a given event.
|
|
636
|
-
*
|
|
637
|
-
* @param {(String|Symbol)} event The event name.
|
|
638
|
-
* @returns {Boolean} `true` if the event had listeners, else `false`.
|
|
639
|
-
* @public
|
|
640
|
-
*/
|
|
641
|
-
EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
|
|
642
|
-
var evt = prefix ? prefix + event : event;
|
|
643
|
-
|
|
644
|
-
if (!this._events[evt]) return false;
|
|
645
|
-
|
|
646
|
-
var listeners = this._events[evt]
|
|
647
|
-
, len = arguments.length
|
|
648
|
-
, args
|
|
649
|
-
, i;
|
|
650
|
-
|
|
651
|
-
if (listeners.fn) {
|
|
652
|
-
if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);
|
|
653
|
-
|
|
654
|
-
switch (len) {
|
|
655
|
-
case 1: return listeners.fn.call(listeners.context), true;
|
|
656
|
-
case 2: return listeners.fn.call(listeners.context, a1), true;
|
|
657
|
-
case 3: return listeners.fn.call(listeners.context, a1, a2), true;
|
|
658
|
-
case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true;
|
|
659
|
-
case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
|
|
660
|
-
case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
for (i = 1, args = new Array(len -1); i < len; i++) {
|
|
664
|
-
args[i - 1] = arguments[i];
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
listeners.fn.apply(listeners.context, args);
|
|
668
|
-
} else {
|
|
669
|
-
var length = listeners.length
|
|
670
|
-
, j;
|
|
671
|
-
|
|
672
|
-
for (i = 0; i < length; i++) {
|
|
673
|
-
if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
|
|
674
|
-
|
|
675
|
-
switch (len) {
|
|
676
|
-
case 1: listeners[i].fn.call(listeners[i].context); break;
|
|
677
|
-
case 2: listeners[i].fn.call(listeners[i].context, a1); break;
|
|
678
|
-
case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break;
|
|
679
|
-
case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break;
|
|
680
|
-
default:
|
|
681
|
-
if (!args) for (j = 1, args = new Array(len -1); j < len; j++) {
|
|
682
|
-
args[j - 1] = arguments[j];
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
listeners[i].fn.apply(listeners[i].context, args);
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
return true;
|
|
691
|
-
};
|
|
692
|
-
|
|
693
|
-
/**
|
|
694
|
-
* Add a listener for a given event.
|
|
695
|
-
*
|
|
696
|
-
* @param {(String|Symbol)} event The event name.
|
|
697
|
-
* @param {Function} fn The listener function.
|
|
698
|
-
* @param {*} [context=this] The context to invoke the listener with.
|
|
699
|
-
* @returns {EventEmitter} `this`.
|
|
700
|
-
* @public
|
|
701
|
-
*/
|
|
702
|
-
EventEmitter.prototype.on = function on(event, fn, context) {
|
|
703
|
-
return addListener(this, event, fn, context, false);
|
|
704
|
-
};
|
|
705
|
-
|
|
706
|
-
/**
|
|
707
|
-
* Add a one-time listener for a given event.
|
|
708
|
-
*
|
|
709
|
-
* @param {(String|Symbol)} event The event name.
|
|
710
|
-
* @param {Function} fn The listener function.
|
|
711
|
-
* @param {*} [context=this] The context to invoke the listener with.
|
|
712
|
-
* @returns {EventEmitter} `this`.
|
|
713
|
-
* @public
|
|
714
|
-
*/
|
|
715
|
-
EventEmitter.prototype.once = function once(event, fn, context) {
|
|
716
|
-
return addListener(this, event, fn, context, true);
|
|
717
|
-
};
|
|
718
|
-
|
|
719
|
-
/**
|
|
720
|
-
* Remove the listeners of a given event.
|
|
721
|
-
*
|
|
722
|
-
* @param {(String|Symbol)} event The event name.
|
|
723
|
-
* @param {Function} fn Only remove the listeners that match this function.
|
|
724
|
-
* @param {*} context Only remove the listeners that have this context.
|
|
725
|
-
* @param {Boolean} once Only remove one-time listeners.
|
|
726
|
-
* @returns {EventEmitter} `this`.
|
|
727
|
-
* @public
|
|
728
|
-
*/
|
|
729
|
-
EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
|
|
730
|
-
var evt = prefix ? prefix + event : event;
|
|
731
|
-
|
|
732
|
-
if (!this._events[evt]) return this;
|
|
733
|
-
if (!fn) {
|
|
734
|
-
clearEvent(this, evt);
|
|
735
|
-
return this;
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
var listeners = this._events[evt];
|
|
739
|
-
|
|
740
|
-
if (listeners.fn) {
|
|
741
|
-
if (
|
|
742
|
-
listeners.fn === fn &&
|
|
743
|
-
(!once || listeners.once) &&
|
|
744
|
-
(!context || listeners.context === context)
|
|
745
|
-
) {
|
|
746
|
-
clearEvent(this, evt);
|
|
747
|
-
}
|
|
748
|
-
} else {
|
|
749
|
-
for (var i = 0, events = [], length = listeners.length; i < length; i++) {
|
|
750
|
-
if (
|
|
751
|
-
listeners[i].fn !== fn ||
|
|
752
|
-
(once && !listeners[i].once) ||
|
|
753
|
-
(context && listeners[i].context !== context)
|
|
754
|
-
) {
|
|
755
|
-
events.push(listeners[i]);
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
|
|
759
|
-
//
|
|
760
|
-
// Reset the array, or remove it completely if we have no more listeners.
|
|
761
|
-
//
|
|
762
|
-
if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;
|
|
763
|
-
else clearEvent(this, evt);
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
return this;
|
|
767
|
-
};
|
|
768
|
-
|
|
769
|
-
/**
|
|
770
|
-
* Remove all listeners, or those of the specified event.
|
|
771
|
-
*
|
|
772
|
-
* @param {(String|Symbol)} [event] The event name.
|
|
773
|
-
* @returns {EventEmitter} `this`.
|
|
774
|
-
* @public
|
|
775
|
-
*/
|
|
776
|
-
EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
|
|
777
|
-
var evt;
|
|
778
|
-
|
|
779
|
-
if (event) {
|
|
780
|
-
evt = prefix ? prefix + event : event;
|
|
781
|
-
if (this._events[evt]) clearEvent(this, evt);
|
|
782
|
-
} else {
|
|
783
|
-
this._events = new Events();
|
|
784
|
-
this._eventsCount = 0;
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
return this;
|
|
788
|
-
};
|
|
789
|
-
|
|
790
|
-
//
|
|
791
|
-
// Alias methods names because people roll like that.
|
|
792
|
-
//
|
|
793
|
-
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
|
794
|
-
EventEmitter.prototype.addListener = EventEmitter.prototype.on;
|
|
795
|
-
|
|
796
|
-
//
|
|
797
|
-
// Expose the prefix.
|
|
798
|
-
//
|
|
799
|
-
EventEmitter.prefixed = prefix;
|
|
800
|
-
|
|
801
|
-
//
|
|
802
|
-
// Allow `EventEmitter` to be imported as module namespace.
|
|
803
|
-
//
|
|
804
|
-
EventEmitter.EventEmitter = EventEmitter;
|
|
805
|
-
|
|
806
|
-
//
|
|
807
|
-
// Expose the module.
|
|
808
|
-
//
|
|
809
|
-
{
|
|
810
|
-
module.exports = EventEmitter;
|
|
811
|
-
}
|
|
812
|
-
} (eventemitter3));
|
|
813
|
-
|
|
814
|
-
var eventemitter3Exports = eventemitter3.exports;
|
|
815
|
-
var EventEmitter = /*@__PURE__*/getDefaultExportFromCjs(eventemitter3Exports);
|
|
816
|
-
|
|
817
|
-
class TimeoutError extends Error {
|
|
818
|
-
constructor(message) {
|
|
819
|
-
super(message);
|
|
820
|
-
this.name = 'TimeoutError';
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
|
|
824
|
-
/**
|
|
825
|
-
An error to be thrown when the request is aborted by AbortController.
|
|
826
|
-
DOMException is thrown instead of this Error when DOMException is available.
|
|
827
|
-
*/
|
|
828
|
-
let AbortError$1 = class AbortError extends Error {
|
|
829
|
-
constructor(message) {
|
|
830
|
-
super();
|
|
831
|
-
this.name = 'AbortError';
|
|
832
|
-
this.message = message;
|
|
833
|
-
}
|
|
834
|
-
};
|
|
835
|
-
|
|
836
|
-
/**
|
|
837
|
-
TODO: Remove AbortError and just throw DOMException when targeting Node 18.
|
|
838
|
-
*/
|
|
839
|
-
const getDOMException = errorMessage => globalThis.DOMException === undefined ?
|
|
840
|
-
new AbortError$1(errorMessage) :
|
|
841
|
-
new DOMException(errorMessage);
|
|
842
|
-
|
|
843
|
-
/**
|
|
844
|
-
TODO: Remove below function and just 'reject(signal.reason)' when targeting Node 18.
|
|
845
|
-
*/
|
|
846
|
-
const getAbortedReason = signal => {
|
|
847
|
-
const reason = signal.reason === undefined ?
|
|
848
|
-
getDOMException('This operation was aborted.') :
|
|
849
|
-
signal.reason;
|
|
850
|
-
|
|
851
|
-
return reason instanceof Error ? reason : getDOMException(reason);
|
|
852
|
-
};
|
|
853
|
-
|
|
854
|
-
function pTimeout(promise, milliseconds, fallback, options) {
|
|
855
|
-
let timer;
|
|
856
|
-
|
|
857
|
-
const cancelablePromise = new Promise((resolve, reject) => {
|
|
858
|
-
if (typeof milliseconds !== 'number' || Math.sign(milliseconds) !== 1) {
|
|
859
|
-
throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${milliseconds}\``);
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
if (milliseconds === Number.POSITIVE_INFINITY) {
|
|
863
|
-
resolve(promise);
|
|
864
|
-
return;
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
options = {
|
|
868
|
-
customTimers: {setTimeout, clearTimeout},
|
|
869
|
-
...options
|
|
870
|
-
};
|
|
871
|
-
|
|
872
|
-
if (options.signal) {
|
|
873
|
-
const {signal} = options;
|
|
874
|
-
if (signal.aborted) {
|
|
875
|
-
reject(getAbortedReason(signal));
|
|
876
|
-
}
|
|
877
|
-
|
|
878
|
-
signal.addEventListener('abort', () => {
|
|
879
|
-
reject(getAbortedReason(signal));
|
|
880
|
-
});
|
|
881
|
-
}
|
|
882
|
-
|
|
883
|
-
timer = options.customTimers.setTimeout.call(undefined, () => {
|
|
884
|
-
if (typeof fallback === 'function') {
|
|
885
|
-
try {
|
|
886
|
-
resolve(fallback());
|
|
887
|
-
} catch (error) {
|
|
888
|
-
reject(error);
|
|
889
|
-
}
|
|
890
|
-
|
|
891
|
-
return;
|
|
892
|
-
}
|
|
893
|
-
|
|
894
|
-
const message = typeof fallback === 'string' ? fallback : `Promise timed out after ${milliseconds} milliseconds`;
|
|
895
|
-
const timeoutError = fallback instanceof Error ? fallback : new TimeoutError(message);
|
|
896
|
-
|
|
897
|
-
if (typeof promise.cancel === 'function') {
|
|
898
|
-
promise.cancel();
|
|
899
|
-
}
|
|
900
|
-
|
|
901
|
-
reject(timeoutError);
|
|
902
|
-
}, milliseconds);
|
|
903
|
-
|
|
904
|
-
(async () => {
|
|
905
|
-
try {
|
|
906
|
-
resolve(await promise);
|
|
907
|
-
} catch (error) {
|
|
908
|
-
reject(error);
|
|
909
|
-
} finally {
|
|
910
|
-
options.customTimers.clearTimeout.call(undefined, timer);
|
|
911
|
-
}
|
|
912
|
-
})();
|
|
913
|
-
});
|
|
914
|
-
|
|
915
|
-
cancelablePromise.clear = () => {
|
|
916
|
-
clearTimeout(timer);
|
|
917
|
-
timer = undefined;
|
|
918
|
-
};
|
|
919
|
-
|
|
920
|
-
return cancelablePromise;
|
|
921
|
-
}
|
|
922
|
-
|
|
923
|
-
// Port of lower_bound from https://en.cppreference.com/w/cpp/algorithm/lower_bound
|
|
924
|
-
// Used to compute insertion index to keep queue sorted after insertion
|
|
925
|
-
function lowerBound(array, value, comparator) {
|
|
926
|
-
let first = 0;
|
|
927
|
-
let count = array.length;
|
|
928
|
-
while (count > 0) {
|
|
929
|
-
const step = Math.trunc(count / 2);
|
|
930
|
-
let it = first + step;
|
|
931
|
-
if (comparator(array[it], value) <= 0) {
|
|
932
|
-
first = ++it;
|
|
933
|
-
count -= step + 1;
|
|
934
|
-
}
|
|
935
|
-
else {
|
|
936
|
-
count = step;
|
|
937
|
-
}
|
|
938
|
-
}
|
|
939
|
-
return first;
|
|
940
|
-
}
|
|
941
|
-
|
|
942
|
-
var __classPrivateFieldGet$1 = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
943
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
944
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
945
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
946
|
-
};
|
|
947
|
-
var _PriorityQueue_queue;
|
|
948
|
-
class PriorityQueue {
|
|
949
|
-
constructor() {
|
|
950
|
-
_PriorityQueue_queue.set(this, []);
|
|
951
|
-
}
|
|
952
|
-
enqueue(run, options) {
|
|
953
|
-
options = {
|
|
954
|
-
priority: 0,
|
|
955
|
-
...options,
|
|
956
|
-
};
|
|
957
|
-
const element = {
|
|
958
|
-
priority: options.priority,
|
|
959
|
-
run,
|
|
960
|
-
};
|
|
961
|
-
if (this.size && __classPrivateFieldGet$1(this, _PriorityQueue_queue, "f")[this.size - 1].priority >= options.priority) {
|
|
962
|
-
__classPrivateFieldGet$1(this, _PriorityQueue_queue, "f").push(element);
|
|
963
|
-
return;
|
|
964
|
-
}
|
|
965
|
-
const index = lowerBound(__classPrivateFieldGet$1(this, _PriorityQueue_queue, "f"), element, (a, b) => b.priority - a.priority);
|
|
966
|
-
__classPrivateFieldGet$1(this, _PriorityQueue_queue, "f").splice(index, 0, element);
|
|
967
|
-
}
|
|
968
|
-
dequeue() {
|
|
969
|
-
const item = __classPrivateFieldGet$1(this, _PriorityQueue_queue, "f").shift();
|
|
970
|
-
return item === null || item === void 0 ? void 0 : item.run;
|
|
971
|
-
}
|
|
972
|
-
filter(options) {
|
|
973
|
-
return __classPrivateFieldGet$1(this, _PriorityQueue_queue, "f").filter((element) => element.priority === options.priority).map((element) => element.run);
|
|
974
|
-
}
|
|
975
|
-
get size() {
|
|
976
|
-
return __classPrivateFieldGet$1(this, _PriorityQueue_queue, "f").length;
|
|
977
|
-
}
|
|
978
|
-
}
|
|
979
|
-
_PriorityQueue_queue = new WeakMap();
|
|
980
|
-
|
|
981
|
-
var __classPrivateFieldSet = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
982
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
983
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
984
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
985
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
986
|
-
};
|
|
987
|
-
var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
988
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
989
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
990
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
991
|
-
};
|
|
992
|
-
var _PQueue_instances, _PQueue_carryoverConcurrencyCount, _PQueue_isIntervalIgnored, _PQueue_intervalCount, _PQueue_intervalCap, _PQueue_interval, _PQueue_intervalEnd, _PQueue_intervalId, _PQueue_timeoutId, _PQueue_queue, _PQueue_queueClass, _PQueue_pending, _PQueue_concurrency, _PQueue_isPaused, _PQueue_throwOnTimeout, _PQueue_doesIntervalAllowAnother_get, _PQueue_doesConcurrentAllowAnother_get, _PQueue_next, _PQueue_onResumeInterval, _PQueue_isIntervalPaused_get, _PQueue_tryToStartAnother, _PQueue_initializeIntervalIfNeeded, _PQueue_onInterval, _PQueue_processQueue, _PQueue_throwOnAbort, _PQueue_onEvent;
|
|
993
|
-
/**
|
|
994
|
-
The error thrown by `queue.add()` when a job is aborted before it is run. See `signal`.
|
|
995
|
-
*/
|
|
996
|
-
class AbortError extends Error {
|
|
997
|
-
}
|
|
998
|
-
/**
|
|
999
|
-
Promise queue with concurrency control.
|
|
1000
|
-
*/
|
|
1001
|
-
class PQueue extends EventEmitter {
|
|
1002
|
-
// TODO: The `throwOnTimeout` option should affect the return types of `add()` and `addAll()`
|
|
1003
|
-
constructor(options) {
|
|
1004
|
-
var _a, _b, _c, _d;
|
|
1005
|
-
super();
|
|
1006
|
-
_PQueue_instances.add(this);
|
|
1007
|
-
_PQueue_carryoverConcurrencyCount.set(this, void 0);
|
|
1008
|
-
_PQueue_isIntervalIgnored.set(this, void 0);
|
|
1009
|
-
_PQueue_intervalCount.set(this, 0);
|
|
1010
|
-
_PQueue_intervalCap.set(this, void 0);
|
|
1011
|
-
_PQueue_interval.set(this, void 0);
|
|
1012
|
-
_PQueue_intervalEnd.set(this, 0);
|
|
1013
|
-
_PQueue_intervalId.set(this, void 0);
|
|
1014
|
-
_PQueue_timeoutId.set(this, void 0);
|
|
1015
|
-
_PQueue_queue.set(this, void 0);
|
|
1016
|
-
_PQueue_queueClass.set(this, void 0);
|
|
1017
|
-
_PQueue_pending.set(this, 0);
|
|
1018
|
-
// The `!` is needed because of https://github.com/microsoft/TypeScript/issues/32194
|
|
1019
|
-
_PQueue_concurrency.set(this, void 0);
|
|
1020
|
-
_PQueue_isPaused.set(this, void 0);
|
|
1021
|
-
_PQueue_throwOnTimeout.set(this, void 0);
|
|
1022
|
-
/**
|
|
1023
|
-
Per-operation timeout in milliseconds. Operations fulfill once `timeout` elapses if they haven't already.
|
|
1024
|
-
|
|
1025
|
-
Applies to each future operation.
|
|
1026
|
-
*/
|
|
1027
|
-
Object.defineProperty(this, "timeout", {
|
|
1028
|
-
enumerable: true,
|
|
1029
|
-
configurable: true,
|
|
1030
|
-
writable: true,
|
|
1031
|
-
value: void 0
|
|
1032
|
-
});
|
|
1033
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
1034
|
-
options = {
|
|
1035
|
-
carryoverConcurrencyCount: false,
|
|
1036
|
-
intervalCap: Number.POSITIVE_INFINITY,
|
|
1037
|
-
interval: 0,
|
|
1038
|
-
concurrency: Number.POSITIVE_INFINITY,
|
|
1039
|
-
autoStart: true,
|
|
1040
|
-
queueClass: PriorityQueue,
|
|
1041
|
-
...options,
|
|
1042
|
-
};
|
|
1043
|
-
if (!(typeof options.intervalCap === 'number' && options.intervalCap >= 1)) {
|
|
1044
|
-
throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${(_b = (_a = options.intervalCap) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : ''}\` (${typeof options.intervalCap})`);
|
|
1045
|
-
}
|
|
1046
|
-
if (options.interval === undefined || !(Number.isFinite(options.interval) && options.interval >= 0)) {
|
|
1047
|
-
throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${(_d = (_c = options.interval) === null || _c === void 0 ? void 0 : _c.toString()) !== null && _d !== void 0 ? _d : ''}\` (${typeof options.interval})`);
|
|
1048
|
-
}
|
|
1049
|
-
__classPrivateFieldSet(this, _PQueue_carryoverConcurrencyCount, options.carryoverConcurrencyCount, "f");
|
|
1050
|
-
__classPrivateFieldSet(this, _PQueue_isIntervalIgnored, options.intervalCap === Number.POSITIVE_INFINITY || options.interval === 0, "f");
|
|
1051
|
-
__classPrivateFieldSet(this, _PQueue_intervalCap, options.intervalCap, "f");
|
|
1052
|
-
__classPrivateFieldSet(this, _PQueue_interval, options.interval, "f");
|
|
1053
|
-
__classPrivateFieldSet(this, _PQueue_queue, new options.queueClass(), "f");
|
|
1054
|
-
__classPrivateFieldSet(this, _PQueue_queueClass, options.queueClass, "f");
|
|
1055
|
-
this.concurrency = options.concurrency;
|
|
1056
|
-
this.timeout = options.timeout;
|
|
1057
|
-
__classPrivateFieldSet(this, _PQueue_throwOnTimeout, options.throwOnTimeout === true, "f");
|
|
1058
|
-
__classPrivateFieldSet(this, _PQueue_isPaused, options.autoStart === false, "f");
|
|
1059
|
-
}
|
|
1060
|
-
get concurrency() {
|
|
1061
|
-
return __classPrivateFieldGet(this, _PQueue_concurrency, "f");
|
|
1062
|
-
}
|
|
1063
|
-
set concurrency(newConcurrency) {
|
|
1064
|
-
if (!(typeof newConcurrency === 'number' && newConcurrency >= 1)) {
|
|
1065
|
-
throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${newConcurrency}\` (${typeof newConcurrency})`);
|
|
1066
|
-
}
|
|
1067
|
-
__classPrivateFieldSet(this, _PQueue_concurrency, newConcurrency, "f");
|
|
1068
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_processQueue).call(this);
|
|
1069
|
-
}
|
|
1070
|
-
async add(function_, options = {}) {
|
|
1071
|
-
options = {
|
|
1072
|
-
timeout: this.timeout,
|
|
1073
|
-
throwOnTimeout: __classPrivateFieldGet(this, _PQueue_throwOnTimeout, "f"),
|
|
1074
|
-
...options,
|
|
1075
|
-
};
|
|
1076
|
-
return new Promise((resolve, reject) => {
|
|
1077
|
-
__classPrivateFieldGet(this, _PQueue_queue, "f").enqueue(async () => {
|
|
1078
|
-
var _a;
|
|
1079
|
-
var _b, _c;
|
|
1080
|
-
__classPrivateFieldSet(this, _PQueue_pending, (_b = __classPrivateFieldGet(this, _PQueue_pending, "f"), _b++, _b), "f");
|
|
1081
|
-
__classPrivateFieldSet(this, _PQueue_intervalCount, (_c = __classPrivateFieldGet(this, _PQueue_intervalCount, "f"), _c++, _c), "f");
|
|
1082
|
-
try {
|
|
1083
|
-
// TODO: Use options.signal?.throwIfAborted() when targeting Node.js 18
|
|
1084
|
-
if ((_a = options.signal) === null || _a === void 0 ? void 0 : _a.aborted) {
|
|
1085
|
-
// TODO: Use ABORT_ERR code when targeting Node.js 16 (https://nodejs.org/docs/latest-v16.x/api/errors.html#abort_err)
|
|
1086
|
-
throw new AbortError('The task was aborted.');
|
|
1087
|
-
}
|
|
1088
|
-
let operation = function_({ signal: options.signal });
|
|
1089
|
-
if (options.timeout) {
|
|
1090
|
-
operation = pTimeout(Promise.resolve(operation), options.timeout);
|
|
1091
|
-
}
|
|
1092
|
-
if (options.signal) {
|
|
1093
|
-
operation = Promise.race([operation, __classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_throwOnAbort).call(this, options.signal)]);
|
|
1094
|
-
}
|
|
1095
|
-
const result = await operation;
|
|
1096
|
-
resolve(result);
|
|
1097
|
-
this.emit('completed', result);
|
|
1098
|
-
}
|
|
1099
|
-
catch (error) {
|
|
1100
|
-
if (error instanceof TimeoutError && !options.throwOnTimeout) {
|
|
1101
|
-
resolve();
|
|
1102
|
-
return;
|
|
1103
|
-
}
|
|
1104
|
-
reject(error);
|
|
1105
|
-
this.emit('error', error);
|
|
1106
|
-
}
|
|
1107
|
-
finally {
|
|
1108
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_next).call(this);
|
|
1109
|
-
}
|
|
1110
|
-
}, options);
|
|
1111
|
-
this.emit('add');
|
|
1112
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_tryToStartAnother).call(this);
|
|
1113
|
-
});
|
|
1114
|
-
}
|
|
1115
|
-
async addAll(functions, options) {
|
|
1116
|
-
return Promise.all(functions.map(async (function_) => this.add(function_, options)));
|
|
1117
|
-
}
|
|
1118
|
-
/**
|
|
1119
|
-
Start (or resume) executing enqueued tasks within concurrency limit. No need to call this if queue is not paused (via `options.autoStart = false` or by `.pause()` method.)
|
|
1120
|
-
*/
|
|
1121
|
-
start() {
|
|
1122
|
-
if (!__classPrivateFieldGet(this, _PQueue_isPaused, "f")) {
|
|
1123
|
-
return this;
|
|
1124
|
-
}
|
|
1125
|
-
__classPrivateFieldSet(this, _PQueue_isPaused, false, "f");
|
|
1126
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_processQueue).call(this);
|
|
1127
|
-
return this;
|
|
1128
|
-
}
|
|
1129
|
-
/**
|
|
1130
|
-
Put queue execution on hold.
|
|
1131
|
-
*/
|
|
1132
|
-
pause() {
|
|
1133
|
-
__classPrivateFieldSet(this, _PQueue_isPaused, true, "f");
|
|
1134
|
-
}
|
|
1135
|
-
/**
|
|
1136
|
-
Clear the queue.
|
|
1137
|
-
*/
|
|
1138
|
-
clear() {
|
|
1139
|
-
__classPrivateFieldSet(this, _PQueue_queue, new (__classPrivateFieldGet(this, _PQueue_queueClass, "f"))(), "f");
|
|
1140
|
-
}
|
|
1141
|
-
/**
|
|
1142
|
-
Can be called multiple times. Useful if you for example add additional items at a later time.
|
|
1143
|
-
|
|
1144
|
-
@returns A promise that settles when the queue becomes empty.
|
|
1145
|
-
*/
|
|
1146
|
-
async onEmpty() {
|
|
1147
|
-
// Instantly resolve if the queue is empty
|
|
1148
|
-
if (__classPrivateFieldGet(this, _PQueue_queue, "f").size === 0) {
|
|
1149
|
-
return;
|
|
1150
|
-
}
|
|
1151
|
-
await __classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_onEvent).call(this, 'empty');
|
|
1152
|
-
}
|
|
1153
|
-
/**
|
|
1154
|
-
@returns A promise that settles when the queue size is less than the given limit: `queue.size < limit`.
|
|
1155
|
-
|
|
1156
|
-
If you want to avoid having the queue grow beyond a certain size you can `await queue.onSizeLessThan()` before adding a new item.
|
|
1157
|
-
|
|
1158
|
-
Note that this only limits the number of items waiting to start. There could still be up to `concurrency` jobs already running that this call does not include in its calculation.
|
|
1159
|
-
*/
|
|
1160
|
-
async onSizeLessThan(limit) {
|
|
1161
|
-
// Instantly resolve if the queue is empty.
|
|
1162
|
-
if (__classPrivateFieldGet(this, _PQueue_queue, "f").size < limit) {
|
|
1163
|
-
return;
|
|
1164
|
-
}
|
|
1165
|
-
await __classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_onEvent).call(this, 'next', () => __classPrivateFieldGet(this, _PQueue_queue, "f").size < limit);
|
|
1166
|
-
}
|
|
1167
|
-
/**
|
|
1168
|
-
The difference with `.onEmpty` is that `.onIdle` guarantees that all work from the queue has finished. `.onEmpty` merely signals that the queue is empty, but it could mean that some promises haven't completed yet.
|
|
1169
|
-
|
|
1170
|
-
@returns A promise that settles when the queue becomes empty, and all promises have completed; `queue.size === 0 && queue.pending === 0`.
|
|
1171
|
-
*/
|
|
1172
|
-
async onIdle() {
|
|
1173
|
-
// Instantly resolve if none pending and if nothing else is queued
|
|
1174
|
-
if (__classPrivateFieldGet(this, _PQueue_pending, "f") === 0 && __classPrivateFieldGet(this, _PQueue_queue, "f").size === 0) {
|
|
1175
|
-
return;
|
|
1176
|
-
}
|
|
1177
|
-
await __classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_onEvent).call(this, 'idle');
|
|
1178
|
-
}
|
|
1179
|
-
/**
|
|
1180
|
-
Size of the queue, the number of queued items waiting to run.
|
|
1181
|
-
*/
|
|
1182
|
-
get size() {
|
|
1183
|
-
return __classPrivateFieldGet(this, _PQueue_queue, "f").size;
|
|
1184
|
-
}
|
|
1185
|
-
/**
|
|
1186
|
-
Size of the queue, filtered by the given options.
|
|
1187
|
-
|
|
1188
|
-
For example, this can be used to find the number of items remaining in the queue with a specific priority level.
|
|
1189
|
-
*/
|
|
1190
|
-
sizeBy(options) {
|
|
1191
|
-
// eslint-disable-next-line unicorn/no-array-callback-reference
|
|
1192
|
-
return __classPrivateFieldGet(this, _PQueue_queue, "f").filter(options).length;
|
|
1193
|
-
}
|
|
1194
|
-
/**
|
|
1195
|
-
Number of running items (no longer in the queue).
|
|
1196
|
-
*/
|
|
1197
|
-
get pending() {
|
|
1198
|
-
return __classPrivateFieldGet(this, _PQueue_pending, "f");
|
|
1199
|
-
}
|
|
1200
|
-
/**
|
|
1201
|
-
Whether the queue is currently paused.
|
|
1202
|
-
*/
|
|
1203
|
-
get isPaused() {
|
|
1204
|
-
return __classPrivateFieldGet(this, _PQueue_isPaused, "f");
|
|
1205
|
-
}
|
|
1206
|
-
}
|
|
1207
|
-
_PQueue_carryoverConcurrencyCount = new WeakMap(), _PQueue_isIntervalIgnored = new WeakMap(), _PQueue_intervalCount = new WeakMap(), _PQueue_intervalCap = new WeakMap(), _PQueue_interval = new WeakMap(), _PQueue_intervalEnd = new WeakMap(), _PQueue_intervalId = new WeakMap(), _PQueue_timeoutId = new WeakMap(), _PQueue_queue = new WeakMap(), _PQueue_queueClass = new WeakMap(), _PQueue_pending = new WeakMap(), _PQueue_concurrency = new WeakMap(), _PQueue_isPaused = new WeakMap(), _PQueue_throwOnTimeout = new WeakMap(), _PQueue_instances = new WeakSet(), _PQueue_doesIntervalAllowAnother_get = function _PQueue_doesIntervalAllowAnother_get() {
|
|
1208
|
-
return __classPrivateFieldGet(this, _PQueue_isIntervalIgnored, "f") || __classPrivateFieldGet(this, _PQueue_intervalCount, "f") < __classPrivateFieldGet(this, _PQueue_intervalCap, "f");
|
|
1209
|
-
}, _PQueue_doesConcurrentAllowAnother_get = function _PQueue_doesConcurrentAllowAnother_get() {
|
|
1210
|
-
return __classPrivateFieldGet(this, _PQueue_pending, "f") < __classPrivateFieldGet(this, _PQueue_concurrency, "f");
|
|
1211
|
-
}, _PQueue_next = function _PQueue_next() {
|
|
1212
|
-
var _a;
|
|
1213
|
-
__classPrivateFieldSet(this, _PQueue_pending, (_a = __classPrivateFieldGet(this, _PQueue_pending, "f"), _a--, _a), "f");
|
|
1214
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_tryToStartAnother).call(this);
|
|
1215
|
-
this.emit('next');
|
|
1216
|
-
}, _PQueue_onResumeInterval = function _PQueue_onResumeInterval() {
|
|
1217
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_onInterval).call(this);
|
|
1218
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_initializeIntervalIfNeeded).call(this);
|
|
1219
|
-
__classPrivateFieldSet(this, _PQueue_timeoutId, undefined, "f");
|
|
1220
|
-
}, _PQueue_isIntervalPaused_get = function _PQueue_isIntervalPaused_get() {
|
|
1221
|
-
const now = Date.now();
|
|
1222
|
-
if (__classPrivateFieldGet(this, _PQueue_intervalId, "f") === undefined) {
|
|
1223
|
-
const delay = __classPrivateFieldGet(this, _PQueue_intervalEnd, "f") - now;
|
|
1224
|
-
if (delay < 0) {
|
|
1225
|
-
// Act as the interval was done
|
|
1226
|
-
// We don't need to resume it here because it will be resumed on line 160
|
|
1227
|
-
__classPrivateFieldSet(this, _PQueue_intervalCount, (__classPrivateFieldGet(this, _PQueue_carryoverConcurrencyCount, "f")) ? __classPrivateFieldGet(this, _PQueue_pending, "f") : 0, "f");
|
|
1228
|
-
}
|
|
1229
|
-
else {
|
|
1230
|
-
// Act as the interval is pending
|
|
1231
|
-
if (__classPrivateFieldGet(this, _PQueue_timeoutId, "f") === undefined) {
|
|
1232
|
-
__classPrivateFieldSet(this, _PQueue_timeoutId, setTimeout(() => {
|
|
1233
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_onResumeInterval).call(this);
|
|
1234
|
-
}, delay), "f");
|
|
1235
|
-
}
|
|
1236
|
-
return true;
|
|
1237
|
-
}
|
|
1238
|
-
}
|
|
1239
|
-
return false;
|
|
1240
|
-
}, _PQueue_tryToStartAnother = function _PQueue_tryToStartAnother() {
|
|
1241
|
-
if (__classPrivateFieldGet(this, _PQueue_queue, "f").size === 0) {
|
|
1242
|
-
// We can clear the interval ("pause")
|
|
1243
|
-
// Because we can redo it later ("resume")
|
|
1244
|
-
if (__classPrivateFieldGet(this, _PQueue_intervalId, "f")) {
|
|
1245
|
-
clearInterval(__classPrivateFieldGet(this, _PQueue_intervalId, "f"));
|
|
1246
|
-
}
|
|
1247
|
-
__classPrivateFieldSet(this, _PQueue_intervalId, undefined, "f");
|
|
1248
|
-
this.emit('empty');
|
|
1249
|
-
if (__classPrivateFieldGet(this, _PQueue_pending, "f") === 0) {
|
|
1250
|
-
this.emit('idle');
|
|
1251
|
-
}
|
|
1252
|
-
return false;
|
|
1253
|
-
}
|
|
1254
|
-
if (!__classPrivateFieldGet(this, _PQueue_isPaused, "f")) {
|
|
1255
|
-
const canInitializeInterval = !__classPrivateFieldGet(this, _PQueue_instances, "a", _PQueue_isIntervalPaused_get);
|
|
1256
|
-
if (__classPrivateFieldGet(this, _PQueue_instances, "a", _PQueue_doesIntervalAllowAnother_get) && __classPrivateFieldGet(this, _PQueue_instances, "a", _PQueue_doesConcurrentAllowAnother_get)) {
|
|
1257
|
-
const job = __classPrivateFieldGet(this, _PQueue_queue, "f").dequeue();
|
|
1258
|
-
if (!job) {
|
|
1259
|
-
return false;
|
|
1260
|
-
}
|
|
1261
|
-
this.emit('active');
|
|
1262
|
-
job();
|
|
1263
|
-
if (canInitializeInterval) {
|
|
1264
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_initializeIntervalIfNeeded).call(this);
|
|
1265
|
-
}
|
|
1266
|
-
return true;
|
|
1267
|
-
}
|
|
1268
|
-
}
|
|
1269
|
-
return false;
|
|
1270
|
-
}, _PQueue_initializeIntervalIfNeeded = function _PQueue_initializeIntervalIfNeeded() {
|
|
1271
|
-
if (__classPrivateFieldGet(this, _PQueue_isIntervalIgnored, "f") || __classPrivateFieldGet(this, _PQueue_intervalId, "f") !== undefined) {
|
|
1272
|
-
return;
|
|
1273
|
-
}
|
|
1274
|
-
__classPrivateFieldSet(this, _PQueue_intervalId, setInterval(() => {
|
|
1275
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_onInterval).call(this);
|
|
1276
|
-
}, __classPrivateFieldGet(this, _PQueue_interval, "f")), "f");
|
|
1277
|
-
__classPrivateFieldSet(this, _PQueue_intervalEnd, Date.now() + __classPrivateFieldGet(this, _PQueue_interval, "f"), "f");
|
|
1278
|
-
}, _PQueue_onInterval = function _PQueue_onInterval() {
|
|
1279
|
-
if (__classPrivateFieldGet(this, _PQueue_intervalCount, "f") === 0 && __classPrivateFieldGet(this, _PQueue_pending, "f") === 0 && __classPrivateFieldGet(this, _PQueue_intervalId, "f")) {
|
|
1280
|
-
clearInterval(__classPrivateFieldGet(this, _PQueue_intervalId, "f"));
|
|
1281
|
-
__classPrivateFieldSet(this, _PQueue_intervalId, undefined, "f");
|
|
1282
|
-
}
|
|
1283
|
-
__classPrivateFieldSet(this, _PQueue_intervalCount, __classPrivateFieldGet(this, _PQueue_carryoverConcurrencyCount, "f") ? __classPrivateFieldGet(this, _PQueue_pending, "f") : 0, "f");
|
|
1284
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_processQueue).call(this);
|
|
1285
|
-
}, _PQueue_processQueue = function _PQueue_processQueue() {
|
|
1286
|
-
// eslint-disable-next-line no-empty
|
|
1287
|
-
while (__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_tryToStartAnother).call(this)) { }
|
|
1288
|
-
}, _PQueue_throwOnAbort = async function _PQueue_throwOnAbort(signal) {
|
|
1289
|
-
return new Promise((_resolve, reject) => {
|
|
1290
|
-
signal.addEventListener('abort', () => {
|
|
1291
|
-
// TODO: Reject with signal.throwIfAborted() when targeting Node.js 18
|
|
1292
|
-
// TODO: Use ABORT_ERR code when targeting Node.js 16 (https://nodejs.org/docs/latest-v16.x/api/errors.html#abort_err)
|
|
1293
|
-
reject(new AbortError('The task was aborted.'));
|
|
1294
|
-
}, { once: true });
|
|
1295
|
-
});
|
|
1296
|
-
}, _PQueue_onEvent = async function _PQueue_onEvent(event, filter) {
|
|
1297
|
-
return new Promise(resolve => {
|
|
1298
|
-
const listener = () => {
|
|
1299
|
-
if (filter && !filter()) {
|
|
1300
|
-
return;
|
|
1301
|
-
}
|
|
1302
|
-
this.off(event, listener);
|
|
1303
|
-
resolve();
|
|
1304
|
-
};
|
|
1305
|
-
this.on(event, listener);
|
|
1306
|
-
});
|
|
1307
|
-
};
|
|
1308
|
-
|
|
1309
474
|
const limit = 1800;
|
|
1310
475
|
const transactionLimit = 1800;
|
|
1311
476
|
const requestTimeout = 30000;
|
|
1312
477
|
const syncTimeout = 30000;
|
|
1313
478
|
class Protocol {
|
|
1314
|
-
|
|
1315
|
-
|
|
479
|
+
constructor() {
|
|
480
|
+
this.resolveTimeout = 30000;
|
|
481
|
+
}
|
|
1316
482
|
get limit() {
|
|
1317
483
|
return limit;
|
|
1318
484
|
}
|
|
@@ -1634,11 +800,12 @@ class EasyWorker {
|
|
|
1634
800
|
|
|
1635
801
|
// import State from './state'
|
|
1636
802
|
class Machine {
|
|
1637
|
-
|
|
1638
|
-
#
|
|
1639
|
-
#nonces = {};
|
|
1640
|
-
lastBlock = { index: 0, hash: '0x0', previousHash: '0x0' };
|
|
803
|
+
#contracts;
|
|
804
|
+
#nonces;
|
|
1641
805
|
constructor(blocks) {
|
|
806
|
+
this.#contracts = {};
|
|
807
|
+
this.#nonces = {};
|
|
808
|
+
this.lastBlock = { index: 0, hash: '0x0', previousHash: '0x0' };
|
|
1642
809
|
// @ts-ignore
|
|
1643
810
|
return this.#init(blocks);
|
|
1644
811
|
}
|
|
@@ -1852,10 +1019,8 @@ class Machine {
|
|
|
1852
1019
|
}
|
|
1853
1020
|
|
|
1854
1021
|
class Jobber {
|
|
1855
|
-
timeout;
|
|
1856
|
-
busy = false;
|
|
1857
|
-
stop;
|
|
1858
1022
|
constructor(timeout) {
|
|
1023
|
+
this.busy = false;
|
|
1859
1024
|
this.timeout = timeout;
|
|
1860
1025
|
}
|
|
1861
1026
|
add(fn) {
|
|
@@ -1877,24 +1042,22 @@ class Jobber {
|
|
|
1877
1042
|
}
|
|
1878
1043
|
}
|
|
1879
1044
|
|
|
1880
|
-
new PQueue({ concurrency: 1, throwOnTimeout: true });
|
|
1881
1045
|
class State extends Contract {
|
|
1882
1046
|
#resolveErrored;
|
|
1883
1047
|
#lastResolvedTime;
|
|
1884
1048
|
#lastResolved;
|
|
1885
|
-
#resolving
|
|
1886
|
-
#resolveErrorCount
|
|
1049
|
+
#resolving;
|
|
1050
|
+
#resolveErrorCount;
|
|
1887
1051
|
#syncState;
|
|
1888
1052
|
#lastBlockInQue;
|
|
1889
|
-
#syncErrorCount
|
|
1890
|
-
#blockHashMap
|
|
1891
|
-
#chainSyncing
|
|
1892
|
-
#lastBlock
|
|
1893
|
-
#blocks
|
|
1894
|
-
|
|
1895
|
-
#totalSize = 0;
|
|
1053
|
+
#syncErrorCount;
|
|
1054
|
+
#blockHashMap;
|
|
1055
|
+
#chainSyncing;
|
|
1056
|
+
#lastBlock;
|
|
1057
|
+
#blocks;
|
|
1058
|
+
#totalSize;
|
|
1896
1059
|
#machine;
|
|
1897
|
-
#loaded
|
|
1060
|
+
#loaded;
|
|
1898
1061
|
get blockHashMap() {
|
|
1899
1062
|
return this.#blockHashMap.entries();
|
|
1900
1063
|
}
|
|
@@ -1907,26 +1070,26 @@ class State extends Contract {
|
|
|
1907
1070
|
/**
|
|
1908
1071
|
* amount the native token has been iteracted with
|
|
1909
1072
|
*/
|
|
1910
|
-
#nativeCalls
|
|
1073
|
+
#nativeCalls;
|
|
1911
1074
|
/**
|
|
1912
1075
|
* amount the native token has been iteracted with
|
|
1913
1076
|
*/
|
|
1914
|
-
#nativeTransfers
|
|
1077
|
+
#nativeTransfers;
|
|
1915
1078
|
/**
|
|
1916
1079
|
* amount of native token burned
|
|
1917
1080
|
* {Number}
|
|
1918
1081
|
*/
|
|
1919
|
-
#nativeBurns
|
|
1082
|
+
#nativeBurns;
|
|
1920
1083
|
/**
|
|
1921
1084
|
* amount of native tokens minted
|
|
1922
1085
|
* {Number}
|
|
1923
1086
|
*/
|
|
1924
|
-
#nativeMints
|
|
1087
|
+
#nativeMints;
|
|
1925
1088
|
/**
|
|
1926
1089
|
* total amount of transactions
|
|
1927
1090
|
* {Number}
|
|
1928
1091
|
*/
|
|
1929
|
-
#totalTransactions
|
|
1092
|
+
#totalTransactions;
|
|
1930
1093
|
get nativeMints() {
|
|
1931
1094
|
return this.#nativeMints;
|
|
1932
1095
|
}
|
|
@@ -1956,6 +1119,46 @@ class State extends Contract {
|
|
|
1956
1119
|
}
|
|
1957
1120
|
constructor() {
|
|
1958
1121
|
super();
|
|
1122
|
+
this.#resolving = false;
|
|
1123
|
+
this.#resolveErrorCount = 0;
|
|
1124
|
+
this.#syncErrorCount = 0;
|
|
1125
|
+
this.#blockHashMap = new Map();
|
|
1126
|
+
this.#chainSyncing = false;
|
|
1127
|
+
this.#lastBlock = { index: 0, hash: '0x0', previousHash: '0x0' };
|
|
1128
|
+
this.#blocks = [];
|
|
1129
|
+
this.knownBlocks = [];
|
|
1130
|
+
this.#totalSize = 0;
|
|
1131
|
+
this.#loaded = false;
|
|
1132
|
+
/**
|
|
1133
|
+
* amount the native token has been iteracted with
|
|
1134
|
+
*/
|
|
1135
|
+
this.#nativeCalls = 0;
|
|
1136
|
+
/**
|
|
1137
|
+
* amount the native token has been iteracted with
|
|
1138
|
+
*/
|
|
1139
|
+
this.#nativeTransfers = 0;
|
|
1140
|
+
/**
|
|
1141
|
+
* amount of native token burned
|
|
1142
|
+
* {Number}
|
|
1143
|
+
*/
|
|
1144
|
+
this.#nativeBurns = 0;
|
|
1145
|
+
/**
|
|
1146
|
+
* amount of native tokens minted
|
|
1147
|
+
* {Number}
|
|
1148
|
+
*/
|
|
1149
|
+
this.#nativeMints = 0;
|
|
1150
|
+
/**
|
|
1151
|
+
* total amount of transactions
|
|
1152
|
+
* {Number}
|
|
1153
|
+
*/
|
|
1154
|
+
this.#totalTransactions = 0;
|
|
1155
|
+
this.#loadBlockTransactions = (transactions) => Promise.all(transactions.map((transaction) => new TransactionMessage(transaction)));
|
|
1156
|
+
this.#getLastTransactions = async () => {
|
|
1157
|
+
let lastTransactions = (await Promise.all(this.#blocks.filter(block => block.loaded).slice(-128)
|
|
1158
|
+
.map(block => this.#loadBlockTransactions(block.transactions))))
|
|
1159
|
+
.reduce((all, transactions) => [...all, ...transactions], []);
|
|
1160
|
+
return Promise.all(lastTransactions.map(transaction => transaction.hash()));
|
|
1161
|
+
};
|
|
1959
1162
|
}
|
|
1960
1163
|
async init() {
|
|
1961
1164
|
this.jobber = new Jobber(30000);
|
|
@@ -2119,7 +1322,6 @@ class State extends Contract {
|
|
|
2119
1322
|
catch (error) {
|
|
2120
1323
|
console.error(error);
|
|
2121
1324
|
}
|
|
2122
|
-
// await queue.clear()
|
|
2123
1325
|
this.#chainSyncing = true;
|
|
2124
1326
|
if (!lastBlock)
|
|
2125
1327
|
lastBlock = await this.#getLatestBlock();
|
|
@@ -2216,13 +1418,8 @@ class State extends Contract {
|
|
|
2216
1418
|
}
|
|
2217
1419
|
return latest;
|
|
2218
1420
|
}
|
|
2219
|
-
#loadBlockTransactions
|
|
2220
|
-
#getLastTransactions
|
|
2221
|
-
let lastTransactions = (await Promise.all(this.#blocks.filter(block => block.loaded).slice(-128)
|
|
2222
|
-
.map(block => this.#loadBlockTransactions(block.transactions))))
|
|
2223
|
-
.reduce((all, transactions) => [...all, ...transactions], []);
|
|
2224
|
-
return Promise.all(lastTransactions.map(transaction => transaction.hash()));
|
|
2225
|
-
};
|
|
1421
|
+
#loadBlockTransactions;
|
|
1422
|
+
#getLastTransactions;
|
|
2226
1423
|
/**
|
|
2227
1424
|
*
|
|
2228
1425
|
* @param {Block[]} blocks
|
|
@@ -2234,8 +1431,8 @@ class State extends Contract {
|
|
|
2234
1431
|
if (block.index === 0)
|
|
2235
1432
|
this.#loaded = true;
|
|
2236
1433
|
const transactions = await this.#loadBlockTransactions([...block.transactions] || []);
|
|
1434
|
+
const lastTransactions = await this.#getLastTransactions();
|
|
2237
1435
|
for (const transaction of transactions) {
|
|
2238
|
-
const lastTransactions = await this.#getLastTransactions();
|
|
2239
1436
|
const hash = await transaction.hash();
|
|
2240
1437
|
if (poolTransactionKeys.includes(hash))
|
|
2241
1438
|
await globalThis.transactionPoolStore.delete(hash);
|
|
@@ -2318,18 +1515,25 @@ const ignorelist = ['BA5XUACBBBAT653LT3GHP2Z5SUHVCA42BP6IBFBJACHOZIHHR4DUPG2XMB'
|
|
|
2318
1515
|
// check if browser or local
|
|
2319
1516
|
class Chain extends State {
|
|
2320
1517
|
#state;
|
|
2321
|
-
#slotTime
|
|
2322
|
-
id;
|
|
2323
|
-
utils = {};
|
|
1518
|
+
#slotTime;
|
|
2324
1519
|
/** {Address[]} */
|
|
2325
|
-
#validators
|
|
1520
|
+
#validators;
|
|
2326
1521
|
/** {Boolean} */
|
|
2327
|
-
#runningEpoch
|
|
2328
|
-
#participants
|
|
2329
|
-
#participating
|
|
2330
|
-
#jail
|
|
1522
|
+
#runningEpoch;
|
|
1523
|
+
#participants;
|
|
1524
|
+
#participating;
|
|
1525
|
+
#jail;
|
|
2331
1526
|
constructor() {
|
|
2332
1527
|
super();
|
|
1528
|
+
this.#slotTime = 10000;
|
|
1529
|
+
this.utils = {};
|
|
1530
|
+
/** {Address[]} */
|
|
1531
|
+
this.#validators = [];
|
|
1532
|
+
/** {Boolean} */
|
|
1533
|
+
this.#runningEpoch = false;
|
|
1534
|
+
this.#participants = [];
|
|
1535
|
+
this.#participating = false;
|
|
1536
|
+
this.#jail = [];
|
|
2333
1537
|
// @ts-ignore
|
|
2334
1538
|
return this.#init();
|
|
2335
1539
|
}
|
|
@@ -2573,7 +1777,7 @@ class Chain extends State {
|
|
|
2573
1777
|
await this.#runEpoch();
|
|
2574
1778
|
}
|
|
2575
1779
|
// todo filter tx that need to wait on prev nonce
|
|
2576
|
-
async #createBlock(limit =
|
|
1780
|
+
async #createBlock(limit = this.transactionLimit) {
|
|
2577
1781
|
// vote for transactions
|
|
2578
1782
|
if (await globalThis.transactionPoolStore.size() === 0)
|
|
2579
1783
|
return;
|
|
@@ -2630,6 +1834,7 @@ class Chain extends State {
|
|
|
2630
1834
|
console.log(await globalThis.transactionPoolStore.has(e.hash));
|
|
2631
1835
|
}
|
|
2632
1836
|
}
|
|
1837
|
+
console.log(block.transactions.length);
|
|
2633
1838
|
// don't add empty block
|
|
2634
1839
|
if (block.transactions.length === 0)
|
|
2635
1840
|
return;
|