@acala-network/chopsticks-core 0.8.0-0 → 0.8.0-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/api.js +5 -1
- package/lib/blockchain/block-builder.js +52 -45
- package/lib/blockchain/block.js +31 -27
- package/lib/blockchain/head-state.js +14 -9
- package/lib/blockchain/index.js +36 -32
- 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 +22 -14
- package/lib/blockchain/txpool.js +26 -19
- package/lib/db/browser.d.ts +1 -1
- package/lib/db/browser.js +42 -11
- package/lib/db/entities.js +6 -3
- package/lib/db/index.d.ts +1 -1
- package/lib/db/index.js +31 -4
- package/lib/db/node.js +31 -4
- package/lib/executor.js +40 -32
- package/lib/genesis-provider.js +46 -16
- package/lib/index.js +29 -13
- package/lib/logger.js +10 -3
- package/lib/offchain.js +11 -7
- package/lib/schema/index.js +12 -9
- package/lib/setup.d.ts +1 -1
- package/lib/setup.js +30 -21
- package/lib/utils/index.js +35 -12
- package/lib/utils/key-cache.js +24 -17
- package/lib/utils/proof.js +17 -9
- package/lib/utils/set-storage.js +15 -11
- 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/offchain.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -7,11 +8,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
9
|
});
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.OffchainWorker = void 0;
|
|
13
|
+
const util_crypto_1 = require("@polkadot/util-crypto");
|
|
14
|
+
const logger_1 = require("./logger");
|
|
15
|
+
const rxjs_1 = require("rxjs");
|
|
16
|
+
const logger = logger_1.defaultLogger.child({ name: 'offchain' });
|
|
17
|
+
class OffchainWorker {
|
|
15
18
|
constructor() {
|
|
16
19
|
this.pendingExtrinsics = [];
|
|
17
20
|
this.offchainStorage = new Map();
|
|
@@ -30,7 +33,7 @@ export class OffchainWorker {
|
|
|
30
33
|
logger.info(`Offchain Worker complete for block #${block.number.toLocaleString()}`);
|
|
31
34
|
const txs = this.pendingExtrinsics.splice(0);
|
|
32
35
|
if (txs.length > 0) {
|
|
33
|
-
queueScheduler.schedule((transactions) => __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
rxjs_1.queueScheduler.schedule((transactions) => __awaiter(this, void 0, void 0, function* () {
|
|
34
37
|
yield block.chain.txPool.buildBlock({ transactions });
|
|
35
38
|
}), 100, txs);
|
|
36
39
|
}
|
|
@@ -41,9 +44,10 @@ export class OffchainWorker {
|
|
|
41
44
|
const validity = yield block.chain.validateExtrinsic(extrinsic, '0x01');
|
|
42
45
|
if (validity.isOk) {
|
|
43
46
|
this.pendingExtrinsics.push(extrinsic);
|
|
44
|
-
return blake2AsHex(extrinsic, 256);
|
|
47
|
+
return (0, util_crypto_1.blake2AsHex)(extrinsic, 256);
|
|
45
48
|
}
|
|
46
49
|
throw validity.asErr;
|
|
47
50
|
});
|
|
48
51
|
}
|
|
49
52
|
}
|
|
53
|
+
exports.OffchainWorker = OffchainWorker;
|
package/lib/schema/index.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.genesisSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
exports.genesisSchema = zod_1.z.object({
|
|
6
|
+
id: zod_1.z.string(),
|
|
7
|
+
name: zod_1.z.string(),
|
|
8
|
+
properties: zod_1.z.object({
|
|
9
|
+
ss58Format: zod_1.z.number().optional(),
|
|
10
|
+
tokenDecimals: zod_1.z.union([zod_1.z.number(), zod_1.z.array(zod_1.z.number())]).optional(),
|
|
11
|
+
tokenSymbol: zod_1.z.union([zod_1.z.string(), zod_1.z.array(zod_1.z.string())]).optional(),
|
|
9
12
|
}),
|
|
10
|
-
genesis: z.object({ raw: z.object({ top: z.record(z.string()) }) }),
|
|
13
|
+
genesis: zod_1.z.object({ raw: zod_1.z.object({ top: zod_1.z.record(zod_1.z.string()) }) }),
|
|
11
14
|
});
|
package/lib/setup.d.ts
CHANGED
package/lib/setup.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -7,28 +8,30 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
9
|
});
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.setup = void 0;
|
|
13
|
+
require("@polkadot/types-codec");
|
|
14
|
+
const api_1 = require("@polkadot/api");
|
|
15
|
+
const api_2 = require("./api");
|
|
16
|
+
const blockchain_1 = require("./blockchain");
|
|
17
|
+
const genesis_provider_1 = require("./genesis-provider");
|
|
18
|
+
const inherent_1 = require("./blockchain/inherent");
|
|
19
|
+
const logger_1 = require("./logger");
|
|
20
|
+
const db_1 = require("./db");
|
|
21
|
+
const setup = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
22
|
let provider;
|
|
20
23
|
if (options.genesis) {
|
|
21
24
|
if (typeof options.genesis === 'string') {
|
|
22
|
-
provider = yield GenesisProvider.fromUrl(options.genesis);
|
|
25
|
+
provider = yield genesis_provider_1.GenesisProvider.fromUrl(options.genesis);
|
|
23
26
|
}
|
|
24
27
|
else {
|
|
25
|
-
provider = new GenesisProvider(options.genesis);
|
|
28
|
+
provider = new genesis_provider_1.GenesisProvider(options.genesis);
|
|
26
29
|
}
|
|
27
30
|
}
|
|
28
31
|
else {
|
|
29
|
-
provider = new WsProvider(options.endpoint);
|
|
32
|
+
provider = new api_1.WsProvider(options.endpoint);
|
|
30
33
|
}
|
|
31
|
-
const api = new Api(provider);
|
|
34
|
+
const api = new api_2.Api(provider);
|
|
32
35
|
yield api.isReady;
|
|
33
36
|
let blockHash;
|
|
34
37
|
if (options.block == null) {
|
|
@@ -43,19 +46,24 @@ export const setup = (options) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
43
46
|
else {
|
|
44
47
|
throw new Error(`Invalid block number or hash: ${options.block}`);
|
|
45
48
|
}
|
|
46
|
-
defaultLogger.debug(Object.assign(Object.assign({}, options), { blockHash }), 'Args');
|
|
49
|
+
logger_1.defaultLogger.debug(Object.assign(Object.assign({}, options), { blockHash }), 'Args');
|
|
47
50
|
let db;
|
|
48
51
|
if (options.db) {
|
|
49
|
-
|
|
52
|
+
if (typeof window !== 'undefined') {
|
|
53
|
+
if (!(options.db instanceof URL)) {
|
|
54
|
+
throw new Error('options.db must be an URL to sql-wasm.wasm when running in browser');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
db = yield (0, db_1.openDb)(options.db);
|
|
50
58
|
}
|
|
51
59
|
const header = yield api.getHeader(blockHash);
|
|
52
|
-
const inherents = new InherentProviders(new SetTimestamp(), [
|
|
53
|
-
new SetValidationData(),
|
|
54
|
-
new ParaInherentEnter(),
|
|
55
|
-
new SetNimbusAuthorInherent(),
|
|
56
|
-
new SetBabeRandomness(),
|
|
60
|
+
const inherents = new inherent_1.InherentProviders(new inherent_1.SetTimestamp(), [
|
|
61
|
+
new inherent_1.SetValidationData(),
|
|
62
|
+
new inherent_1.ParaInherentEnter(),
|
|
63
|
+
new inherent_1.SetNimbusAuthorInherent(),
|
|
64
|
+
new inherent_1.SetBabeRandomness(),
|
|
57
65
|
]);
|
|
58
|
-
return new Blockchain({
|
|
66
|
+
return new blockchain_1.Blockchain({
|
|
59
67
|
api,
|
|
60
68
|
buildBlockMode: options.buildBlockMode,
|
|
61
69
|
inherentProvider: inherents,
|
|
@@ -72,3 +80,4 @@ export const setup = (options) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
72
80
|
maxMemoryBlockCount: options.maxMemoryBlockCount,
|
|
73
81
|
});
|
|
74
82
|
});
|
|
83
|
+
exports.setup = setup;
|
package/lib/utils/index.js
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
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
|
+
};
|
|
1
16
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
17
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
18
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -7,10 +22,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
22
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
23
|
});
|
|
9
24
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.defer = exports.isUrl = exports.getParaId = exports.compactHex = exports.fetchKeysToArray = exports.fetchKeys = void 0;
|
|
27
|
+
const util_1 = require("@polkadot/util");
|
|
28
|
+
__exportStar(require("./set-storage"), exports);
|
|
29
|
+
__exportStar(require("./time-travel"), exports);
|
|
30
|
+
function fetchKeys(getKeys, processKey) {
|
|
14
31
|
return __awaiter(this, void 0, void 0, function* () {
|
|
15
32
|
const processKeys = (keys) => __awaiter(this, void 0, void 0, function* () {
|
|
16
33
|
for (const key of keys) {
|
|
@@ -29,24 +46,28 @@ export function fetchKeys(getKeys, processKey) {
|
|
|
29
46
|
}
|
|
30
47
|
});
|
|
31
48
|
}
|
|
32
|
-
|
|
49
|
+
exports.fetchKeys = fetchKeys;
|
|
50
|
+
function fetchKeysToArray(getKeys) {
|
|
33
51
|
return __awaiter(this, void 0, void 0, function* () {
|
|
34
52
|
const res = [];
|
|
35
53
|
yield fetchKeys(getKeys, (key) => res.push(key));
|
|
36
54
|
return res;
|
|
37
55
|
});
|
|
38
56
|
}
|
|
39
|
-
|
|
40
|
-
|
|
57
|
+
exports.fetchKeysToArray = fetchKeysToArray;
|
|
58
|
+
const compactHex = (value) => {
|
|
59
|
+
return (0, util_1.u8aToHex)((0, util_1.compactStripLength)(value)[1]);
|
|
41
60
|
};
|
|
42
|
-
|
|
61
|
+
exports.compactHex = compactHex;
|
|
62
|
+
const getParaId = (chain) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
63
|
const meta = yield chain.head.meta;
|
|
44
|
-
const raw = yield chain.head.get(compactHex(meta.query.parachainInfo.parachainId()));
|
|
64
|
+
const raw = yield chain.head.get((0, exports.compactHex)(meta.query.parachainInfo.parachainId()));
|
|
45
65
|
if (!raw)
|
|
46
66
|
throw new Error('Cannot find parachain id');
|
|
47
|
-
return meta.registry.createType('u32', hexToU8a(raw));
|
|
67
|
+
return meta.registry.createType('u32', (0, util_1.hexToU8a)(raw));
|
|
48
68
|
});
|
|
49
|
-
|
|
69
|
+
exports.getParaId = getParaId;
|
|
70
|
+
const isUrl = (url) => {
|
|
50
71
|
try {
|
|
51
72
|
new URL(url);
|
|
52
73
|
return true;
|
|
@@ -55,7 +76,8 @@ export const isUrl = (url) => {
|
|
|
55
76
|
return false;
|
|
56
77
|
}
|
|
57
78
|
};
|
|
58
|
-
|
|
79
|
+
exports.isUrl = isUrl;
|
|
80
|
+
function defer() {
|
|
59
81
|
const deferred = {};
|
|
60
82
|
deferred.promise = new Promise((resolve, reject) => {
|
|
61
83
|
deferred.resolve = resolve;
|
|
@@ -63,3 +85,4 @@ export function defer() {
|
|
|
63
85
|
});
|
|
64
86
|
return deferred;
|
|
65
87
|
}
|
|
88
|
+
exports.defer = defer;
|
package/lib/utils/key-cache.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -7,59 +8,64 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
9
|
});
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.PREFIX_LENGTH = void 0;
|
|
16
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
11
17
|
// 0x + 32 module + 32 method
|
|
12
|
-
|
|
13
|
-
|
|
18
|
+
exports.PREFIX_LENGTH = 66;
|
|
19
|
+
class KeyCache {
|
|
14
20
|
constructor() {
|
|
15
21
|
this.ranges = [];
|
|
16
22
|
}
|
|
17
23
|
feed(keys) {
|
|
18
|
-
const _keys = keys.filter((key) => key.length >= PREFIX_LENGTH);
|
|
24
|
+
const _keys = keys.filter((key) => key.length >= exports.PREFIX_LENGTH);
|
|
19
25
|
if (_keys.length === 0)
|
|
20
26
|
return;
|
|
21
|
-
const startKey = _keys[0].slice(PREFIX_LENGTH);
|
|
22
|
-
const endKey = _keys[_keys.length - 1].slice(PREFIX_LENGTH);
|
|
23
|
-
const grouped =
|
|
27
|
+
const startKey = _keys[0].slice(exports.PREFIX_LENGTH);
|
|
28
|
+
const endKey = _keys[_keys.length - 1].slice(exports.PREFIX_LENGTH);
|
|
29
|
+
const grouped = lodash_1.default.groupBy(_keys, (key) => key.slice(0, exports.PREFIX_LENGTH));
|
|
24
30
|
for (const [prefix, keys] of Object.entries(grouped)) {
|
|
25
31
|
const ranges = this.ranges.filter((range) => range.prefix === prefix);
|
|
26
32
|
if (ranges.length === 0) {
|
|
27
33
|
// no existing range with prefix
|
|
28
|
-
this.ranges.push({ prefix, keys: keys.map((i) => i.slice(PREFIX_LENGTH)) });
|
|
34
|
+
this.ranges.push({ prefix, keys: keys.map((i) => i.slice(exports.PREFIX_LENGTH)) });
|
|
29
35
|
continue;
|
|
30
36
|
}
|
|
31
37
|
let merged = false;
|
|
32
38
|
for (const range of ranges) {
|
|
33
|
-
const startPosition =
|
|
39
|
+
const startPosition = lodash_1.default.sortedIndex(range.keys, startKey);
|
|
34
40
|
if (startPosition >= 0 && range.keys[startPosition] === startKey) {
|
|
35
41
|
// found existing range with prefix
|
|
36
|
-
range.keys.splice(startPosition, keys.length, ...keys.map((i) => i.slice(PREFIX_LENGTH)));
|
|
42
|
+
range.keys.splice(startPosition, keys.length, ...keys.map((i) => i.slice(exports.PREFIX_LENGTH)));
|
|
37
43
|
merged = true;
|
|
38
44
|
break;
|
|
39
45
|
}
|
|
40
|
-
const endPosition =
|
|
46
|
+
const endPosition = lodash_1.default.sortedIndex(range.keys, endKey);
|
|
41
47
|
if (endPosition >= 0 && range.keys[endPosition] === endKey) {
|
|
42
48
|
// found existing range with prefix
|
|
43
|
-
range.keys.splice(0, endPosition + 1, ...keys.map((i) => i.slice(PREFIX_LENGTH)));
|
|
49
|
+
range.keys.splice(0, endPosition + 1, ...keys.map((i) => i.slice(exports.PREFIX_LENGTH)));
|
|
44
50
|
merged = true;
|
|
45
51
|
break;
|
|
46
52
|
}
|
|
47
53
|
}
|
|
48
54
|
// insert new prefix with range
|
|
49
55
|
if (!merged) {
|
|
50
|
-
this.ranges.push({ prefix, keys: keys.map((i) => i.slice(PREFIX_LENGTH)) });
|
|
56
|
+
this.ranges.push({ prefix, keys: keys.map((i) => i.slice(exports.PREFIX_LENGTH)) });
|
|
51
57
|
}
|
|
52
58
|
}
|
|
53
59
|
// TODO: merge ranges if they overlap
|
|
54
60
|
}
|
|
55
61
|
next(startKey) {
|
|
56
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
-
if (startKey.length < PREFIX_LENGTH)
|
|
63
|
+
if (startKey.length < exports.PREFIX_LENGTH)
|
|
58
64
|
return;
|
|
59
|
-
const prefix = startKey.slice(0, PREFIX_LENGTH);
|
|
60
|
-
const key = startKey.slice(PREFIX_LENGTH);
|
|
65
|
+
const prefix = startKey.slice(0, exports.PREFIX_LENGTH);
|
|
66
|
+
const key = startKey.slice(exports.PREFIX_LENGTH);
|
|
61
67
|
for (const range of this.ranges.filter((range) => range.prefix === prefix)) {
|
|
62
|
-
const index =
|
|
68
|
+
const index = lodash_1.default.sortedIndex(range.keys, key);
|
|
63
69
|
if (range.keys[index] !== key)
|
|
64
70
|
continue;
|
|
65
71
|
const nextKey = range.keys[index + 1];
|
|
@@ -70,3 +76,4 @@ export default class KeyCache {
|
|
|
70
76
|
});
|
|
71
77
|
}
|
|
72
78
|
}
|
|
79
|
+
exports.default = KeyCache;
|
package/lib/utils/proof.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hrmpChannels = exports.hrmpEgressChannelIndex = exports.hrmpIngressChannelIndex = exports.upgradeGoAheadSignal = exports.dmqMqcHead = exports.WELL_KNOWN_KEYS = void 0;
|
|
4
|
+
const util_1 = require("@polkadot/util");
|
|
5
|
+
const util_crypto_1 = require("@polkadot/util-crypto");
|
|
6
|
+
exports.WELL_KNOWN_KEYS = {
|
|
4
7
|
EPOCH_INDEX: '0x1cb6f36e027abb2091cfb5110ab5087f38316cbf8fa0da822a20ac1c55bf1be3',
|
|
5
8
|
CURRENT_BLOCK_RANDOMNESS: '0x1cb6f36e027abb2091cfb5110ab5087fd077dfdb8adb10f78f10a5df8742c545',
|
|
6
9
|
ONE_EPOCH_AGO_RANDOMNESS: '0x1cb6f36e027abb2091cfb5110ab5087f7ce678799d3eff024253b90e84927cc6',
|
|
@@ -9,25 +12,30 @@ export const WELL_KNOWN_KEYS = {
|
|
|
9
12
|
ACTIVE_CONFIG: '0x06de3d8a54d27e44a9d5ce189618f22db4b49d95320d9021994c850f25b8e385',
|
|
10
13
|
};
|
|
11
14
|
const hash = (prefix, suffix) => {
|
|
12
|
-
return u8aToHex(u8aConcat(hexToU8a(prefix), xxhashAsU8a(suffix, 64), suffix));
|
|
15
|
+
return (0, util_1.u8aToHex)((0, util_1.u8aConcat)((0, util_1.hexToU8a)(prefix), (0, util_crypto_1.xxhashAsU8a)(suffix, 64), suffix));
|
|
13
16
|
};
|
|
14
|
-
|
|
17
|
+
const dmqMqcHead = (paraId) => {
|
|
15
18
|
const prefix = '0x63f78c98723ddc9073523ef3beefda0c4d7fefc408aac59dbfe80a72ac8e3ce5';
|
|
16
19
|
return hash(prefix, paraId.toU8a());
|
|
17
20
|
};
|
|
18
|
-
|
|
21
|
+
exports.dmqMqcHead = dmqMqcHead;
|
|
22
|
+
const upgradeGoAheadSignal = (paraId) => {
|
|
19
23
|
const prefix = '0xcd710b30bd2eab0352ddcc26417aa1949e94c040f5e73d9b7addd6cb603d15d3';
|
|
20
24
|
return hash(prefix, paraId.toU8a());
|
|
21
25
|
};
|
|
22
|
-
|
|
26
|
+
exports.upgradeGoAheadSignal = upgradeGoAheadSignal;
|
|
27
|
+
const hrmpIngressChannelIndex = (paraId) => {
|
|
23
28
|
const prefix = '0x6a0da05ca59913bc38a8630590f2627c1d3719f5b0b12c7105c073c507445948';
|
|
24
29
|
return hash(prefix, paraId.toU8a());
|
|
25
30
|
};
|
|
26
|
-
|
|
31
|
+
exports.hrmpIngressChannelIndex = hrmpIngressChannelIndex;
|
|
32
|
+
const hrmpEgressChannelIndex = (paraId) => {
|
|
27
33
|
const prefix = '0x6a0da05ca59913bc38a8630590f2627cf12b746dcf32e843354583c9702cc020';
|
|
28
34
|
return hash(prefix, paraId.toU8a());
|
|
29
35
|
};
|
|
30
|
-
|
|
36
|
+
exports.hrmpEgressChannelIndex = hrmpEgressChannelIndex;
|
|
37
|
+
const hrmpChannels = (channelId) => {
|
|
31
38
|
const prefix = '0x6a0da05ca59913bc38a8630590f2627cb6604cff828a6e3f579ca6c59ace013d';
|
|
32
39
|
return hash(prefix, channelId.toU8a());
|
|
33
40
|
};
|
|
41
|
+
exports.hrmpChannels = hrmpChannels;
|
package/lib/utils/set-storage.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -7,40 +8,42 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
9
|
});
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.setStorage = void 0;
|
|
13
|
+
const types_1 = require("@polkadot/types");
|
|
14
|
+
const string_1 = require("@polkadot/util/string");
|
|
15
|
+
const util_1 = require("@polkadot/util");
|
|
16
|
+
const storage_layer_1 = require("../blockchain/storage-layer");
|
|
14
17
|
function objectToStorageItems(meta, storage) {
|
|
15
18
|
const storageItems = [];
|
|
16
19
|
for (const sectionName in storage) {
|
|
17
20
|
const section = storage[sectionName];
|
|
18
|
-
const pallet = meta.query[stringCamelCase(sectionName)];
|
|
21
|
+
const pallet = meta.query[(0, string_1.stringCamelCase)(sectionName)];
|
|
19
22
|
if (!pallet)
|
|
20
23
|
throw Error(`Cannot find pallet ${sectionName}`);
|
|
21
24
|
for (const storageName in section) {
|
|
22
25
|
const storage = section[storageName];
|
|
23
26
|
if (storageName === '$removePrefix') {
|
|
24
27
|
for (const mapName of storage) {
|
|
25
|
-
const storageEntry = pallet[stringCamelCase(mapName)];
|
|
28
|
+
const storageEntry = pallet[(0, string_1.stringCamelCase)(mapName)];
|
|
26
29
|
if (!storageEntry)
|
|
27
30
|
throw Error(`Cannot find storage ${mapName} in pallet ${sectionName}`);
|
|
28
31
|
const prefix = storageEntry.keyPrefix();
|
|
29
|
-
storageItems.push([u8aToHex(prefix), StorageValueKind.DeletedPrefix]);
|
|
32
|
+
storageItems.push([(0, util_1.u8aToHex)(prefix), storage_layer_1.StorageValueKind.DeletedPrefix]);
|
|
30
33
|
}
|
|
31
34
|
continue;
|
|
32
35
|
}
|
|
33
|
-
const storageEntry = pallet[stringCamelCase(storageName)];
|
|
36
|
+
const storageEntry = pallet[(0, string_1.stringCamelCase)(storageName)];
|
|
34
37
|
if (!storageEntry)
|
|
35
38
|
throw Error(`Cannot find storage ${storageName} in pallet ${sectionName}`);
|
|
36
39
|
if (storageEntry.meta.type.isPlain) {
|
|
37
|
-
const key = new StorageKey(meta.registry, [storageEntry]);
|
|
40
|
+
const key = new types_1.StorageKey(meta.registry, [storageEntry]);
|
|
38
41
|
const type = storageEntry.meta.modifier.isOptional ? `Option<${key.outputType}>` : key.outputType;
|
|
39
42
|
storageItems.push([key.toHex(), storage ? meta.registry.createType(type, storage).toHex() : null]);
|
|
40
43
|
}
|
|
41
44
|
else {
|
|
42
45
|
for (const [keys, value] of storage) {
|
|
43
|
-
const key = new StorageKey(meta.registry, [storageEntry, keys]);
|
|
46
|
+
const key = new types_1.StorageKey(meta.registry, [storageEntry, keys]);
|
|
44
47
|
const type = storageEntry.meta.modifier.isOptional ? `Option<${key.outputType}>` : key.outputType;
|
|
45
48
|
storageItems.push([key.toHex(), value ? meta.registry.createType(type, value).toHex() : null]);
|
|
46
49
|
}
|
|
@@ -49,7 +52,7 @@ function objectToStorageItems(meta, storage) {
|
|
|
49
52
|
}
|
|
50
53
|
return storageItems;
|
|
51
54
|
}
|
|
52
|
-
|
|
55
|
+
const setStorage = (chain, storage, blockHash) => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
56
|
const block = yield chain.getBlock(blockHash);
|
|
54
57
|
if (!block)
|
|
55
58
|
throw Error(`Cannot find block ${blockHash || 'latest'}`);
|
|
@@ -63,3 +66,4 @@ export const setStorage = (chain, storage, blockHash) => __awaiter(void 0, void
|
|
|
63
66
|
block.pushStorageLayer().setAll(storageItems);
|
|
64
67
|
return block.hash;
|
|
65
68
|
});
|
|
69
|
+
exports.setStorage = setStorage;
|
package/lib/utils/time-travel.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -7,11 +8,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
9
|
});
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.timeTravel = exports.getSlotDuration = exports.getCurrentTimestamp = exports.getCurrentSlot = void 0;
|
|
13
|
+
const util_1 = require("@polkadot/util");
|
|
14
|
+
const _1 = require(".");
|
|
15
|
+
const executor_1 = require("../executor");
|
|
16
|
+
const set_storage_1 = require("./set-storage");
|
|
17
|
+
const getCurrentSlot = (chain) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
18
|
const meta = yield chain.head.meta;
|
|
16
19
|
// use raw key here because some chain did not expose those storage to metadata
|
|
17
20
|
const slotRaw = meta.consts.babe
|
|
@@ -19,49 +22,53 @@ export const getCurrentSlot = (chain) => __awaiter(void 0, void 0, void 0, funct
|
|
|
19
22
|
: yield chain.head.get('0x57f8dc2f5ab09467896f47300f04243806155b3cd9a8c9e5e9a23fd5dc13a5ed'); // aura.currentSlot
|
|
20
23
|
if (!slotRaw)
|
|
21
24
|
throw new Error('Cannot find current slot');
|
|
22
|
-
return meta.registry.createType('Slot', hexToU8a(slotRaw)).toNumber();
|
|
25
|
+
return meta.registry.createType('Slot', (0, util_1.hexToU8a)(slotRaw)).toNumber();
|
|
23
26
|
});
|
|
24
|
-
|
|
27
|
+
exports.getCurrentSlot = getCurrentSlot;
|
|
28
|
+
const getCurrentTimestamp = (chain) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
29
|
const meta = yield chain.head.meta;
|
|
26
|
-
const currentTimestampRaw = (yield chain.head.get(compactHex(meta.query.timestamp.now()))) || '0x';
|
|
27
|
-
return meta.registry.createType('u64', hexToU8a(currentTimestampRaw)).toNumber();
|
|
30
|
+
const currentTimestampRaw = (yield chain.head.get((0, _1.compactHex)(meta.query.timestamp.now()))) || '0x';
|
|
31
|
+
return meta.registry.createType('u64', (0, util_1.hexToU8a)(currentTimestampRaw)).toNumber();
|
|
28
32
|
});
|
|
29
|
-
|
|
33
|
+
exports.getCurrentTimestamp = getCurrentTimestamp;
|
|
34
|
+
const getSlotDuration = (chain) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
35
|
const meta = yield chain.head.meta;
|
|
31
36
|
return meta.consts.babe
|
|
32
37
|
? meta.consts.babe.expectedBlockTime.toNumber()
|
|
33
38
|
: meta.query.aura
|
|
34
|
-
? getAuraSlotDuration(yield chain.head.wasm, meta.registry)
|
|
39
|
+
? (0, executor_1.getAuraSlotDuration)(yield chain.head.wasm, meta.registry)
|
|
35
40
|
: 12000;
|
|
36
41
|
});
|
|
37
|
-
|
|
42
|
+
exports.getSlotDuration = getSlotDuration;
|
|
43
|
+
const timeTravel = (chain, timestamp) => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
44
|
const meta = yield chain.head.meta;
|
|
39
|
-
const slotDuration = yield getSlotDuration(chain);
|
|
45
|
+
const slotDuration = yield (0, exports.getSlotDuration)(chain);
|
|
40
46
|
const newSlot = Math.floor(timestamp / slotDuration);
|
|
41
47
|
// new timestamp
|
|
42
48
|
const storage = [
|
|
43
|
-
[compactHex(meta.query.timestamp.now()), u8aToHex(meta.registry.createType('u64', timestamp).toU8a())],
|
|
49
|
+
[(0, _1.compactHex)(meta.query.timestamp.now()), (0, util_1.u8aToHex)(meta.registry.createType('u64', timestamp).toU8a())],
|
|
44
50
|
];
|
|
45
51
|
if (meta.consts.babe) {
|
|
46
52
|
// new slot
|
|
47
53
|
storage.push([
|
|
48
|
-
compactHex(meta.query.babe.currentSlot()),
|
|
49
|
-
u8aToHex(meta.registry.createType('Slot', newSlot).toU8a()),
|
|
54
|
+
(0, _1.compactHex)(meta.query.babe.currentSlot()),
|
|
55
|
+
(0, util_1.u8aToHex)(meta.registry.createType('Slot', newSlot).toU8a()),
|
|
50
56
|
]);
|
|
51
57
|
// new epoch
|
|
52
58
|
const epochDuration = meta.consts.babe.epochDuration.toNumber();
|
|
53
59
|
const newEpoch = Math.floor(timestamp / epochDuration);
|
|
54
60
|
storage.push([
|
|
55
|
-
compactHex(meta.query.babe.epochIndex()),
|
|
56
|
-
u8aToHex(meta.registry.createType('u64', newEpoch).toU8a()),
|
|
61
|
+
(0, _1.compactHex)(meta.query.babe.epochIndex()),
|
|
62
|
+
(0, util_1.u8aToHex)(meta.registry.createType('u64', newEpoch).toU8a()),
|
|
57
63
|
]);
|
|
58
64
|
}
|
|
59
65
|
else if (meta.query.aura) {
|
|
60
66
|
// new slot
|
|
61
67
|
storage.push([
|
|
62
|
-
compactHex(meta.query.aura.currentSlot()),
|
|
63
|
-
u8aToHex(meta.registry.createType('Slot', newSlot).toU8a()),
|
|
68
|
+
(0, _1.compactHex)(meta.query.aura.currentSlot()),
|
|
69
|
+
(0, util_1.u8aToHex)(meta.registry.createType('Slot', newSlot).toU8a()),
|
|
64
70
|
]);
|
|
65
71
|
}
|
|
66
|
-
yield setStorage(chain, storage);
|
|
72
|
+
yield (0, set_storage_1.setStorage)(chain, storage);
|
|
67
73
|
});
|
|
74
|
+
exports.timeTravel = timeTravel;
|
package/lib/xcm/downward.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -7,28 +8,31 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
9
|
});
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.connectDownward = void 0;
|
|
13
|
+
const util_1 = require("@polkadot/util");
|
|
14
|
+
const utils_1 = require("../utils");
|
|
15
|
+
const _1 = require(".");
|
|
16
|
+
const set_storage_1 = require("../utils/set-storage");
|
|
17
|
+
const connectDownward = (relaychain, parachain) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
18
|
const meta = yield relaychain.head.meta;
|
|
16
|
-
const paraId = yield getParaId(parachain);
|
|
17
|
-
const downwardMessageQueuesKey = compactHex(meta.query.dmp.downwardMessageQueues(paraId));
|
|
19
|
+
const paraId = yield (0, utils_1.getParaId)(parachain);
|
|
20
|
+
const downwardMessageQueuesKey = (0, utils_1.compactHex)(meta.query.dmp.downwardMessageQueues(paraId));
|
|
18
21
|
yield relaychain.headState.subscribeStorage([downwardMessageQueuesKey], (head, pairs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
22
|
const value = pairs[0][1];
|
|
20
23
|
if (!value)
|
|
21
24
|
return;
|
|
22
25
|
const meta = yield head.meta;
|
|
23
|
-
const downwardMessageQueuesKey = compactHex(meta.query.dmp.downwardMessageQueues(paraId));
|
|
26
|
+
const downwardMessageQueuesKey = (0, utils_1.compactHex)(meta.query.dmp.downwardMessageQueues(paraId));
|
|
24
27
|
// clear relaychain message queue
|
|
25
|
-
yield setStorage(relaychain, [[downwardMessageQueuesKey, null]], head.hash);
|
|
28
|
+
yield (0, set_storage_1.setStorage)(relaychain, [[downwardMessageQueuesKey, null]], head.hash);
|
|
26
29
|
const downwardMessages = meta.registry
|
|
27
|
-
.createType('Vec<PolkadotCorePrimitivesInboundDownwardMessage>', hexToU8a(value))
|
|
30
|
+
.createType('Vec<PolkadotCorePrimitivesInboundDownwardMessage>', (0, util_1.hexToU8a)(value))
|
|
28
31
|
.toJSON();
|
|
29
32
|
if (downwardMessages.length === 0)
|
|
30
33
|
return;
|
|
31
|
-
logger.debug({ downwardMessages }, 'downward_message');
|
|
34
|
+
_1.logger.debug({ downwardMessages }, 'downward_message');
|
|
32
35
|
parachain.submitDownwardMessages(downwardMessages);
|
|
33
36
|
}));
|
|
34
37
|
});
|
|
38
|
+
exports.connectDownward = connectDownward;
|