@dedot/contracts 0.0.1-alpha.33
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/Contract.d.ts +15 -0
- package/Contract.js +32 -0
- package/ContractDeployer.d.ts +14 -0
- package/ContractDeployer.js +30 -0
- package/LICENSE +201 -0
- package/README.md +3 -0
- package/TypinkRegistry.d.ts +7 -0
- package/TypinkRegistry.js +12 -0
- package/cjs/Contract.js +36 -0
- package/cjs/ContractDeployer.js +34 -0
- package/cjs/TypinkRegistry.js +16 -0
- package/cjs/executor/ConstructorQueryExecutor.js +27 -0
- package/cjs/executor/ConstructorTxExecutor.js +37 -0
- package/cjs/executor/Executor.js +39 -0
- package/cjs/executor/QueryExecutor.js +38 -0
- package/cjs/executor/TxExecutor.js +27 -0
- package/cjs/executor/index.js +20 -0
- package/cjs/index.js +22 -0
- package/cjs/package.json +1 -0
- package/cjs/types/index.js +17 -0
- package/cjs/types/shared.js +2 -0
- package/cjs/types/v4.js +2 -0
- package/cjs/types/v5.js +2 -0
- package/cjs/utils.js +108 -0
- package/executor/ConstructorQueryExecutor.d.ts +6 -0
- package/executor/ConstructorQueryExecutor.js +23 -0
- package/executor/ConstructorTxExecutor.d.ts +13 -0
- package/executor/ConstructorTxExecutor.js +33 -0
- package/executor/Executor.d.ts +18 -0
- package/executor/Executor.js +35 -0
- package/executor/QueryExecutor.d.ts +7 -0
- package/executor/QueryExecutor.js +34 -0
- package/executor/TxExecutor.d.ts +7 -0
- package/executor/TxExecutor.js +23 -0
- package/executor/index.d.ts +4 -0
- package/executor/index.js +4 -0
- package/index.d.ts +6 -0
- package/index.js +6 -0
- package/package.json +36 -0
- package/types/index.d.ts +57 -0
- package/types/index.js +1 -0
- package/types/shared.d.ts +105 -0
- package/types/shared.js +1 -0
- package/types/v4.d.ts +31 -0
- package/types/v4.js +1 -0
- package/types/v5.d.ts +21 -0
- package/types/v5.js +1 -0
- package/utils.d.ts +11 -0
- package/utils.js +99 -0
package/utils.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { stringCamelCase } from '@dedot/utils';
|
|
2
|
+
export const extractContractTypes = (contractMetadata) => {
|
|
3
|
+
const { types } = contractMetadata;
|
|
4
|
+
return types.map(({ type, id }) => ({
|
|
5
|
+
id,
|
|
6
|
+
type: normalizeContractTypeDef(type.def),
|
|
7
|
+
params: [],
|
|
8
|
+
path: type?.path || [],
|
|
9
|
+
docs: [],
|
|
10
|
+
}));
|
|
11
|
+
};
|
|
12
|
+
export const normalizeContractTypeDef = (def) => {
|
|
13
|
+
let tag;
|
|
14
|
+
let value;
|
|
15
|
+
if (def.variant) {
|
|
16
|
+
tag = 'Enum';
|
|
17
|
+
value = {
|
|
18
|
+
members: def.variant.variants?.map((variant) => ({
|
|
19
|
+
fields: variant.fields?.map((fields) => ({ typeId: fields.type, typeName: fields.typeName })) || [],
|
|
20
|
+
index: variant.index,
|
|
21
|
+
name: variant.name,
|
|
22
|
+
})) || [],
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
else if (def.tuple) {
|
|
26
|
+
tag = 'Tuple';
|
|
27
|
+
value = {
|
|
28
|
+
fields: def.tuple,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
else if (def.sequence) {
|
|
32
|
+
tag = 'Sequence';
|
|
33
|
+
value = {
|
|
34
|
+
typeParam: def.sequence.type,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
else if (def.composite) {
|
|
38
|
+
tag = 'Struct';
|
|
39
|
+
value = {
|
|
40
|
+
fields: def.composite.fields.map((one) => ({
|
|
41
|
+
typeId: one.type,
|
|
42
|
+
name: one.name,
|
|
43
|
+
typeName: one.typeName,
|
|
44
|
+
})),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
else if (def.primitive) {
|
|
48
|
+
tag = 'Primitive';
|
|
49
|
+
value = {
|
|
50
|
+
kind: def.primitive,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
else if (def.array) {
|
|
54
|
+
tag = 'SizedVec';
|
|
55
|
+
value = {
|
|
56
|
+
len: def.array.len,
|
|
57
|
+
typeParam: def.array.type,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
throw Error(`Invalid contract type def: ${JSON.stringify(def)}`);
|
|
62
|
+
}
|
|
63
|
+
return { tag, value };
|
|
64
|
+
};
|
|
65
|
+
const UNSUPPORTED_VERSIONS = ['V3', 'V2', 'V1'];
|
|
66
|
+
const SUPPORTED_VERSIONS = ['5', '4'];
|
|
67
|
+
export const parseRawMetadata = (rawMetadata) => {
|
|
68
|
+
const metadata = JSON.parse(rawMetadata);
|
|
69
|
+
// This is for V1, V2, V3
|
|
70
|
+
const unsupportedVersion = UNSUPPORTED_VERSIONS.find((o) => metadata[o]);
|
|
71
|
+
if (unsupportedVersion) {
|
|
72
|
+
throw new Error(`Unsupported metadata version: ${unsupportedVersion}`);
|
|
73
|
+
}
|
|
74
|
+
// This is for V4, V5
|
|
75
|
+
if (!SUPPORTED_VERSIONS.includes(metadata.version)) {
|
|
76
|
+
throw new Error(`Unsupported metadata version: ${metadata.version}`);
|
|
77
|
+
}
|
|
78
|
+
return metadata;
|
|
79
|
+
};
|
|
80
|
+
export function newProxyChain(carrier) {
|
|
81
|
+
return new Proxy(carrier, {
|
|
82
|
+
get(target, property) {
|
|
83
|
+
return target.doExecute(property.toString());
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
export function ensureSupportContractsPallet(api) {
|
|
88
|
+
try {
|
|
89
|
+
!!api.call.contractsApi.call.meta && !!api.tx.contracts.call.meta;
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
throw new Error('Contracts pallet is not available');
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
export function normalizeLabel(label) {
|
|
96
|
+
if (!label)
|
|
97
|
+
return '';
|
|
98
|
+
return stringCamelCase(label.replaceAll('::', '_'));
|
|
99
|
+
}
|