Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fluffy-readers-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ckb-ccc/core": patch
---

feat(core): add isDaoOutputLimitExceeded utility for NervosDAO 64-output guard
36 changes: 36 additions & 0 deletions packages/core/src/ckb/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2470,6 +2470,42 @@ export class Transaction extends mol.Entity.Base<
}
}

/**
* Checks whether a NervosDAO transaction exceeds the 64-output limit.
* Returns true if the transaction is DAO-related and has more than 64 outputs.
* Short-circuits to false when outputs <= 64.
*
* @param tx - The transaction to check
* @param client - CKB client for resolving the NervosDAO script and input cell info
* @returns true if the DAO output limit is exceeded
*/
export async function isDaoOutputLimitExceeded(
tx: Transaction,
client: Client,
): Promise<boolean> {
if (tx.outputs.length <= 64) {
return false;
}

const { codeHash, hashType } = await client.getKnownScript(
KnownScript.NervosDao,
);
const dao = Script.from({ codeHash, hashType, args: "0x" });

if (tx.outputs.some((o) => o.type?.eq(dao))) {
return true;
}

for (const input of tx.inputs) {
await input.completeExtraInfos(client);
if (input.cellOutput?.type?.eq(dao)) {
return true;
}
}

return false;
}

/**
* Calculate Nervos DAO profit between two blocks.
* This function computes the profit earned from a Nervos DAO deposit
Expand Down