From 0e17e8f713c678c9d417eec313271e3017ae6a68 Mon Sep 17 00:00:00 2001 From: phroi <90913182+phroi@users.noreply.github.com> Date: Sat, 28 Feb 2026 11:26:22 +0000 Subject: [PATCH] feat(core): add isDaoOutputLimitExceeded for NervosDAO 64-output guard --- .changeset/fluffy-readers-warn.md | 5 ++++ packages/core/src/ckb/transaction.ts | 36 ++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 .changeset/fluffy-readers-warn.md diff --git a/.changeset/fluffy-readers-warn.md b/.changeset/fluffy-readers-warn.md new file mode 100644 index 00000000..f15370ac --- /dev/null +++ b/.changeset/fluffy-readers-warn.md @@ -0,0 +1,5 @@ +--- +"@ckb-ccc/core": minor +--- + +feat(core): add isDaoOutputLimitExceeded utility for NervosDAO 64-output guard diff --git a/packages/core/src/ckb/transaction.ts b/packages/core/src/ckb/transaction.ts index 2cb60e90..3d3bc325 100644 --- a/packages/core/src/ckb/transaction.ts +++ b/packages/core/src/ckb/transaction.ts @@ -2426,6 +2426,42 @@ export class Transaction extends 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 { + 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