@acala-network/chopsticks 0.5.5 → 0.5.7
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/api.js +5 -1
- package/lib/blockchain/block-builder.js +43 -36
- package/lib/blockchain/block.js +28 -24
- package/lib/blockchain/head-state.js +14 -9
- package/lib/blockchain/index.js +28 -24
- package/lib/blockchain/inherent/index.js +20 -11
- package/lib/blockchain/inherent/para-enter.js +7 -3
- package/lib/blockchain/inherent/parachain/babe-randomness.js +7 -3
- package/lib/blockchain/inherent/parachain/nimbus-author-inherent.js +7 -3
- package/lib/blockchain/inherent/parachain/validation-data.js +33 -26
- package/lib/blockchain/storage-layer.js +16 -8
- package/lib/blockchain/txpool.js +20 -13
- package/lib/cli.js +35 -30
- package/lib/db/entities.js +9 -6
- package/lib/db/index.js +32 -5
- package/lib/dry-run-preimage.js +27 -23
- package/lib/dry-run.js +16 -12
- package/lib/executor.js +36 -24
- package/lib/genesis-provider.js +24 -17
- package/lib/index.js +31 -7
- package/lib/logger.js +10 -3
- package/lib/rpc/dev/dry-run.js +28 -21
- package/lib/rpc/dev/index.js +16 -14
- package/lib/rpc/index.js +16 -9
- package/lib/rpc/shared.js +7 -3
- package/lib/rpc/substrate/author.js +10 -8
- package/lib/rpc/substrate/chain.js +7 -5
- package/lib/rpc/substrate/index.js +16 -11
- package/lib/rpc/substrate/payment.js +9 -7
- package/lib/rpc/substrate/state.js +7 -5
- package/lib/rpc/substrate/system.js +11 -6
- package/lib/run-block.js +16 -12
- package/lib/schema/index.js +25 -22
- package/lib/server.js +35 -8
- package/lib/setup-with-server.js +12 -8
- package/lib/setup.js +30 -26
- package/lib/utils/decoder.js +25 -16
- package/lib/utils/generate-html-diff.js +20 -12
- package/lib/utils/import-storage.js +19 -11
- package/lib/utils/index.js +19 -10
- package/lib/utils/open-html.js +7 -3
- package/lib/utils/proof.js +17 -9
- package/lib/utils/set-storage.js +14 -10
- package/lib/utils/time-travel.js +28 -21
- package/lib/xcm/downward.js +15 -11
- package/lib/xcm/horizontal.js +11 -7
- package/lib/xcm/index.js +19 -14
- package/lib/xcm/upward.js +10 -6
- package/package.json +2 -2
package/lib/executor.js
CHANGED
|
@@ -1,41 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getAuraSlotDuration = exports.emptyTaskHandler = exports.taskHandler = exports.runTask = exports.createProof = exports.decodeProof = exports.calculateStateRoot = exports.getRuntimeVersion = void 0;
|
|
7
|
+
const util_1 = require("@polkadot/util");
|
|
8
|
+
const chopsticks_executor_1 = require("@acala-network/chopsticks-executor");
|
|
9
|
+
const logger_1 = require("./logger");
|
|
10
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
11
|
+
const logger = logger_1.defaultLogger.child({ name: 'executor' });
|
|
12
|
+
const getRuntimeVersion = async (code) => {
|
|
13
|
+
return (0, chopsticks_executor_1.get_runtime_version)(code).then((version) => {
|
|
14
|
+
version.specName = (0, util_1.hexToString)(version.specName);
|
|
15
|
+
version.implName = (0, util_1.hexToString)(version.implName);
|
|
10
16
|
return version;
|
|
11
17
|
});
|
|
12
18
|
};
|
|
13
|
-
|
|
14
|
-
|
|
19
|
+
exports.getRuntimeVersion = getRuntimeVersion;
|
|
20
|
+
const calculateStateRoot = async (entries) => {
|
|
21
|
+
return (0, chopsticks_executor_1.calculate_state_root)(entries);
|
|
15
22
|
};
|
|
16
|
-
|
|
17
|
-
|
|
23
|
+
exports.calculateStateRoot = calculateStateRoot;
|
|
24
|
+
const decodeProof = async (trieRootHash, keys, nodes) => {
|
|
25
|
+
const decoded = await (0, chopsticks_executor_1.decode_proof)(trieRootHash, keys, nodes);
|
|
18
26
|
return decoded.reduce((accum, [key, value]) => {
|
|
19
27
|
accum[key] = value;
|
|
20
28
|
return accum;
|
|
21
29
|
}, {});
|
|
22
30
|
};
|
|
23
|
-
|
|
24
|
-
|
|
31
|
+
exports.decodeProof = decodeProof;
|
|
32
|
+
const createProof = async (trieRootHash, nodes, entries) => {
|
|
33
|
+
const result = await (0, chopsticks_executor_1.create_proof)(trieRootHash, nodes, entries);
|
|
25
34
|
return { trieRootHash: result[0], nodes: result[1] };
|
|
26
35
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
36
|
+
exports.createProof = createProof;
|
|
37
|
+
const runTask = async (task, callback = exports.emptyTaskHandler) => {
|
|
38
|
+
logger.trace((0, logger_1.truncate)(task), 'taskRun');
|
|
39
|
+
const response = await (0, chopsticks_executor_1.run_task)(task, callback);
|
|
30
40
|
if (response.Call) {
|
|
31
|
-
logger.trace(truncate(response.Call), 'taskResponse');
|
|
41
|
+
logger.trace((0, logger_1.truncate)(response.Call), 'taskResponse');
|
|
32
42
|
}
|
|
33
43
|
else {
|
|
34
44
|
logger.trace({ response }, 'taskResponse');
|
|
35
45
|
}
|
|
36
46
|
return response;
|
|
37
47
|
};
|
|
38
|
-
|
|
48
|
+
exports.runTask = runTask;
|
|
49
|
+
const taskHandler = (block) => {
|
|
39
50
|
return {
|
|
40
51
|
getStorage: async function (key) {
|
|
41
52
|
return block.get(key);
|
|
@@ -49,7 +60,8 @@ export const taskHandler = (block) => {
|
|
|
49
60
|
},
|
|
50
61
|
};
|
|
51
62
|
};
|
|
52
|
-
|
|
63
|
+
exports.taskHandler = taskHandler;
|
|
64
|
+
exports.emptyTaskHandler = {
|
|
53
65
|
getStorage: async function (_key) {
|
|
54
66
|
throw new Error('Method not implemented');
|
|
55
67
|
},
|
|
@@ -60,8 +72,8 @@ export const emptyTaskHandler = {
|
|
|
60
72
|
throw new Error('Method not implemented');
|
|
61
73
|
},
|
|
62
74
|
};
|
|
63
|
-
|
|
64
|
-
const result = await runTask({
|
|
75
|
+
exports.getAuraSlotDuration = lodash_1.default.memoize(async (wasm, registry) => {
|
|
76
|
+
const result = await (0, exports.runTask)({
|
|
65
77
|
wasm,
|
|
66
78
|
calls: [['AuraApi_slot_duration', []]],
|
|
67
79
|
storage: [],
|
|
@@ -70,6 +82,6 @@ export const getAuraSlotDuration = _.memoize(async (wasm, registry) => {
|
|
|
70
82
|
});
|
|
71
83
|
if (!result.Call)
|
|
72
84
|
throw new Error(result.Error);
|
|
73
|
-
const slotDuration = registry.createType('u64', hexToU8a(result.Call.result)).toNumber();
|
|
85
|
+
const slotDuration = registry.createType('u64', (0, util_1.hexToU8a)(result.Call.result)).toNumber();
|
|
74
86
|
return slotDuration;
|
|
75
87
|
});
|
package/lib/genesis-provider.js
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.GenesisProvider = void 0;
|
|
7
|
+
const node_events_1 = require("node:events");
|
|
8
|
+
const node_fs_1 = require("node:fs");
|
|
9
|
+
const util_1 = require("@polkadot/util");
|
|
10
|
+
const axios_1 = __importDefault(require("axios"));
|
|
11
|
+
const schema_1 = require("./schema");
|
|
12
|
+
const executor_1 = require("./executor");
|
|
13
|
+
const utils_1 = require("./utils");
|
|
14
|
+
class GenesisProvider {
|
|
9
15
|
#isConnected = false;
|
|
10
16
|
stats;
|
|
11
17
|
#eventemitter;
|
|
@@ -14,11 +20,11 @@ export class GenesisProvider {
|
|
|
14
20
|
#stateRoot;
|
|
15
21
|
constructor(genesis) {
|
|
16
22
|
this.#genesis = genesis;
|
|
17
|
-
this.#stateRoot = calculateStateRoot(Object.entries(this.#genesis.genesis.raw.top).reduce((accu, item) => {
|
|
23
|
+
this.#stateRoot = (0, executor_1.calculateStateRoot)(Object.entries(this.#genesis.genesis.raw.top).reduce((accu, item) => {
|
|
18
24
|
accu.push(item);
|
|
19
25
|
return accu;
|
|
20
26
|
}, []));
|
|
21
|
-
this.#eventemitter = new EventEmitter();
|
|
27
|
+
this.#eventemitter = new node_events_1.EventEmitter();
|
|
22
28
|
this.#isReadyPromise = new Promise((resolve, reject) => {
|
|
23
29
|
this.#eventemitter.once('connected', () => {
|
|
24
30
|
resolve();
|
|
@@ -28,16 +34,16 @@ export class GenesisProvider {
|
|
|
28
34
|
}
|
|
29
35
|
static fromUrl = async (url) => {
|
|
30
36
|
let file;
|
|
31
|
-
if (isUrl(url)) {
|
|
32
|
-
file = await
|
|
37
|
+
if ((0, utils_1.isUrl)(url)) {
|
|
38
|
+
file = await axios_1.default.get(url).then((x) => x.data);
|
|
33
39
|
}
|
|
34
|
-
else if (lstatSync(url).isFile()) {
|
|
35
|
-
file = JSON.parse(String(readFileSync(url)));
|
|
40
|
+
else if ((0, node_fs_1.lstatSync)(url).isFile()) {
|
|
41
|
+
file = JSON.parse(String((0, node_fs_1.readFileSync)(url)));
|
|
36
42
|
}
|
|
37
43
|
else {
|
|
38
44
|
throw Error(`invalid genesis path or url ${url}`);
|
|
39
45
|
}
|
|
40
|
-
return new GenesisProvider(genesisSchema.parse(file));
|
|
46
|
+
return new GenesisProvider(schema_1.genesisSchema.parse(file));
|
|
41
47
|
};
|
|
42
48
|
get isClonable() {
|
|
43
49
|
return true;
|
|
@@ -114,8 +120,8 @@ export class GenesisProvider {
|
|
|
114
120
|
case 'system_name':
|
|
115
121
|
return this.#genesis.name;
|
|
116
122
|
case 'state_getMetadata': {
|
|
117
|
-
const code = this.#genesis.genesis.raw.top[stringToHex(':code')];
|
|
118
|
-
return runTask({
|
|
123
|
+
const code = this.#genesis.genesis.raw.top[(0, util_1.stringToHex)(':code')];
|
|
124
|
+
return (0, executor_1.runTask)({
|
|
119
125
|
wasm: code,
|
|
120
126
|
calls: [['Metadata_metadata', []]],
|
|
121
127
|
storage: [],
|
|
@@ -145,3 +151,4 @@ export class GenesisProvider {
|
|
|
145
151
|
throw Error('unimplemented');
|
|
146
152
|
};
|
|
147
153
|
}
|
|
154
|
+
exports.GenesisProvider = GenesisProvider;
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.setupWithServer = exports.setup = exports.connectVertical = exports.connectParachains = exports.BuildBlockMode = exports.Blockchain = exports.Api = void 0;
|
|
18
|
+
var api_1 = require("./api");
|
|
19
|
+
Object.defineProperty(exports, "Api", { enumerable: true, get: function () { return api_1.Api; } });
|
|
20
|
+
var blockchain_1 = require("./blockchain");
|
|
21
|
+
Object.defineProperty(exports, "Blockchain", { enumerable: true, get: function () { return blockchain_1.Blockchain; } });
|
|
22
|
+
var txpool_1 = require("./blockchain/txpool");
|
|
23
|
+
Object.defineProperty(exports, "BuildBlockMode", { enumerable: true, get: function () { return txpool_1.BuildBlockMode; } });
|
|
24
|
+
var xcm_1 = require("./xcm");
|
|
25
|
+
Object.defineProperty(exports, "connectParachains", { enumerable: true, get: function () { return xcm_1.connectParachains; } });
|
|
26
|
+
Object.defineProperty(exports, "connectVertical", { enumerable: true, get: function () { return xcm_1.connectVertical; } });
|
|
27
|
+
var setup_1 = require("./setup");
|
|
28
|
+
Object.defineProperty(exports, "setup", { enumerable: true, get: function () { return setup_1.setup; } });
|
|
29
|
+
var setup_with_server_1 = require("./setup-with-server");
|
|
30
|
+
Object.defineProperty(exports, "setupWithServer", { enumerable: true, get: function () { return setup_with_server_1.setupWithServer; } });
|
|
31
|
+
__exportStar(require("./blockchain/inherent"), exports);
|
package/lib/logger.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.truncate = exports.defaultLogger = void 0;
|
|
7
|
+
const pino_1 = __importDefault(require("pino"));
|
|
8
|
+
exports.defaultLogger = (0, pino_1.default)({
|
|
3
9
|
level: process.env.LOG_LEVEL || 'info',
|
|
4
10
|
transport: {
|
|
5
11
|
target: 'pino-pretty',
|
|
@@ -29,4 +35,5 @@ const innerTruncate = (level = 0) => (val) => {
|
|
|
29
35
|
return val;
|
|
30
36
|
}
|
|
31
37
|
};
|
|
32
|
-
|
|
38
|
+
const truncate = (val) => innerTruncate(0)(val);
|
|
39
|
+
exports.truncate = truncate;
|
package/lib/rpc/dev/dry-run.js
CHANGED
|
@@ -1,37 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.dev_dryRun = void 0;
|
|
7
|
+
const zod_1 = __importDefault(require("zod"));
|
|
8
|
+
const decoder_1 = require("../../utils/decoder");
|
|
9
|
+
const generate_html_diff_1 = require("../../utils/generate-html-diff");
|
|
10
|
+
const zHex = zod_1.default.custom((val) => /^0x\w+$/.test(val));
|
|
11
|
+
const zHash = zod_1.default.string().length(66).and(zHex);
|
|
12
|
+
const zParaId = zod_1.default.string().regex(/^\d+$/).transform(Number);
|
|
13
|
+
const dryRunSchema = zod_1.default.object({
|
|
14
|
+
raw: zod_1.default.boolean().optional(),
|
|
15
|
+
html: zod_1.default.boolean().optional(),
|
|
10
16
|
extrinsic: zHex
|
|
11
|
-
.or(
|
|
17
|
+
.or(zod_1.default.object({
|
|
12
18
|
call: zHex,
|
|
13
19
|
address: zHex,
|
|
14
20
|
}))
|
|
15
21
|
.optional(),
|
|
16
|
-
hrmp:
|
|
17
|
-
.record(zParaId,
|
|
18
|
-
.array(
|
|
19
|
-
sentAt:
|
|
22
|
+
hrmp: zod_1.default
|
|
23
|
+
.record(zParaId, zod_1.default
|
|
24
|
+
.array(zod_1.default.object({
|
|
25
|
+
sentAt: zod_1.default.number(),
|
|
20
26
|
data: zHex,
|
|
21
27
|
}))
|
|
22
28
|
.min(1))
|
|
23
29
|
.optional(),
|
|
24
|
-
dmp:
|
|
25
|
-
.array(
|
|
26
|
-
sentAt:
|
|
30
|
+
dmp: zod_1.default
|
|
31
|
+
.array(zod_1.default.object({
|
|
32
|
+
sentAt: zod_1.default.number(),
|
|
27
33
|
msg: zHex,
|
|
28
34
|
}))
|
|
29
35
|
.min(1)
|
|
30
36
|
.optional(),
|
|
31
|
-
ump:
|
|
37
|
+
ump: zod_1.default.record(zParaId, zod_1.default.array(zHex).min(1)).optional(),
|
|
32
38
|
at: zHash.optional(),
|
|
33
39
|
});
|
|
34
|
-
|
|
40
|
+
const dev_dryRun = async (context, [params]) => {
|
|
35
41
|
const { html, extrinsic, hrmp, dmp, ump, raw, at } = dryRunSchema.parse(params);
|
|
36
42
|
const dryRun = async () => {
|
|
37
43
|
if (extrinsic) {
|
|
@@ -54,15 +60,16 @@ export const dev_dryRun = async (context, [params]) => {
|
|
|
54
60
|
};
|
|
55
61
|
const storageDiff = await dryRun();
|
|
56
62
|
if (html) {
|
|
57
|
-
return generateHtmlDiff(context.chain.head, storageDiff);
|
|
63
|
+
return (0, generate_html_diff_1.generateHtmlDiff)(context.chain.head, storageDiff);
|
|
58
64
|
}
|
|
59
65
|
if (raw) {
|
|
60
66
|
return storageDiff;
|
|
61
67
|
}
|
|
62
|
-
const [oldData, newData, delta] = await decodeStorageDiff(context.chain.head, storageDiff);
|
|
68
|
+
const [oldData, newData, delta] = await (0, decoder_1.decodeStorageDiff)(context.chain.head, storageDiff);
|
|
63
69
|
return {
|
|
64
70
|
old: oldData,
|
|
65
71
|
new: newData,
|
|
66
72
|
delta,
|
|
67
73
|
};
|
|
68
74
|
};
|
|
75
|
+
exports.dev_dryRun = dev_dryRun;
|
package/lib/rpc/dev/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const shared_1 = require("../shared");
|
|
4
|
+
const set_storage_1 = require("../../utils/set-storage");
|
|
5
|
+
const logger_1 = require("../../logger");
|
|
6
|
+
const dry_run_1 = require("./dry-run");
|
|
7
|
+
const time_travel_1 = require("../../utils/time-travel");
|
|
8
|
+
const logger = logger_1.defaultLogger.child({ name: 'rpc-dev' });
|
|
7
9
|
const handlers = {
|
|
8
10
|
dev_newBlock: async (context, [param]) => {
|
|
9
11
|
const { count, to, hrmp, ump, dmp, transactions } = param || {};
|
|
@@ -20,7 +22,7 @@ const handlers = {
|
|
|
20
22
|
downwardMessages: dmp,
|
|
21
23
|
})
|
|
22
24
|
.catch((error) => {
|
|
23
|
-
throw new ResponseError(1, error.toString());
|
|
25
|
+
throw new shared_1.ResponseError(1, error.toString());
|
|
24
26
|
});
|
|
25
27
|
logger.debug({ hash: block.hash }, 'dev_newBlock');
|
|
26
28
|
finalHash = block.hash;
|
|
@@ -29,8 +31,8 @@ const handlers = {
|
|
|
29
31
|
},
|
|
30
32
|
dev_setStorage: async (context, params) => {
|
|
31
33
|
const [values, blockHash] = params;
|
|
32
|
-
const hash = await setStorage(context.chain, values, blockHash).catch((error) => {
|
|
33
|
-
throw new ResponseError(1, error.toString());
|
|
34
|
+
const hash = await (0, set_storage_1.setStorage)(context.chain, values, blockHash).catch((error) => {
|
|
35
|
+
throw new shared_1.ResponseError(1, error.toString());
|
|
34
36
|
});
|
|
35
37
|
logger.debug({
|
|
36
38
|
hash,
|
|
@@ -41,8 +43,8 @@ const handlers = {
|
|
|
41
43
|
dev_timeTravel: async (context, [date]) => {
|
|
42
44
|
const timestamp = typeof date === 'string' ? Date.parse(date) : date;
|
|
43
45
|
if (Number.isNaN(timestamp))
|
|
44
|
-
throw new ResponseError(1, 'Invalid date');
|
|
45
|
-
await timeTravel(context.chain, timestamp);
|
|
46
|
+
throw new shared_1.ResponseError(1, 'Invalid date');
|
|
47
|
+
await (0, time_travel_1.timeTravel)(context.chain, timestamp);
|
|
46
48
|
return timestamp;
|
|
47
49
|
},
|
|
48
50
|
dev_setHead: async (context, [hashOrNumber]) => {
|
|
@@ -55,11 +57,11 @@ const handlers = {
|
|
|
55
57
|
block = await context.chain.getBlock(hashOrNumber);
|
|
56
58
|
}
|
|
57
59
|
if (!block) {
|
|
58
|
-
throw new ResponseError(1, `Block not found ${hashOrNumber}`);
|
|
60
|
+
throw new shared_1.ResponseError(1, `Block not found ${hashOrNumber}`);
|
|
59
61
|
}
|
|
60
62
|
await context.chain.setHead(block);
|
|
61
63
|
return block.hash;
|
|
62
64
|
},
|
|
63
|
-
dev_dryRun,
|
|
65
|
+
dev_dryRun: dry_run_1.dev_dryRun,
|
|
64
66
|
};
|
|
65
|
-
|
|
67
|
+
exports.default = handlers;
|
package/lib/rpc/index.js
CHANGED
|
@@ -1,20 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.handler = void 0;
|
|
7
|
+
const shared_1 = require("./shared");
|
|
8
|
+
const dev_1 = __importDefault(require("./dev"));
|
|
9
|
+
const substrate_1 = __importDefault(require("./substrate"));
|
|
4
10
|
const allHandlers = {
|
|
5
|
-
...
|
|
6
|
-
...
|
|
11
|
+
...substrate_1.default,
|
|
12
|
+
...dev_1.default,
|
|
7
13
|
rpc_methods: async () => Promise.resolve({
|
|
8
14
|
version: 1,
|
|
9
15
|
methods: Object.keys(allHandlers),
|
|
10
16
|
}),
|
|
11
17
|
};
|
|
12
|
-
|
|
13
|
-
logger.trace('Handling %s', method);
|
|
18
|
+
const handler = (context) => ({ method, params }, subscriptionManager) => {
|
|
19
|
+
shared_1.logger.trace('Handling %s', method);
|
|
14
20
|
const handler = allHandlers[method];
|
|
15
21
|
if (!handler) {
|
|
16
|
-
logger.warn('Method not found %s', method);
|
|
17
|
-
throw new ResponseError(-32601, `Method not found: ${method}`);
|
|
22
|
+
shared_1.logger.warn('Method not found %s', method);
|
|
23
|
+
throw new shared_1.ResponseError(-32601, `Method not found: ${method}`);
|
|
18
24
|
}
|
|
19
25
|
return handler(context, params, subscriptionManager);
|
|
20
26
|
};
|
|
27
|
+
exports.handler = handler;
|
package/lib/rpc/shared.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResponseError = exports.logger = void 0;
|
|
4
|
+
const logger_1 = require("../logger");
|
|
5
|
+
exports.logger = logger_1.defaultLogger.child({ name: 'rpc' });
|
|
6
|
+
class ResponseError extends Error {
|
|
4
7
|
code;
|
|
5
8
|
constructor(code, message) {
|
|
6
9
|
super(message);
|
|
@@ -14,3 +17,4 @@ export class ResponseError extends Error {
|
|
|
14
17
|
};
|
|
15
18
|
}
|
|
16
19
|
}
|
|
20
|
+
exports.ResponseError = ResponseError;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const txpool_1 = require("../../blockchain/txpool");
|
|
4
|
+
const shared_1 = require("../shared");
|
|
5
|
+
const logger_1 = require("../../logger");
|
|
6
|
+
const logger = logger_1.defaultLogger.child({ name: 'rpc-author' });
|
|
5
7
|
const handlers = {
|
|
6
8
|
author_submitExtrinsic: async (context, [extrinsic]) => {
|
|
7
9
|
return context.chain.submitExtrinsic(extrinsic).catch((error) => {
|
|
8
10
|
const code = error.isInvalid ? 1010 : 1011;
|
|
9
|
-
throw new ResponseError(code, error.toString());
|
|
11
|
+
throw new shared_1.ResponseError(code, error.toString());
|
|
10
12
|
});
|
|
11
13
|
},
|
|
12
14
|
author_submitAndWatchExtrinsic: async (context, [extrinsic], { subscribe, unsubscribe }) => {
|
|
@@ -19,9 +21,9 @@ const handlers = {
|
|
|
19
21
|
done(id);
|
|
20
22
|
}
|
|
21
23
|
};
|
|
22
|
-
context.chain.txPool.event.on(APPLY_EXTRINSIC_ERROR, onExtrinsicFail);
|
|
24
|
+
context.chain.txPool.event.on(txpool_1.APPLY_EXTRINSIC_ERROR, onExtrinsicFail);
|
|
23
25
|
const done = (id) => {
|
|
24
|
-
context.chain.txPool.event.removeListener(APPLY_EXTRINSIC_ERROR, onExtrinsicFail);
|
|
26
|
+
context.chain.txPool.event.removeListener(txpool_1.APPLY_EXTRINSIC_ERROR, onExtrinsicFail);
|
|
25
27
|
unsubscribe(id);
|
|
26
28
|
};
|
|
27
29
|
update = async (block) => {
|
|
@@ -58,4 +60,4 @@ const handlers = {
|
|
|
58
60
|
return context.chain.txPool.pendingExtrinsics;
|
|
59
61
|
},
|
|
60
62
|
};
|
|
61
|
-
|
|
63
|
+
exports.default = handlers;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const shared_1 = require("../shared");
|
|
2
4
|
const processHeader = (header) => {
|
|
3
5
|
const res = header.toJSON();
|
|
4
6
|
res.number = '0x' + res.number.toString(16); // number is hex format
|
|
@@ -8,21 +10,21 @@ const handlers = {
|
|
|
8
10
|
chain_getBlockHash: async (context, [blockNumber]) => {
|
|
9
11
|
const block = await context.chain.getBlockAt(blockNumber);
|
|
10
12
|
if (!block) {
|
|
11
|
-
throw new ResponseError(1, `Block #${blockNumber} not found`);
|
|
13
|
+
throw new shared_1.ResponseError(1, `Block #${blockNumber} not found`);
|
|
12
14
|
}
|
|
13
15
|
return block.hash;
|
|
14
16
|
},
|
|
15
17
|
chain_getHeader: async (context, [hash]) => {
|
|
16
18
|
const block = await context.chain.getBlock(hash);
|
|
17
19
|
if (!block) {
|
|
18
|
-
throw new ResponseError(1, `Block ${hash} not found`);
|
|
20
|
+
throw new shared_1.ResponseError(1, `Block ${hash} not found`);
|
|
19
21
|
}
|
|
20
22
|
return processHeader(await block.header);
|
|
21
23
|
},
|
|
22
24
|
chain_getBlock: async (context, [hash]) => {
|
|
23
25
|
const block = await context.chain.getBlock(hash);
|
|
24
26
|
if (!block) {
|
|
25
|
-
throw new ResponseError(1, `Block ${hash} not found`);
|
|
27
|
+
throw new shared_1.ResponseError(1, `Block ${hash} not found`);
|
|
26
28
|
}
|
|
27
29
|
return {
|
|
28
30
|
block: {
|
|
@@ -64,7 +66,7 @@ const alias = {
|
|
|
64
66
|
chain_unsubscribeNewHeads: handlers.chain_unsubscribeNewHead,
|
|
65
67
|
chain_unsubscribeFinalizedHeads: handlers.chain_unsubscribeNewHead,
|
|
66
68
|
};
|
|
67
|
-
|
|
69
|
+
exports.default = {
|
|
68
70
|
...handlers,
|
|
69
71
|
...alias,
|
|
70
72
|
};
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const author_1 = __importDefault(require("./author"));
|
|
7
|
+
const chain_1 = __importDefault(require("./chain"));
|
|
8
|
+
const payment_1 = __importDefault(require("./payment"));
|
|
9
|
+
const state_1 = __importDefault(require("./state"));
|
|
10
|
+
const system_1 = __importDefault(require("./system"));
|
|
6
11
|
const handlers = {
|
|
7
|
-
...
|
|
8
|
-
...
|
|
9
|
-
...
|
|
10
|
-
...
|
|
11
|
-
...
|
|
12
|
+
...author_1.default,
|
|
13
|
+
...chain_1.default,
|
|
14
|
+
...state_1.default,
|
|
15
|
+
...system_1.default,
|
|
16
|
+
...payment_1.default,
|
|
12
17
|
};
|
|
13
|
-
|
|
18
|
+
exports.default = handlers;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const shared_1 = require("../shared");
|
|
4
|
+
const util_1 = require("@polkadot/util");
|
|
3
5
|
const handlers = {
|
|
4
6
|
payment_queryFeeDetails: async (context, [extrinsic, hash]) => {
|
|
5
7
|
const block = await context.chain.getBlock(hash);
|
|
6
8
|
if (!block) {
|
|
7
|
-
throw new ResponseError(1, `Block ${hash} not found`);
|
|
9
|
+
throw new shared_1.ResponseError(1, `Block ${hash} not found`);
|
|
8
10
|
}
|
|
9
11
|
const registry = await block.registry;
|
|
10
|
-
const tx = hexToU8a(extrinsic);
|
|
12
|
+
const tx = (0, util_1.hexToU8a)(extrinsic);
|
|
11
13
|
const resp = await block.call('TransactionPaymentApi_query_fee_details', [
|
|
12
14
|
registry.createType('Extrinsic', tx).toHex(),
|
|
13
15
|
registry.createType('u32', tx.byteLength).toHex(),
|
|
@@ -17,10 +19,10 @@ const handlers = {
|
|
|
17
19
|
payment_queryInfo: async (context, [extrinsic, hash]) => {
|
|
18
20
|
const block = await context.chain.getBlock(hash);
|
|
19
21
|
if (!block) {
|
|
20
|
-
throw new ResponseError(1, `Block ${hash} not found`);
|
|
22
|
+
throw new shared_1.ResponseError(1, `Block ${hash} not found`);
|
|
21
23
|
}
|
|
22
24
|
const registry = await block.registry;
|
|
23
|
-
const tx = hexToU8a(extrinsic);
|
|
25
|
+
const tx = (0, util_1.hexToU8a)(extrinsic);
|
|
24
26
|
const resp = await block.call('TransactionPaymentApi_query_info', [
|
|
25
27
|
registry.createType('Extrinsic', tx).toHex(),
|
|
26
28
|
registry.createType('u32', tx.byteLength).toHex(),
|
|
@@ -28,4 +30,4 @@ const handlers = {
|
|
|
28
30
|
return resp.result;
|
|
29
31
|
},
|
|
30
32
|
};
|
|
31
|
-
|
|
33
|
+
exports.default = handlers;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const shared_1 = require("../shared");
|
|
4
|
+
const logger_1 = require("../../logger");
|
|
5
|
+
const logger = logger_1.defaultLogger.child({ name: 'rpc-state' });
|
|
4
6
|
const handlers = {
|
|
5
7
|
state_getRuntimeVersion: async (context, [hash]) => {
|
|
6
8
|
const block = await context.chain.getBlock(hash);
|
|
@@ -34,7 +36,7 @@ const handlers = {
|
|
|
34
36
|
state_call: async (context, [method, data, hash]) => {
|
|
35
37
|
const block = await context.chain.getBlock(hash);
|
|
36
38
|
if (!block) {
|
|
37
|
-
throw new ResponseError(1, `Block ${hash} not found`);
|
|
39
|
+
throw new shared_1.ResponseError(1, `Block ${hash} not found`);
|
|
38
40
|
}
|
|
39
41
|
const resp = await block.call(method, [data]);
|
|
40
42
|
return resp.result;
|
|
@@ -77,4 +79,4 @@ const handlers = {
|
|
|
77
79
|
unsubscribe(subid);
|
|
78
80
|
},
|
|
79
81
|
};
|
|
80
|
-
|
|
82
|
+
exports.default = handlers;
|