Skip to content

Commit

Permalink
feat: marshal TX output datum/hash to JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
agaffney committed Jul 4, 2023
1 parent c42ab7a commit 13173e1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
10 changes: 7 additions & 3 deletions ledger/alonzo.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,18 @@ func (o *AlonzoTransactionOutput) UnmarshalCBOR(cborData []byte) error {

func (o AlonzoTransactionOutput) MarshalJSON() ([]byte, error) {
tmpObj := struct {
Address Address `json:"address"`
Amount uint64 `json:"amount"`
Assets *MultiAsset[MultiAssetTypeOutput] `json:"assets,omitempty"`
Address Address `json:"address"`
Amount uint64 `json:"amount"`
Assets *MultiAsset[MultiAssetTypeOutput] `json:"assets,omitempty"`
DatumHash string `json:"datumHash,omitempty"`
}{
Address: o.OutputAddress,
Amount: o.OutputAmount.Amount,
Assets: o.OutputAmount.Assets,
}
if o.TxOutputDatumHash != nil {
tmpObj.DatumHash = o.TxOutputDatumHash.String()
}
return json.Marshal(&tmpObj)
}

Expand Down
16 changes: 13 additions & 3 deletions ledger/babbage.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,24 @@ func (o *BabbageTransactionOutput) UnmarshalCBOR(cborData []byte) error {

func (o BabbageTransactionOutput) MarshalJSON() ([]byte, error) {
tmpObj := struct {
Address Address `json:"address"`
Amount uint64 `json:"amount"`
Assets *MultiAsset[MultiAssetTypeOutput] `json:"assets,omitempty"`
Address Address `json:"address"`
Amount uint64 `json:"amount"`
Assets *MultiAsset[MultiAssetTypeOutput] `json:"assets,omitempty"`
Datum *cbor.LazyValue `json:"datum,omitempty"`
DatumHash string `json:"datumHash,omitempty"`
}{
Address: o.OutputAddress,
Amount: o.OutputAmount.Amount,
Assets: o.OutputAmount.Assets,
}
if o.DatumOption != nil {
if o.DatumOption.hash != nil {
tmpObj.DatumHash = o.DatumOption.hash.String()
}
if o.DatumOption.data != nil {
tmpObj.Datum = o.DatumOption.data
}
}
return json.Marshal(&tmpObj)
}

Expand Down

0 comments on commit 13173e1

Please sign in to comment.