File tree Expand file tree Collapse file tree 8 files changed +128
-20
lines changed Expand file tree Collapse file tree 8 files changed +128
-20
lines changed Original file line number Diff line number Diff line change @@ -242,8 +242,18 @@ func (t AllegraTransaction) Consumed() []TransactionInput {
242
242
return t .Inputs ()
243
243
}
244
244
245
- func (t AllegraTransaction ) Produced () []TransactionOutput {
246
- return t .Outputs ()
245
+ func (t AllegraTransaction ) Produced () []Utxo {
246
+ var ret []Utxo
247
+ for idx , output := range t .Outputs () {
248
+ ret = append (
249
+ ret ,
250
+ Utxo {
251
+ Id : NewShelleyTransactionInput (t .Hash (), idx ),
252
+ Output : output ,
253
+ },
254
+ )
255
+ }
256
+ return ret
247
257
}
248
258
249
259
func (t AllegraTransaction ) ProtocolParametersUpdate () map [Blake2b224 ]any {
Original file line number Diff line number Diff line change @@ -373,12 +373,22 @@ func (t AlonzoTransaction) Consumed() []TransactionInput {
373
373
}
374
374
}
375
375
376
- func (t AlonzoTransaction ) Produced () []TransactionOutput {
376
+ func (t AlonzoTransaction ) Produced () []Utxo {
377
377
if t .IsValid () {
378
- return t .Outputs ()
378
+ var ret []Utxo
379
+ for idx , output := range t .Outputs () {
380
+ ret = append (
381
+ ret ,
382
+ Utxo {
383
+ Id : NewShelleyTransactionInput (t .Hash (), idx ),
384
+ Output : output ,
385
+ },
386
+ )
387
+ }
388
+ return ret
379
389
} else {
380
390
// No collateral return in Alonzo
381
- return []TransactionOutput {}
391
+ return []Utxo {}
382
392
}
383
393
}
384
394
Original file line number Diff line number Diff line change @@ -553,14 +553,29 @@ func (t BabbageTransaction) Consumed() []TransactionInput {
553
553
}
554
554
}
555
555
556
- func (t BabbageTransaction ) Produced () []TransactionOutput {
556
+ func (t BabbageTransaction ) Produced () []Utxo {
557
557
if t .IsValid () {
558
- return t .Outputs ()
558
+ var ret []Utxo
559
+ for idx , output := range t .Outputs () {
560
+ ret = append (
561
+ ret ,
562
+ Utxo {
563
+ Id : NewShelleyTransactionInput (t .Hash (), idx ),
564
+ Output : output ,
565
+ },
566
+ )
567
+ }
568
+ return ret
559
569
} else {
560
570
if t .CollateralReturn () == nil {
561
- return []TransactionOutput {}
571
+ return []Utxo {}
572
+ }
573
+ return []Utxo {
574
+ {
575
+ Id : NewShelleyTransactionInput (t .Hash (), len (t .Outputs ())),
576
+ Output : t .CollateralReturn (),
577
+ },
562
578
}
563
- return []TransactionOutput {t .CollateralReturn ()}
564
579
}
565
580
}
566
581
Original file line number Diff line number Diff line change 15
15
package ledger
16
16
17
17
import (
18
+ "encoding/hex"
18
19
"fmt"
19
20
20
21
utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
@@ -257,8 +258,18 @@ func (t *ByronTransaction) Consumed() []TransactionInput {
257
258
return t .Inputs ()
258
259
}
259
260
260
- func (t * ByronTransaction ) Produced () []TransactionOutput {
261
- return t .Outputs ()
261
+ func (t * ByronTransaction ) Produced () []Utxo {
262
+ var ret []Utxo
263
+ for idx , output := range t .Outputs () {
264
+ ret = append (
265
+ ret ,
266
+ Utxo {
267
+ Id : NewByronTransactionInput (t .Hash (), idx ),
268
+ Output : output ,
269
+ },
270
+ )
271
+ }
272
+ return ret
262
273
}
263
274
264
275
func (t * ByronTransaction ) Utxorpc () * utxorpc.Tx {
@@ -280,6 +291,17 @@ type ByronTransactionInput struct {
280
291
OutputIndex uint32
281
292
}
282
293
294
+ func NewByronTransactionInput (hash string , idx int ) ByronTransactionInput {
295
+ tmpHash , err := hex .DecodeString (hash )
296
+ if err != nil {
297
+ panic (fmt .Sprintf ("failed to decode transaction hash: %s" , err ))
298
+ }
299
+ return ByronTransactionInput {
300
+ TxId : Blake2b256 (tmpHash ),
301
+ OutputIndex : uint32 (idx ),
302
+ }
303
+ }
304
+
283
305
func (i * ByronTransactionInput ) UnmarshalCBOR (data []byte ) error {
284
306
id , err := cbor .DecodeIdFromList (data )
285
307
if err != nil {
Original file line number Diff line number Diff line change @@ -441,14 +441,29 @@ func (t ConwayTransaction) Consumed() []TransactionInput {
441
441
}
442
442
}
443
443
444
- func (t ConwayTransaction ) Produced () []TransactionOutput {
444
+ func (t ConwayTransaction ) Produced () []Utxo {
445
445
if t .IsValid () {
446
- return t .Outputs ()
446
+ var ret []Utxo
447
+ for idx , output := range t .Outputs () {
448
+ ret = append (
449
+ ret ,
450
+ Utxo {
451
+ Id : NewShelleyTransactionInput (t .Hash (), idx ),
452
+ Output : output ,
453
+ },
454
+ )
455
+ }
456
+ return ret
447
457
} else {
448
458
if t .CollateralReturn () == nil {
449
- return []TransactionOutput {}
459
+ return []Utxo {}
460
+ }
461
+ return []Utxo {
462
+ {
463
+ Id : NewShelleyTransactionInput (t .Hash (), len (t .Outputs ())),
464
+ Output : t .CollateralReturn (),
465
+ },
450
466
}
451
- return []TransactionOutput {t .CollateralReturn ()}
452
467
}
453
468
}
454
469
Original file line number Diff line number Diff line change @@ -259,8 +259,18 @@ func (t MaryTransaction) Consumed() []TransactionInput {
259
259
return t .Inputs ()
260
260
}
261
261
262
- func (t MaryTransaction ) Produced () []TransactionOutput {
263
- return t .Outputs ()
262
+ func (t MaryTransaction ) Produced () []Utxo {
263
+ var ret []Utxo
264
+ for idx , output := range t .Outputs () {
265
+ ret = append (
266
+ ret ,
267
+ Utxo {
268
+ Id : NewShelleyTransactionInput (t .Hash (), idx ),
269
+ Output : output ,
270
+ },
271
+ )
272
+ }
273
+ return ret
264
274
}
265
275
266
276
func (t * MaryTransaction ) Cbor () []byte {
Original file line number Diff line number Diff line change @@ -332,6 +332,17 @@ type ShelleyTransactionInput struct {
332
332
OutputIndex uint32
333
333
}
334
334
335
+ func NewShelleyTransactionInput (hash string , idx int ) ShelleyTransactionInput {
336
+ tmpHash , err := hex .DecodeString (hash )
337
+ if err != nil {
338
+ panic (fmt .Sprintf ("failed to decode transaction hash: %s" , err ))
339
+ }
340
+ return ShelleyTransactionInput {
341
+ TxId : Blake2b256 (tmpHash ),
342
+ OutputIndex : uint32 (idx ),
343
+ }
344
+ }
345
+
335
346
func (i ShelleyTransactionInput ) Id () Blake2b256 {
336
347
return i .TxId
337
348
}
@@ -502,8 +513,18 @@ func (t ShelleyTransaction) Consumed() []TransactionInput {
502
513
return t .Inputs ()
503
514
}
504
515
505
- func (t ShelleyTransaction ) Produced () []TransactionOutput {
506
- return t .Outputs ()
516
+ func (t ShelleyTransaction ) Produced () []Utxo {
517
+ var ret []Utxo
518
+ for idx , output := range t .Outputs () {
519
+ ret = append (
520
+ ret ,
521
+ Utxo {
522
+ Id : NewShelleyTransactionInput (t .Hash (), idx ),
523
+ Output : output ,
524
+ },
525
+ )
526
+ }
527
+ return ret
507
528
}
508
529
509
530
func (t ShelleyTransaction ) Utxorpc () * utxorpc.Tx {
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ type Transaction interface {
29
29
Metadata () * cbor.LazyValue
30
30
IsValid () bool
31
31
Consumed () []TransactionInput
32
- Produced () []TransactionOutput
32
+ Produced () []Utxo
33
33
}
34
34
35
35
type TransactionBody interface {
@@ -74,6 +74,11 @@ type TransactionOutput interface {
74
74
Utxorpc () * utxorpc.TxOutput
75
75
}
76
76
77
+ type Utxo struct {
78
+ Id TransactionInput
79
+ Output TransactionOutput
80
+ }
81
+
77
82
func NewTransactionFromCbor (txType uint , data []byte ) (Transaction , error ) {
78
83
switch txType {
79
84
case TxTypeByron :
You can’t perform that action at this time.
0 commit comments