mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-05-31 03:06:44 +00:00

* [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
54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package utxo
|
|
|
|
import (
|
|
"github.com/kaspanet/kaspad/domain/consensus/model"
|
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
type utxoOutpointEntryPair struct {
|
|
outpoint externalapi.DomainOutpoint
|
|
entry externalapi.UTXOEntry
|
|
}
|
|
|
|
type utxoCollectionIterator struct {
|
|
index int
|
|
pairs []utxoOutpointEntryPair
|
|
}
|
|
|
|
func (uc utxoCollection) Iterator() model.ReadOnlyUTXOSetIterator {
|
|
pairs := make([]utxoOutpointEntryPair, len(uc))
|
|
i := 0
|
|
for outpoint, entry := range uc {
|
|
pairs[i] = utxoOutpointEntryPair{
|
|
outpoint: outpoint,
|
|
entry: entry,
|
|
}
|
|
i++
|
|
}
|
|
return &utxoCollectionIterator{index: -1, pairs: pairs}
|
|
}
|
|
|
|
func (uci *utxoCollectionIterator) Next() bool {
|
|
uci.index++
|
|
return uci.index < len(uci.pairs)
|
|
}
|
|
|
|
func (uci *utxoCollectionIterator) Get() (outpoint *externalapi.DomainOutpoint, utxoEntry externalapi.UTXOEntry, err error) {
|
|
pair := uci.pairs[uci.index]
|
|
return &pair.outpoint, pair.entry, nil
|
|
}
|
|
|
|
func (uci *utxoCollectionIterator) WithDiff(diff model.UTXODiff) (model.ReadOnlyUTXOSetIterator, error) {
|
|
d, ok := diff.(*immutableUTXODiff)
|
|
if !ok {
|
|
return nil, errors.New("diff is not of type *immutableUTXODiff")
|
|
}
|
|
|
|
return &readOnlyUTXOIteratorWithDiff{
|
|
baseIterator: uci,
|
|
diff: d,
|
|
toAddIterator: diff.ToAdd().Iterator(),
|
|
}, nil
|
|
}
|