Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions ledger/alonzo/alonzo.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,8 @@ func (o AlonzoTransactionOutput) ToPlutusData() data.PlutusData {
o.OutputAddress.ToPlutusData(),
data.NewMap(valueData),
// Empty datum option
// TODO: implement this
data.NewConstr(0),
// Empty script ref
// TODO: implement this
data.NewConstr(1),
)
return tmpData
Expand Down
31 changes: 29 additions & 2 deletions ledger/byron/byron.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,35 @@ func (o *ByronTransactionOutput) UnmarshalCBOR(data []byte) error {
}

func (o ByronTransactionOutput) ToPlutusData() data.PlutusData {
// A Byron transaction output will never be used for Plutus scripts
return nil
var valueData [][2]data.PlutusData
if o.OutputAmount > 0 {
valueData = append(
valueData,
[2]data.PlutusData{
data.NewByteString(nil),
data.NewMap(
[][2]data.PlutusData{
{
data.NewByteString(nil),
data.NewInteger(
new(big.Int).SetUint64(o.OutputAmount),
),
},
},
),
},
)
}
tmpData := data.NewConstr(
0,
o.OutputAddress.ToPlutusData(),
data.NewMap(valueData),
// Empty datum option
data.NewConstr(0),
// Empty script ref
data.NewConstr(1),
)
return tmpData
}

func (o ByronTransactionOutput) Address() common.Address {
Expand Down
43 changes: 41 additions & 2 deletions ledger/mary/mary.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package mary
import (
"encoding/json"
"fmt"
"math/big"

"github.com/blinklabs-io/gouroboros/cbor"
"github.com/blinklabs-io/gouroboros/ledger/common"
Expand Down Expand Up @@ -449,8 +450,46 @@ func (o MaryTransactionOutput) MarshalJSON() ([]byte, error) {
}

func (o MaryTransactionOutput) ToPlutusData() data.PlutusData {
// A Mary transaction output will never be used for Plutus scripts
return nil
var valueData [][2]data.PlutusData
if o.OutputAmount.Amount > 0 {
valueData = append(
valueData,
[2]data.PlutusData{
data.NewByteString(nil),
data.NewMap(
[][2]data.PlutusData{
{
data.NewByteString(nil),
data.NewInteger(
new(big.Int).SetUint64(o.OutputAmount.Amount),
),
},
},
),
},
)
}
if o.OutputAmount.Assets != nil {
assetData := o.OutputAmount.Assets.ToPlutusData()
assetDataMap, ok := assetData.(*data.Map)
if !ok {
return nil
}
valueData = append(
valueData,
assetDataMap.Pairs...,
)
}
tmpData := data.NewConstr(
0,
o.OutputAddress.ToPlutusData(),
data.NewMap(valueData),
// Empty datum option
data.NewConstr(0),
// Empty script ref
data.NewConstr(1),
)
return tmpData
}

func (o MaryTransactionOutput) Address() common.Address {
Expand Down
31 changes: 29 additions & 2 deletions ledger/shelley/shelley.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,35 @@ func (o *ShelleyTransactionOutput) UnmarshalCBOR(cborData []byte) error {
}

func (o ShelleyTransactionOutput) ToPlutusData() data.PlutusData {
// A Shelley transaction output will never be used for Plutus scripts
return nil
var valueData [][2]data.PlutusData
if o.OutputAmount > 0 {
valueData = append(
valueData,
[2]data.PlutusData{
data.NewByteString(nil),
data.NewMap(
[][2]data.PlutusData{
{
data.NewByteString(nil),
data.NewInteger(
new(big.Int).SetUint64(o.OutputAmount),
),
},
},
),
},
)
}
tmpData := data.NewConstr(
0,
o.OutputAddress.ToPlutusData(),
data.NewMap(valueData),
// Empty datum option
data.NewConstr(0),
// Empty script ref
data.NewConstr(1),
)
return tmpData
}

func (o ShelleyTransactionOutput) Address() common.Address {
Expand Down