Skip to content

Add ToJSON instance for new experimental TxOut#1176

Open
Jimbo4350 wants to merge 1 commit intomasterfrom
issue-926-refactor-fromjson-txout
Open

Add ToJSON instance for new experimental TxOut#1176
Jimbo4350 wants to merge 1 commit intomasterfrom
issue-926-refactor-fromjson-txout

Conversation

@Jimbo4350
Copy link
Copy Markdown
Contributor

Context

Implements a ToJSON instance for the new TxOut era type (which wraps L.TxOut era) in the experimental API, matching the JSON format of the legacy txOutToJsonValue.

Changelog

- description: |
    Add ToJSON instance for new experimental TxOut type using AnyEraTxOut
    from cardano-ledger for era-conditional field inclusion
  type:
   - refactoring
  projects:
   - cardano-api

How to trust this PR

  • Uses AnyEraTxOut from cardano-ledger to conditionally include datum and reference script fields based on era capabilities, avoiding per-era pattern matching in the general instance
  • Standalone instances for pre-Alonzo eras (Shelley, Allegra, Mary) which only have address and value fields
  • Property test verifies JSON output matches the legacy txOutToJsonValue across all Shelley-based eras (Shelley through Conway)
  • Helper functions: addrToJson (bech32/base58), valueToJson (cardano-api Value format), ledgerScriptToScriptInAnyLang (generic script conversion using withPlutusScript)
  • Note: supplemental datums are not representable at the TxOut level (documented in haddock)

Checklist

  • Commit sequence is logical and each commit has a good commit message
  • New tests are added if needed and old tests still pass
  • Code is formatted with fourmolu
  • Self-reviewed the diff

🤖 Generated with Claude Code

Implement ToJSON for the new TxOut type that wraps L.TxOut era,
matching the JSON format of the legacy txOutToJsonValue.

Uses AnyEraTxOut from cardano-ledger to conditionally include
datum and reference script fields based on era capabilities,
avoiding per-era pattern matching. Standalone instances cover
pre-Alonzo eras (Shelley, Allegra, Mary) which only need
address and value fields.

Helper functions:
- addrToJson: renders L.Addr as bech32/base58
- valueToJson: converts to cardano-api Value format
- ledgerScriptToScriptInAnyLang: generic script conversion
  using withPlutusScript, no per-era matching

Includes a property test verifying JSON output matches the
legacy implementation across all Shelley-based eras.
@Jimbo4350 Jimbo4350 force-pushed the issue-926-refactor-fromjson-txout branch from 5fbefff to db3f128 Compare April 2, 2026 20:04
@Jimbo4350 Jimbo4350 marked this pull request as ready for review April 2, 2026 20:04
Copilot AI review requested due to automatic review settings April 2, 2026 20:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants