@ckb-ccc/spore 1.1.0 → 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 +9 -0
- package/dist/cluster/index.d.ts +7 -2
- package/dist/cluster/index.d.ts.map +1 -1
- package/dist/cluster/index.js +19 -21
- package/dist/spore/index.d.ts +9 -4
- package/dist/spore/index.d.ts.map +1 -1
- package/dist/spore/index.js +27 -26
- 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 +17 -19
- 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 +25 -24
- package/package.json +2 -2
- package/src/cluster/index.ts +31 -22
- package/src/spore/index.ts +45 -25
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @ckb-ccc/spore
|
|
2
2
|
|
|
3
|
+
## 1.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`5d4517e`](https://github.com/ckb-devrel/ccc/commit/5d4517e049b541b2a695db7821c4cfc2218678e0) Thanks [@sfsf332](https://github.com/sfsf332)! - refactor(spore): unified findSpore(s) interface
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`a48cccf`](https://github.com/ckb-devrel/ccc/commit/a48cccfae3ce6b3456a5eb863f207e7e5a6e568f)]:
|
|
10
|
+
- @ckb-ccc/core@1.3.1
|
|
11
|
+
|
|
3
12
|
## 1.1.0
|
|
4
13
|
|
|
5
14
|
### Minor Changes
|
package/dist/cluster/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/core";
|
|
2
2
|
import { ClusterDataView } from "../codec/index.js";
|
|
3
3
|
import { SporeScriptInfo, SporeScriptInfoLike } from "../predefined/index.js";
|
|
4
|
-
export declare function findCluster(client: ccc.Client,
|
|
4
|
+
export declare function findCluster(client: ccc.Client, id: ccc.HexLike, scripts?: SporeScriptInfoLike[]): Promise<{
|
|
5
5
|
cell: ccc.Cell;
|
|
6
|
+
cluster: ccc.Cell;
|
|
7
|
+
clusterData: ClusterDataView;
|
|
6
8
|
scriptInfo: SporeScriptInfo;
|
|
7
9
|
} | undefined>;
|
|
8
10
|
export declare function assertCluster(client: ccc.Client, args: ccc.HexLike, scripts?: SporeScriptInfoLike[]): Promise<{
|
|
@@ -60,12 +62,15 @@ export declare function transferSporeCluster(params: {
|
|
|
60
62
|
* @param order the order in creation time of clusters
|
|
61
63
|
* @param scriptInfos the deployed script infos of clusters
|
|
62
64
|
*/
|
|
63
|
-
export declare function findSporeClustersBySigner(
|
|
65
|
+
export declare function findSporeClustersBySigner({ signer, order, limit, scriptInfos, }: {
|
|
64
66
|
signer: ccc.Signer;
|
|
65
67
|
order?: "asc" | "desc";
|
|
68
|
+
limit?: number;
|
|
66
69
|
scriptInfos?: SporeScriptInfoLike[];
|
|
67
70
|
}): AsyncGenerator<{
|
|
71
|
+
cell: ccc.Cell;
|
|
68
72
|
cluster: ccc.Cell;
|
|
69
73
|
clusterData: ClusterDataView;
|
|
74
|
+
scriptInfo: SporeScriptInfo;
|
|
70
75
|
}>;
|
|
71
76
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cluster/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAMpC,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cluster/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAMpC,OAAO,EACL,eAAe,EAGhB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,eAAe,EACf,mBAAmB,EAGpB,MAAM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AAE,GAAG,CAAC,eAAe,CAAC;IACzB,cAAc,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;CAC9B,GAAG,OAAO,CAAC;IACV,EAAE,EAAE,GAAG,CAAC,WAAW,CAAC;CACrB,CAAC,CAwCD;AAED;;;;;;GAMG;AACH,wBAAuB,yBAAyB,CAAC,EAC/C,MAAM,EACN,KAAK,EACL,KAAK,EACL,WAAW,GACZ,EAAE;IACD,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,mBAAmB,EAAE,CAAC;CACrC,GAAG,cAAc,CAAC;IACjB,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC;IACf,OAAO,EAAE,GAAG,CAAC,IAAI,CAAC;IAClB,WAAW,EAAE,eAAe,CAAC;IAC7B,UAAU,EAAE,eAAe,CAAC;CAC7B,CAAC,CA0BD"}
|
package/dist/cluster/index.js
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/core";
|
|
2
2
|
import { assembleCreateClusterAction, assembleTransferClusterAction, prepareSporeTransaction, } from "../advanced.js";
|
|
3
|
-
import {
|
|
3
|
+
import { packRawClusterData, unpackToRawClusterData, } from "../codec/index.js";
|
|
4
4
|
import { findSingletonCellByArgs } from "../helper/index.js";
|
|
5
|
-
import { getClusterScriptInfo, getClusterScriptInfos, } from "../predefined/index.js";
|
|
6
|
-
export async function findCluster(client,
|
|
7
|
-
|
|
5
|
+
import { SporeScriptInfo, getClusterScriptInfo, getClusterScriptInfos, } from "../predefined/index.js";
|
|
6
|
+
export async function findCluster(client, id, scripts) {
|
|
7
|
+
const found = await findSingletonCellByArgs(client, id, scripts ?? Object.values(getClusterScriptInfos(client)));
|
|
8
|
+
if (!found) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
return {
|
|
12
|
+
cell: found.cell,
|
|
13
|
+
cluster: found.cell,
|
|
14
|
+
clusterData: unpackToRawClusterData(found.cell.outputData),
|
|
15
|
+
scriptInfo: found.scriptInfo,
|
|
16
|
+
};
|
|
8
17
|
}
|
|
9
18
|
export async function assertCluster(client, args, scripts) {
|
|
10
19
|
const res = await findCluster(client, args, scripts);
|
|
@@ -99,8 +108,7 @@ export async function transferSporeCluster(params) {
|
|
|
99
108
|
* @param order the order in creation time of clusters
|
|
100
109
|
* @param scriptInfos the deployed script infos of clusters
|
|
101
110
|
*/
|
|
102
|
-
export async function* findSporeClustersBySigner(
|
|
103
|
-
const { signer, order, scriptInfos } = params;
|
|
111
|
+
export async function* findSporeClustersBySigner({ signer, order, limit, scriptInfos, }) {
|
|
104
112
|
for (const scriptInfo of scriptInfos ??
|
|
105
113
|
Object.values(getClusterScriptInfos(signer.client))) {
|
|
106
114
|
if (!scriptInfo) {
|
|
@@ -109,24 +117,14 @@ export async function* findSporeClustersBySigner(params) {
|
|
|
109
117
|
for await (const cluster of signer.findCells({
|
|
110
118
|
script: {
|
|
111
119
|
...scriptInfo,
|
|
112
|
-
args:
|
|
120
|
+
args: "",
|
|
113
121
|
},
|
|
114
|
-
}, true, order,
|
|
115
|
-
let clusterData;
|
|
116
|
-
try {
|
|
117
|
-
clusterData = ClusterData.decode(cluster.outputData);
|
|
118
|
-
}
|
|
119
|
-
catch (_) {
|
|
120
|
-
try {
|
|
121
|
-
clusterData = ClusterDataV1.decode(cluster.outputData);
|
|
122
|
-
}
|
|
123
|
-
catch (e) {
|
|
124
|
-
throw new Error(`Cluster data decode failed: ${e.toString()}`);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
122
|
+
}, true, order, limit)) {
|
|
127
123
|
yield {
|
|
124
|
+
cell: cluster,
|
|
128
125
|
cluster,
|
|
129
|
-
clusterData,
|
|
126
|
+
clusterData: unpackToRawClusterData(cluster.outputData),
|
|
127
|
+
scriptInfo: SporeScriptInfo.from(scriptInfo),
|
|
130
128
|
};
|
|
131
129
|
}
|
|
132
130
|
}
|
package/dist/spore/index.d.ts
CHANGED
|
@@ -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":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAOpC,OAAO,EACL,aAAa,EAGd,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,eAAe,EACf,mBAAmB,EAGpB,MAAM,wBAAwB,CAAC;AAGhC,wBAAsB,SAAS,CAC7B,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,EAAE,EAAE,GAAG,CAAC,OAAO,EACf,OAAO,CAAC,EAAE,mBAAmB,EAAE,GAC9B,OAAO,CACN;IACE,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC;IACf,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC;IAChB,SAAS,EAAE,aAAa,CAAC;IACzB,UAAU,EAAE,eAAe,CAAC;CAC7B,GACD,SAAS,CACZ,CAgBA;AAED,wBAAsB,WAAW,CAC/B,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,IAAI,EAAE,GAAG,CAAC,OAAO,EACjB,OAAO,CAAC,EAAE,mBAAmB,EAAE,GAC9B,OAAO,CAAC;IACT,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC;IACf,UAAU,EAAE,eAAe,CAAC;CAC7B,CAAC,CAQD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,WAAW,CAAC,MAAM,EAAE;IACxC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC;IACnB,IAAI,EAAE,aAAa,CAAC;IACpB,EAAE,CAAC,EAAE,GAAG,CAAC,UAAU,CAAC;IACpB,WAAW,CAAC,EAAE,WAAW,GAAG,aAAa,GAAG,MAAM,CAAC;IACnD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IACxB,WAAW,CAAC,EAAE,mBAAmB,EAAE,CAAC;CACrC,GAAG,cAAc,CAAC;IACjB,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC;IACf,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC;IAChB,SAAS,EAAE,aAAa,CAAC;IACzB,UAAU,EAAE,eAAe,CAAC;CAC7B,CAAC,CAgCD"}
|
package/dist/spore/index.js
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/core";
|
|
2
2
|
import { assembleCreateSporeAction, assembleMeltSporeAction, assembleTransferSporeAction, prepareSporeTransaction, } from "../advanced.js";
|
|
3
|
-
import {
|
|
3
|
+
import { packRawSporeData, unpackToRawSporeData, } from "../codec/index.js";
|
|
4
4
|
import { findSingletonCellByArgs } from "../helper/index.js";
|
|
5
|
-
import { getSporeScriptInfo, getSporeScriptInfos, } from "../predefined/index.js";
|
|
5
|
+
import { SporeScriptInfo, getSporeScriptInfo, getSporeScriptInfos, } from "../predefined/index.js";
|
|
6
6
|
import { prepareCluster } from "./advanced.js";
|
|
7
|
-
export async function findSpore(client,
|
|
8
|
-
|
|
7
|
+
export async function findSpore(client, id, scripts) {
|
|
8
|
+
const found = await findSingletonCellByArgs(client, id, scripts ?? Object.values(getSporeScriptInfos(client)));
|
|
9
|
+
if (!found) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
cell: found.cell,
|
|
14
|
+
spore: found.cell,
|
|
15
|
+
sporeData: unpackToRawSporeData(found.cell.outputData),
|
|
16
|
+
scriptInfo: found.scriptInfo,
|
|
17
|
+
};
|
|
9
18
|
}
|
|
10
19
|
export async function assertSpore(client, args, scripts) {
|
|
11
20
|
const res = await findSpore(client, args, scripts);
|
|
@@ -136,12 +145,11 @@ export async function meltSpore(params) {
|
|
|
136
145
|
*
|
|
137
146
|
* @param signer the owner of spores
|
|
138
147
|
* @param order the order in creation time of spores
|
|
139
|
-
* @param clusterId the cluster that spores belong to
|
|
148
|
+
* @param clusterId the cluster that spores belong to. "" to find public spores
|
|
140
149
|
* @param scriptInfos the deployed script infos of spores
|
|
141
|
-
* @returns
|
|
150
|
+
* @returns specified spore cells
|
|
142
151
|
*/
|
|
143
|
-
export async function* findSporesBySigner(
|
|
144
|
-
const { signer, clusterId, scriptInfos, order } = params;
|
|
152
|
+
export async function* findSporesBySigner({ signer, clusterId, scriptInfos, limit, order, }) {
|
|
145
153
|
for (const scriptInfo of scriptInfos ??
|
|
146
154
|
Object.values(getSporeScriptInfos(signer.client))) {
|
|
147
155
|
if (!scriptInfo) {
|
|
@@ -152,24 +160,17 @@ export async function* findSporesBySigner(params) {
|
|
|
152
160
|
...scriptInfo,
|
|
153
161
|
args: [],
|
|
154
162
|
},
|
|
155
|
-
}, true, order,
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
spore,
|
|
167
|
-
sporeData,
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
catch (e) {
|
|
172
|
-
throw new Error(`Spore data decode failed: ${e.toString()}`);
|
|
163
|
+
}, true, order, limit)) {
|
|
164
|
+
const sporeData = unpackToRawSporeData(spore.outputData);
|
|
165
|
+
if (!clusterId ||
|
|
166
|
+
(clusterId === "" && !sporeData.clusterId) ||
|
|
167
|
+
sporeData.clusterId === ccc.hexFrom(clusterId)) {
|
|
168
|
+
yield {
|
|
169
|
+
cell: spore,
|
|
170
|
+
spore,
|
|
171
|
+
sporeData,
|
|
172
|
+
scriptInfo: SporeScriptInfo.from(scriptInfo),
|
|
173
|
+
};
|
|
173
174
|
}
|
|
174
175
|
}
|
|
175
176
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/core";
|
|
2
2
|
import { ClusterDataView } from "../codec/index.js";
|
|
3
3
|
import { SporeScriptInfo, SporeScriptInfoLike } from "../predefined/index.js";
|
|
4
|
-
export declare function findCluster(client: ccc.Client,
|
|
4
|
+
export declare function findCluster(client: ccc.Client, id: ccc.HexLike, scripts?: SporeScriptInfoLike[]): Promise<{
|
|
5
5
|
cell: ccc.Cell;
|
|
6
|
+
cluster: ccc.Cell;
|
|
7
|
+
clusterData: ClusterDataView;
|
|
6
8
|
scriptInfo: SporeScriptInfo;
|
|
7
9
|
} | undefined>;
|
|
8
10
|
export declare function assertCluster(client: ccc.Client, args: ccc.HexLike, scripts?: SporeScriptInfoLike[]): Promise<{
|
|
@@ -60,12 +62,15 @@ export declare function transferSporeCluster(params: {
|
|
|
60
62
|
* @param order the order in creation time of clusters
|
|
61
63
|
* @param scriptInfos the deployed script infos of clusters
|
|
62
64
|
*/
|
|
63
|
-
export declare function findSporeClustersBySigner(
|
|
65
|
+
export declare function findSporeClustersBySigner({ signer, order, limit, scriptInfos, }: {
|
|
64
66
|
signer: ccc.Signer;
|
|
65
67
|
order?: "asc" | "desc";
|
|
68
|
+
limit?: number;
|
|
66
69
|
scriptInfos?: SporeScriptInfoLike[];
|
|
67
70
|
}): AsyncGenerator<{
|
|
71
|
+
cell: ccc.Cell;
|
|
68
72
|
cluster: ccc.Cell;
|
|
69
73
|
clusterData: ClusterDataView;
|
|
74
|
+
scriptInfo: SporeScriptInfo;
|
|
70
75
|
}>;
|
|
71
76
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cluster/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAMpC,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cluster/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAMpC,OAAO,EACL,eAAe,EAGhB,MAAM,mBAA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ChB,EAAE,EAAE,GAAG,CAAC,UAAU,CAAC;IACnB,EAAE,CAAC,EAAE,GAAG,CAAC,eAAe,CAAC;IACzB,cAAc,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;CAC9B,GAAG,OAAO,CAAC;IACV,EAAE,EAAE,GAAG,CAAC,WAAW,CAAC;CACrB,CAAC,CAwCD;AAED;;;;;;GAMG;AACH,wBAAuB,yBAAyB,CAAC,EAC/C,MAAM,EACN,KAAK,EACL,KAAK,EACL,WAAW,GACZ,EAAE;IACD,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,mBAAmB,EAAE,CAAC;CACrC,GAAG,cAAc,CAAC;IACjB,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC;IACf,OAAO,EAAE,GAAG,CAAC,IAAI,CAAC;IAClB,WAAW,EAAE,eAAe,CAAC;IAC7B,UAAU,EAAE,eAAe,CAAC;CAC7B,CAAC,CA0BD"}
|
|
@@ -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);
|
|
@@ -106,8 +115,7 @@ async function transferSporeCluster(params) {
|
|
|
106
115
|
* @param order the order in creation time of clusters
|
|
107
116
|
* @param scriptInfos the deployed script infos of clusters
|
|
108
117
|
*/
|
|
109
|
-
async function* findSporeClustersBySigner(
|
|
110
|
-
const { signer, order, scriptInfos } = params;
|
|
118
|
+
async function* findSporeClustersBySigner({ signer, order, limit, scriptInfos, }) {
|
|
111
119
|
for (const scriptInfo of scriptInfos ??
|
|
112
120
|
Object.values((0, index_js_3.getClusterScriptInfos)(signer.client))) {
|
|
113
121
|
if (!scriptInfo) {
|
|
@@ -116,24 +124,14 @@ async function* findSporeClustersBySigner(params) {
|
|
|
116
124
|
for await (const cluster of signer.findCells({
|
|
117
125
|
script: {
|
|
118
126
|
...scriptInfo,
|
|
119
|
-
args:
|
|
127
|
+
args: "",
|
|
120
128
|
},
|
|
121
|
-
}, true, order,
|
|
122
|
-
let clusterData;
|
|
123
|
-
try {
|
|
124
|
-
clusterData = index_js_1.ClusterData.decode(cluster.outputData);
|
|
125
|
-
}
|
|
126
|
-
catch (_) {
|
|
127
|
-
try {
|
|
128
|
-
clusterData = index_js_1.ClusterDataV1.decode(cluster.outputData);
|
|
129
|
-
}
|
|
130
|
-
catch (e) {
|
|
131
|
-
throw new Error(`Cluster data decode failed: ${e.toString()}`);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
129
|
+
}, true, order, limit)) {
|
|
134
130
|
yield {
|
|
131
|
+
cell: cluster,
|
|
135
132
|
cluster,
|
|
136
|
-
clusterData,
|
|
133
|
+
clusterData: (0, index_js_1.unpackToRawClusterData)(cluster.outputData),
|
|
134
|
+
scriptInfo: index_js_3.SporeScriptInfo.from(scriptInfo),
|
|
137
135
|
};
|
|
138
136
|
}
|
|
139
137
|
}
|
|
@@ -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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AAG,CAAC,IAAI,CAAC;IAChB,SAAS,EAAE,aAAa,CAAC;IACzB,UAAU,EAAE,eAAe,CAAC;CAC7B,CAAC,CAgCD"}
|
|
@@ -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);
|
|
@@ -144,12 +153,11 @@ async function meltSpore(params) {
|
|
|
144
153
|
*
|
|
145
154
|
* @param signer the owner of spores
|
|
146
155
|
* @param order the order in creation time of spores
|
|
147
|
-
* @param clusterId the cluster that spores belong to
|
|
156
|
+
* @param clusterId the cluster that spores belong to. "" to find public spores
|
|
148
157
|
* @param scriptInfos the deployed script infos of spores
|
|
149
|
-
* @returns
|
|
158
|
+
* @returns specified spore cells
|
|
150
159
|
*/
|
|
151
|
-
async function* findSporesBySigner(
|
|
152
|
-
const { signer, clusterId, scriptInfos, order } = params;
|
|
160
|
+
async function* findSporesBySigner({ signer, clusterId, scriptInfos, limit, order, }) {
|
|
153
161
|
for (const scriptInfo of scriptInfos ??
|
|
154
162
|
Object.values((0, index_js_3.getSporeScriptInfos)(signer.client))) {
|
|
155
163
|
if (!scriptInfo) {
|
|
@@ -160,24 +168,17 @@ async function* findSporesBySigner(params) {
|
|
|
160
168
|
...scriptInfo,
|
|
161
169
|
args: [],
|
|
162
170
|
},
|
|
163
|
-
}, true, order,
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
spore,
|
|
175
|
-
sporeData,
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
catch (e) {
|
|
180
|
-
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
|
+
};
|
|
181
182
|
}
|
|
182
183
|
}
|
|
183
184
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckb-ccc/spore",
|
|
3
|
-
"version": "1.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",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"axios": "^1.7.7",
|
|
57
|
-
"@ckb-ccc/core": "1.3.
|
|
57
|
+
"@ckb-ccc/core": "1.3.1"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"build": "rimraf ./dist && rimraf ./dist.commonjs && tsc && tsc --project tsconfig.commonjs.json && copyfiles -u 2 misc/basedirs/**/* .",
|
package/src/cluster/index.ts
CHANGED
|
@@ -5,10 +5,9 @@ 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
12
|
import { findSingletonCellByArgs } from "../helper/index.js";
|
|
14
13
|
import {
|
|
@@ -20,20 +19,32 @@ import {
|
|
|
20
19
|
|
|
21
20
|
export async function findCluster(
|
|
22
21
|
client: ccc.Client,
|
|
23
|
-
|
|
22
|
+
id: ccc.HexLike,
|
|
24
23
|
scripts?: SporeScriptInfoLike[],
|
|
25
24
|
): Promise<
|
|
26
25
|
| {
|
|
27
26
|
cell: ccc.Cell;
|
|
27
|
+
cluster: ccc.Cell;
|
|
28
|
+
clusterData: ClusterDataView;
|
|
28
29
|
scriptInfo: SporeScriptInfo;
|
|
29
30
|
}
|
|
30
31
|
| undefined
|
|
31
32
|
> {
|
|
32
|
-
|
|
33
|
+
const found = await findSingletonCellByArgs(
|
|
33
34
|
client,
|
|
34
|
-
|
|
35
|
+
id,
|
|
35
36
|
scripts ?? Object.values(getClusterScriptInfos(client)),
|
|
36
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
|
+
};
|
|
37
48
|
}
|
|
38
49
|
|
|
39
50
|
export async function assertCluster(
|
|
@@ -186,46 +197,44 @@ export async function transferSporeCluster(params: {
|
|
|
186
197
|
* @param order the order in creation time of clusters
|
|
187
198
|
* @param scriptInfos the deployed script infos of clusters
|
|
188
199
|
*/
|
|
189
|
-
export async function* findSporeClustersBySigner(
|
|
200
|
+
export async function* findSporeClustersBySigner({
|
|
201
|
+
signer,
|
|
202
|
+
order,
|
|
203
|
+
limit,
|
|
204
|
+
scriptInfos,
|
|
205
|
+
}: {
|
|
190
206
|
signer: ccc.Signer;
|
|
191
207
|
order?: "asc" | "desc";
|
|
208
|
+
limit?: number;
|
|
192
209
|
scriptInfos?: SporeScriptInfoLike[];
|
|
193
210
|
}): AsyncGenerator<{
|
|
211
|
+
cell: ccc.Cell;
|
|
194
212
|
cluster: ccc.Cell;
|
|
195
213
|
clusterData: ClusterDataView;
|
|
214
|
+
scriptInfo: SporeScriptInfo;
|
|
196
215
|
}> {
|
|
197
|
-
const { signer, order, scriptInfos } = params;
|
|
198
216
|
for (const scriptInfo of scriptInfos ??
|
|
199
217
|
Object.values(getClusterScriptInfos(signer.client))) {
|
|
200
218
|
if (!scriptInfo) {
|
|
201
219
|
continue;
|
|
202
220
|
}
|
|
221
|
+
|
|
203
222
|
for await (const cluster of signer.findCells(
|
|
204
223
|
{
|
|
205
224
|
script: {
|
|
206
225
|
...scriptInfo,
|
|
207
|
-
args:
|
|
226
|
+
args: "",
|
|
208
227
|
},
|
|
209
228
|
},
|
|
210
229
|
true,
|
|
211
230
|
order,
|
|
212
|
-
|
|
231
|
+
limit,
|
|
213
232
|
)) {
|
|
214
|
-
let clusterData: ClusterDataView;
|
|
215
|
-
try {
|
|
216
|
-
clusterData = ClusterData.decode(cluster.outputData);
|
|
217
|
-
} catch (_) {
|
|
218
|
-
try {
|
|
219
|
-
clusterData = ClusterDataV1.decode(cluster.outputData);
|
|
220
|
-
} catch (e: unknown) {
|
|
221
|
-
throw new Error(
|
|
222
|
-
`Cluster data decode failed: ${(e as Error).toString()}`,
|
|
223
|
-
);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
233
|
yield {
|
|
234
|
+
cell: cluster,
|
|
227
235
|
cluster,
|
|
228
|
-
clusterData,
|
|
236
|
+
clusterData: unpackToRawClusterData(cluster.outputData),
|
|
237
|
+
scriptInfo: SporeScriptInfo.from(scriptInfo),
|
|
229
238
|
};
|
|
230
239
|
}
|
|
231
240
|
}
|
package/src/spore/index.ts
CHANGED
|
@@ -5,7 +5,11 @@ import {
|
|
|
5
5
|
assembleTransferSporeAction,
|
|
6
6
|
prepareSporeTransaction,
|
|
7
7
|
} from "../advanced.js";
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
SporeDataView,
|
|
10
|
+
packRawSporeData,
|
|
11
|
+
unpackToRawSporeData,
|
|
12
|
+
} from "../codec/index.js";
|
|
9
13
|
import { findSingletonCellByArgs } from "../helper/index.js";
|
|
10
14
|
import {
|
|
11
15
|
SporeScriptInfo,
|
|
@@ -17,20 +21,32 @@ import { prepareCluster } from "./advanced.js";
|
|
|
17
21
|
|
|
18
22
|
export async function findSpore(
|
|
19
23
|
client: ccc.Client,
|
|
20
|
-
|
|
24
|
+
id: ccc.HexLike,
|
|
21
25
|
scripts?: SporeScriptInfoLike[],
|
|
22
26
|
): Promise<
|
|
23
27
|
| {
|
|
24
28
|
cell: ccc.Cell;
|
|
29
|
+
spore: ccc.Cell;
|
|
30
|
+
sporeData: SporeDataView;
|
|
25
31
|
scriptInfo: SporeScriptInfo;
|
|
26
32
|
}
|
|
27
33
|
| undefined
|
|
28
34
|
> {
|
|
29
|
-
|
|
35
|
+
const found = await findSingletonCellByArgs(
|
|
30
36
|
client,
|
|
31
|
-
|
|
37
|
+
id,
|
|
32
38
|
scripts ?? Object.values(getSporeScriptInfos(client)),
|
|
33
39
|
);
|
|
40
|
+
if (!found) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
cell: found.cell,
|
|
46
|
+
spore: found.cell,
|
|
47
|
+
sporeData: unpackToRawSporeData(found.cell.outputData),
|
|
48
|
+
scriptInfo: found.scriptInfo,
|
|
49
|
+
};
|
|
34
50
|
}
|
|
35
51
|
|
|
36
52
|
export async function assertSpore(
|
|
@@ -235,20 +251,28 @@ export async function meltSpore(params: {
|
|
|
235
251
|
*
|
|
236
252
|
* @param signer the owner of spores
|
|
237
253
|
* @param order the order in creation time of spores
|
|
238
|
-
* @param clusterId the cluster that spores belong to
|
|
254
|
+
* @param clusterId the cluster that spores belong to. "" to find public spores
|
|
239
255
|
* @param scriptInfos the deployed script infos of spores
|
|
240
|
-
* @returns
|
|
256
|
+
* @returns specified spore cells
|
|
241
257
|
*/
|
|
242
|
-
export async function* findSporesBySigner(
|
|
258
|
+
export async function* findSporesBySigner({
|
|
259
|
+
signer,
|
|
260
|
+
clusterId,
|
|
261
|
+
scriptInfos,
|
|
262
|
+
limit,
|
|
263
|
+
order,
|
|
264
|
+
}: {
|
|
243
265
|
signer: ccc.Signer;
|
|
244
266
|
order?: "asc" | "desc";
|
|
267
|
+
limit?: number;
|
|
245
268
|
clusterId?: ccc.HexLike;
|
|
246
269
|
scriptInfos?: SporeScriptInfoLike[];
|
|
247
270
|
}): AsyncGenerator<{
|
|
271
|
+
cell: ccc.Cell;
|
|
248
272
|
spore: ccc.Cell;
|
|
249
273
|
sporeData: SporeDataView;
|
|
274
|
+
scriptInfo: SporeScriptInfo;
|
|
250
275
|
}> {
|
|
251
|
-
const { signer, clusterId, scriptInfos, order } = params;
|
|
252
276
|
for (const scriptInfo of scriptInfos ??
|
|
253
277
|
Object.values(getSporeScriptInfos(signer.client))) {
|
|
254
278
|
if (!scriptInfo) {
|
|
@@ -263,24 +287,20 @@ export async function* findSporesBySigner(params: {
|
|
|
263
287
|
},
|
|
264
288
|
true,
|
|
265
289
|
order,
|
|
266
|
-
|
|
290
|
+
limit,
|
|
267
291
|
)) {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
};
|
|
281
|
-
}
|
|
282
|
-
} catch (e: unknown) {
|
|
283
|
-
throw new Error(`Spore data decode failed: ${(e as Error).toString()}`);
|
|
292
|
+
const sporeData = unpackToRawSporeData(spore.outputData);
|
|
293
|
+
if (
|
|
294
|
+
!clusterId ||
|
|
295
|
+
(clusterId === "" && !sporeData.clusterId) ||
|
|
296
|
+
sporeData.clusterId === ccc.hexFrom(clusterId)
|
|
297
|
+
) {
|
|
298
|
+
yield {
|
|
299
|
+
cell: spore,
|
|
300
|
+
spore,
|
|
301
|
+
sporeData,
|
|
302
|
+
scriptInfo: SporeScriptInfo.from(scriptInfo),
|
|
303
|
+
};
|
|
284
304
|
}
|
|
285
305
|
}
|
|
286
306
|
}
|