@dotdm/contracts 0.2.2 → 0.2.3
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/registry.d.ts +10 -13
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +52 -46
- package/dist/registry.js.map +1 -1
- package/package.json +4 -4
package/dist/registry.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PolkadotClient, TypedApi } from "polkadot-api";
|
|
1
|
+
import { PolkadotClient, TypedApi, SS58String } from "polkadot-api";
|
|
2
2
|
import { AssetHub } from "@dotdm/descriptors";
|
|
3
3
|
import { prepareSigner } from "@dotdm/env";
|
|
4
4
|
export declare function getRegistryContract(client: PolkadotClient, addr: string): import("@polkadot-api/sdk-ink").ContractSdk<import("polkadot-api/ink").InkDescriptors<{}, {
|
|
@@ -77,29 +77,26 @@ export declare function getRegistryContract(client: PolkadotClient, addr: string
|
|
|
77
77
|
};
|
|
78
78
|
}, never>>;
|
|
79
79
|
export type RegistryContract = ReturnType<typeof getRegistryContract>;
|
|
80
|
+
type RegisterEntry = {
|
|
81
|
+
cdmPackage: string;
|
|
82
|
+
contractAddr: string;
|
|
83
|
+
metadataUri: string;
|
|
84
|
+
};
|
|
80
85
|
export declare class RegistryManager {
|
|
81
86
|
signer: ReturnType<typeof prepareSigner>;
|
|
87
|
+
origin: SS58String;
|
|
82
88
|
api: TypedApi<AssetHub>;
|
|
83
89
|
client: PolkadotClient;
|
|
84
90
|
registry: RegistryContract;
|
|
85
|
-
constructor(signer: ReturnType<typeof prepareSigner>, api: TypedApi<AssetHub>, client: PolkadotClient, registryAddress: string);
|
|
86
|
-
/**
|
|
87
|
-
* Register a contract in the contracts registry via ink SDK.
|
|
88
|
-
*/
|
|
91
|
+
constructor(signer: ReturnType<typeof prepareSigner>, origin: SS58String, api: TypedApi<AssetHub>, client: PolkadotClient, registryAddress: string);
|
|
89
92
|
register(cdmPackage: string, contractAddr: string, metadataUri?: string): Promise<{
|
|
90
93
|
txHash: string;
|
|
91
94
|
blockHash: string;
|
|
92
95
|
}>;
|
|
93
|
-
|
|
94
|
-
* Register multiple contracts in a single Utility.batch_all transaction.
|
|
95
|
-
*/
|
|
96
|
-
registerBatch(entries: {
|
|
97
|
-
cdmPackage: string;
|
|
98
|
-
contractAddr: string;
|
|
99
|
-
metadataUri: string;
|
|
100
|
-
}[]): Promise<{
|
|
96
|
+
registerBatch(entries: RegisterEntry[]): Promise<{
|
|
101
97
|
txHash: string;
|
|
102
98
|
blockHash: string;
|
|
103
99
|
}>;
|
|
104
100
|
}
|
|
101
|
+
export {};
|
|
105
102
|
//# sourceMappingURL=registry.d.ts.map
|
package/dist/registry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAa,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG3C,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAGvE;AAED,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC;AACtE,KAAK,aAAa,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvF,qBAAa,eAAe;IACjB,MAAM,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;IACzC,MAAM,EAAE,UAAU,CAAC;IACnB,GAAG,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACxB,MAAM,EAAE,cAAc,CAAC;IACvB,QAAQ,EAAE,gBAAgB,CAAC;gBAG9B,MAAM,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,EACxC,MAAM,EAAE,UAAU,EAClB,GAAG,EAAE,QAAQ,CAAC,QAAQ,CAAC,EACvB,MAAM,EAAE,cAAc,EACtB,eAAe,EAAE,MAAM;IASrB,QAAQ,CACV,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,EACpB,WAAW,GAAE,MAAW,GACzB,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAI3C,aAAa,CAAC,OAAO,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;CA2EhG"}
|
package/dist/registry.js
CHANGED
|
@@ -7,70 +7,76 @@ export function getRegistryContract(client, addr) {
|
|
|
7
7
|
}
|
|
8
8
|
export class RegistryManager {
|
|
9
9
|
signer;
|
|
10
|
+
origin;
|
|
10
11
|
api;
|
|
11
12
|
client;
|
|
12
13
|
registry;
|
|
13
|
-
constructor(signer, api, client, registryAddress) {
|
|
14
|
+
constructor(signer, origin, api, client, registryAddress) {
|
|
14
15
|
this.signer = signer;
|
|
16
|
+
this.origin = origin;
|
|
15
17
|
this.api = api;
|
|
16
18
|
this.client = client;
|
|
17
19
|
this.registry = getRegistryContract(client, registryAddress);
|
|
18
20
|
}
|
|
19
|
-
/**
|
|
20
|
-
* Register a contract in the contracts registry via ink SDK.
|
|
21
|
-
*/
|
|
22
21
|
async register(cdmPackage, contractAddr, metadataUri = "") {
|
|
23
|
-
|
|
24
|
-
.send("publishLatest", {
|
|
25
|
-
data: {
|
|
26
|
-
contract_name: cdmPackage,
|
|
27
|
-
contract_address: contractAddr,
|
|
28
|
-
metadata_uri: metadataUri,
|
|
29
|
-
},
|
|
30
|
-
gasLimit: {
|
|
31
|
-
ref_time: GAS_LIMIT.refTime,
|
|
32
|
-
proof_size: GAS_LIMIT.proofSize,
|
|
33
|
-
},
|
|
34
|
-
storageDepositLimit: STORAGE_DEPOSIT_LIMIT,
|
|
35
|
-
})
|
|
36
|
-
.signAndSubmit(this.signer);
|
|
37
|
-
const failures = this.api.event.System.ExtrinsicFailed.filter(result.events);
|
|
38
|
-
if (failures.length > 0) {
|
|
39
|
-
throw new Error(`Register failed: ${stringifyBigInt(failures[0])}`);
|
|
40
|
-
}
|
|
41
|
-
return { txHash: result.txHash, blockHash: result.block.hash };
|
|
22
|
+
return this.registerBatch([{ cdmPackage, contractAddr, metadataUri }]);
|
|
42
23
|
}
|
|
43
|
-
/**
|
|
44
|
-
* Register multiple contracts in a single Utility.batch_all transaction.
|
|
45
|
-
*/
|
|
46
24
|
async registerBatch(entries) {
|
|
47
25
|
if (entries.length === 0)
|
|
48
26
|
return { txHash: "", blockHash: "" };
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
const txs = entries.map((entry) => this.registry.send("publishLatest", {
|
|
27
|
+
const mapped = entries.map((e) => ({
|
|
28
|
+
pkg: e.cdmPackage,
|
|
53
29
|
data: {
|
|
54
|
-
contract_name:
|
|
55
|
-
contract_address:
|
|
56
|
-
metadata_uri:
|
|
57
|
-
},
|
|
58
|
-
gasLimit: {
|
|
59
|
-
ref_time: GAS_LIMIT.refTime,
|
|
60
|
-
proof_size: GAS_LIMIT.proofSize,
|
|
30
|
+
contract_name: e.cdmPackage,
|
|
31
|
+
contract_address: e.contractAddr,
|
|
32
|
+
metadata_uri: e.metadataUri,
|
|
61
33
|
},
|
|
62
|
-
storageDepositLimit: STORAGE_DEPOSIT_LIMIT,
|
|
63
|
-
}));
|
|
64
|
-
const calls = await Promise.all(txs.map(async (tx) => {
|
|
65
|
-
const call = tx.decodedCall;
|
|
66
|
-
return call instanceof Promise ? await call : call;
|
|
67
34
|
}));
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
35
|
+
const sendOpts = {
|
|
36
|
+
gasLimit: { ref_time: GAS_LIMIT.refTime, proof_size: GAS_LIMIT.proofSize },
|
|
37
|
+
storageDepositLimit: STORAGE_DEPOSIT_LIMIT,
|
|
38
|
+
};
|
|
39
|
+
// Dry-run all entries in parallel with submission
|
|
40
|
+
const dryRun = Promise.all(mapped.map((m) => this.registry.query("publishLatest", { origin: this.origin, data: m.data }).then((r) => {
|
|
41
|
+
if (!r.success)
|
|
42
|
+
throw new Error(`Registry rejected "${m.pkg}": not the owner of this contract name`);
|
|
43
|
+
}, (err) => {
|
|
44
|
+
throw new Error(`Registry will revert for "${m.pkg}": ${err}`);
|
|
45
|
+
})));
|
|
46
|
+
// Submit: single call or batch_all
|
|
47
|
+
let submit;
|
|
48
|
+
if (mapped.length === 1) {
|
|
49
|
+
submit = this.registry
|
|
50
|
+
.send("publishLatest", { data: mapped[0].data, ...sendOpts })
|
|
51
|
+
.signAndSubmit(this.signer);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
const txs = mapped.map((m) => this.registry.send("publishLatest", { data: m.data, ...sendOpts }));
|
|
55
|
+
const calls = await Promise.all(txs.map(async (tx) => {
|
|
56
|
+
const call = tx.decodedCall;
|
|
57
|
+
return call instanceof Promise ? await call : call;
|
|
58
|
+
}));
|
|
59
|
+
submit = this.api.tx.Utility.batch_all({ calls }).signAndSubmit(this.signer);
|
|
60
|
+
}
|
|
61
|
+
// Race: dry-run failure exits early with better error
|
|
62
|
+
const result = await new Promise((resolve, reject) => {
|
|
63
|
+
dryRun.catch(reject);
|
|
64
|
+
submit.then(resolve, async (err) => {
|
|
65
|
+
try {
|
|
66
|
+
await dryRun;
|
|
67
|
+
reject(err);
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
reject(e);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
71
74
|
const failures = this.api.event.System.ExtrinsicFailed.filter(result.events);
|
|
72
75
|
if (failures.length > 0) {
|
|
73
|
-
|
|
76
|
+
await dryRun.catch((e) => {
|
|
77
|
+
throw e;
|
|
78
|
+
});
|
|
79
|
+
throw new Error(`Register failed: ${stringifyBigInt(failures[0])}`);
|
|
74
80
|
}
|
|
75
81
|
return { txHash: result.txHash, blockHash: result.block.hash };
|
|
76
82
|
}
|
package/dist/registry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAEjF,MAAM,UAAU,mBAAmB,CAAC,MAAsB,EAAE,IAAY;IACpE,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IACpC,OAAO,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC;AACjE,CAAC;
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAEjF,MAAM,UAAU,mBAAmB,CAAC,MAAsB,EAAE,IAAY;IACpE,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IACpC,OAAO,MAAM,CAAC,WAAW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,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IACnE,CAAC;CACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotdm/contracts",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"@polkadot-api/sdk-ink": "^0.6.2",
|
|
22
22
|
"multiformats": "^13.4.2",
|
|
23
23
|
"polkadot-api": "^1.23.3",
|
|
24
|
-
"@dotdm/descriptors": "0.1.
|
|
25
|
-
"@dotdm/env": "0.2.
|
|
26
|
-
"@dotdm/utils": "0.2.
|
|
24
|
+
"@dotdm/descriptors": "0.1.2",
|
|
25
|
+
"@dotdm/env": "0.2.2",
|
|
26
|
+
"@dotdm/utils": "0.2.2"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/node": "^24.10.1",
|