Skip to content

Commit 15df59d

Browse files
authored
fix: generate CBOR for genesis UTxOs (#984)
Fixes #983 Signed-off-by: Aurora Gaffney <aurora@blinklabs.io>
1 parent b4e4c31 commit 15df59d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

database/utxo.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"slices"
2121

2222
"github.com/blinklabs-io/dingo/database/models"
23+
"github.com/blinklabs-io/gouroboros/cbor"
2324
"github.com/blinklabs-io/gouroboros/ledger"
2425
"github.com/dgraph-io/badger/v4"
2526
)
@@ -56,7 +57,16 @@ func (d *Database) AddUtxos(
5657
utxoSlot.Utxo.Id.Id().Bytes(),
5758
utxoSlot.Utxo.Id.Index(),
5859
)
59-
err := txn.Blob().Set(key, utxoSlot.Utxo.Output.Cbor())
60+
utxoCbor := utxoSlot.Utxo.Output.Cbor()
61+
// Encode output to CBOR if stored CBOR is empty
62+
if len(utxoCbor) == 0 {
63+
var err error
64+
utxoCbor, err = cbor.Encode(utxoSlot.Utxo.Output)
65+
if err != nil {
66+
return err
67+
}
68+
}
69+
err := txn.Blob().Set(key, utxoCbor)
6070
if err != nil {
6171
return err
6272
}

0 commit comments

Comments
 (0)