File tree Expand file tree Collapse file tree 4 files changed +99
-8
lines changed Expand file tree Collapse file tree 4 files changed +99
-8
lines changed Original file line number Diff line number Diff line change @@ -372,10 +372,8 @@ func (o AlonzoTransactionOutput) ToPlutusData() data.PlutusData {
372
372
o .OutputAddress .ToPlutusData (),
373
373
data .NewMap (valueData ),
374
374
// Empty datum option
375
- // TODO: implement this
376
375
data .NewConstr (0 ),
377
376
// Empty script ref
378
- // TODO: implement this
379
377
data .NewConstr (1 ),
380
378
)
381
379
return tmpData
Original file line number Diff line number Diff line change @@ -422,8 +422,35 @@ func (o *ByronTransactionOutput) UnmarshalCBOR(data []byte) error {
422
422
}
423
423
424
424
func (o ByronTransactionOutput ) ToPlutusData () data.PlutusData {
425
- // A Byron transaction output will never be used for Plutus scripts
426
- return nil
425
+ var valueData [][2 ]data.PlutusData
426
+ if o .OutputAmount > 0 {
427
+ valueData = append (
428
+ valueData ,
429
+ [2 ]data.PlutusData {
430
+ data .NewByteString (nil ),
431
+ data .NewMap (
432
+ [][2 ]data.PlutusData {
433
+ {
434
+ data .NewByteString (nil ),
435
+ data .NewInteger (
436
+ new (big.Int ).SetUint64 (o .OutputAmount ),
437
+ ),
438
+ },
439
+ },
440
+ ),
441
+ },
442
+ )
443
+ }
444
+ tmpData := data .NewConstr (
445
+ 0 ,
446
+ o .OutputAddress .ToPlutusData (),
447
+ data .NewMap (valueData ),
448
+ // Empty datum option
449
+ data .NewConstr (0 ),
450
+ // Empty script ref
451
+ data .NewConstr (1 ),
452
+ )
453
+ return tmpData
427
454
}
428
455
429
456
func (o ByronTransactionOutput ) Address () common.Address {
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ package mary
17
17
import (
18
18
"encoding/json"
19
19
"fmt"
20
+ "math/big"
20
21
21
22
"github.com/blinklabs-io/gouroboros/cbor"
22
23
"github.com/blinklabs-io/gouroboros/ledger/common"
@@ -449,8 +450,46 @@ func (o MaryTransactionOutput) MarshalJSON() ([]byte, error) {
449
450
}
450
451
451
452
func (o MaryTransactionOutput ) ToPlutusData () data.PlutusData {
452
- // A Mary transaction output will never be used for Plutus scripts
453
- return nil
453
+ var valueData [][2 ]data.PlutusData
454
+ if o .OutputAmount .Amount > 0 {
455
+ valueData = append (
456
+ valueData ,
457
+ [2 ]data.PlutusData {
458
+ data .NewByteString (nil ),
459
+ data .NewMap (
460
+ [][2 ]data.PlutusData {
461
+ {
462
+ data .NewByteString (nil ),
463
+ data .NewInteger (
464
+ new (big.Int ).SetUint64 (o .OutputAmount .Amount ),
465
+ ),
466
+ },
467
+ },
468
+ ),
469
+ },
470
+ )
471
+ }
472
+ if o .OutputAmount .Assets != nil {
473
+ assetData := o .OutputAmount .Assets .ToPlutusData ()
474
+ assetDataMap , ok := assetData .(* data.Map )
475
+ if ! ok {
476
+ return nil
477
+ }
478
+ valueData = append (
479
+ valueData ,
480
+ assetDataMap .Pairs ... ,
481
+ )
482
+ }
483
+ tmpData := data .NewConstr (
484
+ 0 ,
485
+ o .OutputAddress .ToPlutusData (),
486
+ data .NewMap (valueData ),
487
+ // Empty datum option
488
+ data .NewConstr (0 ),
489
+ // Empty script ref
490
+ data .NewConstr (1 ),
491
+ )
492
+ return tmpData
454
493
}
455
494
456
495
func (o MaryTransactionOutput ) Address () common.Address {
Original file line number Diff line number Diff line change @@ -404,8 +404,35 @@ func (o *ShelleyTransactionOutput) UnmarshalCBOR(cborData []byte) error {
404
404
}
405
405
406
406
func (o ShelleyTransactionOutput ) ToPlutusData () data.PlutusData {
407
- // A Shelley transaction output will never be used for Plutus scripts
408
- return nil
407
+ var valueData [][2 ]data.PlutusData
408
+ if o .OutputAmount > 0 {
409
+ valueData = append (
410
+ valueData ,
411
+ [2 ]data.PlutusData {
412
+ data .NewByteString (nil ),
413
+ data .NewMap (
414
+ [][2 ]data.PlutusData {
415
+ {
416
+ data .NewByteString (nil ),
417
+ data .NewInteger (
418
+ new (big.Int ).SetUint64 (o .OutputAmount ),
419
+ ),
420
+ },
421
+ },
422
+ ),
423
+ },
424
+ )
425
+ }
426
+ tmpData := data .NewConstr (
427
+ 0 ,
428
+ o .OutputAddress .ToPlutusData (),
429
+ data .NewMap (valueData ),
430
+ // Empty datum option
431
+ data .NewConstr (0 ),
432
+ // Empty script ref
433
+ data .NewConstr (1 ),
434
+ )
435
+ return tmpData
409
436
}
410
437
411
438
func (o ShelleyTransactionOutput ) Address () common.Address {
You can’t perform that action at this time.
0 commit comments