Ori Newman 5566aaf95a
[NOD-1512] Implement utxo deserialization (#1003)
* [NOD-1512] Implement UTXO set deserialization

* [NOD-1512] Remove redundant file

* [NOD-1512] Don't use big endian for serialization

* [NOD-1512] Use Read/Write element

* [NOD-1512] Unexport ReadElement

* [NOD-1512] Fix StageVirtualUTXOSet

* [NOD-1512] Get rid of dagParams in consensusStateManager

* [NOD-1512] Get rid of dagParams in consensusStateManager
2020-11-05 10:59:49 +02:00

31 lines
772 B
Go

package utxoserialization
import (
"github.com/kaspanet/kaspad/domain/consensus/model"
"github.com/kaspanet/kaspad/domain/consensus/utils/consensusserialization"
)
// ReadOnlyUTXOSetToProtoUTXOSet converts ReadOnlyUTXOSetIterator to ProtoUTXOSet
func ReadOnlyUTXOSetToProtoUTXOSet(iter model.ReadOnlyUTXOSetIterator) (*ProtoUTXOSet, error) {
protoUTXOSet := &ProtoUTXOSet{
Utxos: []*ProtoUTXO{},
}
for iter.Next() {
outpoint, entry, err := iter.Get()
if err != nil {
return nil, err
}
serializedUTXOBytes, err := consensusserialization.SerializeUTXO(entry, outpoint)
if err != nil {
return nil, err
}
protoUTXOSet.Utxos = append(protoUTXOSet.Utxos, &ProtoUTXO{
EntryOutpointPair: serializedUTXOBytes,
})
}
return protoUTXOSet, nil
}