Skip to content

Add FromJSON instance for new experimental TxOut#1179

Draft
Jimbo4350 wants to merge 4 commits intomasterfrom
issue-926-experimental-fromjson-txout
Draft

Add FromJSON instance for new experimental TxOut#1179
Jimbo4350 wants to merge 4 commits intomasterfrom
issue-926-experimental-fromjson-txout

Conversation

@Jimbo4350
Copy link
Copy Markdown
Contributor

Context

Implements FromJSON instances for the new TxOut era type (which wraps L.TxOut era) in the experimental API, matching the JSON format produced by the ToJSON instances added in #1176.

Closes #926

Changelog

- description: |
    Add FromJSON instance for new experimental TxOut type with per-era
    concrete instances, inline datum parsing from inlineDatumRaw with
    hash validation, and reference script support via scriptInAnyLangToLedgerScript
  type:
   - feature
  projects:
   - cardano-api

How to trust this PR

  • Concrete FromJSON instances for each era (Shelley through Conway), mirroring the ToJSON structure from Add ToJSON instance for new experimental TxOut #1176
  • Pre-Alonzo eras parse address and value only via shared txOutBaseParseJson helper
  • Alonzo adds datum hash parsing via dataHashTxOutL
  • Babbage+ adds inline datum parsing from inlineDatumRaw (hex-encoded original CBOR bytes) with hash validation against inlineDatumhash, and reference script parsing via scriptInAnyLangToLedgerScript
  • Supplemental datums deliberately unsupported — the ledger TxOut does not carry them
  • Helper functions: addrFromJson (reverse of addrToJson), scriptInAnyLangToLedgerScript (reverse of ledgerScriptToScriptInAnyLang)
  • Property test verifies JSON round-trip (fromJSON . toJSON = id) across all Shelley-based eras

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

Add per-era FromJSON instances for the experimental TxOut type,
mirroring the ToJSON structure. Pre-Alonzo eras parse address and
value only; Alonzo adds datum hash support; Babbage+ adds inline
datum (parsed from inlineDatumRaw with hash validation) and
reference script support. Supplemental datums are deliberately
unsupported as the ledger TxOut does not carry them.
Extract the cast-based value conversion from txOutBaseParseJson into
a standalone documented helper. The ledger's Value type family resolves
to Coin for Shelley/Allegra and MaryValue for Mary onwards, requiring
a runtime type check via Data.Typeable.cast to bridge the gap.
Replace the three separate where-bound helpers (datumFields,
inlineDatumFields, refScriptFields) with a single top-level
datumAndRefScriptFields function. Simplifies alonzoOnwardsTxOutToJson
and documents the per-era field layout in one place.
@Jimbo4350 Jimbo4350 force-pushed the issue-926-experimental-fromjson-txout branch from 87cfa8a to bc2431f Compare April 20, 2026 13:48
@Jimbo4350 Jimbo4350 force-pushed the issue-926-experimental-fromjson-txout branch from bc2431f to 9734a72 Compare April 27, 2026 20:19
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.

Implement JSON instances for the new experimental TxOut

1 participant