Skip to content

Commit ed6d574

Browse files
authored
Merge pull request #5028 from IntersectMBO/lehins/deprecate-balance
Deprecate `balance` in favor of a better named `sumUTxO`
2 parents c377787 + b97812e commit ed6d574

File tree

23 files changed

+67
-59
lines changed

23 files changed

+67
-59
lines changed

eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Rules/Utxo.hs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,7 @@ import Cardano.Ledger.Rules.ValidationMode (
8989
import Cardano.Ledger.Shelley.LedgerState (UTxOState (utxosUtxo))
9090
import Cardano.Ledger.Shelley.Rules (ShelleyPpupPredFailure, ShelleyUtxoPredFailure, UtxoEnv (..))
9191
import qualified Cardano.Ledger.Shelley.Rules as Shelley
92-
import Cardano.Ledger.State (
93-
EraCertState,
94-
EraUTxO (..),
95-
UTxO (..),
96-
areAllAdaOnly,
97-
coinBalance,
98-
sumAllValue,
99-
)
92+
import Cardano.Ledger.State
10093
import Cardano.Ledger.TxIn (TxIn)
10194
import qualified Cardano.Ledger.Val as Val
10295
import Cardano.Slotting.EpochInfo.API (EpochInfo, epochInfoSlotToUTCTime)
@@ -315,7 +308,7 @@ validateCollateral pp txb utxoCollateral =
315308
failureIf (null utxoCollateral) NoCollateralInputs
316309
]
317310
where
318-
bal = toDeltaCoin $ coinBalance (UTxO utxoCollateral)
311+
bal = toDeltaCoin $ sumAllCoin utxoCollateral
319312

320313
-- > (∀(a,_,_) ∈ range (collateral txb ◁ utxo), a ∈ Addrvkey)
321314
validateScriptsNotPaidUTxO ::

eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Rules/Utxos.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ alonzoEvalScriptsTxInvalid = do
314314
pure $!
315315
utxos
316316
{ utxosUtxo = UTxO utxoKeep
317-
, utxosFees = fees <> coinBalance (UTxO utxoDel)
317+
, utxosFees = fees <> sumAllCoin utxoDel
318318
, utxosInstantStake = deleteInstantStake (UTxO utxoDel) (utxos ^. instantStakeL)
319319
}
320320

eras/alonzo/test-suite/src/Test/Cardano/Ledger/Alonzo/AlonzoEraGen.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ import Cardano.Ledger.Shelley.Scripts
7676
import Cardano.Ledger.State (
7777
EraUTxO (..),
7878
UTxO (..),
79-
coinBalance,
8079
getScriptsNeeded,
80+
sumCoinUTxO,
8181
txInsFilter,
8282
)
8383
import Cardano.Ledger.TxIn (TxIn)
@@ -543,7 +543,7 @@ instance EraGen AlonzoEra where
543543

544544
sumCollateral :: (EraTx era, AlonzoEraTxBody era) => Tx era -> UTxO era -> Coin
545545
sumCollateral tx utxo =
546-
coinBalance $ txInsFilter utxo $ tx ^. bodyTxL . collateralInputsTxBodyL
546+
sumCoinUTxO $ txInsFilter utxo $ tx ^. bodyTxL . collateralInputsTxBodyL
547547

548548
storageCost :: forall era t. (EraPParams era, EncCBOR t) => Integer -> PParams era -> t -> Coin
549549
storageCost extra pp x = (extra + encodedLen @era x) <×> pp ^. ppMinFeeAL

eras/babbage/impl/src/Cardano/Ledger/Babbage/Collateral.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import Cardano.Ledger.Babbage.TxBody (BabbageEraTxBody (..))
1717
import Cardano.Ledger.BaseTypes (TxIx (..), txIxFromIntegral)
1818
import Cardano.Ledger.Coin (DeltaCoin, toDeltaCoin)
1919
import Cardano.Ledger.Core
20-
import Cardano.Ledger.State (UTxO (..), coinBalance)
20+
import Cardano.Ledger.State
2121
import Cardano.Ledger.TxIn (TxIn (..))
2222
import Cardano.Ledger.Val ((<->))
2323
import qualified Data.Map.Strict as Map
@@ -38,7 +38,7 @@ collAdaBalance txBody utxoCollateral = toDeltaCoin $
3838
SNothing -> colbal
3939
SJust txOut -> colbal <-> (txOut ^. coinTxOutL @era)
4040
where
41-
colbal = coinBalance $ UTxO utxoCollateral
41+
colbal = sumAllCoin utxoCollateral
4242

4343
collOuts ::
4444
BabbageEraTxBody era =>

eras/babbage/impl/src/Cardano/Ledger/Babbage/Rules/Utxo.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ import Cardano.Ledger.Rules.ValidationMode (
7171
import Cardano.Ledger.Shelley.LedgerState (UTxOState (utxosUtxo))
7272
import Cardano.Ledger.Shelley.Rules (ShelleyPpupPredFailure, ShelleyUtxoPredFailure, UtxoEnv)
7373
import qualified Cardano.Ledger.Shelley.Rules as Shelley
74-
import Cardano.Ledger.State (EraCertState (..), EraUTxO (..), UTxO (..), areAllAdaOnly, balance)
74+
import Cardano.Ledger.State
7575
import Cardano.Ledger.TxIn (TxIn)
7676
import Cardano.Ledger.Val ((<->))
7777
import qualified Cardano.Ledger.Val as Val (inject, isAdaOnly, pointwise)
@@ -306,7 +306,7 @@ validateCollateralContainsNonADA txBody utxoCollateral =
306306
then retTxOut ^. valueTxOutL
307307
else collateralBalance
308308
-- This is the balance that is provided by the collateral inputs
309-
collateralBalance = balance $ UTxO utxoCollateral
309+
collateralBalance = sumAllValue utxoCollateral
310310
-- This is the total amount that will be spent as collateral. This is where we account
311311
-- for the fact that we can remove Non-Ada assets from collateral inputs, by directing
312312
-- them to the return TxOut.

eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/ImpTest.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1710,7 +1710,7 @@ showConwayTxBalance pp certState utxo tx =
17101710
]
17111711
where
17121712
txBody = tx ^. bodyTxL
1713-
inputs = balance (txInsFilter utxo (txBody ^. inputsTxBodyL))
1713+
inputs = sumUTxO (txInsFilter utxo (txBody ^. inputsTxBodyL))
17141714
refunds =
17151715
getTotalRefundsTxBody
17161716
pp

eras/mary/impl/src/Cardano/Ledger/Mary/UTxO.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import Cardano.Ledger.State (
2828
EraUTxO (..),
2929
ScriptsProvided (..),
3030
UTxO,
31-
balance,
31+
sumUTxO,
3232
txInsFilter,
3333
)
3434
import Cardano.Ledger.Val (inject)
@@ -78,7 +78,7 @@ getConsumedMaryValue pp lookupStakingDeposit lookupDRepDeposit utxo txBody =
7878
mintedMultiAsset = filterMultiAsset (\_ _ -> (> 0)) $ txBody ^. mintTxBodyL
7979
{- balance (txins tx ◁ u) + wbalance (txwdrls tx) + keyRefunds pp tx -}
8080
consumedValue =
81-
balance (txInsFilter utxo (txBody ^. inputsTxBodyL))
81+
sumUTxO (txInsFilter utxo (txBody ^. inputsTxBodyL))
8282
<> inject (refunds <> withdrawals)
8383
refunds = getTotalRefundsTxBody pp lookupStakingDeposit lookupDRepDeposit txBody
8484
withdrawals = fold . unWithdrawals $ txBody ^. withdrawalsTxBodyL

eras/shelley/impl/CHANGELOG.md

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

33
## 1.17.0.0
44

5+
* Replace export from `Cardano.Ledger.Shelley.UTxO` of deprecated `balance` and `coinBalance` with `sumUTxO` and `sumCoinUTxO` respectively
56
* Remove `ShelleyTxBody`
67
* Removed `era` parameter from `ShelleyTxBodyRaw`
78
* Remove `HeapWords` instances for: #5001

eras/shelley/impl/src/Cardano/Ledger/Shelley/API/ByronTranslation.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ translateToShelleyLedgerStateFromUtxo transCtxt epochNo utxoByron =
138138

139139
reserves :: Coin
140140
reserves =
141-
word64ToCoin (fbtcMaxLovelaceSupply transCtxt) <-> coinBalance utxoShelley
141+
word64ToCoin (fbtcMaxLovelaceSupply transCtxt) <-> sumCoinUTxO utxoShelley
142142

143143
epochState :: EpochState ShelleyEra
144144
epochState =

eras/shelley/impl/src/Cardano/Ledger/Shelley/AdaPots.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ totalAdaPotsES (EpochState (ChainAccountState {casTreasury, casReserves}) ls _ _
7171
UTxOState u _ fees_ _ _ _ = lsUTxOState ls
7272
certState = ls ^. lsCertStateL
7373
rewards_ = fromCompact $ sumRewardsUView (rewards $ certState ^. certDStateL)
74-
coins = coinBalance u
74+
coins = sumCoinUTxO u
7575
govStateObligations = obligationGovState (ls ^. lsUTxOStateL . utxosGovStateL)
7676

7777
sumAdaPots :: AdaPots -> Coin
@@ -145,7 +145,7 @@ consumedTxBody ::
145145
consumedTxBody txBody pp dpstate utxo =
146146
Consumed
147147
{ conInputs =
148-
coinBalance (txInsFilter utxo (txBody ^. inputsTxBodyL))
148+
sumCoinUTxO (txInsFilter utxo (txBody ^. inputsTxBodyL))
149149
, conRefunds = certsTotalRefundsTxBody pp dpstate txBody
150150
, conWithdrawals = fold . unWithdrawals $ txBody ^. withdrawalsTxBodyL
151151
}
@@ -159,7 +159,7 @@ producedTxBody ::
159159
Produced
160160
producedTxBody txBody pp dpstate =
161161
Produced
162-
{ proOutputs = coinBalance (txouts txBody)
162+
{ proOutputs = sumCoinUTxO (txouts txBody)
163163
, proFees = txBody ^. feeTxBodyL
164164
, proDeposits = certsTotalDepositsTxBody pp dpstate txBody
165165
}

0 commit comments

Comments
 (0)