Skip to content

Commit fd3999b

Browse files
committed
Export upgrade functions from individual api modules
1 parent d09b535 commit fd3999b

File tree

7 files changed

+78
-8
lines changed

7 files changed

+78
-8
lines changed

libs/cardano-ledger-api/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 1.12.0.0
44

5+
* Expose `binaryUpgradeTx`, `binaryUpgradeTxBody`, `binaryUpgradeTxWits`, `binaryUpgradeTxAuxData`, `upgradeTx`, `upgradeTxBody`, `upgradeTxWits`, `upgradeTxAuxData`
56
* Add `EraApi` class
67
* Export `VotingProcedure`, `ProposalProcedure`, `currentTreasuryValueTxBodyL` and
78
`treasuryDonationTxBodyL` from `Cardano.Ledger.Api.Tx.Body`

libs/cardano-ledger-api/src/Cardano/Ledger/Api/Tx.hs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,14 @@ module Cardano.Ledger.Api.Tx (
6464
evalTxExUnitsWithLogs,
6565
RedeemerReportWithLogs,
6666
TransactionScriptFailure (..),
67+
68+
-- * Upgrade
69+
binaryUpgradeTx,
70+
upgradeTx,
6771
) where
6872

6973
import Cardano.Ledger.Alonzo.Tx (AlonzoEraTx (..), IsValid (..))
70-
import Cardano.Ledger.Api.Era ()
74+
import Cardano.Ledger.Api.Era (EraApi (..))
7175
import Cardano.Ledger.Api.Scripts.ExUnits (
7276
RedeemerReport,
7377
RedeemerReportWithLogs,
@@ -79,5 +83,5 @@ import Cardano.Ledger.Api.Tx.AuxData
7983
import Cardano.Ledger.Api.Tx.Body
8084
import Cardano.Ledger.Api.Tx.Cert
8185
import Cardano.Ledger.Api.Tx.Wits
82-
import Cardano.Ledger.Core (EraTx (..), txIdTx)
86+
import Cardano.Ledger.Core (EraTx (..), binaryUpgradeTx, txIdTx)
8387
import Cardano.Ledger.Tools (calcMinFeeTx, estimateMinFeeTx, setMinFeeTx, setMinFeeTxUtxo)

libs/cardano-ledger-api/src/Cardano/Ledger/Api/Tx/AuxData.hs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ module Cardano.Ledger.Api.Tx.AuxData (
2020
AlonzoTxAuxData (..),
2121
mkAlonzoTxAuxData,
2222
getAlonzoTxAuxDataScripts,
23+
24+
-- * Upgrade
25+
binaryUpgradeTxAuxData,
26+
upgradeTxAuxData,
2327
) where
2428

2529
import Cardano.Ledger.Allegra.TxAuxData (AllegraEraTxAuxData (..), AllegraTxAuxData (..))
@@ -29,6 +33,6 @@ import Cardano.Ledger.Alonzo.TxAuxData (
2933
getAlonzoTxAuxDataScripts,
3034
mkAlonzoTxAuxData,
3135
)
32-
import Cardano.Ledger.Api.Era ()
33-
import Cardano.Ledger.Core (EraTxAuxData (..), hashTxAuxData)
36+
import Cardano.Ledger.Api.Era (EraApi (..))
37+
import Cardano.Ledger.Core (EraTxAuxData (..), binaryUpgradeTxAuxData, hashTxAuxData)
3438
import Cardano.Ledger.Shelley.TxAuxData (Metadatum (..), ShelleyTxAuxData (..))

libs/cardano-ledger-api/src/Cardano/Ledger/Api/Tx/Body.hs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,16 @@ module Cardano.Ledger.Api.Tx.Body (
6969
ProposalProcedure (..),
7070
currentTreasuryValueTxBodyL,
7171
treasuryDonationTxBodyL,
72+
73+
-- * Upgrade
74+
binaryUpgradeTxBody,
75+
upgradeTxBody,
7276
) where
7377

7478
import Cardano.Ledger.Address (Withdrawals (..))
7579
import Cardano.Ledger.Allegra.Core (AllegraEraTxBody (..))
7680
import Cardano.Ledger.Alonzo.TxBody (AlonzoEraTxBody (..))
77-
import Cardano.Ledger.Api.Era ()
81+
import Cardano.Ledger.Api.Era (EraApi (..))
7882
import Cardano.Ledger.Api.Scripts
7983
import Cardano.Ledger.Api.Tx.Out
8084
import Cardano.Ledger.AuxiliaryData (AuxiliaryDataHash)
@@ -86,7 +90,14 @@ import Cardano.Ledger.Conway.Governance (
8690
VotingProcedure (..),
8791
)
8892
import Cardano.Ledger.Conway.TxBody (ConwayEraTxBody (..))
89-
import Cardano.Ledger.Core (EraTxBody (..), PParams, TxAuxDataHash (..), Value, txIdTxBody)
93+
import Cardano.Ledger.Core (
94+
EraTxBody (..),
95+
PParams,
96+
TxAuxDataHash (..),
97+
Value,
98+
binaryUpgradeTxBody,
99+
txIdTxBody,
100+
)
90101
import Cardano.Ledger.Credential (Credential)
91102
import Cardano.Ledger.Keys (KeyHash (..), KeyRole (..))
92103
import Cardano.Ledger.Mary.Core (MaryEraTxBody (..))

libs/cardano-ledger-api/src/Cardano/Ledger/Api/Tx/Wits.hs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ module Cardano.Ledger.Api.Tx.Wits (
3737

3838
-- ** Conway
3939
ConwayPlutusPurpose (..),
40+
41+
-- * Upgrade
42+
binaryUpgradeTxWits,
43+
upgradeTxWits,
4044
) where
4145

4246
import Cardano.Ledger.Alonzo.Scripts (
@@ -57,9 +61,9 @@ import Cardano.Ledger.Alonzo.TxWits (
5761
unTxDats,
5862
unTxDatsL,
5963
)
60-
import Cardano.Ledger.Api.Era ()
64+
import Cardano.Ledger.Api.Era (EraApi (..))
6165
import Cardano.Ledger.Conway.Scripts (ConwayPlutusPurpose (..))
62-
import Cardano.Ledger.Core (EraTxWits (..), hashScriptTxWitsL)
66+
import Cardano.Ledger.Core (EraTxWits (..), binaryUpgradeTxWits, hashScriptTxWitsL)
6367
import Cardano.Ledger.Keys (KeyRole (Witness))
6468
import Cardano.Ledger.Keys.Bootstrap (BootstrapWitness)
6569
import Cardano.Ledger.Keys.WitVKey (WitVKey (WitVKey), witVKeyHash)

libs/cardano-ledger-core/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 1.18.0.0
44

5+
* Added `binaryUpgradeTx`, `binaryUpgradeTxBody`, `binaryUpgradeTxWits`, `binaryUpgradeTxAuxData`
56
* Remove `upgradeTx` and `TxUpgradeError` from `EraTx`
67
* Remove `upgradeTxBody` and `TxBodyUpgradeError` from `EraTxBody`
78
* Remove `upgradeTxAuxData` from `EraTxAuxData`

libs/cardano-ledger-core/src/Cardano/Ledger/Core.hs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{-# LANGUAGE FlexibleContexts #-}
55
{-# LANGUAGE FlexibleInstances #-}
66
{-# LANGUAGE MultiParamTypeClasses #-}
7+
{-# LANGUAGE OverloadedStrings #-}
78
{-# LANGUAGE PolyKinds #-}
89
{-# LANGUAGE ScopedTypeVariables #-}
910
{-# LANGUAGE TypeApplications #-}
@@ -43,6 +44,10 @@ module Cardano.Ledger.Core (
4344
EraPParams (..),
4445
mkCoinTxOut,
4546
wireSizeTxF,
47+
binaryUpgradeTx,
48+
binaryUpgradeTxBody,
49+
binaryUpgradeTxWits,
50+
binaryUpgradeTxAuxData,
4651

4752
-- * Era
4853
module Cardano.Ledger.Core.Era,
@@ -76,6 +81,7 @@ import Cardano.Ledger.Binary (
7681
Annotator,
7782
DecCBOR,
7883
DecShareCBOR (Share),
84+
DecoderError,
7985
EncCBOR (..),
8086
EncCBORGroup,
8187
Interns,
@@ -85,6 +91,7 @@ import Cardano.Ledger.Binary (
8591
mkSized,
8692
serialize,
8793
serialize',
94+
translateViaCBORAnnotator,
8895
)
8996
import Cardano.Ledger.Coin (Coin)
9097
import Cardano.Ledger.Compactible (Compactible (..))
@@ -102,6 +109,7 @@ import Cardano.Ledger.Rewards (Reward (..), RewardType (..))
102109
import Cardano.Ledger.TxIn (TxId (..), TxIn (..))
103110
import Cardano.Ledger.Val (Val (..), inject)
104111
import Control.DeepSeq (NFData)
112+
import Control.Monad.Except (Except)
105113
import Data.Aeson (ToJSON)
106114
import qualified Data.ByteString as BS
107115
import qualified Data.ByteString.Lazy as LBS
@@ -114,6 +122,8 @@ import Data.MemPack
114122
import Data.Sequence.Strict (StrictSeq)
115123
import Data.Set (Set)
116124
import qualified Data.Set as Set
125+
import Data.Text (Text)
126+
import qualified Data.Text as T
117127
import Data.Word (Word32, Word64)
118128
import GHC.Stack (HasCallStack)
119129
import Lens.Micro
@@ -611,3 +621,38 @@ wireSizeTxF =
611621
then fromIntegral n
612622
else error $ "Impossible: Size of the transaction is too big: " ++ show n
613623
{-# INLINEABLE wireSizeTxF #-}
624+
625+
-- | Translate a transaction through its binary representation from previous to current era.
626+
binaryUpgradeTx ::
627+
forall era.
628+
(Era era, ToCBOR (Tx (PreviousEra era)), DecCBOR (Annotator (Tx era))) =>
629+
Tx (PreviousEra era) ->
630+
Except DecoderError (Tx era)
631+
binaryUpgradeTx = translateViaCBORAnnotator (eraProtVerLow @era) (withEraName @era "Tx")
632+
633+
-- | Translate a tx body through its binary representation from previous to current era.
634+
binaryUpgradeTxBody ::
635+
forall era.
636+
(Era era, ToCBOR (TxBody (PreviousEra era)), DecCBOR (Annotator (TxBody era))) =>
637+
TxBody (PreviousEra era) ->
638+
Except DecoderError (TxBody era)
639+
binaryUpgradeTxBody = translateViaCBORAnnotator (eraProtVerLow @era) (withEraName @era "TxBody")
640+
641+
-- | Translate tx witnesses through its binary representation from previous to current era.
642+
binaryUpgradeTxWits ::
643+
forall era.
644+
(Era era, ToCBOR (TxWits (PreviousEra era)), DecCBOR (Annotator (TxWits era))) =>
645+
TxWits (PreviousEra era) ->
646+
Except DecoderError (TxWits era)
647+
binaryUpgradeTxWits = translateViaCBORAnnotator (eraProtVerLow @era) (withEraName @era "TxWits")
648+
649+
-- | Translate tx auxData through its binary representation from previous to current era.
650+
binaryUpgradeTxAuxData ::
651+
forall era.
652+
(Era era, ToCBOR (TxAuxData (PreviousEra era)), DecCBOR (Annotator (TxAuxData era))) =>
653+
TxAuxData (PreviousEra era) ->
654+
Except DecoderError (TxAuxData era)
655+
binaryUpgradeTxAuxData = translateViaCBORAnnotator (eraProtVerLow @era) (withEraName @era "TxAuxData")
656+
657+
withEraName :: forall era. Era era => Text -> Text
658+
withEraName t = t <> " " <> T.pack (eraName @era) <> "Era"

0 commit comments

Comments
 (0)