@acala-network/chopsticks 0.3.2 → 0.3.4
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/blockchain/head-state.js +11 -3
- package/dist/blockchain/index.d.ts +1 -0
- package/dist/blockchain/index.js +3 -0
- package/dist/blockchain/txpool.d.ts +2 -0
- package/dist/blockchain/txpool.js +15 -0
- package/dist/executor.d.ts +2 -1
- package/dist/executor.js +5 -4
- package/dist/rpc/index.js +4 -0
- package/dist/rpc/substrate/chain.js +5 -1
- package/dist/rpc/substrate/index.js +0 -4
- package/dist/rpc/substrate/system.js +15 -1
- package/dist/schema/index.d.ts +6 -6
- package/dist/template/diff.html +243 -0
- package/dist/utils/generate-html-diff.js +5 -1
- package/dist/xcm/downward.js +2 -0
- package/dist/xcm/upward.js +7 -7
- package/package.json +26 -27
|
@@ -46,15 +46,23 @@ class HeadState {
|
|
|
46
46
|
async setHead(head) {
|
|
47
47
|
this.#head = head;
|
|
48
48
|
for (const cb of Object.values(this.#headListeners)) {
|
|
49
|
-
|
|
49
|
+
try {
|
|
50
|
+
cb(head);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
logger.error(error, 'callback');
|
|
54
|
+
}
|
|
50
55
|
}
|
|
51
56
|
const diff = await this.#head.storageDiff();
|
|
52
57
|
for (const [keys, cb] of Object.values(this.#storageListeners)) {
|
|
53
58
|
const changed = keys.filter((key) => diff[key]).map((key) => [key, diff[key]]);
|
|
54
59
|
if (changed.length > 0) {
|
|
55
|
-
|
|
60
|
+
try {
|
|
61
|
+
cb(head, changed);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
56
64
|
logger.error(error, 'callback');
|
|
57
|
-
}
|
|
65
|
+
}
|
|
58
66
|
}
|
|
59
67
|
}
|
|
60
68
|
Object.assign(this.#oldValues, diff);
|
|
@@ -35,6 +35,7 @@ export declare class Blockchain {
|
|
|
35
35
|
setHead(block: Block): Promise<void>;
|
|
36
36
|
submitExtrinsic(extrinsic: HexString): Promise<HexString>;
|
|
37
37
|
newBlock(params?: BuildBlockParams): Promise<Block>;
|
|
38
|
+
upcomingBlock(count?: number): Promise<Block>;
|
|
38
39
|
dryRunExtrinsic(extrinsic: HexString | {
|
|
39
40
|
call: HexString;
|
|
40
41
|
address: string;
|
package/dist/blockchain/index.js
CHANGED
|
@@ -119,6 +119,9 @@ class Blockchain {
|
|
|
119
119
|
await this.#txpool.buildBlock(params);
|
|
120
120
|
return this.#head;
|
|
121
121
|
}
|
|
122
|
+
async upcomingBlock(count = 1) {
|
|
123
|
+
return this.#txpool.upcomingBlock(count);
|
|
124
|
+
}
|
|
122
125
|
async dryRunExtrinsic(extrinsic, at) {
|
|
123
126
|
await this.api.isReady;
|
|
124
127
|
const head = at ? await this.getBlock(at) : this.head;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { HexString } from '@polkadot/util/types';
|
|
2
|
+
import { Block } from './block';
|
|
2
3
|
import { Blockchain } from '.';
|
|
3
4
|
import { InherentProvider } from './inherent';
|
|
4
5
|
export declare enum BuildBlockMode {
|
|
@@ -26,4 +27,5 @@ export declare class TxPool {
|
|
|
26
27
|
get pendingExtrinsics(): HexString[];
|
|
27
28
|
submitExtrinsic(extrinsic: HexString): void;
|
|
28
29
|
buildBlock(params?: BuildBlockParams): Promise<void>;
|
|
30
|
+
upcomingBlock(count?: number): Promise<Block>;
|
|
29
31
|
}
|
|
@@ -4,6 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.TxPool = exports.BuildBlockMode = void 0;
|
|
7
|
+
const rxjs_1 = require("rxjs");
|
|
8
|
+
const operators_1 = require("rxjs/operators");
|
|
7
9
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
10
|
const block_builder_1 = require("./block-builder");
|
|
9
11
|
var BuildBlockMode;
|
|
@@ -18,6 +20,8 @@ class TxPool {
|
|
|
18
20
|
#mode;
|
|
19
21
|
#inherentProvider;
|
|
20
22
|
#lastBuildBlockPromise = Promise.resolve();
|
|
23
|
+
#last = new rxjs_1.ReplaySubject(1);
|
|
24
|
+
#upcoming = this.#last.pipe((0, rxjs_1.share)());
|
|
21
25
|
constructor(chain, inherentProvider, mode = BuildBlockMode.Batch) {
|
|
22
26
|
this.#chain = chain;
|
|
23
27
|
this.#mode = mode;
|
|
@@ -45,6 +49,17 @@ class TxPool {
|
|
|
45
49
|
const last = this.#lastBuildBlockPromise;
|
|
46
50
|
this.#lastBuildBlockPromise = this.#buildBlock(last, params);
|
|
47
51
|
await this.#lastBuildBlockPromise;
|
|
52
|
+
this.#last.next(this.#chain.head);
|
|
53
|
+
}
|
|
54
|
+
async upcomingBlock(count = 1) {
|
|
55
|
+
if (count < 1)
|
|
56
|
+
throw new Error('count needs to be greater than 0');
|
|
57
|
+
return new Promise((resolve) => {
|
|
58
|
+
const sub = this.#upcoming.pipe((0, operators_1.skip)(count - 1)).subscribe((block) => {
|
|
59
|
+
sub.unsubscribe();
|
|
60
|
+
resolve(block);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
48
63
|
}
|
|
49
64
|
async #buildBlock(wait, params) {
|
|
50
65
|
await this.#chain.api.isReady;
|
package/dist/executor.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { HexString } from '@polkadot/util/types';
|
|
2
2
|
import { Block } from './blockchain/block';
|
|
3
3
|
import { Registry } from '@polkadot/types-codec/types';
|
|
4
|
+
import _ from 'lodash';
|
|
4
5
|
interface JsCallback {
|
|
5
6
|
getStorage: (key: HexString) => Promise<string | undefined>;
|
|
6
7
|
getPrefixKeys: (key: HexString) => Promise<string[]>;
|
|
@@ -36,5 +37,5 @@ export declare const emptyTaskHandler: {
|
|
|
36
37
|
getPrefixKeys: (_key: HexString) => Promise<never>;
|
|
37
38
|
getNextKey: (_key: HexString) => Promise<never>;
|
|
38
39
|
};
|
|
39
|
-
export declare const getAuraSlotDuration: ((wasm: HexString, registry: Registry) => Promise<number>) &
|
|
40
|
+
export declare const getAuraSlotDuration: ((wasm: HexString, registry: Registry) => Promise<number>) & _.MemoizedFunction;
|
|
40
41
|
export {};
|
package/dist/executor.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.getAuraSlotDuration = exports.emptyTaskHandler = exports.taskHandler = exports.runTask = exports.createProof = exports.decodeProof = exports.calculateStateRoot = exports.getRuntimeVersion = void 0;
|
|
4
|
-
const ws_1 = require("ws");
|
|
5
7
|
const util_1 = require("@polkadot/util");
|
|
6
|
-
global.WebSocket = ws_1.WebSocket;
|
|
7
8
|
const chopsticks_executor_1 = require("@acala-network/chopsticks-executor");
|
|
8
9
|
const logger_1 = require("./logger");
|
|
9
|
-
const lodash_1 = require("lodash");
|
|
10
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
10
11
|
const logger = logger_1.defaultLogger.child({ name: 'executor' });
|
|
11
12
|
const getRuntimeVersion = async (code) => {
|
|
12
13
|
return (0, chopsticks_executor_1.get_runtime_version)(code).then((version) => {
|
|
@@ -75,7 +76,7 @@ exports.emptyTaskHandler = {
|
|
|
75
76
|
throw new Error('Method not implemented');
|
|
76
77
|
},
|
|
77
78
|
};
|
|
78
|
-
exports.getAuraSlotDuration =
|
|
79
|
+
exports.getAuraSlotDuration = lodash_1.default.memoize(async (wasm, registry) => {
|
|
79
80
|
const result = await (0, exports.runTask)({
|
|
80
81
|
wasm,
|
|
81
82
|
calls: [['AuraApi_slot_duration', '0x']],
|
package/dist/rpc/index.js
CHANGED
|
@@ -10,6 +10,10 @@ const substrate_1 = __importDefault(require("./substrate"));
|
|
|
10
10
|
const allHandlers = {
|
|
11
11
|
...substrate_1.default,
|
|
12
12
|
...dev_1.default,
|
|
13
|
+
rpc_methods: async () => Promise.resolve({
|
|
14
|
+
version: 1,
|
|
15
|
+
methods: Object.keys(allHandlers),
|
|
16
|
+
}),
|
|
13
17
|
};
|
|
14
18
|
const handler = (context) => ({ method, params }, subscriptionManager) => {
|
|
15
19
|
shared_1.logger.trace('Handling %s', method);
|
|
@@ -10,7 +10,11 @@ const handlers = {
|
|
|
10
10
|
return block.hash;
|
|
11
11
|
},
|
|
12
12
|
chain_getHeader: async (context, [hash]) => {
|
|
13
|
-
|
|
13
|
+
const block = await context.chain.getBlock(hash);
|
|
14
|
+
if (!block) {
|
|
15
|
+
throw new shared_1.ResponseError(1, `Block ${hash} not found`);
|
|
16
|
+
}
|
|
17
|
+
return await block.header;
|
|
14
18
|
},
|
|
15
19
|
chain_getBlock: async (context, [hash]) => {
|
|
16
20
|
const block = await context.chain.getBlock(hash);
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const util_1 = require("@polkadot/util");
|
|
7
|
+
const node_fs_1 = require("node:fs");
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
3
9
|
const handlers = {
|
|
4
10
|
system_chain: async (context) => {
|
|
5
11
|
return context.chain.api.getSystemChain();
|
|
@@ -11,7 +17,8 @@ const handlers = {
|
|
|
11
17
|
return context.chain.api.getSystemName();
|
|
12
18
|
},
|
|
13
19
|
system_version: async (_context) => {
|
|
14
|
-
|
|
20
|
+
const { version } = JSON.parse((0, node_fs_1.readFileSync)(node_path_1.default.join(__dirname, '../../../package.json'), 'utf-8'));
|
|
21
|
+
return `chopsticks-v${version}`;
|
|
15
22
|
},
|
|
16
23
|
system_chainType: async (_context) => {
|
|
17
24
|
return 'Development';
|
|
@@ -27,5 +34,12 @@ const handlers = {
|
|
|
27
34
|
const { outcome } = await context.chain.dryRunExtrinsic(extrinsic, at);
|
|
28
35
|
return outcome.toHex();
|
|
29
36
|
},
|
|
37
|
+
system_accountNextIndex: async (context, [address]) => {
|
|
38
|
+
const head = context.chain.head;
|
|
39
|
+
const registry = await head.registry;
|
|
40
|
+
const account = registry.createType('AccountId', address);
|
|
41
|
+
const result = await head.call('AccountNonceApi_account_nonce', account.toHex());
|
|
42
|
+
return registry.createType('Index', (0, util_1.hexToU8a)(result.result)).toNumber();
|
|
43
|
+
},
|
|
30
44
|
};
|
|
31
45
|
exports.default = handlers;
|
package/dist/schema/index.d.ts
CHANGED
|
@@ -35,12 +35,12 @@ export declare const genesisSchema: z.ZodObject<{
|
|
|
35
35
|
}>;
|
|
36
36
|
}, "strip", z.ZodTypeAny, {
|
|
37
37
|
name: string;
|
|
38
|
+
id: string;
|
|
38
39
|
properties: {
|
|
39
40
|
ss58Format?: number | undefined;
|
|
40
41
|
tokenDecimals?: number | number[] | undefined;
|
|
41
42
|
tokenSymbol?: string | string[] | undefined;
|
|
42
43
|
};
|
|
43
|
-
id: string;
|
|
44
44
|
genesis: {
|
|
45
45
|
raw: {
|
|
46
46
|
top: Record<string, string>;
|
|
@@ -48,12 +48,12 @@ export declare const genesisSchema: z.ZodObject<{
|
|
|
48
48
|
};
|
|
49
49
|
}, {
|
|
50
50
|
name: string;
|
|
51
|
+
id: string;
|
|
51
52
|
properties: {
|
|
52
53
|
ss58Format?: number | undefined;
|
|
53
54
|
tokenDecimals?: number | number[] | undefined;
|
|
54
55
|
tokenSymbol?: string | string[] | undefined;
|
|
55
56
|
};
|
|
56
|
-
id: string;
|
|
57
57
|
genesis: {
|
|
58
58
|
raw: {
|
|
59
59
|
top: Record<string, string>;
|
|
@@ -105,12 +105,12 @@ export declare const configSchema: z.ZodObject<{
|
|
|
105
105
|
}>;
|
|
106
106
|
}, "strip", z.ZodTypeAny, {
|
|
107
107
|
name: string;
|
|
108
|
+
id: string;
|
|
108
109
|
properties: {
|
|
109
110
|
ss58Format?: number | undefined;
|
|
110
111
|
tokenDecimals?: number | number[] | undefined;
|
|
111
112
|
tokenSymbol?: string | string[] | undefined;
|
|
112
113
|
};
|
|
113
|
-
id: string;
|
|
114
114
|
genesis: {
|
|
115
115
|
raw: {
|
|
116
116
|
top: Record<string, string>;
|
|
@@ -118,12 +118,12 @@ export declare const configSchema: z.ZodObject<{
|
|
|
118
118
|
};
|
|
119
119
|
}, {
|
|
120
120
|
name: string;
|
|
121
|
+
id: string;
|
|
121
122
|
properties: {
|
|
122
123
|
ss58Format?: number | undefined;
|
|
123
124
|
tokenDecimals?: number | number[] | undefined;
|
|
124
125
|
tokenSymbol?: string | string[] | undefined;
|
|
125
126
|
};
|
|
126
|
-
id: string;
|
|
127
127
|
genesis: {
|
|
128
128
|
raw: {
|
|
129
129
|
top: Record<string, string>;
|
|
@@ -136,12 +136,12 @@ export declare const configSchema: z.ZodObject<{
|
|
|
136
136
|
db?: string | undefined;
|
|
137
137
|
genesis?: string | {
|
|
138
138
|
name: string;
|
|
139
|
+
id: string;
|
|
139
140
|
properties: {
|
|
140
141
|
ss58Format?: number | undefined;
|
|
141
142
|
tokenDecimals?: number | number[] | undefined;
|
|
142
143
|
tokenSymbol?: string | string[] | undefined;
|
|
143
144
|
};
|
|
144
|
-
id: string;
|
|
145
145
|
genesis: {
|
|
146
146
|
raw: {
|
|
147
147
|
top: Record<string, string>;
|
|
@@ -160,12 +160,12 @@ export declare const configSchema: z.ZodObject<{
|
|
|
160
160
|
db?: string | undefined;
|
|
161
161
|
genesis?: string | {
|
|
162
162
|
name: string;
|
|
163
|
+
id: string;
|
|
163
164
|
properties: {
|
|
164
165
|
ss58Format?: number | undefined;
|
|
165
166
|
tokenDecimals?: number | number[] | undefined;
|
|
166
167
|
tokenSymbol?: string | string[] | undefined;
|
|
167
168
|
};
|
|
168
|
-
id: string;
|
|
169
169
|
genesis: {
|
|
170
170
|
raw: {
|
|
171
171
|
top: Record<string, string>;
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<style>
|
|
5
|
+
body {
|
|
6
|
+
font-family: ui-monospace, 'SFMono-Regular', 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
|
|
7
|
+
font-size: 14px;
|
|
8
|
+
min-width: 600px;
|
|
9
|
+
margin: 0;
|
|
10
|
+
padding: 0;
|
|
11
|
+
background-color: rgb(39, 40, 34);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
div#app {
|
|
15
|
+
margin: 0 !important;
|
|
16
|
+
padding: 10px !important;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.diff {
|
|
20
|
+
padding: 2px 4px;
|
|
21
|
+
border-radius: 4px;
|
|
22
|
+
position: relative;
|
|
23
|
+
color: white;
|
|
24
|
+
line-height: 150%;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.diffWrap {
|
|
28
|
+
position: relative;
|
|
29
|
+
z-index: 1;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
li:has(> span > span.diffWrap > span.diffRemove) > label {
|
|
33
|
+
color: red !important;
|
|
34
|
+
text-decoration: line-through;
|
|
35
|
+
text-decoration-thickness: 1px;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.diffAdd {
|
|
39
|
+
color: darkseagreen;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.diffRemove {
|
|
43
|
+
text-decoration: line-through;
|
|
44
|
+
text-decoration-thickness: 1px;
|
|
45
|
+
color: red;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.diffUpdateFrom {
|
|
49
|
+
text-decoration: line-through;
|
|
50
|
+
text-decoration-thickness: 1px;
|
|
51
|
+
color: red;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.diffUpdateTo {
|
|
55
|
+
color: darkseagreen;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.diffUpdateArrow {
|
|
59
|
+
color: #ccc;
|
|
60
|
+
}
|
|
61
|
+
.unchanged {
|
|
62
|
+
color: #666;
|
|
63
|
+
}
|
|
64
|
+
.delta {
|
|
65
|
+
color: #ccc;
|
|
66
|
+
font-size: 12px;
|
|
67
|
+
margin: 0 10px;
|
|
68
|
+
}
|
|
69
|
+
</style>
|
|
70
|
+
<script src="https://unpkg.com/babel-standalone@6/babel.min.js" crossorigin></script>
|
|
71
|
+
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js" crossorigin></script>
|
|
72
|
+
<script src="https://unpkg.com/react@18/umd/react.production.min.js" crossorigin></script>
|
|
73
|
+
<script src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js" crossorigin></script>
|
|
74
|
+
<script src="https://unpkg.com/react-json-tree@0.18.0/lib/umd/react-json-tree.min.js" crossorigin></script>
|
|
75
|
+
</head>
|
|
76
|
+
|
|
77
|
+
<body>
|
|
78
|
+
<div id="app"></div>
|
|
79
|
+
<script type="text/babel">
|
|
80
|
+
|
|
81
|
+
const left = <%= left %>;
|
|
82
|
+
const delta = <%= delta %>;
|
|
83
|
+
|
|
84
|
+
const expandFirstLevel = (keyName, data, level) => level <= 1;
|
|
85
|
+
|
|
86
|
+
function stringifyAndShrink(val) {
|
|
87
|
+
if (val == null) return 'null';
|
|
88
|
+
if (typeof val === 'string') return val
|
|
89
|
+
return JSON.stringify(val, null, 1);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const styling = (a) => {
|
|
93
|
+
const className = Array.isArray(a) ? a : [a]
|
|
94
|
+
return { className: className.join(' ') }
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function valueRenderer(raw, value, ...keys) {
|
|
98
|
+
const modifyPath = keys.reverse().join('.')
|
|
99
|
+
const removePath = keys.map(x => Number.isInteger(parseInt(x)) ? '_' + x : x).join('.')
|
|
100
|
+
const isDelta = _.has(delta, modifyPath) || _.has(delta, removePath)
|
|
101
|
+
|
|
102
|
+
function renderSpan(name, body) {
|
|
103
|
+
return (
|
|
104
|
+
<span key={name} {...styling(['diff', name])}>
|
|
105
|
+
{body}
|
|
106
|
+
</span>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function renderDelta(value) {
|
|
111
|
+
if (/^\d+(,\d+)*$/.test(value[0]) && /^\d+(,\d+)*$/.test(value[1])) {
|
|
112
|
+
const oldValue = parseInt(value[0].replace(/,/g, ''))
|
|
113
|
+
const newValue = parseInt(value[1].replace(/,/g, ''))
|
|
114
|
+
if (oldValue > 0 && newValue > 0) {
|
|
115
|
+
const delta = Number(newValue - oldValue)
|
|
116
|
+
return (<span className="delta" >{delta > 0 ? '+' : ''}{delta.toLocaleString()}</span>)
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (isDelta && Array.isArray(value)) {
|
|
122
|
+
switch (value.length) {
|
|
123
|
+
case 0:
|
|
124
|
+
return (
|
|
125
|
+
<span {...styling('diffWrap')}>
|
|
126
|
+
{renderSpan('diff', '[]')}
|
|
127
|
+
</span>
|
|
128
|
+
)
|
|
129
|
+
case 1:
|
|
130
|
+
return (
|
|
131
|
+
<span {...styling('diffWrap')}>
|
|
132
|
+
{renderSpan(
|
|
133
|
+
'diffAdd',
|
|
134
|
+
stringifyAndShrink(value[0])
|
|
135
|
+
)}
|
|
136
|
+
</span>
|
|
137
|
+
);
|
|
138
|
+
case 2:
|
|
139
|
+
return (
|
|
140
|
+
<span {...styling('diffWrap')}>
|
|
141
|
+
{renderSpan(
|
|
142
|
+
'diffUpdateFrom',
|
|
143
|
+
stringifyAndShrink(value[0])
|
|
144
|
+
)}
|
|
145
|
+
{renderSpan('diffUpdateArrow', ' => ')}
|
|
146
|
+
{renderSpan(
|
|
147
|
+
'diffUpdateTo',
|
|
148
|
+
stringifyAndShrink(value[1])
|
|
149
|
+
)}
|
|
150
|
+
{renderDelta(value)}
|
|
151
|
+
</span>
|
|
152
|
+
);
|
|
153
|
+
case 3:
|
|
154
|
+
return (
|
|
155
|
+
<span {...styling('diffWrap')}>
|
|
156
|
+
{renderSpan('diffRemove', stringifyAndShrink(value[0]))}
|
|
157
|
+
</span>
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return (
|
|
163
|
+
<span {...styling('diffWrap')}>
|
|
164
|
+
{renderSpan('unchanged', stringifyAndShrink(value))}
|
|
165
|
+
</span>
|
|
166
|
+
);
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
function prepareDelta(value) {
|
|
170
|
+
if (value && value._t === 'a') {
|
|
171
|
+
const res = {};
|
|
172
|
+
for (const key in value) {
|
|
173
|
+
if (key !== '_t') {
|
|
174
|
+
if (key[0] === '_' && !value[key.substr(1)]) {
|
|
175
|
+
res[key.substr(1)] = value[key];
|
|
176
|
+
} else if (value['_' + key]) {
|
|
177
|
+
res[key] = [value['_' + key][0], value[key][0]];
|
|
178
|
+
} else if (!value['_' + key] && key[0] !== '_') {
|
|
179
|
+
res[key] = value[key];
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return res;
|
|
184
|
+
}
|
|
185
|
+
return value;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const theme = {
|
|
189
|
+
scheme: 'monokai',
|
|
190
|
+
base00: '#272822',
|
|
191
|
+
base01: '#383830',
|
|
192
|
+
base02: '#49483e',
|
|
193
|
+
base03: '#75715e',
|
|
194
|
+
base04: '#a59f85',
|
|
195
|
+
base05: '#f8f8f2',
|
|
196
|
+
base06: '#f5f4f1',
|
|
197
|
+
base07: '#f9f8f5',
|
|
198
|
+
base08: '#f92672',
|
|
199
|
+
base09: '#fd971f',
|
|
200
|
+
base0A: '#f4bf75',
|
|
201
|
+
base0B: '#a6e22e',
|
|
202
|
+
base0C: '#a1efe4',
|
|
203
|
+
base0D: '#66d9ef',
|
|
204
|
+
base0E: '#ae81ff',
|
|
205
|
+
base0F: '#cc6633',
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
class App extends React.Component {
|
|
209
|
+
constructor(props) {
|
|
210
|
+
super(props);
|
|
211
|
+
this.state = { showUnchanged: false };
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
toggle = (e) => {
|
|
215
|
+
this.setState(state => {
|
|
216
|
+
return { showUnchanged: !state.showUnchanged }
|
|
217
|
+
})
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
render() {
|
|
221
|
+
return (
|
|
222
|
+
<div>
|
|
223
|
+
<input type="checkbox" onChange={this.toggle} id="show_unchanged" />
|
|
224
|
+
<label for="show_unchanged" style={{fontSize: '12px', color: 'white'}}>Show Unchanged</label>
|
|
225
|
+
<ReactJsonTree.JSONTree
|
|
226
|
+
theme={theme}
|
|
227
|
+
invertTheme={false}
|
|
228
|
+
data={this.state.showUnchanged ? _.merge(_.cloneDeep(left), delta): delta}
|
|
229
|
+
valueRenderer={valueRenderer}
|
|
230
|
+
postprocessValue={prepareDelta}
|
|
231
|
+
isCustomNode={Array.isArray}
|
|
232
|
+
shouldExpandNodeInitially={expandFirstLevel}
|
|
233
|
+
hideRoot
|
|
234
|
+
/>
|
|
235
|
+
</div>
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
ReactDOM.createRoot(document.querySelector('#app')).render(<App />);
|
|
241
|
+
</script>
|
|
242
|
+
</body>
|
|
243
|
+
</html>
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.generateHtmlDiffPreviewFile = exports.generateHtmlDiff = void 0;
|
|
4
7
|
const decoder_1 = require("./decoder");
|
|
5
8
|
const node_fs_1 = require("node:fs");
|
|
6
9
|
const lodash_1 = require("lodash");
|
|
10
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
7
11
|
const generateHtmlDiff = async (block, diff) => {
|
|
8
12
|
const [left, _right, delta] = await (0, decoder_1.decodeStorageDiff)(block, diff);
|
|
9
|
-
const htmlTemplate = (0, node_fs_1.readFileSync)('
|
|
13
|
+
const htmlTemplate = (0, node_fs_1.readFileSync)(node_path_1.default.join(__dirname, '../../template/diff.html'), 'utf-8');
|
|
10
14
|
return (0, lodash_1.template)(htmlTemplate)({ left: JSON.stringify(left), delta: JSON.stringify(delta) });
|
|
11
15
|
};
|
|
12
16
|
exports.generateHtmlDiff = generateHtmlDiff;
|
package/dist/xcm/downward.js
CHANGED
|
@@ -20,6 +20,8 @@ const connectDownward = async (relaychain, parachain) => {
|
|
|
20
20
|
const downwardMessages = meta.registry
|
|
21
21
|
.createType('Vec<PolkadotCorePrimitivesInboundDownwardMessage>', (0, util_1.hexToU8a)(value))
|
|
22
22
|
.toJSON();
|
|
23
|
+
if (downwardMessages.length === 0)
|
|
24
|
+
return;
|
|
23
25
|
_1.logger.debug({ downwardMessages }, 'downward_message');
|
|
24
26
|
await parachain.newBlock({ inherent: { downwardMessages } });
|
|
25
27
|
});
|
package/dist/xcm/upward.js
CHANGED
|
@@ -19,6 +19,8 @@ const connectUpward = async (parachain, relaychain) => {
|
|
|
19
19
|
await (0, set_storage_1.setStorage)(parachain, [[upwardMessagesKey, null]], head.hash);
|
|
20
20
|
const relaychainMeta = await relaychain.head.meta;
|
|
21
21
|
const upwardMessages = parachainMeta.registry.createType('Vec<Bytes>', (0, util_1.hexToU8a)(value));
|
|
22
|
+
if (upwardMessages.length === 0)
|
|
23
|
+
return;
|
|
22
24
|
const queueSize = parachainMeta.registry.createType('(u32, u32)', [
|
|
23
25
|
upwardMessages.length,
|
|
24
26
|
upwardMessages.map((x) => x.byteLength).reduce((s, i) => s + i, 0),
|
|
@@ -26,13 +28,11 @@ const connectUpward = async (parachain, relaychain) => {
|
|
|
26
28
|
const needsDispatch = parachainMeta.registry.createType('Vec<u32>', [paraId]);
|
|
27
29
|
_1.logger.debug({ [paraId.toNumber()]: upwardMessages.toJSON(), queueSize: queueSize.toJSON() }, 'upward_message');
|
|
28
30
|
// TODO: make sure we append instead of replace
|
|
29
|
-
relaychain.head.pushStorageLayer().
|
|
30
|
-
|
|
31
|
-
.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
.pushStorageLayer()
|
|
35
|
-
.set((0, utils_1.compactHex)(relaychainMeta.query.ump.relayDispatchQueueSize(paraId)), queueSize.toHex());
|
|
31
|
+
relaychain.head.pushStorageLayer().setAll([
|
|
32
|
+
[(0, utils_1.compactHex)(relaychainMeta.query.ump.needsDispatch()), needsDispatch.toHex()],
|
|
33
|
+
[(0, utils_1.compactHex)(relaychainMeta.query.ump.relayDispatchQueues(paraId)), upwardMessages.toHex()],
|
|
34
|
+
[(0, utils_1.compactHex)(relaychainMeta.query.ump.relayDispatchQueueSize(paraId)), queueSize.toHex()],
|
|
35
|
+
]);
|
|
36
36
|
await relaychain.newBlock();
|
|
37
37
|
});
|
|
38
38
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acala-network/chopsticks",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"author": "Bryan Chen <xlchen1291@gmail.com>",
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"fix": "eslint . --ext .js,.ts --fix && prettier -w .",
|
|
17
17
|
"prepare": "husky install",
|
|
18
18
|
"start": "ts-node --transpile-only src/index.ts",
|
|
19
|
-
"build": "
|
|
19
|
+
"build": "rm -rf dist && tsc -p tsconfig.prod.json && yarn postbuild",
|
|
20
|
+
"postbuild": "cp -r template ./dist",
|
|
20
21
|
"build-wasm": "wasm-pack build executor --target nodejs --scope acala-network",
|
|
21
22
|
"build-wasm-logging": "yarn build-wasm --features=logging",
|
|
22
23
|
"check": "cd executor && cargo check --locked",
|
|
@@ -30,47 +31,45 @@
|
|
|
30
31
|
},
|
|
31
32
|
"dependencies": {
|
|
32
33
|
"@acala-network/chopsticks-executor": "0.3.0",
|
|
33
|
-
"@polkadot/api": "^9.
|
|
34
|
-
"@polkadot/rpc-provider": "^9.
|
|
35
|
-
"@polkadot/types": "^9.
|
|
36
|
-
"@polkadot/types-codec": "^9.
|
|
37
|
-
"@polkadot/types-known": "^9.
|
|
38
|
-
"@polkadot/util": "^10.2.
|
|
39
|
-
"@polkadot/util-crypto": "^10.2.
|
|
40
|
-
"axios": "^1.2.
|
|
34
|
+
"@polkadot/api": "^9.11.3",
|
|
35
|
+
"@polkadot/rpc-provider": "^9.11.3",
|
|
36
|
+
"@polkadot/types": "^9.11.3",
|
|
37
|
+
"@polkadot/types-codec": "^9.11.3",
|
|
38
|
+
"@polkadot/types-known": "^9.11.3",
|
|
39
|
+
"@polkadot/util": "^10.2.6",
|
|
40
|
+
"@polkadot/util-crypto": "^10.2.6",
|
|
41
|
+
"axios": "^1.2.3",
|
|
41
42
|
"js-yaml": "^4.1.0",
|
|
42
43
|
"jsondiffpatch": "^0.4.1",
|
|
43
44
|
"lodash": "^4.17.21",
|
|
44
|
-
"pino": "^8.
|
|
45
|
+
"pino": "^8.8.0",
|
|
45
46
|
"pino-pretty": "^9.1.1",
|
|
46
47
|
"reflect-metadata": "^0.1.13",
|
|
47
|
-
"sqlite3": "^5.1.
|
|
48
|
+
"sqlite3": "^5.1.4",
|
|
48
49
|
"typeorm": "^0.3.11",
|
|
49
|
-
"typescript": "^4.9.
|
|
50
|
-
"ws": "^8.
|
|
50
|
+
"typescript": "^4.9.4",
|
|
51
|
+
"ws": "^8.12.0",
|
|
51
52
|
"yargs": "^17.6.2",
|
|
52
|
-
"zod": "^3.
|
|
53
|
+
"zod": "^3.20.2"
|
|
53
54
|
},
|
|
54
55
|
"devDependencies": {
|
|
55
56
|
"@types/js-yaml": "^4.0.5",
|
|
56
57
|
"@types/lodash": "^4.14.191",
|
|
57
58
|
"@types/node": "^18.11.18",
|
|
58
|
-
"@types/
|
|
59
|
-
"@types/
|
|
60
|
-
"@
|
|
61
|
-
"@typescript-eslint/
|
|
62
|
-
"
|
|
63
|
-
"eslint": "^8.
|
|
64
|
-
"eslint-
|
|
65
|
-
"eslint-plugin-import": "^2.26.0",
|
|
59
|
+
"@types/ws": "^8.5.4",
|
|
60
|
+
"@types/yargs": "^17.0.19",
|
|
61
|
+
"@typescript-eslint/eslint-plugin": "^5.48.2",
|
|
62
|
+
"@typescript-eslint/parser": "^5.48.2",
|
|
63
|
+
"eslint": "^8.32.0",
|
|
64
|
+
"eslint-config-prettier": "^8.6.0",
|
|
65
|
+
"eslint-plugin-import": "^2.27.5",
|
|
66
66
|
"eslint-plugin-sort-imports-es6-autofix": "^0.6.0",
|
|
67
|
-
"husky": "^8.0.
|
|
67
|
+
"husky": "^8.0.3",
|
|
68
68
|
"lint-staged": "^13.1.0",
|
|
69
|
-
"prettier": "^2.8.
|
|
70
|
-
"rimraf": "^3.0.2",
|
|
69
|
+
"prettier": "^2.8.3",
|
|
71
70
|
"ts-node": "^10.9.1",
|
|
72
71
|
"ts-node-dev": "^2.0.0",
|
|
73
|
-
"vitest": "^0.
|
|
72
|
+
"vitest": "^0.27.2",
|
|
74
73
|
"wasm-pack": "^0.10.3"
|
|
75
74
|
},
|
|
76
75
|
"files": [
|