view.Entries[prevout] = &utxo
}
+
+ for _, prevout := range tx.MainchainOutputIDs {
+ if view.HasUtxo(&prevout) {
+ continue
+ }
+
+ data := db.Get(calcUtxoKey(&prevout))
+ if data == nil {
+ view.Entries[prevout] = storage.NewUtxoEntry(storage.CrosschainUTXOType, 0, false)
+ continue
+ }
+
+ var utxo storage.UtxoEntry
+ if err := proto.Unmarshal(data, &utxo); err != nil {
+ return errors.Wrap(err, "unmarshaling mainchain ouput entry")
+ }
+
+ view.Entries[prevout] = &utxo
+ }
}
return nil
func saveUtxoView(batch dbm.Batch, view *state.UtxoViewpoint) error {
for key, entry := range view.Entries {
- if entry.Spent && !entry.IsCoinBase {
+ if (entry.Type == storage.CrosschainUTXOType) && (!entry.Spent) {
+ batch.Delete(calcUtxoKey(&key))
+ continue
+ }
+
+ if (entry.Type == storage.NormalUTXOType) && (entry.Spent) {
batch.Delete(calcUtxoKey(&key))
continue
}