@acala-network/chopsticks 0.3.7 → 0.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HeadState = exports.randomId = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
4
5
|
const util_1 = require("@polkadot/util");
|
|
5
6
|
const logger_1 = require("../logger");
|
|
6
7
|
const randomId = () => Math.random().toString(36).substring(2);
|
|
@@ -46,23 +47,27 @@ class HeadState {
|
|
|
46
47
|
async setHead(head) {
|
|
47
48
|
this.#head = head;
|
|
48
49
|
for (const cb of Object.values(this.#headListeners)) {
|
|
49
|
-
|
|
50
|
-
cb(head);
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
logger.error(error, 'callback');
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
const diff = await this.#head.storageDiff();
|
|
57
|
-
for (const [keys, cb] of Object.values(this.#storageListeners)) {
|
|
58
|
-
const changed = keys.filter((key) => diff[key]).map((key) => [key, diff[key]]);
|
|
59
|
-
if (changed.length > 0) {
|
|
50
|
+
rxjs_1.asapScheduler.schedule(() => {
|
|
60
51
|
try {
|
|
61
|
-
cb(head
|
|
52
|
+
cb(head);
|
|
62
53
|
}
|
|
63
54
|
catch (error) {
|
|
64
55
|
logger.error(error, 'callback');
|
|
65
56
|
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const diff = await this.#head.storageDiff();
|
|
60
|
+
for (const [keys, cb] of Object.values(this.#storageListeners)) {
|
|
61
|
+
const changed = keys.filter((key) => diff[key]).map((key) => [key, diff[key]]);
|
|
62
|
+
if (changed.length > 0) {
|
|
63
|
+
rxjs_1.asapScheduler.schedule(() => {
|
|
64
|
+
try {
|
|
65
|
+
cb(head, changed);
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
logger.error(error, 'callback');
|
|
69
|
+
}
|
|
70
|
+
});
|
|
66
71
|
}
|
|
67
72
|
}
|
|
68
73
|
Object.assign(this.#oldValues, diff);
|
|
@@ -35,7 +35,7 @@ export declare class Blockchain {
|
|
|
35
35
|
setHead(block: Block): Promise<void>;
|
|
36
36
|
submitExtrinsic(extrinsic: HexString): Promise<HexString>;
|
|
37
37
|
newBlock(params?: BuildBlockParams): Promise<Block>;
|
|
38
|
-
upcomingBlock(
|
|
38
|
+
upcomingBlock(skipCount?: number): Promise<Block>;
|
|
39
39
|
dryRunExtrinsic(extrinsic: HexString | {
|
|
40
40
|
call: HexString;
|
|
41
41
|
address: string;
|
package/dist/blockchain/index.js
CHANGED
|
@@ -119,8 +119,8 @@ class Blockchain {
|
|
|
119
119
|
await this.#txpool.buildBlock(params);
|
|
120
120
|
return this.#head;
|
|
121
121
|
}
|
|
122
|
-
async upcomingBlock(
|
|
123
|
-
return this.#txpool.upcomingBlock(
|
|
122
|
+
async upcomingBlock(skipCount = 0) {
|
|
123
|
+
return this.#txpool.upcomingBlock(skipCount);
|
|
124
124
|
}
|
|
125
125
|
async dryRunExtrinsic(extrinsic, at) {
|
|
126
126
|
await this.api.isReady;
|
|
@@ -27,5 +27,5 @@ export declare class TxPool {
|
|
|
27
27
|
get pendingExtrinsics(): HexString[];
|
|
28
28
|
submitExtrinsic(extrinsic: HexString): void;
|
|
29
29
|
buildBlock(params?: BuildBlockParams): Promise<void>;
|
|
30
|
-
upcomingBlock(
|
|
30
|
+
upcomingBlock(skipCount?: number): Promise<Block>;
|
|
31
31
|
}
|
|
@@ -19,11 +19,11 @@ class TxPool {
|
|
|
19
19
|
#pool = [];
|
|
20
20
|
#mode;
|
|
21
21
|
#inherentProvider;
|
|
22
|
+
#last;
|
|
22
23
|
#lastBuildBlockPromise = Promise.resolve();
|
|
23
|
-
#last = new rxjs_1.ReplaySubject(1);
|
|
24
|
-
#upcoming = this.#last.pipe((0, rxjs_1.share)());
|
|
25
24
|
constructor(chain, inherentProvider, mode = BuildBlockMode.Batch) {
|
|
26
25
|
this.#chain = chain;
|
|
26
|
+
this.#last = new rxjs_1.BehaviorSubject(chain.head);
|
|
27
27
|
this.#mode = mode;
|
|
28
28
|
this.#inherentProvider = inherentProvider;
|
|
29
29
|
}
|
|
@@ -51,15 +51,10 @@ class TxPool {
|
|
|
51
51
|
await this.#lastBuildBlockPromise;
|
|
52
52
|
this.#last.next(this.#chain.head);
|
|
53
53
|
}
|
|
54
|
-
async upcomingBlock(
|
|
55
|
-
if (
|
|
56
|
-
throw new Error('
|
|
57
|
-
return
|
|
58
|
-
const sub = this.#upcoming.pipe((0, operators_1.skip)(count - 1)).subscribe((block) => {
|
|
59
|
-
sub.unsubscribe();
|
|
60
|
-
resolve(block);
|
|
61
|
-
});
|
|
62
|
-
});
|
|
54
|
+
async upcomingBlock(skipCount = 0) {
|
|
55
|
+
if (skipCount < 0)
|
|
56
|
+
throw new Error('skipCount needs to be greater or equal to 0');
|
|
57
|
+
return (0, rxjs_1.firstValueFrom)(this.#last.pipe((0, operators_1.skip)(1 + skipCount), (0, operators_1.take)(1)));
|
|
63
58
|
}
|
|
64
59
|
async #buildBlock(wait, params) {
|
|
65
60
|
await this.#chain.api.isReady;
|