@acala-network/chopsticks-core 0.9.9-1 → 0.9.9-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/inherent/parachain/validation-data.js +6 -4
- package/dist/cjs/chopsticks-provider.js +1 -5
- package/dist/cjs/genesis-provider.js +39 -7
- package/dist/cjs/rpc/dev/index.d.ts +15 -0
- package/dist/cjs/rpc/dev/index.js +38 -0
- package/dist/cjs/rpc/dev/new-block.d.ts +128 -0
- package/dist/cjs/rpc/dev/new-block.js +57 -0
- package/dist/cjs/rpc/dev/set-block-build-mode.d.ts +21 -0
- package/dist/cjs/rpc/dev/set-block-build-mode.js +22 -0
- package/dist/cjs/rpc/dev/set-head.d.ts +21 -0
- package/dist/cjs/rpc/dev/set-head.js +28 -0
- package/dist/cjs/rpc/dev/set-runtime-log-level.d.ts +17 -0
- package/dist/cjs/rpc/dev/set-runtime-log-level.js +21 -0
- package/dist/cjs/rpc/dev/set-storage.d.ts +29 -0
- package/dist/cjs/rpc/dev/set-storage.js +24 -0
- package/dist/cjs/rpc/dev/time-travel.d.ts +17 -0
- package/dist/cjs/rpc/dev/time-travel.js +18 -0
- package/dist/cjs/rpc/index.d.ts +3 -1
- package/dist/cjs/rpc/index.js +8 -5
- package/dist/cjs/rpc/shared.d.ts +3 -0
- package/dist/cjs/rpc/shared.js +9 -0
- package/dist/cjs/wasm-executor/index.d.ts +0 -1
- package/dist/cjs/wasm-executor/index.js +0 -7
- package/dist/esm/blockchain/inherent/parachain/validation-data.js +6 -4
- package/dist/esm/chopsticks-provider.js +1 -5
- package/dist/esm/genesis-provider.js +39 -7
- package/dist/esm/rpc/dev/index.d.ts +15 -0
- package/dist/esm/rpc/dev/index.js +21 -0
- package/dist/esm/rpc/dev/new-block.d.ts +128 -0
- package/dist/esm/rpc/dev/new-block.js +84 -0
- package/dist/esm/rpc/dev/set-block-build-mode.d.ts +21 -0
- package/dist/esm/rpc/dev/set-block-build-mode.js +29 -0
- package/dist/esm/rpc/dev/set-head.d.ts +21 -0
- package/dist/esm/rpc/dev/set-head.js +32 -0
- package/dist/esm/rpc/dev/set-runtime-log-level.d.ts +17 -0
- package/dist/esm/rpc/dev/set-runtime-log-level.js +25 -0
- package/dist/esm/rpc/dev/set-storage.d.ts +29 -0
- package/dist/esm/rpc/dev/set-storage.js +38 -0
- package/dist/esm/rpc/dev/time-travel.d.ts +17 -0
- package/dist/esm/rpc/dev/time-travel.js +22 -0
- package/dist/esm/rpc/index.d.ts +3 -1
- package/dist/esm/rpc/index.js +4 -4
- package/dist/esm/rpc/shared.d.ts +3 -0
- package/dist/esm/rpc/shared.js +3 -0
- package/dist/esm/wasm-executor/index.d.ts +0 -1
- package/dist/esm/wasm-executor/index.js +0 -7
- package/package.json +2 -2
|
@@ -8,8 +8,8 @@ Object.defineProperty(exports, "SetValidationData", {
|
|
|
8
8
|
return SetValidationData;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const _types = require("@polkadot/types");
|
|
12
11
|
const _util = require("@polkadot/util");
|
|
12
|
+
const _types = require("@polkadot/types");
|
|
13
13
|
const _lodash = /*#__PURE__*/ _interop_require_default(require("lodash"));
|
|
14
14
|
const _proof = require("../../../utils/proof.js");
|
|
15
15
|
const _utilcrypto = require("@polkadot/util-crypto");
|
|
@@ -88,11 +88,13 @@ class SetValidationData {
|
|
|
88
88
|
const hrmpIngressChannelIndexKey = (0, _proof.hrmpIngressChannelIndex)(paraId);
|
|
89
89
|
const hrmpEgressChannelIndexKey = (0, _proof.hrmpEgressChannelIndex)(paraId);
|
|
90
90
|
const decoded = await (0, _index1.decodeProof)(extrinsic.validationData.relayParentStorageRoot, extrinsic.relayChainState.trieNodes);
|
|
91
|
+
const slotIncrease = meta.consts.timestamp.minimumPeriod.divn(3000) // relaychain min period
|
|
92
|
+
.toNumber();
|
|
91
93
|
for (const key of Object.values(_proof.WELL_KNOWN_KEYS)){
|
|
92
94
|
if (key === _proof.WELL_KNOWN_KEYS.CURRENT_SLOT) {
|
|
93
95
|
// increment current slot
|
|
94
|
-
const
|
|
95
|
-
const newSlot = meta.registry.createType('Slot',
|
|
96
|
+
const relayCurrentSlot = decoded[key] ? meta.registry.createType('Slot', (0, _util.hexToU8a)(decoded[key])).toNumber() : await (0, _index.getCurrentSlot)(parent.chain) * slotIncrease;
|
|
97
|
+
const newSlot = meta.registry.createType('Slot', relayCurrentSlot + slotIncrease);
|
|
96
98
|
newEntries.push([
|
|
97
99
|
key,
|
|
98
100
|
(0, _util.u8aToHex)(newSlot.toU8a())
|
|
@@ -232,7 +234,7 @@ class SetValidationData {
|
|
|
232
234
|
validationData: {
|
|
233
235
|
...extrinsic.validationData,
|
|
234
236
|
relayParentStorageRoot: trieRootHash,
|
|
235
|
-
relayParentNumber: extrinsic.validationData.relayParentNumber +
|
|
237
|
+
relayParentNumber: extrinsic.validationData.relayParentNumber + slotIncrease
|
|
236
238
|
},
|
|
237
239
|
relayChainState: {
|
|
238
240
|
trieNodes: nodes
|
|
@@ -66,11 +66,7 @@ function _define_property(obj, key, value) {
|
|
|
66
66
|
return obj;
|
|
67
67
|
}
|
|
68
68
|
const providerHandlers = {
|
|
69
|
-
..._index.allHandlers
|
|
70
|
-
dev_newBlock: async (context, _params, _subscriptionManager)=>{
|
|
71
|
-
const block = await context.chain.newBlock();
|
|
72
|
-
return block.hash;
|
|
73
|
-
}
|
|
69
|
+
..._index.allHandlers
|
|
74
70
|
};
|
|
75
71
|
const logger = _logger.defaultLogger.child({
|
|
76
72
|
name: '[Chopsticks provider]'
|
|
@@ -11,6 +11,7 @@ Object.defineProperty(exports, "GenesisProvider", {
|
|
|
11
11
|
const _eventemitter3 = require("eventemitter3");
|
|
12
12
|
const _index = require("./schema/index.js");
|
|
13
13
|
const _index1 = require("./wasm-executor/index.js");
|
|
14
|
+
const _index2 = require("./index.js");
|
|
14
15
|
function _check_private_redeclaration(obj, privateCollection) {
|
|
15
16
|
if (privateCollection.has(obj)) {
|
|
16
17
|
throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
@@ -86,13 +87,29 @@ class GenesisProvider {
|
|
|
86
87
|
return {
|
|
87
88
|
..._index1.emptyTaskHandler,
|
|
88
89
|
getStorage: async function(key) {
|
|
90
|
+
if ((0, _index2.isPrefixedChildKey)(key)) {
|
|
91
|
+
_index2.defaultLogger.warn({
|
|
92
|
+
key
|
|
93
|
+
}, 'genesis child storage not supported');
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
89
96
|
return storage[key];
|
|
90
97
|
},
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
98
|
+
getNextKey: async function(prefix, key) {
|
|
99
|
+
if ((0, _index2.isPrefixedChildKey)(key)) {
|
|
100
|
+
_index2.defaultLogger.warn({
|
|
101
|
+
prefix,
|
|
102
|
+
key
|
|
103
|
+
}, 'genesis child storage not supported');
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
return Object.keys(storage).find((k)=>{
|
|
107
|
+
if (!k.startsWith(prefix)) return false;
|
|
108
|
+
if (key.length > prefix.length) {
|
|
109
|
+
return k > key;
|
|
110
|
+
}
|
|
111
|
+
return true;
|
|
112
|
+
});
|
|
96
113
|
}
|
|
97
114
|
};
|
|
98
115
|
}
|
|
@@ -177,10 +194,25 @@ class GenesisProvider {
|
|
|
177
194
|
return this.blockHash;
|
|
178
195
|
case 'state_getKeysPaged':
|
|
179
196
|
case 'state_getKeysPagedAt':
|
|
180
|
-
|
|
197
|
+
{
|
|
198
|
+
if (params.length < 2) throw Error('invalid params');
|
|
199
|
+
const [prefix, size, start] = params;
|
|
200
|
+
let startKey = start || prefix;
|
|
201
|
+
const keys = [];
|
|
202
|
+
while(keys.length < size){
|
|
203
|
+
const nextKey = await this._jsCallback.getNextKey(prefix, startKey);
|
|
204
|
+
if (!nextKey) break;
|
|
205
|
+
keys.push(nextKey);
|
|
206
|
+
startKey = nextKey;
|
|
207
|
+
}
|
|
208
|
+
return keys;
|
|
209
|
+
}
|
|
181
210
|
case 'state_getStorage':
|
|
182
211
|
case 'state_getStorageAt':
|
|
183
|
-
|
|
212
|
+
{
|
|
213
|
+
if (params.length < 1) throw Error('invalid params');
|
|
214
|
+
return _class_private_field_get(this, _genesis).genesis.raw.top[params[0]];
|
|
215
|
+
}
|
|
184
216
|
default:
|
|
185
217
|
throw Error(`${method} not implemented`);
|
|
186
218
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare const handlers: {
|
|
2
|
+
dev_newBlock: (context: import("../shared.js").Context, [params]: [import("./new-block.js").NewBlockParams]) => Promise<`0x${string}`>;
|
|
3
|
+
dev_setBlockBuildMode: (context: import("../shared.js").Context, [mode]: [import("../../index.js").BuildBlockMode]) => Promise<void>;
|
|
4
|
+
dev_setHead: (context: import("../shared.js").Context, [params]: [number | `0x${string}`]) => Promise<`0x${string}`>;
|
|
5
|
+
dev_setRuntimeLogLevel: (context: import("../shared.js").Context, [runtimeLogLevel]: [number]) => Promise<void>;
|
|
6
|
+
dev_setStorage: (context: import("../shared.js").Context, params: [import("../../index.js").StorageValues, (`0x${string}` | undefined)?]) => Promise<`0x${string}`>;
|
|
7
|
+
dev_timeTravel: (context: import("../shared.js").Context, [date]: [string | number]) => Promise<number>;
|
|
8
|
+
};
|
|
9
|
+
export default handlers;
|
|
10
|
+
export * from './new-block.js';
|
|
11
|
+
export * from './set-block-build-mode.js';
|
|
12
|
+
export * from './set-head.js';
|
|
13
|
+
export * from './set-runtime-log-level.js';
|
|
14
|
+
export * from './set-storage.js';
|
|
15
|
+
export * from './time-travel.js';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return _default;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _newblock = _export_star(require("./new-block.js"), exports);
|
|
12
|
+
const _setblockbuildmode = _export_star(require("./set-block-build-mode.js"), exports);
|
|
13
|
+
const _sethead = _export_star(require("./set-head.js"), exports);
|
|
14
|
+
const _setruntimeloglevel = _export_star(require("./set-runtime-log-level.js"), exports);
|
|
15
|
+
const _setstorage = _export_star(require("./set-storage.js"), exports);
|
|
16
|
+
const _timetravel = _export_star(require("./time-travel.js"), exports);
|
|
17
|
+
function _export_star(from, to) {
|
|
18
|
+
Object.keys(from).forEach(function(k) {
|
|
19
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
20
|
+
Object.defineProperty(to, k, {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function() {
|
|
23
|
+
return from[k];
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return from;
|
|
29
|
+
}
|
|
30
|
+
const handlers = {
|
|
31
|
+
dev_newBlock: _newblock.dev_newBlock,
|
|
32
|
+
dev_setBlockBuildMode: _setblockbuildmode.dev_setBlockBuildMode,
|
|
33
|
+
dev_setHead: _sethead.dev_setHead,
|
|
34
|
+
dev_setRuntimeLogLevel: _setruntimeloglevel.dev_setRuntimeLogLevel,
|
|
35
|
+
dev_setStorage: _setstorage.dev_setStorage,
|
|
36
|
+
dev_timeTravel: _timetravel.dev_timeTravel
|
|
37
|
+
};
|
|
38
|
+
const _default = handlers;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { Context } from '../shared.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
declare const schema: z.ZodObject<{
|
|
4
|
+
count: z.ZodOptional<z.ZodNumber>;
|
|
5
|
+
to: z.ZodOptional<z.ZodNumber>;
|
|
6
|
+
dmp: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
7
|
+
sentAt: z.ZodNumber;
|
|
8
|
+
msg: z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
msg: `0x${string}`;
|
|
11
|
+
sentAt: number;
|
|
12
|
+
}, {
|
|
13
|
+
msg: `0x${string}`;
|
|
14
|
+
sentAt: number;
|
|
15
|
+
}>, "many">>;
|
|
16
|
+
ump: z.ZodOptional<z.ZodRecord<z.ZodNumber, z.ZodArray<z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, "many">>>;
|
|
17
|
+
hrmp: z.ZodOptional<z.ZodRecord<z.ZodUnion<[z.ZodNumber, z.ZodString]>, z.ZodArray<z.ZodObject<{
|
|
18
|
+
sentAt: z.ZodNumber;
|
|
19
|
+
data: z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>;
|
|
20
|
+
}, "strip", z.ZodTypeAny, {
|
|
21
|
+
data: `0x${string}`;
|
|
22
|
+
sentAt: number;
|
|
23
|
+
}, {
|
|
24
|
+
data: `0x${string}`;
|
|
25
|
+
sentAt: number;
|
|
26
|
+
}>, "many">>>;
|
|
27
|
+
transactions: z.ZodOptional<z.ZodArray<z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, "many">>;
|
|
28
|
+
unsafeBlockHeight: z.ZodOptional<z.ZodNumber>;
|
|
29
|
+
}, "strip", z.ZodTypeAny, {
|
|
30
|
+
count?: number | undefined;
|
|
31
|
+
to?: number | undefined;
|
|
32
|
+
dmp?: {
|
|
33
|
+
msg: `0x${string}`;
|
|
34
|
+
sentAt: number;
|
|
35
|
+
}[] | undefined;
|
|
36
|
+
ump?: Record<number, `0x${string}`[]> | undefined;
|
|
37
|
+
hrmp?: Record<string | number, {
|
|
38
|
+
data: `0x${string}`;
|
|
39
|
+
sentAt: number;
|
|
40
|
+
}[]> | undefined;
|
|
41
|
+
transactions?: `0x${string}`[] | undefined;
|
|
42
|
+
unsafeBlockHeight?: number | undefined;
|
|
43
|
+
}, {
|
|
44
|
+
count?: number | undefined;
|
|
45
|
+
to?: number | undefined;
|
|
46
|
+
dmp?: {
|
|
47
|
+
msg: `0x${string}`;
|
|
48
|
+
sentAt: number;
|
|
49
|
+
}[] | undefined;
|
|
50
|
+
ump?: Record<number, `0x${string}`[]> | undefined;
|
|
51
|
+
hrmp?: Record<string | number, {
|
|
52
|
+
data: `0x${string}`;
|
|
53
|
+
sentAt: number;
|
|
54
|
+
}[]> | undefined;
|
|
55
|
+
transactions?: `0x${string}`[] | undefined;
|
|
56
|
+
unsafeBlockHeight?: number | undefined;
|
|
57
|
+
}>;
|
|
58
|
+
type Params = z.infer<typeof schema>;
|
|
59
|
+
export interface NewBlockParams {
|
|
60
|
+
/**
|
|
61
|
+
* The number of blocks to build
|
|
62
|
+
*/
|
|
63
|
+
count: Params['count'];
|
|
64
|
+
/**
|
|
65
|
+
* The block number to build to
|
|
66
|
+
*/
|
|
67
|
+
to: Params['to'];
|
|
68
|
+
/**
|
|
69
|
+
* The downward messages to include in the block
|
|
70
|
+
*/
|
|
71
|
+
dmp: Params['dmp'];
|
|
72
|
+
/**
|
|
73
|
+
* The upward messages to include in the block
|
|
74
|
+
*/
|
|
75
|
+
ump: Params['ump'];
|
|
76
|
+
/**
|
|
77
|
+
* The horizontal messages to include in the block
|
|
78
|
+
*/
|
|
79
|
+
hrmp: Params['hrmp'];
|
|
80
|
+
/**
|
|
81
|
+
* The transactions to include in the block
|
|
82
|
+
*/
|
|
83
|
+
transactions: Params['transactions'];
|
|
84
|
+
/**
|
|
85
|
+
* Build block using a specific block height (unsafe)
|
|
86
|
+
*/
|
|
87
|
+
unsafeBlockHeight: Params['unsafeBlockHeight'];
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Build new blocks.
|
|
91
|
+
*
|
|
92
|
+
* This function is a dev rpc handler. Use `dev_newBlock` as the method name when calling it.
|
|
93
|
+
*
|
|
94
|
+
* @param context - The context object of the rpc handler
|
|
95
|
+
* @param params - The parameters of the rpc handler
|
|
96
|
+
*
|
|
97
|
+
* @example Build 2 blocks
|
|
98
|
+
* ```ts
|
|
99
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
100
|
+
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
101
|
+
* await ws.send('dev_newBlock', [{ count: 2 }])
|
|
102
|
+
* ```
|
|
103
|
+
* @example Build a block with upward messages
|
|
104
|
+
* ```ts
|
|
105
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
106
|
+
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
107
|
+
* await ws.send('dev_newBlock', [
|
|
108
|
+
* {
|
|
109
|
+
* ump: {
|
|
110
|
+
* // https://acala.subscan.io/xcm_message/polkadot-ff66f28818d0b74573e62db8317e354b253fbc80
|
|
111
|
+
* 2000: [
|
|
112
|
+
* '0x021000040000000007903fc4db080a130000000007903fc4db08000d010004000101009c4b11a0974cba4a395c94832fba812868a6cb0ba09e8519b3521093ea359905',
|
|
113
|
+
* ],
|
|
114
|
+
* }
|
|
115
|
+
* }
|
|
116
|
+
* ])
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* @example Build two blocks with unsafeBlockHeight
|
|
120
|
+
* ```ts
|
|
121
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
122
|
+
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
123
|
+
* // this will create two blocks with block height 100000001 and 100000002
|
|
124
|
+
* await ws.send('dev_newBlock', [{ count: 2, unsafeBlockHeight: 100000001 }])
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
export declare const dev_newBlock: (context: Context, [params]: [NewBlockParams]) => Promise<`0x${string}`>;
|
|
128
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "dev_newBlock", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return dev_newBlock;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _shared = require("../shared.js");
|
|
12
|
+
const _zod = require("zod");
|
|
13
|
+
const _logger = require("../../logger.js");
|
|
14
|
+
const schema = _zod.z.object({
|
|
15
|
+
count: _zod.z.number().optional(),
|
|
16
|
+
to: _zod.z.number().optional(),
|
|
17
|
+
dmp: _zod.z.array(_zod.z.object({
|
|
18
|
+
sentAt: _zod.z.number(),
|
|
19
|
+
msg: _shared.zHex
|
|
20
|
+
})).min(1).optional(),
|
|
21
|
+
ump: _zod.z.record(_zod.z.number(), _zod.z.array(_shared.zHex).min(1)).optional(),
|
|
22
|
+
hrmp: _zod.z.record(_zod.z.union([
|
|
23
|
+
_zod.z.number(),
|
|
24
|
+
_zod.z.string()
|
|
25
|
+
]), _zod.z.array(_zod.z.object({
|
|
26
|
+
sentAt: _zod.z.number(),
|
|
27
|
+
data: _shared.zHex
|
|
28
|
+
})).min(1)).optional(),
|
|
29
|
+
transactions: _zod.z.array(_shared.zHex).min(1).optional(),
|
|
30
|
+
unsafeBlockHeight: _zod.z.number().optional()
|
|
31
|
+
});
|
|
32
|
+
const dev_newBlock = async (context, [params])=>{
|
|
33
|
+
const { count, to, hrmp, ump, dmp, transactions, unsafeBlockHeight } = schema.parse(params || {});
|
|
34
|
+
const now = context.chain.head.number;
|
|
35
|
+
const diff = to ? to - now : count;
|
|
36
|
+
const finalCount = diff !== undefined ? Math.max(diff, 1) : 1;
|
|
37
|
+
let finalHash;
|
|
38
|
+
if (unsafeBlockHeight !== undefined && unsafeBlockHeight <= now) {
|
|
39
|
+
throw new _shared.ResponseError(1, 'unsafeBlockHeight must be greater than current block height');
|
|
40
|
+
}
|
|
41
|
+
for(let i = 0; i < finalCount; i++){
|
|
42
|
+
const block = await context.chain.newBlock({
|
|
43
|
+
transactions,
|
|
44
|
+
horizontalMessages: hrmp,
|
|
45
|
+
upwardMessages: ump,
|
|
46
|
+
downwardMessages: dmp,
|
|
47
|
+
unsafeBlockHeight: i === 0 ? unsafeBlockHeight : undefined
|
|
48
|
+
}).catch((error)=>{
|
|
49
|
+
throw new _shared.ResponseError(1, error.toString());
|
|
50
|
+
});
|
|
51
|
+
_logger.defaultLogger.debug({
|
|
52
|
+
hash: block.hash
|
|
53
|
+
}, 'dev_newBlock');
|
|
54
|
+
finalHash = block.hash;
|
|
55
|
+
}
|
|
56
|
+
return finalHash;
|
|
57
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BuildBlockMode } from '../../blockchain/txpool.js';
|
|
2
|
+
import { Context } from '../shared.js';
|
|
3
|
+
/**
|
|
4
|
+
* Set block build mode.
|
|
5
|
+
*
|
|
6
|
+
* 1 - Batch, 2 - Instant, 3 - Manual
|
|
7
|
+
*
|
|
8
|
+
* This function is a dev rpc handler. Use `dev_setBlockBuildMode` as the method name when calling it.
|
|
9
|
+
*
|
|
10
|
+
* @param context - The context object of the rpc handler
|
|
11
|
+
* @param params - The parameters of the rpc handler
|
|
12
|
+
*
|
|
13
|
+
* @example Set build block mode to instant
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
16
|
+
* import { BuildBlockMode } from '@acala-network/chopsticks-core'
|
|
17
|
+
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
18
|
+
* await ws.send('dev_setBlockBuildMode', [BuildBlockMode.Instant])
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare const dev_setBlockBuildMode: (context: Context, [mode]: [BuildBlockMode]) => Promise<void>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "dev_setBlockBuildMode", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return dev_setBlockBuildMode;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _txpool = require("../../blockchain/txpool.js");
|
|
12
|
+
const _shared = require("../shared.js");
|
|
13
|
+
const _logger = require("../../logger.js");
|
|
14
|
+
const dev_setBlockBuildMode = async (context, [mode])=>{
|
|
15
|
+
_logger.defaultLogger.debug({
|
|
16
|
+
mode: _txpool.BuildBlockMode[mode]
|
|
17
|
+
}, 'dev_setBlockBuildMode');
|
|
18
|
+
if (_txpool.BuildBlockMode[mode] === undefined) {
|
|
19
|
+
throw new _shared.ResponseError(1, `Invalid mode ${mode}`);
|
|
20
|
+
}
|
|
21
|
+
context.chain.txPool.mode = mode;
|
|
22
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Context } from '../shared.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
declare const schema: z.ZodUnion<[z.ZodIntersection<z.ZodString, z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>>, z.ZodNumber]>;
|
|
4
|
+
type Params = z.infer<typeof schema>;
|
|
5
|
+
/**
|
|
6
|
+
* Set head.
|
|
7
|
+
*
|
|
8
|
+
* This function is a dev rpc handler. Use `dev_setHead` as the method name when calling it.
|
|
9
|
+
*
|
|
10
|
+
* @param context - The context object of the rpc handler
|
|
11
|
+
* @param hashOrNumber - The block hash or number to set as head
|
|
12
|
+
*
|
|
13
|
+
* @example Set head to block 1000000
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
16
|
+
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
17
|
+
* await ws.send('dev_setHead', [1000000])
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare const dev_setHead: (context: Context, [params]: [Params]) => Promise<`0x${string}`>;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "dev_setHead", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return dev_setHead;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _shared = require("../shared.js");
|
|
12
|
+
const _zod = require("zod");
|
|
13
|
+
const schema = _shared.zHash.or(_zod.z.number());
|
|
14
|
+
const dev_setHead = async (context, [params])=>{
|
|
15
|
+
const hashOrNumber = schema.parse(params);
|
|
16
|
+
let block;
|
|
17
|
+
if (typeof hashOrNumber === 'number') {
|
|
18
|
+
const blockNumber = hashOrNumber > 0 ? hashOrNumber : context.chain.head.number + hashOrNumber;
|
|
19
|
+
block = await context.chain.getBlockAt(blockNumber);
|
|
20
|
+
} else {
|
|
21
|
+
block = await context.chain.getBlock(hashOrNumber);
|
|
22
|
+
}
|
|
23
|
+
if (!block) {
|
|
24
|
+
throw new _shared.ResponseError(1, `Block not found ${hashOrNumber}`);
|
|
25
|
+
}
|
|
26
|
+
await context.chain.setHead(block);
|
|
27
|
+
return block.hash;
|
|
28
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Context } from '../shared.js';
|
|
2
|
+
/**
|
|
3
|
+
* Set runtime log level.
|
|
4
|
+
*
|
|
5
|
+
* This function is a dev rpc handler. Use `dev_setRuntimeLogLevel` as the method name when calling it.
|
|
6
|
+
*
|
|
7
|
+
* @param context - The context object of the rpc handler
|
|
8
|
+
* @param runtimeLogLevel - The runtime log level to set
|
|
9
|
+
*
|
|
10
|
+
* @example Set runtime log level to 1
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
13
|
+
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
14
|
+
* await ws.send('dev_setRuntimeLogLevel', [1])
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare const dev_setRuntimeLogLevel: (context: Context, [runtimeLogLevel]: [number]) => Promise<void>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "dev_setRuntimeLogLevel", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return dev_setRuntimeLogLevel;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _shared = require("../shared.js");
|
|
12
|
+
const _logger = require("../../logger.js");
|
|
13
|
+
const dev_setRuntimeLogLevel = async (context, [runtimeLogLevel])=>{
|
|
14
|
+
_logger.defaultLogger.debug({
|
|
15
|
+
runtimeLogLevel
|
|
16
|
+
}, 'dev_setRuntimeLogLevel');
|
|
17
|
+
if (typeof runtimeLogLevel !== 'number') {
|
|
18
|
+
throw new _shared.ResponseError(1, `Invalid runtimeLogLevel ${runtimeLogLevel}`);
|
|
19
|
+
}
|
|
20
|
+
context.chain.runtimeLogLevel = runtimeLogLevel;
|
|
21
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Context } from '../shared.js';
|
|
2
|
+
import { HexString } from '@polkadot/util/types';
|
|
3
|
+
import { StorageValues } from '../../utils/set-storage.js';
|
|
4
|
+
/**
|
|
5
|
+
* Set storage values.
|
|
6
|
+
*
|
|
7
|
+
* This function is a dev rpc handler. Use `dev_setStorage` as the method name when calling it.
|
|
8
|
+
*
|
|
9
|
+
* @param context - The context object of the rpc handler
|
|
10
|
+
* @param params - The parameters of the rpc handler
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
15
|
+
* import { Keyring } from '@polkadot/keyring'
|
|
16
|
+
*
|
|
17
|
+
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
18
|
+
* const keyring = new Keyring({ type: 'ed25519' })
|
|
19
|
+
* const bob = keyring.addFromUri('//Bob')
|
|
20
|
+
*
|
|
21
|
+
* const storage = {
|
|
22
|
+
* System: {
|
|
23
|
+
* Account: [[[bob.address], { data: { free: 100000 }, nonce: 1 }]],
|
|
24
|
+
* },
|
|
25
|
+
* }
|
|
26
|
+
* await ws.send('dev_setStorage', [storage])
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare const dev_setStorage: (context: Context, params: [StorageValues, HexString?]) => Promise<`0x${string}`>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "dev_setStorage", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return dev_setStorage;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _shared = require("../shared.js");
|
|
12
|
+
const _setstorage = require("../../utils/set-storage.js");
|
|
13
|
+
const _logger = require("../../logger.js");
|
|
14
|
+
const dev_setStorage = async (context, params)=>{
|
|
15
|
+
const [values, blockHash] = params;
|
|
16
|
+
const hash = await (0, _setstorage.setStorage)(context.chain, values, blockHash).catch((error)=>{
|
|
17
|
+
throw new _shared.ResponseError(1, error.toString());
|
|
18
|
+
});
|
|
19
|
+
_logger.defaultLogger.debug({
|
|
20
|
+
hash,
|
|
21
|
+
values
|
|
22
|
+
}, 'dev_setStorage');
|
|
23
|
+
return hash;
|
|
24
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Context } from '../shared.js';
|
|
2
|
+
/**
|
|
3
|
+
* Travel to a specific time.
|
|
4
|
+
*
|
|
5
|
+
* This function is a dev rpc handler. Use `dev_timeTravel` as the method name when calling it.
|
|
6
|
+
*
|
|
7
|
+
* @param context - The context object of the rpc handler
|
|
8
|
+
* @param date - Timestamp or date string to set
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
13
|
+
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
14
|
+
* await ws.send('dev_timeTravel', ['Jan 1, 2023'])
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare const dev_timeTravel: (context: Context, [date]: [string | number]) => Promise<number>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "dev_timeTravel", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return dev_timeTravel;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _shared = require("../shared.js");
|
|
12
|
+
const _timetravel = require("../../utils/time-travel.js");
|
|
13
|
+
const dev_timeTravel = async (context, [date])=>{
|
|
14
|
+
const timestamp = typeof date === 'string' ? Date.parse(date) : date;
|
|
15
|
+
if (Number.isNaN(timestamp)) throw new _shared.ResponseError(1, 'Invalid date');
|
|
16
|
+
await (0, _timetravel.timeTravel)(context.chain, timestamp);
|
|
17
|
+
return timestamp;
|
|
18
|
+
};
|
package/dist/cjs/rpc/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Handlers } from './shared.js';
|
|
2
|
+
import dev from './dev/index.js';
|
|
3
|
+
import substrate from './substrate/index.js';
|
|
2
4
|
export declare const allHandlers: Handlers;
|
|
3
|
-
export {
|
|
5
|
+
export { substrate, dev };
|
|
4
6
|
export { ResponseError } from './shared.js';
|
|
5
7
|
export type { Context, SubscriptionManager, Handler, Handlers } from './shared.js';
|
package/dist/cjs/rpc/index.js
CHANGED
|
@@ -15,11 +15,15 @@ _export(exports, {
|
|
|
15
15
|
allHandlers: function() {
|
|
16
16
|
return allHandlers;
|
|
17
17
|
},
|
|
18
|
-
|
|
18
|
+
dev: function() {
|
|
19
19
|
return _index.default;
|
|
20
|
+
},
|
|
21
|
+
substrate: function() {
|
|
22
|
+
return _index1.default;
|
|
20
23
|
}
|
|
21
24
|
});
|
|
22
|
-
const _index = /*#__PURE__*/ _interop_require_default(require("./
|
|
25
|
+
const _index = /*#__PURE__*/ _interop_require_default(require("./dev/index.js"));
|
|
26
|
+
const _index1 = /*#__PURE__*/ _interop_require_default(require("./substrate/index.js"));
|
|
23
27
|
const _shared = require("./shared.js");
|
|
24
28
|
function _interop_require_default(obj) {
|
|
25
29
|
return obj && obj.__esModule ? obj : {
|
|
@@ -27,11 +31,10 @@ function _interop_require_default(obj) {
|
|
|
27
31
|
};
|
|
28
32
|
}
|
|
29
33
|
const allHandlers = {
|
|
34
|
+
..._index1.default,
|
|
30
35
|
..._index.default,
|
|
31
36
|
rpc_methods: async ()=>Promise.resolve({
|
|
32
37
|
version: 1,
|
|
33
|
-
methods:
|
|
34
|
-
...Object.keys(allHandlers)
|
|
35
|
-
]
|
|
38
|
+
methods: Object.keys(allHandlers).sort()
|
|
36
39
|
})
|
|
37
40
|
};
|
package/dist/cjs/rpc/shared.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
1
2
|
import { Blockchain } from '../blockchain/index.js';
|
|
2
3
|
export declare const logger: import("pino").default.Logger<never>;
|
|
4
|
+
export declare const zHex: z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>;
|
|
5
|
+
export declare const zHash: z.ZodIntersection<z.ZodString, z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>>;
|
|
3
6
|
export declare class ResponseError extends Error {
|
|
4
7
|
code: number;
|
|
5
8
|
constructor(code: number, message: string);
|
package/dist/cjs/rpc/shared.js
CHANGED
|
@@ -14,8 +14,15 @@ _export(exports, {
|
|
|
14
14
|
},
|
|
15
15
|
logger: function() {
|
|
16
16
|
return logger;
|
|
17
|
+
},
|
|
18
|
+
zHash: function() {
|
|
19
|
+
return zHash;
|
|
20
|
+
},
|
|
21
|
+
zHex: function() {
|
|
22
|
+
return zHex;
|
|
17
23
|
}
|
|
18
24
|
});
|
|
25
|
+
const _zod = require("zod");
|
|
19
26
|
const _logger = require("../logger.js");
|
|
20
27
|
function _define_property(obj, key, value) {
|
|
21
28
|
if (key in obj) {
|
|
@@ -33,6 +40,8 @@ function _define_property(obj, key, value) {
|
|
|
33
40
|
const logger = _logger.defaultLogger.child({
|
|
34
41
|
name: 'rpc'
|
|
35
42
|
});
|
|
43
|
+
const zHex = _zod.z.custom((val)=>/^0x\w+$/.test(val));
|
|
44
|
+
const zHash = _zod.z.string().length(66).and(zHex);
|
|
36
45
|
class ResponseError extends Error {
|
|
37
46
|
toJSON() {
|
|
38
47
|
return {
|