@acala-network/chopsticks 0.8.3 → 0.8.5-0
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 +48 -26
- package/lib/setup-with-server.js +2 -2
- package/lib/types.d.ts +2 -3
- package/lib/types.js +1 -1
- 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,19 @@ 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 singleRequest = 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
|
+
});
|
|
38
|
+
const batchRequest = zod_1.z.array(singleRequest);
|
|
39
|
+
const requestSchema = zod_1.z.union([singleRequest, batchRequest]);
|
|
31
40
|
const parseRequest = (request) => {
|
|
32
41
|
try {
|
|
33
42
|
return JSON.parse(request);
|
|
@@ -96,6 +105,33 @@ const createServer = async (handler, port) => {
|
|
|
96
105
|
}
|
|
97
106
|
},
|
|
98
107
|
};
|
|
108
|
+
const processRequest = async (req) => {
|
|
109
|
+
logger.trace({
|
|
110
|
+
id: req.id,
|
|
111
|
+
method: req.method,
|
|
112
|
+
}, 'Received message');
|
|
113
|
+
try {
|
|
114
|
+
const resp = await handler(req, subscriptionManager);
|
|
115
|
+
logger.trace({
|
|
116
|
+
id: req.id,
|
|
117
|
+
method: req.method,
|
|
118
|
+
result: (0, logger_1.truncate)(resp),
|
|
119
|
+
}, 'Response for request');
|
|
120
|
+
return {
|
|
121
|
+
id: req.id,
|
|
122
|
+
jsonrpc: '2.0',
|
|
123
|
+
result: resp ?? null,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
catch (e) {
|
|
127
|
+
logger.info('Error handling request: %s %o', e, e.stack);
|
|
128
|
+
return {
|
|
129
|
+
id: req.id,
|
|
130
|
+
jsonrpc: '2.0',
|
|
131
|
+
error: e instanceof chopsticks_core_1.ResponseError ? e : { code: -32603, message: `Internal ${e}` },
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
};
|
|
99
135
|
ws.on('close', () => {
|
|
100
136
|
logger.debug('Connection closed');
|
|
101
137
|
for (const [subid, onCancel] of Object.entries(subscriptions)) {
|
|
@@ -111,8 +147,8 @@ const createServer = async (handler, port) => {
|
|
|
111
147
|
ws.removeAllListeners();
|
|
112
148
|
});
|
|
113
149
|
ws.on('message', async (message) => {
|
|
114
|
-
const
|
|
115
|
-
if (!
|
|
150
|
+
const parsed = await requestSchema.safeParseAsync(parseRequest(message.toString()));
|
|
151
|
+
if (!parsed.success) {
|
|
116
152
|
logger.info('Invalid request: %s', message);
|
|
117
153
|
send({
|
|
118
154
|
id: null,
|
|
@@ -124,30 +160,16 @@ const createServer = async (handler, port) => {
|
|
|
124
160
|
});
|
|
125
161
|
return;
|
|
126
162
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const resp = await handler(req, subscriptionManager);
|
|
133
|
-
logger.trace({
|
|
134
|
-
id: req.id,
|
|
135
|
-
method: req.method,
|
|
136
|
-
result: (0, logger_1.truncate)(resp),
|
|
137
|
-
}, 'Sending response for request');
|
|
138
|
-
send({
|
|
139
|
-
id: req.id,
|
|
140
|
-
jsonrpc: '2.0',
|
|
141
|
-
result: resp ?? null,
|
|
142
|
-
});
|
|
163
|
+
const { data: req } = parsed;
|
|
164
|
+
if (Array.isArray(req)) {
|
|
165
|
+
logger.trace({ req }, 'Received batch request');
|
|
166
|
+
const resp = await Promise.all(req.map(processRequest));
|
|
167
|
+
send(resp);
|
|
143
168
|
}
|
|
144
|
-
|
|
145
|
-
logger.
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
jsonrpc: '2.0',
|
|
149
|
-
error: e instanceof shared_1.ResponseError ? e : { code: -32603, message: `Internal ${e}` },
|
|
150
|
-
});
|
|
169
|
+
else {
|
|
170
|
+
logger.trace({ req }, 'Received single request');
|
|
171
|
+
const resp = await processRequest(req);
|
|
172
|
+
send(resp);
|
|
151
173
|
}
|
|
152
174
|
});
|
|
153
175
|
});
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acala-network/chopsticks",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.5-0",
|
|
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.5-0",
|
|
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>;
|