Add ToJSON instance for new experimental TxOut#1176
Open
Conversation
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.
5fbefff to
db3f128
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Implements a
ToJSONinstance for the newTxOut eratype (which wrapsL.TxOut era) in the experimental API, matching the JSON format of the legacytxOutToJsonValue.Changelog
How to trust this PR
AnyEraTxOutfrom cardano-ledger to conditionally include datum and reference script fields based on era capabilities, avoiding per-era pattern matching in the general instancetxOutToJsonValueacross all Shelley-based eras (Shelley through Conway)addrToJson(bech32/base58),valueToJson(cardano-api Value format),ledgerScriptToScriptInAnyLang(generic script conversion usingwithPlutusScript)TxOutlevel (documented in haddock)Checklist
fourmolu🤖 Generated with Claude Code