@acala-network/chopsticks-core 0.8.2 → 0.8.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/lib/blockchain/block-builder.d.ts +5 -1
- package/lib/blockchain/block-builder.js +21 -20
- package/lib/blockchain/block.d.ts +1 -1
- package/lib/blockchain/block.js +4 -4
- package/lib/blockchain/index.d.ts +2 -2
- package/lib/blockchain/index.js +4 -2
- package/lib/blockchain/inherent/parachain/validation-data.js +5 -5
- package/lib/blockchain/storage-layer.js +25 -2
- package/lib/blockchain/txpool.js +18 -2
- package/lib/chopsticks-provider.d.ts +0 -0
- package/lib/chopsticks-provider.js +249 -0
- package/lib/chopsticks-worker.d.ts +1 -0
- package/lib/chopsticks-worker.js +101 -0
- package/lib/genesis-provider.d.ts +1 -1
- package/lib/genesis-provider.js +3 -3
- package/lib/index.d.ts +2 -1
- package/lib/index.js +3 -1
- package/lib/rpc/index.d.ts +5 -0
- package/lib/rpc/index.js +26 -0
- package/lib/rpc/shared.d.ts +27 -0
- package/lib/rpc/shared.js +19 -0
- package/lib/rpc/substrate/author.d.ts +28 -0
- package/lib/rpc/substrate/author.js +98 -0
- package/lib/rpc/substrate/chain.d.ts +45 -0
- package/lib/rpc/substrate/chain.js +103 -0
- package/lib/rpc/substrate/index.d.ts +66 -0
- package/lib/rpc/substrate/index.js +38 -0
- package/lib/rpc/substrate/payment.d.ts +16 -0
- package/lib/rpc/substrate/payment.js +54 -0
- package/lib/rpc/substrate/state.d.ts +97 -0
- package/lib/rpc/substrate/state.js +184 -0
- package/lib/rpc/substrate/system.d.ts +28 -0
- package/lib/rpc/substrate/system.js +71 -0
- package/lib/utils/time-travel.js +2 -2
- package/lib/wasm-executor/browser-wasm-executor.mjs +37 -0
- package/lib/wasm-executor/browser-worker.d.ts +5 -0
- package/lib/wasm-executor/browser-worker.js +28 -0
- package/lib/{executor.d.ts → wasm-executor/index.d.ts} +18 -1
- package/lib/{executor.js → wasm-executor/index.js} +60 -15
- package/lib/wasm-executor/node-wasm-executor.mjs +34 -0
- package/lib/wasm-executor/node-worker.d.ts +5 -0
- package/lib/wasm-executor/node-worker.js +31 -0
- package/package.json +6 -4
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.payment_queryInfo = exports.payment_queryFeeDetails = void 0;
|
|
13
|
+
const util_1 = require("@polkadot/util");
|
|
14
|
+
const shared_1 = require("../shared");
|
|
15
|
+
/**
|
|
16
|
+
* @param context
|
|
17
|
+
* @param params - [`extrinsic`, `blockhash`]
|
|
18
|
+
*
|
|
19
|
+
* @return result in hash
|
|
20
|
+
*/
|
|
21
|
+
const payment_queryFeeDetails = (context, [extrinsic, hash]) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
const block = yield context.chain.getBlock(hash);
|
|
23
|
+
if (!block) {
|
|
24
|
+
throw new shared_1.ResponseError(1, `Block ${hash} not found`);
|
|
25
|
+
}
|
|
26
|
+
const registry = yield block.registry;
|
|
27
|
+
const tx = (0, util_1.hexToU8a)(extrinsic);
|
|
28
|
+
const resp = yield block.call('TransactionPaymentApi_query_fee_details', [
|
|
29
|
+
registry.createType('Extrinsic', tx).toHex(),
|
|
30
|
+
registry.createType('u32', tx.byteLength).toHex(),
|
|
31
|
+
]);
|
|
32
|
+
return resp.result;
|
|
33
|
+
});
|
|
34
|
+
exports.payment_queryFeeDetails = payment_queryFeeDetails;
|
|
35
|
+
/**
|
|
36
|
+
* @param context
|
|
37
|
+
* @param params - [`extrinsic`, `blockhash`]
|
|
38
|
+
*
|
|
39
|
+
* @return result in hash
|
|
40
|
+
*/
|
|
41
|
+
const payment_queryInfo = (context, [extrinsic, hash]) => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
+
const block = yield context.chain.getBlock(hash);
|
|
43
|
+
if (!block) {
|
|
44
|
+
throw new shared_1.ResponseError(1, `Block ${hash} not found`);
|
|
45
|
+
}
|
|
46
|
+
const registry = yield block.registry;
|
|
47
|
+
const tx = (0, util_1.hexToU8a)(extrinsic);
|
|
48
|
+
const resp = yield block.call('TransactionPaymentApi_query_info', [
|
|
49
|
+
registry.createType('Extrinsic', tx).toHex(),
|
|
50
|
+
registry.createType('u32', tx.byteLength).toHex(),
|
|
51
|
+
]);
|
|
52
|
+
return resp.result;
|
|
53
|
+
});
|
|
54
|
+
exports.payment_queryInfo = payment_queryInfo;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { HexString } from '@polkadot/util/types';
|
|
2
|
+
import { Handler } from '../shared';
|
|
3
|
+
import { RuntimeVersion } from '../../wasm-executor';
|
|
4
|
+
/**
|
|
5
|
+
* @param context
|
|
6
|
+
* @param params - [`blockhash`]
|
|
7
|
+
*
|
|
8
|
+
* @return runtime version
|
|
9
|
+
*/
|
|
10
|
+
export declare const state_getRuntimeVersion: Handler<[HexString], RuntimeVersion | undefined>;
|
|
11
|
+
/**
|
|
12
|
+
* @param context
|
|
13
|
+
* @param params - [`blockhash`]
|
|
14
|
+
*
|
|
15
|
+
* @return metadata
|
|
16
|
+
*/
|
|
17
|
+
export declare const state_getMetadata: Handler<[HexString], HexString | undefined>;
|
|
18
|
+
/**
|
|
19
|
+
* @param context
|
|
20
|
+
* @param params - [`key`, `blockhash`]
|
|
21
|
+
*
|
|
22
|
+
* @return storage value
|
|
23
|
+
*/
|
|
24
|
+
export declare const state_getStorage: Handler<[HexString, HexString], string | undefined>;
|
|
25
|
+
/**
|
|
26
|
+
* @param context
|
|
27
|
+
* @param params - [`prefix`, `pageSize`, `startKey`, `blockhash`]
|
|
28
|
+
*
|
|
29
|
+
* @return paged keys
|
|
30
|
+
*/
|
|
31
|
+
export declare const state_getKeysPaged: Handler<[string, number, string, HexString], string[] | undefined>;
|
|
32
|
+
/**
|
|
33
|
+
* @param context
|
|
34
|
+
* @param params - [`keys`, `blockhash`]
|
|
35
|
+
*
|
|
36
|
+
* @return storage values
|
|
37
|
+
*/
|
|
38
|
+
export declare const state_queryStorageAt: Handler<[
|
|
39
|
+
string[],
|
|
40
|
+
HexString
|
|
41
|
+
], [] | [
|
|
42
|
+
{
|
|
43
|
+
block: HexString;
|
|
44
|
+
changes: (string | undefined)[][];
|
|
45
|
+
}
|
|
46
|
+
]>;
|
|
47
|
+
/**
|
|
48
|
+
* @param context
|
|
49
|
+
* @param params - [`method`, `data`, `blockhash`]
|
|
50
|
+
*
|
|
51
|
+
* @return result in hash
|
|
52
|
+
*/
|
|
53
|
+
export declare const state_call: Handler<[HexString, HexString, HexString], HexString>;
|
|
54
|
+
/**
|
|
55
|
+
* @return subscription id
|
|
56
|
+
*/
|
|
57
|
+
export declare const state_subscribeRuntimeVersion: Handler<[], string>;
|
|
58
|
+
/**
|
|
59
|
+
* @param context
|
|
60
|
+
* @param params - [`subid`]
|
|
61
|
+
* @param subscriptionManager
|
|
62
|
+
*/
|
|
63
|
+
export declare const state_unsubscribeRuntimeVersion: Handler<[HexString], void>;
|
|
64
|
+
/**
|
|
65
|
+
* @param context
|
|
66
|
+
* @param params - [`keys`]
|
|
67
|
+
* @param subscriptionManager
|
|
68
|
+
*
|
|
69
|
+
* @return subscription id
|
|
70
|
+
*/
|
|
71
|
+
export declare const state_subscribeStorage: Handler<[string[]], string>;
|
|
72
|
+
/**
|
|
73
|
+
* @param context
|
|
74
|
+
* @param params - [`subid`]
|
|
75
|
+
* @param subscriptionManager
|
|
76
|
+
*/
|
|
77
|
+
export declare const state_unsubscribeStorage: Handler<[string], void>;
|
|
78
|
+
/**
|
|
79
|
+
* @param context
|
|
80
|
+
* @param params - [`child`, `key`, `blockhash`]
|
|
81
|
+
*
|
|
82
|
+
* @return storage valuse
|
|
83
|
+
*/
|
|
84
|
+
export declare const childstate_getStorage: Handler<[HexString, HexString, HexString], string | undefined>;
|
|
85
|
+
/**
|
|
86
|
+
* @param context
|
|
87
|
+
* @param params - [`child`, `prefix`, `pageSize`, `startKey`, `blockhash`]
|
|
88
|
+
*
|
|
89
|
+
* @return paged keys
|
|
90
|
+
*/
|
|
91
|
+
export declare const childstate_getKeysPaged: Handler<[
|
|
92
|
+
HexString,
|
|
93
|
+
HexString,
|
|
94
|
+
number,
|
|
95
|
+
HexString,
|
|
96
|
+
HexString
|
|
97
|
+
], HexString[] | undefined>;
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.childstate_getKeysPaged = exports.childstate_getStorage = exports.state_unsubscribeStorage = exports.state_subscribeStorage = exports.state_unsubscribeRuntimeVersion = exports.state_subscribeRuntimeVersion = exports.state_call = exports.state_queryStorageAt = exports.state_getKeysPaged = exports.state_getStorage = exports.state_getMetadata = exports.state_getRuntimeVersion = void 0;
|
|
13
|
+
const shared_1 = require("../shared");
|
|
14
|
+
const logger_1 = require("../../logger");
|
|
15
|
+
const utils_1 = require("../../utils");
|
|
16
|
+
const logger = logger_1.defaultLogger.child({ name: 'rpc-state' });
|
|
17
|
+
/**
|
|
18
|
+
* @param context
|
|
19
|
+
* @param params - [`blockhash`]
|
|
20
|
+
*
|
|
21
|
+
* @return runtime version
|
|
22
|
+
*/
|
|
23
|
+
const state_getRuntimeVersion = (context, [hash]) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
const block = yield context.chain.getBlock(hash);
|
|
25
|
+
return block === null || block === void 0 ? void 0 : block.runtimeVersion;
|
|
26
|
+
});
|
|
27
|
+
exports.state_getRuntimeVersion = state_getRuntimeVersion;
|
|
28
|
+
/**
|
|
29
|
+
* @param context
|
|
30
|
+
* @param params - [`blockhash`]
|
|
31
|
+
*
|
|
32
|
+
* @return metadata
|
|
33
|
+
*/
|
|
34
|
+
const state_getMetadata = (context, [hash]) => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
+
const block = yield context.chain.getBlock(hash);
|
|
36
|
+
return block === null || block === void 0 ? void 0 : block.metadata;
|
|
37
|
+
});
|
|
38
|
+
exports.state_getMetadata = state_getMetadata;
|
|
39
|
+
/**
|
|
40
|
+
* @param context
|
|
41
|
+
* @param params - [`key`, `blockhash`]
|
|
42
|
+
*
|
|
43
|
+
* @return storage value
|
|
44
|
+
*/
|
|
45
|
+
const state_getStorage = (context, [key, hash]) => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
+
const block = yield context.chain.getBlock(hash);
|
|
47
|
+
return block === null || block === void 0 ? void 0 : block.get(key);
|
|
48
|
+
});
|
|
49
|
+
exports.state_getStorage = state_getStorage;
|
|
50
|
+
/**
|
|
51
|
+
* @param context
|
|
52
|
+
* @param params - [`prefix`, `pageSize`, `startKey`, `blockhash`]
|
|
53
|
+
*
|
|
54
|
+
* @return paged keys
|
|
55
|
+
*/
|
|
56
|
+
const state_getKeysPaged = (context, [prefix, pageSize, startKey, hash]) => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
|
+
const block = yield context.chain.getBlock(hash);
|
|
58
|
+
return block === null || block === void 0 ? void 0 : block.getKeysPaged({ prefix, pageSize, startKey });
|
|
59
|
+
});
|
|
60
|
+
exports.state_getKeysPaged = state_getKeysPaged;
|
|
61
|
+
/**
|
|
62
|
+
* @param context
|
|
63
|
+
* @param params - [`keys`, `blockhash`]
|
|
64
|
+
*
|
|
65
|
+
* @return storage values
|
|
66
|
+
*/
|
|
67
|
+
const state_queryStorageAt = (context, [keys, hash]) => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
+
const block = yield context.chain.getBlock(hash);
|
|
69
|
+
if (!block) {
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
const values = yield Promise.all(keys.map((key) => __awaiter(void 0, void 0, void 0, function* () { return [key, yield block.get(key)]; })));
|
|
73
|
+
return [
|
|
74
|
+
{
|
|
75
|
+
block: block.hash,
|
|
76
|
+
changes: values,
|
|
77
|
+
},
|
|
78
|
+
];
|
|
79
|
+
});
|
|
80
|
+
exports.state_queryStorageAt = state_queryStorageAt;
|
|
81
|
+
/**
|
|
82
|
+
* @param context
|
|
83
|
+
* @param params - [`method`, `data`, `blockhash`]
|
|
84
|
+
*
|
|
85
|
+
* @return result in hash
|
|
86
|
+
*/
|
|
87
|
+
const state_call = (context, [method, data, hash]) => __awaiter(void 0, void 0, void 0, function* () {
|
|
88
|
+
const block = yield context.chain.getBlock(hash);
|
|
89
|
+
if (!block) {
|
|
90
|
+
throw new shared_1.ResponseError(1, `Block ${hash} not found`);
|
|
91
|
+
}
|
|
92
|
+
const resp = yield block.call(method, [data]);
|
|
93
|
+
return resp.result;
|
|
94
|
+
});
|
|
95
|
+
exports.state_call = state_call;
|
|
96
|
+
/**
|
|
97
|
+
* @return subscription id
|
|
98
|
+
*/
|
|
99
|
+
const state_subscribeRuntimeVersion = (context, _params, { subscribe }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
100
|
+
let update = (_block) => { };
|
|
101
|
+
const id = yield context.chain.headState.subscrubeRuntimeVersion((block) => update(block));
|
|
102
|
+
const callback = subscribe('state_runtimeVersion', id);
|
|
103
|
+
update = (block) => __awaiter(void 0, void 0, void 0, function* () { return callback(yield block.runtimeVersion); });
|
|
104
|
+
context.chain.head.runtimeVersion.then(callback);
|
|
105
|
+
return id;
|
|
106
|
+
});
|
|
107
|
+
exports.state_subscribeRuntimeVersion = state_subscribeRuntimeVersion;
|
|
108
|
+
/**
|
|
109
|
+
* @param context
|
|
110
|
+
* @param params - [`subid`]
|
|
111
|
+
* @param subscriptionManager
|
|
112
|
+
*/
|
|
113
|
+
const state_unsubscribeRuntimeVersion = (_context, [subid], { unsubscribe }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
114
|
+
unsubscribe(subid);
|
|
115
|
+
});
|
|
116
|
+
exports.state_unsubscribeRuntimeVersion = state_unsubscribeRuntimeVersion;
|
|
117
|
+
/**
|
|
118
|
+
* @param context
|
|
119
|
+
* @param params - [`keys`]
|
|
120
|
+
* @param subscriptionManager
|
|
121
|
+
*
|
|
122
|
+
* @return subscription id
|
|
123
|
+
*/
|
|
124
|
+
const state_subscribeStorage = (context, [keys], { subscribe }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
125
|
+
let update = (_block, _pairs) => { };
|
|
126
|
+
const id = yield context.chain.headState.subscribeStorage(keys, (block, pairs) => update(block, pairs));
|
|
127
|
+
const callback = subscribe('state_storage', id, () => context.chain.headState.unsubscribeStorage(id));
|
|
128
|
+
update = (block, pairs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
129
|
+
logger.trace({ hash: block.hash }, 'state_subscribeStorage');
|
|
130
|
+
callback({
|
|
131
|
+
block: block.hash,
|
|
132
|
+
changes: pairs,
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
136
|
+
const pairs = yield Promise.all(keys.map((key) => __awaiter(void 0, void 0, void 0, function* () {
|
|
137
|
+
const val = yield context.chain.head.get(key);
|
|
138
|
+
return [key, val];
|
|
139
|
+
})));
|
|
140
|
+
callback({
|
|
141
|
+
block: context.chain.head.hash,
|
|
142
|
+
changes: pairs,
|
|
143
|
+
});
|
|
144
|
+
}))();
|
|
145
|
+
return id;
|
|
146
|
+
});
|
|
147
|
+
exports.state_subscribeStorage = state_subscribeStorage;
|
|
148
|
+
/**
|
|
149
|
+
* @param context
|
|
150
|
+
* @param params - [`subid`]
|
|
151
|
+
* @param subscriptionManager
|
|
152
|
+
*/
|
|
153
|
+
const state_unsubscribeStorage = (_context, [subid], { unsubscribe }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
154
|
+
unsubscribe(subid);
|
|
155
|
+
});
|
|
156
|
+
exports.state_unsubscribeStorage = state_unsubscribeStorage;
|
|
157
|
+
/**
|
|
158
|
+
* @param context
|
|
159
|
+
* @param params - [`child`, `key`, `blockhash`]
|
|
160
|
+
*
|
|
161
|
+
* @return storage valuse
|
|
162
|
+
*/
|
|
163
|
+
const childstate_getStorage = (context, [child, key, hash]) => __awaiter(void 0, void 0, void 0, function* () {
|
|
164
|
+
if (!(0, utils_1.isPrefixedChildKey)(child)) {
|
|
165
|
+
throw new shared_1.ResponseError(-32000, 'Client error: Invalid child storage key');
|
|
166
|
+
}
|
|
167
|
+
const block = yield context.chain.getBlock(hash);
|
|
168
|
+
return block === null || block === void 0 ? void 0 : block.get((0, utils_1.prefixedChildKey)(child, key));
|
|
169
|
+
});
|
|
170
|
+
exports.childstate_getStorage = childstate_getStorage;
|
|
171
|
+
/**
|
|
172
|
+
* @param context
|
|
173
|
+
* @param params - [`child`, `prefix`, `pageSize`, `startKey`, `blockhash`]
|
|
174
|
+
*
|
|
175
|
+
* @return paged keys
|
|
176
|
+
*/
|
|
177
|
+
const childstate_getKeysPaged = (context, [child, prefix, pageSize, startKey, hash]) => __awaiter(void 0, void 0, void 0, function* () {
|
|
178
|
+
if (!(0, utils_1.isPrefixedChildKey)(child)) {
|
|
179
|
+
throw new shared_1.ResponseError(-32000, 'Client error: Invalid child storage key');
|
|
180
|
+
}
|
|
181
|
+
const block = yield context.chain.getBlock(hash);
|
|
182
|
+
return block === null || block === void 0 ? void 0 : block.getKeysPaged({ prefix: (0, utils_1.prefixedChildKey)(child, prefix), pageSize, startKey: (0, utils_1.prefixedChildKey)(child, startKey) }).then((keys) => keys.map(utils_1.stripChildPrefix));
|
|
183
|
+
});
|
|
184
|
+
exports.childstate_getKeysPaged = childstate_getKeysPaged;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { HexString } from '@polkadot/util/types';
|
|
2
|
+
import { ChainProperties } from '../../api';
|
|
3
|
+
import { Handler } from '../shared';
|
|
4
|
+
export declare const system_localPeerId: () => Promise<string>;
|
|
5
|
+
export declare const system_nodeRoles: () => Promise<string[]>;
|
|
6
|
+
export declare const system_localListenAddresses: () => Promise<never[]>;
|
|
7
|
+
export declare const system_chain: Handler<void, string>;
|
|
8
|
+
export declare const system_properties: Handler<void, ChainProperties>;
|
|
9
|
+
export declare const system_name: Handler<void, string>;
|
|
10
|
+
export declare const system_version: Handler<void, string>;
|
|
11
|
+
export declare const system_chainType: Handler<void, string>;
|
|
12
|
+
export declare const system_health: () => Promise<{
|
|
13
|
+
peers: number;
|
|
14
|
+
isSyncing: boolean;
|
|
15
|
+
shouldHavePeers: boolean;
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* @param context
|
|
19
|
+
* @param params - [`extrinsic`, `at`]
|
|
20
|
+
*
|
|
21
|
+
* @return ApplyExtrinsicResult (see `@polkadot/types/interfaces`) in hash
|
|
22
|
+
*/
|
|
23
|
+
export declare const system_dryRun: Handler<[HexString, HexString], string>;
|
|
24
|
+
/**
|
|
25
|
+
* @param context
|
|
26
|
+
* @param params - [`address`]
|
|
27
|
+
*/
|
|
28
|
+
export declare const system_accountNextIndex: Handler<[HexString], number>;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.system_accountNextIndex = exports.system_dryRun = exports.system_health = exports.system_chainType = exports.system_version = exports.system_name = exports.system_properties = exports.system_chain = exports.system_localListenAddresses = exports.system_nodeRoles = exports.system_localPeerId = void 0;
|
|
13
|
+
const util_1 = require("@polkadot/util");
|
|
14
|
+
const system_localPeerId = () => __awaiter(void 0, void 0, void 0, function* () { return '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY'; });
|
|
15
|
+
exports.system_localPeerId = system_localPeerId;
|
|
16
|
+
const system_nodeRoles = () => __awaiter(void 0, void 0, void 0, function* () { return ['Full']; });
|
|
17
|
+
exports.system_nodeRoles = system_nodeRoles;
|
|
18
|
+
const system_localListenAddresses = () => __awaiter(void 0, void 0, void 0, function* () { return []; });
|
|
19
|
+
exports.system_localListenAddresses = system_localListenAddresses;
|
|
20
|
+
const system_chain = (context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
return context.chain.api.getSystemChain();
|
|
22
|
+
});
|
|
23
|
+
exports.system_chain = system_chain;
|
|
24
|
+
const system_properties = (context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
+
return context.chain.api.getSystemProperties();
|
|
26
|
+
});
|
|
27
|
+
exports.system_properties = system_properties;
|
|
28
|
+
const system_name = (context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
+
return context.chain.api.getSystemName();
|
|
30
|
+
});
|
|
31
|
+
exports.system_name = system_name;
|
|
32
|
+
const system_version = (_context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
+
return 'chopsticks-v1';
|
|
34
|
+
});
|
|
35
|
+
exports.system_version = system_version;
|
|
36
|
+
const system_chainType = (_context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
return 'Development';
|
|
38
|
+
});
|
|
39
|
+
exports.system_chainType = system_chainType;
|
|
40
|
+
const system_health = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
+
return {
|
|
42
|
+
peers: 0,
|
|
43
|
+
isSyncing: false,
|
|
44
|
+
shouldHavePeers: false,
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
exports.system_health = system_health;
|
|
48
|
+
/**
|
|
49
|
+
* @param context
|
|
50
|
+
* @param params - [`extrinsic`, `at`]
|
|
51
|
+
*
|
|
52
|
+
* @return ApplyExtrinsicResult (see `@polkadot/types/interfaces`) in hash
|
|
53
|
+
*/
|
|
54
|
+
const system_dryRun = (context, [extrinsic, at]) => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
+
const { outcome } = yield context.chain.dryRunExtrinsic(extrinsic, at);
|
|
56
|
+
return outcome.toHex();
|
|
57
|
+
});
|
|
58
|
+
exports.system_dryRun = system_dryRun;
|
|
59
|
+
/**
|
|
60
|
+
* @param context
|
|
61
|
+
* @param params - [`address`]
|
|
62
|
+
*/
|
|
63
|
+
const system_accountNextIndex = (context, [address]) => __awaiter(void 0, void 0, void 0, function* () {
|
|
64
|
+
const head = context.chain.head;
|
|
65
|
+
const registry = yield head.registry;
|
|
66
|
+
const account = registry.createType('AccountId', address);
|
|
67
|
+
const result = yield head.call('AccountNonceApi_account_nonce', [account.toHex()]);
|
|
68
|
+
const nonce = registry.createType('Index', (0, util_1.hexToU8a)(result.result)).toNumber();
|
|
69
|
+
return nonce + context.chain.txPool.pendingExtrinsicsBy(address).length;
|
|
70
|
+
});
|
|
71
|
+
exports.system_accountNextIndex = system_accountNextIndex;
|
package/lib/utils/time-travel.js
CHANGED
|
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.timeTravel = exports.getSlotDuration = exports.getCurrentTimestamp = exports.getCurrentSlot = void 0;
|
|
13
13
|
const util_1 = require("@polkadot/util");
|
|
14
14
|
const _1 = require(".");
|
|
15
|
-
const
|
|
15
|
+
const wasm_executor_1 = require("../wasm-executor");
|
|
16
16
|
const set_storage_1 = require("./set-storage");
|
|
17
17
|
const getCurrentSlot = (chain) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
18
|
const meta = yield chain.head.meta;
|
|
@@ -36,7 +36,7 @@ const getSlotDuration = (chain) => __awaiter(void 0, void 0, void 0, function* (
|
|
|
36
36
|
return meta.consts.babe
|
|
37
37
|
? meta.consts.babe.expectedBlockTime.toNumber()
|
|
38
38
|
: meta.query.aura
|
|
39
|
-
? (0,
|
|
39
|
+
? (0, wasm_executor_1.getAuraSlotDuration)(yield chain.head.wasm, meta.registry)
|
|
40
40
|
: 12000;
|
|
41
41
|
});
|
|
42
42
|
exports.getSlotDuration = getSlotDuration;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as Comlink from 'comlink'
|
|
2
|
+
import * as pkg from '@acala-network/chopsticks-executor'
|
|
3
|
+
|
|
4
|
+
const getRuntimeVersion = async (code) => {
|
|
5
|
+
await pkg.wasmReady
|
|
6
|
+
return pkg.get_runtime_version(code)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// trie_version: 0 for old trie, 1 for new trie
|
|
10
|
+
const calculateStateRoot = async (entries, trie_version) => {
|
|
11
|
+
await pkg.wasmReady
|
|
12
|
+
return pkg.calculate_state_root(entries, trie_version)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const decodeProof = async (trieRootHash, keys, nodes) => {
|
|
16
|
+
await pkg.wasmReady
|
|
17
|
+
const decoded = await pkg.decode_proof(trieRootHash, keys, nodes)
|
|
18
|
+
return decoded.reduce((accum, [key, value]) => {
|
|
19
|
+
accum[key] = value
|
|
20
|
+
return accum
|
|
21
|
+
}, {})
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const createProof = async (nodes, entries) => {
|
|
25
|
+
await pkg.wasmReady
|
|
26
|
+
const result = await pkg.create_proof(nodes, entries)
|
|
27
|
+
return { trieRootHash: result[0], nodes: result[1] }
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const runTask = async (task, callback) => {
|
|
31
|
+
await pkg.wasmReady
|
|
32
|
+
return pkg.run_task(task, callback, 'info')
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const wasmExecutor = { runTask, getRuntimeVersion, calculateStateRoot, createProof, decodeProof }
|
|
36
|
+
|
|
37
|
+
Comlink.expose(wasmExecutor)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.startWorker = void 0;
|
|
13
|
+
const comlink_1 = require("comlink");
|
|
14
|
+
const startWorker = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
const worker = new Worker(new URL('browser-wasm-executor.mjs', import.meta.url), {
|
|
18
|
+
type: 'module',
|
|
19
|
+
name: 'chopsticks-wasm-executor',
|
|
20
|
+
});
|
|
21
|
+
return {
|
|
22
|
+
remote: (0, comlink_1.wrap)(worker),
|
|
23
|
+
terminate: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
worker.terminate();
|
|
25
|
+
}),
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
exports.startWorker = startWorker;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { HexString } from '@polkadot/util/types';
|
|
2
|
-
import { Block } from './blockchain/block';
|
|
3
2
|
import { Registry } from '@polkadot/types-codec/types';
|
|
4
3
|
import _ from 'lodash';
|
|
4
|
+
import { Block } from '../blockchain/block';
|
|
5
5
|
import type { JsCallback } from '@acala-network/chopsticks-executor';
|
|
6
6
|
export { JsCallback };
|
|
7
7
|
export type RuntimeVersion = {
|
|
@@ -14,6 +14,22 @@ export type RuntimeVersion = {
|
|
|
14
14
|
transactionVersion: number;
|
|
15
15
|
stateVersion: number;
|
|
16
16
|
};
|
|
17
|
+
export interface WasmExecutor {
|
|
18
|
+
getRuntimeVersion: (code: HexString) => Promise<RuntimeVersion>;
|
|
19
|
+
calculateStateRoot: (entries: [HexString, HexString][], trie_version: number) => Promise<HexString>;
|
|
20
|
+
createProof: (nodes: HexString[], entries: [HexString, HexString | null][]) => Promise<{
|
|
21
|
+
trieRootHash: `0x${string}`;
|
|
22
|
+
nodes: `0x${string}`[];
|
|
23
|
+
}>;
|
|
24
|
+
decodeProof: (trieRootHash: HexString, keys: HexString[], nodes: HexString[]) => Promise<Record<`0x${string}`, `0x${string}` | null>>;
|
|
25
|
+
runTask: (task: {
|
|
26
|
+
wasm: HexString;
|
|
27
|
+
calls: [string, HexString[]][];
|
|
28
|
+
mockSignatureHost: boolean;
|
|
29
|
+
allowUnresolvedImports: boolean;
|
|
30
|
+
runtimeLogLevel: number;
|
|
31
|
+
}, callback?: JsCallback) => Promise<any>;
|
|
32
|
+
}
|
|
17
33
|
export declare const getRuntimeVersion: (code: HexString) => Promise<RuntimeVersion>;
|
|
18
34
|
export declare const calculateStateRoot: (entries: [HexString, HexString][], trie_version: number) => Promise<HexString>;
|
|
19
35
|
export declare const decodeProof: (trieRootHash: HexString, keys: HexString[], nodes: HexString[]) => Promise<Record<`0x${string}`, `0x${string}` | null>>;
|
|
@@ -39,3 +55,4 @@ export declare const emptyTaskHandler: {
|
|
|
39
55
|
offchainSubmitTransaction: (_tx: HexString) => Promise<never>;
|
|
40
56
|
};
|
|
41
57
|
export declare const getAuraSlotDuration: ((wasm: HexString, registry: Registry) => Promise<number>) & _.MemoizedFunction;
|
|
58
|
+
export declare const releaseWorker: () => Promise<void>;
|