Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCoinsNoSelectionAvailable is returned when a CoinSelector believes there is no possible combination of coins which can meet the requirements provided to the selector. ErrCoinsNoSelectionAvailable = errors.New("no coin selection possible") )
Functions ¶
Types ¶
type Coin ¶
type Coin interface { Hash() *chainhash.Hash Index() uint32 Value() util.Amount PkScript() []byte NumConfs() int64 ValueAge() int64 }
Coin represents a spendable transaction outpoint
type CoinSelector ¶
CoinSelector is an interface that wraps the CoinSelect method. CoinSelect will attempt to select a subset of the coins which has at least the targetValue amount. CoinSelect is not guaranteed to return a selection of coins even if the total value of coins given is greater than the target value. The exact choice of coins in the subset will be implementation specific. It is important to note that the Coins being used as inputs need to have a constant ValueAge() during the execution of CoinSelect.
type CoinSet ¶
type CoinSet struct {
// contains filtered or unexported fields
}
CoinSet is a utility struct for the modifications of a set of Coins that implements the Coins interface. To create a CoinSet, you must call NewCoinSet with nil for an empty set or a slice of coins as the initial contents. It is important to note that the all the Coins being added or removed from a CoinSet must have a constant ValueAge() during the use of the CoinSet, otherwise the cached values will be incorrect.
func NewCoinSet ¶
NewCoinSet creates a CoinSet containing the coins provided. To create an empty CoinSet, you may pass null as the coins input parameter.
func (*CoinSet) PushCoin ¶
PushCoin adds a coin to the end of the list and updates the cached value amounts.
func (*CoinSet) TotalValue ¶
TotalValue returns the total value of the coins in the set.
func (*CoinSet) TotalValueAge ¶
TotalValueAge returns the total value * number of confirmations of the coins in the set.
type MaxValueAgeCoinSelector ¶
MaxValueAgeCoinSelector is a CoinSelector that attempts to construct a selection of coins whose total value is at least targetValue that has as much input value-age as possible. This would be useful in the case where you want to maximize likelihood of the inclusion of your transaction in the next mined block.
func (MaxValueAgeCoinSelector) CoinSelect ¶
CoinSelect will attempt to select coins using the algorithm described in the MaxValueAgeCoinSelector struct.
type MinIndexCoinSelector ¶
MinIndexCoinSelector is a CoinSelector that attempts to construct a selection of coins whose total value is at least targetValue and prefers any number of lower indexes (as in the ordered array) over higher ones.
func (MinIndexCoinSelector) CoinSelect ¶
CoinSelect will attempt to select coins using the algorithm described in the MinIndexCoinSelector struct.
type MinNumberCoinSelector ¶
MinNumberCoinSelector is a CoinSelector that attempts to construct a selection of coins whose total value is at least targetValue that uses as few of the inputs as possible.
func (MinNumberCoinSelector) CoinSelect ¶
CoinSelect will attempt to select coins using the algorithm described in the MinNumberCoinSelector struct.
type MinPriorityCoinSelector ¶
type MinPriorityCoinSelector struct { MaxInputs int MinChangeAmount util.Amount MinAvgValueAgePerInput int64 }
MinPriorityCoinSelector is a CoinSelector that attempts to construct a selection of coins whose total value is at least targetValue and whose average value-age per input is greater than MinAvgValueAgePerInput. If there is change, it must exceed MinChangeAmount to be a valid selection. When possible, MinPriorityCoinSelector will attempt to reduce the average input priority over the threshold, but no guarantees will be made as to minimality of the selection. The selection below is almost certainly suboptimal.
func (MinPriorityCoinSelector) CoinSelect ¶
CoinSelect will attempt to select coins using the algorithm described in the MinPriorityCoinSelector struct.
type SimpleCoin ¶
SimpleCoin defines a concrete instance of Coin that is backed by a util.Tx, a specific outpoint index, and the number of confirmations that transaction has had.
func (*SimpleCoin) Hash ¶
func (c *SimpleCoin) Hash() *chainhash.Hash
Hash returns the hash value of the transaction on which the Coin is an output
func (*SimpleCoin) Index ¶
func (c *SimpleCoin) Index() uint32
Index returns the index of the output on the transaction which the Coin represents
func (*SimpleCoin) NumConfs ¶
func (c *SimpleCoin) NumConfs() int64
NumConfs returns the number of confirmations that the transaction the Coin references has had.
func (*SimpleCoin) PkScript ¶
func (c *SimpleCoin) PkScript() []byte
PkScript returns the outpoint script of the Coin. This can be used to determine what type of script the Coin uses and extract standard addresses if possible using txscript.ExtractPkScriptAddrs for example.
func (*SimpleCoin) Value ¶
func (c *SimpleCoin) Value() util.Amount
Value returns the value of the Coin
func (*SimpleCoin) ValueAge ¶
func (c *SimpleCoin) ValueAge() int64
ValueAge returns the product of the value and the number of confirmations. This is used as an input to calculate the priority of the transaction.