Add blockchain.NewUtxoEntry() to directly create entries for UtxoViewpoint
The current methods to add to a UtxoViewpoint don't allow for a situation where we have only UTXO data but not a whole transaction. This commit allows contstruction of a UtxoEntry without requiring a full MsgTx. AddTxOut() and AddTxOuts() both require a whole transaction, including the inputs, which are only used in order to calculate the txid. In some situations, such as with use of the utreexo accumulator, we only have the utxo data but not the transaction which created it. For reference, utreexo's initial usage of the blockchain.NewUtxoEntry() function is at https://github.com/mit-dci/utreexo/pull/135/files#diff-3f7b8f9991ea957f1f4ad9f5a95415f0R96
This commit is contained in:
parent
b11bf582c5
commit
a383a71670
1 changed files with 16 additions and 0 deletions
|
@ -111,6 +111,22 @@ func (entry *UtxoEntry) Clone() *UtxoEntry {
|
|||
}
|
||||
}
|
||||
|
||||
// NewUtxoEntry returns a new UtxoEntry built from the arguments.
|
||||
func NewUtxoEntry(
|
||||
txOut *wire.TxOut, blockHeight int32, isCoinbase bool) *UtxoEntry {
|
||||
var cbFlag txoFlags
|
||||
if isCoinbase {
|
||||
cbFlag |= tfCoinBase
|
||||
}
|
||||
|
||||
return &UtxoEntry{
|
||||
amount: txOut.Value,
|
||||
pkScript: txOut.PkScript,
|
||||
blockHeight: blockHeight,
|
||||
packedFlags: cbFlag,
|
||||
}
|
||||
}
|
||||
|
||||
// UtxoViewpoint represents a view into the set of unspent transaction outputs
|
||||
// from a specific point of view in the chain. For example, it could be for
|
||||
// the end of the main chain, some point in the history of the main chain, or
|
||||
|
|
Loading…
Reference in a new issue