mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-05-31 03:06:44 +00:00
31 lines
736 B
Go
31 lines
736 B
Go
package utxoserialization
|
|
|
|
import (
|
|
"github.com/kaspanet/kaspad/domain/consensus/model"
|
|
"github.com/kaspanet/kaspad/domain/consensus/utils/utxo"
|
|
)
|
|
|
|
// 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 := utxo.SerializeUTXO(entry, outpoint)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
protoUTXOSet.Utxos = append(protoUTXOSet.Utxos, &ProtoUTXO{
|
|
EntryOutpointPair: serializedUTXOBytes,
|
|
})
|
|
}
|
|
return protoUTXOSet, nil
|
|
}
|