Skip to content

Commit 6727ffe

Browse files
phroiHanssen0
authored andcommitted
feat(core): add isDaoOutputLimitExceeded for NervosDAO 64-output guard
1 parent 44cd2d9 commit 6727ffe

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

.changeset/fluffy-readers-warn.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+
feat(core): add isDaoOutputLimitExceeded utility for NervosDAO 64-output guard

packages/core/src/ckb/transaction.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2426,6 +2426,42 @@ export class Transaction extends Entity.Base<TransactionLike, Transaction>() {
24262426
}
24272427
}
24282428

2429+
/**
2430+
* Checks whether a NervosDAO transaction exceeds the 64-output limit.
2431+
* Returns true if the transaction is DAO-related and has more than 64 outputs.
2432+
* Short-circuits to false when outputs <= 64.
2433+
*
2434+
* @param tx - The transaction to check
2435+
* @param client - CKB client for resolving the NervosDAO script and input cell info
2436+
* @returns true if the DAO output limit is exceeded
2437+
*/
2438+
export async function isDaoOutputLimitExceeded(
2439+
tx: Transaction,
2440+
client: Client,
2441+
): Promise<boolean> {
2442+
if (tx.outputs.length <= 64) {
2443+
return false;
2444+
}
2445+
2446+
const { codeHash, hashType } = await client.getKnownScript(
2447+
KnownScript.NervosDao,
2448+
);
2449+
const dao = Script.from({ codeHash, hashType, args: "0x" });
2450+
2451+
if (tx.outputs.some((o) => o.type?.eq(dao))) {
2452+
return true;
2453+
}
2454+
2455+
for (const input of tx.inputs) {
2456+
await input.completeExtraInfos(client);
2457+
if (input.cellOutput?.type?.eq(dao)) {
2458+
return true;
2459+
}
2460+
}
2461+
2462+
return false;
2463+
}
2464+
24292465
/**
24302466
* Calculate Nervos DAO profit between two blocks.
24312467
* This function computes the profit earned from a Nervos DAO deposit

0 commit comments

Comments
 (0)