@acala-network/chopsticks-core 0.8.2 → 0.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/blockchain/block-builder.d.ts +5 -1
- package/lib/blockchain/block-builder.js +21 -20
- package/lib/blockchain/block.d.ts +1 -1
- package/lib/blockchain/block.js +4 -4
- package/lib/blockchain/index.d.ts +2 -2
- package/lib/blockchain/index.js +4 -2
- package/lib/blockchain/inherent/parachain/validation-data.js +5 -5
- package/lib/blockchain/storage-layer.js +25 -2
- package/lib/blockchain/txpool.js +18 -2
- package/lib/chopsticks-provider.d.ts +0 -0
- package/lib/chopsticks-provider.js +249 -0
- package/lib/chopsticks-worker.d.ts +1 -0
- package/lib/chopsticks-worker.js +101 -0
- package/lib/genesis-provider.d.ts +1 -1
- package/lib/genesis-provider.js +3 -3
- package/lib/index.d.ts +2 -1
- package/lib/index.js +3 -1
- package/lib/rpc/index.d.ts +5 -0
- package/lib/rpc/index.js +26 -0
- package/lib/rpc/shared.d.ts +27 -0
- package/lib/rpc/shared.js +19 -0
- package/lib/rpc/substrate/author.d.ts +28 -0
- package/lib/rpc/substrate/author.js +98 -0
- package/lib/rpc/substrate/chain.d.ts +45 -0
- package/lib/rpc/substrate/chain.js +103 -0
- package/lib/rpc/substrate/index.d.ts +66 -0
- package/lib/rpc/substrate/index.js +38 -0
- package/lib/rpc/substrate/payment.d.ts +16 -0
- package/lib/rpc/substrate/payment.js +54 -0
- package/lib/rpc/substrate/state.d.ts +97 -0
- package/lib/rpc/substrate/state.js +184 -0
- package/lib/rpc/substrate/system.d.ts +28 -0
- package/lib/rpc/substrate/system.js +71 -0
- package/lib/utils/time-travel.js +2 -2
- package/lib/wasm-executor/browser-wasm-executor.mjs +37 -0
- package/lib/wasm-executor/browser-worker.d.ts +5 -0
- package/lib/wasm-executor/browser-worker.js +28 -0
- package/lib/{executor.d.ts → wasm-executor/index.d.ts} +18 -1
- package/lib/{executor.js → wasm-executor/index.js} +60 -15
- package/lib/wasm-executor/node-wasm-executor.mjs +34 -0
- package/lib/wasm-executor/node-worker.d.ts +5 -0
- package/lib/wasm-executor/node-worker.js +31 -0
- package/package.json +6 -4
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const rpc_1 = require("./rpc");
|
|
13
|
+
const logger_1 = require("./logger");
|
|
14
|
+
const utils_1 = require("./utils");
|
|
15
|
+
const setup_1 = require("./setup");
|
|
16
|
+
let chain;
|
|
17
|
+
const logger = logger_1.defaultLogger.child({ name: '[Chopsticks worker]' });
|
|
18
|
+
const subscriptions = {};
|
|
19
|
+
const providerHandlers = Object.assign(Object.assign({}, rpc_1.allHandlers), { new_block: (context, _params, _subscriptionManager) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
const { chain } = context;
|
|
21
|
+
const block = yield chain.newBlock();
|
|
22
|
+
return block;
|
|
23
|
+
}) });
|
|
24
|
+
const subscriptionManager = {
|
|
25
|
+
subscribe: (method, subid, onCancel = () => { }) => {
|
|
26
|
+
subscriptions[subid] = onCancel;
|
|
27
|
+
return (data) => {
|
|
28
|
+
postMessage({
|
|
29
|
+
type: 'subscribe-callback',
|
|
30
|
+
method,
|
|
31
|
+
subid,
|
|
32
|
+
result: JSON.stringify(data),
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
unsubscribe: (subid) => {
|
|
37
|
+
if (subscriptions[subid]) {
|
|
38
|
+
subscriptions[subid](subid); // call onCancel
|
|
39
|
+
postMessage({
|
|
40
|
+
type: 'unsubscribe-callback',
|
|
41
|
+
subid,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
onmessage = (e) => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
+
var _a;
|
|
48
|
+
switch (e.data.type) {
|
|
49
|
+
case 'connect':
|
|
50
|
+
try {
|
|
51
|
+
logger.debug('onMessage: connect. Initializing...');
|
|
52
|
+
chain = yield (0, setup_1.setup)({
|
|
53
|
+
endpoint: e.data.endpoint,
|
|
54
|
+
mockSignatureHost: true,
|
|
55
|
+
db: e.data.dbPath,
|
|
56
|
+
block: e.data.blockHash,
|
|
57
|
+
});
|
|
58
|
+
logger.debug('onMessage: connect. Chain setup done.');
|
|
59
|
+
yield (0, utils_1.setStorage)(chain, e.data.storageValues);
|
|
60
|
+
logger.debug('onMessage: connect. Set storage done.');
|
|
61
|
+
postMessage({
|
|
62
|
+
type: 'connection',
|
|
63
|
+
connected: true,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
logger.error('onMessage: connect error.', e);
|
|
68
|
+
postMessage({
|
|
69
|
+
type: 'connection',
|
|
70
|
+
connected: false,
|
|
71
|
+
message: e,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
break;
|
|
75
|
+
case 'disconnect':
|
|
76
|
+
if (chain) {
|
|
77
|
+
yield ((_a = chain === null || chain === void 0 ? void 0 : chain.api) === null || _a === void 0 ? void 0 : _a.disconnect());
|
|
78
|
+
yield (chain === null || chain === void 0 ? void 0 : chain.close());
|
|
79
|
+
}
|
|
80
|
+
break;
|
|
81
|
+
case 'send':
|
|
82
|
+
{
|
|
83
|
+
const { method, params } = e.data;
|
|
84
|
+
const handler = providerHandlers[method];
|
|
85
|
+
if (!handler) {
|
|
86
|
+
logger.error(`Unable to find rpc handler=${method}`);
|
|
87
|
+
return Promise.reject(new Error(`Unable to find handler=${method}`));
|
|
88
|
+
}
|
|
89
|
+
const result = yield handler({ chain: chain }, params, subscriptionManager);
|
|
90
|
+
postMessage({
|
|
91
|
+
type: 'send-result',
|
|
92
|
+
id: e.data.id,
|
|
93
|
+
method: method,
|
|
94
|
+
result: JSON.stringify(result),
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
break;
|
|
98
|
+
default:
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { HexString } from '@polkadot/util/types';
|
|
2
2
|
import { ProviderInterface, ProviderInterfaceCallback, ProviderInterfaceEmitCb, ProviderInterfaceEmitted, ProviderStats } from '@polkadot/rpc-provider/types';
|
|
3
3
|
import { Genesis } from './schema';
|
|
4
|
-
import { JsCallback } from './executor';
|
|
4
|
+
import { JsCallback } from './wasm-executor';
|
|
5
5
|
export declare class GenesisProvider implements ProviderInterface {
|
|
6
6
|
#private;
|
|
7
7
|
readonly stats?: ProviderStats;
|
package/lib/genesis-provider.js
CHANGED
|
@@ -51,7 +51,7 @@ exports.GenesisProvider = void 0;
|
|
|
51
51
|
const eventemitter3_1 = require("eventemitter3");
|
|
52
52
|
const axios_1 = __importDefault(require("axios"));
|
|
53
53
|
const schema_1 = require("./schema");
|
|
54
|
-
const
|
|
54
|
+
const wasm_executor_1 = require("./wasm-executor");
|
|
55
55
|
const utils_1 = require("./utils");
|
|
56
56
|
class GenesisProvider {
|
|
57
57
|
constructor(genesis) {
|
|
@@ -127,7 +127,7 @@ class GenesisProvider {
|
|
|
127
127
|
throw Error('unimplemented');
|
|
128
128
|
});
|
|
129
129
|
__classPrivateFieldSet(this, _GenesisProvider_genesis, genesis, "f");
|
|
130
|
-
__classPrivateFieldSet(this, _GenesisProvider_stateRoot, (0,
|
|
130
|
+
__classPrivateFieldSet(this, _GenesisProvider_stateRoot, (0, wasm_executor_1.calculateStateRoot)(Object.entries(__classPrivateFieldGet(this, _GenesisProvider_genesis, "f").genesis.raw.top).reduce((accu, item) => {
|
|
131
131
|
accu.push(item);
|
|
132
132
|
return accu;
|
|
133
133
|
}, []), 1), "f");
|
|
@@ -157,7 +157,7 @@ class GenesisProvider {
|
|
|
157
157
|
}
|
|
158
158
|
get _jsCallback() {
|
|
159
159
|
const storage = __classPrivateFieldGet(this, _GenesisProvider_genesis, "f").genesis.raw.top;
|
|
160
|
-
return Object.assign(Object.assign({},
|
|
160
|
+
return Object.assign(Object.assign({}, wasm_executor_1.emptyTaskHandler), { getStorage: function (key) {
|
|
161
161
|
return __awaiter(this, void 0, void 0, function* () {
|
|
162
162
|
return storage[key];
|
|
163
163
|
});
|
package/lib/index.d.ts
CHANGED
|
@@ -15,10 +15,11 @@ export * from './blockchain/txpool';
|
|
|
15
15
|
export * from './blockchain/storage-layer';
|
|
16
16
|
export * from './blockchain/head-state';
|
|
17
17
|
export * from './utils';
|
|
18
|
-
export * from './executor';
|
|
18
|
+
export * from './wasm-executor';
|
|
19
19
|
export * from './schema';
|
|
20
20
|
export * from './xcm';
|
|
21
21
|
export * from './setup';
|
|
22
22
|
export * from './blockchain/inherent';
|
|
23
23
|
export * from './logger';
|
|
24
24
|
export * from './offchain';
|
|
25
|
+
export * from './rpc';
|
package/lib/index.js
CHANGED
|
@@ -31,10 +31,12 @@ __exportStar(require("./blockchain/txpool"), exports);
|
|
|
31
31
|
__exportStar(require("./blockchain/storage-layer"), exports);
|
|
32
32
|
__exportStar(require("./blockchain/head-state"), exports);
|
|
33
33
|
__exportStar(require("./utils"), exports);
|
|
34
|
-
__exportStar(require("./executor"), exports);
|
|
34
|
+
__exportStar(require("./wasm-executor"), exports);
|
|
35
35
|
__exportStar(require("./schema"), exports);
|
|
36
36
|
__exportStar(require("./xcm"), exports);
|
|
37
37
|
__exportStar(require("./setup"), exports);
|
|
38
38
|
__exportStar(require("./blockchain/inherent"), exports);
|
|
39
39
|
__exportStar(require("./logger"), exports);
|
|
40
40
|
__exportStar(require("./offchain"), exports);
|
|
41
|
+
// export * from './chopsticks-provider'
|
|
42
|
+
__exportStar(require("./rpc"), exports);
|
package/lib/rpc/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.ResponseError = exports.substrate = exports.allHandlers = void 0;
|
|
16
|
+
const substrate_1 = __importDefault(require("./substrate"));
|
|
17
|
+
exports.allHandlers = Object.assign(Object.assign({}, substrate_1.default), { rpc_methods: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
return Promise.resolve({
|
|
19
|
+
version: 1,
|
|
20
|
+
methods: [...Object.keys(exports.allHandlers)],
|
|
21
|
+
});
|
|
22
|
+
}) });
|
|
23
|
+
var substrate_2 = require("./substrate");
|
|
24
|
+
Object.defineProperty(exports, "substrate", { enumerable: true, get: function () { return __importDefault(substrate_2).default; } });
|
|
25
|
+
var shared_1 = require("./shared");
|
|
26
|
+
Object.defineProperty(exports, "ResponseError", { enumerable: true, get: function () { return shared_1.ResponseError; } });
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
|
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>;
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
constructor(code, message) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = 'ResponseError';
|
|
10
|
+
this.code = code;
|
|
11
|
+
}
|
|
12
|
+
toJSON() {
|
|
13
|
+
return {
|
|
14
|
+
code: this.code,
|
|
15
|
+
message: this.message,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.ResponseError = ResponseError;
|
|
@@ -0,0 +1,28 @@
|
|
|
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[]>;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.author_pendingExtrinsics = exports.author_unwatchExtrinsic = exports.author_submitAndWatchExtrinsic = exports.author_submitExtrinsic = void 0;
|
|
13
|
+
const txpool_1 = require("../../blockchain/txpool");
|
|
14
|
+
const shared_1 = require("../shared");
|
|
15
|
+
const logger_1 = require("../../logger");
|
|
16
|
+
const logger = logger_1.defaultLogger.child({ name: 'rpc-author' });
|
|
17
|
+
/**
|
|
18
|
+
* @param context
|
|
19
|
+
* @param params - [`extrinsic`]
|
|
20
|
+
*
|
|
21
|
+
* @return Hash
|
|
22
|
+
*/
|
|
23
|
+
const author_submitExtrinsic = (context, [extrinsic]) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
return context.chain.submitExtrinsic(extrinsic).catch((error) => {
|
|
25
|
+
const code = error.isInvalid ? 1010 : 1011;
|
|
26
|
+
throw new shared_1.ResponseError(code, error.toString());
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
exports.author_submitExtrinsic = author_submitExtrinsic;
|
|
30
|
+
/**
|
|
31
|
+
* @param context
|
|
32
|
+
* @param params - [`extrinsic`]
|
|
33
|
+
* @param subscriptionManager
|
|
34
|
+
*
|
|
35
|
+
* @return subscription id
|
|
36
|
+
*/
|
|
37
|
+
const author_submitAndWatchExtrinsic = (context, [extrinsic], { subscribe, unsubscribe }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
+
let update = (_block) => { };
|
|
39
|
+
const id = context.chain.headState.subscribeHead((block) => update(block));
|
|
40
|
+
const callback = subscribe('author_extrinsicUpdate', id, () => context.chain.headState.unsubscribeHead(id));
|
|
41
|
+
const onExtrinsicFail = ([failedExtrinsic, error]) => {
|
|
42
|
+
if (failedExtrinsic === extrinsic) {
|
|
43
|
+
callback(error.toJSON());
|
|
44
|
+
done(id);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
context.chain.txPool.event.on(txpool_1.APPLY_EXTRINSIC_ERROR, onExtrinsicFail);
|
|
48
|
+
const done = (id) => {
|
|
49
|
+
context.chain.txPool.event.removeListener(txpool_1.APPLY_EXTRINSIC_ERROR, onExtrinsicFail);
|
|
50
|
+
unsubscribe(id);
|
|
51
|
+
};
|
|
52
|
+
update = (block) => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
|
+
const extrisnics = yield block.extrinsics;
|
|
54
|
+
if (!extrisnics.includes(extrinsic))
|
|
55
|
+
return;
|
|
56
|
+
logger.debug({ block: block.hash }, 'author_extrinsicUpdate');
|
|
57
|
+
callback({
|
|
58
|
+
inBlock: block.hash,
|
|
59
|
+
});
|
|
60
|
+
// wait a bit for InBlock to be sent
|
|
61
|
+
yield new Promise((r) => setTimeout(r, 100));
|
|
62
|
+
callback({
|
|
63
|
+
finalized: block.hash,
|
|
64
|
+
});
|
|
65
|
+
done(id);
|
|
66
|
+
});
|
|
67
|
+
try {
|
|
68
|
+
yield context.chain.submitExtrinsic(extrinsic);
|
|
69
|
+
callback({
|
|
70
|
+
ready: null,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
logger.error({ error }, 'ExtrinsicFailed');
|
|
75
|
+
const code = error.isInvalid ? 1010 : 1011;
|
|
76
|
+
done(id);
|
|
77
|
+
throw new shared_1.ResponseError(code, error.toString());
|
|
78
|
+
}
|
|
79
|
+
return id;
|
|
80
|
+
});
|
|
81
|
+
exports.author_submitAndWatchExtrinsic = author_submitAndWatchExtrinsic;
|
|
82
|
+
/**
|
|
83
|
+
* @param _context
|
|
84
|
+
* @param params - [`subid`]
|
|
85
|
+
*/
|
|
86
|
+
const author_unwatchExtrinsic = (_context, [subid], { unsubscribe }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
87
|
+
unsubscribe(subid);
|
|
88
|
+
});
|
|
89
|
+
exports.author_unwatchExtrinsic = author_unwatchExtrinsic;
|
|
90
|
+
/**
|
|
91
|
+
* Get pending extrinsics
|
|
92
|
+
*
|
|
93
|
+
* @return Array of pending extrinsics
|
|
94
|
+
*/
|
|
95
|
+
const author_pendingExtrinsics = (context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
96
|
+
return context.chain.txPool.pendingExtrinsics;
|
|
97
|
+
});
|
|
98
|
+
exports.author_pendingExtrinsics = author_pendingExtrinsics;
|
|
@@ -0,0 +1,45 @@
|
|
|
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` | `blockNumber[]` | null]
|
|
7
|
+
*
|
|
8
|
+
* @return Block hash | hash[] | null
|
|
9
|
+
*/
|
|
10
|
+
export declare const chain_getBlockHash: Handler<[number | number[] | null], HexString | (HexString | null)[] | null>;
|
|
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_getHead: Handler<[number | number[] | null], `0x${string}` | (`0x${string}` | null)[] | null>;
|
|
43
|
+
export declare const chain_subscribeNewHeads: Handler<void, string>;
|
|
44
|
+
export declare const chain_unsubscribeNewHeads: Handler<[string], void>;
|
|
45
|
+
export declare const chain_unsubscribeFinalizedHeads: Handler<[string], void>;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.chain_unsubscribeFinalizedHeads = exports.chain_unsubscribeNewHeads = exports.chain_subscribeNewHeads = exports.chain_getHead = exports.chain_unsubscribeNewHead = exports.chain_subscribeFinalizedHeads = exports.chain_subscribeNewHead = exports.chain_getFinalizedHead = exports.chain_getBlock = exports.chain_getHeader = exports.chain_getBlockHash = void 0;
|
|
13
|
+
const shared_1 = require("../shared");
|
|
14
|
+
const processHeader = (header) => {
|
|
15
|
+
const res = header.toJSON();
|
|
16
|
+
res.number = '0x' + res.number.toString(16); // number is hex format
|
|
17
|
+
return res;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* @param context
|
|
21
|
+
* @param params - [`blockNumber` | `blockNumber[]` | null]
|
|
22
|
+
*
|
|
23
|
+
* @return Block hash | hash[] | null
|
|
24
|
+
*/
|
|
25
|
+
const chain_getBlockHash = (context, [blockNumber]) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
+
const numbers = Array.isArray(blockNumber) ? blockNumber : [blockNumber];
|
|
27
|
+
const hashes = yield Promise.all(numbers.map((n) => context.chain.getBlockAt(n))).then((blocks) => blocks.map((b) => (b === null || b === void 0 ? void 0 : b.hash) || null));
|
|
28
|
+
return Array.isArray(blockNumber) ? hashes : hashes[0];
|
|
29
|
+
});
|
|
30
|
+
exports.chain_getBlockHash = chain_getBlockHash;
|
|
31
|
+
/**
|
|
32
|
+
* @param context
|
|
33
|
+
* @param params - [`blockhash`]
|
|
34
|
+
*
|
|
35
|
+
* @return Header - see `@polkadot/types/interfaces`
|
|
36
|
+
*/
|
|
37
|
+
const chain_getHeader = (context, [hash]) => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
+
const block = yield context.chain.getBlock(hash);
|
|
39
|
+
if (!block) {
|
|
40
|
+
throw new shared_1.ResponseError(1, `Block ${hash} not found`);
|
|
41
|
+
}
|
|
42
|
+
return processHeader(yield block.header);
|
|
43
|
+
});
|
|
44
|
+
exports.chain_getHeader = chain_getHeader;
|
|
45
|
+
/**
|
|
46
|
+
* @param context
|
|
47
|
+
* @param params - [`blockhash`]
|
|
48
|
+
*
|
|
49
|
+
* @return Block header and extrinsics
|
|
50
|
+
*/
|
|
51
|
+
const chain_getBlock = (context, [hash]) => __awaiter(void 0, void 0, void 0, function* () {
|
|
52
|
+
const block = yield context.chain.getBlock(hash);
|
|
53
|
+
if (!block) {
|
|
54
|
+
throw new shared_1.ResponseError(1, `Block ${hash} not found`);
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
block: {
|
|
58
|
+
header: yield block.header,
|
|
59
|
+
extrinsics: yield block.extrinsics,
|
|
60
|
+
},
|
|
61
|
+
justifications: null,
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
exports.chain_getBlock = chain_getBlock;
|
|
65
|
+
/**
|
|
66
|
+
* @param context
|
|
67
|
+
*
|
|
68
|
+
* @return head hash
|
|
69
|
+
*/
|
|
70
|
+
const chain_getFinalizedHead = (context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
|
+
return context.chain.head.hash;
|
|
72
|
+
});
|
|
73
|
+
exports.chain_getFinalizedHead = chain_getFinalizedHead;
|
|
74
|
+
const chain_subscribeNewHead = (context, _params, { subscribe }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
75
|
+
let update = () => { };
|
|
76
|
+
const id = context.chain.headState.subscribeHead(() => update());
|
|
77
|
+
const callback = subscribe('chain_newHead', id, () => context.chain.headState.unsubscribeHead(id));
|
|
78
|
+
update = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
79
|
+
callback(processHeader(yield context.chain.head.header));
|
|
80
|
+
});
|
|
81
|
+
update();
|
|
82
|
+
return id;
|
|
83
|
+
});
|
|
84
|
+
exports.chain_subscribeNewHead = chain_subscribeNewHead;
|
|
85
|
+
const chain_subscribeFinalizedHeads = (context, _params, { subscribe }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
86
|
+
let update = () => { };
|
|
87
|
+
const id = context.chain.headState.subscribeHead(() => update());
|
|
88
|
+
const callback = subscribe('chain_finalizedHead', id, () => context.chain.headState.unsubscribeHead(id));
|
|
89
|
+
update = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
90
|
+
callback(processHeader(yield context.chain.head.header));
|
|
91
|
+
});
|
|
92
|
+
update();
|
|
93
|
+
return id;
|
|
94
|
+
});
|
|
95
|
+
exports.chain_subscribeFinalizedHeads = chain_subscribeFinalizedHeads;
|
|
96
|
+
const chain_unsubscribeNewHead = (_context, [subid], { unsubscribe }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
97
|
+
unsubscribe(subid);
|
|
98
|
+
});
|
|
99
|
+
exports.chain_unsubscribeNewHead = chain_unsubscribeNewHead;
|
|
100
|
+
exports.chain_getHead = exports.chain_getBlockHash;
|
|
101
|
+
exports.chain_subscribeNewHeads = exports.chain_subscribeNewHead;
|
|
102
|
+
exports.chain_unsubscribeNewHeads = exports.chain_unsubscribeNewHead;
|
|
103
|
+
exports.chain_unsubscribeFinalizedHeads = exports.chain_unsubscribeNewHead;
|
|
@@ -0,0 +1,66 @@
|
|
|
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("..").Handler<void, string>;
|
|
16
|
+
system_properties: import("..").Handler<void, import("../..").ChainProperties>;
|
|
17
|
+
system_name: import("..").Handler<void, string>;
|
|
18
|
+
system_version: import("..").Handler<void, string>;
|
|
19
|
+
system_chainType: import("..").Handler<void, string>;
|
|
20
|
+
system_health: () => Promise<{
|
|
21
|
+
peers: number;
|
|
22
|
+
isSyncing: boolean;
|
|
23
|
+
shouldHavePeers: boolean;
|
|
24
|
+
}>;
|
|
25
|
+
system_dryRun: import("..").Handler<[`0x${string}`, `0x${string}`], string>;
|
|
26
|
+
system_accountNextIndex: import("..").Handler<[`0x${string}`], number>;
|
|
27
|
+
state_getRuntimeVersion: import("..").Handler<[`0x${string}`], import("../..").RuntimeVersion | undefined>;
|
|
28
|
+
state_getMetadata: import("..").Handler<[`0x${string}`], `0x${string}` | undefined>;
|
|
29
|
+
state_getStorage: import("..").Handler<[`0x${string}`, `0x${string}`], string | undefined>;
|
|
30
|
+
state_getKeysPaged: import("..").Handler<[string, number, string, `0x${string}`], string[] | undefined>;
|
|
31
|
+
state_queryStorageAt: import("..").Handler<[string[], `0x${string}`], [] | [{
|
|
32
|
+
block: `0x${string}`;
|
|
33
|
+
changes: (string | undefined)[][];
|
|
34
|
+
}]>;
|
|
35
|
+
state_call: import("..").Handler<[`0x${string}`, `0x${string}`, `0x${string}`], `0x${string}`>;
|
|
36
|
+
state_subscribeRuntimeVersion: import("..").Handler<[], string>;
|
|
37
|
+
state_unsubscribeRuntimeVersion: import("..").Handler<[`0x${string}`], void>;
|
|
38
|
+
state_subscribeStorage: import("..").Handler<[string[]], string>;
|
|
39
|
+
state_unsubscribeStorage: import("..").Handler<[string], void>;
|
|
40
|
+
childstate_getStorage: import("..").Handler<[`0x${string}`, `0x${string}`, `0x${string}`], string | undefined>;
|
|
41
|
+
childstate_getKeysPaged: import("..").Handler<[`0x${string}`, `0x${string}`, number, `0x${string}`, `0x${string}`], `0x${string}`[] | undefined>;
|
|
42
|
+
payment_queryFeeDetails: import("..").Handler<[`0x${string}`, `0x${string}`], `0x${string}`>;
|
|
43
|
+
payment_queryInfo: import("..").Handler<[`0x${string}`, `0x${string}`], `0x${string}`>;
|
|
44
|
+
chain_getBlockHash: import("..").Handler<[number | number[] | null], `0x${string}` | (`0x${string}` | null)[] | null>;
|
|
45
|
+
chain_getHeader: import("..").Handler<[`0x${string}`], import("@polkadot/types/interfaces").Header>;
|
|
46
|
+
chain_getBlock: import("..").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("..").Handler<void, `0x${string}`>;
|
|
54
|
+
chain_subscribeNewHead: import("..").Handler<void, string>;
|
|
55
|
+
chain_subscribeFinalizedHeads: import("..").Handler<void, string>;
|
|
56
|
+
chain_unsubscribeNewHead: import("..").Handler<[string], void>;
|
|
57
|
+
chain_getHead: import("..").Handler<[number | number[] | null], `0x${string}` | (`0x${string}` | null)[] | null>;
|
|
58
|
+
chain_subscribeNewHeads: import("..").Handler<void, string>;
|
|
59
|
+
chain_unsubscribeNewHeads: import("..").Handler<[string], void>;
|
|
60
|
+
chain_unsubscribeFinalizedHeads: import("..").Handler<[string], void>;
|
|
61
|
+
author_submitExtrinsic: import("..").Handler<[`0x${string}`], `0x${string}`>;
|
|
62
|
+
author_submitAndWatchExtrinsic: import("..").Handler<[`0x${string}`], string>;
|
|
63
|
+
author_unwatchExtrinsic: import("..").Handler<[string], void>;
|
|
64
|
+
author_pendingExtrinsics: import("..").Handler<void, `0x${string}`[]>;
|
|
65
|
+
};
|
|
66
|
+
export default handlers;
|
|
@@ -0,0 +1,38 @@
|
|
|
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 = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, AuthorRPC), ChainRPC), PaymentRPC), StateRPC), SystemRPC);
|
|
38
|
+
exports.default = handlers;
|
|
@@ -0,0 +1,16 @@
|
|
|
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>;
|