@acala-network/chopsticks-core 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/api.d.ts +43 -0
- package/lib/api.js +116 -0
- package/lib/blockchain/block-builder.d.ts +10 -0
- package/lib/blockchain/block-builder.js +290 -0
- package/lib/blockchain/block.d.ts +45 -0
- package/lib/blockchain/block.js +221 -0
- package/lib/blockchain/head-state.d.ts +15 -0
- package/lib/blockchain/head-state.js +94 -0
- package/lib/blockchain/index.d.ts +73 -0
- package/lib/blockchain/index.js +351 -0
- package/lib/blockchain/inherent/index.d.ts +19 -0
- package/lib/blockchain/inherent/index.js +53 -0
- package/lib/blockchain/inherent/para-enter.d.ts +7 -0
- package/lib/blockchain/inherent/para-enter.js +37 -0
- package/lib/blockchain/inherent/parachain/babe-randomness.d.ts +7 -0
- package/lib/blockchain/inherent/parachain/babe-randomness.js +23 -0
- package/lib/blockchain/inherent/parachain/nimbus-author-inherent.d.ts +7 -0
- package/lib/blockchain/inherent/parachain/nimbus-author-inherent.js +23 -0
- package/lib/blockchain/inherent/parachain/validation-data.d.ts +19 -0
- package/lib/blockchain/inherent/parachain/validation-data.js +165 -0
- package/lib/blockchain/storage-layer.d.ts +32 -0
- package/lib/blockchain/storage-layer.js +242 -0
- package/lib/blockchain/txpool.d.ts +44 -0
- package/lib/blockchain/txpool.js +210 -0
- package/lib/db/browser.d.ts +2 -0
- package/lib/db/browser.js +33 -0
- package/lib/db/entities.d.ts +16 -0
- package/lib/db/entities.js +50 -0
- package/lib/db/index.d.ts +1 -0
- package/lib/db/index.js +17 -0
- package/lib/db/node.d.ts +2 -0
- package/lib/db/node.js +22 -0
- package/lib/executor.d.ts +41 -0
- package/lib/executor.js +160 -0
- package/lib/genesis-provider.d.ts +44 -0
- package/lib/genesis-provider.js +172 -0
- package/lib/index.d.ts +13 -0
- package/lib/index.js +13 -0
- package/lib/logger.d.ts +7 -0
- package/lib/logger.js +34 -0
- package/lib/offchain.d.ts +10 -0
- package/lib/offchain.js +49 -0
- package/lib/schema/index.d.ts +62 -0
- package/lib/schema/index.js +11 -0
- package/lib/setup.d.ts +20 -0
- package/lib/setup.js +74 -0
- package/lib/utils/index.d.ts +18 -0
- package/lib/utils/index.js +65 -0
- package/lib/utils/key-cache.d.ts +10 -0
- package/lib/utils/key-cache.js +72 -0
- package/lib/utils/proof.d.ts +15 -0
- package/lib/utils/proof.js +33 -0
- package/lib/utils/set-storage.d.ts +7 -0
- package/lib/utils/set-storage.js +65 -0
- package/lib/utils/time-travel.d.ts +5 -0
- package/lib/utils/time-travel.js +67 -0
- package/lib/xcm/downward.d.ts +2 -0
- package/lib/xcm/downward.js +34 -0
- package/lib/xcm/horizontal.d.ts +2 -0
- package/lib/xcm/horizontal.js +34 -0
- package/lib/xcm/index.d.ts +9 -0
- package/lib/xcm/index.js +29 -0
- package/lib/xcm/upward.d.ts +2 -0
- package/lib/xcm/upward.js +26 -0
- package/package.json +46 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { hexToU8a, u8aConcat, u8aToHex } from '@polkadot/util';
|
|
2
|
+
import { xxhashAsU8a } from '@polkadot/util-crypto';
|
|
3
|
+
export const WELL_KNOWN_KEYS = {
|
|
4
|
+
EPOCH_INDEX: '0x1cb6f36e027abb2091cfb5110ab5087f38316cbf8fa0da822a20ac1c55bf1be3',
|
|
5
|
+
CURRENT_BLOCK_RANDOMNESS: '0x1cb6f36e027abb2091cfb5110ab5087fd077dfdb8adb10f78f10a5df8742c545',
|
|
6
|
+
ONE_EPOCH_AGO_RANDOMNESS: '0x1cb6f36e027abb2091cfb5110ab5087f7ce678799d3eff024253b90e84927cc6',
|
|
7
|
+
TWO_EPOCHS_AGO_RANDOMNESS: '0x1cb6f36e027abb2091cfb5110ab5087f7a414cb008e0e61e46722aa60abdd672',
|
|
8
|
+
CURRENT_SLOT: '0x1cb6f36e027abb2091cfb5110ab5087f06155b3cd9a8c9e5e9a23fd5dc13a5ed',
|
|
9
|
+
ACTIVE_CONFIG: '0x06de3d8a54d27e44a9d5ce189618f22db4b49d95320d9021994c850f25b8e385',
|
|
10
|
+
};
|
|
11
|
+
const hash = (prefix, suffix) => {
|
|
12
|
+
return u8aToHex(u8aConcat(hexToU8a(prefix), xxhashAsU8a(suffix, 64), suffix));
|
|
13
|
+
};
|
|
14
|
+
export const dmqMqcHead = (paraId) => {
|
|
15
|
+
const prefix = '0x63f78c98723ddc9073523ef3beefda0c4d7fefc408aac59dbfe80a72ac8e3ce5';
|
|
16
|
+
return hash(prefix, paraId.toU8a());
|
|
17
|
+
};
|
|
18
|
+
export const upgradeGoAheadSignal = (paraId) => {
|
|
19
|
+
const prefix = '0xcd710b30bd2eab0352ddcc26417aa1949e94c040f5e73d9b7addd6cb603d15d3';
|
|
20
|
+
return hash(prefix, paraId.toU8a());
|
|
21
|
+
};
|
|
22
|
+
export const hrmpIngressChannelIndex = (paraId) => {
|
|
23
|
+
const prefix = '0x6a0da05ca59913bc38a8630590f2627c1d3719f5b0b12c7105c073c507445948';
|
|
24
|
+
return hash(prefix, paraId.toU8a());
|
|
25
|
+
};
|
|
26
|
+
export const hrmpEgressChannelIndex = (paraId) => {
|
|
27
|
+
const prefix = '0x6a0da05ca59913bc38a8630590f2627cf12b746dcf32e843354583c9702cc020';
|
|
28
|
+
return hash(prefix, paraId.toU8a());
|
|
29
|
+
};
|
|
30
|
+
export const hrmpChannels = (channelId) => {
|
|
31
|
+
const prefix = '0x6a0da05ca59913bc38a8630590f2627cb6604cff828a6e3f579ca6c59ace013d';
|
|
32
|
+
return hash(prefix, channelId.toU8a());
|
|
33
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { HexString } from '@polkadot/util/types';
|
|
2
|
+
import { Blockchain } from '../blockchain';
|
|
3
|
+
type RawStorageValues = [string, string | null][];
|
|
4
|
+
type StorageConfig = Record<string, Record<string, any>>;
|
|
5
|
+
export type StorageValues = RawStorageValues | StorageConfig;
|
|
6
|
+
export declare const setStorage: (chain: Blockchain, storage: StorageValues, blockHash?: HexString) => Promise<HexString>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { StorageKey } from '@polkadot/types';
|
|
11
|
+
import { stringCamelCase } from '@polkadot/util/string';
|
|
12
|
+
import { u8aToHex } from '@polkadot/util';
|
|
13
|
+
import { StorageValueKind } from '../blockchain/storage-layer';
|
|
14
|
+
function objectToStorageItems(meta, storage) {
|
|
15
|
+
const storageItems = [];
|
|
16
|
+
for (const sectionName in storage) {
|
|
17
|
+
const section = storage[sectionName];
|
|
18
|
+
const pallet = meta.query[stringCamelCase(sectionName)];
|
|
19
|
+
if (!pallet)
|
|
20
|
+
throw Error(`Cannot find pallet ${sectionName}`);
|
|
21
|
+
for (const storageName in section) {
|
|
22
|
+
const storage = section[storageName];
|
|
23
|
+
if (storageName === '$removePrefix') {
|
|
24
|
+
for (const mapName of storage) {
|
|
25
|
+
const storageEntry = pallet[stringCamelCase(mapName)];
|
|
26
|
+
if (!storageEntry)
|
|
27
|
+
throw Error(`Cannot find storage ${mapName} in pallet ${sectionName}`);
|
|
28
|
+
const prefix = storageEntry.keyPrefix();
|
|
29
|
+
storageItems.push([u8aToHex(prefix), StorageValueKind.DeletedPrefix]);
|
|
30
|
+
}
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const storageEntry = pallet[stringCamelCase(storageName)];
|
|
34
|
+
if (!storageEntry)
|
|
35
|
+
throw Error(`Cannot find storage ${storageName} in pallet ${sectionName}`);
|
|
36
|
+
if (storageEntry.meta.type.isPlain) {
|
|
37
|
+
const key = new StorageKey(meta.registry, [storageEntry]);
|
|
38
|
+
const type = storageEntry.meta.modifier.isOptional ? `Option<${key.outputType}>` : key.outputType;
|
|
39
|
+
storageItems.push([key.toHex(), storage ? meta.registry.createType(type, storage).toHex() : null]);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
for (const [keys, value] of storage) {
|
|
43
|
+
const key = new StorageKey(meta.registry, [storageEntry, keys]);
|
|
44
|
+
const type = storageEntry.meta.modifier.isOptional ? `Option<${key.outputType}>` : key.outputType;
|
|
45
|
+
storageItems.push([key.toHex(), value ? meta.registry.createType(type, value).toHex() : null]);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return storageItems;
|
|
51
|
+
}
|
|
52
|
+
export const setStorage = (chain, storage, blockHash) => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
|
+
const block = yield chain.getBlock(blockHash);
|
|
54
|
+
if (!block)
|
|
55
|
+
throw Error(`Cannot find block ${blockHash || 'latest'}`);
|
|
56
|
+
let storageItems;
|
|
57
|
+
if (Array.isArray(storage)) {
|
|
58
|
+
storageItems = storage;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
storageItems = objectToStorageItems(yield block.meta, storage);
|
|
62
|
+
}
|
|
63
|
+
block.pushStorageLayer().setAll(storageItems);
|
|
64
|
+
return block.hash;
|
|
65
|
+
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Blockchain } from '../blockchain';
|
|
2
|
+
export declare const getCurrentSlot: (chain: Blockchain) => Promise<number>;
|
|
3
|
+
export declare const getCurrentTimestamp: (chain: Blockchain) => Promise<number>;
|
|
4
|
+
export declare const getSlotDuration: (chain: Blockchain) => Promise<number>;
|
|
5
|
+
export declare const timeTravel: (chain: Blockchain, timestamp: number) => Promise<void>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { hexToU8a, u8aToHex } from '@polkadot/util';
|
|
11
|
+
import { compactHex } from '.';
|
|
12
|
+
import { getAuraSlotDuration } from '../executor';
|
|
13
|
+
import { setStorage } from './set-storage';
|
|
14
|
+
export const getCurrentSlot = (chain) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
const meta = yield chain.head.meta;
|
|
16
|
+
// use raw key here because some chain did not expose those storage to metadata
|
|
17
|
+
const slotRaw = meta.consts.babe
|
|
18
|
+
? yield chain.head.get('0x1cb6f36e027abb2091cfb5110ab5087f06155b3cd9a8c9e5e9a23fd5dc13a5ed') // babe.currentSlot
|
|
19
|
+
: yield chain.head.get('0x57f8dc2f5ab09467896f47300f04243806155b3cd9a8c9e5e9a23fd5dc13a5ed'); // aura.currentSlot
|
|
20
|
+
if (!slotRaw)
|
|
21
|
+
throw new Error('Cannot find current slot');
|
|
22
|
+
return meta.registry.createType('Slot', hexToU8a(slotRaw)).toNumber();
|
|
23
|
+
});
|
|
24
|
+
export const getCurrentTimestamp = (chain) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
+
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();
|
|
28
|
+
});
|
|
29
|
+
export const getSlotDuration = (chain) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
+
const meta = yield chain.head.meta;
|
|
31
|
+
return meta.consts.babe
|
|
32
|
+
? meta.consts.babe.expectedBlockTime.toNumber()
|
|
33
|
+
: meta.query.aura
|
|
34
|
+
? getAuraSlotDuration(yield chain.head.wasm, meta.registry)
|
|
35
|
+
: 12000;
|
|
36
|
+
});
|
|
37
|
+
export const timeTravel = (chain, timestamp) => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
+
const meta = yield chain.head.meta;
|
|
39
|
+
const slotDuration = yield getSlotDuration(chain);
|
|
40
|
+
const newSlot = Math.floor(timestamp / slotDuration);
|
|
41
|
+
// new timestamp
|
|
42
|
+
const storage = [
|
|
43
|
+
[compactHex(meta.query.timestamp.now()), u8aToHex(meta.registry.createType('u64', timestamp).toU8a())],
|
|
44
|
+
];
|
|
45
|
+
if (meta.consts.babe) {
|
|
46
|
+
// new slot
|
|
47
|
+
storage.push([
|
|
48
|
+
compactHex(meta.query.babe.currentSlot()),
|
|
49
|
+
u8aToHex(meta.registry.createType('Slot', newSlot).toU8a()),
|
|
50
|
+
]);
|
|
51
|
+
// new epoch
|
|
52
|
+
const epochDuration = meta.consts.babe.epochDuration.toNumber();
|
|
53
|
+
const newEpoch = Math.floor(timestamp / epochDuration);
|
|
54
|
+
storage.push([
|
|
55
|
+
compactHex(meta.query.babe.epochIndex()),
|
|
56
|
+
u8aToHex(meta.registry.createType('u64', newEpoch).toU8a()),
|
|
57
|
+
]);
|
|
58
|
+
}
|
|
59
|
+
else if (meta.query.aura) {
|
|
60
|
+
// new slot
|
|
61
|
+
storage.push([
|
|
62
|
+
compactHex(meta.query.aura.currentSlot()),
|
|
63
|
+
u8aToHex(meta.registry.createType('Slot', newSlot).toU8a()),
|
|
64
|
+
]);
|
|
65
|
+
}
|
|
66
|
+
yield setStorage(chain, storage);
|
|
67
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { hexToU8a } from '@polkadot/util';
|
|
11
|
+
import { compactHex, getParaId } from '../utils';
|
|
12
|
+
import { logger } from '.';
|
|
13
|
+
import { setStorage } from '../utils/set-storage';
|
|
14
|
+
export const connectDownward = (relaychain, parachain) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
const meta = yield relaychain.head.meta;
|
|
16
|
+
const paraId = yield getParaId(parachain);
|
|
17
|
+
const downwardMessageQueuesKey = compactHex(meta.query.dmp.downwardMessageQueues(paraId));
|
|
18
|
+
yield relaychain.headState.subscribeStorage([downwardMessageQueuesKey], (head, pairs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
const value = pairs[0][1];
|
|
20
|
+
if (!value)
|
|
21
|
+
return;
|
|
22
|
+
const meta = yield head.meta;
|
|
23
|
+
const downwardMessageQueuesKey = compactHex(meta.query.dmp.downwardMessageQueues(paraId));
|
|
24
|
+
// clear relaychain message queue
|
|
25
|
+
yield setStorage(relaychain, [[downwardMessageQueuesKey, null]], head.hash);
|
|
26
|
+
const downwardMessages = meta.registry
|
|
27
|
+
.createType('Vec<PolkadotCorePrimitivesInboundDownwardMessage>', hexToU8a(value))
|
|
28
|
+
.toJSON();
|
|
29
|
+
if (downwardMessages.length === 0)
|
|
30
|
+
return;
|
|
31
|
+
logger.debug({ downwardMessages }, 'downward_message');
|
|
32
|
+
parachain.submitDownwardMessages(downwardMessages);
|
|
33
|
+
}));
|
|
34
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { hexToU8a } from '@polkadot/util';
|
|
11
|
+
import { compactHex } from '../utils';
|
|
12
|
+
import { logger } from '.';
|
|
13
|
+
export const connectHorizontal = (parachains) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
for (const [id, chain] of Object.entries(parachains)) {
|
|
15
|
+
const meta = yield chain.head.meta;
|
|
16
|
+
const hrmpOutboundMessagesKey = compactHex(meta.query.parachainSystem.hrmpOutboundMessages());
|
|
17
|
+
yield chain.headState.subscribeStorage([hrmpOutboundMessagesKey], (head, pairs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
const value = pairs[0][1];
|
|
19
|
+
if (!value)
|
|
20
|
+
return;
|
|
21
|
+
const meta = yield head.meta;
|
|
22
|
+
const outboundHrmpMessage = meta.registry
|
|
23
|
+
.createType('Vec<PolkadotCorePrimitivesOutboundHrmpMessage>', hexToU8a(value))
|
|
24
|
+
.toJSON();
|
|
25
|
+
logger.info({ outboundHrmpMessage }, 'outboundHrmpMessage');
|
|
26
|
+
for (const { recipient, data } of outboundHrmpMessage) {
|
|
27
|
+
const receiver = parachains[recipient];
|
|
28
|
+
if (receiver) {
|
|
29
|
+
receiver.submitHorizontalMessages(Number(id), [{ sentAt: head.number, data }]);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Blockchain } from '../blockchain';
|
|
2
|
+
export declare const logger: import("pino").default.Logger<{
|
|
3
|
+
level: string;
|
|
4
|
+
transport: {
|
|
5
|
+
target: string;
|
|
6
|
+
};
|
|
7
|
+
}>;
|
|
8
|
+
export declare const connectVertical: (relaychain: Blockchain, parachain: Blockchain) => Promise<void>;
|
|
9
|
+
export declare const connectParachains: (parachains: Blockchain[]) => Promise<void>;
|
package/lib/xcm/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { connectDownward } from './downward';
|
|
11
|
+
import { connectHorizontal } from './horizontal';
|
|
12
|
+
import { connectUpward } from './upward';
|
|
13
|
+
import { defaultLogger } from '../logger';
|
|
14
|
+
import { getParaId } from '../utils';
|
|
15
|
+
export const logger = defaultLogger.child({ name: 'xcm' });
|
|
16
|
+
export const connectVertical = (relaychain, parachain) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
yield connectDownward(relaychain, parachain);
|
|
18
|
+
yield connectUpward(parachain, relaychain);
|
|
19
|
+
logger.info(`Connected relaychain '${yield relaychain.api.getSystemChain()}' with parachain '${yield parachain.api.getSystemChain()}'`);
|
|
20
|
+
});
|
|
21
|
+
export const connectParachains = (parachains) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
const list = {};
|
|
23
|
+
for (const chain of parachains) {
|
|
24
|
+
const paraId = yield getParaId(chain);
|
|
25
|
+
list[paraId.toNumber()] = chain;
|
|
26
|
+
}
|
|
27
|
+
yield connectHorizontal(list);
|
|
28
|
+
logger.info(`Connected parachains [${Object.keys(list)}]`);
|
|
29
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { hexToU8a } from '@polkadot/util';
|
|
11
|
+
import { compactHex, getParaId } from '../utils';
|
|
12
|
+
export const connectUpward = (parachain, relaychain) => __awaiter(void 0, void 0, void 0, function* () {
|
|
13
|
+
const meta = yield parachain.head.meta;
|
|
14
|
+
const paraId = (yield getParaId(parachain)).toNumber();
|
|
15
|
+
const upwardMessagesKey = compactHex(meta.query.parachainSystem.upwardMessages());
|
|
16
|
+
yield parachain.headState.subscribeStorage([upwardMessagesKey], (_head, pairs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
const value = pairs[0][1];
|
|
18
|
+
if (!value)
|
|
19
|
+
return;
|
|
20
|
+
const meta = yield relaychain.head.meta;
|
|
21
|
+
const upwardMessages = meta.registry.createType('Vec<Bytes>', hexToU8a(value));
|
|
22
|
+
if (upwardMessages.length === 0)
|
|
23
|
+
return;
|
|
24
|
+
relaychain.submitUpwardMessages(paraId, upwardMessages.map((x) => x.toHex()));
|
|
25
|
+
}));
|
|
26
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@acala-network/chopsticks-core",
|
|
3
|
+
"version": "0.8.0-0",
|
|
4
|
+
"author": "Bryan Chen <xlchen1291@gmail.com>",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"clean": "rm -rf lib tsconfig.tsbuildinfo",
|
|
8
|
+
"build": "tsc -p ./tsconfig.json"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@acala-network/chopsticks-executor": "0.8.0-0",
|
|
12
|
+
"@polkadot/api": "^10.9.1",
|
|
13
|
+
"axios": "^1.4.0",
|
|
14
|
+
"eventemitter3": "^5.0.1",
|
|
15
|
+
"localforage": "^1.10.0",
|
|
16
|
+
"lodash": "^4.17.21",
|
|
17
|
+
"pino": "^8.14.1",
|
|
18
|
+
"pino-pretty": "^10.0.1",
|
|
19
|
+
"sql.js": "^1.8.0",
|
|
20
|
+
"sqlite3": "^5.1.6",
|
|
21
|
+
"typeorm": "^0.3.17",
|
|
22
|
+
"zod": "^3.21.4"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/lodash": "^4.14.195",
|
|
26
|
+
"@types/sql.js": "^1",
|
|
27
|
+
"typescript": "^5.1.6"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"lib"
|
|
31
|
+
],
|
|
32
|
+
"main": "./lib/index.js",
|
|
33
|
+
"types": "./lib/index.d.ts",
|
|
34
|
+
"exports": {
|
|
35
|
+
".": {
|
|
36
|
+
"types": "./lib/index.d.ts",
|
|
37
|
+
"default": "./lib/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./*": {
|
|
40
|
+
"types": "./lib/*.d.ts",
|
|
41
|
+
"default": "./lib/*.js"
|
|
42
|
+
},
|
|
43
|
+
"./package.json": "./package.json"
|
|
44
|
+
},
|
|
45
|
+
"stableVersion": "0.7.3"
|
|
46
|
+
}
|