Skip to content

Commit dae6355

Browse files
authored
Merge pull request #173 from ashuralyk/chore/tiny-complete
chore: tiny complete for core & spore
2 parents 29a2e22 + 9eaa0ad commit dae6355

File tree

5 files changed

+140
-1
lines changed

5 files changed

+140
-1
lines changed

.changeset/blue-pans-hope.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@ckb-ccc/spore": minor
3+
---
4+
5+
support search spore/cluster under customized lock script

.changeset/gentle-crews-stare.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@ckb-ccc/core": minor
3+
---
4+
5+
Add treatment to uncompatible XUDT data format

packages/core/src/ckb/transaction.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,11 +701,13 @@ export class WitnessArgs extends mol.Entity.Base<
701701
}
702702

703703
/**
704+
* Convert a bytes to a num.
705+
*
704706
* @public
705707
*/
706708
export function udtBalanceFrom(dataLike: BytesLike): Num {
707709
const data = bytesFrom(dataLike).slice(0, 16);
708-
return numFromBytes(data);
710+
return data.length === 0 ? Zero : numFromBytes(data);
709711
}
710712

711713
export const RawTransaction = mol.table({

packages/spore/src/cluster/index.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,61 @@ export async function* findSporeClustersBySigner({
234234
}
235235
}
236236
}
237+
238+
/**
239+
* Search on-chain clusters under the specified lock or not
240+
*
241+
* @param client the client to search clusters
242+
* @param lock the lock of clusters
243+
*/
244+
export async function* findSporeClusters({
245+
client,
246+
lock,
247+
order,
248+
limit,
249+
scriptInfos,
250+
}: {
251+
client: ccc.Client;
252+
lock?: ccc.ScriptLike;
253+
order?: "asc" | "desc";
254+
limit?: number;
255+
scriptInfos?: SporeScriptInfoLike[];
256+
}): AsyncGenerator<{
257+
cell: ccc.Cell;
258+
cluster: ccc.Cell;
259+
clusterData: ClusterDataView;
260+
scriptInfo: SporeScriptInfo;
261+
}> {
262+
for (const scriptInfo of scriptInfos ??
263+
Object.values(getClusterScriptInfos(client))) {
264+
if (!scriptInfo) {
265+
continue;
266+
}
267+
268+
for await (const cluster of client.findCells(
269+
{
270+
script: {
271+
...scriptInfo,
272+
args: "",
273+
},
274+
scriptType: "type",
275+
scriptSearchMode: "prefix",
276+
withData: true,
277+
filter: lock
278+
? {
279+
script: lock,
280+
}
281+
: undefined,
282+
},
283+
order,
284+
limit,
285+
)) {
286+
yield {
287+
cell: cluster,
288+
cluster,
289+
clusterData: unpackToRawClusterData(cluster.outputData),
290+
scriptInfo: SporeScriptInfo.from(scriptInfo),
291+
};
292+
}
293+
}
294+
}

packages/spore/src/spore/index.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,72 @@ export async function* findSporesBySigner({
295295
}
296296
}
297297
}
298+
299+
/**
300+
* Search on-chain spores under the specified lock or not, if cluster provided, filter spores belonging to this cluster
301+
*
302+
* @param client the client to search spores
303+
* @param lock the lock of spores
304+
* @param clusterId the cluster that spores belong to. "" to find public spores
305+
* @param scriptInfos the deployed script infos of spores
306+
* @returns specified spore cells
307+
*/
308+
export async function* findSpores({
309+
client,
310+
lock,
311+
clusterId,
312+
scriptInfos,
313+
limit,
314+
order,
315+
}: {
316+
client: ccc.Client;
317+
lock?: ccc.ScriptLike;
318+
order?: "asc" | "desc";
319+
limit?: number;
320+
clusterId?: ccc.HexLike;
321+
scriptInfos?: SporeScriptInfoLike[];
322+
}): AsyncGenerator<{
323+
cell: ccc.Cell;
324+
spore: ccc.Cell;
325+
sporeData: SporeDataView;
326+
scriptInfo: SporeScriptInfo;
327+
}> {
328+
for (const scriptInfo of scriptInfos ??
329+
Object.values(getSporeScriptInfos(client))) {
330+
if (!scriptInfo) {
331+
continue;
332+
}
333+
for await (const spore of client.findCells(
334+
{
335+
script: {
336+
...scriptInfo,
337+
args: [],
338+
},
339+
scriptType: "type",
340+
scriptSearchMode: "prefix",
341+
withData: true,
342+
filter: lock
343+
? {
344+
script: lock,
345+
}
346+
: undefined,
347+
},
348+
order,
349+
limit,
350+
)) {
351+
const sporeData = unpackToRawSporeData(spore.outputData);
352+
if (
353+
!clusterId ||
354+
(clusterId === "" && !sporeData.clusterId) ||
355+
sporeData.clusterId === ccc.hexFrom(clusterId)
356+
) {
357+
yield {
358+
cell: spore,
359+
spore,
360+
sporeData,
361+
scriptInfo: SporeScriptInfo.from(scriptInfo),
362+
};
363+
}
364+
}
365+
}
366+
}

0 commit comments

Comments
 (0)