dedot 0.0.1-next.fecbe32d.13 → 0.1.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/README.md +80 -86
- package/bin/dedot +3 -0
- package/chaintypes/index.d.ts +1 -1
- package/chaintypes/index.js +1 -1
- package/cjs/chaintypes/index.js +1 -1
- package/cjs/{json-rpc → codecs}/index.js +1 -1
- package/cjs/{storage → contracts}/index.js +1 -1
- package/cjs/index.js +6 -15
- package/cjs/runtime-specs/index.js +17 -0
- package/cjs/{chaintypes/substrate → shape}/index.js +1 -1
- package/cjs/{client → types}/index.js +1 -1
- package/cjs/types/json-rpc/index.js +17 -0
- package/cjs/utils/index.js +17 -0
- package/codecs/index.d.ts +1 -0
- package/codecs/index.js +1 -0
- package/contracts/index.d.ts +1 -0
- package/contracts/index.js +1 -0
- package/index.d.ts +2 -9
- package/index.js +2 -9
- package/package.json +76 -36
- package/runtime-specs/index.d.ts +1 -0
- package/runtime-specs/index.js +1 -0
- package/shape/index.d.ts +1 -0
- package/shape/index.js +1 -0
- package/types/index.d.ts +1 -0
- package/types/index.js +1 -0
- package/types/json-rpc/index.d.ts +1 -0
- package/types/json-rpc/index.js +1 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/chaintypes/substrate/consts.d.ts +0 -1971
- package/chaintypes/substrate/consts.js +0 -1
- package/chaintypes/substrate/errors.d.ts +0 -3337
- package/chaintypes/substrate/errors.js +0 -1
- package/chaintypes/substrate/events.d.ts +0 -4777
- package/chaintypes/substrate/events.js +0 -1
- package/chaintypes/substrate/index.d.ts +0 -18
- package/chaintypes/substrate/index.js +0 -1
- package/chaintypes/substrate/json-rpc.d.ts +0 -3
- package/chaintypes/substrate/json-rpc.js +0 -1
- package/chaintypes/substrate/query.d.ts +0 -3447
- package/chaintypes/substrate/query.js +0 -1
- package/chaintypes/substrate/runtime.d.ts +0 -708
- package/chaintypes/substrate/runtime.js +0 -1
- package/chaintypes/substrate/tx.d.ts +0 -8800
- package/chaintypes/substrate/tx.js +0 -1
- package/chaintypes/substrate/types.d.ts +0 -20332
- package/chaintypes/substrate/types.js +0 -1
- package/cjs/chaintypes/substrate/consts.js +0 -2
- package/cjs/chaintypes/substrate/errors.js +0 -2
- package/cjs/chaintypes/substrate/events.js +0 -2
- package/cjs/chaintypes/substrate/json-rpc.js +0 -2
- package/cjs/chaintypes/substrate/query.js +0 -2
- package/cjs/chaintypes/substrate/runtime.js +0 -2
- package/cjs/chaintypes/substrate/tx.js +0 -2
- package/cjs/chaintypes/substrate/types.js +0 -2
- package/cjs/client/BaseSubstrateClient.js +0 -247
- package/cjs/client/Dedot.js +0 -257
- package/cjs/executor/ConstantExecutor.js +0 -20
- package/cjs/executor/ErrorExecutor.js +0 -46
- package/cjs/executor/EventExecutor.js +0 -52
- package/cjs/executor/Executor.js +0 -45
- package/cjs/executor/RuntimeApiExecutor.js +0 -113
- package/cjs/executor/StorageQueryExecutor.js +0 -109
- package/cjs/executor/TxExecutor.js +0 -158
- package/cjs/executor/index.js +0 -23
- package/cjs/extrinsic/SubmittableResult.js +0 -33
- package/cjs/extrinsic/extensions/ExtraSignedExtension.js +0 -87
- package/cjs/extrinsic/extensions/SignedExtension.js +0 -41
- package/cjs/extrinsic/extensions/index.js +0 -19
- package/cjs/extrinsic/extensions/known/ChargeAssetTxPayment.js +0 -43
- package/cjs/extrinsic/extensions/known/ChargeTransactionPayment.js +0 -16
- package/cjs/extrinsic/extensions/known/CheckGenesis.js +0 -19
- package/cjs/extrinsic/extensions/known/CheckMortality.js +0 -70
- package/cjs/extrinsic/extensions/known/CheckNonZeroSender.js +0 -10
- package/cjs/extrinsic/extensions/known/CheckNonce.js +0 -33
- package/cjs/extrinsic/extensions/known/CheckSpecVersion.js +0 -19
- package/cjs/extrinsic/extensions/known/CheckTxVersion.js +0 -19
- package/cjs/extrinsic/extensions/known/CheckWeight.js +0 -10
- package/cjs/extrinsic/extensions/known/PrevalidateAttests.js +0 -11
- package/cjs/extrinsic/extensions/known/index.js +0 -25
- package/cjs/extrinsic/index.js +0 -18
- package/cjs/json-rpc/JsonRpcClient.js +0 -157
- package/cjs/proxychain.js +0 -27
- package/cjs/storage/QueryableStorage.js +0 -161
- package/cjs/types.js +0 -2
- package/client/BaseSubstrateClient.d.ts +0 -65
- package/client/BaseSubstrateClient.js +0 -242
- package/client/Dedot.d.ts +0 -130
- package/client/Dedot.js +0 -253
- package/client/index.d.ts +0 -1
- package/client/index.js +0 -1
- package/executor/ConstantExecutor.d.ts +0 -11
- package/executor/ConstantExecutor.js +0 -16
- package/executor/ErrorExecutor.d.ts +0 -11
- package/executor/ErrorExecutor.js +0 -42
- package/executor/EventExecutor.d.ts +0 -11
- package/executor/EventExecutor.js +0 -48
- package/executor/Executor.d.ts +0 -150
- package/executor/Executor.js +0 -41
- package/executor/RuntimeApiExecutor.d.ts +0 -19
- package/executor/RuntimeApiExecutor.js +0 -109
- package/executor/StorageQueryExecutor.d.ts +0 -13
- package/executor/StorageQueryExecutor.js +0 -105
- package/executor/TxExecutor.d.ts +0 -48
- package/executor/TxExecutor.js +0 -152
- package/executor/index.d.ts +0 -7
- package/executor/index.js +0 -7
- package/extrinsic/SubmittableResult.d.ts +0 -19
- package/extrinsic/SubmittableResult.js +0 -29
- package/extrinsic/extensions/ExtraSignedExtension.d.ts +0 -14
- package/extrinsic/extensions/ExtraSignedExtension.js +0 -60
- package/extrinsic/extensions/SignedExtension.d.ts +0 -40
- package/extrinsic/extensions/SignedExtension.js +0 -37
- package/extrinsic/extensions/index.d.ts +0 -3
- package/extrinsic/extensions/index.js +0 -3
- package/extrinsic/extensions/known/ChargeAssetTxPayment.d.ts +0 -14
- package/extrinsic/extensions/known/ChargeAssetTxPayment.js +0 -39
- package/extrinsic/extensions/known/ChargeTransactionPayment.d.ts +0 -6
- package/extrinsic/extensions/known/ChargeTransactionPayment.js +0 -12
- package/extrinsic/extensions/known/CheckGenesis.d.ts +0 -10
- package/extrinsic/extensions/known/CheckGenesis.js +0 -15
- package/extrinsic/extensions/known/CheckMortality.d.ts +0 -15
- package/extrinsic/extensions/known/CheckMortality.js +0 -66
- package/extrinsic/extensions/known/CheckNonZeroSender.d.ts +0 -6
- package/extrinsic/extensions/known/CheckNonZeroSender.js +0 -6
- package/extrinsic/extensions/known/CheckNonce.d.ts +0 -10
- package/extrinsic/extensions/known/CheckNonce.js +0 -29
- package/extrinsic/extensions/known/CheckSpecVersion.d.ts +0 -9
- package/extrinsic/extensions/known/CheckSpecVersion.js +0 -15
- package/extrinsic/extensions/known/CheckTxVersion.d.ts +0 -9
- package/extrinsic/extensions/known/CheckTxVersion.js +0 -15
- package/extrinsic/extensions/known/CheckWeight.d.ts +0 -6
- package/extrinsic/extensions/known/CheckWeight.js +0 -6
- package/extrinsic/extensions/known/PrevalidateAttests.d.ts +0 -7
- package/extrinsic/extensions/known/PrevalidateAttests.js +0 -7
- package/extrinsic/extensions/known/index.d.ts +0 -3
- package/extrinsic/extensions/known/index.js +0 -22
- package/extrinsic/index.d.ts +0 -2
- package/extrinsic/index.js +0 -2
- package/json-rpc/JsonRpcClient.d.ts +0 -49
- package/json-rpc/JsonRpcClient.js +0 -153
- package/json-rpc/index.d.ts +0 -1
- package/json-rpc/index.js +0 -1
- package/proxychain.d.ts +0 -14
- package/proxychain.js +0 -23
- package/storage/QueryableStorage.d.ts +0 -35
- package/storage/QueryableStorage.js +0 -157
- package/storage/index.d.ts +0 -1
- package/storage/index.js +0 -1
- package/types.d.ts +0 -103
- package/types.js +0 -1
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { GenericSubstrateApi } from '@dedot/types';
|
|
2
|
-
import type { SubstrateApi } from '../chaintypes/index.js';
|
|
3
|
-
import { Executor } from './Executor.js';
|
|
4
|
-
/**
|
|
5
|
-
* @name ConstantExecutor
|
|
6
|
-
*
|
|
7
|
-
* Find & decode the constant value from metadata
|
|
8
|
-
*/
|
|
9
|
-
export declare class ConstantExecutor<ChainApi extends GenericSubstrateApi = SubstrateApi> extends Executor<ChainApi> {
|
|
10
|
-
doExecute(pallet: string, constantName: string): unknown;
|
|
11
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { assert, UnknownApiError, stringCamelCase } from '@dedot/utils';
|
|
2
|
-
import { Executor } from './Executor.js';
|
|
3
|
-
/**
|
|
4
|
-
* @name ConstantExecutor
|
|
5
|
-
*
|
|
6
|
-
* Find & decode the constant value from metadata
|
|
7
|
-
*/
|
|
8
|
-
export class ConstantExecutor extends Executor {
|
|
9
|
-
doExecute(pallet, constantName) {
|
|
10
|
-
const targetPallet = this.getPallet(pallet);
|
|
11
|
-
const constantDef = targetPallet.constants.find((one) => stringCamelCase(one.name) === constantName);
|
|
12
|
-
assert(constantDef, new UnknownApiError(`Constant ${constantName} not found in pallet ${pallet}`));
|
|
13
|
-
const $codec = this.registry.findCodec(constantDef.typeId);
|
|
14
|
-
return $codec.tryDecode(constantDef.value);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { GenericPalletError, GenericSubstrateApi } from '@dedot/types';
|
|
2
|
-
import type { SubstrateApi } from '../chaintypes/index.js';
|
|
3
|
-
import { Executor } from './Executor.js';
|
|
4
|
-
/**
|
|
5
|
-
* @name ErrorExecutor
|
|
6
|
-
* @description Find pallet error information from metadata
|
|
7
|
-
*/
|
|
8
|
-
export declare class ErrorExecutor<ChainApi extends GenericSubstrateApi = SubstrateApi> extends Executor<ChainApi> {
|
|
9
|
-
#private;
|
|
10
|
-
doExecute(pallet: string, errorName: string): GenericPalletError;
|
|
11
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { assert, hexToU8a, isHex, isNumber, isObject, stringPascalCase, UnknownApiError } from '@dedot/utils';
|
|
2
|
-
import { Executor } from './Executor.js';
|
|
3
|
-
/**
|
|
4
|
-
* @name ErrorExecutor
|
|
5
|
-
* @description Find pallet error information from metadata
|
|
6
|
-
*/
|
|
7
|
-
export class ErrorExecutor extends Executor {
|
|
8
|
-
doExecute(pallet, errorName) {
|
|
9
|
-
const targetPallet = this.getPallet(pallet);
|
|
10
|
-
const errorTypeId = targetPallet.error;
|
|
11
|
-
assert(errorTypeId, new UnknownApiError(`Not found error with id ${errorTypeId} in pallet ${pallet}`));
|
|
12
|
-
const errorDef = this.#getErrorDef(errorTypeId, errorName);
|
|
13
|
-
return {
|
|
14
|
-
meta: {
|
|
15
|
-
...errorDef,
|
|
16
|
-
pallet: targetPallet.name,
|
|
17
|
-
palletIndex: targetPallet.index,
|
|
18
|
-
},
|
|
19
|
-
is: (errorInfo) => {
|
|
20
|
-
if (isObject(errorInfo) && errorInfo.tag === 'Module') {
|
|
21
|
-
errorInfo = errorInfo.value;
|
|
22
|
-
}
|
|
23
|
-
if (isObject(errorInfo) && isNumber(errorInfo.index) && isHex(errorInfo.error)) {
|
|
24
|
-
return errorInfo.index === targetPallet.index && hexToU8a(errorInfo.error)[0] === errorDef.index;
|
|
25
|
-
}
|
|
26
|
-
return false;
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
#getErrorDef(errorTypeId, errorName) {
|
|
31
|
-
const def = this.metadata.types[errorTypeId];
|
|
32
|
-
assert(def, new UnknownApiError(`Error def not found for id ${errorTypeId}`));
|
|
33
|
-
const { tag, value } = def.type;
|
|
34
|
-
assert(tag === 'Enum', new UnknownApiError(`Error type should be an enum, found: ${tag}`));
|
|
35
|
-
const errorDef = value.members.find(({ name }) => stringPascalCase(name) === errorName);
|
|
36
|
-
assert(errorDef, new UnknownApiError(`Error def not found for ${errorName}`));
|
|
37
|
-
return {
|
|
38
|
-
...errorDef,
|
|
39
|
-
fieldCodecs: errorDef.fields.map(({ typeId }) => this.registry.findCodec(typeId)),
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { GenericPalletEvent, GenericSubstrateApi } from '@dedot/types';
|
|
2
|
-
import type { SubstrateApi } from '../chaintypes/index.js';
|
|
3
|
-
import { Executor } from './Executor.js';
|
|
4
|
-
/**
|
|
5
|
-
* @name EventExecutor
|
|
6
|
-
* @description Find pallet event information from metadata
|
|
7
|
-
*/
|
|
8
|
-
export declare class EventExecutor<ChainApi extends GenericSubstrateApi = SubstrateApi> extends Executor<ChainApi> {
|
|
9
|
-
#private;
|
|
10
|
-
doExecute(pallet: string, errorName: string): GenericPalletEvent<string, string>;
|
|
11
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { assert, UnknownApiError, stringCamelCase, stringPascalCase } from '@dedot/utils';
|
|
2
|
-
import { Executor } from './Executor.js';
|
|
3
|
-
/**
|
|
4
|
-
* @name EventExecutor
|
|
5
|
-
* @description Find pallet event information from metadata
|
|
6
|
-
*/
|
|
7
|
-
export class EventExecutor extends Executor {
|
|
8
|
-
doExecute(pallet, errorName) {
|
|
9
|
-
const targetPallet = this.getPallet(pallet);
|
|
10
|
-
const eventTypeId = targetPallet.event;
|
|
11
|
-
assert(eventTypeId, new UnknownApiError(`Not found event with id ${eventTypeId} in pallet ${pallet}`));
|
|
12
|
-
const eventDef = this.#getEventDef(eventTypeId, errorName);
|
|
13
|
-
const is = (event) => {
|
|
14
|
-
const palletCheck = stringCamelCase(event.pallet) === pallet;
|
|
15
|
-
if (typeof event.palletEvent === 'string') {
|
|
16
|
-
return palletCheck && stringPascalCase(event.palletEvent) === errorName;
|
|
17
|
-
}
|
|
18
|
-
else if (typeof event.palletEvent === 'object') {
|
|
19
|
-
return palletCheck && stringPascalCase(event.palletEvent.name) === errorName;
|
|
20
|
-
}
|
|
21
|
-
return false;
|
|
22
|
-
};
|
|
23
|
-
const as = (event) => {
|
|
24
|
-
return is(event) ? event : undefined;
|
|
25
|
-
};
|
|
26
|
-
return {
|
|
27
|
-
is,
|
|
28
|
-
as,
|
|
29
|
-
meta: {
|
|
30
|
-
...eventDef,
|
|
31
|
-
pallet: targetPallet.name,
|
|
32
|
-
palletIndex: targetPallet.index,
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
#getEventDef(eventTypeId, errorName) {
|
|
37
|
-
const def = this.metadata.types[eventTypeId];
|
|
38
|
-
assert(def, new UnknownApiError(`Event def not found for id ${eventTypeId}`));
|
|
39
|
-
const { tag, value } = def.type;
|
|
40
|
-
assert(tag === 'Enum', new UnknownApiError(`Event type should be an enum, found: ${tag}`));
|
|
41
|
-
const eventDef = value.members.find(({ name }) => stringPascalCase(name) === errorName);
|
|
42
|
-
assert(eventDef, new UnknownApiError(`Event def not found for ${errorName}`));
|
|
43
|
-
return {
|
|
44
|
-
...eventDef,
|
|
45
|
-
fieldCodecs: eventDef.fields.map(({ typeId }) => this.registry.findCodec(typeId)),
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
}
|
package/executor/Executor.d.ts
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import type { BlockHash, PalletDefLatest } from '@dedot/codecs';
|
|
2
|
-
import type { GenericSubstrateApi } from '@dedot/types';
|
|
3
|
-
import type { SubstrateApi } from '../chaintypes/index.js';
|
|
4
|
-
import { ISubstrateClientAt } from '../types.js';
|
|
5
|
-
/**
|
|
6
|
-
* @name Executor
|
|
7
|
-
* @description Execution abstraction for a specific action
|
|
8
|
-
*/
|
|
9
|
-
export declare abstract class Executor<ChainApi extends GenericSubstrateApi = SubstrateApi> {
|
|
10
|
-
#private;
|
|
11
|
-
constructor(api: ISubstrateClientAt<ChainApi>, atBlockHash?: BlockHash);
|
|
12
|
-
get api(): ISubstrateClientAt<ChainApi>;
|
|
13
|
-
get atBlockHash(): `0x${string}` | undefined;
|
|
14
|
-
get registry(): import("@dedot/codecs").PortableRegistry;
|
|
15
|
-
get metadata(): {
|
|
16
|
-
types: {
|
|
17
|
-
id: number;
|
|
18
|
-
path: string[];
|
|
19
|
-
params: {
|
|
20
|
-
name: string;
|
|
21
|
-
typeId: number | undefined;
|
|
22
|
-
}[];
|
|
23
|
-
type: {
|
|
24
|
-
tag: "Struct";
|
|
25
|
-
value: {
|
|
26
|
-
fields: import("@dedot/codecs").Field[];
|
|
27
|
-
};
|
|
28
|
-
} | {
|
|
29
|
-
tag: "Enum";
|
|
30
|
-
value: {
|
|
31
|
-
members: {
|
|
32
|
-
name: string;
|
|
33
|
-
fields: import("@dedot/codecs").Field[];
|
|
34
|
-
index: number;
|
|
35
|
-
docs: string[];
|
|
36
|
-
}[];
|
|
37
|
-
};
|
|
38
|
-
} | {
|
|
39
|
-
tag: "Sequence";
|
|
40
|
-
value: {
|
|
41
|
-
typeParam: number;
|
|
42
|
-
};
|
|
43
|
-
} | {
|
|
44
|
-
tag: "SizedVec";
|
|
45
|
-
value: {
|
|
46
|
-
len: number;
|
|
47
|
-
typeParam: number;
|
|
48
|
-
};
|
|
49
|
-
} | {
|
|
50
|
-
tag: "Tuple";
|
|
51
|
-
value: {
|
|
52
|
-
fields: number[];
|
|
53
|
-
};
|
|
54
|
-
} | {
|
|
55
|
-
tag: "Primitive";
|
|
56
|
-
value: {
|
|
57
|
-
kind: "bool" | "char" | "str" | "u8" | "u16" | "u32" | "u64" | "u128" | "u256" | "i8" | "i16" | "i32" | "i64" | "i128" | "i256";
|
|
58
|
-
};
|
|
59
|
-
} | {
|
|
60
|
-
tag: "Compact";
|
|
61
|
-
value: {
|
|
62
|
-
typeParam: number;
|
|
63
|
-
};
|
|
64
|
-
} | {
|
|
65
|
-
tag: "BitSequence";
|
|
66
|
-
value: {
|
|
67
|
-
bitOrderType: number;
|
|
68
|
-
bitStoreType: number;
|
|
69
|
-
};
|
|
70
|
-
};
|
|
71
|
-
docs: string[];
|
|
72
|
-
}[];
|
|
73
|
-
pallets: {
|
|
74
|
-
name: string;
|
|
75
|
-
storage: {
|
|
76
|
-
prefix: string;
|
|
77
|
-
entries: {
|
|
78
|
-
name: string;
|
|
79
|
-
modifier: string;
|
|
80
|
-
type: {
|
|
81
|
-
tag: "Plain";
|
|
82
|
-
value: {
|
|
83
|
-
valueTypeId: number;
|
|
84
|
-
};
|
|
85
|
-
} | {
|
|
86
|
-
tag: "Map";
|
|
87
|
-
value: {
|
|
88
|
-
hashers: ("identity" | "blake2_128" | "blake2_256" | "blake2_128Concat" | "twox128" | "twox256" | "twox64Concat")[];
|
|
89
|
-
keyTypeId: number;
|
|
90
|
-
valueTypeId: number;
|
|
91
|
-
};
|
|
92
|
-
};
|
|
93
|
-
default: `0x${string}`;
|
|
94
|
-
docs: string[];
|
|
95
|
-
}[];
|
|
96
|
-
} | undefined;
|
|
97
|
-
calls: number | undefined;
|
|
98
|
-
event: number | undefined;
|
|
99
|
-
constants: {
|
|
100
|
-
name: string;
|
|
101
|
-
typeId: number;
|
|
102
|
-
value: `0x${string}`;
|
|
103
|
-
docs: string[];
|
|
104
|
-
}[];
|
|
105
|
-
error: number | undefined;
|
|
106
|
-
index: number;
|
|
107
|
-
docs: string[];
|
|
108
|
-
}[];
|
|
109
|
-
extrinsic: {
|
|
110
|
-
version: number;
|
|
111
|
-
addressTypeId: number;
|
|
112
|
-
callTypeId: number;
|
|
113
|
-
signatureTypeId: number;
|
|
114
|
-
extraTypeId: number;
|
|
115
|
-
signedExtensions: {
|
|
116
|
-
ident: string;
|
|
117
|
-
typeId: number;
|
|
118
|
-
additionalSigned: number;
|
|
119
|
-
}[];
|
|
120
|
-
};
|
|
121
|
-
runtimeType: number;
|
|
122
|
-
apis: {
|
|
123
|
-
name: string;
|
|
124
|
-
methods: {
|
|
125
|
-
name: string;
|
|
126
|
-
inputs: {
|
|
127
|
-
name: string;
|
|
128
|
-
typeId: number;
|
|
129
|
-
}[];
|
|
130
|
-
output: number;
|
|
131
|
-
docs: string[];
|
|
132
|
-
}[];
|
|
133
|
-
docs: string[];
|
|
134
|
-
}[];
|
|
135
|
-
outerEnums: {
|
|
136
|
-
callEnumTypeId: number;
|
|
137
|
-
eventEnumTypeId: number;
|
|
138
|
-
errorEnumTypeId: number;
|
|
139
|
-
};
|
|
140
|
-
custom: {
|
|
141
|
-
map: ReadonlyMap<string, {
|
|
142
|
-
typeId: number;
|
|
143
|
-
value: `0x${string}`;
|
|
144
|
-
}>;
|
|
145
|
-
};
|
|
146
|
-
};
|
|
147
|
-
getPallet(name: string): PalletDefLatest;
|
|
148
|
-
execute(...paths: string[]): unknown;
|
|
149
|
-
abstract doExecute(...paths: string[]): unknown;
|
|
150
|
-
}
|
package/executor/Executor.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { assert, stringCamelCase, UnknownApiError } from '@dedot/utils';
|
|
2
|
-
/**
|
|
3
|
-
* @name Executor
|
|
4
|
-
* @description Execution abstraction for a specific action
|
|
5
|
-
*/
|
|
6
|
-
export class Executor {
|
|
7
|
-
#api;
|
|
8
|
-
#atBlockHash;
|
|
9
|
-
constructor(api, atBlockHash) {
|
|
10
|
-
this.#api = api;
|
|
11
|
-
this.#atBlockHash = atBlockHash;
|
|
12
|
-
}
|
|
13
|
-
get api() {
|
|
14
|
-
return this.#api;
|
|
15
|
-
}
|
|
16
|
-
get atBlockHash() {
|
|
17
|
-
return this.#atBlockHash || this.api.atBlockHash;
|
|
18
|
-
}
|
|
19
|
-
get registry() {
|
|
20
|
-
return this.api.registry;
|
|
21
|
-
}
|
|
22
|
-
get metadata() {
|
|
23
|
-
return this.api.metadata.latest;
|
|
24
|
-
}
|
|
25
|
-
getPallet(name) {
|
|
26
|
-
const targetPallet = this.metadata.pallets.find((p) => stringCamelCase(p.name) === name);
|
|
27
|
-
assert(targetPallet, new UnknownApiError(`Pallet not found: ${name}`));
|
|
28
|
-
return targetPallet;
|
|
29
|
-
}
|
|
30
|
-
execute(...paths) {
|
|
31
|
-
try {
|
|
32
|
-
return this.doExecute(...paths);
|
|
33
|
-
}
|
|
34
|
-
catch (e) {
|
|
35
|
-
if (!this.api.options?.throwOnUnknownApi && e instanceof UnknownApiError) {
|
|
36
|
-
return undefined;
|
|
37
|
-
}
|
|
38
|
-
throw e;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { GenericRuntimeApiMethod, GenericSubstrateApi, RuntimeApiMethodParamSpec, RuntimeApiMethodSpec, RuntimeApiSpec } from '@dedot/types';
|
|
2
|
-
import { Executor } from './Executor.js';
|
|
3
|
-
export declare const FallbackRuntimeApis: Record<string, number>;
|
|
4
|
-
export declare const FallbackRuntimeApiSpecs: {
|
|
5
|
-
Metadata: RuntimeApiSpec[];
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* @name RuntimeApiExecutor
|
|
9
|
-
* @description Execute a runtime api call,
|
|
10
|
-
* runtime api definitions/specs are either from Metadata V15
|
|
11
|
-
* or defined externally when initializing `Dedot` instance
|
|
12
|
-
* via `ApiOptions.runtimeApis` option.
|
|
13
|
-
*/
|
|
14
|
-
export declare class RuntimeApiExecutor<ChainApi extends GenericSubstrateApi = GenericSubstrateApi> extends Executor<ChainApi> {
|
|
15
|
-
#private;
|
|
16
|
-
doExecute(runtimeApi: string, method: string): GenericRuntimeApiMethod;
|
|
17
|
-
tryDecode(callSpec: RuntimeApiMethodSpec, raw: any): unknown;
|
|
18
|
-
tryEncode(paramSpec: RuntimeApiMethodParamSpec, value: any): Uint8Array;
|
|
19
|
-
}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { Metadata, toRuntimeApiMethods, toRuntimeApiSpecs } from '@dedot/specs';
|
|
2
|
-
import { assert, calcRuntimeApiHash, isNumber, stringPascalCase, stringSnakeCase, concatU8a, u8aToHex, UnknownApiError, } from '@dedot/utils';
|
|
3
|
-
import { Executor } from './Executor.js';
|
|
4
|
-
export const FallbackRuntimeApis = { '0x37e397fc7c91f5e4': 2 };
|
|
5
|
-
export const FallbackRuntimeApiSpecs = { Metadata };
|
|
6
|
-
/**
|
|
7
|
-
* @name RuntimeApiExecutor
|
|
8
|
-
* @description Execute a runtime api call,
|
|
9
|
-
* runtime api definitions/specs are either from Metadata V15
|
|
10
|
-
* or defined externally when initializing `Dedot` instance
|
|
11
|
-
* via `ApiOptions.runtimeApis` option.
|
|
12
|
-
*/
|
|
13
|
-
export class RuntimeApiExecutor extends Executor {
|
|
14
|
-
doExecute(runtimeApi, method) {
|
|
15
|
-
const runtimeApiName = stringPascalCase(runtimeApi);
|
|
16
|
-
const methodName = stringSnakeCase(method);
|
|
17
|
-
const callName = this.#callName({ runtimeApiName, methodName });
|
|
18
|
-
const callSpec = this.#findRuntimeApiMethodSpec(runtimeApiName, methodName);
|
|
19
|
-
assert(callSpec, new UnknownApiError(`Runtime api spec not found for ${callName}`));
|
|
20
|
-
const callFn = async (...args) => {
|
|
21
|
-
const { params } = callSpec;
|
|
22
|
-
const formattedInputs = params.map((param, index) => this.tryEncode(param, args[index]));
|
|
23
|
-
const bytes = u8aToHex(concatU8a(...formattedInputs));
|
|
24
|
-
const callArgs = [callName, bytes];
|
|
25
|
-
if (this.atBlockHash) {
|
|
26
|
-
callArgs.push(this.atBlockHash);
|
|
27
|
-
}
|
|
28
|
-
const result = await this.api.rpc.state_call(...callArgs);
|
|
29
|
-
return this.tryDecode(callSpec, result);
|
|
30
|
-
};
|
|
31
|
-
callFn.meta = callSpec;
|
|
32
|
-
return callFn;
|
|
33
|
-
}
|
|
34
|
-
tryDecode(callSpec, raw) {
|
|
35
|
-
const $codec = this.#findCodec(callSpec, `Codec not found to decode respond data for ${this.#callName(callSpec)}`);
|
|
36
|
-
return $codec.tryDecode(raw);
|
|
37
|
-
}
|
|
38
|
-
tryEncode(paramSpec, value) {
|
|
39
|
-
const $codec = this.#findCodec(paramSpec, `Codec not found to encode input for param ${paramSpec.name}`);
|
|
40
|
-
return $codec.tryEncode(value);
|
|
41
|
-
}
|
|
42
|
-
#findCodec(spec, error) {
|
|
43
|
-
const { codec, typeId, type } = spec;
|
|
44
|
-
if (codec)
|
|
45
|
-
return codec;
|
|
46
|
-
if (isNumber(typeId)) {
|
|
47
|
-
return this.registry.findCodec(typeId);
|
|
48
|
-
}
|
|
49
|
-
throw new Error(error || 'Codec not found');
|
|
50
|
-
}
|
|
51
|
-
#callName({ runtimeApiName, methodName }) {
|
|
52
|
-
return `${runtimeApiName}_${methodName}`;
|
|
53
|
-
}
|
|
54
|
-
#findRuntimeApiMethodSpec(runtimeApi, method) {
|
|
55
|
-
const targetVersion = this.#findTargetRuntimeApiVersion(runtimeApi);
|
|
56
|
-
if (!isNumber(targetVersion))
|
|
57
|
-
return undefined;
|
|
58
|
-
const userDefinedSpec = this.#findDefinedSpec(this.api.options.runtimeApis, runtimeApi, method, targetVersion);
|
|
59
|
-
if (userDefinedSpec)
|
|
60
|
-
return userDefinedSpec;
|
|
61
|
-
const methodDef = this.#findRuntimeApiMethodDef(runtimeApi, method);
|
|
62
|
-
if (methodDef) {
|
|
63
|
-
return this.#toMethodSpec(runtimeApi, methodDef);
|
|
64
|
-
}
|
|
65
|
-
return this.#findDefinedSpec(FallbackRuntimeApiSpecs, runtimeApi, method, targetVersion);
|
|
66
|
-
}
|
|
67
|
-
#findRuntimeApiMethodDef(runtimeApi, method) {
|
|
68
|
-
try {
|
|
69
|
-
for (const api of this.metadata.apis) {
|
|
70
|
-
if (api.name !== runtimeApi)
|
|
71
|
-
continue;
|
|
72
|
-
for (const apiMethod of api.methods) {
|
|
73
|
-
if (apiMethod.name === method)
|
|
74
|
-
return apiMethod;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
catch { }
|
|
79
|
-
}
|
|
80
|
-
#toMethodSpec(runtimeApi, methodDef) {
|
|
81
|
-
const { name, inputs, output, docs } = methodDef;
|
|
82
|
-
return {
|
|
83
|
-
docs,
|
|
84
|
-
runtimeApiName: runtimeApi,
|
|
85
|
-
methodName: name,
|
|
86
|
-
typeId: output,
|
|
87
|
-
params: inputs.map(({ name, typeId }) => ({
|
|
88
|
-
name,
|
|
89
|
-
typeId,
|
|
90
|
-
})),
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
#findTargetRuntimeApiVersion(runtimeApi) {
|
|
94
|
-
const runtimeApiHash = calcRuntimeApiHash(runtimeApi);
|
|
95
|
-
try {
|
|
96
|
-
return this.api.runtimeVersion.apis[runtimeApiHash] || FallbackRuntimeApis[runtimeApiHash];
|
|
97
|
-
}
|
|
98
|
-
catch {
|
|
99
|
-
return FallbackRuntimeApis[runtimeApiHash];
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
#findDefinedSpec(specs, runtimeApi, method, runtimeApiVersion) {
|
|
103
|
-
if (!specs)
|
|
104
|
-
return undefined;
|
|
105
|
-
const methodSpecs = toRuntimeApiSpecs(specs).map(toRuntimeApiMethods).flat();
|
|
106
|
-
return methodSpecs.find(({ runtimeApiName, methodName, version }) => `${stringPascalCase(runtimeApiName)}_${stringSnakeCase(methodName)}` === `${runtimeApi}_${method}` &&
|
|
107
|
-
runtimeApiVersion === version);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { BlockHash, StorageData, StorageKey } from '@dedot/codecs';
|
|
2
|
-
import type { Callback, GenericStorageQuery, GenericSubstrateApi, Unsub } from '@dedot/types';
|
|
3
|
-
import type { SubstrateApi } from '../chaintypes/index.js';
|
|
4
|
-
import { Executor } from './Executor.js';
|
|
5
|
-
/**
|
|
6
|
-
* @name StorageQueryExecutor
|
|
7
|
-
* @description Execute a query to on-chain storage
|
|
8
|
-
*/
|
|
9
|
-
export declare class StorageQueryExecutor<ChainApi extends GenericSubstrateApi = SubstrateApi> extends Executor<ChainApi> {
|
|
10
|
-
doExecute(pallet: string, storage: string): GenericStorageQuery;
|
|
11
|
-
protected getStorage(key: StorageKey, at?: BlockHash): Promise<StorageData | undefined>;
|
|
12
|
-
protected subscribeStorage(keys: StorageKey[], callback: Callback<Array<StorageData | undefined>>): Promise<Unsub>;
|
|
13
|
-
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { assert, isFunction } from '@dedot/utils';
|
|
2
|
-
import { QueryableStorage } from '../storage/QueryableStorage.js';
|
|
3
|
-
import { Executor } from './Executor.js';
|
|
4
|
-
const DEFAULT_KEYS_PAGE_SIZE = 1000;
|
|
5
|
-
const DEFAULT_ENTRIES_PAGE_SIZE = 250;
|
|
6
|
-
/**
|
|
7
|
-
* @name StorageQueryExecutor
|
|
8
|
-
* @description Execute a query to on-chain storage
|
|
9
|
-
*/
|
|
10
|
-
export class StorageQueryExecutor extends Executor {
|
|
11
|
-
doExecute(pallet, storage) {
|
|
12
|
-
const entry = new QueryableStorage(this.registry, pallet, storage);
|
|
13
|
-
const extractArgs = (args) => {
|
|
14
|
-
const inArgs = args.slice();
|
|
15
|
-
const lastArg = args.at(-1);
|
|
16
|
-
const callback = isFunction(lastArg) ? inArgs.pop() : undefined;
|
|
17
|
-
return [inArgs, callback];
|
|
18
|
-
};
|
|
19
|
-
const getStorageKey = (...args) => {
|
|
20
|
-
const [inArgs] = extractArgs(args);
|
|
21
|
-
return entry.encodeKey(inArgs.at(0));
|
|
22
|
-
};
|
|
23
|
-
const getStorage = async (key) => {
|
|
24
|
-
const raw = await this.getStorage(key, this.atBlockHash);
|
|
25
|
-
return entry.decodeValue(raw);
|
|
26
|
-
};
|
|
27
|
-
const queryFn = async (...args) => {
|
|
28
|
-
const [inArgs, callback] = extractArgs(args);
|
|
29
|
-
const encodedKey = entry.encodeKey(inArgs.at(0));
|
|
30
|
-
// if a callback is passed, make a storage subscription and return an unsub function
|
|
31
|
-
if (callback) {
|
|
32
|
-
return await this.subscribeStorage([encodedKey], (changes) => {
|
|
33
|
-
if (changes.length === 0)
|
|
34
|
-
return;
|
|
35
|
-
callback(entry.decodeValue(changes[0]));
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
return getStorage(encodedKey);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
const queryMultiFn = async (...args) => {
|
|
43
|
-
const [inArgs, callback] = extractArgs(args);
|
|
44
|
-
const multiArgs = inArgs.at(0);
|
|
45
|
-
assert(Array.isArray(multiArgs), 'First param for multi query should be an array');
|
|
46
|
-
const encodedKeys = multiArgs.map((arg) => entry.encodeKey(arg));
|
|
47
|
-
// if a callback is passed, make a storage subscription and return an unsub function
|
|
48
|
-
if (callback) {
|
|
49
|
-
return await this.subscribeStorage(encodedKeys, (changes) => {
|
|
50
|
-
callback(changes.map((change) => entry.decodeValue(change)));
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
return await Promise.all(encodedKeys.map(getStorage));
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
queryFn.rawKey = getStorageKey;
|
|
58
|
-
queryFn.meta = {
|
|
59
|
-
pallet: entry.pallet.name,
|
|
60
|
-
palletIndex: entry.pallet.index,
|
|
61
|
-
...entry.storageEntry,
|
|
62
|
-
};
|
|
63
|
-
queryFn.multi = queryMultiFn;
|
|
64
|
-
const isMap = entry.storageEntry.type.tag === 'Map';
|
|
65
|
-
if (isMap) {
|
|
66
|
-
const rawKeys = async (pagination) => {
|
|
67
|
-
const pageSize = pagination?.pageSize || DEFAULT_KEYS_PAGE_SIZE;
|
|
68
|
-
const startKey = pagination?.startKey || entry.prefixKey;
|
|
69
|
-
return await this.api.rpc.state_getKeysPaged(entry.prefixKey, pageSize, startKey, this.atBlockHash);
|
|
70
|
-
};
|
|
71
|
-
const keys = async (pagination) => {
|
|
72
|
-
const storageKeys = await rawKeys({ pageSize: DEFAULT_KEYS_PAGE_SIZE, ...pagination });
|
|
73
|
-
return storageKeys.map((key) => entry.decodeKey(key));
|
|
74
|
-
};
|
|
75
|
-
const entries = async (pagination) => {
|
|
76
|
-
const storageKeys = await rawKeys({ pageSize: DEFAULT_ENTRIES_PAGE_SIZE, ...pagination });
|
|
77
|
-
const changeSets = await this.api.rpc.state_queryStorageAt(storageKeys, this.atBlockHash);
|
|
78
|
-
const changes = changeSets[0].changes.reduce((o, [key, value]) => {
|
|
79
|
-
o[key] = value;
|
|
80
|
-
return o;
|
|
81
|
-
}, {});
|
|
82
|
-
return storageKeys.map((key) => [entry.decodeKey(key), entry.decodeValue(changes[key])]);
|
|
83
|
-
};
|
|
84
|
-
// @ts-ignore
|
|
85
|
-
queryFn.keys = keys;
|
|
86
|
-
// @ts-ignore
|
|
87
|
-
queryFn.entries = entries;
|
|
88
|
-
}
|
|
89
|
-
return queryFn;
|
|
90
|
-
}
|
|
91
|
-
getStorage(key, at) {
|
|
92
|
-
return this.api.rpc.state_getStorage(key, at);
|
|
93
|
-
}
|
|
94
|
-
subscribeStorage(keys, callback) {
|
|
95
|
-
const lastChanges = {};
|
|
96
|
-
return this.api.rpc.state_subscribeStorage(keys, (changeSet) => {
|
|
97
|
-
changeSet.changes.forEach(([key, value]) => {
|
|
98
|
-
if (lastChanges[key] !== value) {
|
|
99
|
-
lastChanges[key] = value ?? undefined;
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
return callback(keys.map((key) => lastChanges[key]));
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
}
|
package/executor/TxExecutor.d.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { SignOptions } from '@polkadot/keyring/types';
|
|
2
|
-
import { IKeyringPair } from '@polkadot/types/types';
|
|
3
|
-
import { BlockHash, Extrinsic, Hash } from '@dedot/codecs';
|
|
4
|
-
import type { AddressOrPair, Callback, DryRunResult, GenericSubstrateApi, GenericTxCall, IRuntimeTxCall, ISubmittableResult, SignerOptions, Unsub } from '@dedot/types';
|
|
5
|
-
import { HexString } from '@dedot/utils';
|
|
6
|
-
import type { SubstrateApi } from '../chaintypes/index.js';
|
|
7
|
-
import { Executor } from './Executor.js';
|
|
8
|
-
export declare function isKeyringPair(account: AddressOrPair): account is IKeyringPair;
|
|
9
|
-
/**
|
|
10
|
-
* Sign a raw message
|
|
11
|
-
* @param signerPair
|
|
12
|
-
* @param raw
|
|
13
|
-
* @param options
|
|
14
|
-
*/
|
|
15
|
-
export declare function signRaw(signerPair: IKeyringPair, raw: HexString, options?: SignOptions): Uint8Array;
|
|
16
|
-
/**
|
|
17
|
-
* @name TxExecutor
|
|
18
|
-
* @description Execute a transaction instruction, returns a submittable extrinsic
|
|
19
|
-
*/
|
|
20
|
-
export declare class TxExecutor<ChainApi extends GenericSubstrateApi = SubstrateApi> extends Executor<ChainApi> {
|
|
21
|
-
#private;
|
|
22
|
-
doExecute(pallet: string, functionName: string): GenericTxCall;
|
|
23
|
-
createExtrinsic(call: IRuntimeTxCall): {
|
|
24
|
-
sign(fromAccount: AddressOrPair, options?: Partial<SignerOptions>): Promise<any>;
|
|
25
|
-
signAndSend(account: AddressOrPair, options?: Partial<SignerOptions>): Promise<Hash>;
|
|
26
|
-
signAndSend(account: AddressOrPair, callback: Callback<ISubmittableResult>): Promise<Unsub>;
|
|
27
|
-
signAndSend(account: AddressOrPair, options: Partial<SignerOptions>, callback?: Callback<ISubmittableResult>): Promise<Unsub>;
|
|
28
|
-
"__#42@#normalizeOptions"(partialOptions?: Partial<SignerOptions> | Callback<ISubmittableResult>, callback?: Callback<ISubmittableResult>): [Partial<SignerOptions>, Callback<ISubmittableResult> | undefined];
|
|
29
|
-
dryRun(account: AddressOrPair, optionsOrHash?: Partial<SignerOptions> | BlockHash): Promise<DryRunResult>;
|
|
30
|
-
send(): Promise<Hash>;
|
|
31
|
-
send(callback: Callback<ISubmittableResult>): Promise<Unsub>;
|
|
32
|
-
"__#6@#private": any;
|
|
33
|
-
registry: import("@dedot/codecs").PortableRegistry;
|
|
34
|
-
readonly signed: boolean;
|
|
35
|
-
readonly version: number;
|
|
36
|
-
readonly signature: import("@dedot/codecs").ExtrinsicSignatureV4<any, any, any> | undefined;
|
|
37
|
-
readonly call: any;
|
|
38
|
-
readonly callU8a: Uint8Array;
|
|
39
|
-
readonly callHex: `0x${string}`;
|
|
40
|
-
readonly callLength: number;
|
|
41
|
-
attachSignature(signature: import("@dedot/codecs").ExtrinsicSignatureV4<any, any, any>): void;
|
|
42
|
-
readonly $Codec: import("subshape").Shape<Extrinsic<any, any, any, any>, Extrinsic<any, any, any, any>>;
|
|
43
|
-
toU8a(): Uint8Array;
|
|
44
|
-
toHex(): `0x${string}`;
|
|
45
|
-
readonly length: number;
|
|
46
|
-
readonly hash: `0x${string}`;
|
|
47
|
-
};
|
|
48
|
-
}
|