Skip to content
Open

Fg #3

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
60 changes: 60 additions & 0 deletions .github/workflows/main_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Run Tests

on:
push:
branches:
- master
pull_request:

permissions:
contents: read

jobs:
unit:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14, 'lts/*']
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@eeb10cff27034e7acf239c5d29f62154018672fd # v3
with:
node-version: ${{ matrix.node-version }}
registry-url: https://registry.npmjs.org/
cache: 'npm'
- run: npm i
- run: npm run unit
coverage:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14, 'lts/*']
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@eeb10cff27034e7acf239c5d29f62154018672fd # v3
with:
node-version: ${{ matrix.node-version }}
registry-url: https://registry.npmjs.org/
cache: 'npm'
- run: npm i
- run: npm run coverage
lint:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14, 'lts/*']
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@eeb10cff27034e7acf239c5d29f62154018672fd # v3
with:
node-version: ${{ matrix.node-version }}
registry-url: https://registry.npmjs.org/
cache: 'npm'
- run: npm i
- run: npm run standard
15 changes: 0 additions & 15 deletions .travis.yml

This file was deleted.

30 changes: 25 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,16 @@ let utxos = [
txId: '...',
vout: 0,
...,
value: 10000
value: 10000,
// For use with PSBT:
// not needed for coinSelect, but will be passed on to inputs later
nonWitnessUtxo: Buffer.from('...full raw hex of txId tx...', 'hex'),
// OR
// if your utxo is a segwit output, you can use witnessUtxo instead
witnessUtxo: {
script: Buffer.from('... scriptPubkey hex...', 'hex'),
value: 10000 // 0.0001 BTC and is the exact same as the value above
}
}
]
let targets = [
Expand All @@ -56,9 +65,17 @@ console.log(fee)
// .inputs and .outputs will be undefined if no solution was found
if (!inputs || !outputs) return

let txb = new bitcoin.TransactionBuilder()

inputs.forEach(input => txb.addInput(input.txId, input.vout))
let psbt = new bitcoin.Psbt()

inputs.forEach(input =>
psbt.addInput({
hash: input.txId,
index: input.vout,
nonWitnessUtxo: input.nonWitnessUtxo,
// OR (not both)
witnessUtxo: input.witnessUtxo,
})
)
outputs.forEach(output => {
// watch out, outputs may have been added that you need to provide
// an output address/script for
Expand All @@ -67,7 +84,10 @@ outputs.forEach(output => {
wallet.nextChangeAddress()
}

txb.addOutput(output.address, output.value)
psbt.addOutput({
address: output.address,
value: output.value,
})
})
```

Expand Down
20 changes: 20 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export interface UTXO {
txid: string | Buffer,
vout: number,
value: number,
nonWitnessUtxo? : Buffer,
witnessUtxo? : {
script: Buffer,
value: number
}
}
export interface Target {
address: string,
value?: number
}
export interface SelectedUTXO {
inputs?: UTXO[],
outputs?: Target[],
fee: number
}
export default function coinSelect(utxos: UTXO[], outputs: Target[], feeRate: number): SelectedUTXO;
Loading