|
15 | 15 | package ledger |
16 | 16 |
|
17 | 17 | import ( |
| 18 | + "encoding/hex" |
18 | 19 | "encoding/json" |
19 | 20 | "fmt" |
20 | 21 |
|
| 22 | + utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano" |
| 23 | + |
21 | 24 | "github.com/blinklabs-io/gouroboros/cbor" |
22 | 25 | ) |
23 | 26 |
|
@@ -90,6 +93,25 @@ func (b *BabbageBlock) Transactions() []Transaction { |
90 | 93 | return ret |
91 | 94 | } |
92 | 95 |
|
| 96 | +func (b *BabbageBlock) Utxorpc() *utxorpc.Block { |
| 97 | + var block *utxorpc.Block |
| 98 | + var body *utxorpc.BlockBody |
| 99 | + var header *utxorpc.BlockHeader |
| 100 | + var txs []*utxorpc.Tx |
| 101 | + header.Slot = b.SlotNumber() |
| 102 | + tmpHash, _ := hex.DecodeString(b.Hash()) |
| 103 | + header.Hash = tmpHash |
| 104 | + header.Height = b.BlockNumber() |
| 105 | + for _, t := range b.Transactions() { |
| 106 | + tx := t.Utxorpc() |
| 107 | + txs = append(txs, tx) |
| 108 | + } |
| 109 | + body.Tx = txs |
| 110 | + block.Body = body |
| 111 | + block.Header = header |
| 112 | + return block |
| 113 | +} |
| 114 | + |
93 | 115 | type BabbageBlockHeader struct { |
94 | 116 | cbor.StructAsArray |
95 | 117 | cbor.DecodeStoreCbor |
@@ -304,6 +326,17 @@ func (o BabbageTransactionOutput) Datum() *cbor.LazyValue { |
304 | 326 | return nil |
305 | 327 | } |
306 | 328 |
|
| 329 | +func (o BabbageTransactionOutput) Utxorpc() *utxorpc.TxOutput { |
| 330 | + return &utxorpc.TxOutput{ |
| 331 | + Address: o.OutputAddress.Bytes(), |
| 332 | + Coin: o.Amount(), |
| 333 | + // Assets: o.Assets(), |
| 334 | + // Datum: o.Datum(), |
| 335 | + DatumHash: o.DatumHash().Bytes(), |
| 336 | + // Script: o.ScriptRef, |
| 337 | + } |
| 338 | +} |
| 339 | + |
307 | 340 | type BabbageTransactionWitnessSet struct { |
308 | 341 | AlonzoTransactionWitnessSet |
309 | 342 | PlutusV2Scripts []cbor.RawMessage `cbor:"6,keyasint,omitempty"` |
@@ -373,6 +406,10 @@ func (t *BabbageTransaction) Cbor() []byte { |
373 | 406 | return cborData |
374 | 407 | } |
375 | 408 |
|
| 409 | +func (t *BabbageTransaction) Utxorpc() *utxorpc.Tx { |
| 410 | + return t.Body.Utxorpc() |
| 411 | +} |
| 412 | + |
376 | 413 | func NewBabbageBlockFromCbor(data []byte) (*BabbageBlock, error) { |
377 | 414 | var babbageBlock BabbageBlock |
378 | 415 | if _, err := cbor.Decode(data, &babbageBlock); err != nil { |
|
0 commit comments