From a383a7167007197578e780476cf5719c97dfd31b Mon Sep 17 00:00:00 2001 From: adiabat Date: Fri, 29 May 2020 12:03:02 -0400 Subject: [PATCH] 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 --- blockchain/utxoviewpoint.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/blockchain/utxoviewpoint.go b/blockchain/utxoviewpoint.go index 08005d27..b8576581 100644 --- a/blockchain/utxoviewpoint.go +++ b/blockchain/utxoviewpoint.go @@ -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