{-# LANGUAGE DataKinds #-}
{-# LANGUAGE RankNTypes #-}

-- | Define Lenses that facilitate accessing the types in the Var Model.
--   Note the types in the Model, are often wrapped in a newtype in the real state,
--   or they are embedded in something like UMap to save space. So we need interesting
--   Lenses to make this possible.
--   Many other (more standard) Lenses are defined in Cardano.Ledger.Shelley.LedgerState
module Test.Cardano.Ledger.Constrained.Lenses where

import Cardano.Ledger.BaseTypes (SlotNo)
import Cardano.Ledger.Coin (Coin (..), CompactForm, DeltaCoin)
import Cardano.Ledger.Compactible (Compactible (fromCompact))
import Cardano.Ledger.Credential (Credential, Ptr)
import Cardano.Ledger.DRep (DRep)
import Cardano.Ledger.Keys (GenDelegPair (..), GenDelegs (..), KeyHash, KeyRole (..))
import Cardano.Ledger.Shelley.LedgerState hiding (deltaReserves, deltaTreasury, rewards)
import qualified Cardano.Ledger.Shelley.LedgerState as LS (deltaReserves, deltaTreasury)
import Cardano.Ledger.Shelley.PoolRank (Likelihood (..), LogWeight (..), NonMyopic (..))
import Cardano.Ledger.TxIn (TxIn (..))
import Cardano.Ledger.UMap (
  RDPair (..),
  UMap (..),
  compactCoinOrError,
  dRepMap,
  depositMap,
  invPtrMap,
  rewardMap,
  sPoolMap,
  unify,
 )
import qualified Cardano.Ledger.UMap as UM
import Cardano.Ledger.UTxO (UTxO (..))
import Data.Foldable (Foldable (..))
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.Maybe.Strict (StrictMaybe (..))
import Data.Sequence.Strict (StrictSeq, fromList)
import Data.Set (Set)
import Lens.Micro
import Test.Cardano.Ledger.Constrained.Classes (TxOutF (..), liftUTxO)
import Test.Cardano.Ledger.Generic.Proof (Proof)

-- ====================================================
-- Lenses
{- A lens for a record field name 'mm'  looks like this.
   Of course the types will change. This example makes a lens
   for an Int field inside of NewEpoch state

mmL :: Lens' (NewEpochState era) Int
mmL = lens mm (\ds u -> ds { mm = u })

-}

-- ===================================
-- InstantaneousRewards

iRReservesL :: Lens' InstantaneousRewards (Map (Credential 'Staking) Coin)
iRReservesL :: Lens' InstantaneousRewards (Map (Credential 'Staking) Coin)
iRReservesL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens InstantaneousRewards -> Map (Credential 'Staking) Coin
iRReserves (\InstantaneousRewards
ds Map (Credential 'Staking) Coin
u -> InstantaneousRewards
ds {iRReserves :: Map (Credential 'Staking) Coin
iRReserves = Map (Credential 'Staking) Coin
u})

iRTreasuryL :: Lens' InstantaneousRewards (Map (Credential 'Staking) Coin)
iRTreasuryL :: Lens' InstantaneousRewards (Map (Credential 'Staking) Coin)
iRTreasuryL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens InstantaneousRewards -> Map (Credential 'Staking) Coin
iRTreasury (\InstantaneousRewards
ds Map (Credential 'Staking) Coin
u -> InstantaneousRewards
ds {iRTreasury :: Map (Credential 'Staking) Coin
iRTreasury = Map (Credential 'Staking) Coin
u})

deltaReservesL :: Lens' InstantaneousRewards DeltaCoin
deltaReservesL :: Lens' InstantaneousRewards DeltaCoin
deltaReservesL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens InstantaneousRewards -> DeltaCoin
LS.deltaReserves (\InstantaneousRewards
ds DeltaCoin
u -> InstantaneousRewards
ds {deltaReserves :: DeltaCoin
LS.deltaReserves = DeltaCoin
u})

deltaTreasuryL :: Lens' InstantaneousRewards DeltaCoin
deltaTreasuryL :: Lens' InstantaneousRewards DeltaCoin
deltaTreasuryL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens InstantaneousRewards -> DeltaCoin
LS.deltaTreasury (\InstantaneousRewards
ds DeltaCoin
u -> InstantaneousRewards
ds {deltaTreasury :: DeltaCoin
LS.deltaTreasury = DeltaCoin
u})

unGenDelegsL :: Lens' GenDelegs (Map (KeyHash 'Genesis) GenDelegPair)
unGenDelegsL :: Lens' GenDelegs (Map (KeyHash 'Genesis) GenDelegPair)
unGenDelegsL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens GenDelegs -> Map (KeyHash 'Genesis) GenDelegPair
unGenDelegs (\(GenDelegs Map (KeyHash 'Genesis) GenDelegPair
_) Map (KeyHash 'Genesis) GenDelegPair
new -> Map (KeyHash 'Genesis) GenDelegPair -> GenDelegs
GenDelegs Map (KeyHash 'Genesis) GenDelegPair
new)

-- Lenses for (FutureGenDeleg c)
fGenDelegSlotL :: Lens' FutureGenDeleg SlotNo
fGenDelegSlotL :: Lens' FutureGenDeleg SlotNo
fGenDelegSlotL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens FutureGenDeleg -> SlotNo
fGenDelegSlot (\FutureGenDeleg
ds SlotNo
u -> FutureGenDeleg
ds {fGenDelegSlot :: SlotNo
fGenDelegSlot = SlotNo
u})

fGenDelegGenKeyHashL :: Lens' FutureGenDeleg (KeyHash 'Genesis)
fGenDelegGenKeyHashL :: Lens' FutureGenDeleg (KeyHash 'Genesis)
fGenDelegGenKeyHashL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens FutureGenDeleg -> KeyHash 'Genesis
fGenDelegGenKeyHash (\FutureGenDeleg
ds KeyHash 'Genesis
u -> FutureGenDeleg
ds {fGenDelegGenKeyHash :: KeyHash 'Genesis
fGenDelegGenKeyHash = KeyHash 'Genesis
u})

-- IncrementalStake

isCredMapL :: Lens' IncrementalStake (Map (Credential 'Staking) Coin)
isCredMapL :: Lens' IncrementalStake (Map (Credential 'Staking) Coin)
isCredMapL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Compactible a => CompactForm a -> a
fromCompact forall b c a. (b -> c) -> (a -> b) -> a -> c
. IncrementalStake -> Map (Credential 'Staking) (CompactForm Coin)
credMap) (\IncrementalStake
ds Map (Credential 'Staking) Coin
u -> IncrementalStake
ds {credMap :: Map (Credential 'Staking) (CompactForm Coin)
credMap = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap HasCallStack => Coin -> CompactForm Coin
compactCoinOrError Map (Credential 'Staking) Coin
u})

isPtrMapL :: Lens' IncrementalStake (Map Ptr Coin)
isPtrMapL :: Lens' IncrementalStake (Map Ptr Coin)
isPtrMapL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Compactible a => CompactForm a -> a
fromCompact forall b c a. (b -> c) -> (a -> b) -> a -> c
. IncrementalStake -> Map Ptr (CompactForm Coin)
ptrMap) (\IncrementalStake
ds Map Ptr Coin
u -> IncrementalStake
ds {ptrMap :: Map Ptr (CompactForm Coin)
ptrMap = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap HasCallStack => Coin -> CompactForm Coin
compactCoinOrError Map Ptr Coin
u})

-- ===============================================
-- NonMyopic

nmLikelihoodsL :: Lens' NonMyopic (Map (KeyHash 'StakePool) [Float])
nmLikelihoodsL :: Lens' NonMyopic (Map (KeyHash 'StakePool) [Float])
nmLikelihoodsL =
  forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens
    (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Likelihood -> [Float]
fromLikelihood forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonMyopic -> Map (KeyHash 'StakePool) Likelihood
likelihoodsNM)
    (\NonMyopic
ds Map (KeyHash 'StakePool) [Float]
u -> NonMyopic
ds {likelihoodsNM :: Map (KeyHash 'StakePool) Likelihood
likelihoodsNM = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Float] -> Likelihood
toLikelihood Map (KeyHash 'StakePool) [Float]
u})
  where
    fromLikelihood :: Likelihood -> [Float]
fromLikelihood (Likelihood StrictSeq LogWeight
ls) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap LogWeight -> Float
unLogWeight forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => t a -> [a]
toList StrictSeq LogWeight
ls
    toLikelihood :: [Float] -> Likelihood
toLikelihood = StrictSeq LogWeight -> Likelihood
Likelihood forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [a] -> StrictSeq a
fromList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Float -> LogWeight
LogWeight

nmRewardPotL :: Lens' NonMyopic Coin
nmRewardPotL :: Lens' NonMyopic Coin
nmRewardPotL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens NonMyopic -> Coin
rewardPotNM (\NonMyopic
ds Coin
u -> NonMyopic
ds {rewardPotNM :: Coin
rewardPotNM = Coin
u})

-- ======================================================
-- (Virtual) UMap

spRewL :: Lens' Split (Map (Credential 'Staking) Coin)
spRewL :: Lens' Split (Map (Credential 'Staking) Coin)
spRewL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens Split -> Map (Credential 'Staking) Coin
spRew (\Split
ds Map (Credential 'Staking) Coin
u -> Split
ds {spRew :: Map (Credential 'Staking) Coin
spRew = Map (Credential 'Staking) Coin
u})

spDepL :: Lens' Split (Map (Credential 'Staking) Coin)
spDepL :: Lens' Split (Map (Credential 'Staking) Coin)
spDepL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens Split -> Map (Credential 'Staking) Coin
spDep (\Split
ds Map (Credential 'Staking) Coin
u -> Split
ds {spDep :: Map (Credential 'Staking) Coin
spDep = Map (Credential 'Staking) Coin
u})

spDelL :: Lens' Split (Map (Credential 'Staking) (KeyHash 'StakePool))
spDelL :: Lens' Split (Map (Credential 'Staking) (KeyHash 'StakePool))
spDelL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens Split -> Map (Credential 'Staking) (KeyHash 'StakePool)
spDel (\Split
ds Map (Credential 'Staking) (KeyHash 'StakePool)
u -> Split
ds {spDel :: Map (Credential 'Staking) (KeyHash 'StakePool)
spDel = Map (Credential 'Staking) (KeyHash 'StakePool)
u})

spRevPtrL :: Lens' Split (Map (Credential 'Staking) (Set Ptr))
spRevPtrL :: Lens' Split (Map (Credential 'Staking) (Set Ptr))
spRevPtrL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens Split -> Map (Credential 'Staking) (Set Ptr)
spRevPtr (\Split
ds Map (Credential 'Staking) (Set Ptr)
u -> Split
ds {spRevPtr :: Map (Credential 'Staking) (Set Ptr)
spRevPtr = Map (Credential 'Staking) (Set Ptr)
u})

spPtrL :: Lens' Split (Map Ptr (Credential 'Staking))
spPtrL :: Lens' Split (Map Ptr (Credential 'Staking))
spPtrL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens Split -> Map Ptr (Credential 'Staking)
spPtr (\Split
ds Map Ptr (Credential 'Staking)
u -> Split
ds {spPtr :: Map Ptr (Credential 'Staking)
spPtr = Map Ptr (Credential 'Staking)
u})

spDRepL :: Lens' Split (Map (Credential 'Staking) DRep)
spDRepL :: Lens' Split (Map (Credential 'Staking) DRep)
spDRepL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens Split -> Map (Credential 'Staking) DRep
spDRep (\Split
ds Map (Credential 'Staking) DRep
u -> Split
ds {spDRep :: Map (Credential 'Staking) DRep
spDRep = Map (Credential 'Staking) DRep
u})

-- ========================================================================================
-- Mapping the abstract names: rewards, delegations, ptrs, credDeposits through the UMap

-- | Abstract view of the UMap
data Split = Split
  { Split -> Map (Credential 'Staking) Coin
spRew :: Map (Credential 'Staking) Coin
  , Split -> Map (Credential 'Staking) Coin
spDep :: Map (Credential 'Staking) Coin
  , Split -> Map (Credential 'Staking) (KeyHash 'StakePool)
spDel :: Map (Credential 'Staking) (KeyHash 'StakePool)
  , Split -> Map (Credential 'Staking) DRep
spDRep :: Map (Credential 'Staking) DRep
  , Split -> Map (Credential 'Staking) (Set Ptr)
spRevPtr :: Map (Credential 'Staking) (Set Ptr)
  , Split -> Map Ptr (Credential 'Staking)
spPtr :: Map Ptr (Credential 'Staking)
  }

-- | The abstraction function, from concrete (UMap) to abstract (Split)
splitUMap :: UMap -> Split
splitUMap :: UMap -> Split
splitUMap UMap
um =
  Map (Credential 'Staking) Coin
-> Map (Credential 'Staking) Coin
-> Map (Credential 'Staking) (KeyHash 'StakePool)
-> Map (Credential 'Staking) DRep
-> Map (Credential 'Staking) (Set Ptr)
-> Map Ptr (Credential 'Staking)
-> Split
Split (UMap -> Map (Credential 'Staking) Coin
rewardMap UMap
um) (UMap -> Map (Credential 'Staking) Coin
depositMap UMap
um) (UMap -> Map (Credential 'Staking) (KeyHash 'StakePool)
sPoolMap UMap
um) (UMap -> Map (Credential 'Staking) DRep
dRepMap UMap
um) (UMap -> Map (Credential 'Staking) (Set Ptr)
invPtrMap UMap
um) (UMap -> Map Ptr (Credential 'Staking)
UM.ptrMap UMap
um)

-- | The concretization function from abstract (Split) to concrete (UMap)
unSplitUMap :: Split -> UMap
unSplitUMap :: Split -> UMap
unSplitUMap (Split Map (Credential 'Staking) Coin
rew Map (Credential 'Staking) Coin
dep Map (Credential 'Staking) (KeyHash 'StakePool)
deleg Map (Credential 'Staking) DRep
drep Map (Credential 'Staking) (Set Ptr)
_revptr Map Ptr (Credential 'Staking)
ptr) = Map (Credential 'Staking) RDPair
-> Map Ptr (Credential 'Staking)
-> Map (Credential 'Staking) (KeyHash 'StakePool)
-> Map (Credential 'Staking) DRep
-> UMap
unify (forall {k}. Ord k => Map k Coin -> Map k Coin -> Map k RDPair
merge Map (Credential 'Staking) Coin
rew Map (Credential 'Staking) Coin
dep) Map Ptr (Credential 'Staking)
ptr Map (Credential 'Staking) (KeyHash 'StakePool)
deleg Map (Credential 'Staking) DRep
drep
  where
    merge :: Map k Coin -> Map k Coin -> Map k RDPair
merge Map k Coin
x Map k Coin
y | forall k a. Map k a -> Set k
Map.keysSet Map k Coin
x forall a. Eq a => a -> a -> Bool
/= forall k a. Map k a -> Set k
Map.keysSet Map k Coin
y = forall a. HasCallStack => [Char] -> a
error [Char]
"different domains"
    merge Map k Coin
x Map k Coin
y = forall k a b c.
Ord k =>
(a -> b -> c) -> Map k a -> Map k b -> Map k c
Map.intersectionWith Coin -> Coin -> RDPair
rdpair Map k Coin
x Map k Coin
y
    rdpair :: Coin -> Coin -> RDPair
rdpair Coin
x Coin
y = CompactForm Coin -> CompactForm Coin -> RDPair
RDPair (HasCallStack => Coin -> CompactForm Coin
compactCoinOrError Coin
x) (HasCallStack => Coin -> CompactForm Coin
compactCoinOrError Coin
y)

-- Lenses that reach through the concrete  (UMap) using abstract inputs

rewardsUMapL :: Lens' UMap (Map (Credential 'Staking) Coin)
rewardsUMapL :: Lens' UMap (Map (Credential 'Staking) Coin)
rewardsUMapL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens UMap -> Map (Credential 'Staking) Coin
rewardMap UMap -> Map (Credential 'Staking) Coin -> UMap
delta
  where
    delta :: UMap -> Map (Credential 'Staking) Coin -> UMap
delta UMap
um Map (Credential 'Staking) Coin
new = Split -> UMap
unSplitUMap (Split
split {spRew :: Map (Credential 'Staking) Coin
spRew = Map (Credential 'Staking) Coin
new})
      where
        split :: Split
split = UMap -> Split
splitUMap UMap
um

stakeDepositsUMapL :: Lens' UMap (Map (Credential 'Staking) Coin)
stakeDepositsUMapL :: Lens' UMap (Map (Credential 'Staking) Coin)
stakeDepositsUMapL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens UMap -> Map (Credential 'Staking) Coin
depositMap UMap -> Map (Credential 'Staking) Coin -> UMap
delta
  where
    delta :: UMap -> Map (Credential 'Staking) Coin -> UMap
delta UMap
um Map (Credential 'Staking) Coin
new = Split -> UMap
unSplitUMap (Split
split {spDep :: Map (Credential 'Staking) Coin
spDep = Map (Credential 'Staking) Coin
new})
      where
        split :: Split
split = UMap -> Split
splitUMap UMap
um

ptrsUMapL :: Lens' UMap (Map Ptr (Credential 'Staking))
ptrsUMapL :: Lens' UMap (Map Ptr (Credential 'Staking))
ptrsUMapL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens UMap -> Map Ptr (Credential 'Staking)
UM.ptrMap (\(UMap Map (Credential 'Staking) UMElem
x Map Ptr (Credential 'Staking)
_) Map Ptr (Credential 'Staking)
p -> Map (Credential 'Staking) UMElem
-> Map Ptr (Credential 'Staking) -> UMap
UMap Map (Credential 'Staking) UMElem
x Map Ptr (Credential 'Staking)
p)

delegationsUMapL :: Lens' UMap (Map (Credential 'Staking) (KeyHash 'StakePool))
delegationsUMapL :: Lens' UMap (Map (Credential 'Staking) (KeyHash 'StakePool))
delegationsUMapL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens UMap -> Map (Credential 'Staking) (KeyHash 'StakePool)
sPoolMap UMap -> Map (Credential 'Staking) (KeyHash 'StakePool) -> UMap
delta
  where
    delta :: UMap -> Map (Credential 'Staking) (KeyHash 'StakePool) -> UMap
delta UMap
um Map (Credential 'Staking) (KeyHash 'StakePool)
new = Split -> UMap
unSplitUMap (Split
split {spDel :: Map (Credential 'Staking) (KeyHash 'StakePool)
spDel = Map (Credential 'Staking) (KeyHash 'StakePool)
new})
      where
        split :: Split
split = UMap -> Split
splitUMap UMap
um

drepUMapL :: Lens' UMap (Map (Credential 'Staking) DRep)
drepUMapL :: Lens' UMap (Map (Credential 'Staking) DRep)
drepUMapL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens UMap -> Map (Credential 'Staking) DRep
dRepMap UMap -> Map (Credential 'Staking) DRep -> UMap
delta
  where
    delta :: UMap -> Map (Credential 'Staking) DRep -> UMap
delta UMap
um Map (Credential 'Staking) DRep
new = Split -> UMap
unSplitUMap ((UMap -> Split
splitUMap UMap
um) {spDRep :: Map (Credential 'Staking) DRep
spDRep = Map (Credential 'Staking) DRep
new})

-- Conversion Lenses

strictMaybeToMaybeL :: Lens' (StrictMaybe x) (Maybe x)
strictMaybeToMaybeL :: forall x. Lens' (StrictMaybe x) (Maybe x)
strictMaybeToMaybeL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens forall {a}. StrictMaybe a -> Maybe a
ff forall {p} {a}. p -> Maybe a -> StrictMaybe a
gg
  where
    ff :: StrictMaybe a -> Maybe a
ff (SJust a
x) = forall a. a -> Maybe a
Just a
x
    ff StrictMaybe a
SNothing = forall a. Maybe a
Nothing
    gg :: p -> Maybe a -> StrictMaybe a
gg p
_ (Just a
x) = forall a. a -> StrictMaybe a
SJust a
x
    gg p
_ Maybe a
Nothing = forall a. StrictMaybe a
SNothing

idLens :: Lens' a a
idLens :: forall a. Lens' a a
idLens = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens (\a
x -> a
x) (\a
_ a
y -> a
y)

strictSeqListL :: Lens' (StrictSeq a) [a]
strictSeqListL :: forall a. Lens' (StrictSeq a) [a]
strictSeqListL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (\StrictSeq a
_ [a]
y -> forall a. [a] -> StrictSeq a
fromList [a]
y)

mapCompactFormCoinL :: Lens' (Map a (CompactForm Coin)) (Map a Coin)
mapCompactFormCoinL :: forall a. Lens' (Map a (CompactForm Coin)) (Map a Coin)
mapCompactFormCoinL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens (forall a b k. (a -> b) -> Map k a -> Map k b
Map.map forall a. Compactible a => CompactForm a -> a
fromCompact) (\Map a (CompactForm Coin)
_ Map a Coin
y -> forall a b k. (a -> b) -> Map k a -> Map k b
Map.map HasCallStack => Coin -> CompactForm Coin
compactCoinOrError Map a Coin
y)

pairL :: Lens' x y -> Lens' a b -> Lens' (x, a) (y, b)
pairL :: forall x y a b. Lens' x y -> Lens' a b -> Lens' (x, a) (y, b)
pairL Lens' x y
xy Lens' a b
ab = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens (x, a) -> (y, b)
getter (x, a) -> (y, b) -> (x, a)
setter
  where
    getter :: (x, a) -> (y, b)
getter (x
x, a
a) = (x
x forall s a. s -> Getting a s a -> a
^. Lens' x y
xy, a
a forall s a. s -> Getting a s a -> a
^. Lens' a b
ab)
    setter :: (x, a) -> (y, b) -> (x, a)
setter (x
x, a
a) (y
y, b
b) = (x
x forall a b. a -> (a -> b) -> b
& Lens' x y
xy forall s t a b. ASetter s t a b -> b -> s -> t
.~ y
y, a
a forall a b. a -> (a -> b) -> b
& Lens' a b
ab forall s t a b. ASetter s t a b -> b -> s -> t
.~ b
b)

-- | Lens to convert from the abstract type UtxO type of the Model, to the concrete UTxO type.
--   The mode uses the type family abstraction TxOutF, and does not wrap the map
--   with the UtxO constructor. Note the getter is 'liftUTxO' from Test.Cardano.Ledger.Constrained.Classes
--   liftUTxO :: Map (TxIn ) (TxOutF era) -> UTxO era
utxoFL :: Proof era -> Lens' (Map TxIn (TxOutF era)) (UTxO era)
utxoFL :: forall era. Proof era -> Lens' (Map TxIn (TxOutF era)) (UTxO era)
utxoFL Proof era
p = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens forall era. Map TxIn (TxOutF era) -> UTxO era
liftUTxO (\Map TxIn (TxOutF era)
_ (UTxO Map TxIn (TxOut era)
new) -> (forall a b k. (a -> b) -> Map k a -> Map k b
Map.map (forall era. Proof era -> TxOut era -> TxOutF era
TxOutF Proof era
p) Map TxIn (TxOut era)
new))

-- ======================================================================
-- Don't tell me that these have impementations in Lens.Micro( _1, _2 )
-- The problem with this, is that it needs special pragmas to work, and without
-- these pragmas, causes ghci to hang.
-- In addition there is NO documentation (only examples in Lens.Micro)
-- and who remembers this any way?
-- Way easier to remember these because they use the Cardano.Ledger Lens naming conventions

fstL :: Lens' (a, b) a
fstL :: forall a b. Lens' (a, b) a
fstL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens forall a b. (a, b) -> a
fst (\(a
_, b
b) a
a -> (a
a, b
b))

sndL :: Lens' (a, b) b
sndL :: forall a b. Lens' (a, b) b
sndL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens forall a b. (a, b) -> b
snd (\(a
a, b
_) b
b -> (a
a, b
b))