diff --git a/.changeset/fluffy-readers-warn.md b/.changeset/fluffy-readers-warn.md new file mode 100644 index 00000000..28e3e902 --- /dev/null +++ b/.changeset/fluffy-readers-warn.md @@ -0,0 +1,5 @@ +--- +"@ckb-ccc/core": patch +--- + +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 35fc4a72..b2029d7c 100644 --- a/packages/core/src/ckb/transaction.ts +++ b/packages/core/src/ckb/transaction.ts @@ -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 { + 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