Skip to content

Commit

Permalink
Replace modifyLedgerBody with ledger-api lens
Browse files Browse the repository at this point in the history
  • Loading branch information
Anviking committed Nov 15, 2023
1 parent b70e590 commit c2119bb
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 48 deletions.
45 changes: 0 additions & 45 deletions lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ module Internal.Cardano.Write.Tx
, CardanoApi.ShelleyLedgerEra
, cardanoEraFromRecentEra
, shelleyBasedEraFromRecentEra
, asCardanoApiTx
, fromCardanoApiTx
, toCardanoApiUTxO
, fromCardanoApiUTxO
Expand Down Expand Up @@ -89,7 +88,6 @@ module Internal.Cardano.Write.Tx
, Core.TxBody
, txBody
, outputs
, modifyLedgerBody
, emptyTx
, serializeTx

Expand Down Expand Up @@ -786,56 +784,13 @@ outputs
outputs RecentEraConway = map sizedValue . toList . Conway.ctbOutputs
outputs RecentEraBabbage = map sizedValue . toList . Babbage.btbOutputs

-- NOTE: To reduce the need for the caller to deal with
-- @CardanoApiEra (CardanoApi.ShelleyLedgerEra era) ~ era@, we quantify this
-- function over @cardanoEra@ instead of @era@.
--
-- TODO [ADP-2353] Move to @cardano-api@ related module
modifyLedgerBody
:: forall cardanoEra. IsRecentEra cardanoEra
=> (Core.TxBody (CardanoApi.ShelleyLedgerEra cardanoEra) ->
Core.TxBody (CardanoApi.ShelleyLedgerEra cardanoEra))
-> Core.Tx (CardanoApi.ShelleyLedgerEra cardanoEra)
-> Core.Tx (CardanoApi.ShelleyLedgerEra cardanoEra)
modifyLedgerBody f = asCardanoApiTx @cardanoEra modify
where
modify (CardanoApi.Tx body keyWits) = CardanoApi.Tx body' keyWits
where
body' = case body of
CardanoApi.ByronTxBody {} ->
error "Impossible: ByronTxBody in CardanoApi.ShelleyLedgerEra"
CardanoApi.ShelleyTxBody
shelleyEra
ledgerBody
scripts
scriptData
auxData
validity ->
CardanoApi.ShelleyTxBody
shelleyEra
(f ledgerBody)
scripts
scriptData
auxData
validity

emptyTx :: RecentEra era -> Core.Tx (CardanoApi.ShelleyLedgerEra era)
emptyTx era = withConstraints era $ Core.mkBasicTx Core.mkBasicTxBody

--------------------------------------------------------------------------------
-- Compatibility
--------------------------------------------------------------------------------

asCardanoApiTx
:: forall era. IsRecentEra era
=> (CardanoApi.Tx era -> CardanoApi.Tx era)
-> Core.Tx (CardanoApi.ShelleyLedgerEra era)
-> Core.Tx (CardanoApi.ShelleyLedgerEra era)
asCardanoApiTx f
= fromCardanoApiTx
. f
. toCardanoApiTx

fromCardanoApiTx
:: forall era. IsRecentEra era
=> CardanoApi.Tx era
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ import Internal.Cardano.Write.Tx
, getFeePerByte
, isBelowMinimumCoinForTxOut
, maxScriptExecutionCost
, modifyLedgerBody
, modifyTxOutCoin
, outputs
, toCardanoApiTx
Expand Down Expand Up @@ -657,8 +656,7 @@ assignMinimalAdaQuantitiesToOutputsWithoutAda
-> Tx (CardanoApi.ShelleyLedgerEra era)
assignMinimalAdaQuantitiesToOutputsWithoutAda era pp =
withConstraints era
$ modifyLedgerBody @era
$ over outputsTxBodyL
$ over (bodyTxL . outputsTxBodyL)
$ fmap modifyTxOut
where
modifyTxOut out = flip (modifyTxOutCoin era) out $ \c ->
Expand Down

0 comments on commit c2119bb

Please sign in to comment.