@dotdm/contracts 0.2.2-dev.1772309292 → 0.2.2
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 +13 -10
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +46 -52
- package/dist/registry.js.map +1 -1
- package/package.json +2 -2
package/dist/registry.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PolkadotClient, TypedApi
|
|
1
|
+
import { PolkadotClient, TypedApi } 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,26 +77,29 @@ 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
|
-
};
|
|
85
80
|
export declare class RegistryManager {
|
|
86
81
|
signer: ReturnType<typeof prepareSigner>;
|
|
87
|
-
origin: SS58String;
|
|
88
82
|
api: TypedApi<AssetHub>;
|
|
89
83
|
client: PolkadotClient;
|
|
90
84
|
registry: RegistryContract;
|
|
91
|
-
constructor(signer: ReturnType<typeof prepareSigner>,
|
|
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
|
+
*/
|
|
92
89
|
register(cdmPackage: string, contractAddr: string, metadataUri?: string): Promise<{
|
|
93
90
|
txHash: string;
|
|
94
91
|
blockHash: string;
|
|
95
92
|
}>;
|
|
96
|
-
|
|
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<{
|
|
97
101
|
txHash: string;
|
|
98
102
|
blockHash: string;
|
|
99
103
|
}>;
|
|
100
104
|
}
|
|
101
|
-
export {};
|
|
102
105
|
//# 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,
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxD,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;AAEtE,qBAAa,eAAe;IACjB,MAAM,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;IACzC,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,GAAG,EAAE,QAAQ,CAAC,QAAQ,CAAC,EACvB,MAAM,EAAE,cAAc,EACtB,eAAe,EAAE,MAAM;IAQ3B;;OAEG;IACG,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;IAwBjD;;OAEG;IACG,aAAa,CACf,OAAO,EAAE;QACL,UAAU,EAAE,MAAM,CAAC;QACnB,YAAY,EAAE,MAAM,CAAC;QACrB,WAAW,EAAE,MAAM,CAAC;KACvB,EAAE,GACJ,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;CA2CpD"}
|
package/dist/registry.js
CHANGED
|
@@ -7,76 +7,70 @@ export function getRegistryContract(client, addr) {
|
|
|
7
7
|
}
|
|
8
8
|
export class RegistryManager {
|
|
9
9
|
signer;
|
|
10
|
-
origin;
|
|
11
10
|
api;
|
|
12
11
|
client;
|
|
13
12
|
registry;
|
|
14
|
-
constructor(signer,
|
|
13
|
+
constructor(signer, api, client, registryAddress) {
|
|
15
14
|
this.signer = signer;
|
|
16
|
-
this.origin = origin;
|
|
17
15
|
this.api = api;
|
|
18
16
|
this.client = client;
|
|
19
17
|
this.registry = getRegistryContract(client, registryAddress);
|
|
20
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Register a contract in the contracts registry via ink SDK.
|
|
21
|
+
*/
|
|
21
22
|
async register(cdmPackage, contractAddr, metadataUri = "") {
|
|
22
|
-
|
|
23
|
+
const result = await this.registry
|
|
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 };
|
|
23
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Register multiple contracts in a single Utility.batch_all transaction.
|
|
45
|
+
*/
|
|
24
46
|
async registerBatch(entries) {
|
|
25
47
|
if (entries.length === 0)
|
|
26
48
|
return { txHash: "", blockHash: "" };
|
|
27
|
-
|
|
28
|
-
|
|
49
|
+
if (entries.length === 1) {
|
|
50
|
+
return this.register(entries[0].cdmPackage, entries[0].contractAddr, entries[0].metadataUri);
|
|
51
|
+
}
|
|
52
|
+
const txs = entries.map((entry) => this.registry.send("publishLatest", {
|
|
29
53
|
data: {
|
|
30
|
-
contract_name:
|
|
31
|
-
contract_address:
|
|
32
|
-
metadata_uri:
|
|
54
|
+
contract_name: entry.cdmPackage,
|
|
55
|
+
contract_address: entry.contractAddr,
|
|
56
|
+
metadata_uri: entry.metadataUri,
|
|
57
|
+
},
|
|
58
|
+
gasLimit: {
|
|
59
|
+
ref_time: GAS_LIMIT.refTime,
|
|
60
|
+
proof_size: GAS_LIMIT.proofSize,
|
|
33
61
|
},
|
|
34
|
-
}));
|
|
35
|
-
const sendOpts = {
|
|
36
|
-
gasLimit: { ref_time: GAS_LIMIT.refTime, proof_size: GAS_LIMIT.proofSize },
|
|
37
62
|
storageDepositLimit: STORAGE_DEPOSIT_LIMIT,
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
});
|
|
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
|
+
}));
|
|
68
|
+
const result = await this.api.tx.Utility.batch_all({
|
|
69
|
+
calls,
|
|
70
|
+
}).signAndSubmit(this.signer);
|
|
74
71
|
const failures = this.api.event.System.ExtrinsicFailed.filter(result.events);
|
|
75
72
|
if (failures.length > 0) {
|
|
76
|
-
|
|
77
|
-
throw e;
|
|
78
|
-
});
|
|
79
|
-
throw new Error(`Register failed: ${stringifyBigInt(failures[0])}`);
|
|
73
|
+
throw new Error(`Batch register failed: ${stringifyBigInt(failures[0])}`);
|
|
80
74
|
}
|
|
81
75
|
return { txHash: result.txHash, blockHash: result.block.hash };
|
|
82
76
|
}
|
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,CAAC,SAAS,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC;AACjE,CAAC;AAID,MAAM,OAAO,eAAe;IACjB,MAAM,CAAmC;IACzC,GAAG,CAAqB;IACxB,MAAM,CAAiB;IACvB,QAAQ,CAAmB;IAElC,YACI,MAAwC,EACxC,GAAuB,EACvB,MAAsB,EACtB,eAAuB;QAEvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,MAAM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C,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAC9E,CAAC;QAED,OAAO,EAAE,MAAM,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.2
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"multiformats": "^13.4.2",
|
|
23
23
|
"polkadot-api": "^1.23.3",
|
|
24
24
|
"@dotdm/descriptors": "0.1.1",
|
|
25
|
-
"@dotdm/env": "0.2.1
|
|
25
|
+
"@dotdm/env": "0.2.1",
|
|
26
26
|
"@dotdm/utils": "0.2.1"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|