Skip to content

Conversation

@Jimbo4350
Copy link
Contributor

Changelog

- description: |
   Implement `writeTxFileTextEnvelope` and `writeTxFileTextEnvelopeCanonical` for `SignedTx`
# uncomment types applicable to the change:
  type:
   - feature        

# uncomment at least one main project this PR is associated with
  projects:
   - cardano-api

Context

Additional context for the PR goes here. If the PR fixes a particular issue please provide a link to the issue.

How to trust this PR

Highlight important bits of the PR that will make the review faster. If there are commands the reviewer can run to observe the new behavior, describe them.

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated. See Running tests for more details
  • Self-reviewed the diff

@Jimbo4350 Jimbo4350 force-pushed the jordan/add-write-text-envelope-functions-for-signed-tx branch from 00d933e to 292cdc0 Compare November 20, 2025 19:53
@Jimbo4350 Jimbo4350 force-pushed the jordan/add-write-text-envelope-functions-for-signed-tx branch from 292cdc0 to fee95da Compare November 21, 2025 12:09
Copy link
Contributor

@palas palas left a comment

Choose a reason for hiding this comment

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

Just a few comments. Make sure the potential incompatibility issue is not a problem, and the rest are only suggestions

Comment on lines +75 to +87
serialiseToRawBytes (SignedTx tx) =
Ledger.serialize' (Ledger.eraProtVerHigh @(LedgerEra era)) tx
deserialiseFromRawBytes _ =
bimap wrapError SignedTx
. Ledger.decodeFullAnnotator
(Ledger.eraProtVerHigh @(LedgerEra era))
"SignedTx"
Ledger.decCBOR
. fromStrict
where
wrapError
:: Ledger.DecoderError -> SerialiseAsRawBytesError
wrapError = SerialiseAsRawBytesError . displayException
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this can probably be implemented in terms of SerialiseAsCBOR now, or the other way around, because they are almost identical code except for the error handling

. fromStrict

instance (L.EraTx (LedgerEra era), HasTypeProxy era) => HasTextEnvelope (SignedTx era) where
textEnvelopeType _ = "Tx"
Copy link
Contributor

Choose a reason for hiding this comment

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

This may break compatibility with the old API text envelope type:

instance IsShelleyBasedEra era => HasTextEnvelope (Tx era) where

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, do you have in mind how will deserialising work without knowing the era? I guess because we have only two eras is not too problematic, but we may need two separate functions (one for each era).

Comment on lines +53 to +61
either
( \err ->
error $
"writeTxFileTextEnvelopeCanonical: Impossible - deserialisation of just serialised bytes failed "
<> show err
)
id
. canonicaliseCborBs
$ teRawCBOR te
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use: first or mapLeft.

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.

3 participants