Skip to content

Commit 9ced91e

Browse files
committed
Deprecate wallet query functions.
Api.State.Query sub-modules are the place for all ledger-state queries.
1 parent 0b2a841 commit 9ced91e

3 files changed

Lines changed: 57 additions & 7 deletions

File tree

eras/shelley/impl/CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

33
## 1.19.0.0
44

5+
* Export `currentSnapshot` from `Shelley.API.Wallet`.
6+
* Deprecate `Shelley.API.Wallet` query functions in favour of `Cardano.Ledger.Api.State.Query` sub-modules:
7+
- `getUTxO`
8+
- `getFilteredUTxO`
9+
- `getUTxOSubset`
10+
- `getPools`
11+
- `getStakePools`
12+
- `poolsByTotalStakeFraction`
13+
- `getTotalStake`
14+
- `getNonMyopicMemberRewards`
15+
- `currentSnapshot`
16+
- `getRewardInfoPools`
17+
- `getRewardProvenance`.
518
* Add `Ord` instance for `RewardInfoPool` and `RewardParams`.
619
* Add `Shelley.API.Forecast` and `Shelley.Forecast`:
720
- Add `EraForecast` and `ShelleyEraForecast` typeclasses to deprecate `GetLedgerView` from `cardano-ledger-tpraos`.

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

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ module Cardano.Ledger.Shelley.API.Wallet (
3737
totalAdaES,
3838
totalAdaPotsES,
3939
getStakePools,
40+
41+
-- * Snapshots
42+
currentSnapshot,
4043
) where
4144

4245
import Cardano.Ledger.Address (compactAddr)
@@ -122,6 +125,10 @@ getUTxO ::
122125
NewEpochState era ->
123126
UTxO era
124127
getUTxO = utxosUtxo . lsUTxOState . esLState . nesEs
128+
{-# DEPRECATED
129+
getUTxO
130+
"Use queryUTxOFull from Cardano.Ledger.Api.State.Query.UTxO instead."
131+
#-}
125132

126133
-- | Get the UTxO filtered by address.
127134
getFilteredUTxO ::
@@ -139,12 +146,20 @@ getFilteredUTxO ss addrSet =
139146
Left addr -> addr `Set.member` addrSet
140147
Right cAddr -> cAddr `Set.member` compactAddrSet
141148
{-# INLINEABLE getFilteredUTxO #-}
149+
{-# DEPRECATED
150+
getFilteredUTxO
151+
"Use queryUTxOByAddress from Cardano.Ledger.Api.State.Query.UTxO instead."
152+
#-}
142153

143154
getUTxOSubset ::
144155
NewEpochState era ->
145156
Set TxIn ->
146157
UTxO era
147158
getUTxOSubset nes = txInsFilter (getUTxO nes)
159+
{-# DEPRECATED
160+
getUTxOSubset
161+
"Use queryUTxOByTxIn from Cardano.Ledger.Api.State.Query.UTxO instead."
162+
#-}
148163

149164
--------------------------------------------------------------------------------
150165
-- Stake pools and pool rewards
@@ -158,6 +173,10 @@ getPools ::
158173
getPools = Map.keysSet . f
159174
where
160175
f nes = nes ^. nesEsL . esLStateL . lsCertStateL . certPStateL . psStakePoolsL
176+
{-# DEPRECATED
177+
getPools
178+
"Use queryStakePools from Cardano.Ledger.Api.State.Query.Pool instead."
179+
#-}
161180

162181
-- | Get the /current/ registered stake pool state for a given set of
163182
-- stake pools. The result map will contain entries for all the given stake
@@ -170,6 +189,10 @@ getStakePools ::
170189
getStakePools = Map.restrictKeys . f
171190
where
172191
f nes = nes ^. nesEsL . esLStateL . lsCertStateL . certPStateL . psStakePoolsL
192+
{-# DEPRECATED
193+
getStakePools
194+
"Use queryPoolState or queryStakePoolParams from Cardano.Ledger.Api.State.Query.Pool instead."
195+
#-}
173196

174197
-- | Get pool sizes, but in terms of total stake
175198
--
@@ -200,13 +223,21 @@ poolsByTotalStakeFraction globals nes =
200223
IndividualPoolStake
201224
toTotalStakeFrac (IndividualPoolStake s c vrf) =
202225
IndividualPoolStake (s * stakeRatio) c vrf
226+
{-# DEPRECATED
227+
poolsByTotalStakeFraction
228+
"Use queryStakePoolDistrByTotalSupply from Cardano.Ledger.Api.State.Query.Pool instead"
229+
#-}
203230

204231
-- | Calculate the current total stake.
205232
getTotalStake :: Globals -> NewEpochState era -> Coin
206233
getTotalStake globals ss =
207234
let supply = Coin . fromIntegral $ maxLovelaceSupply globals
208235
es = nesEs ss
209236
in circulation es supply
237+
{-# DEPRECATED
238+
getTotalStake
239+
"Use 'circulation' from Cardano.Ledger.Shelley.LedgerState instead."
240+
#-}
210241

211242
-- | Calculate the Non-Myopic Pool Member Rewards for a set of credentials.
212243
-- For each given credential, this function returns a map from each stake
@@ -252,6 +283,10 @@ getNonMyopicMemberRewards globals ss = Map.fromSet nmmRewards
252283
getTopRankedPools rPot totalStakeCoin pp $
253284
Map.intersectionWith (,) (VMap.toMap (VMap.map percentile' ls)) $
254285
VMap.toMap stakePoolsSnapShot
286+
{-# DEPRECATED
287+
getNonMyopicMemberRewards
288+
"Use queryNonMyopicMemberRewards from Cardano.Ledger.Api.State.Query.Reward instead"
289+
#-}
255290

256291
-- | Create a current snapshot of the ledger state.
257292
--
@@ -266,6 +301,10 @@ currentSnapshot nes =
266301
instantStake = ledgerState ^. instantStakeG
267302
dstate = ledgerState ^. lsCertStateL . certDStateL
268303
pstate = ledgerState ^. lsCertStateL . certPStateL
304+
{-# DEPRECATED
305+
currentSnapshot
306+
"Use queryCurrentSnapshot from Cardano.Ledger.Api.State.Query.Snapshot instead."
307+
#-}
269308

270309
-- | Information about a stake pool
271310
data RewardInfoPool = RewardInfoPool
@@ -359,17 +398,14 @@ getRewardInfoPools globals nes =
359398
, performanceEstimate =
360399
unPerformanceEstimate $ percentile' $ histLookup poolId
361400
}
401+
{-# DEPRECATED getRewardInfoPools "Use queryRewardInfoPools from Cardano.Ledger.Api.State.Query.Reward instead" #-}
362402

363403
-- | Calculate stake pool rewards from the snapshot labeled `go`.
364404
-- Also includes information on how the rewards were calculated
365405
-- ('RewardProvenance').
366406
--
367407
-- For a calculation of rewards based on the current stake distribution,
368408
-- see 'getRewardInfoPools'.
369-
--
370-
-- TODO: Deprecate 'getRewardProvenance', because wallets are more
371-
-- likely to use 'getRewardInfoPools' for up-to-date information
372-
-- on stake pool rewards.
373409
getRewardProvenance ::
374410
forall era.
375411
(EraGov era, EraCertState era) =>
@@ -391,6 +427,7 @@ getRewardProvenance globals newEpochState =
391427
slotsPerEpoch = epochInfoSize (epochInfoPure globals) epochNo
392428
asc = activeSlotCoeff globals
393429
secparam = securityParameter globals
430+
{-# DEPRECATED getRewardProvenance "Use queryRewardProvenance from Cardano.Ledger.Api.State.Query.Reward instead" #-}
394431

395432
--------------------------------------------------------------------------------
396433
-- Transaction helpers

libs/ledger-state/bench/Performance.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module Main where
99

1010
import Cardano.Ledger.Address
1111
import Cardano.Ledger.Api.Era
12+
import Cardano.Ledger.Api.State.Query (queryUTxOByAddress, queryUTxOFull)
1213
import Cardano.Ledger.BaseTypes
1314
import Cardano.Ledger.Binary
1415
import Cardano.Ledger.Conway
@@ -18,7 +19,6 @@ import Cardano.Ledger.Conway.Rules (
1819
)
1920
import Cardano.Ledger.Core
2021
import Cardano.Ledger.Shelley.API.Mempool
21-
import Cardano.Ledger.Shelley.API.Wallet (getFilteredUTxO, getUTxO)
2222
import Cardano.Ledger.Shelley.Genesis (
2323
ShelleyGenesis (..),
2424
fromNominalDiffTimeMicro,
@@ -143,7 +143,7 @@ main = do
143143
in bgroup
144144
"MinMaxTxId"
145145
[ env (pure setAddr) $
146-
bench "getFilteredNewUTxO" . nf (getFilteredUTxO newEpochState)
146+
bench "getFilteredNewUTxO" . nf (queryUTxOByAddress newEpochState)
147147
, env (pure setAddr) $
148148
bench "getFilteredOldUTxO" . nf (getFilteredOldUTxO newEpochState)
149149
]
@@ -270,7 +270,7 @@ getFilteredOldUTxO ss addrs =
270270
UTxO $
271271
Map.filter (\txOut -> (txOut ^. compactAddrTxOutL) `Set.member` addrSBSs) fullUTxO
272272
where
273-
UTxO fullUTxO = getUTxO ss
273+
UTxO fullUTxO = queryUTxOFull ss
274274
addrSBSs = Set.map compactAddr addrs
275275

276276
seqTuple :: (a, b) -> (a, b)

0 commit comments

Comments
 (0)