kaspad/domain/consensus/utils/utxo/utxo_entry.go
Svarog a585f32763
[NOD-1551] Make UTXODiff immutable + skip cloning it in datastore (#1167)
* [NOD-1551] Make UTXO-Diff implemented fully in utils/utxo

* [NOD-1551] Fixes everywhere except database

* [NOD-1551] Fix database

* [NOD-1551] Add comments

* [NOD-1551] Partial commit

* [NOD-1551] Comlete making UTXOEntry immutable + don't clone it in UTXOCollectionClone

* [NOD-1551] Rename ToUnmutable -> ToImmutable

* [NOD-1551] Track immutable references generated from mutable UTXODiff, and invalidate them if the mutable one changed

* [NOD-1551] Clone scriptPubKey in NewUTXOEntry

* [NOD-1551] Remove redundant code

* [NOD-1551] Remove redundant call for .CloneMutable and then .ToImmutable

* [NOD-1551] Make utxoEntry pointert-receiver + clone ScriptPubKey in getter
2020-12-03 13:24:24 +02:00

41 lines
982 B
Go

package utxo
import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
type utxoEntry struct {
amount uint64
scriptPublicKey []byte
blockBlueScore uint64
isCoinbase bool
}
// NewUTXOEntry creates a new utxoEntry representing the given txOut
func NewUTXOEntry(amount uint64, scriptPubKey []byte, isCoinbase bool, blockBlueScore uint64) externalapi.UTXOEntry {
scriptPubKeyClone := make([]byte, len(scriptPubKey))
copy(scriptPubKeyClone, scriptPubKey)
return &utxoEntry{
amount: amount,
scriptPublicKey: scriptPubKeyClone,
blockBlueScore: blockBlueScore,
isCoinbase: isCoinbase,
}
}
func (u *utxoEntry) Amount() uint64 {
return u.amount
}
func (u *utxoEntry) ScriptPublicKey() []byte {
clone := make([]byte, len(u.scriptPublicKey))
copy(clone, u.scriptPublicKey)
return clone
}
func (u *utxoEntry) BlockBlueScore() uint64 {
return u.blockBlueScore
}
func (u *utxoEntry) IsCoinbase() bool {
return u.isCoinbase
}