CoinSelection class
Represents a selection of inputs to fund a transaction. If the inputs provide sufficient value to cover the ouputs and fee for a transaction that isn't too large, ready shall be true and it is possible to obtain a signable transaction.
Constructors
-
CoinSelection.new({int version = Transaction.currentVersion, required Iterable<
InputCandidate> selected, required Iterable<Output> recipients, required Program changeProgram, required BigInt feePerKb, required BigInt minFee, required BigInt minChange, int locktime = 0}) -
Selects all the inputs from
selected
to send to therecipients
outputs and provide change to thechangeProgram
. ThefeePerKb
specifies the required fee in sats per KB with a minimum fee specified withminFee
. TheminChange
is the minimum allowed change. -
CoinSelection.inOrderUntilEnough({int version = Transaction.currentVersion, required Iterable<
InputCandidate> candidates, required Iterable<Output> recipients, required Program changeProgram, required BigInt feePerKb, required BigInt minFee, required BigInt minChange, int locktime = 0, bool randomise = false, int maxCandidates = 6800}) -
A simple selection algorithm that selects inputs from the
candidates
in the order that they are given until the required amount has been reached. If there are not enough coins, all shall be selected and enoughFunds shall be false. Ifrandomise
is set to true, the order of inputs shall be randomised after being selected. This is useful for candidates that are not already randomised as it may avoid giving clues to the algorithm being used. The algorithm will only take upto 6800 candidates by default to avoid taking too long and due to size limitations. This can be changed withmaxCandidates
.factory -
CoinSelection.largestFirst({int version = Transaction.currentVersion, required Iterable<
InputCandidate> candidates, required Iterable<Output> recipients, required Program changeProgram, required BigInt feePerKb, required BigInt minFee, required BigInt minChange, int locktime = 0}) -
A simple selection algorithm that selects inputs from the
candidates
starting from the largest value until the required amount has been reached. The order of the selected inputs are randomised.factory -
CoinSelection.optimal({int version = Transaction.currentVersion, required Iterable<
InputCandidate> candidates, required Iterable<Output> recipients, required Program changeProgram, required BigInt feePerKb, required BigInt minFee, required BigInt minChange, int locktime = 0}) -
A useful default coin selection algorithm.
Currently this will first select candidates at random until the required
input amount is reached. If the resulting transaction is too large or not
enough funds have been reached it will fall back to adding the largest
input values first.
factory
-
CoinSelection.random({int version = Transaction.currentVersion, required Iterable<
InputCandidate> candidates, required Iterable<Output> recipients, required Program changeProgram, required BigInt feePerKb, required BigInt minFee, required BigInt minChange, int locktime = 0}) -
A simple selection algorithm that selects inputs randomly from the
candidates
until the required amount has been reached.factory
Properties
- changeless → bool
-
True when the change output is omitted
no setter
- changeProgram → Program
-
final
- changeValue ↔ BigInt
-
The value of the change output. This is 0 for a changeless transaction or
negative if there aren't enough funds.
latefinal
- enoughFunds → bool
-
True when the input value covers the outputs and fee
no setter
- fee ↔ BigInt
-
The fee to be paid by the transaction
latefinal
- feePerKb → BigInt
-
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- inputValue ↔ BigInt
-
The total value of selected inputs
latefinal
- locktime → int
-
final
- minChange → BigInt
-
final
- minFee → BigInt
-
final
- ready → bool
-
True if a signable solution has been found
no setter
-
recipients
→ List<
Output> -
final
- recipientValue ↔ BigInt
-
The total value of all recipient outputs
latefinal
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
selected
→ List<
InputCandidate> -
final
- signedSize ↔ int
-
The maximum size of the transaction after being fully signed
latefinal
- tooLarge → bool
-
True if the resulting fully signed transaction will be too large
no setter
- transaction → Transaction
-
Obtains the transaction with selected inputs and outputs including any
change at a random location, ready to be signed. Throws
InsufficientFunds if there is not enough input value to meet the output
value and fee, or TransactionTooLarge if the resulting signed
transaction would be too large.
no setter
- version → int
-
final
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited