@dotdm/cdm 0.5.0 → 0.5.1-dev.1774500408
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/dist/browser.d.ts +26 -0
- package/dist/browser.js +12 -0
- package/dist/chunk-AYCBE7SX.js +174 -0
- package/dist/chunk-EFGJVSBH.js +73 -0
- package/dist/{types.d.ts → codegen-ZBogcw6T.d.ts} +22 -14
- package/dist/codegen.d.ts +2 -6
- package/dist/codegen.js +6 -90
- package/dist/index.d.ts +13 -7
- package/dist/index.js +58 -6
- package/package.json +10 -5
- package/dist/cdm-core.d.ts +0 -21
- package/dist/cdm-core.d.ts.map +0 -1
- package/dist/cdm-core.js +0 -83
- package/dist/cdm-core.js.map +0 -1
- package/dist/cdm-node.d.ts +0 -4
- package/dist/cdm-node.d.ts.map +0 -1
- package/dist/cdm-node.js +0 -10
- package/dist/cdm-node.js.map +0 -1
- package/dist/cdm.d.ts +0 -5
- package/dist/cdm.d.ts.map +0 -1
- package/dist/cdm.js +0 -5
- package/dist/cdm.js.map +0 -1
- package/dist/codegen.d.ts.map +0 -1
- package/dist/codegen.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/resolver.d.ts +0 -3
- package/dist/resolver.d.ts.map +0 -1
- package/dist/resolver.js +0 -35
- package/dist/resolver.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/dist/wrap.d.ts +0 -8
- package/dist/wrap.d.ts.map +0 -1
- package/dist/wrap.js +0 -82
- package/dist/wrap.js.map +0 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { PolkadotClient, HexString } from 'polkadot-api';
|
|
2
|
+
import { InkSdk } from '@polkadot-api/sdk-ink';
|
|
3
|
+
import { CdmJson } from '@dotdm/contracts';
|
|
4
|
+
import { C as CdmOptions, e as CdmDefaults, d as CdmContracts, b as CdmContract } from './codegen-ZBogcw6T.js';
|
|
5
|
+
export { A as AbiEntry, a as AbiParam, c as CdmContractDef, Q as QueryResult, R as ResolvedContract, T as TxOpts, f as TxResult, g as generateContractTypes } from './codegen-ZBogcw6T.js';
|
|
6
|
+
|
|
7
|
+
declare class Cdm {
|
|
8
|
+
private cdmJson;
|
|
9
|
+
private targetHash;
|
|
10
|
+
private _client;
|
|
11
|
+
private _inkSdk;
|
|
12
|
+
private ownsClient;
|
|
13
|
+
private defaults;
|
|
14
|
+
constructor(cdmJson: CdmJson, options?: CdmOptions);
|
|
15
|
+
setDefaults(defaults: CdmDefaults): void;
|
|
16
|
+
get client(): PolkadotClient;
|
|
17
|
+
get inkSdk(): InkSdk;
|
|
18
|
+
private getContractData;
|
|
19
|
+
getContract<K extends string & keyof CdmContracts>(library: K): CdmContract<CdmContracts[K]>;
|
|
20
|
+
getAddress(library: string): HexString;
|
|
21
|
+
destroy(): void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare function createCdm(cdmJson: CdmJson, options?: CdmOptions): Cdm;
|
|
25
|
+
|
|
26
|
+
export { Cdm, CdmContract, CdmContracts, CdmDefaults, CdmOptions, createCdm };
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
// src/cdm-core.ts
|
|
2
|
+
import { createClient } from "polkadot-api";
|
|
3
|
+
import { getWsProvider } from "polkadot-api/ws-provider";
|
|
4
|
+
import { withPolkadotSdkCompat } from "polkadot-api/polkadot-sdk-compat";
|
|
5
|
+
import { createInkSdk } from "@polkadot-api/sdk-ink";
|
|
6
|
+
import { ALICE_SS58 } from "@dotdm/utils";
|
|
7
|
+
import { prepareSigner } from "@dotdm/env";
|
|
8
|
+
|
|
9
|
+
// src/wrap.ts
|
|
10
|
+
function buildMethodArgMap(abi) {
|
|
11
|
+
const map = {};
|
|
12
|
+
for (const entry of abi) {
|
|
13
|
+
if (entry.type === "function" && entry.name) {
|
|
14
|
+
map[entry.name] = entry.inputs.map((p) => p.name);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return map;
|
|
18
|
+
}
|
|
19
|
+
function positionalToNamed(argNames, values) {
|
|
20
|
+
const data = {};
|
|
21
|
+
for (let i = 0; i < argNames.length; i++) {
|
|
22
|
+
data[argNames[i]] = values[i];
|
|
23
|
+
}
|
|
24
|
+
return data;
|
|
25
|
+
}
|
|
26
|
+
function extractOverrides(argNames, args) {
|
|
27
|
+
if (args.length > argNames.length && args.length > 0) {
|
|
28
|
+
const last = args[args.length - 1];
|
|
29
|
+
if (last && typeof last === "object" && !Array.isArray(last)) {
|
|
30
|
+
return { positionalArgs: args.slice(0, -1), overrides: last };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return { positionalArgs: args };
|
|
34
|
+
}
|
|
35
|
+
function wrapContract(papiContract, abi, defaults) {
|
|
36
|
+
const methodArgs = buildMethodArgMap(abi);
|
|
37
|
+
return new Proxy({}, {
|
|
38
|
+
get(_, methodName) {
|
|
39
|
+
if (typeof methodName !== "string") return void 0;
|
|
40
|
+
const argNames = methodArgs[methodName];
|
|
41
|
+
if (!argNames) return void 0;
|
|
42
|
+
return {
|
|
43
|
+
query: async (...args) => {
|
|
44
|
+
const { positionalArgs, overrides } = extractOverrides(argNames, args);
|
|
45
|
+
const data = positionalToNamed(argNames, positionalArgs);
|
|
46
|
+
const origin = overrides?.origin ?? defaults.origin;
|
|
47
|
+
if (!origin)
|
|
48
|
+
throw new Error(
|
|
49
|
+
"No origin provided for query. Pass { origin } or set defaultOrigin."
|
|
50
|
+
);
|
|
51
|
+
const result = await papiContract.query(methodName, {
|
|
52
|
+
origin,
|
|
53
|
+
data,
|
|
54
|
+
...overrides?.value !== void 0 && { value: overrides.value }
|
|
55
|
+
});
|
|
56
|
+
return {
|
|
57
|
+
success: result.success,
|
|
58
|
+
value: result.success ? result.value.response : void 0,
|
|
59
|
+
gasRequired: result.value?.gasRequired
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
tx: async (...args) => {
|
|
63
|
+
const { positionalArgs, overrides } = extractOverrides(argNames, args);
|
|
64
|
+
const data = positionalToNamed(argNames, positionalArgs);
|
|
65
|
+
const signer = overrides?.signer ?? defaults.signer;
|
|
66
|
+
if (!signer)
|
|
67
|
+
throw new Error(
|
|
68
|
+
"No signer provided for tx. Pass { signer } or set defaultSigner."
|
|
69
|
+
);
|
|
70
|
+
const origin = overrides?.origin ?? defaults.origin;
|
|
71
|
+
const tx = papiContract.send(methodName, {
|
|
72
|
+
data,
|
|
73
|
+
origin: origin ?? "",
|
|
74
|
+
...overrides?.value !== void 0 && { value: overrides.value },
|
|
75
|
+
...overrides?.gasLimit && { gasLimit: overrides.gasLimit },
|
|
76
|
+
...overrides?.storageDepositLimit !== void 0 && {
|
|
77
|
+
storageDepositLimit: overrides.storageDepositLimit
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
const result = await tx.signAndSubmit(signer);
|
|
81
|
+
return {
|
|
82
|
+
txHash: result.txHash,
|
|
83
|
+
blockHash: result.block?.hash ?? "",
|
|
84
|
+
ok: result.ok,
|
|
85
|
+
events: result.events ?? []
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// src/cdm-core.ts
|
|
94
|
+
var Cdm = class {
|
|
95
|
+
cdmJson;
|
|
96
|
+
targetHash;
|
|
97
|
+
_client = null;
|
|
98
|
+
_inkSdk = null;
|
|
99
|
+
ownsClient = false;
|
|
100
|
+
defaults;
|
|
101
|
+
constructor(cdmJson, options) {
|
|
102
|
+
this.cdmJson = cdmJson;
|
|
103
|
+
if (options?.targetHash) {
|
|
104
|
+
this.targetHash = options.targetHash;
|
|
105
|
+
} else {
|
|
106
|
+
const targets = Object.keys(this.cdmJson.targets);
|
|
107
|
+
if (targets.length === 0) throw new Error("No targets found in cdm.json");
|
|
108
|
+
this.targetHash = targets[0];
|
|
109
|
+
}
|
|
110
|
+
if (options?.client) {
|
|
111
|
+
this._client = options.client;
|
|
112
|
+
this.ownsClient = false;
|
|
113
|
+
}
|
|
114
|
+
this.defaults = {
|
|
115
|
+
origin: options?.defaultOrigin ?? ALICE_SS58,
|
|
116
|
+
signer: options?.defaultSigner ?? prepareSigner("Alice")
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
setDefaults(defaults) {
|
|
120
|
+
if (defaults.origin !== void 0) this.defaults.origin = defaults.origin;
|
|
121
|
+
if (defaults.signer !== void 0) this.defaults.signer = defaults.signer;
|
|
122
|
+
}
|
|
123
|
+
get client() {
|
|
124
|
+
if (!this._client) {
|
|
125
|
+
const target = this.cdmJson.targets[this.targetHash];
|
|
126
|
+
if (!target) throw new Error(`Target ${this.targetHash} not found in cdm.json`);
|
|
127
|
+
this._client = createClient(withPolkadotSdkCompat(getWsProvider(target["asset-hub"])));
|
|
128
|
+
this.ownsClient = true;
|
|
129
|
+
}
|
|
130
|
+
return this._client;
|
|
131
|
+
}
|
|
132
|
+
get inkSdk() {
|
|
133
|
+
if (!this._inkSdk) {
|
|
134
|
+
this._inkSdk = createInkSdk(this.client);
|
|
135
|
+
}
|
|
136
|
+
return this._inkSdk;
|
|
137
|
+
}
|
|
138
|
+
getContractData(library) {
|
|
139
|
+
const contractsForTarget = this.cdmJson.contracts?.[this.targetHash];
|
|
140
|
+
if (!contractsForTarget || !(library in contractsForTarget)) {
|
|
141
|
+
throw new Error(
|
|
142
|
+
`Contract "${library}" not found in cdm.json contracts for target ${this.targetHash}`
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
return contractsForTarget[library];
|
|
146
|
+
}
|
|
147
|
+
getContract(library) {
|
|
148
|
+
const data = this.getContractData(library);
|
|
149
|
+
const descriptor = { abi: data.abi };
|
|
150
|
+
const papiContract = this.inkSdk.getContract(descriptor, data.address);
|
|
151
|
+
return wrapContract(papiContract, data.abi, this.defaults);
|
|
152
|
+
}
|
|
153
|
+
getAddress(library) {
|
|
154
|
+
const data = this.getContractData(library);
|
|
155
|
+
return data.address;
|
|
156
|
+
}
|
|
157
|
+
destroy() {
|
|
158
|
+
if (this.ownsClient && this._client) {
|
|
159
|
+
this._client.destroy();
|
|
160
|
+
this._client = null;
|
|
161
|
+
}
|
|
162
|
+
this._inkSdk = null;
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
// src/cdm.ts
|
|
167
|
+
function createCdm(cdmJson, options) {
|
|
168
|
+
return new Cdm(cdmJson, options);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export {
|
|
172
|
+
Cdm,
|
|
173
|
+
createCdm
|
|
174
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// src/codegen.ts
|
|
2
|
+
function mapSolidityType(param) {
|
|
3
|
+
const t = param.type;
|
|
4
|
+
if (t.endsWith("[]")) {
|
|
5
|
+
const inner = { ...param, type: t.slice(0, -2) };
|
|
6
|
+
return `${mapSolidityType(inner)}[]`;
|
|
7
|
+
}
|
|
8
|
+
const fixedArrayMatch = t.match(/^(.+)\[(\d+)\]$/);
|
|
9
|
+
if (fixedArrayMatch) {
|
|
10
|
+
const inner = { ...param, type: fixedArrayMatch[1] };
|
|
11
|
+
return `${mapSolidityType(inner)}[]`;
|
|
12
|
+
}
|
|
13
|
+
if (t === "tuple" && param.components) {
|
|
14
|
+
const fields = param.components.map((c) => `${c.name}: ${mapSolidityType(c)}`);
|
|
15
|
+
return `{ ${fields.join("; ")} }`;
|
|
16
|
+
}
|
|
17
|
+
if (/^uint(8|16|32)$/.test(t)) return "number";
|
|
18
|
+
if (/^uint\d*$/.test(t)) return "bigint";
|
|
19
|
+
if (/^int(8|16|32)$/.test(t)) return "number";
|
|
20
|
+
if (/^int\d*$/.test(t)) return "bigint";
|
|
21
|
+
if (t === "address") return "HexString";
|
|
22
|
+
if (t === "bytes") return "Binary";
|
|
23
|
+
const bytesMatch = t.match(/^bytes(\d+)$/);
|
|
24
|
+
if (bytesMatch) return `FixedSizeBinary<${bytesMatch[1]}>`;
|
|
25
|
+
if (t === "bool") return "boolean";
|
|
26
|
+
if (t === "string") return "string";
|
|
27
|
+
return "unknown";
|
|
28
|
+
}
|
|
29
|
+
function generateMethodResponseType(outputs) {
|
|
30
|
+
if (!outputs || outputs.length === 0) return "undefined";
|
|
31
|
+
if (outputs.length === 1) return mapSolidityType(outputs[0]);
|
|
32
|
+
const fields = outputs.map((o, i) => {
|
|
33
|
+
const name = o.name || `_${i}`;
|
|
34
|
+
return `${name}: ${mapSolidityType(o)}`;
|
|
35
|
+
});
|
|
36
|
+
return `{ ${fields.join("; ")} }`;
|
|
37
|
+
}
|
|
38
|
+
function generateMethodArgsType(inputs) {
|
|
39
|
+
if (inputs.length === 0) return "[]";
|
|
40
|
+
const parts = inputs.map((p) => `${p.name}: ${mapSolidityType(p)}`);
|
|
41
|
+
return `[${parts.join(", ")}]`;
|
|
42
|
+
}
|
|
43
|
+
function generateContractTypes(contracts) {
|
|
44
|
+
const lines = [
|
|
45
|
+
"// Auto-generated by cdm install -- do not edit",
|
|
46
|
+
'import type { HexString, Binary, FixedSizeBinary } from "polkadot-api";',
|
|
47
|
+
"",
|
|
48
|
+
'declare module "@dotdm/cdm" {',
|
|
49
|
+
" interface CdmContracts {"
|
|
50
|
+
];
|
|
51
|
+
for (const contract of contracts) {
|
|
52
|
+
const methods = contract.abi.filter((e) => e.type === "function" && e.name);
|
|
53
|
+
lines.push(` "${contract.library}": {`);
|
|
54
|
+
lines.push(" methods: {");
|
|
55
|
+
for (const method of methods) {
|
|
56
|
+
const args = generateMethodArgsType(method.inputs);
|
|
57
|
+
const response = generateMethodResponseType(method.outputs);
|
|
58
|
+
lines.push(
|
|
59
|
+
` ${method.name}: { args: ${args}; response: ${response} };`
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
lines.push(" };");
|
|
63
|
+
lines.push(" };");
|
|
64
|
+
}
|
|
65
|
+
lines.push(" }");
|
|
66
|
+
lines.push("}");
|
|
67
|
+
lines.push("");
|
|
68
|
+
return lines.join("\n");
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export {
|
|
72
|
+
generateContractTypes
|
|
73
|
+
};
|
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import * as polkadot_api from 'polkadot-api';
|
|
2
|
+
import { SS58String, PolkadotSigner } from 'polkadot-api';
|
|
3
|
+
|
|
4
|
+
interface CdmContractDef {
|
|
3
5
|
methods: Record<string, {
|
|
4
6
|
args: any[];
|
|
5
7
|
response: any;
|
|
6
8
|
}>;
|
|
7
9
|
}
|
|
8
|
-
|
|
10
|
+
interface CdmContracts {
|
|
9
11
|
}
|
|
10
|
-
|
|
12
|
+
interface QueryResult<T> {
|
|
11
13
|
success: boolean;
|
|
12
14
|
value: T;
|
|
13
15
|
gasRequired?: bigint;
|
|
14
16
|
}
|
|
15
|
-
|
|
17
|
+
interface TxOpts {
|
|
16
18
|
signer?: PolkadotSigner;
|
|
17
19
|
origin?: SS58String;
|
|
18
20
|
value?: bigint;
|
|
@@ -22,30 +24,30 @@ export interface TxOpts {
|
|
|
22
24
|
};
|
|
23
25
|
storageDepositLimit?: bigint;
|
|
24
26
|
}
|
|
25
|
-
|
|
27
|
+
interface TxResult {
|
|
26
28
|
txHash: string;
|
|
27
29
|
blockHash: string;
|
|
28
30
|
ok: boolean;
|
|
29
31
|
events: unknown[];
|
|
30
32
|
}
|
|
31
|
-
|
|
33
|
+
type CdmContract<C extends CdmContractDef> = {
|
|
32
34
|
[K in keyof C["methods"]]: {
|
|
33
35
|
query: (...args: C["methods"][K]["args"]) => Promise<QueryResult<C["methods"][K]["response"]>>;
|
|
34
36
|
tx: (...args: [...C["methods"][K]["args"], opts?: TxOpts]) => Promise<TxResult>;
|
|
35
37
|
};
|
|
36
38
|
};
|
|
37
|
-
|
|
39
|
+
interface CdmDefaults {
|
|
38
40
|
origin?: SS58String;
|
|
39
41
|
signer?: PolkadotSigner;
|
|
40
42
|
}
|
|
41
|
-
|
|
43
|
+
interface CdmOptions {
|
|
42
44
|
cdmJsonPath?: string;
|
|
43
45
|
targetHash?: string;
|
|
44
|
-
client?:
|
|
46
|
+
client?: polkadot_api.PolkadotClient;
|
|
45
47
|
defaultOrigin?: SS58String;
|
|
46
48
|
defaultSigner?: PolkadotSigner;
|
|
47
49
|
}
|
|
48
|
-
|
|
50
|
+
interface ResolvedContract {
|
|
49
51
|
name: string;
|
|
50
52
|
address: string;
|
|
51
53
|
abi: AbiEntry[];
|
|
@@ -53,16 +55,22 @@ export interface ResolvedContract {
|
|
|
53
55
|
version: number;
|
|
54
56
|
metadataCid: string;
|
|
55
57
|
}
|
|
56
|
-
|
|
58
|
+
interface AbiParam {
|
|
57
59
|
name: string;
|
|
58
60
|
type: string;
|
|
59
61
|
components?: AbiParam[];
|
|
60
62
|
}
|
|
61
|
-
|
|
63
|
+
interface AbiEntry {
|
|
62
64
|
type: string;
|
|
63
65
|
name?: string;
|
|
64
66
|
inputs: AbiParam[];
|
|
65
67
|
outputs?: AbiParam[];
|
|
66
68
|
stateMutability?: string;
|
|
67
69
|
}
|
|
68
|
-
|
|
70
|
+
|
|
71
|
+
declare function generateContractTypes(contracts: {
|
|
72
|
+
library: string;
|
|
73
|
+
abi: AbiEntry[];
|
|
74
|
+
}[]): string;
|
|
75
|
+
|
|
76
|
+
export { type AbiEntry as A, type CdmOptions as C, type QueryResult as Q, type ResolvedContract as R, type TxOpts as T, type AbiParam as a, type CdmContract as b, type CdmContractDef as c, type CdmContracts as d, type CdmDefaults as e, type TxResult as f, generateContractTypes as g };
|
package/dist/codegen.d.ts
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
library: string;
|
|
4
|
-
abi: AbiEntry[];
|
|
5
|
-
}[]): string;
|
|
6
|
-
//# sourceMappingURL=codegen.d.ts.map
|
|
1
|
+
export { g as generateContractTypes } from './codegen-ZBogcw6T.js';
|
|
2
|
+
import 'polkadot-api';
|
package/dist/codegen.js
CHANGED
|
@@ -1,90 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
// Fixed-size arrays like uint256[3]
|
|
9
|
-
const fixedArrayMatch = t.match(/^(.+)\[(\d+)\]$/);
|
|
10
|
-
if (fixedArrayMatch) {
|
|
11
|
-
const inner = { ...param, type: fixedArrayMatch[1] };
|
|
12
|
-
return `${mapSolidityType(inner)}[]`;
|
|
13
|
-
}
|
|
14
|
-
// Tuple
|
|
15
|
-
if (t === "tuple" && param.components) {
|
|
16
|
-
const fields = param.components.map((c) => `${c.name}: ${mapSolidityType(c)}`);
|
|
17
|
-
return `{ ${fields.join("; ")} }`;
|
|
18
|
-
}
|
|
19
|
-
// Unsigned integers
|
|
20
|
-
if (/^uint(8|16|32)$/.test(t))
|
|
21
|
-
return "number";
|
|
22
|
-
if (/^uint\d*$/.test(t))
|
|
23
|
-
return "bigint"; // uint64, uint128, uint256, uint (=uint256)
|
|
24
|
-
// Signed integers
|
|
25
|
-
if (/^int(8|16|32)$/.test(t))
|
|
26
|
-
return "number";
|
|
27
|
-
if (/^int\d*$/.test(t))
|
|
28
|
-
return "bigint";
|
|
29
|
-
// Address
|
|
30
|
-
if (t === "address")
|
|
31
|
-
return "HexString";
|
|
32
|
-
// Bytes
|
|
33
|
-
if (t === "bytes")
|
|
34
|
-
return "Binary";
|
|
35
|
-
const bytesMatch = t.match(/^bytes(\d+)$/);
|
|
36
|
-
if (bytesMatch)
|
|
37
|
-
return `FixedSizeBinary<${bytesMatch[1]}>`;
|
|
38
|
-
// Boolean
|
|
39
|
-
if (t === "bool")
|
|
40
|
-
return "boolean";
|
|
41
|
-
// String
|
|
42
|
-
if (t === "string")
|
|
43
|
-
return "string";
|
|
44
|
-
// Fallback
|
|
45
|
-
return "unknown";
|
|
46
|
-
}
|
|
47
|
-
function generateMethodResponseType(outputs) {
|
|
48
|
-
if (!outputs || outputs.length === 0)
|
|
49
|
-
return "undefined";
|
|
50
|
-
if (outputs.length === 1)
|
|
51
|
-
return mapSolidityType(outputs[0]);
|
|
52
|
-
// Multiple outputs -> tuple-like object
|
|
53
|
-
const fields = outputs.map((o, i) => {
|
|
54
|
-
const name = o.name || `_${i}`;
|
|
55
|
-
return `${name}: ${mapSolidityType(o)}`;
|
|
56
|
-
});
|
|
57
|
-
return `{ ${fields.join("; ")} }`;
|
|
58
|
-
}
|
|
59
|
-
function generateMethodArgsType(inputs) {
|
|
60
|
-
if (inputs.length === 0)
|
|
61
|
-
return "[]";
|
|
62
|
-
const parts = inputs.map((p) => `${p.name}: ${mapSolidityType(p)}`);
|
|
63
|
-
return `[${parts.join(", ")}]`;
|
|
64
|
-
}
|
|
65
|
-
export function generateContractTypes(contracts) {
|
|
66
|
-
const lines = [
|
|
67
|
-
"// Auto-generated by cdm install -- do not edit",
|
|
68
|
-
'import type { HexString, Binary, FixedSizeBinary } from "polkadot-api";',
|
|
69
|
-
"",
|
|
70
|
-
'declare module "@dotdm/cdm" {',
|
|
71
|
-
" interface CdmContracts {",
|
|
72
|
-
];
|
|
73
|
-
for (const contract of contracts) {
|
|
74
|
-
const methods = contract.abi.filter((e) => e.type === "function" && e.name);
|
|
75
|
-
lines.push(` "${contract.library}": {`);
|
|
76
|
-
lines.push(" methods: {");
|
|
77
|
-
for (const method of methods) {
|
|
78
|
-
const args = generateMethodArgsType(method.inputs);
|
|
79
|
-
const response = generateMethodResponseType(method.outputs);
|
|
80
|
-
lines.push(` ${method.name}: { args: ${args}; response: ${response} };`);
|
|
81
|
-
}
|
|
82
|
-
lines.push(" };");
|
|
83
|
-
lines.push(" };");
|
|
84
|
-
}
|
|
85
|
-
lines.push(" }");
|
|
86
|
-
lines.push("}");
|
|
87
|
-
lines.push("");
|
|
88
|
-
return lines.join("\n");
|
|
89
|
-
}
|
|
90
|
-
//# sourceMappingURL=codegen.js.map
|
|
1
|
+
import {
|
|
2
|
+
generateContractTypes
|
|
3
|
+
} from "./chunk-EFGJVSBH.js";
|
|
4
|
+
export {
|
|
5
|
+
generateContractTypes
|
|
6
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
export { createCdm } from
|
|
3
|
-
|
|
4
|
-
export {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { Cdm } from './browser.js';
|
|
2
|
+
export { createCdm } from './browser.js';
|
|
3
|
+
import { C as CdmOptions, R as ResolvedContract } from './codegen-ZBogcw6T.js';
|
|
4
|
+
export { A as AbiEntry, a as AbiParam, b as CdmContract, c as CdmContractDef, d as CdmContracts, e as CdmDefaults, Q as QueryResult, T as TxOpts, f as TxResult, g as generateContractTypes } from './codegen-ZBogcw6T.js';
|
|
5
|
+
import 'polkadot-api';
|
|
6
|
+
import '@polkadot-api/sdk-ink';
|
|
7
|
+
import '@dotdm/contracts';
|
|
8
|
+
|
|
9
|
+
declare function createCdmFromFile(options?: CdmOptions): Cdm;
|
|
10
|
+
|
|
11
|
+
declare function resolveContract(targetHash: string, library: string, version: number | "latest"): ResolvedContract;
|
|
12
|
+
|
|
13
|
+
export { Cdm, CdmOptions, ResolvedContract, createCdmFromFile, resolveContract };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,58 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import {
|
|
2
|
+
Cdm,
|
|
3
|
+
createCdm
|
|
4
|
+
} from "./chunk-AYCBE7SX.js";
|
|
5
|
+
import {
|
|
6
|
+
generateContractTypes
|
|
7
|
+
} from "./chunk-EFGJVSBH.js";
|
|
8
|
+
|
|
9
|
+
// src/cdm-node.ts
|
|
10
|
+
import { readCdmJson } from "@dotdm/contracts";
|
|
11
|
+
function createCdmFromFile(options) {
|
|
12
|
+
const result = readCdmJson(options?.cdmJsonPath);
|
|
13
|
+
if (!result) {
|
|
14
|
+
throw new Error("cdm.json not found. Run 'cdm install' first.");
|
|
15
|
+
}
|
|
16
|
+
return new Cdm(result.cdmJson, options);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// src/resolver.ts
|
|
20
|
+
import { readFileSync, existsSync, realpathSync } from "fs";
|
|
21
|
+
import { resolve } from "path";
|
|
22
|
+
import { getCdmRoot, getContractDir, resolveContractAbiPath } from "@dotdm/contracts";
|
|
23
|
+
function resolveContract(targetHash, library, version) {
|
|
24
|
+
let resolvedVersion;
|
|
25
|
+
if (version === "latest") {
|
|
26
|
+
const latestLink = resolve(getCdmRoot(), targetHash, "contracts", library, "latest");
|
|
27
|
+
if (!existsSync(latestLink)) {
|
|
28
|
+
throw new Error(`No "latest" symlink found for ${library} in target ${targetHash}`);
|
|
29
|
+
}
|
|
30
|
+
const realPath = realpathSync(latestLink);
|
|
31
|
+
resolvedVersion = parseInt(realPath.split("/").pop(), 10);
|
|
32
|
+
} else {
|
|
33
|
+
resolvedVersion = version;
|
|
34
|
+
}
|
|
35
|
+
const contractDir = getContractDir(targetHash, library, resolvedVersion);
|
|
36
|
+
if (!existsSync(contractDir)) {
|
|
37
|
+
throw new Error(`Contract ${library}@${resolvedVersion} not found in ${contractDir}`);
|
|
38
|
+
}
|
|
39
|
+
const infoPath = resolve(contractDir, "info.json");
|
|
40
|
+
const info = JSON.parse(readFileSync(infoPath, "utf-8"));
|
|
41
|
+
const abiPath = resolveContractAbiPath(targetHash, library, resolvedVersion);
|
|
42
|
+
const abi = JSON.parse(readFileSync(abiPath, "utf-8"));
|
|
43
|
+
return {
|
|
44
|
+
name: info.name,
|
|
45
|
+
address: info.address,
|
|
46
|
+
abi,
|
|
47
|
+
abiPath,
|
|
48
|
+
version: info.version,
|
|
49
|
+
metadataCid: info.metadataCid
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export {
|
|
53
|
+
Cdm,
|
|
54
|
+
createCdm,
|
|
55
|
+
createCdmFromFile,
|
|
56
|
+
generateContractTypes,
|
|
57
|
+
resolveContract
|
|
58
|
+
};
|
package/package.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotdm/cdm",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1-dev.1774500408",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
9
|
+
"browser": {
|
|
10
|
+
"types": "./dist/browser.d.ts",
|
|
11
|
+
"import": "./dist/browser.js"
|
|
12
|
+
},
|
|
9
13
|
"types": "./dist/index.d.ts",
|
|
10
14
|
"import": "./dist/index.js"
|
|
11
15
|
},
|
|
@@ -23,16 +27,17 @@
|
|
|
23
27
|
"dependencies": {
|
|
24
28
|
"@polkadot-api/sdk-ink": "^0.6.2",
|
|
25
29
|
"polkadot-api": "^1.23.3",
|
|
26
|
-
"@dotdm/
|
|
27
|
-
"@dotdm/
|
|
28
|
-
"@dotdm/
|
|
30
|
+
"@dotdm/utils": "0.3.0-dev.1774500408",
|
|
31
|
+
"@dotdm/contracts": "0.3.0-dev.1774500408",
|
|
32
|
+
"@dotdm/env": "0.3.0-dev.1774500408"
|
|
29
33
|
},
|
|
30
34
|
"devDependencies": {
|
|
31
35
|
"@types/node": "^24.10.1",
|
|
36
|
+
"tsup": "^8.5.0",
|
|
32
37
|
"typescript": "^5.9.3"
|
|
33
38
|
},
|
|
34
39
|
"scripts": {
|
|
35
|
-
"build": "
|
|
40
|
+
"build": "tsup src/index.ts src/browser.ts src/codegen.ts --format esm --dts --clean",
|
|
36
41
|
"clean": "rm -rf dist"
|
|
37
42
|
}
|
|
38
43
|
}
|
package/dist/cdm-core.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { PolkadotClient, HexString } from "polkadot-api";
|
|
2
|
-
import type { InkSdk } from "@polkadot-api/sdk-ink";
|
|
3
|
-
import type { CdmJson } from "@dotdm/contracts";
|
|
4
|
-
import type { CdmContract, CdmContracts, CdmDefaults, CdmOptions } from "./types";
|
|
5
|
-
export declare class Cdm {
|
|
6
|
-
private cdmJson;
|
|
7
|
-
private targetHash;
|
|
8
|
-
private _client;
|
|
9
|
-
private _inkSdk;
|
|
10
|
-
private ownsClient;
|
|
11
|
-
private defaults;
|
|
12
|
-
constructor(cdmJson: CdmJson, options?: CdmOptions);
|
|
13
|
-
setDefaults(defaults: CdmDefaults): void;
|
|
14
|
-
get client(): PolkadotClient;
|
|
15
|
-
get inkSdk(): InkSdk;
|
|
16
|
-
private getContractData;
|
|
17
|
-
getContract<K extends string & keyof CdmContracts>(library: K): CdmContract<CdmContracts[K]>;
|
|
18
|
-
getAddress(library: string): HexString;
|
|
19
|
-
destroy(): void;
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=cdm-core.d.ts.map
|
package/dist/cdm-core.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cdm-core.d.ts","sourceRoot":"","sources":["../src/cdm-core.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAc,SAAS,EAAE,MAAM,cAAc,CAAC;AAC1E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,EAAE,OAAO,EAAmB,MAAM,kBAAkB,CAAC;AAIjE,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAElF,qBAAa,GAAG;IACZ,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,OAAO,CAA+B;IAC9C,OAAO,CAAC,OAAO,CAAuB;IACtC,OAAO,CAAC,UAAU,CAAkB;IACpC,OAAO,CAAC,QAAQ,CAAc;gBAElB,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,UAAU;IAuBlD,WAAW,CAAC,QAAQ,EAAE,WAAW,GAAG,IAAI;IAKxC,IAAI,MAAM,IAAI,cAAc,CAQ3B;IAED,IAAI,MAAM,IAAI,MAAM,CAKnB;IAED,OAAO,CAAC,eAAe;IAUvB,WAAW,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,YAAY,EAAE,OAAO,EAAE,CAAC,GAAG,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAU5F,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS;IAKtC,OAAO,IAAI,IAAI;CAOlB"}
|
package/dist/cdm-core.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { createClient } from "polkadot-api";
|
|
2
|
-
import { getWsProvider } from "polkadot-api/ws-provider";
|
|
3
|
-
import { withPolkadotSdkCompat } from "polkadot-api/polkadot-sdk-compat";
|
|
4
|
-
import { createInkSdk } from "@polkadot-api/sdk-ink";
|
|
5
|
-
import { ALICE_SS58 } from "@dotdm/utils";
|
|
6
|
-
import { prepareSigner } from "@dotdm/env";
|
|
7
|
-
import { wrapContract } from "./wrap";
|
|
8
|
-
export class Cdm {
|
|
9
|
-
cdmJson;
|
|
10
|
-
targetHash;
|
|
11
|
-
_client = null;
|
|
12
|
-
_inkSdk = null;
|
|
13
|
-
ownsClient = false;
|
|
14
|
-
defaults;
|
|
15
|
-
constructor(cdmJson, options) {
|
|
16
|
-
this.cdmJson = cdmJson;
|
|
17
|
-
// Determine target hash
|
|
18
|
-
if (options?.targetHash) {
|
|
19
|
-
this.targetHash = options.targetHash;
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
const targets = Object.keys(this.cdmJson.targets);
|
|
23
|
-
if (targets.length === 0)
|
|
24
|
-
throw new Error("No targets found in cdm.json");
|
|
25
|
-
this.targetHash = targets[0];
|
|
26
|
-
}
|
|
27
|
-
if (options?.client) {
|
|
28
|
-
this._client = options.client;
|
|
29
|
-
this.ownsClient = false;
|
|
30
|
-
}
|
|
31
|
-
this.defaults = {
|
|
32
|
-
origin: options?.defaultOrigin ?? ALICE_SS58,
|
|
33
|
-
signer: options?.defaultSigner ?? prepareSigner("Alice"),
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
setDefaults(defaults) {
|
|
37
|
-
if (defaults.origin !== undefined)
|
|
38
|
-
this.defaults.origin = defaults.origin;
|
|
39
|
-
if (defaults.signer !== undefined)
|
|
40
|
-
this.defaults.signer = defaults.signer;
|
|
41
|
-
}
|
|
42
|
-
get client() {
|
|
43
|
-
if (!this._client) {
|
|
44
|
-
const target = this.cdmJson.targets[this.targetHash];
|
|
45
|
-
if (!target)
|
|
46
|
-
throw new Error(`Target ${this.targetHash} not found in cdm.json`);
|
|
47
|
-
this._client = createClient(withPolkadotSdkCompat(getWsProvider(target["asset-hub"])));
|
|
48
|
-
this.ownsClient = true;
|
|
49
|
-
}
|
|
50
|
-
return this._client;
|
|
51
|
-
}
|
|
52
|
-
get inkSdk() {
|
|
53
|
-
if (!this._inkSdk) {
|
|
54
|
-
this._inkSdk = createInkSdk(this.client);
|
|
55
|
-
}
|
|
56
|
-
return this._inkSdk;
|
|
57
|
-
}
|
|
58
|
-
getContractData(library) {
|
|
59
|
-
const contractsForTarget = this.cdmJson.contracts?.[this.targetHash];
|
|
60
|
-
if (!contractsForTarget || !(library in contractsForTarget)) {
|
|
61
|
-
throw new Error(`Contract "${library}" not found in cdm.json contracts for target ${this.targetHash}`);
|
|
62
|
-
}
|
|
63
|
-
return contractsForTarget[library];
|
|
64
|
-
}
|
|
65
|
-
getContract(library) {
|
|
66
|
-
const data = this.getContractData(library);
|
|
67
|
-
const descriptor = { abi: data.abi };
|
|
68
|
-
const papiContract = this.inkSdk.getContract(descriptor, data.address);
|
|
69
|
-
return wrapContract(papiContract, data.abi, this.defaults);
|
|
70
|
-
}
|
|
71
|
-
getAddress(library) {
|
|
72
|
-
const data = this.getContractData(library);
|
|
73
|
-
return data.address;
|
|
74
|
-
}
|
|
75
|
-
destroy() {
|
|
76
|
-
if (this.ownsClient && this._client) {
|
|
77
|
-
this._client.destroy();
|
|
78
|
-
this._client = null;
|
|
79
|
-
}
|
|
80
|
-
this._inkSdk = null;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
//# sourceMappingURL=cdm-core.js.map
|
package/dist/cdm-core.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cdm-core.js","sourceRoot":"","sources":["../src/cdm-core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAIrD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGtC,MAAM,OAAO,GAAG;IACJ,OAAO,CAAU;IACjB,UAAU,CAAS;IACnB,OAAO,GAA0B,IAAI,CAAC;IACtC,OAAO,GAAkB,IAAI,CAAC;IAC9B,UAAU,GAAY,KAAK,CAAC;IAC5B,QAAQ,CAAc;IAE9B,YAAY,OAAgB,EAAE,OAAoB;QAC9C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,wBAAwB;QACxB,IAAI,OAAO,EAAE,UAAU,EAAE,CAAC;YACtB,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACzC,CAAC;aAAM,CAAC;YACJ,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAClD,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;gBAAE,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAA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ELETED
package/dist/cdm-node.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cdm-node.d.ts","sourceRoot":"","sources":["../src/cdm-node.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C,wBAAgB,iBAAiB,CAAC,OAAO,CAAC,EAAE,UAAU,GAAG,GAAG,CAM3D"}
|
package/dist/cdm-node.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { readCdmJson } from "@dotdm/contracts";
|
|
2
|
-
import { Cdm } from "./cdm-core";
|
|
3
|
-
export function createCdmFromFile(options) {
|
|
4
|
-
const result = readCdmJson(options?.cdmJsonPath);
|
|
5
|
-
if (!result) {
|
|
6
|
-
throw new Error("cdm.json not found. Run 'cdm install' first.");
|
|
7
|
-
}
|
|
8
|
-
return new Cdm(result.cdmJson, options);
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=cdm-node.js.map
|
package/dist/cdm-node.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cdm-node.js","sourceRoot":"","sources":["../src/cdm-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAGjC,MAAM,UAAU,iBAAiB,CAAC,OAAoB;IAClD,MAAM,MAAM,GAAG,WAAW,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IACjD,IAAI,CAAC,MAAM,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IACpE,CAAC;IACD,OAAO,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAC5C,CAAC"}
|
package/dist/cdm.d.ts
DELETED
package/dist/cdm.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cdm.d.ts","sourceRoot":"","sources":["../src/cdm.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C,wBAAgB,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,GAAG,CAErE"}
|
package/dist/cdm.js
DELETED
package/dist/cdm.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cdm.js","sourceRoot":"","sources":["../src/cdm.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAGjC,MAAM,UAAU,SAAS,CAAC,OAAgB,EAAE,OAAoB;IAC5D,OAAO,IAAI,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AACrC,CAAC"}
|
package/dist/codegen.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../src/codegen.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAY,MAAM,SAAS,CAAC;AAmElD,wBAAgB,qBAAqB,CAAC,SAAS,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,QAAQ,EAAE,CAAA;CAAE,EAAE,GAAG,MAAM,CA6B/F"}
|
package/dist/codegen.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"codegen.js","sourceRoot":"","sources":["../src/codegen.ts"],"names":[],"mappings":"AAEA,SAAS,eAAe,CAAC,KAAe;IACpC,MAAM,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC;IAErB,cAAc;IACd,IAAI,CAAC,CAAC,QAAQ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Root":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAClD,YAAY,EACR,WAAW,EACX,YAAY,EACZ,cAAc,EACd,WAAW,EACX,UAAU,EACV,WAAW,EACX,MAAM,EACN,QAAQ,EACR,gBAAgB,EAChB,QAAQ,EACR,QAAQ,GACX,MAAM,SAAS,CAAC"}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/resolver.d.ts
DELETED
package/dist/resolver.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../src/resolver.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAY,MAAM,SAAS,CAAC;AAE1D,wBAAgB,eAAe,CAC3B,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GAAG,QAAQ,GAC3B,gBAAgB,CAiClB"}
|
package/dist/resolver.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { readFileSync, existsSync, realpathSync } from "fs";
|
|
2
|
-
import { resolve } from "path";
|
|
3
|
-
import { getCdmRoot, getContractDir, resolveContractAbiPath } from "@dotdm/contracts";
|
|
4
|
-
export function resolveContract(targetHash, library, version) {
|
|
5
|
-
// If version is "latest", resolve the symlink
|
|
6
|
-
let resolvedVersion;
|
|
7
|
-
if (version === "latest") {
|
|
8
|
-
const latestLink = resolve(getCdmRoot(), targetHash, "contracts", library, "latest");
|
|
9
|
-
if (!existsSync(latestLink)) {
|
|
10
|
-
throw new Error(`No "latest" symlink found for ${library} in target ${targetHash}`);
|
|
11
|
-
}
|
|
12
|
-
const realPath = realpathSync(latestLink);
|
|
13
|
-
resolvedVersion = parseInt(realPath.split("/").pop(), 10);
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
resolvedVersion = version;
|
|
17
|
-
}
|
|
18
|
-
const contractDir = getContractDir(targetHash, library, resolvedVersion);
|
|
19
|
-
if (!existsSync(contractDir)) {
|
|
20
|
-
throw new Error(`Contract ${library}@${resolvedVersion} not found in ${contractDir}`);
|
|
21
|
-
}
|
|
22
|
-
const infoPath = resolve(contractDir, "info.json");
|
|
23
|
-
const info = JSON.parse(readFileSync(infoPath, "utf-8"));
|
|
24
|
-
const abiPath = resolveContractAbiPath(targetHash, library, resolvedVersion);
|
|
25
|
-
const abi = JSON.parse(readFileSync(abiPath, "utf-8"));
|
|
26
|
-
return {
|
|
27
|
-
name: info.name,
|
|
28
|
-
address: info.address,
|
|
29
|
-
abi,
|
|
30
|
-
abiPath,
|
|
31
|
-
version: info.version,
|
|
32
|
-
metadataCid: info.metadataCid,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
//# sourceMappingURL=resolver.js.map
|
package/dist/resolver.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolver.js","sourceRoot":"","sources":["../src/resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,IAAI,C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C;CAC3B;AAED,MAAM,WAAW,QAAQ;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,QAAQ,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,QAAQ,EAAE,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC5B"}
|
package/dist/types.js
DELETED
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/dist/wrap.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { AbiEntry, CdmDefaults, QueryResult, TxResult } from "./types";
|
|
2
|
-
type PapiInkContract = any;
|
|
3
|
-
export declare function wrapContract(papiContract: PapiInkContract, abi: AbiEntry[], defaults: CdmDefaults): Record<string, {
|
|
4
|
-
query: (...args: any[]) => Promise<QueryResult<any>>;
|
|
5
|
-
tx: (...args: any[]) => Promise<TxResult>;
|
|
6
|
-
}>;
|
|
7
|
-
export {};
|
|
8
|
-
//# sourceMappingURL=wrap.d.ts.map
|
package/dist/wrap.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wrap.d.ts","sourceRoot":"","sources":["../src/wrap.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAU,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEpF,KAAK,eAAe,GAAG,GAAG,CAAC;AAkC3B,wBAAgB,YAAY,CACxB,YAAY,EAAE,eAAe,EAC7B,GAAG,EAAE,QAAQ,EAAE,EACf,QAAQ,EAAE,WAAW,GACtB,MAAM,CACL,MAAM,EACN;IACI,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;IACrD,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;CAC7C,CACJ,CA+DA"}
|
package/dist/wrap.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
function buildMethodArgMap(abi) {
|
|
2
|
-
const map = {};
|
|
3
|
-
for (const entry of abi) {
|
|
4
|
-
if (entry.type === "function" && entry.name) {
|
|
5
|
-
map[entry.name] = entry.inputs.map((p) => p.name);
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
return map;
|
|
9
|
-
}
|
|
10
|
-
function positionalToNamed(argNames, values) {
|
|
11
|
-
const data = {};
|
|
12
|
-
for (let i = 0; i < argNames.length; i++) {
|
|
13
|
-
data[argNames[i]] = values[i];
|
|
14
|
-
}
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
// Check if last arg is an overrides object (not a regular positional arg)
|
|
18
|
-
function extractOverrides(argNames, args) {
|
|
19
|
-
if (args.length > argNames.length && args.length > 0) {
|
|
20
|
-
const last = args[args.length - 1];
|
|
21
|
-
if (last && typeof last === "object" && !Array.isArray(last)) {
|
|
22
|
-
return { positionalArgs: args.slice(0, -1), overrides: last };
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return { positionalArgs: args };
|
|
26
|
-
}
|
|
27
|
-
export function wrapContract(papiContract, abi, defaults) {
|
|
28
|
-
const methodArgs = buildMethodArgMap(abi);
|
|
29
|
-
return new Proxy({}, {
|
|
30
|
-
get(_, methodName) {
|
|
31
|
-
if (typeof methodName !== "string")
|
|
32
|
-
return undefined;
|
|
33
|
-
const argNames = methodArgs[methodName];
|
|
34
|
-
if (!argNames)
|
|
35
|
-
return undefined;
|
|
36
|
-
return {
|
|
37
|
-
query: async (...args) => {
|
|
38
|
-
const { positionalArgs, overrides } = extractOverrides(argNames, args);
|
|
39
|
-
const data = positionalToNamed(argNames, positionalArgs);
|
|
40
|
-
const origin = overrides?.origin ?? defaults.origin;
|
|
41
|
-
if (!origin)
|
|
42
|
-
throw new Error("No origin provided for query. Pass { origin } or set defaultOrigin.");
|
|
43
|
-
const result = await papiContract.query(methodName, {
|
|
44
|
-
origin,
|
|
45
|
-
data,
|
|
46
|
-
...(overrides?.value !== undefined && { value: overrides.value }),
|
|
47
|
-
});
|
|
48
|
-
return {
|
|
49
|
-
success: result.success,
|
|
50
|
-
value: result.success ? result.value.response : undefined,
|
|
51
|
-
gasRequired: result.value?.gasRequired,
|
|
52
|
-
};
|
|
53
|
-
},
|
|
54
|
-
tx: async (...args) => {
|
|
55
|
-
const { positionalArgs, overrides } = extractOverrides(argNames, args);
|
|
56
|
-
const data = positionalToNamed(argNames, positionalArgs);
|
|
57
|
-
const signer = overrides?.signer ?? defaults.signer;
|
|
58
|
-
if (!signer)
|
|
59
|
-
throw new Error("No signer provided for tx. Pass { signer } or set defaultSigner.");
|
|
60
|
-
const origin = overrides?.origin ?? defaults.origin;
|
|
61
|
-
const tx = papiContract.send(methodName, {
|
|
62
|
-
data,
|
|
63
|
-
origin: origin ?? "",
|
|
64
|
-
...(overrides?.value !== undefined && { value: overrides.value }),
|
|
65
|
-
...(overrides?.gasLimit && { gasLimit: overrides.gasLimit }),
|
|
66
|
-
...(overrides?.storageDepositLimit !== undefined && {
|
|
67
|
-
storageDepositLimit: overrides.storageDepositLimit,
|
|
68
|
-
}),
|
|
69
|
-
});
|
|
70
|
-
const result = await tx.signAndSubmit(signer);
|
|
71
|
-
return {
|
|
72
|
-
txHash: result.txHash,
|
|
73
|
-
blockHash: result.block?.hash ?? "",
|
|
74
|
-
ok: result.ok,
|
|
75
|
-
events: result.events ?? [],
|
|
76
|
-
};
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
//# sourceMappingURL=wrap.js.map
|
package/dist/wrap.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wrap.js","sourceRoot":"","sources":["../src/wrap.ts"],"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