@acala-network/chopsticks 0.7.2 → 0.8.0-0
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/cli-options.d.ts +40 -0
- package/lib/cli-options.js +43 -0
- package/lib/cli.d.ts +1 -2
- package/lib/cli.js +20 -183
- package/lib/context.d.ts +5 -0
- package/lib/context.js +37 -0
- package/lib/index.d.ts +2 -7
- package/lib/index.js +4 -15
- package/lib/logger.d.ts +1 -7
- package/lib/logger.js +3 -38
- package/lib/plugins/decode-key/index.d.ts +2 -0
- package/lib/plugins/decode-key/index.js +27 -0
- package/lib/plugins/dry-run/cli.d.ts +2 -0
- package/lib/plugins/dry-run/cli.js +46 -0
- package/lib/plugins/dry-run/dry-run-extrinsic.d.ts +2 -0
- package/lib/{dry-run.js → plugins/dry-run/dry-run-extrinsic.js} +8 -8
- package/lib/{dry-run-preimage.d.ts → plugins/dry-run/dry-run-preimage.d.ts} +1 -1
- package/lib/{dry-run-preimage.js → plugins/dry-run/dry-run-preimage.js} +10 -12
- package/lib/plugins/dry-run/index.d.ts +2 -0
- package/lib/plugins/dry-run/index.js +18 -0
- package/lib/plugins/dry-run/rpc.d.ts +3 -0
- package/lib/{rpc/dev/dry-run.js → plugins/dry-run/rpc.js} +10 -7
- package/lib/plugins/index.d.ts +4 -0
- package/lib/plugins/index.js +52 -0
- package/lib/plugins/new-block/index.d.ts +2 -0
- package/lib/plugins/new-block/index.js +28 -0
- package/lib/plugins/run-block/index.d.ts +2 -0
- package/lib/plugins/run-block/index.js +67 -0
- package/lib/plugins/set-block-build-mode/index.d.ts +2 -0
- package/lib/plugins/set-block-build-mode/index.js +14 -0
- package/lib/plugins/set-head/index.d.ts +2 -0
- package/lib/plugins/set-head/index.js +20 -0
- package/lib/plugins/set-storage/index.d.ts +2 -0
- package/lib/plugins/set-storage/index.js +18 -0
- package/lib/plugins/time-travel/index.d.ts +2 -0
- package/lib/plugins/time-travel/index.js +13 -0
- package/lib/plugins/try-runtime/index.d.ts +2 -0
- package/lib/plugins/try-runtime/index.js +58 -0
- package/lib/rpc/index.d.ts +1 -1
- package/lib/rpc/index.js +11 -4
- package/lib/rpc/shared.d.ts +1 -1
- package/lib/rpc/shared.js +1 -1
- package/lib/rpc/substrate/author.js +3 -3
- package/lib/schema/index.d.ts +9 -66
- package/lib/schema/index.js +41 -14
- package/lib/server.js +2 -1
- package/lib/setup-with-server.d.ts +1 -3
- package/lib/setup-with-server.js +2 -2
- package/lib/utils/decoder.d.ts +1 -1
- package/lib/utils/generate-html-diff.d.ts +1 -1
- package/lib/utils/override.d.ts +4 -0
- package/lib/utils/{import-storage.js → override.js} +6 -6
- package/package.json +13 -16
- package/lib/api.d.ts +0 -43
- package/lib/api.js +0 -79
- package/lib/blockchain/block-builder.d.ts +0 -10
- package/lib/blockchain/block-builder.js +0 -297
- package/lib/blockchain/block.d.ts +0 -45
- package/lib/blockchain/block.js +0 -194
- package/lib/blockchain/head-state.d.ts +0 -15
- package/lib/blockchain/head-state.js +0 -71
- package/lib/blockchain/index.d.ts +0 -64
- package/lib/blockchain/index.js +0 -243
- package/lib/blockchain/inherent/index.d.ts +0 -19
- package/lib/blockchain/inherent/index.js +0 -36
- package/lib/blockchain/inherent/para-enter.d.ts +0 -7
- package/lib/blockchain/inherent/para-enter.js +0 -33
- package/lib/blockchain/inherent/parachain/babe-randomness.d.ts +0 -7
- package/lib/blockchain/inherent/parachain/babe-randomness.js +0 -15
- package/lib/blockchain/inherent/parachain/nimbus-author-inherent.d.ts +0 -7
- package/lib/blockchain/inherent/parachain/nimbus-author-inherent.js +0 -15
- package/lib/blockchain/inherent/parachain/validation-data.d.ts +0 -19
- package/lib/blockchain/inherent/parachain/validation-data.js +0 -172
- package/lib/blockchain/storage-layer.d.ts +0 -32
- package/lib/blockchain/storage-layer.js +0 -200
- package/lib/blockchain/txpool.d.ts +0 -45
- package/lib/blockchain/txpool.js +0 -184
- package/lib/db/entities.d.ts +0 -5
- package/lib/db/entities.js +0 -33
- package/lib/db/index.d.ts +0 -3
- package/lib/db/index.js +0 -41
- package/lib/dry-run.d.ts +0 -2
- package/lib/executor.d.ts +0 -40
- package/lib/executor.js +0 -131
- package/lib/genesis-provider.d.ts +0 -44
- package/lib/genesis-provider.js +0 -155
- package/lib/offchain.d.ts +0 -10
- package/lib/offchain.js +0 -37
- package/lib/rpc/dev/dry-run.d.ts +0 -2
- package/lib/rpc/dev/index.d.ts +0 -3
- package/lib/rpc/dev/index.js +0 -75
- package/lib/run-block.d.ts +0 -2
- package/lib/run-block.js +0 -51
- package/lib/setup.d.ts +0 -11
- package/lib/setup.js +0 -86
- package/lib/try-runtime.d.ts +0 -2
- package/lib/try-runtime.js +0 -36
- package/lib/utils/import-storage.d.ts +0 -5
- package/lib/utils/index.d.ts +0 -16
- package/lib/utils/index.js +0 -59
- package/lib/utils/key-cache.d.ts +0 -10
- package/lib/utils/key-cache.js +0 -66
- package/lib/utils/proof.d.ts +0 -15
- package/lib/utils/proof.js +0 -41
- package/lib/utils/set-storage.d.ts +0 -7
- package/lib/utils/set-storage.js +0 -59
- package/lib/utils/time-travel.d.ts +0 -5
- package/lib/utils/time-travel.js +0 -65
- package/lib/xcm/downward.d.ts +0 -2
- package/lib/xcm/downward.js +0 -29
- package/lib/xcm/horizontal.d.ts +0 -2
- package/lib/xcm/horizontal.js +0 -29
- package/lib/xcm/index.d.ts +0 -9
- package/lib/xcm/index.js +0 -25
- package/lib/xcm/upward.d.ts +0 -2
- package/lib/xcm/upward.js +0 -21
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { Header } from '@polkadot/types/interfaces';
|
|
2
|
-
import { DecoratedMeta } from '@polkadot/types/metadata/decorate/types';
|
|
3
|
-
import { TypeRegistry } from '@polkadot/types';
|
|
4
|
-
import type { HexString } from '@polkadot/util/types';
|
|
5
|
-
import { Blockchain } from '.';
|
|
6
|
-
import { StorageLayer, StorageLayerProvider, StorageValue } from './storage-layer';
|
|
7
|
-
import type { RuntimeVersion } from '../executor';
|
|
8
|
-
export type TaskCallResponse = {
|
|
9
|
-
result: HexString;
|
|
10
|
-
storageDiff: [HexString, HexString | null][];
|
|
11
|
-
offchainStorageDiff: [HexString, HexString | null][];
|
|
12
|
-
runtimeLogs: string[];
|
|
13
|
-
};
|
|
14
|
-
export declare class Block {
|
|
15
|
-
#private;
|
|
16
|
-
readonly number: number;
|
|
17
|
-
readonly hash: HexString;
|
|
18
|
-
constructor(chain: Blockchain, number: number, hash: HexString, parentBlock?: Block, block?: {
|
|
19
|
-
header: Header;
|
|
20
|
-
extrinsics: HexString[];
|
|
21
|
-
storage?: StorageLayerProvider;
|
|
22
|
-
storageDiff?: Record<string, StorageValue | null>;
|
|
23
|
-
});
|
|
24
|
-
get chain(): Blockchain;
|
|
25
|
-
get header(): Header | Promise<Header>;
|
|
26
|
-
get extrinsics(): HexString[] | Promise<HexString[]>;
|
|
27
|
-
get parentBlock(): undefined | Block | Promise<Block | undefined>;
|
|
28
|
-
get storage(): StorageLayerProvider;
|
|
29
|
-
get(key: string): Promise<string | undefined>;
|
|
30
|
-
getKeysPaged(options: {
|
|
31
|
-
prefix?: string;
|
|
32
|
-
startKey?: string;
|
|
33
|
-
pageSize: number;
|
|
34
|
-
}): Promise<string[]>;
|
|
35
|
-
pushStorageLayer(): StorageLayer;
|
|
36
|
-
popStorageLayer(): void;
|
|
37
|
-
storageDiff(): Promise<Record<HexString, HexString | null>>;
|
|
38
|
-
get wasm(): Promise<`0x${string}`>;
|
|
39
|
-
setWasm(wasm: HexString): void;
|
|
40
|
-
get registry(): Promise<TypeRegistry>;
|
|
41
|
-
get runtimeVersion(): Promise<RuntimeVersion>;
|
|
42
|
-
get metadata(): Promise<HexString>;
|
|
43
|
-
get meta(): Promise<DecoratedMeta>;
|
|
44
|
-
call(method: string, args: HexString[]): Promise<TaskCallResponse>;
|
|
45
|
-
}
|
package/lib/blockchain/block.js
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Block = void 0;
|
|
4
|
-
const types_1 = require("@polkadot/types");
|
|
5
|
-
const metadata_1 = require("@polkadot/types/metadata");
|
|
6
|
-
const util_1 = require("@polkadot/types-known/util");
|
|
7
|
-
const util_2 = require("@polkadot/util");
|
|
8
|
-
const storage_layer_1 = require("./storage-layer");
|
|
9
|
-
const utils_1 = require("../utils");
|
|
10
|
-
const logger_1 = require("../logger");
|
|
11
|
-
const executor_1 = require("../executor");
|
|
12
|
-
class Block {
|
|
13
|
-
number;
|
|
14
|
-
hash;
|
|
15
|
-
#chain;
|
|
16
|
-
#header;
|
|
17
|
-
#parentBlock;
|
|
18
|
-
#extrinsics;
|
|
19
|
-
#wasm;
|
|
20
|
-
#runtimeVersion;
|
|
21
|
-
#metadata;
|
|
22
|
-
#registry;
|
|
23
|
-
#meta;
|
|
24
|
-
#baseStorage;
|
|
25
|
-
#storages;
|
|
26
|
-
constructor(chain, number, hash, parentBlock, block) {
|
|
27
|
-
this.number = number;
|
|
28
|
-
this.hash = hash;
|
|
29
|
-
this.#chain = chain;
|
|
30
|
-
this.#parentBlock = parentBlock;
|
|
31
|
-
this.#header = block?.header;
|
|
32
|
-
this.#extrinsics = block?.extrinsics;
|
|
33
|
-
this.#baseStorage = block?.storage ?? new storage_layer_1.RemoteStorageLayer(chain.api, hash, chain.db);
|
|
34
|
-
this.#storages = [];
|
|
35
|
-
const storageDiff = block?.storageDiff;
|
|
36
|
-
if (storageDiff) {
|
|
37
|
-
// if code doesn't change then reuse parent block's meta
|
|
38
|
-
if (!storageDiff?.[(0, util_2.stringToHex)(':code')]) {
|
|
39
|
-
this.#runtimeVersion = parentBlock?.runtimeVersion;
|
|
40
|
-
this.#metadata = parentBlock?.metadata;
|
|
41
|
-
this.#registry = parentBlock?.registry;
|
|
42
|
-
this.#meta = parentBlock?.meta;
|
|
43
|
-
}
|
|
44
|
-
this.pushStorageLayer().setAll(storageDiff);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
get chain() {
|
|
48
|
-
return this.#chain;
|
|
49
|
-
}
|
|
50
|
-
get header() {
|
|
51
|
-
if (!this.#header) {
|
|
52
|
-
this.#header = Promise.all([this.registry, this.#chain.api.getHeader(this.hash)]).then(([registry, header]) => registry.createType('Header', header));
|
|
53
|
-
}
|
|
54
|
-
return this.#header;
|
|
55
|
-
}
|
|
56
|
-
get extrinsics() {
|
|
57
|
-
if (!this.#extrinsics) {
|
|
58
|
-
this.#extrinsics = this.#chain.api.getBlock(this.hash).then((b) => b.block.extrinsics);
|
|
59
|
-
}
|
|
60
|
-
return this.#extrinsics;
|
|
61
|
-
}
|
|
62
|
-
get parentBlock() {
|
|
63
|
-
if (this.number === 0) {
|
|
64
|
-
return undefined;
|
|
65
|
-
}
|
|
66
|
-
if (!this.#parentBlock) {
|
|
67
|
-
this.#parentBlock = Promise.resolve(this.header).then((h) => this.#chain.getBlock(h.parentHash.toHex()));
|
|
68
|
-
}
|
|
69
|
-
return this.#parentBlock;
|
|
70
|
-
}
|
|
71
|
-
get storage() {
|
|
72
|
-
return this.#storages[this.#storages.length - 1] ?? this.#baseStorage;
|
|
73
|
-
}
|
|
74
|
-
async get(key) {
|
|
75
|
-
const val = await this.storage.get(key, true);
|
|
76
|
-
switch (val) {
|
|
77
|
-
case "Deleted" /* StorageValueKind.Deleted */:
|
|
78
|
-
return undefined;
|
|
79
|
-
default:
|
|
80
|
-
return val;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
async getKeysPaged(options) {
|
|
84
|
-
const layer = new storage_layer_1.StorageLayer(this.storage);
|
|
85
|
-
await layer.fold();
|
|
86
|
-
const prefix = options.prefix ?? '0x';
|
|
87
|
-
const startKey = options.startKey ?? prefix;
|
|
88
|
-
const pageSize = options.pageSize;
|
|
89
|
-
return layer.getKeysPaged(prefix, pageSize, startKey);
|
|
90
|
-
}
|
|
91
|
-
pushStorageLayer() {
|
|
92
|
-
const layer = new storage_layer_1.StorageLayer(this.storage);
|
|
93
|
-
this.#storages.push(layer);
|
|
94
|
-
return layer;
|
|
95
|
-
}
|
|
96
|
-
popStorageLayer() {
|
|
97
|
-
this.#storages.pop();
|
|
98
|
-
}
|
|
99
|
-
async storageDiff() {
|
|
100
|
-
const storage = {};
|
|
101
|
-
for (const layer of this.#storages) {
|
|
102
|
-
await layer.mergeInto(storage);
|
|
103
|
-
}
|
|
104
|
-
return storage;
|
|
105
|
-
}
|
|
106
|
-
get wasm() {
|
|
107
|
-
if (!this.#wasm) {
|
|
108
|
-
this.#wasm = (async () => {
|
|
109
|
-
const wasmKey = (0, util_2.stringToHex)(':code');
|
|
110
|
-
const wasm = await this.get(wasmKey);
|
|
111
|
-
if (!wasm) {
|
|
112
|
-
throw new Error('No wasm found');
|
|
113
|
-
}
|
|
114
|
-
return wasm;
|
|
115
|
-
})();
|
|
116
|
-
}
|
|
117
|
-
return this.#wasm;
|
|
118
|
-
}
|
|
119
|
-
setWasm(wasm) {
|
|
120
|
-
const wasmKey = (0, util_2.stringToHex)(':code');
|
|
121
|
-
this.pushStorageLayer().set(wasmKey, wasm);
|
|
122
|
-
this.#wasm = Promise.resolve(wasm);
|
|
123
|
-
this.#runtimeVersion = undefined;
|
|
124
|
-
this.#registry = undefined;
|
|
125
|
-
this.#meta = undefined;
|
|
126
|
-
this.#metadata = undefined;
|
|
127
|
-
}
|
|
128
|
-
get registry() {
|
|
129
|
-
if (!this.#registry) {
|
|
130
|
-
this.#registry = Promise.all([
|
|
131
|
-
this.metadata,
|
|
132
|
-
this.#chain.api.chainProperties,
|
|
133
|
-
this.#chain.api.chain,
|
|
134
|
-
this.runtimeVersion,
|
|
135
|
-
]).then(([data, properties, chain, version]) => {
|
|
136
|
-
const registry = new types_1.TypeRegistry(this.hash);
|
|
137
|
-
registry.setKnownTypes(this.chain.registeredTypes);
|
|
138
|
-
registry.setChainProperties(registry.createType('ChainProperties', properties));
|
|
139
|
-
registry.register((0, util_1.getSpecTypes)(registry, chain, version.specName, version.specVersion));
|
|
140
|
-
registry.setHasher((0, util_1.getSpecHasher)(registry, chain, version.specName));
|
|
141
|
-
registry.setMetadata(new types_1.Metadata(registry, data), undefined, (0, util_2.objectSpread)({}, (0, util_1.getSpecExtensions)(registry, chain, version.specName), this.#chain.api.signedExtensions));
|
|
142
|
-
return registry;
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
return this.#registry;
|
|
146
|
-
}
|
|
147
|
-
get runtimeVersion() {
|
|
148
|
-
if (!this.#runtimeVersion) {
|
|
149
|
-
this.#runtimeVersion = this.wasm.then(executor_1.getRuntimeVersion);
|
|
150
|
-
}
|
|
151
|
-
return this.#runtimeVersion;
|
|
152
|
-
}
|
|
153
|
-
get metadata() {
|
|
154
|
-
if (!this.#metadata) {
|
|
155
|
-
this.#metadata = this.call('Metadata_metadata', []).then((resp) => (0, utils_1.compactHex)((0, util_2.hexToU8a)(resp.result)));
|
|
156
|
-
}
|
|
157
|
-
return this.#metadata;
|
|
158
|
-
}
|
|
159
|
-
get meta() {
|
|
160
|
-
if (!this.#meta) {
|
|
161
|
-
this.#meta = Promise.all([this.registry, this.metadata]).then(([registry, metadataStr]) => {
|
|
162
|
-
const metadata = new types_1.Metadata(registry, metadataStr);
|
|
163
|
-
return (0, metadata_1.expandMetadata)(registry, metadata);
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
return this.#meta;
|
|
167
|
-
}
|
|
168
|
-
async call(method, args) {
|
|
169
|
-
const wasm = await this.wasm;
|
|
170
|
-
const response = await (0, executor_1.runTask)({
|
|
171
|
-
wasm,
|
|
172
|
-
calls: [[method, args]],
|
|
173
|
-
mockSignatureHost: this.#chain.mockSignatureHost,
|
|
174
|
-
allowUnresolvedImports: this.#chain.allowUnresolvedImports,
|
|
175
|
-
runtimeLogLevel: this.#chain.runtimeLogLevel,
|
|
176
|
-
}, (0, executor_1.taskHandler)(this));
|
|
177
|
-
if (response.Call) {
|
|
178
|
-
for (const log of response.Call.runtimeLogs) {
|
|
179
|
-
logger_1.defaultLogger.info(`RuntimeLogs:\n${log}`);
|
|
180
|
-
}
|
|
181
|
-
if (this.chain.offchainWorker) {
|
|
182
|
-
// apply offchain storage
|
|
183
|
-
for (const [key, value] of response.Call.offchainStorageDiff) {
|
|
184
|
-
this.chain.offchainWorker.set(key, value);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
return response.Call;
|
|
188
|
-
}
|
|
189
|
-
if (response.Error)
|
|
190
|
-
throw Error(response.Error);
|
|
191
|
-
throw Error('Unexpected response');
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
exports.Block = Block;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Block } from './block';
|
|
2
|
-
type Callback = (block: Block, pairs: [string, string][]) => void | Promise<void>;
|
|
3
|
-
export declare const randomId: () => string;
|
|
4
|
-
export declare class HeadState {
|
|
5
|
-
#private;
|
|
6
|
-
constructor(head: Block);
|
|
7
|
-
subscribeHead(cb: (block: Block) => void): string;
|
|
8
|
-
unsubscribeHead(id: string): void;
|
|
9
|
-
subscribeStorage(keys: string[], cb: Callback): Promise<string>;
|
|
10
|
-
unsubscribeStorage(id: string): void;
|
|
11
|
-
subscrubeRuntimeVersion(cb: (block: Block) => void): Promise<string>;
|
|
12
|
-
unsubscribeRuntimeVersion(id: string): void;
|
|
13
|
-
setHead(head: Block): Promise<void>;
|
|
14
|
-
}
|
|
15
|
-
export {};
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HeadState = exports.randomId = void 0;
|
|
4
|
-
const util_1 = require("@polkadot/util");
|
|
5
|
-
const logger_1 = require("../logger");
|
|
6
|
-
const randomId = () => Math.random().toString(36).substring(2);
|
|
7
|
-
exports.randomId = randomId;
|
|
8
|
-
const logger = logger_1.defaultLogger.child({ name: 'head-state' });
|
|
9
|
-
class HeadState {
|
|
10
|
-
#headListeners = {};
|
|
11
|
-
#storageListeners = {};
|
|
12
|
-
#oldValues = {};
|
|
13
|
-
#head;
|
|
14
|
-
constructor(head) {
|
|
15
|
-
this.#head = head;
|
|
16
|
-
}
|
|
17
|
-
subscribeHead(cb) {
|
|
18
|
-
const id = (0, exports.randomId)();
|
|
19
|
-
this.#headListeners[id] = cb;
|
|
20
|
-
return id;
|
|
21
|
-
}
|
|
22
|
-
unsubscribeHead(id) {
|
|
23
|
-
delete this.#headListeners[id];
|
|
24
|
-
}
|
|
25
|
-
async subscribeStorage(keys, cb) {
|
|
26
|
-
const id = (0, exports.randomId)();
|
|
27
|
-
this.#storageListeners[id] = [keys, cb];
|
|
28
|
-
for (const key of keys) {
|
|
29
|
-
this.#oldValues[key] = await this.#head.get(key);
|
|
30
|
-
}
|
|
31
|
-
return id;
|
|
32
|
-
}
|
|
33
|
-
unsubscribeStorage(id) {
|
|
34
|
-
delete this.#storageListeners[id];
|
|
35
|
-
}
|
|
36
|
-
async subscrubeRuntimeVersion(cb) {
|
|
37
|
-
const id = (0, exports.randomId)();
|
|
38
|
-
const codeKey = (0, util_1.stringToHex)(':code');
|
|
39
|
-
this.#storageListeners[id] = [[codeKey], cb];
|
|
40
|
-
this.#oldValues[codeKey] = await this.#head.get(codeKey);
|
|
41
|
-
return id;
|
|
42
|
-
}
|
|
43
|
-
unsubscribeRuntimeVersion(id) {
|
|
44
|
-
delete this.#storageListeners[id];
|
|
45
|
-
}
|
|
46
|
-
async setHead(head) {
|
|
47
|
-
this.#head = head;
|
|
48
|
-
for (const cb of Object.values(this.#headListeners)) {
|
|
49
|
-
try {
|
|
50
|
-
await cb(head);
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
logger.error(error, 'setHead head callback error');
|
|
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) {
|
|
60
|
-
try {
|
|
61
|
-
await cb(head, changed);
|
|
62
|
-
}
|
|
63
|
-
catch (error) {
|
|
64
|
-
logger.error(error, 'setHead storaeg diff callback error');
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
Object.assign(this.#oldValues, diff);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
exports.HeadState = HeadState;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { ApplyExtrinsicResult } from '@polkadot/types/interfaces';
|
|
2
|
-
import { DataSource } from 'typeorm';
|
|
3
|
-
import { HexString } from '@polkadot/util/types';
|
|
4
|
-
import { RegisteredTypes } from '@polkadot/types/types';
|
|
5
|
-
import type { TransactionValidity } from '@polkadot/types/interfaces/txqueue';
|
|
6
|
-
import { Api } from '../api';
|
|
7
|
-
import { Block } from './block';
|
|
8
|
-
import { BuildBlockMode, BuildBlockParams, DownwardMessage, HorizontalMessage, TxPool } from './txpool';
|
|
9
|
-
import { HeadState } from './head-state';
|
|
10
|
-
import { InherentProvider } from './inherent';
|
|
11
|
-
import { OffchainWorker } from '../offchain';
|
|
12
|
-
export interface Options {
|
|
13
|
-
api: Api;
|
|
14
|
-
buildBlockMode?: BuildBlockMode;
|
|
15
|
-
inherentProvider: InherentProvider;
|
|
16
|
-
db?: DataSource;
|
|
17
|
-
header: {
|
|
18
|
-
number: number;
|
|
19
|
-
hash: HexString;
|
|
20
|
-
};
|
|
21
|
-
mockSignatureHost?: boolean;
|
|
22
|
-
allowUnresolvedImports?: boolean;
|
|
23
|
-
runtimeLogLevel?: number;
|
|
24
|
-
registeredTypes: RegisteredTypes;
|
|
25
|
-
offchainWorker?: boolean;
|
|
26
|
-
}
|
|
27
|
-
export declare class Blockchain {
|
|
28
|
-
#private;
|
|
29
|
-
readonly uid: string;
|
|
30
|
-
readonly api: Api;
|
|
31
|
-
readonly db: DataSource | undefined;
|
|
32
|
-
readonly mockSignatureHost: boolean;
|
|
33
|
-
readonly allowUnresolvedImports: boolean;
|
|
34
|
-
readonly runtimeLogLevel: number;
|
|
35
|
-
readonly registeredTypes: RegisteredTypes;
|
|
36
|
-
readonly headState: HeadState;
|
|
37
|
-
readonly offchainWorker: OffchainWorker | undefined;
|
|
38
|
-
constructor({ api, buildBlockMode, inherentProvider, db, header, mockSignatureHost, allowUnresolvedImports, runtimeLogLevel, registeredTypes, offchainWorker, }: Options);
|
|
39
|
-
get head(): Block;
|
|
40
|
-
get txPool(): TxPool;
|
|
41
|
-
getBlockAt(number?: number): Promise<Block | undefined>;
|
|
42
|
-
getBlock(hash?: HexString): Promise<Block | undefined>;
|
|
43
|
-
unregisterBlock(block: Block): void;
|
|
44
|
-
setHead(block: Block): Promise<void>;
|
|
45
|
-
submitExtrinsic(extrinsic: HexString): Promise<HexString>;
|
|
46
|
-
validateExtrinsic(extrinsic: HexString, source?: '0x00' | '0x01' | '0x02' /** External */): Promise<TransactionValidity>;
|
|
47
|
-
submitUpwardMessages(id: number, ump: HexString[]): void;
|
|
48
|
-
submitDownwardMessages(dmp: DownwardMessage[]): void;
|
|
49
|
-
submitHorizontalMessages(id: number, hrmp: HorizontalMessage[]): void;
|
|
50
|
-
newBlock(params?: Partial<BuildBlockParams>): Promise<Block>;
|
|
51
|
-
newBlockWithParams(params: BuildBlockParams): Promise<Block>;
|
|
52
|
-
upcomingBlocks(): Promise<number>;
|
|
53
|
-
dryRunExtrinsic(extrinsic: HexString | {
|
|
54
|
-
call: HexString;
|
|
55
|
-
address: string;
|
|
56
|
-
}, at?: HexString): Promise<{
|
|
57
|
-
outcome: ApplyExtrinsicResult;
|
|
58
|
-
storageDiff: [HexString, HexString | null][];
|
|
59
|
-
}>;
|
|
60
|
-
dryRunHrmp(hrmp: Record<number, HorizontalMessage[]>, at?: HexString): Promise<[HexString, HexString | null][]>;
|
|
61
|
-
dryRunDmp(dmp: DownwardMessage[], at?: HexString): Promise<[HexString, HexString | null][]>;
|
|
62
|
-
dryRunUmp(ump: Record<number, HexString[]>, at?: HexString): Promise<[HexString, HexString | null][]>;
|
|
63
|
-
getInherents(): Promise<HexString[]>;
|
|
64
|
-
}
|
package/lib/blockchain/index.js
DELETED
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Blockchain = void 0;
|
|
4
|
-
const util_crypto_1 = require("@polkadot/util-crypto");
|
|
5
|
-
const util_1 = require("@polkadot/util");
|
|
6
|
-
const block_1 = require("./block");
|
|
7
|
-
const txpool_1 = require("./txpool");
|
|
8
|
-
const head_state_1 = require("./head-state");
|
|
9
|
-
const offchain_1 = require("../offchain");
|
|
10
|
-
const utils_1 = require("../utils");
|
|
11
|
-
const logger_1 = require("../logger");
|
|
12
|
-
const block_builder_1 = require("./block-builder");
|
|
13
|
-
const logger = logger_1.defaultLogger.child({ name: 'blockchain' });
|
|
14
|
-
class Blockchain {
|
|
15
|
-
uid = Math.random().toString(36).substring(2);
|
|
16
|
-
api;
|
|
17
|
-
db;
|
|
18
|
-
mockSignatureHost;
|
|
19
|
-
allowUnresolvedImports;
|
|
20
|
-
runtimeLogLevel;
|
|
21
|
-
registeredTypes;
|
|
22
|
-
#txpool;
|
|
23
|
-
#inherentProvider;
|
|
24
|
-
#head;
|
|
25
|
-
#blocksByNumber = [];
|
|
26
|
-
#blocksByHash = {};
|
|
27
|
-
#loadingBlocks = {};
|
|
28
|
-
headState;
|
|
29
|
-
offchainWorker;
|
|
30
|
-
constructor({ api, buildBlockMode, inherentProvider, db, header, mockSignatureHost = false, allowUnresolvedImports = false, runtimeLogLevel = 0, registeredTypes = {}, offchainWorker = false, }) {
|
|
31
|
-
this.api = api;
|
|
32
|
-
this.db = db;
|
|
33
|
-
this.mockSignatureHost = mockSignatureHost;
|
|
34
|
-
this.allowUnresolvedImports = allowUnresolvedImports;
|
|
35
|
-
this.runtimeLogLevel = runtimeLogLevel;
|
|
36
|
-
this.registeredTypes = registeredTypes;
|
|
37
|
-
this.#head = new block_1.Block(this, header.number, header.hash);
|
|
38
|
-
this.#registerBlock(this.#head);
|
|
39
|
-
this.#txpool = new txpool_1.TxPool(this, inherentProvider, buildBlockMode);
|
|
40
|
-
this.#inherentProvider = inherentProvider;
|
|
41
|
-
this.headState = new head_state_1.HeadState(this.#head);
|
|
42
|
-
if (offchainWorker) {
|
|
43
|
-
this.offchainWorker = new offchain_1.OffchainWorker();
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
#registerBlock(block) {
|
|
47
|
-
this.#blocksByNumber[block.number] = block;
|
|
48
|
-
this.#blocksByHash[block.hash] = block;
|
|
49
|
-
}
|
|
50
|
-
get head() {
|
|
51
|
-
return this.#head;
|
|
52
|
-
}
|
|
53
|
-
get txPool() {
|
|
54
|
-
return this.#txpool;
|
|
55
|
-
}
|
|
56
|
-
async getBlockAt(number) {
|
|
57
|
-
if (number === undefined) {
|
|
58
|
-
return this.head;
|
|
59
|
-
}
|
|
60
|
-
if (number > this.#head.number) {
|
|
61
|
-
return undefined;
|
|
62
|
-
}
|
|
63
|
-
if (!this.#blocksByNumber[number]) {
|
|
64
|
-
const hash = await this.api.getBlockHash(number);
|
|
65
|
-
const block = new block_1.Block(this, number, hash);
|
|
66
|
-
this.#registerBlock(block);
|
|
67
|
-
}
|
|
68
|
-
return this.#blocksByNumber[number];
|
|
69
|
-
}
|
|
70
|
-
async getBlock(hash) {
|
|
71
|
-
await this.api.isReady;
|
|
72
|
-
if (hash == null) {
|
|
73
|
-
hash = this.head.hash;
|
|
74
|
-
}
|
|
75
|
-
if (!this.#blocksByHash[hash]) {
|
|
76
|
-
const loadingBlock = this.#loadingBlocks[hash];
|
|
77
|
-
if (loadingBlock) {
|
|
78
|
-
await loadingBlock;
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
const loadingBlock = (async () => {
|
|
82
|
-
try {
|
|
83
|
-
const header = await this.api.getHeader(hash);
|
|
84
|
-
const block = new block_1.Block(this, Number(header.number), hash);
|
|
85
|
-
this.#registerBlock(block);
|
|
86
|
-
}
|
|
87
|
-
catch (e) {
|
|
88
|
-
logger.debug(`getBlock(${hash}) failed: ${e}`);
|
|
89
|
-
}
|
|
90
|
-
})();
|
|
91
|
-
this.#loadingBlocks[hash] = loadingBlock;
|
|
92
|
-
await loadingBlock;
|
|
93
|
-
delete this.#loadingBlocks[hash];
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return this.#blocksByHash[hash];
|
|
97
|
-
}
|
|
98
|
-
unregisterBlock(block) {
|
|
99
|
-
if (block.hash === this.head.hash) {
|
|
100
|
-
throw new Error('Cannot unregister head block');
|
|
101
|
-
}
|
|
102
|
-
if (this.#blocksByNumber[block.number]?.hash === block.hash) {
|
|
103
|
-
delete this.#blocksByNumber[block.number];
|
|
104
|
-
}
|
|
105
|
-
delete this.#blocksByHash[block.hash];
|
|
106
|
-
}
|
|
107
|
-
async setHead(block) {
|
|
108
|
-
logger.debug({
|
|
109
|
-
number: block.number,
|
|
110
|
-
hash: block.hash,
|
|
111
|
-
}, 'setHead');
|
|
112
|
-
this.#head = block;
|
|
113
|
-
this.#registerBlock(block);
|
|
114
|
-
await this.headState.setHead(block);
|
|
115
|
-
if (this.offchainWorker) {
|
|
116
|
-
await this.offchainWorker.run(block);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
async submitExtrinsic(extrinsic) {
|
|
120
|
-
const validity = await this.validateExtrinsic(extrinsic);
|
|
121
|
-
if (validity.isOk) {
|
|
122
|
-
await this.#txpool.submitExtrinsic(extrinsic);
|
|
123
|
-
return (0, util_crypto_1.blake2AsHex)(extrinsic, 256);
|
|
124
|
-
}
|
|
125
|
-
throw validity.asErr;
|
|
126
|
-
}
|
|
127
|
-
async validateExtrinsic(extrinsic, source = '0x02' /** External */) {
|
|
128
|
-
const args = (0, util_1.u8aToHex)((0, util_1.u8aConcat)(source, extrinsic, this.head.hash));
|
|
129
|
-
const res = await this.head.call('TaggedTransactionQueue_validate_transaction', [args]);
|
|
130
|
-
const registry = await this.head.registry;
|
|
131
|
-
return registry.createType('TransactionValidity', res.result);
|
|
132
|
-
}
|
|
133
|
-
submitUpwardMessages(id, ump) {
|
|
134
|
-
this.#txpool.submitUpwardMessages(id, ump);
|
|
135
|
-
logger.debug({ id, ump }, 'submitUpwardMessages');
|
|
136
|
-
}
|
|
137
|
-
submitDownwardMessages(dmp) {
|
|
138
|
-
this.#txpool.submitDownwardMessages(dmp);
|
|
139
|
-
logger.debug({ dmp }, 'submitDownwardMessages');
|
|
140
|
-
}
|
|
141
|
-
submitHorizontalMessages(id, hrmp) {
|
|
142
|
-
this.#txpool.submitHorizontalMessages(id, hrmp);
|
|
143
|
-
logger.debug({ id, hrmp }, 'submitHorizontalMessages');
|
|
144
|
-
}
|
|
145
|
-
async newBlock(params) {
|
|
146
|
-
await this.#txpool.buildBlock(params);
|
|
147
|
-
return this.#head;
|
|
148
|
-
}
|
|
149
|
-
async newBlockWithParams(params) {
|
|
150
|
-
await this.#txpool.buildBlockWithParams(params);
|
|
151
|
-
return this.#head;
|
|
152
|
-
}
|
|
153
|
-
async upcomingBlocks() {
|
|
154
|
-
return this.#txpool.upcomingBlocks();
|
|
155
|
-
}
|
|
156
|
-
async dryRunExtrinsic(extrinsic, at) {
|
|
157
|
-
await this.api.isReady;
|
|
158
|
-
const head = at ? await this.getBlock(at) : this.head;
|
|
159
|
-
if (!head) {
|
|
160
|
-
throw new Error(`Cannot find block ${at}`);
|
|
161
|
-
}
|
|
162
|
-
const registry = await head.registry;
|
|
163
|
-
const inherents = await this.#inherentProvider.createInherents(head, {
|
|
164
|
-
transactions: [],
|
|
165
|
-
downwardMessages: [],
|
|
166
|
-
upwardMessages: [],
|
|
167
|
-
horizontalMessages: {},
|
|
168
|
-
});
|
|
169
|
-
const { result, storageDiff } = await (0, block_builder_1.dryRunExtrinsic)(head, inherents, extrinsic);
|
|
170
|
-
const outcome = registry.createType('ApplyExtrinsicResult', result);
|
|
171
|
-
return { outcome, storageDiff };
|
|
172
|
-
}
|
|
173
|
-
async dryRunHrmp(hrmp, at) {
|
|
174
|
-
await this.api.isReady;
|
|
175
|
-
const head = at ? await this.getBlock(at) : this.head;
|
|
176
|
-
if (!head) {
|
|
177
|
-
throw new Error(`Cannot find block ${at}`);
|
|
178
|
-
}
|
|
179
|
-
const inherents = await this.#inherentProvider.createInherents(head, {
|
|
180
|
-
transactions: [],
|
|
181
|
-
downwardMessages: [],
|
|
182
|
-
upwardMessages: [],
|
|
183
|
-
horizontalMessages: hrmp,
|
|
184
|
-
});
|
|
185
|
-
return (0, block_builder_1.dryRunInherents)(head, inherents);
|
|
186
|
-
}
|
|
187
|
-
async dryRunDmp(dmp, at) {
|
|
188
|
-
await this.api.isReady;
|
|
189
|
-
const head = at ? await this.getBlock(at) : this.head;
|
|
190
|
-
if (!head) {
|
|
191
|
-
throw new Error(`Cannot find block ${at}`);
|
|
192
|
-
}
|
|
193
|
-
const inherents = await this.#inherentProvider.createInherents(head, {
|
|
194
|
-
transactions: [],
|
|
195
|
-
downwardMessages: dmp,
|
|
196
|
-
upwardMessages: [],
|
|
197
|
-
horizontalMessages: {},
|
|
198
|
-
});
|
|
199
|
-
return (0, block_builder_1.dryRunInherents)(head, inherents);
|
|
200
|
-
}
|
|
201
|
-
async dryRunUmp(ump, at) {
|
|
202
|
-
await this.api.isReady;
|
|
203
|
-
const head = at ? await this.getBlock(at) : this.head;
|
|
204
|
-
if (!head) {
|
|
205
|
-
throw new Error(`Cannot find block ${at}`);
|
|
206
|
-
}
|
|
207
|
-
const meta = await head.meta;
|
|
208
|
-
const needsDispatch = meta.registry.createType('Vec<u32>', Object.keys(ump));
|
|
209
|
-
const stroageValues = [
|
|
210
|
-
[(0, utils_1.compactHex)(meta.query.ump.needsDispatch()), needsDispatch.toHex()],
|
|
211
|
-
];
|
|
212
|
-
for (const [paraId, messages] of Object.entries(ump)) {
|
|
213
|
-
const upwardMessages = meta.registry.createType('Vec<Bytes>', messages);
|
|
214
|
-
if (upwardMessages.length === 0)
|
|
215
|
-
throw new Error('No upward meesage');
|
|
216
|
-
const queueSize = meta.registry.createType('(u32, u32)', [
|
|
217
|
-
upwardMessages.length,
|
|
218
|
-
upwardMessages.map((x) => x.byteLength).reduce((s, i) => s + i, 0),
|
|
219
|
-
]);
|
|
220
|
-
stroageValues.push([(0, utils_1.compactHex)(meta.query.ump.relayDispatchQueues(paraId)), upwardMessages.toHex()]);
|
|
221
|
-
stroageValues.push([(0, utils_1.compactHex)(meta.query.ump.relayDispatchQueueSize(paraId)), queueSize.toHex()]);
|
|
222
|
-
}
|
|
223
|
-
head.pushStorageLayer().setAll(stroageValues);
|
|
224
|
-
const inherents = await this.#inherentProvider.createInherents(head, {
|
|
225
|
-
transactions: [],
|
|
226
|
-
downwardMessages: [],
|
|
227
|
-
upwardMessages: [],
|
|
228
|
-
horizontalMessages: {},
|
|
229
|
-
});
|
|
230
|
-
return (0, block_builder_1.dryRunInherents)(head, inherents);
|
|
231
|
-
}
|
|
232
|
-
async getInherents() {
|
|
233
|
-
await this.api.isReady;
|
|
234
|
-
const inherents = await this.#inherentProvider.createInherents(this.head, {
|
|
235
|
-
transactions: [],
|
|
236
|
-
downwardMessages: [],
|
|
237
|
-
upwardMessages: [],
|
|
238
|
-
horizontalMessages: {},
|
|
239
|
-
});
|
|
240
|
-
return inherents;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
exports.Blockchain = Blockchain;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Block } from '../block';
|
|
2
|
-
import { BuildBlockParams } from '../txpool';
|
|
3
|
-
import { HexString } from '@polkadot/util/types';
|
|
4
|
-
export { SetValidationData } from './parachain/validation-data';
|
|
5
|
-
export { ParaInherentEnter } from './para-enter';
|
|
6
|
-
export { SetBabeRandomness } from './parachain/babe-randomness';
|
|
7
|
-
export { SetNimbusAuthorInherent } from './parachain/nimbus-author-inherent';
|
|
8
|
-
export interface CreateInherents {
|
|
9
|
-
createInherents(parent: Block, params: BuildBlockParams): Promise<HexString[]>;
|
|
10
|
-
}
|
|
11
|
-
export type InherentProvider = CreateInherents;
|
|
12
|
-
export declare class SetTimestamp implements InherentProvider {
|
|
13
|
-
createInherents(parent: Block): Promise<HexString[]>;
|
|
14
|
-
}
|
|
15
|
-
export declare class InherentProviders implements InherentProvider {
|
|
16
|
-
#private;
|
|
17
|
-
constructor(base: InherentProvider, providers: CreateInherents[]);
|
|
18
|
-
createInherents(parent: Block, params: BuildBlockParams): Promise<HexString[]>;
|
|
19
|
-
}
|