From 3800e7f21dc8af6b5ea23e7a437055d1680aa43f Mon Sep 17 00:00:00 2001 From: tea2x Date: Sun, 18 Aug 2024 10:25:36 +0700 Subject: [PATCH] fix duplicated headers when batching dao unlocks --- package-lock.json | 4 ++-- package.json | 2 +- src/lumos-patcher.ts | 21 ++++++++++++++------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index 84791ff..34a4e16 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "joy-dao", - "version": "1.1.1", + "version": "0.0.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "joy-dao", - "version": "1.1.1", + "version": "0.0.4", "license": "ISC", "devDependencies": { "@ckb-ccc/connector-react": "^0.0.5-alpha.13", diff --git a/package.json b/package.json index 42b28ef..54828b1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "joy-dao", - "version": "0.0.3", + "version": "0.0.4", "description": "Nervos DAO transaction builder", "main": "dist/index.js", "files": [ diff --git a/src/lumos-patcher.ts b/src/lumos-patcher.ts index 27b86eb..70f25a1 100644 --- a/src/lumos-patcher.ts +++ b/src/lumos-patcher.ts @@ -185,15 +185,22 @@ export const unlock = async ( } // add dao unlock header deps - txSkeleton = txSkeleton.update("headerDeps", (headerDeps) => { - return headerDeps.push( - daoDepositCell.blockHash!, - daoWithdrawalCell.blockHash! - ); - }); + let headerDeps = txSkeleton.get("headerDeps"); + if (!headerDeps.contains(daoDepositCell.blockHash!)) { + txSkeleton = txSkeleton.update("headerDeps", (headerDeps) => { + return headerDeps.push(daoDepositCell.blockHash!); + }); + } + + if (!headerDeps.contains(daoWithdrawalCell.blockHash!)) { + txSkeleton = txSkeleton.update("headerDeps", (headerDeps) => { + return headerDeps.push(daoWithdrawalCell.blockHash!); + }); + } // add dao unlock witness - const depositHeaderDepIndex = txSkeleton.get("headerDeps").size - 2; + headerDeps = txSkeleton.get("headerDeps"); + const depositHeaderDepIndex = headerDeps.indexOf(daoDepositCell.blockHash!); const defaultWitnessArgs: WitnessArgs = { inputType: bytes.hexify(number.Uint64LE.pack(depositHeaderDepIndex)), };