From 6bf125e90ae5a33de16576b462ed06535546217e Mon Sep 17 00:00:00 2001 From: Leon Date: Tue, 25 Nov 2025 23:44:13 +0800 Subject: [PATCH 1/2] feat: add skipUtxoSelection option and update version to 3.1.15 --- package.json | 2 +- test/fixtures/witness.js | 91 ++++++++++++++++++++++++++++++++++++++++ test/witness.js | 5 ++- witness.js | 6 ++- 4 files changed, 99 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index cac5791..a0f545c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@onekeyfe/coinselect", - "version": "3.1.14", + "version": "3.1.15", "description": "A transaction input selection module for bitcoin.", "keywords": [ "coinselect", diff --git a/test/fixtures/witness.js b/test/fixtures/witness.js index e3aa757..ad661dc 100644 --- a/test/fixtures/witness.js +++ b/test/fixtures/witness.js @@ -364,6 +364,97 @@ const fixtures = [ outputsPermutation: [0] }, shouldThrow: false + }, + { + description: 'skipUtxoSelection - coin control with specific inputs', + feeRate: 10, + inputs: [ + { + txId: 'f46689066ac0493cc55920c3918163ccda6c64998d6c078c6254e1c00c36a332', + vout: 0, + value: 50000, + amount: '50000', + confirmations: 100, + own: true, + coinbase: false, + address: 'tb1qul5mzh5phe7xqyqek0nl42hflfrn7ugxck59jd', + path: "m/84'/1'/0'/0/0" + }, + { + txId: 'a88d1066ac0493cc55920c3918163ccda6c64998d6c078c6254e1c00c36a332', + vout: 1, + value: 30000, + amount: '30000', + confirmations: 200, + own: true, + coinbase: false, + address: 'tb1qul5mzh5phe7xqyqek0nl42hflfrn7ugxck59jd', + path: "m/84'/1'/0'/0/0" + } + ], + outputs: [ + { + type: 'payment', + address: 'tb1quawu6eyfuechu3qhdeejnrzne9y7shr08u8zzt', + value: 60000, + amount: '60000' + } + ], + network: testnet, + changeAddress: { + address: 'tb1qul5mzh5phe7xqyqek0nl42hflfrn7ugxck59jd', + path: "m/84'/1'/0'/0/0" + }, + txType: 'p2wpkh', + skipUtxoSelection: true, + expected: { + type: 'final', + fee: '2090', + feePerByte: '10', + bytes: 209, + max: undefined, + totalSpent: '62090', + inputs: [ + { + txId: 'a88d1066ac0493cc55920c3918163ccda6c64998d6c078c6254e1c00c36a332', + vout: 1, + value: 30000, + confirmations: 200, + own: true, + address: 'tb1qul5mzh5phe7xqyqek0nl42hflfrn7ugxck59jd', + path: "m/84'/1'/0'/0/0", + coinbase: false, + amount: '30000' + }, + { + txId: 'f46689066ac0493cc55920c3918163ccda6c64998d6c078c6254e1c00c36a332', + vout: 0, + value: 50000, + confirmations: 100, + own: true, + address: 'tb1qul5mzh5phe7xqyqek0nl42hflfrn7ugxck59jd', + path: "m/84'/1'/0'/0/0", + coinbase: false, + amount: '50000' + } + ], + outputs: [ + { + type: 'payment', + address: 'tb1quawu6eyfuechu3qhdeejnrzne9y7shr08u8zzt', + value: 60000, + amount: '60000' + }, + { + type: 'change', + address: 'tb1qul5mzh5phe7xqyqek0nl42hflfrn7ugxck59jd', + path: "m/84'/1'/0'/0/0", + amount: '17910' + } + ], + outputsPermutation: [0, 1] + }, + shouldThrow: false } ] diff --git a/test/witness.js b/test/witness.js index 046f145..1cc606f 100644 --- a/test/witness.js +++ b/test/witness.js @@ -25,7 +25,8 @@ fixtures.forEach(function (f) { feeRate: f.feeRate, network: f.network, changeAddress: f.changeAddress, - txType: f.txType + txType: f.txType, + skipUtxoSelection: f.skipUtxoSelection }) const compareOutputs = (actual, expected) => { @@ -61,7 +62,7 @@ fixtures.forEach(function (f) { t.same(actual.bytes, f.expected.bytes) t.same(actual.max, f.expected.max) t.same(actual.totalSpent, f.expected.totalSpent) - t.same(actual.inputs, f.expected.inputs) + t.ok(compareOutputs(actual.inputs, f.expected.inputs), 'inputs are the same') t.ok(compareOutputs(actual.outputs, f.expected.outputs), 'outputs are the same') t.end() } diff --git a/witness.js b/witness.js index 52d622d..92314ca 100644 --- a/witness.js +++ b/witness.js @@ -8,7 +8,8 @@ module.exports = function coinSelect ({ network, txType, baseFee = 0, - dustThreshold = 546 + dustThreshold = 546, + skipUtxoSelection = false }) { const result = composeTx({ utxos, @@ -19,7 +20,8 @@ module.exports = function coinSelect ({ dustThreshold, changeAddress, network, - baseFee + baseFee, + skipUtxoSelection }) if (result.type === 'error') { From 4b0e62a5152f50ab0e49eb8f7db04740bad2e219 Mon Sep 17 00:00:00 2001 From: Leon Date: Wed, 26 Nov 2025 00:02:45 +0800 Subject: [PATCH 2/2] chore: update GitHub Actions to use latest action versions and replace npm install with npm ci --- .github/workflows/main_ci.yml | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/.github/workflows/main_ci.yml b/.github/workflows/main_ci.yml index d59d6a4..9829f02 100644 --- a/.github/workflows/main_ci.yml +++ b/.github/workflows/main_ci.yml @@ -15,46 +15,37 @@ jobs: strategy: matrix: node-version: [20, 'lts/*'] - # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ steps: - - uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # v2 + - uses: actions/checkout@v4 - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@eeb10cff27034e7acf239c5d29f62154018672fd # v3 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - registry-url: https://registry.npmjs.org/ - cache: 'npm' - - run: npm i + - run: npm ci - run: npm run unit coverage: runs-on: ubuntu-latest strategy: matrix: node-version: [20, 'lts/*'] - # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ steps: - - uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # v2 + - uses: actions/checkout@v4 - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@eeb10cff27034e7acf239c5d29f62154018672fd # v3 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - registry-url: https://registry.npmjs.org/ - cache: 'npm' - - run: npm i + - run: npm ci - run: npm run coverage lint: runs-on: ubuntu-latest strategy: matrix: node-version: [20, 'lts/*'] - # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ steps: - - uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # v2 + - uses: actions/checkout@v4 - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@eeb10cff27034e7acf239c5d29f62154018672fd # v3 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - registry-url: https://registry.npmjs.org/ - cache: 'npm' - - run: npm i + - run: npm ci - run: npm run standard