@dedot/api 0.0.1-alpha.32
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/LICENSE +201 -0
- package/README.md +1 -0
- package/chaintypes/index.d.ts +1 -0
- package/chaintypes/index.js +1 -0
- package/chaintypes/substrate/consts.d.ts +2132 -0
- package/chaintypes/substrate/consts.js +2 -0
- package/chaintypes/substrate/errors.d.ts +3490 -0
- package/chaintypes/substrate/errors.js +2 -0
- package/chaintypes/substrate/events.d.ts +5187 -0
- package/chaintypes/substrate/events.js +2 -0
- package/chaintypes/substrate/index.d.ts +22 -0
- package/chaintypes/substrate/index.js +2 -0
- package/chaintypes/substrate/json-rpc.d.ts +3 -0
- package/chaintypes/substrate/json-rpc.js +2 -0
- package/chaintypes/substrate/query.d.ts +3829 -0
- package/chaintypes/substrate/query.js +2 -0
- package/chaintypes/substrate/runtime.d.ts +850 -0
- package/chaintypes/substrate/runtime.js +2 -0
- package/chaintypes/substrate/tx.d.ts +14269 -0
- package/chaintypes/substrate/tx.js +2 -0
- package/chaintypes/substrate/types.d.ts +30457 -0
- package/chaintypes/substrate/types.js +2 -0
- package/cjs/chaintypes/index.js +17 -0
- package/cjs/chaintypes/substrate/consts.js +3 -0
- package/cjs/chaintypes/substrate/errors.js +3 -0
- package/cjs/chaintypes/substrate/events.js +3 -0
- package/cjs/chaintypes/substrate/index.js +18 -0
- package/cjs/chaintypes/substrate/json-rpc.js +3 -0
- package/cjs/chaintypes/substrate/query.js +3 -0
- package/cjs/chaintypes/substrate/runtime.js +3 -0
- package/cjs/chaintypes/substrate/tx.js +3 -0
- package/cjs/chaintypes/substrate/types.js +3 -0
- package/cjs/client/BaseSubstrateClient.js +257 -0
- package/cjs/client/Dedot.js +250 -0
- package/cjs/client/DedotClient.js +186 -0
- package/cjs/client/index.js +18 -0
- package/cjs/executor/ConstantExecutor.js +20 -0
- package/cjs/executor/ErrorExecutor.js +46 -0
- package/cjs/executor/EventExecutor.js +52 -0
- package/cjs/executor/Executor.js +42 -0
- package/cjs/executor/RuntimeApiExecutor.js +121 -0
- package/cjs/executor/StorageQueryExecutor.js +115 -0
- package/cjs/executor/TxExecutor.js +55 -0
- package/cjs/executor/index.js +26 -0
- package/cjs/executor/v2/RuntimeApiExecutorV2.js +21 -0
- package/cjs/executor/v2/StorageQueryExecutorV2.js +65 -0
- package/cjs/executor/v2/TxExecutorV2.js +20 -0
- package/cjs/extrinsic/extensions/ExtraSignedExtension.js +87 -0
- package/cjs/extrinsic/extensions/SignedExtension.js +41 -0
- package/cjs/extrinsic/extensions/index.js +19 -0
- package/cjs/extrinsic/extensions/known/ChargeAssetTxPayment.js +43 -0
- package/cjs/extrinsic/extensions/known/ChargeTransactionPayment.js +16 -0
- package/cjs/extrinsic/extensions/known/CheckGenesis.js +19 -0
- package/cjs/extrinsic/extensions/known/CheckMortality.js +90 -0
- package/cjs/extrinsic/extensions/known/CheckNonZeroSender.js +10 -0
- package/cjs/extrinsic/extensions/known/CheckNonce.js +33 -0
- package/cjs/extrinsic/extensions/known/CheckSpecVersion.js +19 -0
- package/cjs/extrinsic/extensions/known/CheckTxVersion.js +19 -0
- package/cjs/extrinsic/extensions/known/CheckWeight.js +10 -0
- package/cjs/extrinsic/extensions/known/PrevalidateAttests.js +11 -0
- package/cjs/extrinsic/extensions/known/index.js +25 -0
- package/cjs/extrinsic/index.js +18 -0
- package/cjs/extrinsic/submittable/BaseSubmittableExtrinsic.js +70 -0
- package/cjs/extrinsic/submittable/SubmittableExtrinsic.js +47 -0
- package/cjs/extrinsic/submittable/SubmittableExtrinsicV2.js +204 -0
- package/cjs/extrinsic/submittable/SubmittableResult.js +33 -0
- package/cjs/extrinsic/submittable/errors.js +16 -0
- package/cjs/extrinsic/submittable/fakeSigner.js +13 -0
- package/cjs/extrinsic/submittable/index.js +20 -0
- package/cjs/extrinsic/submittable/utils.js +20 -0
- package/cjs/index.js +21 -0
- package/cjs/json-rpc/JsonRpcClient.js +165 -0
- package/cjs/json-rpc/group/ChainHead/BlockUsage.js +24 -0
- package/cjs/json-rpc/group/ChainHead/ChainHead.js +603 -0
- package/cjs/json-rpc/group/ChainHead/error.js +59 -0
- package/cjs/json-rpc/group/ChainHead/index.js +18 -0
- package/cjs/json-rpc/group/ChainSpec.js +19 -0
- package/cjs/json-rpc/group/JsonRpcGroup.js +89 -0
- package/cjs/json-rpc/group/Transaction.js +25 -0
- package/cjs/json-rpc/group/TransactionWatch.js +17 -0
- package/cjs/json-rpc/group/index.js +21 -0
- package/cjs/json-rpc/index.js +20 -0
- package/cjs/json-rpc/scaledResponses.js +15 -0
- package/cjs/json-rpc/subscriptionsInfo.js +20 -0
- package/cjs/package.json +1 -0
- package/cjs/proxychain.js +27 -0
- package/cjs/storage/QueryableStorage.js +161 -0
- package/cjs/storage/index.js +17 -0
- package/cjs/types.js +2 -0
- package/client/BaseSubstrateClient.d.ts +65 -0
- package/client/BaseSubstrateClient.js +252 -0
- package/client/Dedot.d.ts +131 -0
- package/client/Dedot.js +246 -0
- package/client/DedotClient.d.ts +61 -0
- package/client/DedotClient.js +182 -0
- package/client/index.d.ts +2 -0
- package/client/index.js +2 -0
- package/executor/ConstantExecutor.d.ts +10 -0
- package/executor/ConstantExecutor.js +16 -0
- package/executor/ErrorExecutor.d.ts +10 -0
- package/executor/ErrorExecutor.js +42 -0
- package/executor/EventExecutor.d.ts +10 -0
- package/executor/EventExecutor.js +48 -0
- package/executor/Executor.d.ts +149 -0
- package/executor/Executor.js +38 -0
- package/executor/RuntimeApiExecutor.d.ts +27 -0
- package/executor/RuntimeApiExecutor.js +117 -0
- package/executor/StorageQueryExecutor.d.ts +14 -0
- package/executor/StorageQueryExecutor.js +111 -0
- package/executor/TxExecutor.d.ts +10 -0
- package/executor/TxExecutor.js +51 -0
- package/executor/index.d.ts +10 -0
- package/executor/index.js +10 -0
- package/executor/v2/RuntimeApiExecutorV2.d.ts +14 -0
- package/executor/v2/RuntimeApiExecutorV2.js +17 -0
- package/executor/v2/StorageQueryExecutorV2.d.ts +17 -0
- package/executor/v2/StorageQueryExecutorV2.js +61 -0
- package/executor/v2/TxExecutorV2.d.ts +11 -0
- package/executor/v2/TxExecutorV2.js +16 -0
- package/extrinsic/extensions/ExtraSignedExtension.d.ts +14 -0
- package/extrinsic/extensions/ExtraSignedExtension.js +60 -0
- package/extrinsic/extensions/SignedExtension.d.ts +40 -0
- package/extrinsic/extensions/SignedExtension.js +37 -0
- package/extrinsic/extensions/index.d.ts +3 -0
- package/extrinsic/extensions/index.js +3 -0
- package/extrinsic/extensions/known/ChargeAssetTxPayment.d.ts +14 -0
- package/extrinsic/extensions/known/ChargeAssetTxPayment.js +39 -0
- package/extrinsic/extensions/known/ChargeTransactionPayment.d.ts +6 -0
- package/extrinsic/extensions/known/ChargeTransactionPayment.js +12 -0
- package/extrinsic/extensions/known/CheckGenesis.d.ts +10 -0
- package/extrinsic/extensions/known/CheckGenesis.js +15 -0
- package/extrinsic/extensions/known/CheckMortality.d.ts +15 -0
- package/extrinsic/extensions/known/CheckMortality.js +86 -0
- package/extrinsic/extensions/known/CheckNonZeroSender.d.ts +6 -0
- package/extrinsic/extensions/known/CheckNonZeroSender.js +6 -0
- package/extrinsic/extensions/known/CheckNonce.d.ts +10 -0
- package/extrinsic/extensions/known/CheckNonce.js +29 -0
- package/extrinsic/extensions/known/CheckSpecVersion.d.ts +9 -0
- package/extrinsic/extensions/known/CheckSpecVersion.js +15 -0
- package/extrinsic/extensions/known/CheckTxVersion.d.ts +9 -0
- package/extrinsic/extensions/known/CheckTxVersion.js +15 -0
- package/extrinsic/extensions/known/CheckWeight.d.ts +6 -0
- package/extrinsic/extensions/known/CheckWeight.js +6 -0
- package/extrinsic/extensions/known/PrevalidateAttests.d.ts +7 -0
- package/extrinsic/extensions/known/PrevalidateAttests.js +7 -0
- package/extrinsic/extensions/known/index.d.ts +3 -0
- package/extrinsic/extensions/known/index.js +22 -0
- package/extrinsic/index.d.ts +2 -0
- package/extrinsic/index.js +2 -0
- package/extrinsic/submittable/BaseSubmittableExtrinsic.d.ts +17 -0
- package/extrinsic/submittable/BaseSubmittableExtrinsic.js +66 -0
- package/extrinsic/submittable/SubmittableExtrinsic.d.ts +12 -0
- package/extrinsic/submittable/SubmittableExtrinsic.js +43 -0
- package/extrinsic/submittable/SubmittableExtrinsicV2.d.ts +15 -0
- package/extrinsic/submittable/SubmittableExtrinsicV2.js +200 -0
- package/extrinsic/submittable/SubmittableResult.d.ts +19 -0
- package/extrinsic/submittable/SubmittableResult.js +29 -0
- package/extrinsic/submittable/errors.d.ts +11 -0
- package/extrinsic/submittable/errors.js +12 -0
- package/extrinsic/submittable/fakeSigner.d.ts +2 -0
- package/extrinsic/submittable/fakeSigner.js +10 -0
- package/extrinsic/submittable/index.d.ts +4 -0
- package/extrinsic/submittable/index.js +4 -0
- package/extrinsic/submittable/utils.d.ts +10 -0
- package/extrinsic/submittable/utils.js +15 -0
- package/index.d.ts +6 -0
- package/index.js +5 -0
- package/json-rpc/JsonRpcClient.d.ts +50 -0
- package/json-rpc/JsonRpcClient.js +160 -0
- package/json-rpc/group/ChainHead/BlockUsage.d.ts +11 -0
- package/json-rpc/group/ChainHead/BlockUsage.js +20 -0
- package/json-rpc/group/ChainHead/ChainHead.d.ts +70 -0
- package/json-rpc/group/ChainHead/ChainHead.js +599 -0
- package/json-rpc/group/ChainHead/error.d.ts +47 -0
- package/json-rpc/group/ChainHead/error.js +48 -0
- package/json-rpc/group/ChainHead/index.d.ts +2 -0
- package/json-rpc/group/ChainHead/index.js +2 -0
- package/json-rpc/group/ChainSpec.d.ts +10 -0
- package/json-rpc/group/ChainSpec.js +15 -0
- package/json-rpc/group/JsonRpcGroup.d.ts +74 -0
- package/json-rpc/group/JsonRpcGroup.js +85 -0
- package/json-rpc/group/Transaction.d.ts +11 -0
- package/json-rpc/group/Transaction.js +21 -0
- package/json-rpc/group/TransactionWatch.d.ts +10 -0
- package/json-rpc/group/TransactionWatch.js +13 -0
- package/json-rpc/group/index.d.ts +5 -0
- package/json-rpc/group/index.js +5 -0
- package/json-rpc/index.d.ts +4 -0
- package/json-rpc/index.js +4 -0
- package/json-rpc/scaledResponses.d.ts +2 -0
- package/json-rpc/scaledResponses.js +12 -0
- package/json-rpc/subscriptionsInfo.d.ts +2 -0
- package/json-rpc/subscriptionsInfo.js +17 -0
- package/package.json +54 -0
- package/proxychain.d.ts +14 -0
- package/proxychain.js +23 -0
- package/storage/QueryableStorage.d.ts +35 -0
- package/storage/QueryableStorage.js +157 -0
- package/storage/index.d.ts +1 -0
- package/storage/index.js +1 -0
- package/types.d.ts +120 -0
- package/types.js +1 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Properties } from '@dedot/types/json-rpc';
|
|
2
|
+
import { HexString } from '@dedot/utils';
|
|
3
|
+
import { IJsonRpcClient } from '../../types.js';
|
|
4
|
+
import { JsonRpcGroup, JsonRpcGroupOptions } from './JsonRpcGroup.js';
|
|
5
|
+
export declare class ChainSpec extends JsonRpcGroup {
|
|
6
|
+
constructor(client: IJsonRpcClient, options?: Partial<JsonRpcGroupOptions>);
|
|
7
|
+
chainName(): Promise<string>;
|
|
8
|
+
genesisHash(): Promise<HexString>;
|
|
9
|
+
properties(): Promise<Properties>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { JsonRpcGroup } from './JsonRpcGroup.js';
|
|
2
|
+
export class ChainSpec extends JsonRpcGroup {
|
|
3
|
+
constructor(client, options) {
|
|
4
|
+
super(client, { prefix: 'chainSpec', supportedVersions: ['unstable', 'v1'], ...options });
|
|
5
|
+
}
|
|
6
|
+
async chainName() {
|
|
7
|
+
return this.send('chainName');
|
|
8
|
+
}
|
|
9
|
+
async genesisHash() {
|
|
10
|
+
return this.send('genesisHash');
|
|
11
|
+
}
|
|
12
|
+
async properties() {
|
|
13
|
+
return this.send('properties');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { EventEmitter } from '@dedot/utils';
|
|
2
|
+
import { IJsonRpcClient } from '../../types.js';
|
|
3
|
+
export type JsonRpcGroupVersion = 'unstable' | `v${number}`;
|
|
4
|
+
export interface JsonRpcGroupOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Prefix of the json-rpc group.
|
|
7
|
+
* E.g: chainHead, chainSpec, archive, etc.
|
|
8
|
+
*
|
|
9
|
+
* According to JSON-RPC v2 Spec: https://paritytech.github.io/json-rpc-interface-spec/grouping-functions-and-node-capabilities.html#grouping-functions-and-node-capabilities
|
|
10
|
+
*
|
|
11
|
+
* Note: The prefix should not contain any `_` character.
|
|
12
|
+
*/
|
|
13
|
+
prefix: string;
|
|
14
|
+
/**
|
|
15
|
+
* By default, the version is automatically detected from the available rpc-methods.
|
|
16
|
+
* If a fixed version is provided, it will be forced to use instead.
|
|
17
|
+
*/
|
|
18
|
+
fixedVersion?: JsonRpcGroupVersion;
|
|
19
|
+
/**
|
|
20
|
+
* List of rpc-methods to use for version detection.
|
|
21
|
+
* If not provided, the list will be fetched from the node/server.
|
|
22
|
+
* This is helpful when the node does not support `rpc_methods` method
|
|
23
|
+
* Or if we want to share the same rpc-methods list across multiple groups.
|
|
24
|
+
*/
|
|
25
|
+
rpcMethods?: string[];
|
|
26
|
+
/**
|
|
27
|
+
* List of supported versions.
|
|
28
|
+
* If provided, the detected version must be in this list else an error will be thrown.
|
|
29
|
+
* This is helpful when we want to verify behaviour of new version before using/support it.
|
|
30
|
+
* If not provided, any detected version will be used.
|
|
31
|
+
*/
|
|
32
|
+
supportedVersions?: JsonRpcGroupVersion[];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @name JsonRpcGroup
|
|
36
|
+
* A group of json-rpc methods with a common prefix.
|
|
37
|
+
*
|
|
38
|
+
* JSON-RPC V2: https://paritytech.github.io/json-rpc-interface-spec/grouping-functions-and-node-capabilities.html#grouping-functions-and-node-capabilities
|
|
39
|
+
*/
|
|
40
|
+
export declare class JsonRpcGroup<Event extends string = string> extends EventEmitter<Event> {
|
|
41
|
+
#private;
|
|
42
|
+
client: IJsonRpcClient;
|
|
43
|
+
options: JsonRpcGroupOptions;
|
|
44
|
+
constructor(client: IJsonRpcClient, options: JsonRpcGroupOptions);
|
|
45
|
+
/**
|
|
46
|
+
* Check if the group is supported by the connected JSON-RPC server.
|
|
47
|
+
*/
|
|
48
|
+
supported(): Promise<boolean>;
|
|
49
|
+
/**
|
|
50
|
+
* Send a json-rpc request, note the method should not contain the prefix and version parts.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const client = await JsonRpcClient.new('wss://rpc.polkadot.io');
|
|
55
|
+
* const achieve = new JsonRpcGroup(client, { prefix: 'archive', supportedVersions: ['unstable'] });
|
|
56
|
+
*
|
|
57
|
+
* const finalizedHeight = await achieve.send<number>('finalizedHeight'); // sending archive_unstable_finalizedHeight
|
|
58
|
+
* console.log(finalizedHeight);
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @param method
|
|
62
|
+
* @param params
|
|
63
|
+
*/
|
|
64
|
+
send<T = any>(method: string, ...params: any[]): Promise<T>;
|
|
65
|
+
/**
|
|
66
|
+
* The prefix of the group
|
|
67
|
+
*/
|
|
68
|
+
get prefix(): string;
|
|
69
|
+
/**
|
|
70
|
+
* Detect & return the version of the group.
|
|
71
|
+
* This will be used to construct the json-rpc method name.
|
|
72
|
+
*/
|
|
73
|
+
version(): Promise<JsonRpcGroupVersion>;
|
|
74
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { EventEmitter } from '@dedot/utils';
|
|
2
|
+
/**
|
|
3
|
+
* @name JsonRpcGroup
|
|
4
|
+
* A group of json-rpc methods with a common prefix.
|
|
5
|
+
*
|
|
6
|
+
* JSON-RPC V2: https://paritytech.github.io/json-rpc-interface-spec/grouping-functions-and-node-capabilities.html#grouping-functions-and-node-capabilities
|
|
7
|
+
*/
|
|
8
|
+
export class JsonRpcGroup extends EventEmitter {
|
|
9
|
+
client;
|
|
10
|
+
options;
|
|
11
|
+
#detectedVersion;
|
|
12
|
+
constructor(client, options) {
|
|
13
|
+
super();
|
|
14
|
+
this.client = client;
|
|
15
|
+
this.options = options;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Check if the group is supported by the connected JSON-RPC server.
|
|
19
|
+
*/
|
|
20
|
+
async supported() {
|
|
21
|
+
try {
|
|
22
|
+
const detectedVersion = await this.#detectVersion();
|
|
23
|
+
const { supportedVersions } = this.options;
|
|
24
|
+
// if there aren't any specific supported versions, then any detected version is supported
|
|
25
|
+
if (!supportedVersions || supportedVersions.length === 0)
|
|
26
|
+
return true;
|
|
27
|
+
return supportedVersions.includes(detectedVersion);
|
|
28
|
+
}
|
|
29
|
+
catch { }
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Send a json-rpc request, note the method should not contain the prefix and version parts.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const client = await JsonRpcClient.new('wss://rpc.polkadot.io');
|
|
38
|
+
* const achieve = new JsonRpcGroup(client, { prefix: 'archive', supportedVersions: ['unstable'] });
|
|
39
|
+
*
|
|
40
|
+
* const finalizedHeight = await achieve.send<number>('finalizedHeight'); // sending archive_unstable_finalizedHeight
|
|
41
|
+
* console.log(finalizedHeight);
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @param method
|
|
45
|
+
* @param params
|
|
46
|
+
*/
|
|
47
|
+
async send(method, ...params) {
|
|
48
|
+
const rpcMethod = `${this.prefix}_${await this.version()}_${method}`;
|
|
49
|
+
return this.client.rpc[rpcMethod](...params);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The prefix of the group
|
|
53
|
+
*/
|
|
54
|
+
get prefix() {
|
|
55
|
+
return this.options.prefix;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Detect & return the version of the group.
|
|
59
|
+
* This will be used to construct the json-rpc method name.
|
|
60
|
+
*/
|
|
61
|
+
async version() {
|
|
62
|
+
const { fixedVersion, supportedVersions } = this.options;
|
|
63
|
+
if (fixedVersion)
|
|
64
|
+
return fixedVersion;
|
|
65
|
+
const detectedVersion = await this.#detectVersion();
|
|
66
|
+
if (supportedVersions && supportedVersions.length > 0 && !supportedVersions.includes(detectedVersion)) {
|
|
67
|
+
throw new Error(`Detected version ${detectedVersion} is not supported`);
|
|
68
|
+
}
|
|
69
|
+
return detectedVersion;
|
|
70
|
+
}
|
|
71
|
+
async #detectVersion() {
|
|
72
|
+
if (!this.#detectedVersion) {
|
|
73
|
+
this.#detectedVersion = await this.#doDetectVersion();
|
|
74
|
+
}
|
|
75
|
+
return this.#detectedVersion;
|
|
76
|
+
}
|
|
77
|
+
async #doDetectVersion() {
|
|
78
|
+
const rpcMethods = this.options.rpcMethods || (await this.client.rpc.rpc_methods()).methods;
|
|
79
|
+
const prefixedMethods = rpcMethods.filter((method) => method.startsWith(`${this.prefix}_`));
|
|
80
|
+
if (prefixedMethods.length === 0) {
|
|
81
|
+
throw new Error(`No methods found with prefix ${this.prefix}`);
|
|
82
|
+
}
|
|
83
|
+
return prefixedMethods[0].split('_')[1];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Unsub } from '@dedot/types';
|
|
2
|
+
import { OperationId } from '@dedot/types/json-rpc';
|
|
3
|
+
import { HexString } from '@dedot/utils';
|
|
4
|
+
import { IJsonRpcClient, TxBroadcaster } from '../../types.js';
|
|
5
|
+
import { JsonRpcGroup, JsonRpcGroupOptions } from './JsonRpcGroup.js';
|
|
6
|
+
export declare class Transaction extends JsonRpcGroup implements TxBroadcaster {
|
|
7
|
+
constructor(client: IJsonRpcClient, options?: Partial<JsonRpcGroupOptions>);
|
|
8
|
+
broadcastTx(tx: HexString): Promise<Unsub>;
|
|
9
|
+
broadcast(tx: string): Promise<OperationId>;
|
|
10
|
+
stop(operationId: OperationId): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { assert } from '@dedot/utils';
|
|
2
|
+
import { JsonRpcGroup } from './JsonRpcGroup.js';
|
|
3
|
+
export class Transaction extends JsonRpcGroup {
|
|
4
|
+
constructor(client, options) {
|
|
5
|
+
super(client, { prefix: 'transaction', supportedVersions: ['unstable', 'v1'], ...options });
|
|
6
|
+
}
|
|
7
|
+
async broadcastTx(tx) {
|
|
8
|
+
const operationId = await this.broadcast(tx);
|
|
9
|
+
return () => {
|
|
10
|
+
return this.stop(operationId);
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
async broadcast(tx) {
|
|
14
|
+
const operationId = await this.send('broadcast', tx);
|
|
15
|
+
assert(operationId, 'Maximum number of broadcasted transactions has been reached');
|
|
16
|
+
return operationId;
|
|
17
|
+
}
|
|
18
|
+
stop(operationId) {
|
|
19
|
+
return this.send('stop', operationId);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Callback, Unsub } from '@dedot/types';
|
|
2
|
+
import { TransactionWatchEvent } from '@dedot/types/json-rpc';
|
|
3
|
+
import { HexString } from '@dedot/utils';
|
|
4
|
+
import { IJsonRpcClient, TxBroadcaster } from '../../types.js';
|
|
5
|
+
import { JsonRpcGroup, JsonRpcGroupOptions } from './JsonRpcGroup.js';
|
|
6
|
+
export declare class TransactionWatch extends JsonRpcGroup implements TxBroadcaster {
|
|
7
|
+
constructor(client: IJsonRpcClient, options?: Partial<JsonRpcGroupOptions>);
|
|
8
|
+
broadcastTx(tx: HexString): Promise<Unsub>;
|
|
9
|
+
submitAndWatch(tx: HexString, callback: Callback<TransactionWatchEvent>): Promise<Unsub>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { noop } from '@dedot/utils';
|
|
2
|
+
import { JsonRpcGroup } from './JsonRpcGroup.js';
|
|
3
|
+
export class TransactionWatch extends JsonRpcGroup {
|
|
4
|
+
constructor(client, options) {
|
|
5
|
+
super(client, { prefix: 'transactionWatch', supportedVersions: ['unstable'], ...options });
|
|
6
|
+
}
|
|
7
|
+
broadcastTx(tx) {
|
|
8
|
+
return this.submitAndWatch(tx, noop);
|
|
9
|
+
}
|
|
10
|
+
async submitAndWatch(tx, callback) {
|
|
11
|
+
return this.send('submitAndWatch', tx, callback);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { $ApplyExtrinsicResult, $Header, $Metadata, $SignedBlock, $TransactionStatus, $VersionedFinalityProof, } from '@dedot/codecs';
|
|
2
|
+
export const scaledResponses = {
|
|
3
|
+
system_dryRun: $ApplyExtrinsicResult,
|
|
4
|
+
state_getMetadata: $Metadata,
|
|
5
|
+
chain_getHeader: $Header,
|
|
6
|
+
chain_getBlock: $SignedBlock,
|
|
7
|
+
chain_subscribeAllHeads: $Header,
|
|
8
|
+
chain_subscribeNewHeads: $Header,
|
|
9
|
+
chain_subscribeFinalizedHeads: $Header,
|
|
10
|
+
author_submitAndWatchExtrinsic: $TransactionStatus,
|
|
11
|
+
beefy_subscribeJustifications: $VersionedFinalityProof,
|
|
12
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const subscriptionsInfo = {
|
|
2
|
+
author_submitAndWatchExtrinsic: ['author_extrinsicUpdate', 'author_unwatchExtrinsic'],
|
|
3
|
+
state_subscribeRuntimeVersion: ['state_runtimeVersion', 'state_unsubscribeRuntimeVersion'],
|
|
4
|
+
state_subscribeStorage: ['state_storage', 'state_unsubscribeStorage'],
|
|
5
|
+
chain_subscribeAllHeads: ['chain_allHead', 'chain_unsubscribeAllHeads'],
|
|
6
|
+
chain_subscribeNewHeads: ['chain_newHead', 'chain_unsubscribeNewHeads'],
|
|
7
|
+
chain_subscribeFinalizedHeads: ['chain_finalizedHead', 'chain_unsubscribeFinalizedHeads'],
|
|
8
|
+
grandpa_subscribeJustifications: ['grandpa_justifications', 'grandpa_unsubscribeJustifications'],
|
|
9
|
+
beefy_subscribeJustifications: ['beefy_justifications', 'beefy_unsubscribeJustifications'],
|
|
10
|
+
chainHead_unstable_follow: ['chainHead_unstable_followEvent', 'chainHead_unstable_unfollow'],
|
|
11
|
+
chainHead_v1_follow: ['chainHead_v1_followEvent', 'chainHead_v1_unfollow'],
|
|
12
|
+
transactionWatch_unstable_submitAndWatch: [
|
|
13
|
+
'transactionWatch_unstable_watchEvent',
|
|
14
|
+
'transactionWatch_unstable_unwatch',
|
|
15
|
+
],
|
|
16
|
+
transactionWatch_v1_submitAndWatch: ['transactionWatch_v1_watchEvent', 'transactionWatch_v1_unwatch'],
|
|
17
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dedot/api",
|
|
3
|
+
"version": "0.0.1-alpha.32",
|
|
4
|
+
"description": "A delightful JavaScript/TypeScript client for Polkadot & Substrate",
|
|
5
|
+
"author": "Thang X. Vu <thang@coongcrafts.io>",
|
|
6
|
+
"homepage": "https://github.com/dedotdev/dedot",
|
|
7
|
+
"repository": {
|
|
8
|
+
"directory": "packages/api",
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/dedotdev/dedot.git"
|
|
11
|
+
},
|
|
12
|
+
"main": "./cjs/index.js",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"sideEffects": false,
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@dedot/codecs": "0.0.1-alpha.32",
|
|
17
|
+
"@dedot/providers": "0.0.1-alpha.32",
|
|
18
|
+
"@dedot/runtime-specs": "0.0.1-alpha.32",
|
|
19
|
+
"@dedot/shape": "0.0.1-alpha.32",
|
|
20
|
+
"@dedot/storage": "0.0.1-alpha.32",
|
|
21
|
+
"@dedot/types": "0.0.1-alpha.32",
|
|
22
|
+
"@dedot/utils": "0.0.1-alpha.32"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc --project tsconfig.build.json && tsc --project tsconfig.build.cjs.json",
|
|
26
|
+
"clean": "rm -rf ./dist && rm -rf ./tsconfig.tsbuildinfo ./tsconfig.build.tsbuildinfo",
|
|
27
|
+
"test": "vitest --watch=false"
|
|
28
|
+
},
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./index.d.ts",
|
|
32
|
+
"import": "./index.js",
|
|
33
|
+
"require": "./cjs/index.js",
|
|
34
|
+
"default": "./index.js"
|
|
35
|
+
},
|
|
36
|
+
"./chaintypes": {
|
|
37
|
+
"types": "./chaintypes/index.d.ts",
|
|
38
|
+
"import": "./chaintypes/index.js",
|
|
39
|
+
"require": "./cjs/chaintypes/index.js",
|
|
40
|
+
"default": "./chaintypes/index.js"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public",
|
|
45
|
+
"directory": "dist"
|
|
46
|
+
},
|
|
47
|
+
"license": "Apache-2.0",
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@polkadot/types": "^11.0.2"
|
|
50
|
+
},
|
|
51
|
+
"gitHead": "43501104eee360a19ae18a70fe506e16d9357835",
|
|
52
|
+
"module": "./index.js",
|
|
53
|
+
"types": "./index.d.ts"
|
|
54
|
+
}
|
package/proxychain.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { GenericSubstrateApi } from '@dedot/types';
|
|
2
|
+
import { Executor } from './executor/index.js';
|
|
3
|
+
export interface Carrier<ChainApi extends GenericSubstrateApi> {
|
|
4
|
+
executor: Executor<ChainApi>;
|
|
5
|
+
chain?: string[];
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Create a chain of proxy objects
|
|
9
|
+
*
|
|
10
|
+
* @param carrier
|
|
11
|
+
* @param currentLevel
|
|
12
|
+
* @param maxLevel
|
|
13
|
+
*/
|
|
14
|
+
export declare const newProxyChain: <ChainApi extends GenericSubstrateApi<import("@dedot/types").RpcVersion>>(carrier: Carrier<ChainApi>, currentLevel?: number, maxLevel?: number) => unknown;
|
package/proxychain.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a chain of proxy objects
|
|
3
|
+
*
|
|
4
|
+
* @param carrier
|
|
5
|
+
* @param currentLevel
|
|
6
|
+
* @param maxLevel
|
|
7
|
+
*/
|
|
8
|
+
export const newProxyChain = (carrier, currentLevel = 1, maxLevel = 3) => {
|
|
9
|
+
const { executor, chain = [] } = carrier;
|
|
10
|
+
if (currentLevel === maxLevel) {
|
|
11
|
+
return executor.execute(...chain);
|
|
12
|
+
}
|
|
13
|
+
return new Proxy(carrier, {
|
|
14
|
+
get(target, property, receiver) {
|
|
15
|
+
if (!target.chain) {
|
|
16
|
+
target.chain = [];
|
|
17
|
+
}
|
|
18
|
+
const { chain } = target;
|
|
19
|
+
chain.push(property.toString());
|
|
20
|
+
return newProxyChain(target, currentLevel + 1, maxLevel);
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { PortableRegistry, PalletDefLatest, StorageDataLike, StorageEntryLatest, StorageKey, PrefixedStorageKey } from '@dedot/codecs';
|
|
2
|
+
/**
|
|
3
|
+
* @name QueryableStorage
|
|
4
|
+
* @description A helper to encode key & decode value for a storage entry
|
|
5
|
+
*/
|
|
6
|
+
export declare class QueryableStorage {
|
|
7
|
+
#private;
|
|
8
|
+
readonly registry: PortableRegistry;
|
|
9
|
+
readonly palletName: string;
|
|
10
|
+
readonly storageItem: string;
|
|
11
|
+
readonly pallet: PalletDefLatest;
|
|
12
|
+
readonly storageEntry: StorageEntryLatest;
|
|
13
|
+
constructor(registry: PortableRegistry, palletName: string, storageItem: string);
|
|
14
|
+
get prefixKey(): PrefixedStorageKey;
|
|
15
|
+
get prefixKeyAsU8a(): Uint8Array;
|
|
16
|
+
/**
|
|
17
|
+
* Encode plain key input to raw/bytes storage key
|
|
18
|
+
*
|
|
19
|
+
* @param keyInput
|
|
20
|
+
*/
|
|
21
|
+
encodeKey(keyInput?: any): StorageKey;
|
|
22
|
+
/**
|
|
23
|
+
* Decode storage key to plain key input
|
|
24
|
+
* Only storage keys that hashed by `twox64Concat`, `blake2_128Concat`, or `identity` can be decoded
|
|
25
|
+
*
|
|
26
|
+
* @param key
|
|
27
|
+
*/
|
|
28
|
+
decodeKey(key: StorageKey): any;
|
|
29
|
+
/**
|
|
30
|
+
* Decode raw/bytes storage data to plain value
|
|
31
|
+
*
|
|
32
|
+
* @param raw
|
|
33
|
+
*/
|
|
34
|
+
decodeValue(raw?: StorageDataLike | null): any;
|
|
35
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { $StorageData, } from '@dedot/codecs';
|
|
2
|
+
import { assert, HASHERS, hexAddPrefix, UnknownApiError } from '@dedot/utils';
|
|
3
|
+
import { xxhashAsU8a, hexToU8a, stringCamelCase, concatU8a, u8aToHex } from '@dedot/utils';
|
|
4
|
+
// https://github.com/polkadot-js/api/blob/0982f68507942c5bf6f751f662804344e211b289/packages/types/src/primitive/StorageKey.ts#L29-L38
|
|
5
|
+
const HASHER_INFO = {
|
|
6
|
+
blake2_128: [16, false],
|
|
7
|
+
blake2_256: [32, false],
|
|
8
|
+
blake2_128Concat: [16, true],
|
|
9
|
+
twox128: [16, false],
|
|
10
|
+
twox256: [32, false],
|
|
11
|
+
twox64Concat: [8, true],
|
|
12
|
+
identity: [0, true],
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* @name QueryableStorage
|
|
16
|
+
* @description A helper to encode key & decode value for a storage entry
|
|
17
|
+
*/
|
|
18
|
+
export class QueryableStorage {
|
|
19
|
+
registry;
|
|
20
|
+
palletName;
|
|
21
|
+
storageItem;
|
|
22
|
+
pallet;
|
|
23
|
+
storageEntry;
|
|
24
|
+
constructor(registry, palletName, storageItem) {
|
|
25
|
+
this.registry = registry;
|
|
26
|
+
this.palletName = palletName;
|
|
27
|
+
this.storageItem = storageItem;
|
|
28
|
+
this.pallet = this.#getPallet();
|
|
29
|
+
this.storageEntry = this.#getStorageEntry();
|
|
30
|
+
}
|
|
31
|
+
get prefixKey() {
|
|
32
|
+
return u8aToHex(this.prefixKeyAsU8a);
|
|
33
|
+
}
|
|
34
|
+
get prefixKeyAsU8a() {
|
|
35
|
+
const palletNameHash = xxhashAsU8a(this.pallet.name, 128);
|
|
36
|
+
const storageItemHash = xxhashAsU8a(this.storageEntry.name, 128);
|
|
37
|
+
return concatU8a(palletNameHash, storageItemHash);
|
|
38
|
+
}
|
|
39
|
+
#getStorageMapInfo(type) {
|
|
40
|
+
assert(type.tag === 'Map');
|
|
41
|
+
const { hashers, keyTypeId } = type.value;
|
|
42
|
+
let keyTypeIds = [keyTypeId];
|
|
43
|
+
if (hashers.length > 1) {
|
|
44
|
+
const { type } = this.registry.findType(keyTypeId);
|
|
45
|
+
assert(type.tag === 'Tuple', 'Key type should be a tuple!');
|
|
46
|
+
keyTypeIds = type.value.fields;
|
|
47
|
+
}
|
|
48
|
+
return { hashers, keyTypeIds };
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Encode plain key input to raw/bytes storage key
|
|
52
|
+
*
|
|
53
|
+
* @param keyInput
|
|
54
|
+
*/
|
|
55
|
+
encodeKey(keyInput) {
|
|
56
|
+
const { type } = this.storageEntry;
|
|
57
|
+
if (type.tag === 'Plain') {
|
|
58
|
+
return this.prefixKey;
|
|
59
|
+
}
|
|
60
|
+
else if (type.tag === 'Map') {
|
|
61
|
+
const { hashers, keyTypeIds } = this.#getStorageMapInfo(type);
|
|
62
|
+
const extractedInputs = this.#extractRequiredKeyInputs(keyInput, hashers.length);
|
|
63
|
+
const keyParts = keyTypeIds.map((keyId, index) => {
|
|
64
|
+
const input = extractedInputs[index];
|
|
65
|
+
const hasher = HASHERS[hashers[index]];
|
|
66
|
+
const $keyCodec = this.registry.findCodec(keyId);
|
|
67
|
+
return hasher($keyCodec.tryEncode(input));
|
|
68
|
+
});
|
|
69
|
+
return u8aToHex(concatU8a(this.prefixKeyAsU8a, ...keyParts));
|
|
70
|
+
}
|
|
71
|
+
throw Error(`Invalid storage entry type: ${type}`);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Decode storage key to plain key input
|
|
75
|
+
* Only storage keys that hashed by `twox64Concat`, `blake2_128Concat`, or `identity` can be decoded
|
|
76
|
+
*
|
|
77
|
+
* @param key
|
|
78
|
+
*/
|
|
79
|
+
decodeKey(key) {
|
|
80
|
+
const { type } = this.storageEntry;
|
|
81
|
+
if (type.tag === 'Plain') {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
else if (type.tag === 'Map') {
|
|
85
|
+
const prefix = this.prefixKey;
|
|
86
|
+
if (!key.startsWith(prefix)) {
|
|
87
|
+
throw new Error(`Storage key does not match this storage entry (${this.palletName}.${this.storageItem})`);
|
|
88
|
+
}
|
|
89
|
+
const { hashers, keyTypeIds } = this.#getStorageMapInfo(type);
|
|
90
|
+
let keyData = hexToU8a(hexAddPrefix(key.slice(prefix.length)));
|
|
91
|
+
const results = keyTypeIds.map((keyId, index) => {
|
|
92
|
+
const [hashLen, canDecode] = HASHER_INFO[hashers[index]];
|
|
93
|
+
if (!canDecode)
|
|
94
|
+
throw new Error('Cannot decode storage key');
|
|
95
|
+
const $keyCodec = this.registry.findCodec(keyId);
|
|
96
|
+
keyData = keyData.slice(hashLen);
|
|
97
|
+
const result = $keyCodec.tryDecode(keyData);
|
|
98
|
+
const encoded = $keyCodec.tryEncode(result);
|
|
99
|
+
keyData = keyData.slice(encoded.length);
|
|
100
|
+
return result;
|
|
101
|
+
});
|
|
102
|
+
return hashers.length > 1 ? results : results[0];
|
|
103
|
+
}
|
|
104
|
+
throw Error(`Invalid storage entry type: ${type}`);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Decode raw/bytes storage data to plain value
|
|
108
|
+
*
|
|
109
|
+
* @param raw
|
|
110
|
+
*/
|
|
111
|
+
decodeValue(raw) {
|
|
112
|
+
const { modifier, type: { value: { valueTypeId }, }, default: defaultValue, } = this.storageEntry;
|
|
113
|
+
if (raw === null || raw === undefined) {
|
|
114
|
+
if (modifier === 'Optional') {
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
else if (modifier === 'Default') {
|
|
118
|
+
return this.registry.findCodec(valueTypeId).tryDecode(hexToU8a(defaultValue));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
return this.registry.findCodec(valueTypeId).tryDecode($StorageData.tryEncode(raw));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
#extractRequiredKeyInputs(keyInput, numberOfValue) {
|
|
126
|
+
if (numberOfValue === 0) {
|
|
127
|
+
return [];
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
if (keyInput === undefined) {
|
|
131
|
+
throw new Error(`Invalid key inputs, required ${numberOfValue} input(s)`);
|
|
132
|
+
}
|
|
133
|
+
if (numberOfValue === 1) {
|
|
134
|
+
return [keyInput];
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
if (!Array.isArray(keyInput)) {
|
|
138
|
+
throw new Error(`Input should be an array with ${numberOfValue} value(s)`);
|
|
139
|
+
}
|
|
140
|
+
if (keyInput.length !== numberOfValue) {
|
|
141
|
+
throw new Error(`Mismatch key inputs length, required an array of ${numberOfValue} value(s)`);
|
|
142
|
+
}
|
|
143
|
+
return keyInput.slice(0, numberOfValue);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
#getPallet() {
|
|
148
|
+
const targetPallet = this.registry.metadata.pallets.find((p) => stringCamelCase(p.name) === stringCamelCase(this.palletName));
|
|
149
|
+
assert(targetPallet, new UnknownApiError(`Pallet not found: ${this.palletName}`));
|
|
150
|
+
return targetPallet;
|
|
151
|
+
}
|
|
152
|
+
#getStorageEntry() {
|
|
153
|
+
const targetEntry = this.pallet.storage?.entries?.find((entry) => stringCamelCase(entry.name) === stringCamelCase(this.storageItem));
|
|
154
|
+
assert(targetEntry, new UnknownApiError(`Storage item not found: ${this.storageItem}`));
|
|
155
|
+
return targetEntry;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './QueryableStorage.js';
|
package/storage/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './QueryableStorage.js';
|