Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrSiacoinSourceAlreadyAdded is the error returned when a user tries to // provide the same source siacoin input multiple times. ErrSiacoinSourceAlreadyAdded = errors.New("source siacoin input has already been used") // ErrSiacoinInputAlreadyUsed warns a user that a siacoin input has already // been used in the transaction graph. ErrSiacoinInputAlreadyUsed = errors.New("cannot use the same siacoin input twice in a graph") // ErrNoSuchSiacoinInput warns a user that they are trying to reference a // siacoin input which does not yet exist. ErrNoSuchSiacoinInput = errors.New("no siacoin input exists with that index") // ErrSiacoinInputsOutputsMismatch warns a user that they have constructed a // transaction which does not spend the same amount of siacoins that it // consumes. ErrSiacoinInputsOutputsMismatch = errors.New("siacoin input value to transaction does not match siacoin output value of transaction") )
var ( // AnyoneCanSpendUnlockHash is the unlock hash of unlock conditions that are // trivially spendable. AnyoneCanSpendUnlockHash types.UnlockHash = types.UnlockConditions{}.UnlockHash() )
Functions ¶
func MinimumTransactionSet ¶
func MinimumTransactionSet(requiredTxns []types.Transaction, relatedTxns []types.Transaction) []types.Transaction
MinimumTransactionSet takes two transaction sets as input and returns a combined transaction set. The first input is the set of required transactions, which the caller is indicating must all be a part of the final set.The second input is a set of related transactions that the caller believes may contain parent transactions of the required transactions. MinimumCombinedSet will scan through the related transactions and pull in any which are required parents of the required transactions, returning the final result.
The final transaction set which gets returned will contain all of the required transactions, and will contain any of the related transactions which are necessary for the required transactions to be confirmed.
NOTE: Both of the inputs are proper transaction sets. A proper transaction set is already sorted so that no parent comes after a child in the array.
func SprintTxnWithObjectIDs ¶
func SprintTxnWithObjectIDs(t types.Transaction) string
SprintTxnWithObjectIDs creates a string representing this Transaction in human-readable form with all object IDs included to allow for easy dependency matching (by humans) in debug-logs.
Types ¶
type SimpleTransaction ¶
type SimpleTransaction struct { SiacoinInputs []int // Which inputs to use, by index. SiacoinOutputs []types.Currency // The values of each output. MinerFees []types.Currency // The fees used. }
SimpleTransaction specifies what outputs it spends, and what outputs it creates, by index. When passed in TransactionGraph, it will be automatically transformed into a valid transaction.
Currently, there is only support for SiacoinInputs, SiacoinOutputs, and MinerFees, however the code has been structured so that support for Siafunds and FileContracts can be easily added in the future.
type TransactionGraph ¶
type TransactionGraph struct {
// contains filtered or unexported fields
}
TransactionGraph is a helper tool to allow a user to easily construct elaborate transaction graphs. The transaction tool will handle creating valid transactions, providing the user with a clean interface for building transactions.
func NewTransactionGraph ¶
func NewTransactionGraph() *TransactionGraph
NewTransactionGraph will return a blank transaction graph that is ready for use.
func (*TransactionGraph) AddSiacoinSource ¶
func (tg *TransactionGraph) AddSiacoinSource(scoid types.SiacoinOutputID, value types.Currency) (int, error)
AddSiacoinSource will add a new source of siacoins to the transaction graph, returning the index that this source can be referenced by. The provided output must have the address AnyoneCanSpendUnlockHash.
The value is used as an input so that the graph can check whether all transactions are spending as many siacoins as they create.
func (*TransactionGraph) AddTransaction ¶
func (tg *TransactionGraph) AddTransaction(st SimpleTransaction) (newSiacoinInputs []int, err error)
AddTransaction will add a new transaction to the transaction graph, following the guide of the input. The indexes of all the outputs created will be returned.
func (*TransactionGraph) Transactions ¶
func (tg *TransactionGraph) Transactions() []types.Transaction
Transactions will return the transactions that were built up in the graph.