@acala-network/chopsticks 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/context.js +6 -1
- package/lib/plugins/dry-run/rpc.d.ts +1 -1
- package/lib/plugins/dry-run/rpc.js +3 -3
- package/lib/plugins/index.d.ts +1 -1
- package/lib/plugins/new-block/index.d.ts +1 -2
- package/lib/plugins/new-block/index.js +5 -2
- package/lib/plugins/set-block-build-mode/index.d.ts +1 -2
- package/lib/plugins/set-block-build-mode/index.js +1 -2
- package/lib/plugins/set-head/index.d.ts +1 -1
- package/lib/plugins/set-head/index.js +2 -2
- package/lib/plugins/set-runtime-log-level/index.d.ts +1 -1
- package/lib/plugins/set-runtime-log-level/index.js +2 -2
- package/lib/plugins/set-storage/index.d.ts +1 -2
- package/lib/plugins/set-storage/index.js +1 -2
- package/lib/plugins/time-travel/index.d.ts +1 -1
- package/lib/plugins/time-travel/index.js +1 -2
- package/lib/rpc/index.d.ts +1 -1
- package/lib/rpc/index.js +5 -9
- package/lib/server.d.ts +1 -1
- package/lib/server.js +12 -4
- package/lib/setup-with-server.js +2 -2
- package/lib/types.d.ts +2 -3
- package/lib/types.js +1 -1
- package/lib/utils/signFake.d.ts +2 -2
- package/lib/utils/signFake.js +1 -2
- package/package.json +2 -2
- package/lib/rpc/shared.d.ts +0 -27
- package/lib/rpc/shared.js +0 -20
- package/lib/rpc/substrate/author.d.ts +0 -28
- package/lib/rpc/substrate/author.js +0 -87
- package/lib/rpc/substrate/chain.d.ts +0 -44
- package/lib/rpc/substrate/chain.js +0 -95
- package/lib/rpc/substrate/index.d.ts +0 -65
- package/lib/rpc/substrate/index.js +0 -44
- package/lib/rpc/substrate/payment.d.ts +0 -16
- package/lib/rpc/substrate/payment.js +0 -45
- package/lib/rpc/substrate/state.d.ts +0 -97
- package/lib/rpc/substrate/state.js +0 -177
- package/lib/rpc/substrate/system.d.ts +0 -28
- package/lib/rpc/substrate/system.js +0 -68
package/lib/context.js
CHANGED
|
@@ -3,8 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.setupContext = void 0;
|
|
4
4
|
require("./utils/tunnel");
|
|
5
5
|
const entities_1 = require("@acala-network/chopsticks-core/db/entities");
|
|
6
|
-
const override_1 = require("./utils/override");
|
|
7
6
|
const chopsticks_core_1 = require("@acala-network/chopsticks-core");
|
|
7
|
+
const override_1 = require("./utils/override");
|
|
8
|
+
const logger = chopsticks_core_1.defaultLogger.child({ name: 'setup-context' });
|
|
8
9
|
const setupContext = async (argv, overrideParent = false) => {
|
|
9
10
|
const chain = await (0, chopsticks_core_1.setup)({
|
|
10
11
|
endpoint: argv.endpoint,
|
|
@@ -37,6 +38,10 @@ const setupContext = async (argv, overrideParent = false) => {
|
|
|
37
38
|
if (blockData) {
|
|
38
39
|
const block = await chain.loadBlockFromDB(blockData?.number);
|
|
39
40
|
block && (await chain.setHead(block));
|
|
41
|
+
logger.info(`Resume from block ${blockData.number}, hash: ${blockData.hash}`);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
throw new Error(`Resume failed. Cannot find block ${argv.resume}`);
|
|
40
45
|
}
|
|
41
46
|
}
|
|
42
47
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.rpc = exports.name = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
|
-
const
|
|
5
|
+
const chopsticks_core_1 = require("@acala-network/chopsticks-core");
|
|
6
6
|
const decoder_1 = require("../../utils/decoder");
|
|
7
7
|
const generate_html_diff_1 = require("../../utils/generate-html-diff");
|
|
8
8
|
const zHex = zod_1.z.custom((val) => /^0x\w+$/.test(val));
|
|
@@ -73,7 +73,7 @@ const rpc = async (context, [params]) => {
|
|
|
73
73
|
if (extrinsic) {
|
|
74
74
|
const { outcome, storageDiff } = await context.chain.dryRunExtrinsic(extrinsic, at);
|
|
75
75
|
if (outcome.isErr) {
|
|
76
|
-
throw new
|
|
76
|
+
throw new chopsticks_core_1.ResponseError(1, outcome.asErr.toString());
|
|
77
77
|
}
|
|
78
78
|
return storageDiff;
|
|
79
79
|
}
|
|
@@ -86,7 +86,7 @@ const rpc = async (context, [params]) => {
|
|
|
86
86
|
if (ump) {
|
|
87
87
|
return context.chain.dryRunUmp(ump, at);
|
|
88
88
|
}
|
|
89
|
-
throw new
|
|
89
|
+
throw new chopsticks_core_1.ResponseError(1, 'No extrinsic to run');
|
|
90
90
|
};
|
|
91
91
|
const storageDiff = await dryRun();
|
|
92
92
|
if (html) {
|
package/lib/plugins/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Context } from '
|
|
2
|
-
import { DownwardMessage, HorizontalMessage } from '@acala-network/chopsticks-core';
|
|
1
|
+
import { Context, DownwardMessage, HorizontalMessage } from '@acala-network/chopsticks-core';
|
|
3
2
|
import { HexString } from '@polkadot/util/types';
|
|
4
3
|
export interface NewBlockParams {
|
|
5
4
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.rpc = void 0;
|
|
4
|
-
const
|
|
4
|
+
const chopsticks_core_1 = require("@acala-network/chopsticks-core");
|
|
5
5
|
const logger_1 = require("../../logger");
|
|
6
6
|
/**
|
|
7
7
|
* Build new blocks.
|
|
@@ -48,6 +48,9 @@ const rpc = async (context, params) => {
|
|
|
48
48
|
const diff = to ? to - now : count;
|
|
49
49
|
const finalCount = diff > 0 ? diff : 1;
|
|
50
50
|
let finalHash;
|
|
51
|
+
if (unsafeBlockHeight < now) {
|
|
52
|
+
throw new chopsticks_core_1.ResponseError(1, 'unsafeBlockHeight must be greater than current block height');
|
|
53
|
+
}
|
|
51
54
|
for (let i = 0; i < finalCount; i++) {
|
|
52
55
|
const block = await context.chain
|
|
53
56
|
.newBlock({
|
|
@@ -58,7 +61,7 @@ const rpc = async (context, params) => {
|
|
|
58
61
|
unsafeBlockHeight: i === 0 ? unsafeBlockHeight : undefined,
|
|
59
62
|
})
|
|
60
63
|
.catch((error) => {
|
|
61
|
-
throw new
|
|
64
|
+
throw new chopsticks_core_1.ResponseError(1, error.toString());
|
|
62
65
|
});
|
|
63
66
|
logger_1.defaultLogger.debug({ hash: block.hash }, 'dev_newBlock');
|
|
64
67
|
finalHash = block.hash;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { BuildBlockMode } from '@acala-network/chopsticks-core';
|
|
2
|
-
import { Context } from '../../rpc/shared';
|
|
1
|
+
import { BuildBlockMode, Context } from '@acala-network/chopsticks-core';
|
|
3
2
|
/**
|
|
4
3
|
* Set a build block mode. See [BuildBlockMode](../core/enums/BuildBlockMode).
|
|
5
4
|
*
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.rpc = void 0;
|
|
4
4
|
const chopsticks_core_1 = require("@acala-network/chopsticks-core");
|
|
5
|
-
const shared_1 = require("../../rpc/shared");
|
|
6
5
|
const logger_1 = require("../../logger");
|
|
7
6
|
/**
|
|
8
7
|
* Set a build block mode. See [BuildBlockMode](../core/enums/BuildBlockMode).
|
|
@@ -23,7 +22,7 @@ const logger_1 = require("../../logger");
|
|
|
23
22
|
const rpc = async (context, [mode]) => {
|
|
24
23
|
logger_1.defaultLogger.debug({ mode }, 'dev_setBlockBuildMode');
|
|
25
24
|
if (chopsticks_core_1.BuildBlockMode[mode] === undefined) {
|
|
26
|
-
throw new
|
|
25
|
+
throw new chopsticks_core_1.ResponseError(1, `Invalid mode ${mode}`);
|
|
27
26
|
}
|
|
28
27
|
context.chain.txPool.mode = mode;
|
|
29
28
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.rpc = void 0;
|
|
4
|
-
const
|
|
4
|
+
const chopsticks_core_1 = require("@acala-network/chopsticks-core");
|
|
5
5
|
/**
|
|
6
6
|
* Set head.
|
|
7
7
|
*
|
|
@@ -27,7 +27,7 @@ const rpc = async (context, [hashOrNumber]) => {
|
|
|
27
27
|
block = await context.chain.getBlock(hashOrNumber);
|
|
28
28
|
}
|
|
29
29
|
if (!block) {
|
|
30
|
-
throw new
|
|
30
|
+
throw new chopsticks_core_1.ResponseError(1, `Block not found ${hashOrNumber}`);
|
|
31
31
|
}
|
|
32
32
|
await context.chain.setHead(block);
|
|
33
33
|
return block.hash;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.rpc = void 0;
|
|
4
|
-
const
|
|
4
|
+
const chopsticks_core_1 = require("@acala-network/chopsticks-core");
|
|
5
5
|
const logger_1 = require("../../logger");
|
|
6
6
|
/**
|
|
7
7
|
* Set runtime log level.
|
|
@@ -21,7 +21,7 @@ const logger_1 = require("../../logger");
|
|
|
21
21
|
const rpc = async (context, [runtimeLogLevel]) => {
|
|
22
22
|
logger_1.defaultLogger.debug({ runtimeLogLevel }, 'dev_setRuntimeLogLevel');
|
|
23
23
|
if (typeof runtimeLogLevel !== 'number') {
|
|
24
|
-
throw new
|
|
24
|
+
throw new chopsticks_core_1.ResponseError(1, `Invalid runtimeLogLevel ${runtimeLogLevel}`);
|
|
25
25
|
}
|
|
26
26
|
context.chain.runtimeLogLevel = runtimeLogLevel;
|
|
27
27
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
+
import { Context, StorageValues } from '@acala-network/chopsticks-core';
|
|
1
2
|
import { HexString } from '@polkadot/util/types';
|
|
2
|
-
import { Context } from '../../rpc/shared';
|
|
3
|
-
import { StorageValues } from '@acala-network/chopsticks-core';
|
|
4
3
|
/**
|
|
5
4
|
* Set storage values.
|
|
6
5
|
*
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.rpc = void 0;
|
|
4
|
-
const shared_1 = require("../../rpc/shared");
|
|
5
4
|
const chopsticks_core_1 = require("@acala-network/chopsticks-core");
|
|
6
5
|
const logger_1 = require("../../logger");
|
|
7
6
|
/**
|
|
@@ -32,7 +31,7 @@ const logger_1 = require("../../logger");
|
|
|
32
31
|
const rpc = async (context, params) => {
|
|
33
32
|
const [values, blockHash] = params;
|
|
34
33
|
const hash = await (0, chopsticks_core_1.setStorage)(context.chain, values, blockHash).catch((error) => {
|
|
35
|
-
throw new
|
|
34
|
+
throw new chopsticks_core_1.ResponseError(1, error.toString());
|
|
36
35
|
});
|
|
37
36
|
logger_1.defaultLogger.debug({
|
|
38
37
|
hash,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.rpc = void 0;
|
|
4
|
-
const shared_1 = require("../../rpc/shared");
|
|
5
4
|
const chopsticks_core_1 = require("@acala-network/chopsticks-core");
|
|
6
5
|
/**
|
|
7
6
|
* Travel to a specific time.
|
|
@@ -21,7 +20,7 @@ const chopsticks_core_1 = require("@acala-network/chopsticks-core");
|
|
|
21
20
|
const rpc = async (context, [date]) => {
|
|
22
21
|
const timestamp = typeof date === 'string' ? Date.parse(date) : date;
|
|
23
22
|
if (Number.isNaN(timestamp))
|
|
24
|
-
throw new
|
|
23
|
+
throw new chopsticks_core_1.ResponseError(1, 'Invalid date');
|
|
25
24
|
await (0, chopsticks_core_1.timeTravel)(context.chain, timestamp);
|
|
26
25
|
return timestamp;
|
|
27
26
|
};
|
package/lib/rpc/index.d.ts
CHANGED
package/lib/rpc/index.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.handler = void 0;
|
|
7
|
-
const
|
|
4
|
+
const chopsticks_core_1 = require("@acala-network/chopsticks-core");
|
|
8
5
|
const plugins_1 = require("../plugins");
|
|
9
|
-
const substrate_1 = __importDefault(require("./substrate"));
|
|
10
6
|
const allHandlers = {
|
|
11
|
-
...
|
|
7
|
+
...chopsticks_core_1.substrate,
|
|
12
8
|
rpc_methods: async () => Promise.resolve({
|
|
13
9
|
version: 1,
|
|
14
10
|
methods: [...Object.keys(allHandlers), ...Object.keys(plugins_1.pluginHandlers)],
|
|
@@ -23,11 +19,11 @@ const getHandler = (method) => {
|
|
|
23
19
|
return handler;
|
|
24
20
|
};
|
|
25
21
|
const handler = (context) => ({ method, params }, subscriptionManager) => {
|
|
26
|
-
|
|
22
|
+
chopsticks_core_1.logger.trace('Handling %s', method);
|
|
27
23
|
const handler = getHandler(method);
|
|
28
24
|
if (!handler) {
|
|
29
|
-
|
|
30
|
-
throw new
|
|
25
|
+
chopsticks_core_1.logger.warn('Method not found %s', method);
|
|
26
|
+
throw new chopsticks_core_1.ResponseError(-32601, `Method not found: ${method}`);
|
|
31
27
|
}
|
|
32
28
|
return handler(context, params, subscriptionManager);
|
|
33
29
|
};
|
package/lib/server.d.ts
CHANGED
package/lib/server.js
CHANGED
|
@@ -24,10 +24,17 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.createServer = void 0;
|
|
27
|
+
const chopsticks_core_1 = require("@acala-network/chopsticks-core");
|
|
28
|
+
const zod_1 = require("zod");
|
|
27
29
|
const ws_1 = __importStar(require("ws"));
|
|
28
|
-
const shared_1 = require("./rpc/shared");
|
|
29
30
|
const logger_1 = require("./logger");
|
|
30
31
|
const logger = logger_1.defaultLogger.child({ name: 'ws' });
|
|
32
|
+
const requestSchema = zod_1.z.object({
|
|
33
|
+
id: zod_1.z.number(),
|
|
34
|
+
jsonrpc: zod_1.z.literal('2.0'),
|
|
35
|
+
method: zod_1.z.string(),
|
|
36
|
+
params: zod_1.z.array(zod_1.z.any()).default([]),
|
|
37
|
+
});
|
|
31
38
|
const parseRequest = (request) => {
|
|
32
39
|
try {
|
|
33
40
|
return JSON.parse(request);
|
|
@@ -111,8 +118,8 @@ const createServer = async (handler, port) => {
|
|
|
111
118
|
ws.removeAllListeners();
|
|
112
119
|
});
|
|
113
120
|
ws.on('message', async (message) => {
|
|
114
|
-
const
|
|
115
|
-
if (!
|
|
121
|
+
const parsed = await requestSchema.safeParseAsync(parseRequest(message.toString()));
|
|
122
|
+
if (!parsed.success) {
|
|
116
123
|
logger.info('Invalid request: %s', message);
|
|
117
124
|
send({
|
|
118
125
|
id: null,
|
|
@@ -124,6 +131,7 @@ const createServer = async (handler, port) => {
|
|
|
124
131
|
});
|
|
125
132
|
return;
|
|
126
133
|
}
|
|
134
|
+
const { data: req } = parsed;
|
|
127
135
|
logger.trace({
|
|
128
136
|
id: req.id,
|
|
129
137
|
method: req.method,
|
|
@@ -146,7 +154,7 @@ const createServer = async (handler, port) => {
|
|
|
146
154
|
send({
|
|
147
155
|
id: req.id,
|
|
148
156
|
jsonrpc: '2.0',
|
|
149
|
-
error: e instanceof
|
|
157
|
+
error: e instanceof chopsticks_core_1.ResponseError ? e : { code: -32603, message: `Internal ${e}` },
|
|
150
158
|
});
|
|
151
159
|
}
|
|
152
160
|
});
|
package/lib/setup-with-server.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.setupWithServer = void 0;
|
|
4
4
|
const server_1 = require("./server");
|
|
5
5
|
const rpc_1 = require("./rpc");
|
|
6
|
-
const
|
|
6
|
+
const chopsticks_core_1 = require("@acala-network/chopsticks-core");
|
|
7
7
|
const context_1 = require("./context");
|
|
8
8
|
const setupWithServer = async (argv) => {
|
|
9
9
|
const context = await (0, context_1.setupContext)(argv);
|
|
@@ -13,7 +13,7 @@ const setupWithServer = async (argv) => {
|
|
|
13
13
|
await context.chain.newBlock();
|
|
14
14
|
}
|
|
15
15
|
const { close, port: listenPort } = await (0, server_1.createServer)((0, rpc_1.handler)(context), port);
|
|
16
|
-
|
|
16
|
+
chopsticks_core_1.logger.info(`${await context.chain.api.getSystemChain()} RPC listening on port ${listenPort}`);
|
|
17
17
|
return {
|
|
18
18
|
...context,
|
|
19
19
|
listenPort,
|
package/lib/types.d.ts
CHANGED
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
*
|
|
11
11
|
* @packageDocumentation
|
|
12
12
|
*/
|
|
13
|
-
export { ChainProperties, RuntimeVersion } from '@acala-network/chopsticks-core';
|
|
13
|
+
export type { ChainProperties, RuntimeVersion, Context, SubscriptionManager, Handler, } from '@acala-network/chopsticks-core';
|
|
14
|
+
export * from '@acala-network/chopsticks-core/src/rpc/substrate';
|
|
14
15
|
export * from './plugins/types';
|
|
15
|
-
export * from './rpc/substrate';
|
|
16
|
-
export { Context, SubscriptionManager, Handler } from './rpc/shared';
|
package/lib/types.js
CHANGED
|
@@ -14,5 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("@acala-network/chopsticks-core/src/rpc/substrate"), exports);
|
|
17
18
|
__exportStar(require("./plugins/types"), exports);
|
|
18
|
-
__exportStar(require("./rpc/substrate"), exports);
|
package/lib/utils/signFake.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ import { ApiPromise } from '@polkadot/api';
|
|
|
2
2
|
import { GenericExtrinsic } from '@polkadot/types';
|
|
3
3
|
import { SignatureOptions } from '@polkadot/types/types';
|
|
4
4
|
export type SignFakeOptions = Partial<SignatureOptions>;
|
|
5
|
-
export declare const signFakeWithApi: (api: ApiPromise, tx: GenericExtrinsic, addr: string, options?: SignFakeOptions) => Promise<
|
|
6
|
-
export declare const signFake: (tx: GenericExtrinsic, addr: string, options: SignatureOptions) =>
|
|
5
|
+
export declare const signFakeWithApi: (api: ApiPromise, tx: GenericExtrinsic, addr: string, options?: SignFakeOptions) => Promise<void>;
|
|
6
|
+
export declare const signFake: (tx: GenericExtrinsic, addr: string, options: SignatureOptions) => void;
|
package/lib/utils/signFake.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.signFake = exports.signFakeWithApi = void 0;
|
|
4
4
|
const signFakeWithApi = async (api, tx, addr, options = {}) => {
|
|
5
5
|
const nonce = options.nonce ?? (await api.query.system.account(addr)).nonce;
|
|
6
|
-
|
|
6
|
+
(0, exports.signFake)(tx, addr, {
|
|
7
7
|
nonce,
|
|
8
8
|
genesisHash: api.genesisHash,
|
|
9
9
|
runtimeVersion: api.runtimeVersion,
|
|
@@ -18,6 +18,5 @@ const signFake = (tx, addr, options) => {
|
|
|
18
18
|
mockSignature.set([0xde, 0xad, 0xbe, 0xef]);
|
|
19
19
|
tx.signFake(addr, options);
|
|
20
20
|
tx.signature.set(mockSignature);
|
|
21
|
-
return tx;
|
|
22
21
|
};
|
|
23
22
|
exports.signFake = signFake;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acala-network/chopsticks",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.4",
|
|
4
4
|
"author": "Acala Developers <hello@acala.network>",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"bin": "./chopsticks.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"docs:prep": "typedoc"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@acala-network/chopsticks-core": "0.8.
|
|
20
|
+
"@acala-network/chopsticks-core": "0.8.4",
|
|
21
21
|
"@pnpm/npm-conf": "^2.2.2",
|
|
22
22
|
"@polkadot/api": "^10.9.1",
|
|
23
23
|
"axios": "^1.5.1",
|
package/lib/rpc/shared.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Blockchain } from '@acala-network/chopsticks-core';
|
|
2
|
-
export declare const logger: import("pino").default.Logger<{
|
|
3
|
-
level: string;
|
|
4
|
-
transport: {
|
|
5
|
-
target: string;
|
|
6
|
-
};
|
|
7
|
-
}>;
|
|
8
|
-
export declare class ResponseError extends Error {
|
|
9
|
-
code: number;
|
|
10
|
-
constructor(code: number, message: string);
|
|
11
|
-
toJSON(): {
|
|
12
|
-
code: number;
|
|
13
|
-
message: string;
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
export interface Context {
|
|
17
|
-
/**
|
|
18
|
-
* The blockchain instance, see `Blockchain` type in the `core` package
|
|
19
|
-
*/
|
|
20
|
-
chain: Blockchain;
|
|
21
|
-
}
|
|
22
|
-
export interface SubscriptionManager {
|
|
23
|
-
subscribe: (method: string, subid: string, onCancel?: () => void) => (data: any) => void;
|
|
24
|
-
unsubscribe: (subid: string) => void;
|
|
25
|
-
}
|
|
26
|
-
export type Handler<TParams = any, TReturn = any> = (context: Context, params: TParams, subscriptionManager: SubscriptionManager) => Promise<TReturn>;
|
|
27
|
-
export type Handlers = Record<string, Handler>;
|
package/lib/rpc/shared.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ResponseError = exports.logger = void 0;
|
|
4
|
-
const logger_1 = require("../logger");
|
|
5
|
-
exports.logger = logger_1.defaultLogger.child({ name: 'rpc' });
|
|
6
|
-
class ResponseError extends Error {
|
|
7
|
-
code;
|
|
8
|
-
constructor(code, message) {
|
|
9
|
-
super(message);
|
|
10
|
-
this.name = 'ResponseError';
|
|
11
|
-
this.code = code;
|
|
12
|
-
}
|
|
13
|
-
toJSON() {
|
|
14
|
-
return {
|
|
15
|
-
code: this.code,
|
|
16
|
-
message: this.message,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
exports.ResponseError = ResponseError;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { HexString } from '@polkadot/util/types';
|
|
2
|
-
import { Handler } from '../shared';
|
|
3
|
-
/**
|
|
4
|
-
* @param context
|
|
5
|
-
* @param params - [`extrinsic`]
|
|
6
|
-
*
|
|
7
|
-
* @return Hash
|
|
8
|
-
*/
|
|
9
|
-
export declare const author_submitExtrinsic: Handler<[HexString], HexString>;
|
|
10
|
-
/**
|
|
11
|
-
* @param context
|
|
12
|
-
* @param params - [`extrinsic`]
|
|
13
|
-
* @param subscriptionManager
|
|
14
|
-
*
|
|
15
|
-
* @return subscription id
|
|
16
|
-
*/
|
|
17
|
-
export declare const author_submitAndWatchExtrinsic: Handler<[HexString], string>;
|
|
18
|
-
/**
|
|
19
|
-
* @param _context
|
|
20
|
-
* @param params - [`subid`]
|
|
21
|
-
*/
|
|
22
|
-
export declare const author_unwatchExtrinsic: Handler<[string], void>;
|
|
23
|
-
/**
|
|
24
|
-
* Get pending extrinsics
|
|
25
|
-
*
|
|
26
|
-
* @return Array of pending extrinsics
|
|
27
|
-
*/
|
|
28
|
-
export declare const author_pendingExtrinsics: Handler<void, HexString[]>;
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.author_pendingExtrinsics = exports.author_unwatchExtrinsic = exports.author_submitAndWatchExtrinsic = exports.author_submitExtrinsic = void 0;
|
|
4
|
-
const chopsticks_core_1 = require("@acala-network/chopsticks-core");
|
|
5
|
-
const shared_1 = require("../shared");
|
|
6
|
-
const logger_1 = require("../../logger");
|
|
7
|
-
const logger = logger_1.defaultLogger.child({ name: 'rpc-author' });
|
|
8
|
-
/**
|
|
9
|
-
* @param context
|
|
10
|
-
* @param params - [`extrinsic`]
|
|
11
|
-
*
|
|
12
|
-
* @return Hash
|
|
13
|
-
*/
|
|
14
|
-
const author_submitExtrinsic = async (context, [extrinsic]) => {
|
|
15
|
-
return context.chain.submitExtrinsic(extrinsic).catch((error) => {
|
|
16
|
-
const code = error.isInvalid ? 1010 : 1011;
|
|
17
|
-
throw new shared_1.ResponseError(code, error.toString());
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
exports.author_submitExtrinsic = author_submitExtrinsic;
|
|
21
|
-
/**
|
|
22
|
-
* @param context
|
|
23
|
-
* @param params - [`extrinsic`]
|
|
24
|
-
* @param subscriptionManager
|
|
25
|
-
*
|
|
26
|
-
* @return subscription id
|
|
27
|
-
*/
|
|
28
|
-
const author_submitAndWatchExtrinsic = async (context, [extrinsic], { subscribe, unsubscribe }) => {
|
|
29
|
-
let update = (_block) => { };
|
|
30
|
-
const id = context.chain.headState.subscribeHead((block) => update(block));
|
|
31
|
-
const callback = subscribe('author_extrinsicUpdate', id, () => context.chain.headState.unsubscribeHead(id));
|
|
32
|
-
const onExtrinsicFail = ([failedExtrinsic, error]) => {
|
|
33
|
-
if (failedExtrinsic === extrinsic) {
|
|
34
|
-
callback(error.toJSON());
|
|
35
|
-
done(id);
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
context.chain.txPool.event.on(chopsticks_core_1.APPLY_EXTRINSIC_ERROR, onExtrinsicFail);
|
|
39
|
-
const done = (id) => {
|
|
40
|
-
context.chain.txPool.event.removeListener(chopsticks_core_1.APPLY_EXTRINSIC_ERROR, onExtrinsicFail);
|
|
41
|
-
unsubscribe(id);
|
|
42
|
-
};
|
|
43
|
-
update = async (block) => {
|
|
44
|
-
const extrisnics = await block.extrinsics;
|
|
45
|
-
if (!extrisnics.includes(extrinsic))
|
|
46
|
-
return;
|
|
47
|
-
logger.debug({ block: block.hash }, 'author_extrinsicUpdate');
|
|
48
|
-
callback({
|
|
49
|
-
inBlock: block.hash,
|
|
50
|
-
});
|
|
51
|
-
callback({
|
|
52
|
-
finalized: block.hash,
|
|
53
|
-
});
|
|
54
|
-
done(id);
|
|
55
|
-
};
|
|
56
|
-
try {
|
|
57
|
-
await context.chain.submitExtrinsic(extrinsic);
|
|
58
|
-
callback({
|
|
59
|
-
ready: null,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
catch (error) {
|
|
63
|
-
logger.error({ error }, 'ExtrinsicFailed');
|
|
64
|
-
const code = error.isInvalid ? 1010 : 1011;
|
|
65
|
-
done(id);
|
|
66
|
-
throw new shared_1.ResponseError(code, error.toString());
|
|
67
|
-
}
|
|
68
|
-
return id;
|
|
69
|
-
};
|
|
70
|
-
exports.author_submitAndWatchExtrinsic = author_submitAndWatchExtrinsic;
|
|
71
|
-
/**
|
|
72
|
-
* @param _context
|
|
73
|
-
* @param params - [`subid`]
|
|
74
|
-
*/
|
|
75
|
-
const author_unwatchExtrinsic = async (_context, [subid], { unsubscribe }) => {
|
|
76
|
-
unsubscribe(subid);
|
|
77
|
-
};
|
|
78
|
-
exports.author_unwatchExtrinsic = author_unwatchExtrinsic;
|
|
79
|
-
/**
|
|
80
|
-
* Get pending extrinsics
|
|
81
|
-
*
|
|
82
|
-
* @return Array of pending extrinsics
|
|
83
|
-
*/
|
|
84
|
-
const author_pendingExtrinsics = async (context) => {
|
|
85
|
-
return context.chain.txPool.pendingExtrinsics;
|
|
86
|
-
};
|
|
87
|
-
exports.author_pendingExtrinsics = author_pendingExtrinsics;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { Header } from '@polkadot/types/interfaces';
|
|
2
|
-
import { HexString } from '@polkadot/util/types';
|
|
3
|
-
import { Handler } from '../shared';
|
|
4
|
-
/**
|
|
5
|
-
* @param context
|
|
6
|
-
* @param params - [`blockNumber`]
|
|
7
|
-
*
|
|
8
|
-
* @return Block hash
|
|
9
|
-
*/
|
|
10
|
-
export declare const chain_getBlockHash: Handler<[number], HexString>;
|
|
11
|
-
/**
|
|
12
|
-
* @param context
|
|
13
|
-
* @param params - [`blockhash`]
|
|
14
|
-
*
|
|
15
|
-
* @return Header - see `@polkadot/types/interfaces`
|
|
16
|
-
*/
|
|
17
|
-
export declare const chain_getHeader: Handler<[HexString], Header>;
|
|
18
|
-
/**
|
|
19
|
-
* @param context
|
|
20
|
-
* @param params - [`blockhash`]
|
|
21
|
-
*
|
|
22
|
-
* @return Block header and extrinsics
|
|
23
|
-
*/
|
|
24
|
-
export declare const chain_getBlock: Handler<[
|
|
25
|
-
HexString
|
|
26
|
-
], {
|
|
27
|
-
block: {
|
|
28
|
-
header: Header;
|
|
29
|
-
extrinsics: HexString[];
|
|
30
|
-
};
|
|
31
|
-
justifications: null;
|
|
32
|
-
}>;
|
|
33
|
-
/**
|
|
34
|
-
* @param context
|
|
35
|
-
*
|
|
36
|
-
* @return head hash
|
|
37
|
-
*/
|
|
38
|
-
export declare const chain_getFinalizedHead: Handler<void, HexString>;
|
|
39
|
-
export declare const chain_subscribeNewHead: Handler<void, string>;
|
|
40
|
-
export declare const chain_subscribeFinalizedHeads: Handler<void, string>;
|
|
41
|
-
export declare const chain_unsubscribeNewHead: Handler<[string], void>;
|
|
42
|
-
export declare const chain_subscribeNewHeads: Handler<void, string>;
|
|
43
|
-
export declare const chain_unsubscribeNewHeads: Handler<[string], void>;
|
|
44
|
-
export declare const chain_unsubscribeFinalizedHeads: Handler<[string], void>;
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.chain_unsubscribeFinalizedHeads = exports.chain_unsubscribeNewHeads = exports.chain_subscribeNewHeads = exports.chain_unsubscribeNewHead = exports.chain_subscribeFinalizedHeads = exports.chain_subscribeNewHead = exports.chain_getFinalizedHead = exports.chain_getBlock = exports.chain_getHeader = exports.chain_getBlockHash = void 0;
|
|
4
|
-
const shared_1 = require("../shared");
|
|
5
|
-
const processHeader = (header) => {
|
|
6
|
-
const res = header.toJSON();
|
|
7
|
-
res.number = '0x' + res.number.toString(16); // number is hex format
|
|
8
|
-
return res;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* @param context
|
|
12
|
-
* @param params - [`blockNumber`]
|
|
13
|
-
*
|
|
14
|
-
* @return Block hash
|
|
15
|
-
*/
|
|
16
|
-
const chain_getBlockHash = async (context, [blockNumber]) => {
|
|
17
|
-
const block = await context.chain.getBlockAt(blockNumber);
|
|
18
|
-
if (!block) {
|
|
19
|
-
throw new shared_1.ResponseError(1, `Block #${blockNumber} not found`);
|
|
20
|
-
}
|
|
21
|
-
return block.hash;
|
|
22
|
-
};
|
|
23
|
-
exports.chain_getBlockHash = chain_getBlockHash;
|
|
24
|
-
/**
|
|
25
|
-
* @param context
|
|
26
|
-
* @param params - [`blockhash`]
|
|
27
|
-
*
|
|
28
|
-
* @return Header - see `@polkadot/types/interfaces`
|
|
29
|
-
*/
|
|
30
|
-
const chain_getHeader = async (context, [hash]) => {
|
|
31
|
-
const block = await context.chain.getBlock(hash);
|
|
32
|
-
if (!block) {
|
|
33
|
-
throw new shared_1.ResponseError(1, `Block ${hash} not found`);
|
|
34
|
-
}
|
|
35
|
-
return processHeader(await block.header);
|
|
36
|
-
};
|
|
37
|
-
exports.chain_getHeader = chain_getHeader;
|
|
38
|
-
/**
|
|
39
|
-
* @param context
|
|
40
|
-
* @param params - [`blockhash`]
|
|
41
|
-
*
|
|
42
|
-
* @return Block header and extrinsics
|
|
43
|
-
*/
|
|
44
|
-
const chain_getBlock = async (context, [hash]) => {
|
|
45
|
-
const block = await context.chain.getBlock(hash);
|
|
46
|
-
if (!block) {
|
|
47
|
-
throw new shared_1.ResponseError(1, `Block ${hash} not found`);
|
|
48
|
-
}
|
|
49
|
-
return {
|
|
50
|
-
block: {
|
|
51
|
-
header: await block.header,
|
|
52
|
-
extrinsics: await block.extrinsics,
|
|
53
|
-
},
|
|
54
|
-
justifications: null,
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
exports.chain_getBlock = chain_getBlock;
|
|
58
|
-
/**
|
|
59
|
-
* @param context
|
|
60
|
-
*
|
|
61
|
-
* @return head hash
|
|
62
|
-
*/
|
|
63
|
-
const chain_getFinalizedHead = async (context) => {
|
|
64
|
-
return context.chain.head.hash;
|
|
65
|
-
};
|
|
66
|
-
exports.chain_getFinalizedHead = chain_getFinalizedHead;
|
|
67
|
-
const chain_subscribeNewHead = async (context, _params, { subscribe }) => {
|
|
68
|
-
let update = () => { };
|
|
69
|
-
const id = context.chain.headState.subscribeHead(() => update());
|
|
70
|
-
const callback = subscribe('chain_newHead', id, () => context.chain.headState.unsubscribeHead(id));
|
|
71
|
-
update = async () => {
|
|
72
|
-
callback(processHeader(await context.chain.head.header));
|
|
73
|
-
};
|
|
74
|
-
update();
|
|
75
|
-
return id;
|
|
76
|
-
};
|
|
77
|
-
exports.chain_subscribeNewHead = chain_subscribeNewHead;
|
|
78
|
-
const chain_subscribeFinalizedHeads = async (context, _params, { subscribe }) => {
|
|
79
|
-
let update = () => { };
|
|
80
|
-
const id = context.chain.headState.subscribeHead(() => update());
|
|
81
|
-
const callback = subscribe('chain_finalizedHead', id, () => context.chain.headState.unsubscribeHead(id));
|
|
82
|
-
update = async () => {
|
|
83
|
-
callback(processHeader(await context.chain.head.header));
|
|
84
|
-
};
|
|
85
|
-
update();
|
|
86
|
-
return id;
|
|
87
|
-
};
|
|
88
|
-
exports.chain_subscribeFinalizedHeads = chain_subscribeFinalizedHeads;
|
|
89
|
-
const chain_unsubscribeNewHead = async (_context, [subid], { unsubscribe }) => {
|
|
90
|
-
unsubscribe(subid);
|
|
91
|
-
};
|
|
92
|
-
exports.chain_unsubscribeNewHead = chain_unsubscribeNewHead;
|
|
93
|
-
exports.chain_subscribeNewHeads = exports.chain_subscribeNewHead;
|
|
94
|
-
exports.chain_unsubscribeNewHeads = exports.chain_unsubscribeNewHead;
|
|
95
|
-
exports.chain_unsubscribeFinalizedHeads = exports.chain_unsubscribeNewHead;
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import * as AuthorRPC from './author';
|
|
2
|
-
import * as ChainRPC from './chain';
|
|
3
|
-
import * as PaymentRPC from './payment';
|
|
4
|
-
import * as StateRPC from './state';
|
|
5
|
-
import * as SystemRPC from './system';
|
|
6
|
-
export { AuthorRPC };
|
|
7
|
-
export { ChainRPC };
|
|
8
|
-
export { PaymentRPC };
|
|
9
|
-
export { StateRPC };
|
|
10
|
-
export { SystemRPC };
|
|
11
|
-
declare const handlers: {
|
|
12
|
-
system_localPeerId: () => Promise<string>;
|
|
13
|
-
system_nodeRoles: () => Promise<string[]>;
|
|
14
|
-
system_localListenAddresses: () => Promise<never[]>;
|
|
15
|
-
system_chain: import("../shared").Handler<void, string>;
|
|
16
|
-
system_properties: import("../shared").Handler<void, import("@acala-network/chopsticks-core").ChainProperties>;
|
|
17
|
-
system_name: import("../shared").Handler<void, string>;
|
|
18
|
-
system_version: import("../shared").Handler<void, string>;
|
|
19
|
-
system_chainType: import("../shared").Handler<void, string>;
|
|
20
|
-
system_health: () => Promise<{
|
|
21
|
-
peers: number;
|
|
22
|
-
isSyncing: boolean;
|
|
23
|
-
shouldHavePeers: boolean;
|
|
24
|
-
}>;
|
|
25
|
-
system_dryRun: import("../shared").Handler<[`0x${string}`, `0x${string}`], string>;
|
|
26
|
-
system_accountNextIndex: import("../shared").Handler<[`0x${string}`], number>;
|
|
27
|
-
state_getRuntimeVersion: import("../shared").Handler<[`0x${string}`], import("@acala-network/chopsticks-core").RuntimeVersion | undefined>;
|
|
28
|
-
state_getMetadata: import("../shared").Handler<[`0x${string}`], `0x${string}` | undefined>;
|
|
29
|
-
state_getStorage: import("../shared").Handler<[`0x${string}`, `0x${string}`], string | undefined>;
|
|
30
|
-
state_getKeysPaged: import("../shared").Handler<[string, number, string, `0x${string}`], string[] | undefined>;
|
|
31
|
-
state_queryStorageAt: import("../shared").Handler<[string[], `0x${string}`], [] | [{
|
|
32
|
-
block: `0x${string}`;
|
|
33
|
-
changes: (string | undefined)[][];
|
|
34
|
-
}]>;
|
|
35
|
-
state_call: import("../shared").Handler<[`0x${string}`, `0x${string}`, `0x${string}`], `0x${string}`>;
|
|
36
|
-
state_subscribeRuntimeVersion: import("../shared").Handler<[], string>;
|
|
37
|
-
state_unsubscribeRuntimeVersion: import("../shared").Handler<[`0x${string}`], void>;
|
|
38
|
-
state_subscribeStorage: import("../shared").Handler<[string[]], string>;
|
|
39
|
-
state_unsubscribeStorage: import("../shared").Handler<[string], void>;
|
|
40
|
-
childstate_getStorage: import("../shared").Handler<[`0x${string}`, `0x${string}`, `0x${string}`], string | undefined>;
|
|
41
|
-
childstate_getKeysPaged: import("../shared").Handler<[`0x${string}`, `0x${string}`, number, `0x${string}`, `0x${string}`], `0x${string}`[] | undefined>;
|
|
42
|
-
payment_queryFeeDetails: import("../shared").Handler<[`0x${string}`, `0x${string}`], `0x${string}`>;
|
|
43
|
-
payment_queryInfo: import("../shared").Handler<[`0x${string}`, `0x${string}`], `0x${string}`>;
|
|
44
|
-
chain_getBlockHash: import("../shared").Handler<[number], `0x${string}`>;
|
|
45
|
-
chain_getHeader: import("../shared").Handler<[`0x${string}`], import("@polkadot/types/interfaces").Header>;
|
|
46
|
-
chain_getBlock: import("../shared").Handler<[`0x${string}`], {
|
|
47
|
-
block: {
|
|
48
|
-
header: import("@polkadot/types/interfaces").Header;
|
|
49
|
-
extrinsics: `0x${string}`[];
|
|
50
|
-
};
|
|
51
|
-
justifications: null;
|
|
52
|
-
}>;
|
|
53
|
-
chain_getFinalizedHead: import("../shared").Handler<void, `0x${string}`>;
|
|
54
|
-
chain_subscribeNewHead: import("../shared").Handler<void, string>;
|
|
55
|
-
chain_subscribeFinalizedHeads: import("../shared").Handler<void, string>;
|
|
56
|
-
chain_unsubscribeNewHead: import("../shared").Handler<[string], void>;
|
|
57
|
-
chain_subscribeNewHeads: import("../shared").Handler<void, string>;
|
|
58
|
-
chain_unsubscribeNewHeads: import("../shared").Handler<[string], void>;
|
|
59
|
-
chain_unsubscribeFinalizedHeads: import("../shared").Handler<[string], void>;
|
|
60
|
-
author_submitExtrinsic: import("../shared").Handler<[`0x${string}`], `0x${string}`>;
|
|
61
|
-
author_submitAndWatchExtrinsic: import("../shared").Handler<[`0x${string}`], string>;
|
|
62
|
-
author_unwatchExtrinsic: import("../shared").Handler<[string], void>;
|
|
63
|
-
author_pendingExtrinsics: import("../shared").Handler<void, `0x${string}`[]>;
|
|
64
|
-
};
|
|
65
|
-
export default handlers;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.SystemRPC = exports.StateRPC = exports.PaymentRPC = exports.ChainRPC = exports.AuthorRPC = void 0;
|
|
27
|
-
const AuthorRPC = __importStar(require("./author"));
|
|
28
|
-
exports.AuthorRPC = AuthorRPC;
|
|
29
|
-
const ChainRPC = __importStar(require("./chain"));
|
|
30
|
-
exports.ChainRPC = ChainRPC;
|
|
31
|
-
const PaymentRPC = __importStar(require("./payment"));
|
|
32
|
-
exports.PaymentRPC = PaymentRPC;
|
|
33
|
-
const StateRPC = __importStar(require("./state"));
|
|
34
|
-
exports.StateRPC = StateRPC;
|
|
35
|
-
const SystemRPC = __importStar(require("./system"));
|
|
36
|
-
exports.SystemRPC = SystemRPC;
|
|
37
|
-
const handlers = {
|
|
38
|
-
...AuthorRPC,
|
|
39
|
-
...ChainRPC,
|
|
40
|
-
...PaymentRPC,
|
|
41
|
-
...StateRPC,
|
|
42
|
-
...SystemRPC,
|
|
43
|
-
};
|
|
44
|
-
exports.default = handlers;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { HexString } from '@polkadot/util/types';
|
|
2
|
-
import { Handler } from '../shared';
|
|
3
|
-
/**
|
|
4
|
-
* @param context
|
|
5
|
-
* @param params - [`extrinsic`, `blockhash`]
|
|
6
|
-
*
|
|
7
|
-
* @return result in hash
|
|
8
|
-
*/
|
|
9
|
-
export declare const payment_queryFeeDetails: Handler<[HexString, HexString], HexString>;
|
|
10
|
-
/**
|
|
11
|
-
* @param context
|
|
12
|
-
* @param params - [`extrinsic`, `blockhash`]
|
|
13
|
-
*
|
|
14
|
-
* @return result in hash
|
|
15
|
-
*/
|
|
16
|
-
export declare const payment_queryInfo: Handler<[HexString, HexString], HexString>;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.payment_queryInfo = exports.payment_queryFeeDetails = void 0;
|
|
4
|
-
const util_1 = require("@polkadot/util");
|
|
5
|
-
const shared_1 = require("../shared");
|
|
6
|
-
/**
|
|
7
|
-
* @param context
|
|
8
|
-
* @param params - [`extrinsic`, `blockhash`]
|
|
9
|
-
*
|
|
10
|
-
* @return result in hash
|
|
11
|
-
*/
|
|
12
|
-
const payment_queryFeeDetails = async (context, [extrinsic, hash]) => {
|
|
13
|
-
const block = await context.chain.getBlock(hash);
|
|
14
|
-
if (!block) {
|
|
15
|
-
throw new shared_1.ResponseError(1, `Block ${hash} not found`);
|
|
16
|
-
}
|
|
17
|
-
const registry = await block.registry;
|
|
18
|
-
const tx = (0, util_1.hexToU8a)(extrinsic);
|
|
19
|
-
const resp = await block.call('TransactionPaymentApi_query_fee_details', [
|
|
20
|
-
registry.createType('Extrinsic', tx).toHex(),
|
|
21
|
-
registry.createType('u32', tx.byteLength).toHex(),
|
|
22
|
-
]);
|
|
23
|
-
return resp.result;
|
|
24
|
-
};
|
|
25
|
-
exports.payment_queryFeeDetails = payment_queryFeeDetails;
|
|
26
|
-
/**
|
|
27
|
-
* @param context
|
|
28
|
-
* @param params - [`extrinsic`, `blockhash`]
|
|
29
|
-
*
|
|
30
|
-
* @return result in hash
|
|
31
|
-
*/
|
|
32
|
-
const payment_queryInfo = async (context, [extrinsic, hash]) => {
|
|
33
|
-
const block = await context.chain.getBlock(hash);
|
|
34
|
-
if (!block) {
|
|
35
|
-
throw new shared_1.ResponseError(1, `Block ${hash} not found`);
|
|
36
|
-
}
|
|
37
|
-
const registry = await block.registry;
|
|
38
|
-
const tx = (0, util_1.hexToU8a)(extrinsic);
|
|
39
|
-
const resp = await block.call('TransactionPaymentApi_query_info', [
|
|
40
|
-
registry.createType('Extrinsic', tx).toHex(),
|
|
41
|
-
registry.createType('u32', tx.byteLength).toHex(),
|
|
42
|
-
]);
|
|
43
|
-
return resp.result;
|
|
44
|
-
};
|
|
45
|
-
exports.payment_queryInfo = payment_queryInfo;
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { RuntimeVersion } from '@acala-network/chopsticks-core';
|
|
2
|
-
import { HexString } from '@polkadot/util/types';
|
|
3
|
-
import { Handler } from '../shared';
|
|
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>;
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
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;
|
|
4
|
-
const chopsticks_core_1 = require("@acala-network/chopsticks-core");
|
|
5
|
-
const shared_1 = require("../shared");
|
|
6
|
-
const logger_1 = require("../../logger");
|
|
7
|
-
const logger = logger_1.defaultLogger.child({ name: 'rpc-state' });
|
|
8
|
-
/**
|
|
9
|
-
* @param context
|
|
10
|
-
* @param params - [`blockhash`]
|
|
11
|
-
*
|
|
12
|
-
* @return runtime version
|
|
13
|
-
*/
|
|
14
|
-
const state_getRuntimeVersion = async (context, [hash]) => {
|
|
15
|
-
const block = await context.chain.getBlock(hash);
|
|
16
|
-
return block?.runtimeVersion;
|
|
17
|
-
};
|
|
18
|
-
exports.state_getRuntimeVersion = state_getRuntimeVersion;
|
|
19
|
-
/**
|
|
20
|
-
* @param context
|
|
21
|
-
* @param params - [`blockhash`]
|
|
22
|
-
*
|
|
23
|
-
* @return metadata
|
|
24
|
-
*/
|
|
25
|
-
const state_getMetadata = async (context, [hash]) => {
|
|
26
|
-
const block = await context.chain.getBlock(hash);
|
|
27
|
-
return block?.metadata;
|
|
28
|
-
};
|
|
29
|
-
exports.state_getMetadata = state_getMetadata;
|
|
30
|
-
/**
|
|
31
|
-
* @param context
|
|
32
|
-
* @param params - [`key`, `blockhash`]
|
|
33
|
-
*
|
|
34
|
-
* @return storage value
|
|
35
|
-
*/
|
|
36
|
-
const state_getStorage = async (context, [key, hash]) => {
|
|
37
|
-
const block = await context.chain.getBlock(hash);
|
|
38
|
-
return block?.get(key);
|
|
39
|
-
};
|
|
40
|
-
exports.state_getStorage = state_getStorage;
|
|
41
|
-
/**
|
|
42
|
-
* @param context
|
|
43
|
-
* @param params - [`prefix`, `pageSize`, `startKey`, `blockhash`]
|
|
44
|
-
*
|
|
45
|
-
* @return paged keys
|
|
46
|
-
*/
|
|
47
|
-
const state_getKeysPaged = async (context, [prefix, pageSize, startKey, hash]) => {
|
|
48
|
-
const block = await context.chain.getBlock(hash);
|
|
49
|
-
return block?.getKeysPaged({ prefix, pageSize, startKey });
|
|
50
|
-
};
|
|
51
|
-
exports.state_getKeysPaged = state_getKeysPaged;
|
|
52
|
-
/**
|
|
53
|
-
* @param context
|
|
54
|
-
* @param params - [`keys`, `blockhash`]
|
|
55
|
-
*
|
|
56
|
-
* @return storage values
|
|
57
|
-
*/
|
|
58
|
-
const state_queryStorageAt = async (context, [keys, hash]) => {
|
|
59
|
-
const block = await context.chain.getBlock(hash);
|
|
60
|
-
if (!block) {
|
|
61
|
-
return [];
|
|
62
|
-
}
|
|
63
|
-
const values = await Promise.all(keys.map(async (key) => [key, await block.get(key)]));
|
|
64
|
-
return [
|
|
65
|
-
{
|
|
66
|
-
block: block.hash,
|
|
67
|
-
changes: values,
|
|
68
|
-
},
|
|
69
|
-
];
|
|
70
|
-
};
|
|
71
|
-
exports.state_queryStorageAt = state_queryStorageAt;
|
|
72
|
-
/**
|
|
73
|
-
* @param context
|
|
74
|
-
* @param params - [`method`, `data`, `blockhash`]
|
|
75
|
-
*
|
|
76
|
-
* @return result in hash
|
|
77
|
-
*/
|
|
78
|
-
const state_call = async (context, [method, data, hash]) => {
|
|
79
|
-
const block = await context.chain.getBlock(hash);
|
|
80
|
-
if (!block) {
|
|
81
|
-
throw new shared_1.ResponseError(1, `Block ${hash} not found`);
|
|
82
|
-
}
|
|
83
|
-
const resp = await block.call(method, [data]);
|
|
84
|
-
return resp.result;
|
|
85
|
-
};
|
|
86
|
-
exports.state_call = state_call;
|
|
87
|
-
/**
|
|
88
|
-
* @return subscription id
|
|
89
|
-
*/
|
|
90
|
-
const state_subscribeRuntimeVersion = async (context, _params, { subscribe }) => {
|
|
91
|
-
let update = (_block) => { };
|
|
92
|
-
const id = await context.chain.headState.subscrubeRuntimeVersion((block) => update(block));
|
|
93
|
-
const callback = subscribe('state_runtimeVersion', id);
|
|
94
|
-
update = async (block) => callback(await block.runtimeVersion);
|
|
95
|
-
context.chain.head.runtimeVersion.then(callback);
|
|
96
|
-
return id;
|
|
97
|
-
};
|
|
98
|
-
exports.state_subscribeRuntimeVersion = state_subscribeRuntimeVersion;
|
|
99
|
-
/**
|
|
100
|
-
* @param context
|
|
101
|
-
* @param params - [`subid`]
|
|
102
|
-
* @param subscriptionManager
|
|
103
|
-
*/
|
|
104
|
-
const state_unsubscribeRuntimeVersion = async (_context, [subid], { unsubscribe }) => {
|
|
105
|
-
unsubscribe(subid);
|
|
106
|
-
};
|
|
107
|
-
exports.state_unsubscribeRuntimeVersion = state_unsubscribeRuntimeVersion;
|
|
108
|
-
/**
|
|
109
|
-
* @param context
|
|
110
|
-
* @param params - [`keys`]
|
|
111
|
-
* @param subscriptionManager
|
|
112
|
-
*
|
|
113
|
-
* @return subscription id
|
|
114
|
-
*/
|
|
115
|
-
const state_subscribeStorage = async (context, [keys], { subscribe }) => {
|
|
116
|
-
let update = (_block, _pairs) => { };
|
|
117
|
-
const id = await context.chain.headState.subscribeStorage(keys, (block, pairs) => update(block, pairs));
|
|
118
|
-
const callback = subscribe('state_storage', id, () => context.chain.headState.unsubscribeStorage(id));
|
|
119
|
-
update = async (block, pairs) => {
|
|
120
|
-
logger.trace({ hash: block.hash }, 'state_subscribeStorage');
|
|
121
|
-
callback({
|
|
122
|
-
block: block.hash,
|
|
123
|
-
changes: pairs,
|
|
124
|
-
});
|
|
125
|
-
};
|
|
126
|
-
(async () => {
|
|
127
|
-
const pairs = await Promise.all(keys.map(async (key) => {
|
|
128
|
-
const val = await context.chain.head.get(key);
|
|
129
|
-
return [key, val];
|
|
130
|
-
}));
|
|
131
|
-
callback({
|
|
132
|
-
block: context.chain.head.hash,
|
|
133
|
-
changes: pairs,
|
|
134
|
-
});
|
|
135
|
-
})();
|
|
136
|
-
return id;
|
|
137
|
-
};
|
|
138
|
-
exports.state_subscribeStorage = state_subscribeStorage;
|
|
139
|
-
/**
|
|
140
|
-
* @param context
|
|
141
|
-
* @param params - [`subid`]
|
|
142
|
-
* @param subscriptionManager
|
|
143
|
-
*/
|
|
144
|
-
const state_unsubscribeStorage = async (_context, [subid], { unsubscribe }) => {
|
|
145
|
-
unsubscribe(subid);
|
|
146
|
-
};
|
|
147
|
-
exports.state_unsubscribeStorage = state_unsubscribeStorage;
|
|
148
|
-
/**
|
|
149
|
-
* @param context
|
|
150
|
-
* @param params - [`child`, `key`, `blockhash`]
|
|
151
|
-
*
|
|
152
|
-
* @return storage valuse
|
|
153
|
-
*/
|
|
154
|
-
const childstate_getStorage = async (context, [child, key, hash]) => {
|
|
155
|
-
if (!(0, chopsticks_core_1.isPrefixedChildKey)(child)) {
|
|
156
|
-
throw new shared_1.ResponseError(-32000, 'Client error: Invalid child storage key');
|
|
157
|
-
}
|
|
158
|
-
const block = await context.chain.getBlock(hash);
|
|
159
|
-
return block?.get((0, chopsticks_core_1.prefixedChildKey)(child, key));
|
|
160
|
-
};
|
|
161
|
-
exports.childstate_getStorage = childstate_getStorage;
|
|
162
|
-
/**
|
|
163
|
-
* @param context
|
|
164
|
-
* @param params - [`child`, `prefix`, `pageSize`, `startKey`, `blockhash`]
|
|
165
|
-
*
|
|
166
|
-
* @return paged keys
|
|
167
|
-
*/
|
|
168
|
-
const childstate_getKeysPaged = async (context, [child, prefix, pageSize, startKey, hash]) => {
|
|
169
|
-
if (!(0, chopsticks_core_1.isPrefixedChildKey)(child)) {
|
|
170
|
-
throw new shared_1.ResponseError(-32000, 'Client error: Invalid child storage key');
|
|
171
|
-
}
|
|
172
|
-
const block = await context.chain.getBlock(hash);
|
|
173
|
-
return block
|
|
174
|
-
?.getKeysPaged({ prefix: (0, chopsticks_core_1.prefixedChildKey)(child, prefix), pageSize, startKey: (0, chopsticks_core_1.prefixedChildKey)(child, startKey) })
|
|
175
|
-
.then((keys) => keys.map(chopsticks_core_1.stripChildPrefix));
|
|
176
|
-
};
|
|
177
|
-
exports.childstate_getKeysPaged = childstate_getKeysPaged;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { ChainProperties } from '@acala-network/chopsticks-core';
|
|
2
|
-
import { HexString } from '@polkadot/util/types';
|
|
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>;
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
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;
|
|
7
|
-
const util_1 = require("@polkadot/util");
|
|
8
|
-
const node_fs_1 = require("node:fs");
|
|
9
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
-
const system_localPeerId = async () => '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
|
|
11
|
-
exports.system_localPeerId = system_localPeerId;
|
|
12
|
-
const system_nodeRoles = async () => ['Full'];
|
|
13
|
-
exports.system_nodeRoles = system_nodeRoles;
|
|
14
|
-
const system_localListenAddresses = async () => [];
|
|
15
|
-
exports.system_localListenAddresses = system_localListenAddresses;
|
|
16
|
-
const system_chain = async (context) => {
|
|
17
|
-
return context.chain.api.getSystemChain();
|
|
18
|
-
};
|
|
19
|
-
exports.system_chain = system_chain;
|
|
20
|
-
const system_properties = async (context) => {
|
|
21
|
-
return context.chain.api.getSystemProperties();
|
|
22
|
-
};
|
|
23
|
-
exports.system_properties = system_properties;
|
|
24
|
-
const system_name = async (context) => {
|
|
25
|
-
return context.chain.api.getSystemName();
|
|
26
|
-
};
|
|
27
|
-
exports.system_name = system_name;
|
|
28
|
-
const system_version = async (_context) => {
|
|
29
|
-
const { version } = JSON.parse((0, node_fs_1.readFileSync)(node_path_1.default.join(__dirname, '../../../package.json'), 'utf-8'));
|
|
30
|
-
return `chopsticks-v${version}`;
|
|
31
|
-
};
|
|
32
|
-
exports.system_version = system_version;
|
|
33
|
-
const system_chainType = async (_context) => {
|
|
34
|
-
return 'Development';
|
|
35
|
-
};
|
|
36
|
-
exports.system_chainType = system_chainType;
|
|
37
|
-
const system_health = async () => {
|
|
38
|
-
return {
|
|
39
|
-
peers: 0,
|
|
40
|
-
isSyncing: false,
|
|
41
|
-
shouldHavePeers: false,
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
exports.system_health = system_health;
|
|
45
|
-
/**
|
|
46
|
-
* @param context
|
|
47
|
-
* @param params - [`extrinsic`, `at`]
|
|
48
|
-
*
|
|
49
|
-
* @return ApplyExtrinsicResult (see `@polkadot/types/interfaces`) in hash
|
|
50
|
-
*/
|
|
51
|
-
const system_dryRun = async (context, [extrinsic, at]) => {
|
|
52
|
-
const { outcome } = await context.chain.dryRunExtrinsic(extrinsic, at);
|
|
53
|
-
return outcome.toHex();
|
|
54
|
-
};
|
|
55
|
-
exports.system_dryRun = system_dryRun;
|
|
56
|
-
/**
|
|
57
|
-
* @param context
|
|
58
|
-
* @param params - [`address`]
|
|
59
|
-
*/
|
|
60
|
-
const system_accountNextIndex = async (context, [address]) => {
|
|
61
|
-
const head = context.chain.head;
|
|
62
|
-
const registry = await head.registry;
|
|
63
|
-
const account = registry.createType('AccountId', address);
|
|
64
|
-
const result = await head.call('AccountNonceApi_account_nonce', [account.toHex()]);
|
|
65
|
-
const nonce = registry.createType('Index', (0, util_1.hexToU8a)(result.result)).toNumber();
|
|
66
|
-
return nonce + context.chain.txPool.pendingExtrinsicsBy(address).length;
|
|
67
|
-
};
|
|
68
|
-
exports.system_accountNextIndex = system_accountNextIndex;
|