mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-05 13:46:42 +00:00

* [NOD-1570] Implement utxo.IteratorWithDiff * [NOD-1570] Utilize utxo.ITeratorWithDiff in RestorePastUTXOSetIterator and VirtualUTXOSetIterator * [NOD-1570] Fix comment
41 lines
1.0 KiB
Go
41 lines
1.0 KiB
Go
package utxo
|
|
|
|
import (
|
|
"github.com/kaspanet/kaspad/domain/consensus/model"
|
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
|
)
|
|
|
|
type utxoOutpointEntryPair struct {
|
|
outpoint externalapi.DomainOutpoint
|
|
entry *externalapi.UTXOEntry
|
|
}
|
|
|
|
type utxoCollectionIterator struct {
|
|
index int
|
|
pairs []utxoOutpointEntryPair
|
|
}
|
|
|
|
// CollectionIterator creates a utxo iterator from give UTXO collection
|
|
func CollectionIterator(collection model.UTXOCollection) model.ReadOnlyUTXOSetIterator {
|
|
pairs := make([]utxoOutpointEntryPair, len(collection))
|
|
i := 0
|
|
for outpoint, entry := range collection {
|
|
pairs[i] = utxoOutpointEntryPair{
|
|
outpoint: outpoint,
|
|
entry: entry,
|
|
}
|
|
i++
|
|
}
|
|
return &utxoCollectionIterator{index: -1, pairs: pairs}
|
|
}
|
|
|
|
func (u *utxoCollectionIterator) Next() bool {
|
|
u.index++
|
|
return u.index < len(u.pairs)
|
|
}
|
|
|
|
func (u *utxoCollectionIterator) Get() (outpoint *externalapi.DomainOutpoint, utxoEntry *externalapi.UTXOEntry, err error) {
|
|
pair := u.pairs[u.index]
|
|
return &pair.outpoint, pair.entry, nil
|
|
}
|