@acala-network/chopsticks-core 0.9.13 → 0.10.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/dist/cjs/blockchain/storage-layer.js +1 -1
- package/dist/cjs/env.d.ts +69 -0
- package/dist/cjs/env.js +105 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/logger.js +4 -5
- package/dist/cjs/rpc/substrate/chain.d.ts +4 -2
- package/dist/cjs/rpc/substrate/chain.js +2 -1
- package/dist/cjs/rpc/substrate/index.d.ts +3 -2
- package/dist/cjs/rpc/substrate/state.d.ts +1 -0
- package/dist/cjs/rpc/substrate/state.js +4 -0
- package/dist/cjs/xcm/horizontal.d.ts +1 -1
- package/dist/cjs/xcm/horizontal.js +2 -2
- package/dist/cjs/xcm/index.d.ts +1 -1
- package/dist/cjs/xcm/index.js +2 -2
- package/dist/esm/blockchain/storage-layer.js +1 -1
- package/dist/esm/env.d.ts +69 -0
- package/dist/esm/env.js +48 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/logger.js +4 -5
- package/dist/esm/rpc/substrate/chain.d.ts +4 -2
- package/dist/esm/rpc/substrate/chain.js +2 -1
- package/dist/esm/rpc/substrate/index.d.ts +3 -2
- package/dist/esm/rpc/substrate/state.d.ts +1 -0
- package/dist/esm/rpc/substrate/state.js +1 -0
- package/dist/esm/xcm/horizontal.d.ts +1 -1
- package/dist/esm/xcm/horizontal.js +2 -2
- package/dist/esm/xcm/index.d.ts +1 -1
- package/dist/esm/xcm/index.js +2 -2
- package/package.json +2 -2
|
@@ -311,7 +311,7 @@ class StorageLayer {
|
|
|
311
311
|
if (idx !== -1) {
|
|
312
312
|
if (includeFirst) {
|
|
313
313
|
const key = _class_private_field_get(this, _keys)[idx];
|
|
314
|
-
if (key && key.startsWith(prefix)) {
|
|
314
|
+
if (key && key.startsWith(prefix) && key > startKey) {
|
|
315
315
|
foundNextKey(key);
|
|
316
316
|
}
|
|
317
317
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
export declare const environmentSchema: z.ZodObject<{
|
|
3
|
+
/**
|
|
4
|
+
* Disable auto HRMP on setup. Default is `false`.
|
|
5
|
+
*/
|
|
6
|
+
DISABLE_AUTO_HRMP: z.ZodEffects<z.ZodDefault<z.ZodEnum<["true", "false"]>>, boolean, "true" | "false" | undefined>;
|
|
7
|
+
/**
|
|
8
|
+
* Set port for Chopsticks to listen on, default is `8000`.
|
|
9
|
+
*/
|
|
10
|
+
PORT: z.ZodOptional<z.ZodString>;
|
|
11
|
+
/**
|
|
12
|
+
* Disable plugins for faster startup. Default is `false`.
|
|
13
|
+
*/
|
|
14
|
+
DISABLE_PLUGINS: z.ZodEffects<z.ZodDefault<z.ZodEnum<["true", "false"]>>, boolean, "true" | "false" | undefined>;
|
|
15
|
+
HTTP_PROXY: z.ZodOptional<z.ZodString>;
|
|
16
|
+
http_proxy: z.ZodOptional<z.ZodString>;
|
|
17
|
+
HTTPS_PROXY: z.ZodOptional<z.ZodString>;
|
|
18
|
+
https_proxy: z.ZodOptional<z.ZodString>;
|
|
19
|
+
/**
|
|
20
|
+
* Chopsticks log level, "fatal" | "error" | "warn" | "info" | "debug" | "trace".
|
|
21
|
+
* Default is "info".
|
|
22
|
+
*/
|
|
23
|
+
LOG_LEVEL: z.ZodDefault<z.ZodEnum<["fatal", "error", "warn", "info", "debug", "trace"]>>;
|
|
24
|
+
/**
|
|
25
|
+
* Don't truncate log messages, show full log output. Default is `false`.
|
|
26
|
+
*/
|
|
27
|
+
VERBOSE_LOG: z.ZodEffects<z.ZodDefault<z.ZodEnum<["true", "false"]>>, boolean, "true" | "false" | undefined>;
|
|
28
|
+
/**
|
|
29
|
+
* Don't log objects. Default is `false`.
|
|
30
|
+
*/
|
|
31
|
+
LOG_COMPACT: z.ZodEffects<z.ZodDefault<z.ZodEnum<["true", "false"]>>, boolean, "true" | "false" | undefined>;
|
|
32
|
+
}, "strip", z.ZodTypeAny, {
|
|
33
|
+
DISABLE_AUTO_HRMP: boolean;
|
|
34
|
+
DISABLE_PLUGINS: boolean;
|
|
35
|
+
LOG_LEVEL: "error" | "fatal" | "warn" | "info" | "debug" | "trace";
|
|
36
|
+
VERBOSE_LOG: boolean;
|
|
37
|
+
LOG_COMPACT: boolean;
|
|
38
|
+
PORT?: string | undefined;
|
|
39
|
+
HTTP_PROXY?: string | undefined;
|
|
40
|
+
http_proxy?: string | undefined;
|
|
41
|
+
HTTPS_PROXY?: string | undefined;
|
|
42
|
+
https_proxy?: string | undefined;
|
|
43
|
+
}, {
|
|
44
|
+
DISABLE_AUTO_HRMP?: "true" | "false" | undefined;
|
|
45
|
+
PORT?: string | undefined;
|
|
46
|
+
DISABLE_PLUGINS?: "true" | "false" | undefined;
|
|
47
|
+
HTTP_PROXY?: string | undefined;
|
|
48
|
+
http_proxy?: string | undefined;
|
|
49
|
+
HTTPS_PROXY?: string | undefined;
|
|
50
|
+
https_proxy?: string | undefined;
|
|
51
|
+
LOG_LEVEL?: "error" | "fatal" | "warn" | "info" | "debug" | "trace" | undefined;
|
|
52
|
+
VERBOSE_LOG?: "true" | "false" | undefined;
|
|
53
|
+
LOG_COMPACT?: "true" | "false" | undefined;
|
|
54
|
+
}>;
|
|
55
|
+
/**
|
|
56
|
+
* Environment variables available for users
|
|
57
|
+
*/
|
|
58
|
+
export declare const environment: {
|
|
59
|
+
DISABLE_AUTO_HRMP: boolean;
|
|
60
|
+
DISABLE_PLUGINS: boolean;
|
|
61
|
+
LOG_LEVEL: "error" | "fatal" | "warn" | "info" | "debug" | "trace";
|
|
62
|
+
VERBOSE_LOG: boolean;
|
|
63
|
+
LOG_COMPACT: boolean;
|
|
64
|
+
PORT?: string | undefined;
|
|
65
|
+
HTTP_PROXY?: string | undefined;
|
|
66
|
+
http_proxy?: string | undefined;
|
|
67
|
+
HTTPS_PROXY?: string | undefined;
|
|
68
|
+
https_proxy?: string | undefined;
|
|
69
|
+
};
|
package/dist/cjs/env.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
environment: function() {
|
|
13
|
+
return environment;
|
|
14
|
+
},
|
|
15
|
+
environmentSchema: function() {
|
|
16
|
+
return environmentSchema;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _zod = /*#__PURE__*/ _interop_require_wildcard(require("zod"));
|
|
20
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
21
|
+
if (typeof WeakMap !== "function") return null;
|
|
22
|
+
var cacheBabelInterop = new WeakMap();
|
|
23
|
+
var cacheNodeInterop = new WeakMap();
|
|
24
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
25
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
26
|
+
})(nodeInterop);
|
|
27
|
+
}
|
|
28
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
29
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
30
|
+
return obj;
|
|
31
|
+
}
|
|
32
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
33
|
+
return {
|
|
34
|
+
default: obj
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
38
|
+
if (cache && cache.has(obj)) {
|
|
39
|
+
return cache.get(obj);
|
|
40
|
+
}
|
|
41
|
+
var newObj = {
|
|
42
|
+
__proto__: null
|
|
43
|
+
};
|
|
44
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
45
|
+
for(var key in obj){
|
|
46
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
47
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
48
|
+
if (desc && (desc.get || desc.set)) {
|
|
49
|
+
Object.defineProperty(newObj, key, desc);
|
|
50
|
+
} else {
|
|
51
|
+
newObj[key] = obj[key];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
newObj.default = obj;
|
|
56
|
+
if (cache) {
|
|
57
|
+
cache.set(obj, newObj);
|
|
58
|
+
}
|
|
59
|
+
return newObj;
|
|
60
|
+
}
|
|
61
|
+
const environmentSchema = _zod.object({
|
|
62
|
+
/**
|
|
63
|
+
* Disable auto HRMP on setup. Default is `false`.
|
|
64
|
+
*/ DISABLE_AUTO_HRMP: _zod.enum([
|
|
65
|
+
'true',
|
|
66
|
+
'false'
|
|
67
|
+
]).default('false').transform((v)=>v === 'true'),
|
|
68
|
+
/**
|
|
69
|
+
* Set port for Chopsticks to listen on, default is `8000`.
|
|
70
|
+
*/ PORT: _zod.string().optional(),
|
|
71
|
+
/**
|
|
72
|
+
* Disable plugins for faster startup. Default is `false`.
|
|
73
|
+
*/ DISABLE_PLUGINS: _zod.enum([
|
|
74
|
+
'true',
|
|
75
|
+
'false'
|
|
76
|
+
]).default('false').transform((v)=>v === 'true'),
|
|
77
|
+
HTTP_PROXY: _zod.string().optional(),
|
|
78
|
+
http_proxy: _zod.string().optional(),
|
|
79
|
+
HTTPS_PROXY: _zod.string().optional(),
|
|
80
|
+
https_proxy: _zod.string().optional(),
|
|
81
|
+
/**
|
|
82
|
+
* Chopsticks log level, "fatal" | "error" | "warn" | "info" | "debug" | "trace".
|
|
83
|
+
* Default is "info".
|
|
84
|
+
*/ LOG_LEVEL: _zod.enum([
|
|
85
|
+
'fatal',
|
|
86
|
+
'error',
|
|
87
|
+
'warn',
|
|
88
|
+
'info',
|
|
89
|
+
'debug',
|
|
90
|
+
'trace'
|
|
91
|
+
]).default('info'),
|
|
92
|
+
/**
|
|
93
|
+
* Don't truncate log messages, show full log output. Default is `false`.
|
|
94
|
+
*/ VERBOSE_LOG: _zod.enum([
|
|
95
|
+
'true',
|
|
96
|
+
'false'
|
|
97
|
+
]).default('false').transform((v)=>v === 'true'),
|
|
98
|
+
/**
|
|
99
|
+
* Don't log objects. Default is `false`.
|
|
100
|
+
*/ LOG_COMPACT: _zod.enum([
|
|
101
|
+
'true',
|
|
102
|
+
'false'
|
|
103
|
+
]).default('false').transform((v)=>v === 'true')
|
|
104
|
+
});
|
|
105
|
+
const environment = environmentSchema.parse(typeof process === 'object' ? process.env : {});
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -36,6 +36,7 @@ export * from './blockchain/block-builder.js';
|
|
|
36
36
|
export * from './blockchain/txpool.js';
|
|
37
37
|
export * from './blockchain/storage-layer.js';
|
|
38
38
|
export * from './blockchain/head-state.js';
|
|
39
|
+
export * from './env.js';
|
|
39
40
|
export * from './utils/index.js';
|
|
40
41
|
export * from './wasm-executor/index.js';
|
|
41
42
|
export * from './schema/index.js';
|
package/dist/cjs/index.js
CHANGED
|
@@ -17,6 +17,7 @@ _export_star(require("./blockchain/block-builder.js"), exports);
|
|
|
17
17
|
_export_star(require("./blockchain/txpool.js"), exports);
|
|
18
18
|
_export_star(require("./blockchain/storage-layer.js"), exports);
|
|
19
19
|
_export_star(require("./blockchain/head-state.js"), exports);
|
|
20
|
+
_export_star(require("./env.js"), exports);
|
|
20
21
|
_export_star(require("./utils/index.js"), exports);
|
|
21
22
|
_export_star(require("./wasm-executor/index.js"), exports);
|
|
22
23
|
_export_star(require("./schema/index.js"), exports);
|
package/dist/cjs/logger.js
CHANGED
|
@@ -20,15 +20,14 @@ _export(exports, {
|
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
22
|
const _pino = require("pino");
|
|
23
|
-
const
|
|
24
|
-
const hideObject = typeof process === 'object' && !!process.env.LOG_COMPACT || false;
|
|
23
|
+
const _env = require("./env.js");
|
|
25
24
|
const pinoLogger = (0, _pino.pino)({
|
|
26
|
-
level,
|
|
25
|
+
level: _env.environment.LOG_LEVEL,
|
|
27
26
|
transport: {
|
|
28
27
|
target: 'pino-pretty',
|
|
29
28
|
options: {
|
|
30
29
|
ignore: 'pid,hostname',
|
|
31
|
-
hideObject
|
|
30
|
+
hideObject: _env.environment.LOG_COMPACT
|
|
32
31
|
}
|
|
33
32
|
}
|
|
34
33
|
});
|
|
@@ -36,7 +35,7 @@ const defaultLogger = pinoLogger.child({
|
|
|
36
35
|
app: 'chopsticks'
|
|
37
36
|
});
|
|
38
37
|
const innerTruncate = (level = 0)=>(val)=>{
|
|
39
|
-
const verboseLog =
|
|
38
|
+
const verboseLog = _env.environment.VERBOSE_LOG;
|
|
40
39
|
const levelLimit = verboseLog ? 10 : 5;
|
|
41
40
|
if (val == null) {
|
|
42
41
|
return val;
|
|
@@ -7,7 +7,9 @@ import type { Header } from '../../index.js';
|
|
|
7
7
|
*
|
|
8
8
|
* @return Block hash | hash[] | null
|
|
9
9
|
*/
|
|
10
|
-
export declare const chain_getBlockHash: Handler<[
|
|
10
|
+
export declare const chain_getBlockHash: Handler<[
|
|
11
|
+
number | HexString | number[] | HexString[] | null
|
|
12
|
+
], HexString | (HexString | null)[] | null>;
|
|
11
13
|
/**
|
|
12
14
|
* @param context
|
|
13
15
|
* @param params - [`blockhash`]
|
|
@@ -39,7 +41,7 @@ export declare const chain_getFinalizedHead: Handler<void, HexString>;
|
|
|
39
41
|
export declare const chain_subscribeNewHead: Handler<void, string>;
|
|
40
42
|
export declare const chain_subscribeFinalizedHeads: Handler<void, string>;
|
|
41
43
|
export declare const chain_unsubscribeNewHead: Handler<[string], void>;
|
|
42
|
-
export declare const chain_getHead: Handler<[number | number[] | null], `0x${string}` | (`0x${string}` | null)[] | null>;
|
|
44
|
+
export declare const chain_getHead: Handler<[number | `0x${string}` | `0x${string}`[] | number[] | null], `0x${string}` | (`0x${string}` | null)[] | null>;
|
|
43
45
|
export declare const chain_subscribeNewHeads: Handler<void, string>;
|
|
44
46
|
export declare const chain_unsubscribeNewHeads: Handler<[string], void>;
|
|
45
47
|
export declare const chain_unsubscribeFinalizedHeads: Handler<[string], void>;
|
|
@@ -43,6 +43,7 @@ _export(exports, {
|
|
|
43
43
|
return chain_unsubscribeNewHeads;
|
|
44
44
|
}
|
|
45
45
|
});
|
|
46
|
+
const _util = require("@polkadot/util");
|
|
46
47
|
const _shared = require("../shared.js");
|
|
47
48
|
const processHeader = ({ parentHash, number, stateRoot, extrinsicsRoot, digest })=>{
|
|
48
49
|
return {
|
|
@@ -59,7 +60,7 @@ const chain_getBlockHash = async (context, [blockNumber])=>{
|
|
|
59
60
|
const numbers = Array.isArray(blockNumber) ? blockNumber : [
|
|
60
61
|
blockNumber
|
|
61
62
|
];
|
|
62
|
-
const hashes = await Promise.all(numbers.map((n)=>context.chain.getBlockAt(n))).then((blocks)=>blocks.map((b)=>b?.hash || null));
|
|
63
|
+
const hashes = await Promise.all(numbers.map((n)=>(0, _util.isHex)(n, undefined, true) ? (0, _util.hexToNumber)(n) : n).map((n)=>context.chain.getBlockAt(n))).then((blocks)=>blocks.map((b)=>b?.hash || null));
|
|
63
64
|
return Array.isArray(blockNumber) ? hashes : hashes[0];
|
|
64
65
|
};
|
|
65
66
|
const chain_getHeader = async (context, [hash])=>{
|
|
@@ -39,9 +39,10 @@ declare const handlers: {
|
|
|
39
39
|
state_unsubscribeStorage: import("../shared.js").Handler<[string], void>;
|
|
40
40
|
childstate_getStorage: import("../shared.js").Handler<[`0x${string}`, `0x${string}`, `0x${string}`], string | null>;
|
|
41
41
|
childstate_getKeysPaged: import("../shared.js").Handler<[`0x${string}`, `0x${string}`, number, `0x${string}`, `0x${string}`], `0x${string}`[] | undefined>;
|
|
42
|
+
state_getStorageAt: import("../shared.js").Handler<[`0x${string}`, `0x${string}`], string | null>;
|
|
42
43
|
payment_queryFeeDetails: import("../shared.js").Handler<[`0x${string}`, `0x${string}`], `0x${string}`>;
|
|
43
44
|
payment_queryInfo: import("../shared.js").Handler<[`0x${string}`, `0x${string}`], `0x${string}`>;
|
|
44
|
-
chain_getBlockHash: import("../shared.js").Handler<[number | number[] | null], `0x${string}` | (`0x${string}` | null)[] | null>;
|
|
45
|
+
chain_getBlockHash: import("../shared.js").Handler<[number | `0x${string}` | `0x${string}`[] | number[] | null], `0x${string}` | (`0x${string}` | null)[] | null>;
|
|
45
46
|
chain_getHeader: import("../shared.js").Handler<[`0x${string}`], import("../../index.js").Header>;
|
|
46
47
|
chain_getBlock: import("../shared.js").Handler<[`0x${string}`], {
|
|
47
48
|
block: {
|
|
@@ -54,7 +55,7 @@ declare const handlers: {
|
|
|
54
55
|
chain_subscribeNewHead: import("../shared.js").Handler<void, string>;
|
|
55
56
|
chain_subscribeFinalizedHeads: import("../shared.js").Handler<void, string>;
|
|
56
57
|
chain_unsubscribeNewHead: import("../shared.js").Handler<[string], void>;
|
|
57
|
-
chain_getHead: import("../shared.js").Handler<[number | number[] | null], `0x${string}` | (`0x${string}` | null)[] | null>;
|
|
58
|
+
chain_getHead: import("../shared.js").Handler<[number | `0x${string}` | `0x${string}`[] | number[] | null], `0x${string}` | (`0x${string}` | null)[] | null>;
|
|
58
59
|
chain_subscribeNewHeads: import("../shared.js").Handler<void, string>;
|
|
59
60
|
chain_unsubscribeNewHeads: import("../shared.js").Handler<[string], void>;
|
|
60
61
|
chain_unsubscribeFinalizedHeads: import("../shared.js").Handler<[string], void>;
|
|
@@ -30,6 +30,9 @@ _export(exports, {
|
|
|
30
30
|
state_getStorage: function() {
|
|
31
31
|
return state_getStorage;
|
|
32
32
|
},
|
|
33
|
+
state_getStorageAt: function() {
|
|
34
|
+
return state_getStorageAt;
|
|
35
|
+
},
|
|
33
36
|
state_queryStorageAt: function() {
|
|
34
37
|
return state_queryStorageAt;
|
|
35
38
|
},
|
|
@@ -165,3 +168,4 @@ const childstate_getKeysPaged = async (context, [child, prefix, pageSize, startK
|
|
|
165
168
|
startKey: (0, _index.prefixedChildKey)(child, startKey)
|
|
166
169
|
}).then((keys)=>keys.map(_index.stripChildPrefix));
|
|
167
170
|
};
|
|
171
|
+
const state_getStorageAt = state_getStorage;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Blockchain } from '../blockchain/index.js';
|
|
2
|
-
export declare const connectHorizontal: (parachains: Record<number, Blockchain
|
|
2
|
+
export declare const connectHorizontal: (parachains: Record<number, Blockchain>, disableAutoHrmp?: boolean) => Promise<void>;
|
|
@@ -11,7 +11,7 @@ Object.defineProperty(exports, "connectHorizontal", {
|
|
|
11
11
|
const _util = require("@polkadot/util");
|
|
12
12
|
const _index = require("../utils/index.js");
|
|
13
13
|
const _index1 = require("./index.js");
|
|
14
|
-
const connectHorizontal = async (parachains)=>{
|
|
14
|
+
const connectHorizontal = async (parachains, disableAutoHrmp = false)=>{
|
|
15
15
|
for (const [id, chain] of Object.entries(parachains)){
|
|
16
16
|
const meta = await chain.head.meta;
|
|
17
17
|
const hrmpOutboundMessagesKey = (0, _index.compactHex)(meta.query.parachainSystem.hrmpOutboundMessages());
|
|
@@ -38,7 +38,7 @@ const connectHorizontal = async (parachains)=>{
|
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
40
|
const hrmpHeads = await chain.head.read('BTreeMap<u32, H256>', meta.query.parachainSystem.lastHrmpMqcHeads);
|
|
41
|
-
if (hrmpHeads && !
|
|
41
|
+
if (hrmpHeads && !disableAutoHrmp) {
|
|
42
42
|
const existingChannels = Array.from(hrmpHeads.keys()).map((x)=>x.toNumber());
|
|
43
43
|
for (const paraId of Object.keys(parachains).filter((x)=>x !== id)){
|
|
44
44
|
if (!existingChannels.includes(Number(paraId))) {
|
package/dist/cjs/xcm/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Blockchain } from '../blockchain/index.js';
|
|
2
2
|
export declare const xcmLogger: import("pino").default.Logger<never>;
|
|
3
3
|
export declare const connectVertical: (relaychain: Blockchain, parachain: Blockchain) => Promise<void>;
|
|
4
|
-
export declare const connectParachains: (parachains: Blockchain[]) => Promise<void>;
|
|
4
|
+
export declare const connectParachains: (parachains: Blockchain[], disableAutoHrmp?: boolean) => Promise<void>;
|
package/dist/cjs/xcm/index.js
CHANGED
|
@@ -32,12 +32,12 @@ const connectVertical = async (relaychain, parachain)=>{
|
|
|
32
32
|
await (0, _upward.connectUpward)(parachain, relaychain);
|
|
33
33
|
xcmLogger.info(`Connected relaychain '${await relaychain.api.getSystemChain()}' with parachain '${await parachain.api.getSystemChain()}'`);
|
|
34
34
|
};
|
|
35
|
-
const connectParachains = async (parachains)=>{
|
|
35
|
+
const connectParachains = async (parachains, disableAutoHrmp = false)=>{
|
|
36
36
|
const list = {};
|
|
37
37
|
for (const chain of parachains){
|
|
38
38
|
const paraId = await (0, _index.getParaId)(chain);
|
|
39
39
|
list[paraId.toNumber()] = chain;
|
|
40
40
|
}
|
|
41
|
-
await (0, _horizontal.connectHorizontal)(list);
|
|
41
|
+
await (0, _horizontal.connectHorizontal)(list, disableAutoHrmp);
|
|
42
42
|
xcmLogger.info(`Connected parachains [${Object.keys(list)}]`);
|
|
43
43
|
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
export declare const environmentSchema: z.ZodObject<{
|
|
3
|
+
/**
|
|
4
|
+
* Disable auto HRMP on setup. Default is `false`.
|
|
5
|
+
*/
|
|
6
|
+
DISABLE_AUTO_HRMP: z.ZodEffects<z.ZodDefault<z.ZodEnum<["true", "false"]>>, boolean, "true" | "false" | undefined>;
|
|
7
|
+
/**
|
|
8
|
+
* Set port for Chopsticks to listen on, default is `8000`.
|
|
9
|
+
*/
|
|
10
|
+
PORT: z.ZodOptional<z.ZodString>;
|
|
11
|
+
/**
|
|
12
|
+
* Disable plugins for faster startup. Default is `false`.
|
|
13
|
+
*/
|
|
14
|
+
DISABLE_PLUGINS: z.ZodEffects<z.ZodDefault<z.ZodEnum<["true", "false"]>>, boolean, "true" | "false" | undefined>;
|
|
15
|
+
HTTP_PROXY: z.ZodOptional<z.ZodString>;
|
|
16
|
+
http_proxy: z.ZodOptional<z.ZodString>;
|
|
17
|
+
HTTPS_PROXY: z.ZodOptional<z.ZodString>;
|
|
18
|
+
https_proxy: z.ZodOptional<z.ZodString>;
|
|
19
|
+
/**
|
|
20
|
+
* Chopsticks log level, "fatal" | "error" | "warn" | "info" | "debug" | "trace".
|
|
21
|
+
* Default is "info".
|
|
22
|
+
*/
|
|
23
|
+
LOG_LEVEL: z.ZodDefault<z.ZodEnum<["fatal", "error", "warn", "info", "debug", "trace"]>>;
|
|
24
|
+
/**
|
|
25
|
+
* Don't truncate log messages, show full log output. Default is `false`.
|
|
26
|
+
*/
|
|
27
|
+
VERBOSE_LOG: z.ZodEffects<z.ZodDefault<z.ZodEnum<["true", "false"]>>, boolean, "true" | "false" | undefined>;
|
|
28
|
+
/**
|
|
29
|
+
* Don't log objects. Default is `false`.
|
|
30
|
+
*/
|
|
31
|
+
LOG_COMPACT: z.ZodEffects<z.ZodDefault<z.ZodEnum<["true", "false"]>>, boolean, "true" | "false" | undefined>;
|
|
32
|
+
}, "strip", z.ZodTypeAny, {
|
|
33
|
+
DISABLE_AUTO_HRMP: boolean;
|
|
34
|
+
DISABLE_PLUGINS: boolean;
|
|
35
|
+
LOG_LEVEL: "error" | "fatal" | "warn" | "info" | "debug" | "trace";
|
|
36
|
+
VERBOSE_LOG: boolean;
|
|
37
|
+
LOG_COMPACT: boolean;
|
|
38
|
+
PORT?: string | undefined;
|
|
39
|
+
HTTP_PROXY?: string | undefined;
|
|
40
|
+
http_proxy?: string | undefined;
|
|
41
|
+
HTTPS_PROXY?: string | undefined;
|
|
42
|
+
https_proxy?: string | undefined;
|
|
43
|
+
}, {
|
|
44
|
+
DISABLE_AUTO_HRMP?: "true" | "false" | undefined;
|
|
45
|
+
PORT?: string | undefined;
|
|
46
|
+
DISABLE_PLUGINS?: "true" | "false" | undefined;
|
|
47
|
+
HTTP_PROXY?: string | undefined;
|
|
48
|
+
http_proxy?: string | undefined;
|
|
49
|
+
HTTPS_PROXY?: string | undefined;
|
|
50
|
+
https_proxy?: string | undefined;
|
|
51
|
+
LOG_LEVEL?: "error" | "fatal" | "warn" | "info" | "debug" | "trace" | undefined;
|
|
52
|
+
VERBOSE_LOG?: "true" | "false" | undefined;
|
|
53
|
+
LOG_COMPACT?: "true" | "false" | undefined;
|
|
54
|
+
}>;
|
|
55
|
+
/**
|
|
56
|
+
* Environment variables available for users
|
|
57
|
+
*/
|
|
58
|
+
export declare const environment: {
|
|
59
|
+
DISABLE_AUTO_HRMP: boolean;
|
|
60
|
+
DISABLE_PLUGINS: boolean;
|
|
61
|
+
LOG_LEVEL: "error" | "fatal" | "warn" | "info" | "debug" | "trace";
|
|
62
|
+
VERBOSE_LOG: boolean;
|
|
63
|
+
LOG_COMPACT: boolean;
|
|
64
|
+
PORT?: string | undefined;
|
|
65
|
+
HTTP_PROXY?: string | undefined;
|
|
66
|
+
http_proxy?: string | undefined;
|
|
67
|
+
HTTPS_PROXY?: string | undefined;
|
|
68
|
+
https_proxy?: string | undefined;
|
|
69
|
+
};
|
package/dist/esm/env.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
export const environmentSchema = z.object({
|
|
3
|
+
/**
|
|
4
|
+
* Disable auto HRMP on setup. Default is `false`.
|
|
5
|
+
*/ DISABLE_AUTO_HRMP: z.enum([
|
|
6
|
+
'true',
|
|
7
|
+
'false'
|
|
8
|
+
]).default('false').transform((v)=>v === 'true'),
|
|
9
|
+
/**
|
|
10
|
+
* Set port for Chopsticks to listen on, default is `8000`.
|
|
11
|
+
*/ PORT: z.string().optional(),
|
|
12
|
+
/**
|
|
13
|
+
* Disable plugins for faster startup. Default is `false`.
|
|
14
|
+
*/ DISABLE_PLUGINS: z.enum([
|
|
15
|
+
'true',
|
|
16
|
+
'false'
|
|
17
|
+
]).default('false').transform((v)=>v === 'true'),
|
|
18
|
+
HTTP_PROXY: z.string().optional(),
|
|
19
|
+
http_proxy: z.string().optional(),
|
|
20
|
+
HTTPS_PROXY: z.string().optional(),
|
|
21
|
+
https_proxy: z.string().optional(),
|
|
22
|
+
/**
|
|
23
|
+
* Chopsticks log level, "fatal" | "error" | "warn" | "info" | "debug" | "trace".
|
|
24
|
+
* Default is "info".
|
|
25
|
+
*/ LOG_LEVEL: z.enum([
|
|
26
|
+
'fatal',
|
|
27
|
+
'error',
|
|
28
|
+
'warn',
|
|
29
|
+
'info',
|
|
30
|
+
'debug',
|
|
31
|
+
'trace'
|
|
32
|
+
]).default('info'),
|
|
33
|
+
/**
|
|
34
|
+
* Don't truncate log messages, show full log output. Default is `false`.
|
|
35
|
+
*/ VERBOSE_LOG: z.enum([
|
|
36
|
+
'true',
|
|
37
|
+
'false'
|
|
38
|
+
]).default('false').transform((v)=>v === 'true'),
|
|
39
|
+
/**
|
|
40
|
+
* Don't log objects. Default is `false`.
|
|
41
|
+
*/ LOG_COMPACT: z.enum([
|
|
42
|
+
'true',
|
|
43
|
+
'false'
|
|
44
|
+
]).default('false').transform((v)=>v === 'true')
|
|
45
|
+
});
|
|
46
|
+
/**
|
|
47
|
+
* Environment variables available for users
|
|
48
|
+
*/ export const environment = environmentSchema.parse(typeof process === 'object' ? process.env : {});
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -36,6 +36,7 @@ export * from './blockchain/block-builder.js';
|
|
|
36
36
|
export * from './blockchain/txpool.js';
|
|
37
37
|
export * from './blockchain/storage-layer.js';
|
|
38
38
|
export * from './blockchain/head-state.js';
|
|
39
|
+
export * from './env.js';
|
|
39
40
|
export * from './utils/index.js';
|
|
40
41
|
export * from './wasm-executor/index.js';
|
|
41
42
|
export * from './schema/index.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -13,6 +13,7 @@ export * from './blockchain/block-builder.js';
|
|
|
13
13
|
export * from './blockchain/txpool.js';
|
|
14
14
|
export * from './blockchain/storage-layer.js';
|
|
15
15
|
export * from './blockchain/head-state.js';
|
|
16
|
+
export * from './env.js';
|
|
16
17
|
export * from './utils/index.js';
|
|
17
18
|
export * from './wasm-executor/index.js';
|
|
18
19
|
export * from './schema/index.js';
|
package/dist/esm/logger.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { pino } from 'pino';
|
|
2
|
-
|
|
3
|
-
const hideObject = typeof process === 'object' && !!process.env.LOG_COMPACT || false;
|
|
2
|
+
import { environment } from './env.js';
|
|
4
3
|
export const pinoLogger = pino({
|
|
5
|
-
level,
|
|
4
|
+
level: environment.LOG_LEVEL,
|
|
6
5
|
transport: {
|
|
7
6
|
target: 'pino-pretty',
|
|
8
7
|
options: {
|
|
9
8
|
ignore: 'pid,hostname',
|
|
10
|
-
hideObject
|
|
9
|
+
hideObject: environment.LOG_COMPACT
|
|
11
10
|
}
|
|
12
11
|
}
|
|
13
12
|
});
|
|
@@ -15,7 +14,7 @@ export const defaultLogger = pinoLogger.child({
|
|
|
15
14
|
app: 'chopsticks'
|
|
16
15
|
});
|
|
17
16
|
const innerTruncate = (level = 0)=>(val)=>{
|
|
18
|
-
const verboseLog =
|
|
17
|
+
const verboseLog = environment.VERBOSE_LOG;
|
|
19
18
|
const levelLimit = verboseLog ? 10 : 5;
|
|
20
19
|
if (val == null) {
|
|
21
20
|
return val;
|
|
@@ -7,7 +7,9 @@ import type { Header } from '../../index.js';
|
|
|
7
7
|
*
|
|
8
8
|
* @return Block hash | hash[] | null
|
|
9
9
|
*/
|
|
10
|
-
export declare const chain_getBlockHash: Handler<[
|
|
10
|
+
export declare const chain_getBlockHash: Handler<[
|
|
11
|
+
number | HexString | number[] | HexString[] | null
|
|
12
|
+
], HexString | (HexString | null)[] | null>;
|
|
11
13
|
/**
|
|
12
14
|
* @param context
|
|
13
15
|
* @param params - [`blockhash`]
|
|
@@ -39,7 +41,7 @@ export declare const chain_getFinalizedHead: Handler<void, HexString>;
|
|
|
39
41
|
export declare const chain_subscribeNewHead: Handler<void, string>;
|
|
40
42
|
export declare const chain_subscribeFinalizedHeads: Handler<void, string>;
|
|
41
43
|
export declare const chain_unsubscribeNewHead: Handler<[string], void>;
|
|
42
|
-
export declare const chain_getHead: Handler<[number | number[] | null], `0x${string}` | (`0x${string}` | null)[] | null>;
|
|
44
|
+
export declare const chain_getHead: Handler<[number | `0x${string}` | `0x${string}`[] | number[] | null], `0x${string}` | (`0x${string}` | null)[] | null>;
|
|
43
45
|
export declare const chain_subscribeNewHeads: Handler<void, string>;
|
|
44
46
|
export declare const chain_unsubscribeNewHeads: Handler<[string], void>;
|
|
45
47
|
export declare const chain_unsubscribeFinalizedHeads: Handler<[string], void>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { hexToNumber, isHex } from '@polkadot/util';
|
|
1
2
|
import { ResponseError } from '../shared.js';
|
|
2
3
|
const processHeader = ({ parentHash, number, stateRoot, extrinsicsRoot, digest })=>{
|
|
3
4
|
return {
|
|
@@ -19,7 +20,7 @@ const processHeader = ({ parentHash, number, stateRoot, extrinsicsRoot, digest }
|
|
|
19
20
|
const numbers = Array.isArray(blockNumber) ? blockNumber : [
|
|
20
21
|
blockNumber
|
|
21
22
|
];
|
|
22
|
-
const hashes = await Promise.all(numbers.map((n)=>context.chain.getBlockAt(n))).then((blocks)=>blocks.map((b)=>b?.hash || null));
|
|
23
|
+
const hashes = await Promise.all(numbers.map((n)=>isHex(n, undefined, true) ? hexToNumber(n) : n).map((n)=>context.chain.getBlockAt(n))).then((blocks)=>blocks.map((b)=>b?.hash || null));
|
|
23
24
|
return Array.isArray(blockNumber) ? hashes : hashes[0];
|
|
24
25
|
};
|
|
25
26
|
/**
|
|
@@ -39,9 +39,10 @@ declare const handlers: {
|
|
|
39
39
|
state_unsubscribeStorage: import("../shared.js").Handler<[string], void>;
|
|
40
40
|
childstate_getStorage: import("../shared.js").Handler<[`0x${string}`, `0x${string}`, `0x${string}`], string | null>;
|
|
41
41
|
childstate_getKeysPaged: import("../shared.js").Handler<[`0x${string}`, `0x${string}`, number, `0x${string}`, `0x${string}`], `0x${string}`[] | undefined>;
|
|
42
|
+
state_getStorageAt: import("../shared.js").Handler<[`0x${string}`, `0x${string}`], string | null>;
|
|
42
43
|
payment_queryFeeDetails: import("../shared.js").Handler<[`0x${string}`, `0x${string}`], `0x${string}`>;
|
|
43
44
|
payment_queryInfo: import("../shared.js").Handler<[`0x${string}`, `0x${string}`], `0x${string}`>;
|
|
44
|
-
chain_getBlockHash: import("../shared.js").Handler<[number | number[] | null], `0x${string}` | (`0x${string}` | null)[] | null>;
|
|
45
|
+
chain_getBlockHash: import("../shared.js").Handler<[number | `0x${string}` | `0x${string}`[] | number[] | null], `0x${string}` | (`0x${string}` | null)[] | null>;
|
|
45
46
|
chain_getHeader: import("../shared.js").Handler<[`0x${string}`], import("../../index.js").Header>;
|
|
46
47
|
chain_getBlock: import("../shared.js").Handler<[`0x${string}`], {
|
|
47
48
|
block: {
|
|
@@ -54,7 +55,7 @@ declare const handlers: {
|
|
|
54
55
|
chain_subscribeNewHead: import("../shared.js").Handler<void, string>;
|
|
55
56
|
chain_subscribeFinalizedHeads: import("../shared.js").Handler<void, string>;
|
|
56
57
|
chain_unsubscribeNewHead: import("../shared.js").Handler<[string], void>;
|
|
57
|
-
chain_getHead: import("../shared.js").Handler<[number | number[] | null], `0x${string}` | (`0x${string}` | null)[] | null>;
|
|
58
|
+
chain_getHead: import("../shared.js").Handler<[number | `0x${string}` | `0x${string}`[] | number[] | null], `0x${string}` | (`0x${string}` | null)[] | null>;
|
|
58
59
|
chain_subscribeNewHeads: import("../shared.js").Handler<void, string>;
|
|
59
60
|
chain_unsubscribeNewHeads: import("../shared.js").Handler<[string], void>;
|
|
60
61
|
chain_unsubscribeFinalizedHeads: import("../shared.js").Handler<[string], void>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Blockchain } from '../blockchain/index.js';
|
|
2
|
-
export declare const connectHorizontal: (parachains: Record<number, Blockchain
|
|
2
|
+
export declare const connectHorizontal: (parachains: Record<number, Blockchain>, disableAutoHrmp?: boolean) => Promise<void>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { hexToU8a } from '@polkadot/util';
|
|
2
2
|
import { compactHex } from '../utils/index.js';
|
|
3
3
|
import { xcmLogger } from './index.js';
|
|
4
|
-
export const connectHorizontal = async (parachains)=>{
|
|
4
|
+
export const connectHorizontal = async (parachains, disableAutoHrmp = false)=>{
|
|
5
5
|
for (const [id, chain] of Object.entries(parachains)){
|
|
6
6
|
const meta = await chain.head.meta;
|
|
7
7
|
const hrmpOutboundMessagesKey = compactHex(meta.query.parachainSystem.hrmpOutboundMessages());
|
|
@@ -28,7 +28,7 @@ export const connectHorizontal = async (parachains)=>{
|
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
30
|
const hrmpHeads = await chain.head.read('BTreeMap<u32, H256>', meta.query.parachainSystem.lastHrmpMqcHeads);
|
|
31
|
-
if (hrmpHeads && !
|
|
31
|
+
if (hrmpHeads && !disableAutoHrmp) {
|
|
32
32
|
const existingChannels = Array.from(hrmpHeads.keys()).map((x)=>x.toNumber());
|
|
33
33
|
for (const paraId of Object.keys(parachains).filter((x)=>x !== id)){
|
|
34
34
|
if (!existingChannels.includes(Number(paraId))) {
|
package/dist/esm/xcm/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Blockchain } from '../blockchain/index.js';
|
|
2
2
|
export declare const xcmLogger: import("pino").default.Logger<never>;
|
|
3
3
|
export declare const connectVertical: (relaychain: Blockchain, parachain: Blockchain) => Promise<void>;
|
|
4
|
-
export declare const connectParachains: (parachains: Blockchain[]) => Promise<void>;
|
|
4
|
+
export declare const connectParachains: (parachains: Blockchain[], disableAutoHrmp?: boolean) => Promise<void>;
|
package/dist/esm/xcm/index.js
CHANGED
|
@@ -11,12 +11,12 @@ export const connectVertical = async (relaychain, parachain)=>{
|
|
|
11
11
|
await connectUpward(parachain, relaychain);
|
|
12
12
|
xcmLogger.info(`Connected relaychain '${await relaychain.api.getSystemChain()}' with parachain '${await parachain.api.getSystemChain()}'`);
|
|
13
13
|
};
|
|
14
|
-
export const connectParachains = async (parachains)=>{
|
|
14
|
+
export const connectParachains = async (parachains, disableAutoHrmp = false)=>{
|
|
15
15
|
const list = {};
|
|
16
16
|
for (const chain of parachains){
|
|
17
17
|
const paraId = await getParaId(chain);
|
|
18
18
|
list[paraId.toNumber()] = chain;
|
|
19
19
|
}
|
|
20
|
-
await connectHorizontal(list);
|
|
20
|
+
await connectHorizontal(list, disableAutoHrmp);
|
|
21
21
|
xcmLogger.info(`Connected parachains [${Object.keys(list)}]`);
|
|
22
22
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acala-network/chopsticks-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0-2",
|
|
4
4
|
"author": "Acala Developers <hello@acala.network>",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"docs:prep": "typedoc"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@acala-network/chopsticks-executor": "0.
|
|
15
|
+
"@acala-network/chopsticks-executor": "0.10.0-2",
|
|
16
16
|
"@polkadot/rpc-provider": "^10.11.2",
|
|
17
17
|
"@polkadot/types": "^10.11.2",
|
|
18
18
|
"@polkadot/types-codec": "^10.11.2",
|