@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.
Files changed (56) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/advanced.d.ts +2 -4
  3. package/dist/advanced.d.ts.map +1 -1
  4. package/dist/advanced.js +2 -4
  5. package/dist/advancedBarrel.d.ts +5 -0
  6. package/dist/advancedBarrel.d.ts.map +1 -0
  7. package/dist/advancedBarrel.js +4 -0
  8. package/dist/barrel.d.ts +5 -0
  9. package/dist/barrel.d.ts.map +1 -0
  10. package/dist/barrel.js +4 -0
  11. package/dist/cluster/index.d.ts +7 -2
  12. package/dist/cluster/index.d.ts.map +1 -1
  13. package/dist/cluster/index.js +21 -25
  14. package/dist/helper/index.d.ts +0 -2
  15. package/dist/helper/index.d.ts.map +1 -1
  16. package/dist/helper/index.js +0 -19
  17. package/dist/index.d.ts +2 -4
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +2 -4
  20. package/dist/spore/advanced.d.ts.map +1 -1
  21. package/dist/spore/advanced.js +2 -10
  22. package/dist/spore/index.d.ts +9 -4
  23. package/dist/spore/index.d.ts.map +1 -1
  24. package/dist/spore/index.js +29 -30
  25. package/dist.commonjs/advanced.d.ts +2 -4
  26. package/dist.commonjs/advanced.d.ts.map +1 -1
  27. package/dist.commonjs/advanced.js +15 -4
  28. package/dist.commonjs/advancedBarrel.d.ts +5 -0
  29. package/dist.commonjs/advancedBarrel.d.ts.map +1 -0
  30. package/dist.commonjs/advancedBarrel.js +20 -0
  31. package/dist.commonjs/barrel.d.ts +5 -0
  32. package/dist.commonjs/barrel.d.ts.map +1 -0
  33. package/dist.commonjs/barrel.js +33 -0
  34. package/dist.commonjs/cluster/index.d.ts +7 -2
  35. package/dist.commonjs/cluster/index.d.ts.map +1 -1
  36. package/dist.commonjs/cluster/index.js +18 -22
  37. package/dist.commonjs/helper/index.d.ts +0 -2
  38. package/dist.commonjs/helper/index.d.ts.map +1 -1
  39. package/dist.commonjs/helper/index.js +0 -21
  40. package/dist.commonjs/index.d.ts +2 -4
  41. package/dist.commonjs/index.d.ts.map +1 -1
  42. package/dist.commonjs/index.js +3 -5
  43. package/dist.commonjs/spore/advanced.d.ts.map +1 -1
  44. package/dist.commonjs/spore/advanced.js +2 -10
  45. package/dist.commonjs/spore/index.d.ts +9 -4
  46. package/dist.commonjs/spore/index.d.ts.map +1 -1
  47. package/dist.commonjs/spore/index.js +26 -27
  48. package/package.json +12 -2
  49. package/src/advanced.ts +2 -4
  50. package/src/advancedBarrel.ts +4 -0
  51. package/src/barrel.ts +4 -0
  52. package/src/cluster/index.ts +33 -29
  53. package/src/helper/index.ts +0 -33
  54. package/src/index.ts +2 -4
  55. package/src/spore/advanced.ts +2 -12
  56. package/src/spore/index.ts +46 -31
@@ -5,11 +5,12 @@ import {
5
5
  assembleTransferSporeAction,
6
6
  prepareSporeTransaction,
7
7
  } from "../advanced.js";
8
- import { SporeData, SporeDataView, packRawSporeData } from "../codec/index.js";
9
8
  import {
10
- findSingletonCellByArgs,
11
- injectOneCapacityCell,
12
- } from "../helper/index.js";
9
+ SporeDataView,
10
+ packRawSporeData,
11
+ unpackToRawSporeData,
12
+ } from "../codec/index.js";
13
+ import { findSingletonCellByArgs } from "../helper/index.js";
13
14
  import {
14
15
  SporeScriptInfo,
15
16
  SporeScriptInfoLike,
@@ -20,20 +21,32 @@ import { prepareCluster } from "./advanced.js";
20
21
 
21
22
  export async function findSpore(
22
23
  client: ccc.Client,
23
- args: ccc.HexLike,
24
+ id: ccc.HexLike,
24
25
  scripts?: SporeScriptInfoLike[],
25
26
  ): Promise<
26
27
  | {
27
28
  cell: ccc.Cell;
29
+ spore: ccc.Cell;
30
+ sporeData: SporeDataView;
28
31
  scriptInfo: SporeScriptInfo;
29
32
  }
30
33
  | undefined
31
34
  > {
32
- return findSingletonCellByArgs(
35
+ const found = await findSingletonCellByArgs(
33
36
  client,
34
- args,
37
+ id,
35
38
  scripts ?? Object.values(getSporeScriptInfos(client)),
36
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
+ };
37
50
  }
38
51
 
39
52
  export async function assertSpore(
@@ -90,9 +103,7 @@ export async function createSpore(params: {
90
103
  const actions = [];
91
104
  const ids: ccc.Hex[] = [];
92
105
  const tx = ccc.Transaction.from(params.tx ?? {});
93
- if (tx.inputs.length === 0) {
94
- await injectOneCapacityCell(signer, tx);
95
- }
106
+ await tx.completeInputsAtLeastOne(signer);
96
107
 
97
108
  const { script: lock } = await signer.getRecommendedAddressObj();
98
109
 
@@ -240,20 +251,28 @@ export async function meltSpore(params: {
240
251
  *
241
252
  * @param signer the owner of spores
242
253
  * @param order the order in creation time of spores
243
- * @param clusterId the cluster that spores belong to
254
+ * @param clusterId the cluster that spores belong to. "" to find public spores
244
255
  * @param scriptInfos the deployed script infos of spores
245
- * @returns speific spore cells
256
+ * @returns specified spore cells
246
257
  */
247
- export async function* findSporesBySigner(params: {
258
+ export async function* findSporesBySigner({
259
+ signer,
260
+ clusterId,
261
+ scriptInfos,
262
+ limit,
263
+ order,
264
+ }: {
248
265
  signer: ccc.Signer;
249
266
  order?: "asc" | "desc";
267
+ limit?: number;
250
268
  clusterId?: ccc.HexLike;
251
269
  scriptInfos?: SporeScriptInfoLike[];
252
270
  }): AsyncGenerator<{
271
+ cell: ccc.Cell;
253
272
  spore: ccc.Cell;
254
273
  sporeData: SporeDataView;
274
+ scriptInfo: SporeScriptInfo;
255
275
  }> {
256
- const { signer, clusterId, scriptInfos, order } = params;
257
276
  for (const scriptInfo of scriptInfos ??
258
277
  Object.values(getSporeScriptInfos(signer.client))) {
259
278
  if (!scriptInfo) {
@@ -268,24 +287,20 @@ export async function* findSporesBySigner(params: {
268
287
  },
269
288
  true,
270
289
  order,
271
- 10,
290
+ limit,
272
291
  )) {
273
- try {
274
- const sporeData = SporeData.decode(spore.outputData);
275
- if (!clusterId) {
276
- yield {
277
- spore,
278
- sporeData,
279
- };
280
- }
281
- if (sporeData.clusterId === clusterId) {
282
- return {
283
- spore,
284
- sporeData,
285
- };
286
- }
287
- } catch (e: unknown) {
288
- 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
+ };
289
304
  }
290
305
  }
291
306
  }