lbcutil/coinset
Dave Collins fac8a9a582
multi: Update markdown files for GFM changes.
The github markdown interpreter has been changed such that it no longer
allows spaces in between the brackets and parenthesis of links.  This
updates all of the markdown files accordingly.

While here, it also corrects a couple of inconsistencies in regards to
other README.md files in the project.
2017-05-25 13:01:10 -05:00
..
coins.go build: Add gosimple linter to goclean.sh 2017-01-11 15:38:44 -05:00
coins_test.go Drop fastsha256 in favor of crypto/sha256 2017-01-10 17:09:00 -05:00
cov_report.sh Added CoinSelector interface and a few simple algos as a sub-package 2014-03-22 23:25:33 -04:00
README.md multi: Update markdown files for GFM changes. 2017-05-25 13:01:10 -05:00
test_coverage.txt Added CoinSelector interface and a few simple algos as a sub-package 2014-03-22 23:25:33 -04:00

coinset

Build Status ISC License GoDoc

Package coinset provides bitcoin-specific convenience functions for selecting from and managing sets of unspent transaction outpoints (UTXOs).

A comprehensive suite of tests is provided to ensure proper functionality. See test_coverage.txt for the gocov coverage report. Alternatively, if you are running a POSIX OS, you can run the cov_report.sh script for a real-time report.

Installation and Updating

$ go get -u github.com/btcsuite/btcutil/coinset

Usage

Each unspent transaction outpoint is represented by the Coin interface. An example of a concrete type that implements Coin is coinset.SimpleCoin.

The typical use case for this library is for creating raw bitcoin transactions given a set of Coins that may be spent by the user, for example as below:

var unspentCoins = []coinset.Coin{ ... }

When the user needs to spend a certain amount, they will need to select a subset of these coins which contain at least that value. CoinSelector is an interface that represents types that implement coin selection algos, subject to various criteria. There are a few examples of CoinSelector's:

  • MinIndexCoinSelector

  • MinNumberCoinSelector

  • MaxValueAgeCoinSelector

  • MinPriorityCoinSelector

For example, if the user wishes to maximize the probability that their transaction is mined quickly, they could use the MaxValueAgeCoinSelector to select high priority coins, then also attach a relatively high fee.

selector := &coinset.MaxValueAgeCoinSelector{
    MaxInputs: 10,
    MinAmountChange: 10000,
}
selectedCoins, err := selector.CoinSelect(targetAmount + bigFee, unspentCoins)
if err != nil {
	return err
}
msgTx := coinset.NewMsgTxWithInputCoins(selectedCoins)
...

The user can then create the msgTx.TxOut's as required, then sign the transaction and transmit it to the network.

License

Package coinset is licensed under the copyfree ISC License.