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 {
372372 o .OutputAddress .ToPlutusData (),
373373 data .NewMap (valueData ),
374374 // Empty datum option
375- // TODO: implement this
376375 data .NewConstr (0 ),
377376 // Empty script ref
378- // TODO: implement this
379377 data .NewConstr (1 ),
380378 )
381379 return tmpData
Original file line number Diff line number Diff line change @@ -422,8 +422,35 @@ func (o *ByronTransactionOutput) UnmarshalCBOR(data []byte) error {
422422}
423423
424424func (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
427454}
428455
429456func (o ByronTransactionOutput ) Address () common.Address {
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ package mary
1717import (
1818 "encoding/json"
1919 "fmt"
20+ "math/big"
2021
2122 "github.com/blinklabs-io/gouroboros/cbor"
2223 "github.com/blinklabs-io/gouroboros/ledger/common"
@@ -449,8 +450,46 @@ func (o MaryTransactionOutput) MarshalJSON() ([]byte, error) {
449450}
450451
451452func (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
454493}
455494
456495func (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 {
404404}
405405
406406func (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
409436}
410437
411438func (o ShelleyTransactionOutput ) Address () common.Address {
You can’t perform that action at this time.
0 commit comments