@ckb-ccc/spore 1.0.8 → 1.1.1
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/CHANGELOG.md +22 -0
- package/dist/advanced.d.ts +2 -4
- package/dist/advanced.d.ts.map +1 -1
- package/dist/advanced.js +2 -4
- package/dist/advancedBarrel.d.ts +5 -0
- package/dist/advancedBarrel.d.ts.map +1 -0
- package/dist/advancedBarrel.js +4 -0
- package/dist/barrel.d.ts +5 -0
- package/dist/barrel.d.ts.map +1 -0
- package/dist/barrel.js +4 -0
- package/dist/cluster/index.d.ts +7 -2
- package/dist/cluster/index.d.ts.map +1 -1
- package/dist/cluster/index.js +21 -25
- package/dist/helper/index.d.ts +0 -2
- package/dist/helper/index.d.ts.map +1 -1
- package/dist/helper/index.js +0 -19
- package/dist/index.d.ts +2 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -4
- package/dist/spore/advanced.d.ts.map +1 -1
- package/dist/spore/advanced.js +2 -10
- package/dist/spore/index.d.ts +9 -4
- package/dist/spore/index.d.ts.map +1 -1
- package/dist/spore/index.js +29 -30
- package/dist.commonjs/advanced.d.ts +2 -4
- package/dist.commonjs/advanced.d.ts.map +1 -1
- package/dist.commonjs/advanced.js +15 -4
- package/dist.commonjs/advancedBarrel.d.ts +5 -0
- package/dist.commonjs/advancedBarrel.d.ts.map +1 -0
- package/dist.commonjs/advancedBarrel.js +20 -0
- package/dist.commonjs/barrel.d.ts +5 -0
- package/dist.commonjs/barrel.d.ts.map +1 -0
- package/dist.commonjs/barrel.js +33 -0
- package/dist.commonjs/cluster/index.d.ts +7 -2
- package/dist.commonjs/cluster/index.d.ts.map +1 -1
- package/dist.commonjs/cluster/index.js +18 -22
- package/dist.commonjs/helper/index.d.ts +0 -2
- package/dist.commonjs/helper/index.d.ts.map +1 -1
- package/dist.commonjs/helper/index.js +0 -21
- package/dist.commonjs/index.d.ts +2 -4
- package/dist.commonjs/index.d.ts.map +1 -1
- package/dist.commonjs/index.js +3 -5
- package/dist.commonjs/spore/advanced.d.ts.map +1 -1
- package/dist.commonjs/spore/advanced.js +2 -10
- package/dist.commonjs/spore/index.d.ts +9 -4
- package/dist.commonjs/spore/index.d.ts.map +1 -1
- package/dist.commonjs/spore/index.js +26 -27
- package/package.json +12 -2
- package/src/advanced.ts +2 -4
- package/src/advancedBarrel.ts +4 -0
- package/src/barrel.ts +4 -0
- package/src/cluster/index.ts +33 -29
- package/src/helper/index.ts +0 -33
- package/src/index.ts +2 -4
- package/src/spore/advanced.ts +2 -12
- package/src/spore/index.ts +46 -31
|
@@ -10,8 +10,17 @@ const advanced_js_1 = require("../advanced.js");
|
|
|
10
10
|
const index_js_1 = require("../codec/index.js");
|
|
11
11
|
const index_js_2 = require("../helper/index.js");
|
|
12
12
|
const index_js_3 = require("../predefined/index.js");
|
|
13
|
-
async function findCluster(client,
|
|
14
|
-
|
|
13
|
+
async function findCluster(client, id, scripts) {
|
|
14
|
+
const found = await (0, index_js_2.findSingletonCellByArgs)(client, id, scripts ?? Object.values((0, index_js_3.getClusterScriptInfos)(client)));
|
|
15
|
+
if (!found) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
cell: found.cell,
|
|
20
|
+
cluster: found.cell,
|
|
21
|
+
clusterData: (0, index_js_1.unpackToRawClusterData)(found.cell.outputData),
|
|
22
|
+
scriptInfo: found.scriptInfo,
|
|
23
|
+
};
|
|
15
24
|
}
|
|
16
25
|
async function assertCluster(client, args, scripts) {
|
|
17
26
|
const res = await findCluster(client, args, scripts);
|
|
@@ -38,9 +47,7 @@ async function createSporeCluster(params) {
|
|
|
38
47
|
const scriptInfo = params.scriptInfo ?? (0, index_js_3.getClusterScriptInfo)(signer.client);
|
|
39
48
|
// prepare transaction
|
|
40
49
|
const tx = core_1.ccc.Transaction.from(params.tx ?? {});
|
|
41
|
-
|
|
42
|
-
await (0, index_js_2.injectOneCapacityCell)(signer, tx);
|
|
43
|
-
}
|
|
50
|
+
await tx.completeInputsAtLeastOne(signer);
|
|
44
51
|
// build cluster cell
|
|
45
52
|
const id = core_1.ccc.hashTypeId(tx.inputs[0], tx.outputs.length);
|
|
46
53
|
const packedClusterData = (0, index_js_1.packRawClusterData)(data);
|
|
@@ -108,8 +115,7 @@ async function transferSporeCluster(params) {
|
|
|
108
115
|
* @param order the order in creation time of clusters
|
|
109
116
|
* @param scriptInfos the deployed script infos of clusters
|
|
110
117
|
*/
|
|
111
|
-
async function* findSporeClustersBySigner(
|
|
112
|
-
const { signer, order, scriptInfos } = params;
|
|
118
|
+
async function* findSporeClustersBySigner({ signer, order, limit, scriptInfos, }) {
|
|
113
119
|
for (const scriptInfo of scriptInfos ??
|
|
114
120
|
Object.values((0, index_js_3.getClusterScriptInfos)(signer.client))) {
|
|
115
121
|
if (!scriptInfo) {
|
|
@@ -118,24 +124,14 @@ async function* findSporeClustersBySigner(params) {
|
|
|
118
124
|
for await (const cluster of signer.findCells({
|
|
119
125
|
script: {
|
|
120
126
|
...scriptInfo,
|
|
121
|
-
args:
|
|
127
|
+
args: "",
|
|
122
128
|
},
|
|
123
|
-
}, true, order,
|
|
124
|
-
let clusterData;
|
|
125
|
-
try {
|
|
126
|
-
clusterData = index_js_1.ClusterData.decode(cluster.outputData);
|
|
127
|
-
}
|
|
128
|
-
catch (_) {
|
|
129
|
-
try {
|
|
130
|
-
clusterData = index_js_1.ClusterDataV1.decode(cluster.outputData);
|
|
131
|
-
}
|
|
132
|
-
catch (e) {
|
|
133
|
-
throw new Error(`Cluster data decode failed: ${e.toString()}`);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
129
|
+
}, true, order, limit)) {
|
|
136
130
|
yield {
|
|
131
|
+
cell: cluster,
|
|
137
132
|
cluster,
|
|
138
|
-
clusterData,
|
|
133
|
+
clusterData: (0, index_js_1.unpackToRawClusterData)(cluster.outputData),
|
|
134
|
+
scriptInfo: index_js_3.SporeScriptInfo.from(scriptInfo),
|
|
139
135
|
};
|
|
140
136
|
}
|
|
141
137
|
}
|
|
@@ -4,6 +4,4 @@ export declare function findSingletonCellByArgs(client: ccc.Client, args: ccc.He
|
|
|
4
4
|
cell: ccc.Cell;
|
|
5
5
|
scriptInfo: SporeScriptInfo;
|
|
6
6
|
} | undefined>;
|
|
7
|
-
export declare function searchOneCellBySigner(signer: ccc.Signer): Promise<ccc.Cell | undefined>;
|
|
8
|
-
export declare function injectOneCapacityCell(signer: ccc.Signer, tx: ccc.Transaction): Promise<void>;
|
|
9
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helper/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE9E,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,IAAI,EAAE,GAAG,CAAC,OAAO,EACjB,OAAO,EAAE,CAAC,mBAAmB,GAAG,SAAS,CAAC,EAAE,GAC3C,OAAO,CACN;IACE,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC;IACf,UAAU,EAAE,eAAe,CAAC;CAC7B,GACD,SAAS,CACZ,CAqBA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helper/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE9E,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,IAAI,EAAE,GAAG,CAAC,OAAO,EACjB,OAAO,EAAE,CAAC,mBAAmB,GAAG,SAAS,CAAC,EAAE,GAC3C,OAAO,CACN;IACE,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC;IACf,UAAU,EAAE,eAAe,CAAC;CAC7B,GACD,SAAS,CACZ,CAqBA"}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.findSingletonCellByArgs = findSingletonCellByArgs;
|
|
4
|
-
exports.searchOneCellBySigner = searchOneCellBySigner;
|
|
5
|
-
exports.injectOneCapacityCell = injectOneCapacityCell;
|
|
6
|
-
const core_1 = require("@ckb-ccc/core");
|
|
7
4
|
const index_js_1 = require("../predefined/index.js");
|
|
8
5
|
async function findSingletonCellByArgs(client, args, scripts) {
|
|
9
6
|
for (const scriptInfo of scripts) {
|
|
@@ -22,21 +19,3 @@ async function findSingletonCellByArgs(client, args, scripts) {
|
|
|
22
19
|
}
|
|
23
20
|
}
|
|
24
21
|
}
|
|
25
|
-
async function searchOneCellBySigner(signer) {
|
|
26
|
-
for await (const cell of signer.findCells({
|
|
27
|
-
scriptLenRange: [0, 1],
|
|
28
|
-
outputDataLenRange: [0, 1],
|
|
29
|
-
}, true, undefined, 1)) {
|
|
30
|
-
return cell;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
async function injectOneCapacityCell(signer, tx) {
|
|
34
|
-
const liveCell = await searchOneCellBySigner(signer);
|
|
35
|
-
if (!liveCell) {
|
|
36
|
-
throw new Error("No live cell found");
|
|
37
|
-
}
|
|
38
|
-
tx.inputs.push(core_1.ccc.CellInput.from({
|
|
39
|
-
previousOutput: liveCell.outPoint,
|
|
40
|
-
...liveCell,
|
|
41
|
-
}));
|
|
42
|
-
}
|
package/dist.commonjs/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,OAAO,KAAK,KAAK,MAAM,aAAa,CAAC"}
|
package/dist.commonjs/index.js
CHANGED
|
@@ -26,8 +26,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
26
26
|
return result;
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
30
|
-
__exportStar(require("./
|
|
31
|
-
exports.
|
|
32
|
-
__exportStar(require("./predefined/index.js"), exports);
|
|
33
|
-
__exportStar(require("./spore/index.js"), exports);
|
|
29
|
+
exports.spore = void 0;
|
|
30
|
+
__exportStar(require("./barrel.js"), exports);
|
|
31
|
+
exports.spore = __importStar(require("./barrel.js"));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../../src/spore/advanced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAGzC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../../src/spore/advanced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAGzC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAE1D,wBAAsB,cAAc,CAClC,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,EAAE,EAAE,GAAG,CAAC,WAAW,EACnB,IAAI,EAAE,aAAa,EACnB,WAAW,CAAC,EAAE,WAAW,GAAG,aAAa,GAAG,MAAM,EAClD,cAAc,CAAC,EAAE,GAAG,CAAC,OAAO,GAC3B,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,OAAO,MAAM,CAAC,GAAG,SAAS,CAAC,CAiEvD"}
|
|
@@ -4,7 +4,6 @@ exports.prepareCluster = prepareCluster;
|
|
|
4
4
|
const core_1 = require("@ckb-ccc/core");
|
|
5
5
|
const advanced_js_1 = require("../advanced.js");
|
|
6
6
|
const index_js_1 = require("../cluster/index.js");
|
|
7
|
-
const index_js_2 = require("../helper/index.js");
|
|
8
7
|
async function prepareCluster(signer, tx, data, clusterMode, scriptInfoHash) {
|
|
9
8
|
// skip if the spore is not belong to a cluster
|
|
10
9
|
if (!data.clusterId || clusterMode === "skip") {
|
|
@@ -18,17 +17,10 @@ async function prepareCluster(signer, tx, data, clusterMode, scriptInfoHash) {
|
|
|
18
17
|
switch (clusterMode) {
|
|
19
18
|
case "lockProxy": {
|
|
20
19
|
const lock = cluster.cellOutput.lock;
|
|
21
|
-
if (await tx.findInputIndexByLock(lock, signer.client) === undefined) {
|
|
20
|
+
if ((await tx.findInputIndexByLock(lock, signer.client)) === undefined) {
|
|
22
21
|
// note: We can only search proxy of signer, if any custom logic is in need, developer should get
|
|
23
22
|
// the proxy filled in transaction before invoking `createSpore`
|
|
24
|
-
|
|
25
|
-
if (!proxy) {
|
|
26
|
-
throw new Error("Cluster lock proxy cell not found");
|
|
27
|
-
}
|
|
28
|
-
tx.inputs.push(core_1.ccc.CellInput.from({
|
|
29
|
-
previousOutput: proxy.outPoint,
|
|
30
|
-
...proxy,
|
|
31
|
-
}));
|
|
23
|
+
await tx.completeInputsAddOne(signer);
|
|
32
24
|
}
|
|
33
25
|
if (tx.outputs.every((output) => output.lock !== lock)) {
|
|
34
26
|
tx.addOutput({
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/core";
|
|
2
2
|
import { SporeDataView } from "../codec/index.js";
|
|
3
3
|
import { SporeScriptInfo, SporeScriptInfoLike } from "../predefined/index.js";
|
|
4
|
-
export declare function findSpore(client: ccc.Client,
|
|
4
|
+
export declare function findSpore(client: ccc.Client, id: ccc.HexLike, scripts?: SporeScriptInfoLike[]): Promise<{
|
|
5
5
|
cell: ccc.Cell;
|
|
6
|
+
spore: ccc.Cell;
|
|
7
|
+
sporeData: SporeDataView;
|
|
6
8
|
scriptInfo: SporeScriptInfo;
|
|
7
9
|
} | undefined>;
|
|
8
10
|
export declare function assertSpore(client: ccc.Client, args: ccc.HexLike, scripts?: SporeScriptInfoLike[]): Promise<{
|
|
@@ -82,17 +84,20 @@ export declare function meltSpore(params: {
|
|
|
82
84
|
*
|
|
83
85
|
* @param signer the owner of spores
|
|
84
86
|
* @param order the order in creation time of spores
|
|
85
|
-
* @param clusterId the cluster that spores belong to
|
|
87
|
+
* @param clusterId the cluster that spores belong to. "" to find public spores
|
|
86
88
|
* @param scriptInfos the deployed script infos of spores
|
|
87
|
-
* @returns
|
|
89
|
+
* @returns specified spore cells
|
|
88
90
|
*/
|
|
89
|
-
export declare function findSporesBySigner(
|
|
91
|
+
export declare function findSporesBySigner({ signer, clusterId, scriptInfos, limit, order, }: {
|
|
90
92
|
signer: ccc.Signer;
|
|
91
93
|
order?: "asc" | "desc";
|
|
94
|
+
limit?: number;
|
|
92
95
|
clusterId?: ccc.HexLike;
|
|
93
96
|
scriptInfos?: SporeScriptInfoLike[];
|
|
94
97
|
}): AsyncGenerator<{
|
|
98
|
+
cell: ccc.Cell;
|
|
95
99
|
spore: ccc.Cell;
|
|
96
100
|
sporeData: SporeDataView;
|
|
101
|
+
scriptInfo: SporeScriptInfo;
|
|
97
102
|
}>;
|
|
98
103
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/spore/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAOpC,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/spore/index.ts"],"names":[],"mappings":"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"}
|
|
@@ -12,8 +12,17 @@ const index_js_1 = require("../codec/index.js");
|
|
|
12
12
|
const index_js_2 = require("../helper/index.js");
|
|
13
13
|
const index_js_3 = require("../predefined/index.js");
|
|
14
14
|
const advanced_js_2 = require("./advanced.js");
|
|
15
|
-
async function findSpore(client,
|
|
16
|
-
|
|
15
|
+
async function findSpore(client, id, scripts) {
|
|
16
|
+
const found = await (0, index_js_2.findSingletonCellByArgs)(client, id, scripts ?? Object.values((0, index_js_3.getSporeScriptInfos)(client)));
|
|
17
|
+
if (!found) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
cell: found.cell,
|
|
22
|
+
spore: found.cell,
|
|
23
|
+
sporeData: (0, index_js_1.unpackToRawSporeData)(found.cell.outputData),
|
|
24
|
+
scriptInfo: found.scriptInfo,
|
|
25
|
+
};
|
|
17
26
|
}
|
|
18
27
|
async function assertSpore(client, args, scripts) {
|
|
19
28
|
const res = await findSpore(client, args, scripts);
|
|
@@ -47,9 +56,7 @@ async function createSpore(params) {
|
|
|
47
56
|
const actions = [];
|
|
48
57
|
const ids = [];
|
|
49
58
|
const tx = core_1.ccc.Transaction.from(params.tx ?? {});
|
|
50
|
-
|
|
51
|
-
await (0, index_js_2.injectOneCapacityCell)(signer, tx);
|
|
52
|
-
}
|
|
59
|
+
await tx.completeInputsAtLeastOne(signer);
|
|
53
60
|
const { script: lock } = await signer.getRecommendedAddressObj();
|
|
54
61
|
// build spore cell
|
|
55
62
|
const id = core_1.ccc.hashTypeId(tx.inputs[0], tx.outputs.length);
|
|
@@ -146,12 +153,11 @@ async function meltSpore(params) {
|
|
|
146
153
|
*
|
|
147
154
|
* @param signer the owner of spores
|
|
148
155
|
* @param order the order in creation time of spores
|
|
149
|
-
* @param clusterId the cluster that spores belong to
|
|
156
|
+
* @param clusterId the cluster that spores belong to. "" to find public spores
|
|
150
157
|
* @param scriptInfos the deployed script infos of spores
|
|
151
|
-
* @returns
|
|
158
|
+
* @returns specified spore cells
|
|
152
159
|
*/
|
|
153
|
-
async function* findSporesBySigner(
|
|
154
|
-
const { signer, clusterId, scriptInfos, order } = params;
|
|
160
|
+
async function* findSporesBySigner({ signer, clusterId, scriptInfos, limit, order, }) {
|
|
155
161
|
for (const scriptInfo of scriptInfos ??
|
|
156
162
|
Object.values((0, index_js_3.getSporeScriptInfos)(signer.client))) {
|
|
157
163
|
if (!scriptInfo) {
|
|
@@ -162,24 +168,17 @@ async function* findSporesBySigner(params) {
|
|
|
162
168
|
...scriptInfo,
|
|
163
169
|
args: [],
|
|
164
170
|
},
|
|
165
|
-
}, true, order,
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
spore,
|
|
177
|
-
sporeData,
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
catch (e) {
|
|
182
|
-
throw new Error(`Spore data decode failed: ${e.toString()}`);
|
|
171
|
+
}, true, order, limit)) {
|
|
172
|
+
const sporeData = (0, index_js_1.unpackToRawSporeData)(spore.outputData);
|
|
173
|
+
if (!clusterId ||
|
|
174
|
+
(clusterId === "" && !sporeData.clusterId) ||
|
|
175
|
+
sporeData.clusterId === core_1.ccc.hexFrom(clusterId)) {
|
|
176
|
+
yield {
|
|
177
|
+
cell: spore,
|
|
178
|
+
spore,
|
|
179
|
+
sporeData,
|
|
180
|
+
scriptInfo: index_js_3.SporeScriptInfo.from(scriptInfo),
|
|
181
|
+
};
|
|
183
182
|
}
|
|
184
183
|
}
|
|
185
184
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckb-ccc/spore",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "CCC - CKBer's Codebase. Common Chains Connector's support for Spore protocol",
|
|
5
5
|
"author": "ashuralyk <ashuralyk@live.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,10 +19,20 @@
|
|
|
19
19
|
"require": "./dist.commonjs/index.js",
|
|
20
20
|
"default": "./dist.commonjs/index.js"
|
|
21
21
|
},
|
|
22
|
+
"./barrel": {
|
|
23
|
+
"import": "./dist/barrel.js",
|
|
24
|
+
"require": "./dist.commonjs/barrel.js",
|
|
25
|
+
"default": "./dist.commonjs/barrel.js"
|
|
26
|
+
},
|
|
22
27
|
"./advanced": {
|
|
23
28
|
"import": "./dist/advanced.js",
|
|
24
29
|
"require": "./dist.commonjs/advanced.js",
|
|
25
30
|
"default": "./dist.commonjs/advanced.js"
|
|
31
|
+
},
|
|
32
|
+
"./advancedBarrel": {
|
|
33
|
+
"import": "./dist/advancedBarrel.js",
|
|
34
|
+
"require": "./dist.commonjs/advancedBarrel.js",
|
|
35
|
+
"default": "./dist.commonjs/advancedBarrel.js"
|
|
26
36
|
}
|
|
27
37
|
},
|
|
28
38
|
"devDependencies": {
|
|
@@ -44,7 +54,7 @@
|
|
|
44
54
|
},
|
|
45
55
|
"dependencies": {
|
|
46
56
|
"axios": "^1.7.7",
|
|
47
|
-
"@ckb-ccc/core": "1.
|
|
57
|
+
"@ckb-ccc/core": "1.3.1"
|
|
48
58
|
},
|
|
49
59
|
"scripts": {
|
|
50
60
|
"build": "rimraf ./dist && rimraf ./dist.commonjs && tsc && tsc --project tsconfig.commonjs.json && copyfiles -u 2 misc/basedirs/**/* .",
|
package/src/advanced.ts
CHANGED
package/src/barrel.ts
ADDED
package/src/cluster/index.ts
CHANGED
|
@@ -5,15 +5,11 @@ import {
|
|
|
5
5
|
prepareSporeTransaction,
|
|
6
6
|
} from "../advanced.js";
|
|
7
7
|
import {
|
|
8
|
-
ClusterData,
|
|
9
|
-
ClusterDataV1,
|
|
10
8
|
ClusterDataView,
|
|
11
9
|
packRawClusterData,
|
|
10
|
+
unpackToRawClusterData,
|
|
12
11
|
} from "../codec/index.js";
|
|
13
|
-
import {
|
|
14
|
-
findSingletonCellByArgs,
|
|
15
|
-
injectOneCapacityCell,
|
|
16
|
-
} from "../helper/index.js";
|
|
12
|
+
import { findSingletonCellByArgs } from "../helper/index.js";
|
|
17
13
|
import {
|
|
18
14
|
SporeScriptInfo,
|
|
19
15
|
SporeScriptInfoLike,
|
|
@@ -23,20 +19,32 @@ import {
|
|
|
23
19
|
|
|
24
20
|
export async function findCluster(
|
|
25
21
|
client: ccc.Client,
|
|
26
|
-
|
|
22
|
+
id: ccc.HexLike,
|
|
27
23
|
scripts?: SporeScriptInfoLike[],
|
|
28
24
|
): Promise<
|
|
29
25
|
| {
|
|
30
26
|
cell: ccc.Cell;
|
|
27
|
+
cluster: ccc.Cell;
|
|
28
|
+
clusterData: ClusterDataView;
|
|
31
29
|
scriptInfo: SporeScriptInfo;
|
|
32
30
|
}
|
|
33
31
|
| undefined
|
|
34
32
|
> {
|
|
35
|
-
|
|
33
|
+
const found = await findSingletonCellByArgs(
|
|
36
34
|
client,
|
|
37
|
-
|
|
35
|
+
id,
|
|
38
36
|
scripts ?? Object.values(getClusterScriptInfos(client)),
|
|
39
37
|
);
|
|
38
|
+
if (!found) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
cell: found.cell,
|
|
44
|
+
cluster: found.cell,
|
|
45
|
+
clusterData: unpackToRawClusterData(found.cell.outputData),
|
|
46
|
+
scriptInfo: found.scriptInfo,
|
|
47
|
+
};
|
|
40
48
|
}
|
|
41
49
|
|
|
42
50
|
export async function assertCluster(
|
|
@@ -85,9 +93,7 @@ export async function createSporeCluster(params: {
|
|
|
85
93
|
|
|
86
94
|
// prepare transaction
|
|
87
95
|
const tx = ccc.Transaction.from(params.tx ?? {});
|
|
88
|
-
|
|
89
|
-
await injectOneCapacityCell(signer, tx);
|
|
90
|
-
}
|
|
96
|
+
await tx.completeInputsAtLeastOne(signer);
|
|
91
97
|
|
|
92
98
|
// build cluster cell
|
|
93
99
|
const id = ccc.hashTypeId(tx.inputs[0], tx.outputs.length);
|
|
@@ -191,46 +197,44 @@ export async function transferSporeCluster(params: {
|
|
|
191
197
|
* @param order the order in creation time of clusters
|
|
192
198
|
* @param scriptInfos the deployed script infos of clusters
|
|
193
199
|
*/
|
|
194
|
-
export async function* findSporeClustersBySigner(
|
|
200
|
+
export async function* findSporeClustersBySigner({
|
|
201
|
+
signer,
|
|
202
|
+
order,
|
|
203
|
+
limit,
|
|
204
|
+
scriptInfos,
|
|
205
|
+
}: {
|
|
195
206
|
signer: ccc.Signer;
|
|
196
207
|
order?: "asc" | "desc";
|
|
208
|
+
limit?: number;
|
|
197
209
|
scriptInfos?: SporeScriptInfoLike[];
|
|
198
210
|
}): AsyncGenerator<{
|
|
211
|
+
cell: ccc.Cell;
|
|
199
212
|
cluster: ccc.Cell;
|
|
200
213
|
clusterData: ClusterDataView;
|
|
214
|
+
scriptInfo: SporeScriptInfo;
|
|
201
215
|
}> {
|
|
202
|
-
const { signer, order, scriptInfos } = params;
|
|
203
216
|
for (const scriptInfo of scriptInfos ??
|
|
204
217
|
Object.values(getClusterScriptInfos(signer.client))) {
|
|
205
218
|
if (!scriptInfo) {
|
|
206
219
|
continue;
|
|
207
220
|
}
|
|
221
|
+
|
|
208
222
|
for await (const cluster of signer.findCells(
|
|
209
223
|
{
|
|
210
224
|
script: {
|
|
211
225
|
...scriptInfo,
|
|
212
|
-
args:
|
|
226
|
+
args: "",
|
|
213
227
|
},
|
|
214
228
|
},
|
|
215
229
|
true,
|
|
216
230
|
order,
|
|
217
|
-
|
|
231
|
+
limit,
|
|
218
232
|
)) {
|
|
219
|
-
let clusterData: ClusterDataView;
|
|
220
|
-
try {
|
|
221
|
-
clusterData = ClusterData.decode(cluster.outputData);
|
|
222
|
-
} catch (_) {
|
|
223
|
-
try {
|
|
224
|
-
clusterData = ClusterDataV1.decode(cluster.outputData);
|
|
225
|
-
} catch (e: unknown) {
|
|
226
|
-
throw new Error(
|
|
227
|
-
`Cluster data decode failed: ${(e as Error).toString()}`,
|
|
228
|
-
);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
233
|
yield {
|
|
234
|
+
cell: cluster,
|
|
232
235
|
cluster,
|
|
233
|
-
clusterData,
|
|
236
|
+
clusterData: unpackToRawClusterData(cluster.outputData),
|
|
237
|
+
scriptInfo: SporeScriptInfo.from(scriptInfo),
|
|
234
238
|
};
|
|
235
239
|
}
|
|
236
240
|
}
|
package/src/helper/index.ts
CHANGED
|
@@ -33,36 +33,3 @@ export async function findSingletonCellByArgs(
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
|
|
37
|
-
export async function searchOneCellBySigner(
|
|
38
|
-
signer: ccc.Signer,
|
|
39
|
-
): Promise<ccc.Cell | undefined> {
|
|
40
|
-
for await (const cell of signer.findCells(
|
|
41
|
-
{
|
|
42
|
-
scriptLenRange: [0, 1],
|
|
43
|
-
outputDataLenRange: [0, 1],
|
|
44
|
-
},
|
|
45
|
-
true,
|
|
46
|
-
undefined,
|
|
47
|
-
1,
|
|
48
|
-
)) {
|
|
49
|
-
return cell;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export async function injectOneCapacityCell(
|
|
54
|
-
signer: ccc.Signer,
|
|
55
|
-
tx: ccc.Transaction,
|
|
56
|
-
): Promise<void> {
|
|
57
|
-
const liveCell = await searchOneCellBySigner(signer);
|
|
58
|
-
if (!liveCell) {
|
|
59
|
-
throw new Error("No live cell found");
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
tx.inputs.push(
|
|
63
|
-
ccc.CellInput.from({
|
|
64
|
-
previousOutput: liveCell.outPoint,
|
|
65
|
-
...liveCell,
|
|
66
|
-
}),
|
|
67
|
-
);
|
|
68
|
-
}
|
package/src/index.ts
CHANGED
package/src/spore/advanced.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { ccc, mol } from "@ckb-ccc/core";
|
|
|
2
2
|
import { assembleTransferClusterAction } from "../advanced.js";
|
|
3
3
|
import { assertCluster } from "../cluster/index.js";
|
|
4
4
|
import { Action, SporeDataView } from "../codec/index.js";
|
|
5
|
-
import { searchOneCellBySigner } from "../helper/index.js";
|
|
6
5
|
|
|
7
6
|
export async function prepareCluster(
|
|
8
7
|
signer: ccc.Signer,
|
|
@@ -30,19 +29,10 @@ export async function prepareCluster(
|
|
|
30
29
|
case "lockProxy": {
|
|
31
30
|
const lock = cluster.cellOutput.lock;
|
|
32
31
|
|
|
33
|
-
if (await tx.findInputIndexByLock(lock, signer.client) === undefined) {
|
|
32
|
+
if ((await tx.findInputIndexByLock(lock, signer.client)) === undefined) {
|
|
34
33
|
// note: We can only search proxy of signer, if any custom logic is in need, developer should get
|
|
35
34
|
// the proxy filled in transaction before invoking `createSpore`
|
|
36
|
-
|
|
37
|
-
if (!proxy) {
|
|
38
|
-
throw new Error("Cluster lock proxy cell not found");
|
|
39
|
-
}
|
|
40
|
-
tx.inputs.push(
|
|
41
|
-
ccc.CellInput.from({
|
|
42
|
-
previousOutput: proxy.outPoint,
|
|
43
|
-
...proxy,
|
|
44
|
-
}),
|
|
45
|
-
);
|
|
35
|
+
await tx.completeInputsAddOne(signer);
|
|
46
36
|
}
|
|
47
37
|
if (tx.outputs.every((output) => output.lock !== lock)) {
|
|
48
38
|
tx.addOutput({
|