@acala-network/chopsticks 0.5.0 → 0.5.2
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/lib/blockchain/index.js
CHANGED
|
@@ -113,7 +113,7 @@ class Blockchain {
|
|
|
113
113
|
const registry = await this.head.registry;
|
|
114
114
|
const validity = registry.createType('TransactionValidity', res.result);
|
|
115
115
|
if (validity.isOk) {
|
|
116
|
-
this.#txpool.submitExtrinsic(extrinsic);
|
|
116
|
+
await this.#txpool.submitExtrinsic(extrinsic);
|
|
117
117
|
return (0, util_crypto_1.blake2AsHex)(extrinsic, 256);
|
|
118
118
|
}
|
|
119
119
|
throw validity.asErr;
|
|
@@ -28,7 +28,8 @@ export declare class TxPool {
|
|
|
28
28
|
readonly event: EventEmitter;
|
|
29
29
|
constructor(chain: Blockchain, inherentProvider: InherentProvider, mode?: BuildBlockMode);
|
|
30
30
|
get pendingExtrinsics(): HexString[];
|
|
31
|
-
|
|
31
|
+
pendingExtrinsicsBy(address: string): HexString[];
|
|
32
|
+
submitExtrinsic(extrinsic: HexString): Promise<void>;
|
|
32
33
|
submitUpwardMessages(id: number, ump: HexString[]): void;
|
|
33
34
|
submitDownwardMessages(dmp: DownwardMessage[]): void;
|
|
34
35
|
submitHorizontalMessages(id: number, hrmp: HorizontalMessage[]): void;
|
package/lib/blockchain/txpool.js
CHANGED
|
@@ -32,12 +32,20 @@ class TxPool {
|
|
|
32
32
|
this.#inherentProvider = inherentProvider;
|
|
33
33
|
}
|
|
34
34
|
get pendingExtrinsics() {
|
|
35
|
-
return this.#pool;
|
|
35
|
+
return this.#pool.map(({ extrinsic }) => extrinsic);
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
this.#pool.
|
|
37
|
+
pendingExtrinsicsBy(address) {
|
|
38
|
+
return this.#pool.filter(({ signer }) => signer === address).map(({ extrinsic }) => extrinsic);
|
|
39
|
+
}
|
|
40
|
+
async submitExtrinsic(extrinsic) {
|
|
41
|
+
this.#pool.push({ extrinsic, signer: await this.#getSigner(extrinsic) });
|
|
39
42
|
this.#maybeBuildBlock();
|
|
40
43
|
}
|
|
44
|
+
async #getSigner(extrinsic) {
|
|
45
|
+
const registry = await this.#chain.head.registry;
|
|
46
|
+
const tx = registry.createType('GenericExtrinsic', extrinsic);
|
|
47
|
+
return tx.signer.toString();
|
|
48
|
+
}
|
|
41
49
|
submitUpwardMessages(id, ump) {
|
|
42
50
|
if (!this.#ump[id]) {
|
|
43
51
|
this.#ump[id] = [];
|
|
@@ -79,7 +87,7 @@ class TxPool {
|
|
|
79
87
|
await this.upcomingBlocks();
|
|
80
88
|
}
|
|
81
89
|
async buildBlock(params) {
|
|
82
|
-
const transactions = params?.transactions || this.#pool.splice(0);
|
|
90
|
+
const transactions = params?.transactions || this.#pool.splice(0).map(({ extrinsic }) => extrinsic);
|
|
83
91
|
const upwardMessages = params?.upwardMessages || { ...this.#ump };
|
|
84
92
|
const downwardMessages = params?.downwardMessages || this.#dmp.splice(0);
|
|
85
93
|
const horizontalMessages = params?.horizontalMessages || { ...this.#hrmp };
|
|
@@ -133,7 +141,9 @@ class TxPool {
|
|
|
133
141
|
const [newBlock, pendingExtrinsics] = await (0, block_builder_1.buildBlock)(head, inherents, params.transactions, params.upwardMessages, (extrinsic, error) => {
|
|
134
142
|
this.event.emit(exports.APPLY_EXTRINSIC_ERROR, [extrinsic, error]);
|
|
135
143
|
});
|
|
136
|
-
|
|
144
|
+
for (const extrinsic of pendingExtrinsics) {
|
|
145
|
+
this.#pool.push({ extrinsic, signer: await this.#getSigner(extrinsic) });
|
|
146
|
+
}
|
|
137
147
|
await this.#chain.setHead(newBlock);
|
|
138
148
|
this.#pendingBlocks.shift();
|
|
139
149
|
deferred.resolve();
|
|
@@ -42,7 +42,8 @@ const handlers = {
|
|
|
42
42
|
const registry = await head.registry;
|
|
43
43
|
const account = registry.createType('AccountId', address);
|
|
44
44
|
const result = await head.call('AccountNonceApi_account_nonce', [account.toHex()]);
|
|
45
|
-
|
|
45
|
+
const nonce = registry.createType('Index', (0, util_1.hexToU8a)(result.result)).toNumber();
|
|
46
|
+
return nonce + context.chain.txPool.pendingExtrinsicsBy(address).length;
|
|
46
47
|
},
|
|
47
48
|
};
|
|
48
49
|
exports.default = handlers;
|
package/package.json
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acala-network/chopsticks",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"author": "Bryan Chen <xlchen1291@gmail.com>",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"bin": "./chopsticks.js",
|
|
9
9
|
"scripts": {
|
|
10
|
-
"lint": "tsc --noEmit --project tsconfig.json && eslint . --ext .js,.ts && prettier --check .",
|
|
11
|
-
"fix": "eslint . --ext .js,.ts --fix && prettier -w .",
|
|
12
10
|
"build": "rm -rf lib && tsc -p ./tsconfig.json",
|
|
13
11
|
"test": "vitest run",
|
|
14
12
|
"test:watch": "vitest",
|
|
@@ -20,7 +18,7 @@
|
|
|
20
18
|
"dev:moonbeam": "ts-node-dev --transpile-only --inspect --notify=false src/cli.ts -- dev --config=../../configs/moonbeam.yml"
|
|
21
19
|
},
|
|
22
20
|
"dependencies": {
|
|
23
|
-
"@acala-network/chopsticks-executor": "0.5.
|
|
21
|
+
"@acala-network/chopsticks-executor": "0.5.2",
|
|
24
22
|
"@polkadot/api": "^9.14.2",
|
|
25
23
|
"@polkadot/rpc-provider": "^9.14.2",
|
|
26
24
|
"@polkadot/types": "^9.14.2",
|
|
@@ -46,16 +44,8 @@
|
|
|
46
44
|
"@types/js-yaml": "^4.0.5",
|
|
47
45
|
"@types/lodash": "^4.14.191",
|
|
48
46
|
"@types/node": "^18.14.2",
|
|
49
|
-
"@types/prettier": "^2.7.2",
|
|
50
47
|
"@types/ws": "^8.5.4",
|
|
51
48
|
"@types/yargs": "^17.0.22",
|
|
52
|
-
"@typescript-eslint/eslint-plugin": "^5.54.0",
|
|
53
|
-
"@typescript-eslint/parser": "^5.53.0",
|
|
54
|
-
"eslint": "^8.34.0",
|
|
55
|
-
"eslint-config-prettier": "^8.6.0",
|
|
56
|
-
"eslint-plugin-import": "^2.27.5",
|
|
57
|
-
"eslint-plugin-sort-imports-es6-autofix": "^0.6.0",
|
|
58
|
-
"prettier": "^2.8.4",
|
|
59
49
|
"ts-node": "^10.9.1",
|
|
60
50
|
"ts-node-dev": "^2.0.0",
|
|
61
51
|
"typescript": "^4.9.5",
|