mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00
[NOD-1508] Implement VirtualUTXOSetIterator (#998)
This commit is contained in:
parent
7f2ef708a6
commit
f06dc7ea90
@ -46,10 +46,6 @@ func (c consensusStateStore) IsStaged() bool {
|
||||
c.stagedVirtualUTXODiff != nil
|
||||
}
|
||||
|
||||
func (c consensusStateStore) VirtualUTXOSetIterator(dbContext model.DBReader) (model.ReadOnlyUTXOSetIterator, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (c consensusStateStore) StageVirtualUTXOSet(virtualUTXOSetIterator model.ReadOnlyUTXOSetIterator) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
@ -92,3 +92,48 @@ func (c consensusStateStore) HasUTXOByOutpoint(dbContext model.DBReader, outpoin
|
||||
|
||||
return dbContext.Has(key)
|
||||
}
|
||||
|
||||
func (c consensusStateStore) VirtualUTXOSetIterator(dbContext model.DBReader) (model.ReadOnlyUTXOSetIterator, error) {
|
||||
cursor, err := dbContext.Cursor(utxoSetBucket)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return newUTXOSetIterator(cursor), nil
|
||||
}
|
||||
|
||||
type utxoSetIterator struct {
|
||||
cursor model.DBCursor
|
||||
}
|
||||
|
||||
func newUTXOSetIterator(cursor model.DBCursor) model.ReadOnlyUTXOSetIterator {
|
||||
return &utxoSetIterator{cursor: cursor}
|
||||
}
|
||||
|
||||
func (u utxoSetIterator) Next() bool {
|
||||
return u.cursor.Next()
|
||||
}
|
||||
|
||||
func (u utxoSetIterator) Get() (outpoint *externalapi.DomainOutpoint, utxoEntry *externalapi.UTXOEntry) {
|
||||
key, err := u.cursor.Key()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
utxoEntryBytes, err := u.cursor.Value()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
outpoint, err = deserializeOutpoint(key.Suffix())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
utxoEntry, err = deserializeUTXOEntry(utxoEntryBytes)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return outpoint, utxoEntry
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user