{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ViewPatterns #-}
module Cardano.Ledger.UMap (
RDPair (..),
rdRewardCoin,
rdDepositCoin,
UMElem (UMElem),
umElemRDPair,
umElemRDActive,
RewardDelegation (..),
umElemDRepDelegatedReward,
umElemDelegations,
umElemPtrs,
umElemSPool,
umElemDRep,
umElemAsTuple,
nullUMElem,
nullUMElemMaybe,
UMap (..),
umElemsL,
empty,
umInvariant,
StakeCredentials (..),
toStakeCredentials,
domRestrictedStakeCredentials,
UView (..),
rewDepUView,
ptrUView,
sPoolUView,
dRepUView,
unUView,
unUnifyToVMap,
rdPairMap,
rewardMap,
compactRewardMap,
depositMap,
ptrMap,
invPtrMap,
sPoolMap,
dRepMap,
domRestrictedMap,
CompactForm (CompactCoin),
toCompact,
fromCompact,
addCompact,
sumCompactCoin,
sumRewardsUView,
sumDepositUView,
compactCoinOrError,
unify,
unUnify,
nullUView,
member,
member',
notMember,
delete,
delete',
insertWith,
insertWith',
insert,
insert',
adjust,
lookup,
domain,
range,
(∪),
unionL,
(⨃),
unionR,
(∪+),
unionRewAgg,
unionKeyDeposits,
(⋪),
domDelete,
(⋫),
rngDelete,
(◁),
domRestrict,
findWithDefault,
size,
domDeleteAll,
deleteStakingCredential,
extractStakingCredential,
)
where
import Cardano.Ledger.BaseTypes (strictMaybe)
import Cardano.Ledger.Binary
import Cardano.Ledger.Coin (Coin (..), CompactForm (CompactCoin), compactCoinOrError)
import Cardano.Ledger.Compactible (Compactible (..))
import Cardano.Ledger.Credential (Credential (..), Ptr)
import Cardano.Ledger.DRep (DRep)
import Cardano.Ledger.Keys (KeyHash, KeyRole (..))
import Control.DeepSeq (NFData (..))
import Control.Monad.Trans.State.Strict (StateT (..))
import Data.Aeson (ToJSON (..), object, (.=))
import qualified Data.Aeson as Aeson
import Data.Foldable (Foldable (..))
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.MapExtras as MapExtras (extract, intersectDomPLeft)
import Data.Maybe as Maybe (fromMaybe, isNothing, mapMaybe)
import Data.Maybe.Strict (StrictMaybe (..))
import Data.Proxy
import Data.Set (Set)
import qualified Data.Set as Set
import qualified Data.Set.Internal as SI (Set (Tip))
import qualified Data.VMap as VMap
import GHC.Generics (Generic)
import Lens.Micro (Lens', lens)
import NoThunks.Class (NoThunks (..))
import Prelude hiding (lookup, null)
data RDPair = RDPair
{ RDPair -> CompactForm Coin
rdReward :: {-# UNPACK #-} !(CompactForm Coin)
, RDPair -> CompactForm Coin
rdDeposit :: {-# UNPACK #-} !(CompactForm Coin)
}
deriving (Int -> RDPair -> ShowS
[RDPair] -> ShowS
RDPair -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RDPair] -> ShowS
$cshowList :: [RDPair] -> ShowS
show :: RDPair -> String
$cshow :: RDPair -> String
showsPrec :: Int -> RDPair -> ShowS
$cshowsPrec :: Int -> RDPair -> ShowS
Show, RDPair -> RDPair -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RDPair -> RDPair -> Bool
$c/= :: RDPair -> RDPair -> Bool
== :: RDPair -> RDPair -> Bool
$c== :: RDPair -> RDPair -> Bool
Eq, Eq RDPair
RDPair -> RDPair -> Bool
RDPair -> RDPair -> Ordering
RDPair -> RDPair -> RDPair
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: RDPair -> RDPair -> RDPair
$cmin :: RDPair -> RDPair -> RDPair
max :: RDPair -> RDPair -> RDPair
$cmax :: RDPair -> RDPair -> RDPair
>= :: RDPair -> RDPair -> Bool
$c>= :: RDPair -> RDPair -> Bool
> :: RDPair -> RDPair -> Bool
$c> :: RDPair -> RDPair -> Bool
<= :: RDPair -> RDPair -> Bool
$c<= :: RDPair -> RDPair -> Bool
< :: RDPair -> RDPair -> Bool
$c< :: RDPair -> RDPair -> Bool
compare :: RDPair -> RDPair -> Ordering
$ccompare :: RDPair -> RDPair -> Ordering
Ord, forall x. Rep RDPair x -> RDPair
forall x. RDPair -> Rep RDPair x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RDPair x -> RDPair
$cfrom :: forall x. RDPair -> Rep RDPair x
Generic, Context -> RDPair -> IO (Maybe ThunkInfo)
Proxy RDPair -> String
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
showTypeOf :: Proxy RDPair -> String
$cshowTypeOf :: Proxy RDPair -> String
wNoThunks :: Context -> RDPair -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> RDPair -> IO (Maybe ThunkInfo)
noThunks :: Context -> RDPair -> IO (Maybe ThunkInfo)
$cnoThunks :: Context -> RDPair -> IO (Maybe ThunkInfo)
NoThunks, RDPair -> ()
forall a. (a -> ()) -> NFData a
rnf :: RDPair -> ()
$crnf :: RDPair -> ()
NFData)
rdRewardCoin :: RDPair -> Coin
rdRewardCoin :: RDPair -> Coin
rdRewardCoin RDPair
rdp = forall a. Compactible a => CompactForm a -> a
fromCompact (RDPair -> CompactForm Coin
rdReward RDPair
rdp)
rdDepositCoin :: RDPair -> Coin
rdDepositCoin :: RDPair -> Coin
rdDepositCoin RDPair
rdp = forall a. Compactible a => CompactForm a -> a
fromCompact (RDPair -> CompactForm Coin
rdDeposit RDPair
rdp)
instance EncCBOR RDPair where
encCBOR :: RDPair -> Encoding
encCBOR RDPair {CompactForm Coin
rdReward :: CompactForm Coin
rdReward :: RDPair -> CompactForm Coin
rdReward, CompactForm Coin
rdDeposit :: CompactForm Coin
rdDeposit :: RDPair -> CompactForm Coin
rdDeposit} =
Word -> Encoding
encodeListLen Word
2 forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR CompactForm Coin
rdReward forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR CompactForm Coin
rdDeposit
instance DecCBOR RDPair where
decCBOR :: forall s. Decoder s RDPair
decCBOR =
forall a s. Text -> (a -> Int) -> Decoder s a -> Decoder s a
decodeRecordNamed Text
"RDPair" (forall a b. a -> b -> a
const Int
2) forall a b. (a -> b) -> a -> b
$ CompactForm Coin -> CompactForm Coin -> RDPair
RDPair forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a s. DecCBOR a => Decoder s a
decCBOR forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a s. DecCBOR a => Decoder s a
decCBOR
data UMElem
= TEEEE
| TEEEF !DRep
| TEEFE !(KeyHash 'StakePool)
| TEEFF !(KeyHash 'StakePool) !DRep
| TEFEE !(Set Ptr)
| TEFEF !(Set Ptr) !DRep
| TEFFE !(Set Ptr) !(KeyHash 'StakePool)
| TEFFF !(Set Ptr) !(KeyHash 'StakePool) !DRep
| TFEEE {-# UNPACK #-} !RDPair
| TFEEF {-# UNPACK #-} !RDPair !DRep
| TFEFE {-# UNPACK #-} !RDPair !(KeyHash 'StakePool)
| TFEFF {-# UNPACK #-} !RDPair !(KeyHash 'StakePool) !DRep
| TFFEE {-# UNPACK #-} !RDPair !(Set Ptr)
| TFFEF {-# UNPACK #-} !RDPair !(Set Ptr) !DRep
| TFFFE {-# UNPACK #-} !RDPair !(Set Ptr) !(KeyHash 'StakePool)
| TFFFF {-# UNPACK #-} !RDPair !(Set Ptr) !(KeyHash 'StakePool) !DRep
deriving (UMElem -> UMElem -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UMElem -> UMElem -> Bool
$c/= :: UMElem -> UMElem -> Bool
== :: UMElem -> UMElem -> Bool
$c== :: UMElem -> UMElem -> Bool
Eq, Eq UMElem
UMElem -> UMElem -> Bool
UMElem -> UMElem -> Ordering
UMElem -> UMElem -> UMElem
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: UMElem -> UMElem -> UMElem
$cmin :: UMElem -> UMElem -> UMElem
max :: UMElem -> UMElem -> UMElem
$cmax :: UMElem -> UMElem -> UMElem
>= :: UMElem -> UMElem -> Bool
$c>= :: UMElem -> UMElem -> Bool
> :: UMElem -> UMElem -> Bool
$c> :: UMElem -> UMElem -> Bool
<= :: UMElem -> UMElem -> Bool
$c<= :: UMElem -> UMElem -> Bool
< :: UMElem -> UMElem -> Bool
$c< :: UMElem -> UMElem -> Bool
compare :: UMElem -> UMElem -> Ordering
$ccompare :: UMElem -> UMElem -> Ordering
Ord, Int -> UMElem -> ShowS
[UMElem] -> ShowS
UMElem -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UMElem] -> ShowS
$cshowList :: [UMElem] -> ShowS
show :: UMElem -> String
$cshow :: UMElem -> String
showsPrec :: Int -> UMElem -> ShowS
$cshowsPrec :: Int -> UMElem -> ShowS
Show, forall x. Rep UMElem x -> UMElem
forall x. UMElem -> Rep UMElem x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UMElem x -> UMElem
$cfrom :: forall x. UMElem -> Rep UMElem x
Generic, Context -> UMElem -> IO (Maybe ThunkInfo)
Proxy UMElem -> String
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
showTypeOf :: Proxy UMElem -> String
$cshowTypeOf :: Proxy UMElem -> String
wNoThunks :: Context -> UMElem -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> UMElem -> IO (Maybe ThunkInfo)
noThunks :: Context -> UMElem -> IO (Maybe ThunkInfo)
$cnoThunks :: Context -> UMElem -> IO (Maybe ThunkInfo)
NoThunks, UMElem -> ()
forall a. (a -> ()) -> NFData a
rnf :: UMElem -> ()
$crnf :: UMElem -> ()
NFData)
instance ToJSON UMElem where
toJSON :: UMElem -> Value
toJSON = [Pair] -> Value
object forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall e a. KeyValue e a => UMElem -> [a]
toUMElemair
toEncoding :: UMElem -> Encoding
toEncoding = Series -> Encoding
Aeson.pairs forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall e a. KeyValue e a => UMElem -> [a]
toUMElemair
toUMElemair :: Aeson.KeyValue e a => UMElem -> [a]
toUMElemair :: forall e a. KeyValue e a => UMElem -> [a]
toUMElemair (UMElem !StrictMaybe RDPair
rd !Set Ptr
ptr !StrictMaybe (KeyHash 'StakePool)
spool !StrictMaybe DRep
drep) =
[ Key
"reward" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap RDPair -> CompactForm Coin
rdReward StrictMaybe RDPair
rd
, Key
"deposit" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap RDPair -> CompactForm Coin
rdDeposit StrictMaybe RDPair
rd
, Key
"ptr" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Set Ptr
ptr
, Key
"spool" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= StrictMaybe (KeyHash 'StakePool)
spool
, Key
"drep" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= StrictMaybe DRep
drep
]
instance EncCBOR UMElem where
encCBOR :: UMElem -> Encoding
encCBOR (UMElem StrictMaybe RDPair
rd Set Ptr
ptrSet StrictMaybe (KeyHash 'StakePool)
sPool StrictMaybe DRep
dRep) =
Word -> Encoding
encodeListLen Word
4 forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR StrictMaybe RDPair
rd forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR Set Ptr
ptrSet forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR StrictMaybe (KeyHash 'StakePool)
sPool forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR StrictMaybe DRep
dRep
instance DecShareCBOR UMElem where
type Share UMElem = Interns (KeyHash 'StakePool)
decShareCBOR :: forall s. Share UMElem -> Decoder s UMElem
decShareCBOR Share UMElem
is =
forall a s. Text -> (a -> Int) -> Decoder s a -> Decoder s a
decodeRecordNamed Text
"UMElem" (forall a b. a -> b -> a
const Int
4) forall a b. (a -> b) -> a -> b
$
StrictMaybe RDPair
-> Set Ptr
-> StrictMaybe (KeyHash 'StakePool)
-> StrictMaybe DRep
-> UMElem
UMElem
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a s. DecCBOR a => Decoder s a
decCBOR
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall s a. Version -> Decoder s a -> Decoder s a -> Decoder s a
ifDecoderVersionAtLeast (forall (v :: Natural).
(KnownNat v, MinVersion <= v, v <= MaxVersion) =>
Version
natVersion @9) (forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall a s. DecCBOR a => Proxy a -> Decoder s ()
dropCBOR (forall {k} (t :: k). Proxy t
Proxy @(Set Ptr))) forall a s. DecCBOR a => Decoder s a
decCBOR
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (f :: * -> *) b s.
(DecCBOR (f b), Monad f) =>
Interns b -> Decoder s (f b)
decShareMonadCBOR Share UMElem
is
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a s. DecCBOR a => Decoder s a
decCBOR
umElemAsTuple ::
UMElem ->
(StrictMaybe RDPair, Set Ptr, StrictMaybe (KeyHash 'StakePool), StrictMaybe DRep)
umElemAsTuple :: UMElem
-> (StrictMaybe RDPair, Set Ptr, StrictMaybe (KeyHash 'StakePool),
StrictMaybe DRep)
umElemAsTuple = \case
UMElem
TEEEE -> (forall a. StrictMaybe a
SNothing, forall a. Set a
Set.empty, forall a. StrictMaybe a
SNothing, forall a. StrictMaybe a
SNothing)
TEEEF DRep
v -> (forall a. StrictMaybe a
SNothing, forall a. Set a
Set.empty, forall a. StrictMaybe a
SNothing, forall a. a -> StrictMaybe a
SJust DRep
v)
TEEFE KeyHash 'StakePool
s -> (forall a. StrictMaybe a
SNothing, forall a. Set a
Set.empty, forall a. a -> StrictMaybe a
SJust KeyHash 'StakePool
s, forall a. StrictMaybe a
SNothing)
TEEFF KeyHash 'StakePool
s DRep
v -> (forall a. StrictMaybe a
SNothing, forall a. Set a
Set.empty, forall a. a -> StrictMaybe a
SJust KeyHash 'StakePool
s, forall a. a -> StrictMaybe a
SJust DRep
v)
TEFEE Set Ptr
p -> (forall a. StrictMaybe a
SNothing, Set Ptr
p, forall a. StrictMaybe a
SNothing, forall a. StrictMaybe a
SNothing)
TEFEF Set Ptr
p DRep
v -> (forall a. StrictMaybe a
SNothing, Set Ptr
p, forall a. StrictMaybe a
SNothing, forall a. a -> StrictMaybe a
SJust DRep
v)
TEFFE Set Ptr
p KeyHash 'StakePool
s -> (forall a. StrictMaybe a
SNothing, Set Ptr
p, forall a. a -> StrictMaybe a
SJust KeyHash 'StakePool
s, forall a. StrictMaybe a
SNothing)
TEFFF Set Ptr
p KeyHash 'StakePool
s DRep
v -> (forall a. StrictMaybe a
SNothing, Set Ptr
p, forall a. a -> StrictMaybe a
SJust KeyHash 'StakePool
s, forall a. a -> StrictMaybe a
SJust DRep
v)
TFEEE RDPair
r -> (forall a. a -> StrictMaybe a
SJust RDPair
r, forall a. Set a
Set.empty, forall a. StrictMaybe a
SNothing, forall a. StrictMaybe a
SNothing)
TFEEF RDPair
r DRep
v -> (forall a. a -> StrictMaybe a
SJust RDPair
r, forall a. Set a
Set.empty, forall a. StrictMaybe a
SNothing, forall a. a -> StrictMaybe a
SJust DRep
v)
TFEFE RDPair
r KeyHash 'StakePool
s -> (forall a. a -> StrictMaybe a
SJust RDPair
r, forall a. Set a
Set.empty, forall a. a -> StrictMaybe a
SJust KeyHash 'StakePool
s, forall a. StrictMaybe a
SNothing)
TFEFF RDPair
r KeyHash 'StakePool
s DRep
v -> (forall a. a -> StrictMaybe a
SJust RDPair
r, forall a. Set a
Set.empty, forall a. a -> StrictMaybe a
SJust KeyHash 'StakePool
s, forall a. a -> StrictMaybe a
SJust DRep
v)
TFFEE RDPair
r Set Ptr
p -> (forall a. a -> StrictMaybe a
SJust RDPair
r, Set Ptr
p, forall a. StrictMaybe a
SNothing, forall a. StrictMaybe a
SNothing)
TFFEF RDPair
r Set Ptr
p DRep
v -> (forall a. a -> StrictMaybe a
SJust RDPair
r, Set Ptr
p, forall a. StrictMaybe a
SNothing, forall a. a -> StrictMaybe a
SJust DRep
v)
TFFFE RDPair
r Set Ptr
p KeyHash 'StakePool
s -> (forall a. a -> StrictMaybe a
SJust RDPair
r, Set Ptr
p, forall a. a -> StrictMaybe a
SJust KeyHash 'StakePool
s, forall a. StrictMaybe a
SNothing)
TFFFF RDPair
r Set Ptr
p KeyHash 'StakePool
s DRep
v -> (forall a. a -> StrictMaybe a
SJust RDPair
r, Set Ptr
p, forall a. a -> StrictMaybe a
SJust KeyHash 'StakePool
s, forall a. a -> StrictMaybe a
SJust DRep
v)
{-# INLINE umElemAsTuple #-}
umElemDRepDelegatedReward :: UMElem -> Maybe (CompactForm Coin, DRep)
umElemDRepDelegatedReward :: UMElem -> Maybe (CompactForm Coin, DRep)
umElemDRepDelegatedReward = \case
TFEEF RDPair {CompactForm Coin
rdReward :: CompactForm Coin
rdReward :: RDPair -> CompactForm Coin
rdReward} DRep
dRep -> forall a. a -> Maybe a
Just (CompactForm Coin
rdReward, DRep
dRep)
TFEFF RDPair {CompactForm Coin
rdReward :: CompactForm Coin
rdReward :: RDPair -> CompactForm Coin
rdReward} KeyHash 'StakePool
_ DRep
dRep -> forall a. a -> Maybe a
Just (CompactForm Coin
rdReward, DRep
dRep)
TFFEF RDPair {CompactForm Coin
rdReward :: CompactForm Coin
rdReward :: RDPair -> CompactForm Coin
rdReward} Set Ptr
_ DRep
dRep -> forall a. a -> Maybe a
Just (CompactForm Coin
rdReward, DRep
dRep)
TFFFF RDPair {CompactForm Coin
rdReward :: CompactForm Coin
rdReward :: RDPair -> CompactForm Coin
rdReward} Set Ptr
_ KeyHash 'StakePool
_ DRep
dRep -> forall a. a -> Maybe a
Just (CompactForm Coin
rdReward, DRep
dRep)
UMElem
_ -> forall a. Maybe a
Nothing
{-# INLINE umElemDRepDelegatedReward #-}
umElemRDActive :: UMElem -> Maybe RDPair
umElemRDActive :: UMElem -> Maybe RDPair
umElemRDActive = \case
TFEFE RDPair
rdA KeyHash 'StakePool
_ -> forall a. a -> Maybe a
Just RDPair
rdA
TFEFF RDPair
rdA KeyHash 'StakePool
_ DRep
_ -> forall a. a -> Maybe a
Just RDPair
rdA
TFFFE RDPair
rdA Set Ptr
_ KeyHash 'StakePool
_ -> forall a. a -> Maybe a
Just RDPair
rdA
TFFFF RDPair
rdA Set Ptr
_ KeyHash 'StakePool
_ DRep
_ -> forall a. a -> Maybe a
Just RDPair
rdA
UMElem
_ -> forall a. Maybe a
Nothing
{-# INLINE umElemRDActive #-}
data RewardDelegation
= RewardDelegationSPO !(KeyHash 'StakePool) !(CompactForm Coin)
| RewardDelegationDRep !DRep !(CompactForm Coin)
| RewardDelegationBoth !(KeyHash 'StakePool) !DRep !(CompactForm Coin)
umElemDelegations :: UMElem -> Maybe RewardDelegation
umElemDelegations :: UMElem -> Maybe RewardDelegation
umElemDelegations (UMElem StrictMaybe RDPair
r Set Ptr
_p StrictMaybe (KeyHash 'StakePool)
s StrictMaybe DRep
d) =
let reward :: CompactForm Coin
reward = forall a b. a -> (b -> a) -> StrictMaybe b -> a
strictMaybe forall a. Monoid a => a
mempty RDPair -> CompactForm Coin
rdReward StrictMaybe RDPair
r
in case (StrictMaybe (KeyHash 'StakePool)
s, StrictMaybe DRep
d) of
(SJust KeyHash 'StakePool
spo, SJust DRep
drep) -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ KeyHash 'StakePool -> DRep -> CompactForm Coin -> RewardDelegation
RewardDelegationBoth KeyHash 'StakePool
spo DRep
drep CompactForm Coin
reward
(SJust KeyHash 'StakePool
spo, StrictMaybe DRep
SNothing) -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ KeyHash 'StakePool -> CompactForm Coin -> RewardDelegation
RewardDelegationSPO KeyHash 'StakePool
spo CompactForm Coin
reward
(StrictMaybe (KeyHash 'StakePool)
SNothing, SJust DRep
drep) -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ DRep -> CompactForm Coin -> RewardDelegation
RewardDelegationDRep DRep
drep CompactForm Coin
reward
(StrictMaybe (KeyHash 'StakePool)
SNothing, StrictMaybe DRep
SNothing) -> forall a. Maybe a
Nothing
{-# INLINE umElemDelegations #-}
umElemRDPair :: UMElem -> Maybe RDPair
umElemRDPair :: UMElem -> Maybe RDPair
umElemRDPair = \case
TFEEE RDPair
r -> forall a. a -> Maybe a
Just RDPair
r
TFEEF RDPair
r DRep
_ -> forall a. a -> Maybe a
Just RDPair
r
TFEFE RDPair
r KeyHash 'StakePool
_ -> forall a. a -> Maybe a
Just RDPair
r
TFEFF RDPair
r KeyHash 'StakePool
_ DRep
_ -> forall a. a -> Maybe a
Just RDPair
r
TFFEE RDPair
r Set Ptr
_ -> forall a. a -> Maybe a
Just RDPair
r
TFFEF RDPair
r Set Ptr
_ DRep
_ -> forall a. a -> Maybe a
Just RDPair
r
TFFFE RDPair
r Set Ptr
_ KeyHash 'StakePool
_ -> forall a. a -> Maybe a
Just RDPair
r
TFFFF RDPair
r Set Ptr
_ KeyHash 'StakePool
_ DRep
_ -> forall a. a -> Maybe a
Just RDPair
r
UMElem
_ -> forall a. Maybe a
Nothing
{-# INLINE umElemRDPair #-}
umElemPtrs :: UMElem -> Maybe (Set.Set Ptr)
umElemPtrs :: UMElem -> Maybe (Set Ptr)
umElemPtrs = \case
TEFEE Set Ptr
p | Bool -> Bool
not (forall a. Set a -> Bool
Set.null Set Ptr
p) -> forall a. a -> Maybe a
Just Set Ptr
p
TEFEF Set Ptr
p DRep
_ | Bool -> Bool
not (forall a. Set a -> Bool
Set.null Set Ptr
p) -> forall a. a -> Maybe a
Just Set Ptr
p
TEFFE Set Ptr
p KeyHash 'StakePool
_ | Bool -> Bool
not (forall a. Set a -> Bool
Set.null Set Ptr
p) -> forall a. a -> Maybe a
Just Set Ptr
p
TEFFF Set Ptr
p KeyHash 'StakePool
_ DRep
_ | Bool -> Bool
not (forall a. Set a -> Bool
Set.null Set Ptr
p) -> forall a. a -> Maybe a
Just Set Ptr
p
TFFEE RDPair
_ Set Ptr
p | Bool -> Bool
not (forall a. Set a -> Bool
Set.null Set Ptr
p) -> forall a. a -> Maybe a
Just Set Ptr
p
TFFEF RDPair
_ Set Ptr
p DRep
_ | Bool -> Bool
not (forall a. Set a -> Bool
Set.null Set Ptr
p) -> forall a. a -> Maybe a
Just Set Ptr
p
TFFFE RDPair
_ Set Ptr
p KeyHash 'StakePool
_ | Bool -> Bool
not (forall a. Set a -> Bool
Set.null Set Ptr
p) -> forall a. a -> Maybe a
Just Set Ptr
p
TFFFF RDPair
_ Set Ptr
p KeyHash 'StakePool
_ DRep
_ | Bool -> Bool
not (forall a. Set a -> Bool
Set.null Set Ptr
p) -> forall a. a -> Maybe a
Just Set Ptr
p
UMElem
_ -> forall a. Maybe a
Nothing
{-# INLINE umElemPtrs #-}
umElemSPool :: UMElem -> Maybe (KeyHash 'StakePool)
umElemSPool :: UMElem -> Maybe (KeyHash 'StakePool)
umElemSPool = \case
TEEFE KeyHash 'StakePool
s -> forall a. a -> Maybe a
Just KeyHash 'StakePool
s
TEEFF KeyHash 'StakePool
s DRep
_ -> forall a. a -> Maybe a
Just KeyHash 'StakePool
s
TEFFE Set Ptr
_ KeyHash 'StakePool
s -> forall a. a -> Maybe a
Just KeyHash 'StakePool
s
TEFFF Set Ptr
_ KeyHash 'StakePool
s DRep
_ -> forall a. a -> Maybe a
Just KeyHash 'StakePool
s
TFEFE RDPair
_ KeyHash 'StakePool
s -> forall a. a -> Maybe a
Just KeyHash 'StakePool
s
TFEFF RDPair
_ KeyHash 'StakePool
s DRep
_ -> forall a. a -> Maybe a
Just KeyHash 'StakePool
s
TFFFE RDPair
_ Set Ptr
_ KeyHash 'StakePool
s -> forall a. a -> Maybe a
Just KeyHash 'StakePool
s
TFFFF RDPair
_ Set Ptr
_ KeyHash 'StakePool
s DRep
_ -> forall a. a -> Maybe a
Just KeyHash 'StakePool
s
UMElem
_ -> forall a. Maybe a
Nothing
{-# INLINE umElemSPool #-}
umElemDRep :: UMElem -> Maybe DRep
umElemDRep :: UMElem -> Maybe DRep
umElemDRep = \case
TEEEF DRep
d -> forall a. a -> Maybe a
Just DRep
d
TEEFF KeyHash 'StakePool
_ DRep
d -> forall a. a -> Maybe a
Just DRep
d
TEFEF Set Ptr
_ DRep
d -> forall a. a -> Maybe a
Just DRep
d
TEFFF Set Ptr
_ KeyHash 'StakePool
_ DRep
d -> forall a. a -> Maybe a
Just DRep
d
TFEEF RDPair
_ DRep
d -> forall a. a -> Maybe a
Just DRep
d
TFEFF RDPair
_ KeyHash 'StakePool
_ DRep
d -> forall a. a -> Maybe a
Just DRep
d
TFFEF RDPair
_ Set Ptr
_ DRep
d -> forall a. a -> Maybe a
Just DRep
d
TFFFF RDPair
_ Set Ptr
_ KeyHash 'StakePool
_ DRep
d -> forall a. a -> Maybe a
Just DRep
d
UMElem
_ -> forall a. Maybe a
Nothing
{-# INLINE umElemDRep #-}
pattern UMElem ::
StrictMaybe RDPair ->
Set Ptr ->
StrictMaybe (KeyHash 'StakePool) ->
StrictMaybe DRep ->
UMElem
pattern $bUMElem :: StrictMaybe RDPair
-> Set Ptr
-> StrictMaybe (KeyHash 'StakePool)
-> StrictMaybe DRep
-> UMElem
$mUMElem :: forall {r}.
UMElem
-> (StrictMaybe RDPair
-> Set Ptr
-> StrictMaybe (KeyHash 'StakePool)
-> StrictMaybe DRep
-> r)
-> ((# #) -> r)
-> r
UMElem i j k l <- (umElemAsTuple -> (i, j, k, l))
where
UMElem StrictMaybe RDPair
i Set Ptr
j StrictMaybe (KeyHash 'StakePool)
k StrictMaybe DRep
l = case (StrictMaybe RDPair
i, Set Ptr
j, StrictMaybe (KeyHash 'StakePool)
k, StrictMaybe DRep
l) of
(StrictMaybe RDPair
SNothing, Set Ptr
SI.Tip, StrictMaybe (KeyHash 'StakePool)
SNothing, StrictMaybe DRep
SNothing) -> UMElem
TEEEE
(StrictMaybe RDPair
SNothing, Set Ptr
SI.Tip, StrictMaybe (KeyHash 'StakePool)
SNothing, SJust DRep
d) -> DRep -> UMElem
TEEEF DRep
d
(StrictMaybe RDPair
SNothing, Set Ptr
SI.Tip, SJust KeyHash 'StakePool
s, StrictMaybe DRep
SNothing) -> KeyHash 'StakePool -> UMElem
TEEFE KeyHash 'StakePool
s
(StrictMaybe RDPair
SNothing, Set Ptr
SI.Tip, SJust KeyHash 'StakePool
s, SJust DRep
d) -> KeyHash 'StakePool -> DRep -> UMElem
TEEFF KeyHash 'StakePool
s DRep
d
(StrictMaybe RDPair
SNothing, Set Ptr
p, StrictMaybe (KeyHash 'StakePool)
SNothing, StrictMaybe DRep
SNothing) -> Set Ptr -> UMElem
TEFEE Set Ptr
p
(StrictMaybe RDPair
SNothing, Set Ptr
p, StrictMaybe (KeyHash 'StakePool)
SNothing, SJust DRep
d) -> Set Ptr -> DRep -> UMElem
TEFEF Set Ptr
p DRep
d
(StrictMaybe RDPair
SNothing, Set Ptr
p, SJust KeyHash 'StakePool
s, StrictMaybe DRep
SNothing) -> Set Ptr -> KeyHash 'StakePool -> UMElem
TEFFE Set Ptr
p KeyHash 'StakePool
s
(StrictMaybe RDPair
SNothing, Set Ptr
p, SJust KeyHash 'StakePool
s, SJust DRep
d) -> Set Ptr -> KeyHash 'StakePool -> DRep -> UMElem
TEFFF Set Ptr
p KeyHash 'StakePool
s DRep
d
(SJust RDPair
r, Set Ptr
SI.Tip, StrictMaybe (KeyHash 'StakePool)
SNothing, StrictMaybe DRep
SNothing) -> RDPair -> UMElem
TFEEE RDPair
r
(SJust RDPair
r, Set Ptr
SI.Tip, StrictMaybe (KeyHash 'StakePool)
SNothing, SJust DRep
d) -> RDPair -> DRep -> UMElem
TFEEF RDPair
r DRep
d
(SJust RDPair
r, Set Ptr
SI.Tip, SJust KeyHash 'StakePool
s, StrictMaybe DRep
SNothing) -> RDPair -> KeyHash 'StakePool -> UMElem
TFEFE RDPair
r KeyHash 'StakePool
s
(SJust RDPair
r, Set Ptr
SI.Tip, SJust KeyHash 'StakePool
s, SJust DRep
d) -> RDPair -> KeyHash 'StakePool -> DRep -> UMElem
TFEFF RDPair
r KeyHash 'StakePool
s DRep
d
(SJust RDPair
r, Set Ptr
p, StrictMaybe (KeyHash 'StakePool)
SNothing, StrictMaybe DRep
SNothing) -> RDPair -> Set Ptr -> UMElem
TFFEE RDPair
r Set Ptr
p
(SJust RDPair
r, Set Ptr
p, StrictMaybe (KeyHash 'StakePool)
SNothing, SJust DRep
d) -> RDPair -> Set Ptr -> DRep -> UMElem
TFFEF RDPair
r Set Ptr
p DRep
d
(SJust RDPair
r, Set Ptr
p, SJust KeyHash 'StakePool
s, StrictMaybe DRep
SNothing) -> RDPair -> Set Ptr -> KeyHash 'StakePool -> UMElem
TFFFE RDPair
r Set Ptr
p KeyHash 'StakePool
s
(SJust RDPair
r, Set Ptr
p, SJust KeyHash 'StakePool
s, SJust DRep
d) -> RDPair -> Set Ptr -> KeyHash 'StakePool -> DRep -> UMElem
TFFFF RDPair
r Set Ptr
p KeyHash 'StakePool
s DRep
d
{-# COMPLETE UMElem #-}
data UMap = UMap
{ UMap -> Map (Credential 'Staking) UMElem
umElems :: !(Map (Credential 'Staking) UMElem)
, UMap -> Map Ptr (Credential 'Staking)
umPtrs :: !(Map Ptr (Credential 'Staking))
}
deriving (Int -> UMap -> ShowS
[UMap] -> ShowS
UMap -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UMap] -> ShowS
$cshowList :: [UMap] -> ShowS
show :: UMap -> String
$cshow :: UMap -> String
showsPrec :: Int -> UMap -> ShowS
$cshowsPrec :: Int -> UMap -> ShowS
Show, UMap -> UMap -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UMap -> UMap -> Bool
$c/= :: UMap -> UMap -> Bool
== :: UMap -> UMap -> Bool
$c== :: UMap -> UMap -> Bool
Eq, forall x. Rep UMap x -> UMap
forall x. UMap -> Rep UMap x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UMap x -> UMap
$cfrom :: forall x. UMap -> Rep UMap x
Generic, Context -> UMap -> IO (Maybe ThunkInfo)
Proxy UMap -> String
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
showTypeOf :: Proxy UMap -> String
$cshowTypeOf :: Proxy UMap -> String
wNoThunks :: Context -> UMap -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> UMap -> IO (Maybe ThunkInfo)
noThunks :: Context -> UMap -> IO (Maybe ThunkInfo)
$cnoThunks :: Context -> UMap -> IO (Maybe ThunkInfo)
NoThunks, UMap -> ()
forall a. (a -> ()) -> NFData a
rnf :: UMap -> ()
$crnf :: UMap -> ()
NFData)
umElemsL :: Lens' UMap (Map (Credential 'Staking) UMElem)
umElemsL :: Lens' UMap (Map (Credential 'Staking) UMElem)
umElemsL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens UMap -> Map (Credential 'Staking) UMElem
umElems (\UMap
x Map (Credential 'Staking) UMElem
y -> UMap
x {umElems :: Map (Credential 'Staking) UMElem
umElems = Map (Credential 'Staking) UMElem
y})
data StakeCredentials = StakeCredentials
{ StakeCredentials -> Map (Credential 'Staking) Coin
scRewards :: Map (Credential 'Staking) Coin
, StakeCredentials -> Map (Credential 'Staking) Coin
scDeposits :: Map (Credential 'Staking) Coin
, StakeCredentials -> Map (Credential 'Staking) (KeyHash 'StakePool)
scSPools :: Map (Credential 'Staking) (KeyHash 'StakePool)
, StakeCredentials -> Map (Credential 'Staking) DRep
scDReps :: Map (Credential 'Staking) DRep
, StakeCredentials -> Map Ptr (Credential 'Staking)
scPtrs :: Map Ptr (Credential 'Staking)
, StakeCredentials -> Map (Credential 'Staking) (Set Ptr)
scPtrsInverse :: Map (Credential 'Staking) (Set Ptr)
}
deriving (Int -> StakeCredentials -> ShowS
[StakeCredentials] -> ShowS
StakeCredentials -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StakeCredentials] -> ShowS
$cshowList :: [StakeCredentials] -> ShowS
show :: StakeCredentials -> String
$cshow :: StakeCredentials -> String
showsPrec :: Int -> StakeCredentials -> ShowS
$cshowsPrec :: Int -> StakeCredentials -> ShowS
Show, StakeCredentials -> StakeCredentials -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StakeCredentials -> StakeCredentials -> Bool
$c/= :: StakeCredentials -> StakeCredentials -> Bool
== :: StakeCredentials -> StakeCredentials -> Bool
$c== :: StakeCredentials -> StakeCredentials -> Bool
Eq, forall x. Rep StakeCredentials x -> StakeCredentials
forall x. StakeCredentials -> Rep StakeCredentials x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StakeCredentials x -> StakeCredentials
$cfrom :: forall x. StakeCredentials -> Rep StakeCredentials x
Generic, Context -> StakeCredentials -> IO (Maybe ThunkInfo)
Proxy StakeCredentials -> String
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
showTypeOf :: Proxy StakeCredentials -> String
$cshowTypeOf :: Proxy StakeCredentials -> String
wNoThunks :: Context -> StakeCredentials -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> StakeCredentials -> IO (Maybe ThunkInfo)
noThunks :: Context -> StakeCredentials -> IO (Maybe ThunkInfo)
$cnoThunks :: Context -> StakeCredentials -> IO (Maybe ThunkInfo)
NoThunks, StakeCredentials -> ()
forall a. (a -> ()) -> NFData a
rnf :: StakeCredentials -> ()
$crnf :: StakeCredentials -> ()
NFData)
instance ToJSON UMap where
toJSON :: UMap -> Value
toJSON = [Pair] -> Value
object forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall e a. KeyValue e a => UMap -> [a]
toUMapPair
toEncoding :: UMap -> Encoding
toEncoding = Series -> Encoding
Aeson.pairs forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall e a. KeyValue e a => UMap -> [a]
toUMapPair
toUMapPair :: Aeson.KeyValue e a => UMap -> [a]
toUMapPair :: forall e a. KeyValue e a => UMap -> [a]
toUMapPair (UMap !Map (Credential 'Staking) UMElem
m1 !Map Ptr (Credential 'Staking)
m2) =
[ Key
"credentials" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Map (Credential 'Staking) UMElem
m1
, Key
"pointers" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Map Ptr (Credential 'Staking)
m2
]
instance EncCBOR UMap where
encCBOR :: UMap -> Encoding
encCBOR UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems, Map Ptr (Credential 'Staking)
umPtrs :: Map Ptr (Credential 'Staking)
umPtrs :: UMap -> Map Ptr (Credential 'Staking)
umPtrs} =
Word -> Encoding
encodeListLen Word
2 forall a. Semigroup a => a -> a -> a
<> forall k v.
(k -> Encoding) -> (v -> Encoding) -> Map k v -> Encoding
encodeMap forall a. EncCBOR a => a -> Encoding
encCBOR forall a. EncCBOR a => a -> Encoding
encCBOR Map (Credential 'Staking) UMElem
umElems forall a. Semigroup a => a -> a -> a
<> forall k v.
(k -> Encoding) -> (v -> Encoding) -> Map k v -> Encoding
encodeMap forall a. EncCBOR a => a -> Encoding
encCBOR forall a. EncCBOR a => a -> Encoding
encCBOR Map Ptr (Credential 'Staking)
umPtrs
instance DecShareCBOR UMap where
type Share UMap = (Interns (Credential 'Staking), Interns (KeyHash 'StakePool))
decSharePlusCBOR :: forall s. StateT (Share UMap) (Decoder s) UMap
decSharePlusCBOR =
forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
StateT
( \(Interns (Credential 'Staking)
a, Interns (KeyHash 'StakePool)
b) ->
forall a s. Text -> (a -> Int) -> Decoder s a -> Decoder s a
decodeRecordNamed Text
"UMap" (forall a b. a -> b -> a
const Int
2) forall a b. (a -> b) -> a -> b
$ do
Map (Credential 'Staking) UMElem
umElems <- forall k s v.
Ord k =>
Decoder s k -> Decoder s v -> Decoder s (Map k v)
decodeMap (forall k. Interns k -> k -> k
interns Interns (Credential 'Staking)
a forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a s. DecCBOR a => Decoder s a
decCBOR) (forall a s. DecShareCBOR a => Share a -> Decoder s a
decShareCBOR Interns (KeyHash 'StakePool)
b)
let a' :: Interns (Credential 'Staking)
a' = forall k a. Ord k => Map k a -> Interns k
internsFromMap Map (Credential 'Staking) UMElem
umElems forall a. Semigroup a => a -> a -> a
<> Interns (Credential 'Staking)
a
Map Ptr (Credential 'Staking)
umPtrs <-
forall s a. Version -> Decoder s a -> Decoder s a -> Decoder s a
ifDecoderVersionAtLeast
(forall (v :: Natural).
(KnownNat v, MinVersion <= v, v <= MaxVersion) =>
Version
natVersion @9)
(forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall a s. DecCBOR a => Proxy a -> Decoder s ()
dropCBOR (forall {k} (t :: k). Proxy t
Proxy @(Map (Credential 'Staking) (Set Ptr))))
forall a b. (a -> b) -> a -> b
$ forall k s v.
Ord k =>
Decoder s k -> Decoder s v -> Decoder s (Map k v)
decodeMap forall a s. DecCBOR a => Decoder s a
decCBOR (forall k. Interns k -> k -> k
interns Interns (Credential 'Staking)
a' forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a s. DecCBOR a => Decoder s a
decCBOR)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems, Map Ptr (Credential 'Staking)
umPtrs :: Map Ptr (Credential 'Staking)
umPtrs :: Map Ptr (Credential 'Staking)
umPtrs}, (Interns (Credential 'Staking)
a', Interns (KeyHash 'StakePool)
b))
)
umInvariant :: Credential 'Staking -> Ptr -> UMap -> Bool
umInvariant :: Credential 'Staking -> Ptr -> UMap -> Bool
umInvariant Credential 'Staking
cred Ptr
ptr UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems, Map Ptr (Credential 'Staking)
umPtrs :: Map Ptr (Credential 'Staking)
umPtrs :: UMap -> Map Ptr (Credential 'Staking)
umPtrs} = Bool
forwards Bool -> Bool -> Bool
&& Bool
backwards
where
forwards :: Bool
forwards =
case forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Credential 'Staking
cred Map (Credential 'Staking) UMElem
umElems of
Maybe UMElem
Nothing -> Credential 'Staking
cred forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` Map Ptr (Credential 'Staking)
umPtrs
Just (UMElem StrictMaybe RDPair
_r Set Ptr
ptrSet StrictMaybe (KeyHash 'StakePool)
_s StrictMaybe DRep
_) ->
Bool -> Bool
not (forall a. Ord a => a -> Set a -> Bool
Set.member Ptr
ptr Set Ptr
ptrSet)
Bool -> Bool -> Bool
|| ( case forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Ptr
ptr Map Ptr (Credential 'Staking)
umPtrs of
Maybe (Credential 'Staking)
Nothing -> Bool
False
Just Credential 'Staking
cred2 -> Credential 'Staking
cred forall a. Eq a => a -> a -> Bool
== Credential 'Staking
cred2
)
backwards :: Bool
backwards =
case forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Ptr
ptr Map Ptr (Credential 'Staking)
umPtrs of
Maybe (Credential 'Staking)
Nothing -> forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (\(UMElem StrictMaybe RDPair
_ Set Ptr
ptrSet StrictMaybe (KeyHash 'StakePool)
_ StrictMaybe DRep
_) -> forall a. Ord a => a -> Set a -> Bool
Set.notMember Ptr
ptr Set Ptr
ptrSet) Map (Credential 'Staking) UMElem
umElems
Just Credential 'Staking
cred' ->
case forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Credential 'Staking
cred' Map (Credential 'Staking) UMElem
umElems of
Maybe UMElem
Nothing -> Bool
False
Just (UMElem StrictMaybe RDPair
_ Set Ptr
ptrSet StrictMaybe (KeyHash 'StakePool)
_ StrictMaybe DRep
_) -> forall a. Ord a => a -> Set a -> Bool
Set.member Ptr
ptr Set Ptr
ptrSet
data UView k v where
RewDepUView ::
!UMap ->
UView (Credential 'Staking) RDPair
PtrUView ::
!UMap ->
UView Ptr (Credential 'Staking)
SPoolUView ::
!UMap ->
UView (Credential 'Staking) (KeyHash 'StakePool)
DRepUView ::
!UMap ->
UView (Credential 'Staking) DRep
rewDepUView ::
Map (Credential 'Staking) UMElem ->
Map Ptr (Credential 'Staking) ->
UView (Credential 'Staking) RDPair
rewDepUView :: Map (Credential 'Staking) UMElem
-> Map Ptr (Credential 'Staking)
-> UView (Credential 'Staking) RDPair
rewDepUView Map (Credential 'Staking) UMElem
a Map Ptr (Credential 'Staking)
b = UMap -> UView (Credential 'Staking) RDPair
RewDepUView (Map (Credential 'Staking) UMElem
-> Map Ptr (Credential 'Staking) -> UMap
UMap Map (Credential 'Staking) UMElem
a Map Ptr (Credential 'Staking)
b)
ptrUView ::
Map (Credential 'Staking) UMElem ->
Map Ptr (Credential 'Staking) ->
UView Ptr (Credential 'Staking)
ptrUView :: Map (Credential 'Staking) UMElem
-> Map Ptr (Credential 'Staking) -> UView Ptr (Credential 'Staking)
ptrUView Map (Credential 'Staking) UMElem
a Map Ptr (Credential 'Staking)
b = UMap -> UView Ptr (Credential 'Staking)
PtrUView (Map (Credential 'Staking) UMElem
-> Map Ptr (Credential 'Staking) -> UMap
UMap Map (Credential 'Staking) UMElem
a Map Ptr (Credential 'Staking)
b)
sPoolUView ::
Map (Credential 'Staking) UMElem ->
Map Ptr (Credential 'Staking) ->
UView (Credential 'Staking) (KeyHash 'StakePool)
sPoolUView :: Map (Credential 'Staking) UMElem
-> Map Ptr (Credential 'Staking)
-> UView (Credential 'Staking) (KeyHash 'StakePool)
sPoolUView Map (Credential 'Staking) UMElem
a Map Ptr (Credential 'Staking)
b = UMap -> UView (Credential 'Staking) (KeyHash 'StakePool)
SPoolUView (Map (Credential 'Staking) UMElem
-> Map Ptr (Credential 'Staking) -> UMap
UMap Map (Credential 'Staking) UMElem
a Map Ptr (Credential 'Staking)
b)
dRepUView ::
Map (Credential 'Staking) UMElem ->
Map Ptr (Credential 'Staking) ->
UView (Credential 'Staking) DRep
dRepUView :: Map (Credential 'Staking) UMElem
-> Map Ptr (Credential 'Staking)
-> UView (Credential 'Staking) DRep
dRepUView Map (Credential 'Staking) UMElem
a Map Ptr (Credential 'Staking)
b = UMap -> UView (Credential 'Staking) DRep
DRepUView (Map (Credential 'Staking) UMElem
-> Map Ptr (Credential 'Staking) -> UMap
UMap Map (Credential 'Staking) UMElem
a Map Ptr (Credential 'Staking)
b)
unUView :: UView k v -> UMap
unUView :: forall k v. UView k v -> UMap
unUView = \case
RewDepUView UMap
um -> UMap
um
PtrUView UMap
um -> UMap
um
SPoolUView UMap
um -> UMap
um
DRepUView UMap
um -> UMap
um
unUnify :: UView k v -> Map k v
unUnify :: forall k v. UView k v -> Map k v
unUnify = \case
RewDepUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} -> forall a b k. (a -> Maybe b) -> Map k a -> Map k b
Map.mapMaybe UMElem -> Maybe RDPair
umElemRDPair Map (Credential 'Staking) UMElem
umElems
PtrUView UMap {Map Ptr (Credential 'Staking)
umPtrs :: Map Ptr (Credential 'Staking)
umPtrs :: UMap -> Map Ptr (Credential 'Staking)
umPtrs} -> Map Ptr (Credential 'Staking)
umPtrs
SPoolUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} -> forall a b k. (a -> Maybe b) -> Map k a -> Map k b
Map.mapMaybe UMElem -> Maybe (KeyHash 'StakePool)
umElemSPool Map (Credential 'Staking) UMElem
umElems
DRepUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} -> forall a b k. (a -> Maybe b) -> Map k a -> Map k b
Map.mapMaybe UMElem -> Maybe DRep
umElemDRep Map (Credential 'Staking) UMElem
umElems
unUnifyToVMap :: UView k v -> VMap.VMap VMap.VB VMap.VB k v
unUnifyToVMap :: forall k v. UView k v -> VMap VB VB k v
unUnifyToVMap UView k v
uview = case UView k v
uview of
RewDepUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} ->
forall k (kv :: * -> *) (vv :: * -> *) v.
(Ord k, Vector kv k, Vector vv v) =>
Int -> [(k, v)] -> VMap kv vv k v
VMap.fromListN (forall k v. UView k v -> Int
size UView k v
uview) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> Maybe b) -> [a] -> [b]
Maybe.mapMaybe forall {a}. (a, UMElem) -> Maybe (a, RDPair)
toRDPair forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k a. Map k a -> [(k, a)]
Map.toList forall a b. (a -> b) -> a -> b
$ Map (Credential 'Staking) UMElem
umElems
PtrUView UMap {Map Ptr (Credential 'Staking)
umPtrs :: Map Ptr (Credential 'Staking)
umPtrs :: UMap -> Map Ptr (Credential 'Staking)
umPtrs} -> forall (kv :: * -> *) k (vv :: * -> *) v.
(Vector kv k, Vector vv v) =>
Map k v -> VMap kv vv k v
VMap.fromMap Map Ptr (Credential 'Staking)
umPtrs
SPoolUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} ->
forall k (kv :: * -> *) (vv :: * -> *) v.
(Ord k, Vector kv k, Vector vv v) =>
Int -> [(k, v)] -> VMap kv vv k v
VMap.fromListN (forall k v. UView k v -> Int
size UView k v
uview) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> Maybe b) -> [a] -> [b]
Maybe.mapMaybe forall {a}. (a, UMElem) -> Maybe (a, KeyHash 'StakePool)
toSPool forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k a. Map k a -> [(k, a)]
Map.toList forall a b. (a -> b) -> a -> b
$ Map (Credential 'Staking) UMElem
umElems
DRepUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} ->
forall k (kv :: * -> *) (vv :: * -> *) v.
(Ord k, Vector kv k, Vector vv v) =>
Int -> [(k, v)] -> VMap kv vv k v
VMap.fromListN (forall k v. UView k v -> Int
size UView k v
uview) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> Maybe b) -> [a] -> [b]
Maybe.mapMaybe forall {a}. (a, UMElem) -> Maybe (a, DRep)
toDRep forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k a. Map k a -> [(k, a)]
Map.toList forall a b. (a -> b) -> a -> b
$ Map (Credential 'Staking) UMElem
umElems
where
toRDPair :: (a, UMElem) -> Maybe (a, RDPair)
toRDPair (a
key, UMElem
t) = (,) a
key forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> UMElem -> Maybe RDPair
umElemRDPair UMElem
t
toSPool :: (a, UMElem) -> Maybe (a, KeyHash 'StakePool)
toSPool (a
key, UMElem
t) = (,) a
key forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> UMElem -> Maybe (KeyHash 'StakePool)
umElemSPool UMElem
t
toDRep :: (a, UMElem) -> Maybe (a, DRep)
toDRep (a
key, UMElem
t) = (,) a
key forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> UMElem -> Maybe DRep
umElemDRep UMElem
t
rdPairMap :: UMap -> Map (Credential 'Staking) RDPair
rdPairMap :: UMap -> Map (Credential 'Staking) RDPair
rdPairMap UMap
x = forall k v. UView k v -> Map k v
unUnify forall a b. (a -> b) -> a -> b
$ UMap -> UView (Credential 'Staking) RDPair
RewDepUView UMap
x
rewardMap :: UMap -> Map (Credential 'Staking) Coin
rewardMap :: UMap -> Map (Credential 'Staking) Coin
rewardMap UMap
x = forall a b k. (a -> b) -> Map k a -> Map k b
Map.map (forall a. Compactible a => CompactForm a -> a
fromCompact forall b c a. (b -> c) -> (a -> b) -> a -> c
. RDPair -> CompactForm Coin
rdReward) forall a b. (a -> b) -> a -> b
$ forall k v. UView k v -> Map k v
unUnify forall a b. (a -> b) -> a -> b
$ UMap -> UView (Credential 'Staking) RDPair
RewDepUView UMap
x
compactRewardMap :: UMap -> Map (Credential 'Staking) (CompactForm Coin)
compactRewardMap :: UMap -> Map (Credential 'Staking) (CompactForm Coin)
compactRewardMap UMap
x = forall a b k. (a -> b) -> Map k a -> Map k b
Map.map RDPair -> CompactForm Coin
rdReward forall a b. (a -> b) -> a -> b
$ forall k v. UView k v -> Map k v
unUnify forall a b. (a -> b) -> a -> b
$ UMap -> UView (Credential 'Staking) RDPair
RewDepUView UMap
x
depositMap :: UMap -> Map (Credential 'Staking) Coin
depositMap :: UMap -> Map (Credential 'Staking) Coin
depositMap UMap
x = forall a b k. (a -> b) -> Map k a -> Map k b
Map.map (forall a. Compactible a => CompactForm a -> a
fromCompact forall b c a. (b -> c) -> (a -> b) -> a -> c
. RDPair -> CompactForm Coin
rdDeposit) forall a b. (a -> b) -> a -> b
$ forall k v. UView k v -> Map k v
unUnify forall a b. (a -> b) -> a -> b
$ UMap -> UView (Credential 'Staking) RDPair
RewDepUView UMap
x
ptrMap :: UMap -> Map Ptr (Credential 'Staking)
ptrMap :: UMap -> Map Ptr (Credential 'Staking)
ptrMap UMap
x = forall k v. UView k v -> Map k v
unUnify forall a b. (a -> b) -> a -> b
$ UMap -> UView Ptr (Credential 'Staking)
PtrUView UMap
x
invPtrMap :: UMap -> Map (Credential 'Staking) (Set Ptr)
invPtrMap :: UMap -> Map (Credential 'Staking) (Set Ptr)
invPtrMap UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} =
forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Map.foldlWithKey'
(\Map (Credential 'Staking) (Set Ptr)
ans Credential 'Staking
k (UMElem StrictMaybe RDPair
_ Set Ptr
ptrSet StrictMaybe (KeyHash 'StakePool)
_ StrictMaybe DRep
_) -> if forall a. Set a -> Bool
Set.null Set Ptr
ptrSet then Map (Credential 'Staking) (Set Ptr)
ans else forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert Credential 'Staking
k Set Ptr
ptrSet Map (Credential 'Staking) (Set Ptr)
ans)
forall k a. Map k a
Map.empty
Map (Credential 'Staking) UMElem
umElems
sPoolMap :: UMap -> Map (Credential 'Staking) (KeyHash 'StakePool)
sPoolMap :: UMap -> Map (Credential 'Staking) (KeyHash 'StakePool)
sPoolMap UMap
x = forall k v. UView k v -> Map k v
unUnify forall a b. (a -> b) -> a -> b
$ UMap -> UView (Credential 'Staking) (KeyHash 'StakePool)
SPoolUView UMap
x
dRepMap :: UMap -> Map (Credential 'Staking) DRep
dRepMap :: UMap -> Map (Credential 'Staking) DRep
dRepMap UMap
x = forall k v. UView k v -> Map k v
unUnify forall a b. (a -> b) -> a -> b
$ UMap -> UView (Credential 'Staking) DRep
DRepUView UMap
x
domRestrictedMap :: Set k -> UView k v -> Map k v
domRestrictedMap :: forall k v. Set k -> UView k v -> Map k v
domRestrictedMap Set k
setk = \case
RewDepUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} -> forall a b k. (a -> Maybe b) -> Map k a -> Map k b
Map.mapMaybe UMElem -> Maybe RDPair
umElemRDPair (forall k a. Ord k => Map k a -> Set k -> Map k a
Map.restrictKeys Map (Credential 'Staking) UMElem
umElems Set k
setk)
PtrUView UMap {Map Ptr (Credential 'Staking)
umPtrs :: Map Ptr (Credential 'Staking)
umPtrs :: UMap -> Map Ptr (Credential 'Staking)
umPtrs} -> forall k a. Ord k => Map k a -> Set k -> Map k a
Map.restrictKeys Map Ptr (Credential 'Staking)
umPtrs Set k
setk
SPoolUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} -> forall a b k. (a -> Maybe b) -> Map k a -> Map k b
Map.mapMaybe UMElem -> Maybe (KeyHash 'StakePool)
umElemSPool (forall k a. Ord k => Map k a -> Set k -> Map k a
Map.restrictKeys Map (Credential 'Staking) UMElem
umElems Set k
setk)
DRepUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} -> forall a b k. (a -> Maybe b) -> Map k a -> Map k b
Map.mapMaybe UMElem -> Maybe DRep
umElemDRep (forall k a. Ord k => Map k a -> Set k -> Map k a
Map.restrictKeys Map (Credential 'Staking) UMElem
umElems Set k
setk)
toStakeCredentials :: UMap -> StakeCredentials
toStakeCredentials :: UMap -> StakeCredentials
toStakeCredentials UMap
umap =
StakeCredentials
{ scRewards :: Map (Credential 'Staking) Coin
scRewards = UMap -> Map (Credential 'Staking) Coin
rewardMap UMap
umap
, scDeposits :: Map (Credential 'Staking) Coin
scDeposits = UMap -> Map (Credential 'Staking) Coin
depositMap UMap
umap
, scSPools :: Map (Credential 'Staking) (KeyHash 'StakePool)
scSPools = UMap -> Map (Credential 'Staking) (KeyHash 'StakePool)
sPoolMap UMap
umap
, scDReps :: Map (Credential 'Staking) DRep
scDReps = UMap -> Map (Credential 'Staking) DRep
dRepMap UMap
umap
, scPtrs :: Map Ptr (Credential 'Staking)
scPtrs = UMap -> Map Ptr (Credential 'Staking)
ptrMap UMap
umap
, scPtrsInverse :: Map (Credential 'Staking) (Set Ptr)
scPtrsInverse = UMap -> Map (Credential 'Staking) (Set Ptr)
invPtrMap UMap
umap
}
domRestrictedStakeCredentials :: Set (Credential 'Staking) -> UMap -> StakeCredentials
domRestrictedStakeCredentials :: Set (Credential 'Staking) -> UMap -> StakeCredentials
domRestrictedStakeCredentials Set (Credential 'Staking)
setk UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems, Map Ptr (Credential 'Staking)
umPtrs :: Map Ptr (Credential 'Staking)
umPtrs :: UMap -> Map Ptr (Credential 'Staking)
umPtrs} =
let umElems' :: Map (Credential 'Staking) UMElem
umElems' = forall k a. Ord k => Map k a -> Set k -> Map k a
Map.restrictKeys Map (Credential 'Staking) UMElem
umElems Set (Credential 'Staking)
setk
ptrs :: Map (Credential 'Staking) (Set Ptr)
ptrs = forall a b k. (a -> Maybe b) -> Map k a -> Map k b
Map.mapMaybe UMElem -> Maybe (Set Ptr)
umElemPtrs Map (Credential 'Staking) UMElem
umElems'
in StakeCredentials
{ scRewards :: Map (Credential 'Staking) Coin
scRewards = forall a b k. (a -> Maybe b) -> Map k a -> Map k b
Map.mapMaybe (\UMElem
e -> forall a. Compactible a => CompactForm a -> a
fromCompact forall b c a. (b -> c) -> (a -> b) -> a -> c
. RDPair -> CompactForm Coin
rdReward forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> UMElem -> Maybe RDPair
umElemRDPair UMElem
e) Map (Credential 'Staking) UMElem
umElems'
, scDeposits :: Map (Credential 'Staking) Coin
scDeposits = forall a b k. (a -> Maybe b) -> Map k a -> Map k b
Map.mapMaybe (\UMElem
e -> forall a. Compactible a => CompactForm a -> a
fromCompact forall b c a. (b -> c) -> (a -> b) -> a -> c
. RDPair -> CompactForm Coin
rdDeposit forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> UMElem -> Maybe RDPair
umElemRDPair UMElem
e) Map (Credential 'Staking) UMElem
umElems'
, scSPools :: Map (Credential 'Staking) (KeyHash 'StakePool)
scSPools = forall a b k. (a -> Maybe b) -> Map k a -> Map k b
Map.mapMaybe UMElem -> Maybe (KeyHash 'StakePool)
umElemSPool Map (Credential 'Staking) UMElem
umElems'
, scDReps :: Map (Credential 'Staking) DRep
scDReps = forall a b k. (a -> Maybe b) -> Map k a -> Map k b
Map.mapMaybe UMElem -> Maybe DRep
umElemDRep Map (Credential 'Staking) UMElem
umElems'
, scPtrs :: Map Ptr (Credential 'Staking)
scPtrs = Map Ptr (Credential 'Staking)
umPtrs forall k a. Ord k => Map k a -> Set k -> Map k a
`Map.restrictKeys` forall (t :: * -> *) m. (Foldable t, Monoid m) => t m -> m
fold Map (Credential 'Staking) (Set Ptr)
ptrs
, scPtrsInverse :: Map (Credential 'Staking) (Set Ptr)
scPtrsInverse = Map (Credential 'Staking) (Set Ptr)
ptrs
}
instance Foldable (UView k) where
foldMap :: forall m a. Monoid m => (a -> m) -> UView k a -> m
foldMap a -> m
f = \case
RewDepUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} -> forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Map.foldlWithKey m -> Credential 'Staking -> UMElem -> m
accum forall a. Monoid a => a
mempty Map (Credential 'Staking) UMElem
umElems
where
accum :: m -> Credential 'Staking -> UMElem -> m
accum m
ans Credential 'Staking
_ (UMElem (SJust RDPair
rd) Set Ptr
_ StrictMaybe (KeyHash 'StakePool)
_ StrictMaybe DRep
_) = m
ans forall a. Semigroup a => a -> a -> a
<> a -> m
f RDPair
rd
accum m
ans Credential 'Staking
_ UMElem
_ = m
ans
PtrUView UMap {Map Ptr (Credential 'Staking)
umPtrs :: Map Ptr (Credential 'Staking)
umPtrs :: UMap -> Map Ptr (Credential 'Staking)
umPtrs} -> forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap a -> m
f Map Ptr (Credential 'Staking)
umPtrs
SPoolUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} -> forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Map.foldlWithKey m -> Credential 'Staking -> UMElem -> m
accum forall a. Monoid a => a
mempty Map (Credential 'Staking) UMElem
umElems
where
accum :: m -> Credential 'Staking -> UMElem -> m
accum m
ans Credential 'Staking
_ (UMElem StrictMaybe RDPair
_ Set Ptr
_ (SJust KeyHash 'StakePool
sd) StrictMaybe DRep
_) = m
ans forall a. Semigroup a => a -> a -> a
<> a -> m
f KeyHash 'StakePool
sd
accum m
ans Credential 'Staking
_ UMElem
_ = m
ans
DRepUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} -> forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Map.foldlWithKey m -> Credential 'Staking -> UMElem -> m
accum forall a. Monoid a => a
mempty Map (Credential 'Staking) UMElem
umElems
where
accum :: m -> Credential 'Staking -> UMElem -> m
accum m
ans Credential 'Staking
_ (UMElem StrictMaybe RDPair
_ Set Ptr
_ StrictMaybe (KeyHash 'StakePool)
_ (SJust DRep
vd)) = m
ans forall a. Semigroup a => a -> a -> a
<> a -> m
f DRep
vd
accum m
ans Credential 'Staking
_ UMElem
_ = m
ans
foldr :: forall a b. (a -> b -> b) -> b -> UView k a -> b
foldr a -> b -> b
accum b
ans0 = \case
RewDepUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} -> forall a b k. (a -> b -> b) -> b -> Map k a -> b
Map.foldr UMElem -> b -> b
accum' b
ans0 Map (Credential 'Staking) UMElem
umElems
where
accum' :: UMElem -> b -> b
accum' (UMElem (SJust RDPair
rd) Set Ptr
_ StrictMaybe (KeyHash 'StakePool)
_ StrictMaybe DRep
_) b
ans = a -> b -> b
accum RDPair
rd b
ans
accum' UMElem
_ b
ans = b
ans
PtrUView UMap {Map Ptr (Credential 'Staking)
umPtrs :: Map Ptr (Credential 'Staking)
umPtrs :: UMap -> Map Ptr (Credential 'Staking)
umPtrs} -> forall a b k. (a -> b -> b) -> b -> Map k a -> b
Map.foldr a -> b -> b
accum b
ans0 Map Ptr (Credential 'Staking)
umPtrs
SPoolUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} -> forall a b k. (a -> b -> b) -> b -> Map k a -> b
Map.foldr UMElem -> b -> b
accum' b
ans0 Map (Credential 'Staking) UMElem
umElems
where
accum' :: UMElem -> b -> b
accum' (UMElem StrictMaybe RDPair
_ Set Ptr
_ (SJust KeyHash 'StakePool
sd) StrictMaybe DRep
_) b
ans = a -> b -> b
accum KeyHash 'StakePool
sd b
ans
accum' UMElem
_ b
ans = b
ans
DRepUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} -> forall a b k. (a -> b -> b) -> b -> Map k a -> b
Map.foldr UMElem -> b -> b
accum' b
ans0 Map (Credential 'Staking) UMElem
umElems
where
accum' :: UMElem -> b -> b
accum' (UMElem StrictMaybe RDPair
_ Set Ptr
_ StrictMaybe (KeyHash 'StakePool)
_ (SJust DRep
vd)) b
ans = a -> b -> b
accum DRep
vd b
ans
accum' UMElem
_ b
ans = b
ans
foldl' :: forall b a. (b -> a -> b) -> b -> UView k a -> b
foldl' b -> a -> b
accum b
ans0 = \case
RewDepUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} -> forall a b k. (a -> b -> a) -> a -> Map k b -> a
Map.foldl' b -> UMElem -> b
accum' b
ans0 Map (Credential 'Staking) UMElem
umElems
where
accum' :: b -> UMElem -> b
accum' b
ans = forall b a. b -> (a -> b) -> Maybe a -> b
maybe b
ans (b -> a -> b
accum b
ans) forall b c a. (b -> c) -> (a -> b) -> a -> c
. UMElem -> Maybe RDPair
umElemRDPair
PtrUView UMap {Map Ptr (Credential 'Staking)
umPtrs :: Map Ptr (Credential 'Staking)
umPtrs :: UMap -> Map Ptr (Credential 'Staking)
umPtrs} -> forall a b k. (a -> b -> a) -> a -> Map k b -> a
Map.foldl' b -> a -> b
accum b
ans0 Map Ptr (Credential 'Staking)
umPtrs
SPoolUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} -> forall a b k. (a -> b -> a) -> a -> Map k b -> a
Map.foldl' b -> UMElem -> b
accum' b
ans0 Map (Credential 'Staking) UMElem
umElems
where
accum' :: b -> UMElem -> b
accum' b
ans = forall b a. b -> (a -> b) -> Maybe a -> b
maybe b
ans (b -> a -> b
accum b
ans) forall b c a. (b -> c) -> (a -> b) -> a -> c
. UMElem -> Maybe (KeyHash 'StakePool)
umElemSPool
DRepUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} -> forall a b k. (a -> b -> a) -> a -> Map k b -> a
Map.foldl' b -> UMElem -> b
accum' b
ans0 Map (Credential 'Staking) UMElem
umElems
where
accum' :: b -> UMElem -> b
accum' b
ans = forall b a. b -> (a -> b) -> Maybe a -> b
maybe b
ans (b -> a -> b
accum b
ans) forall b c a. (b -> c) -> (a -> b) -> a -> c
. UMElem -> Maybe DRep
umElemDRep
length :: forall a. UView k a -> Int
length = forall k v. UView k v -> Int
size
nullUMElem :: UMElem -> Bool
nullUMElem :: UMElem -> Bool
nullUMElem = \case
UMElem StrictMaybe RDPair
SNothing Set Ptr
ptrSet StrictMaybe (KeyHash 'StakePool)
SNothing StrictMaybe DRep
SNothing | forall a. Set a -> Bool
Set.null Set Ptr
ptrSet -> Bool
True
UMElem
_ -> Bool
False
nullUMElemMaybe :: UMElem -> Maybe UMElem
nullUMElemMaybe :: UMElem -> Maybe UMElem
nullUMElemMaybe = \case
UMElem
e | UMElem -> Bool
nullUMElem UMElem
e -> forall a. Maybe a
Nothing
UMElem
e -> forall a. a -> Maybe a
Just UMElem
e
empty :: UMap
empty :: UMap
empty = Map (Credential 'Staking) UMElem
-> Map Ptr (Credential 'Staking) -> UMap
UMap forall k a. Map k a
Map.empty forall k a. Map k a
Map.empty
delete' :: k -> UView k v -> UView k v
delete' :: forall k v. k -> UView k v -> UView k v
delete' k
key = \case
RewDepUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems, Map Ptr (Credential 'Staking)
umPtrs :: Map Ptr (Credential 'Staking)
umPtrs :: UMap -> Map Ptr (Credential 'Staking)
umPtrs} -> Map (Credential 'Staking) UMElem
-> Map Ptr (Credential 'Staking)
-> UView (Credential 'Staking) RDPair
rewDepUView (forall k a. Ord k => (a -> Maybe a) -> k -> Map k a -> Map k a
Map.update UMElem -> Maybe UMElem
go k
key Map (Credential 'Staking) UMElem
umElems) Map Ptr (Credential 'Staking)
umPtrs
where
go :: UMElem -> Maybe UMElem
go (UMElem StrictMaybe RDPair
_ Set Ptr
ptrSet StrictMaybe (KeyHash 'StakePool)
sPool StrictMaybe DRep
dRep) = UMElem -> Maybe UMElem
nullUMElemMaybe forall a b. (a -> b) -> a -> b
$ StrictMaybe RDPair
-> Set Ptr
-> StrictMaybe (KeyHash 'StakePool)
-> StrictMaybe DRep
-> UMElem
UMElem forall a. StrictMaybe a
SNothing Set Ptr
ptrSet StrictMaybe (KeyHash 'StakePool)
sPool StrictMaybe DRep
dRep
PtrUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems, Map Ptr (Credential 'Staking)
umPtrs :: Map Ptr (Credential 'Staking)
umPtrs :: UMap -> Map Ptr (Credential 'Staking)
umPtrs} -> case forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup k
key Map Ptr (Credential 'Staking)
umPtrs of
Maybe (Credential 'Staking)
Nothing -> UMap -> UView Ptr (Credential 'Staking)
PtrUView forall a b. (a -> b) -> a -> b
$ Map (Credential 'Staking) UMElem
-> Map Ptr (Credential 'Staking) -> UMap
UMap Map (Credential 'Staking) UMElem
umElems Map Ptr (Credential 'Staking)
umPtrs
Just Credential 'Staking
cred -> Map (Credential 'Staking) UMElem
-> Map Ptr (Credential 'Staking) -> UView Ptr (Credential 'Staking)
ptrUView (forall k a. Ord k => (a -> Maybe a) -> k -> Map k a -> Map k a
Map.update UMElem -> Maybe UMElem
go Credential 'Staking
cred Map (Credential 'Staking) UMElem
umElems) (forall k a. Ord k => k -> Map k a -> Map k a
Map.delete k
key Map Ptr (Credential 'Staking)
umPtrs)
where
go :: UMElem -> Maybe UMElem
go (UMElem StrictMaybe RDPair
rd Set Ptr
ptrSet StrictMaybe (KeyHash 'StakePool)
sPool StrictMaybe DRep
dRep) = UMElem -> Maybe UMElem
nullUMElemMaybe forall a b. (a -> b) -> a -> b
$ StrictMaybe RDPair
-> Set Ptr
-> StrictMaybe (KeyHash 'StakePool)
-> StrictMaybe DRep
-> UMElem
UMElem StrictMaybe RDPair
rd (forall a. Ord a => a -> Set a -> Set a
Set.delete k
key Set Ptr
ptrSet) StrictMaybe (KeyHash 'StakePool)
sPool StrictMaybe DRep
dRep
SPoolUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems, Map Ptr (Credential 'Staking)
umPtrs :: Map Ptr (Credential 'Staking)
umPtrs :: UMap -> Map Ptr (Credential 'Staking)
umPtrs} -> Map (Credential 'Staking) UMElem
-> Map Ptr (Credential 'Staking)
-> UView (Credential 'Staking) (KeyHash 'StakePool)
sPoolUView (forall k a. Ord k => (a -> Maybe a) -> k -> Map k a -> Map k a
Map.update UMElem -> Maybe UMElem
go k
key Map (Credential 'Staking) UMElem
umElems) Map Ptr (Credential 'Staking)
umPtrs
where
go :: UMElem -> Maybe UMElem
go (UMElem StrictMaybe RDPair
rd Set Ptr
ptrSet StrictMaybe (KeyHash 'StakePool)
_ StrictMaybe DRep
dRep) = UMElem -> Maybe UMElem
nullUMElemMaybe forall a b. (a -> b) -> a -> b
$ StrictMaybe RDPair
-> Set Ptr
-> StrictMaybe (KeyHash 'StakePool)
-> StrictMaybe DRep
-> UMElem
UMElem StrictMaybe RDPair
rd Set Ptr
ptrSet forall a. StrictMaybe a
SNothing StrictMaybe DRep
dRep
DRepUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems, Map Ptr (Credential 'Staking)
umPtrs :: Map Ptr (Credential 'Staking)
umPtrs :: UMap -> Map Ptr (Credential 'Staking)
umPtrs} -> Map (Credential 'Staking) UMElem
-> Map Ptr (Credential 'Staking)
-> UView (Credential 'Staking) DRep
dRepUView (forall k a. Ord k => (a -> Maybe a) -> k -> Map k a -> Map k a
Map.update UMElem -> Maybe UMElem
go k
key Map (Credential 'Staking) UMElem
umElems) Map Ptr (Credential 'Staking)
umPtrs
where
go :: UMElem -> Maybe UMElem
go (UMElem StrictMaybe RDPair
rd Set Ptr
ptrSet StrictMaybe (KeyHash 'StakePool)
sPool StrictMaybe DRep
_) = UMElem -> Maybe UMElem
nullUMElemMaybe forall a b. (a -> b) -> a -> b
$ StrictMaybe RDPair
-> Set Ptr
-> StrictMaybe (KeyHash 'StakePool)
-> StrictMaybe DRep
-> UMElem
UMElem StrictMaybe RDPair
rd Set Ptr
ptrSet StrictMaybe (KeyHash 'StakePool)
sPool forall a. StrictMaybe a
SNothing
delete :: k -> UView k v -> UMap
delete :: forall k v. k -> UView k v -> UMap
delete k
k UView k v
m = forall k v. UView k v -> UMap
unUView forall a b. (a -> b) -> a -> b
$ forall k v. k -> UView k v -> UView k v
delete' k
k UView k v
m
insertWith' :: (v -> v -> v) -> k -> v -> UView k v -> UView k v
insertWith' :: forall v k. (v -> v -> v) -> k -> v -> UView k v -> UView k v
insertWith' v -> v -> v
combine k
key v
val = \case
RewDepUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems, Map Ptr (Credential 'Staking)
umPtrs :: Map Ptr (Credential 'Staking)
umPtrs :: UMap -> Map Ptr (Credential 'Staking)
umPtrs} -> Map (Credential 'Staking) UMElem
-> Map Ptr (Credential 'Staking)
-> UView (Credential 'Staking) RDPair
rewDepUView (forall k a.
Ord k =>
(Maybe a -> Maybe a) -> k -> Map k a -> Map k a
Map.alter Maybe UMElem -> Maybe UMElem
go k
key Map (Credential 'Staking) UMElem
umElems) Map Ptr (Credential 'Staking)
umPtrs
where
go :: Maybe UMElem -> Maybe UMElem
go = \case
Maybe UMElem
Nothing -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ StrictMaybe RDPair
-> Set Ptr
-> StrictMaybe (KeyHash 'StakePool)
-> StrictMaybe DRep
-> UMElem
UMElem (forall a. a -> StrictMaybe a
SJust v
val) forall a. Set a
Set.empty forall a. StrictMaybe a
SNothing forall a. StrictMaybe a
SNothing
Just (UMElem StrictMaybe RDPair
SNothing Set Ptr
ptrSet StrictMaybe (KeyHash 'StakePool)
sPool StrictMaybe DRep
dRep) -> UMElem -> Maybe UMElem
nullUMElemMaybe forall a b. (a -> b) -> a -> b
$ StrictMaybe RDPair
-> Set Ptr
-> StrictMaybe (KeyHash 'StakePool)
-> StrictMaybe DRep
-> UMElem
UMElem (forall a. a -> StrictMaybe a
SJust v
val) Set Ptr
ptrSet StrictMaybe (KeyHash 'StakePool)
sPool StrictMaybe DRep
dRep
Just (UMElem (SJust RDPair
old) Set Ptr
ptrSet StrictMaybe (KeyHash 'StakePool)
sPool StrictMaybe DRep
dRep) -> UMElem -> Maybe UMElem
nullUMElemMaybe forall a b. (a -> b) -> a -> b
$ StrictMaybe RDPair
-> Set Ptr
-> StrictMaybe (KeyHash 'StakePool)
-> StrictMaybe DRep
-> UMElem
UMElem (forall a. a -> StrictMaybe a
SJust forall a b. (a -> b) -> a -> b
$ v -> v -> v
combine RDPair
old v
val) Set Ptr
ptrSet StrictMaybe (KeyHash 'StakePool)
sPool StrictMaybe DRep
dRep
PtrUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems, Map Ptr (Credential 'Staking)
umPtrs :: Map Ptr (Credential 'Staking)
umPtrs :: UMap -> Map Ptr (Credential 'Staking)
umPtrs} ->
let
(v
oldCred, v
newCred) = case forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup k
key Map Ptr (Credential 'Staking)
umPtrs of
Maybe (Credential 'Staking)
Nothing -> (v
val, v
val)
Just Credential 'Staking
oldVal -> (Credential 'Staking
oldVal, v -> v -> v
combine Credential 'Staking
oldVal v
val)
newUmElem :: Map v UMElem
newUmElem = forall k a. Ord k => (a -> Maybe a) -> k -> Map k a -> Map k a
Map.update UMElem -> Maybe UMElem
addPtr v
newCred forall a b. (a -> b) -> a -> b
$ forall k a. Ord k => (a -> Maybe a) -> k -> Map k a -> Map k a
Map.update UMElem -> Maybe UMElem
delPtr v
oldCred Map (Credential 'Staking) UMElem
umElems
where
addPtr :: UMElem -> Maybe UMElem
addPtr (UMElem StrictMaybe RDPair
rd Set Ptr
ptrSet StrictMaybe (KeyHash 'StakePool)
sPool StrictMaybe DRep
dRep) = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ StrictMaybe RDPair
-> Set Ptr
-> StrictMaybe (KeyHash 'StakePool)
-> StrictMaybe DRep
-> UMElem
UMElem StrictMaybe RDPair
rd (forall a. Ord a => a -> Set a -> Set a
Set.insert k
key Set Ptr
ptrSet) StrictMaybe (KeyHash 'StakePool)
sPool StrictMaybe DRep
dRep
delPtr :: UMElem -> Maybe UMElem
delPtr (UMElem StrictMaybe RDPair
rd Set Ptr
ptrSet StrictMaybe (KeyHash 'StakePool)
sPool StrictMaybe DRep
dRep) = UMElem -> Maybe UMElem
nullUMElemMaybe forall a b. (a -> b) -> a -> b
$ StrictMaybe RDPair
-> Set Ptr
-> StrictMaybe (KeyHash 'StakePool)
-> StrictMaybe DRep
-> UMElem
UMElem StrictMaybe RDPair
rd (forall a. Ord a => a -> Set a -> Set a
Set.delete k
key Set Ptr
ptrSet) StrictMaybe (KeyHash 'StakePool)
sPool StrictMaybe DRep
dRep
newUmPtr :: Map k v
newUmPtr = forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert k
key v
newCred Map Ptr (Credential 'Staking)
umPtrs
in
UMap -> UView Ptr (Credential 'Staking)
PtrUView forall a b. (a -> b) -> a -> b
$ Map (Credential 'Staking) UMElem
-> Map Ptr (Credential 'Staking) -> UMap
UMap Map v UMElem
newUmElem Map k v
newUmPtr
SPoolUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems, Map Ptr (Credential 'Staking)
umPtrs :: Map Ptr (Credential 'Staking)
umPtrs :: UMap -> Map Ptr (Credential 'Staking)
umPtrs} -> Map (Credential 'Staking) UMElem
-> Map Ptr (Credential 'Staking)
-> UView (Credential 'Staking) (KeyHash 'StakePool)
sPoolUView (forall k a.
Ord k =>
(Maybe a -> Maybe a) -> k -> Map k a -> Map k a
Map.alter Maybe UMElem -> Maybe UMElem
go k
key Map (Credential 'Staking) UMElem
umElems) Map Ptr (Credential 'Staking)
umPtrs
where
go :: Maybe UMElem -> Maybe UMElem
go = \case
Maybe UMElem
Nothing -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ StrictMaybe RDPair
-> Set Ptr
-> StrictMaybe (KeyHash 'StakePool)
-> StrictMaybe DRep
-> UMElem
UMElem forall a. StrictMaybe a
SNothing forall a. Set a
Set.empty (forall a. a -> StrictMaybe a
SJust v
val) forall a. StrictMaybe a
SNothing
Just (UMElem StrictMaybe RDPair
rd Set Ptr
ptrSet StrictMaybe (KeyHash 'StakePool)
SNothing StrictMaybe DRep
dRep) -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ StrictMaybe RDPair
-> Set Ptr
-> StrictMaybe (KeyHash 'StakePool)
-> StrictMaybe DRep
-> UMElem
UMElem StrictMaybe RDPair
rd Set Ptr
ptrSet (forall a. a -> StrictMaybe a
SJust v
val) StrictMaybe DRep
dRep
Just (UMElem StrictMaybe RDPair
rd Set Ptr
ptrSet (SJust KeyHash 'StakePool
old) StrictMaybe DRep
dRep) -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ StrictMaybe RDPair
-> Set Ptr
-> StrictMaybe (KeyHash 'StakePool)
-> StrictMaybe DRep
-> UMElem
UMElem StrictMaybe RDPair
rd Set Ptr
ptrSet (forall a. a -> StrictMaybe a
SJust forall a b. (a -> b) -> a -> b
$ v -> v -> v
combine KeyHash 'StakePool
old v
val) StrictMaybe DRep
dRep
DRepUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems, Map Ptr (Credential 'Staking)
umPtrs :: Map Ptr (Credential 'Staking)
umPtrs :: UMap -> Map Ptr (Credential 'Staking)
umPtrs} -> Map (Credential 'Staking) UMElem
-> Map Ptr (Credential 'Staking)
-> UView (Credential 'Staking) DRep
dRepUView (forall k a.
Ord k =>
(Maybe a -> Maybe a) -> k -> Map k a -> Map k a
Map.alter Maybe UMElem -> Maybe UMElem
go k
key Map (Credential 'Staking) UMElem
umElems) Map Ptr (Credential 'Staking)
umPtrs
where
go :: Maybe UMElem -> Maybe UMElem
go = \case
Maybe UMElem
Nothing -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ StrictMaybe RDPair
-> Set Ptr
-> StrictMaybe (KeyHash 'StakePool)
-> StrictMaybe DRep
-> UMElem
UMElem forall a. StrictMaybe a
SNothing forall a. Set a
Set.empty forall a. StrictMaybe a
SNothing forall a b. (a -> b) -> a -> b
$ forall a. a -> StrictMaybe a
SJust v
val
Just (UMElem StrictMaybe RDPair
rd Set Ptr
ptrSet StrictMaybe (KeyHash 'StakePool)
sPool StrictMaybe DRep
SNothing) -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ StrictMaybe RDPair
-> Set Ptr
-> StrictMaybe (KeyHash 'StakePool)
-> StrictMaybe DRep
-> UMElem
UMElem StrictMaybe RDPair
rd Set Ptr
ptrSet StrictMaybe (KeyHash 'StakePool)
sPool forall a b. (a -> b) -> a -> b
$ forall a. a -> StrictMaybe a
SJust v
val
Just (UMElem StrictMaybe RDPair
rd Set Ptr
ptrSet StrictMaybe (KeyHash 'StakePool)
sPool (SJust DRep
old)) -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ StrictMaybe RDPair
-> Set Ptr
-> StrictMaybe (KeyHash 'StakePool)
-> StrictMaybe DRep
-> UMElem
UMElem StrictMaybe RDPair
rd Set Ptr
ptrSet StrictMaybe (KeyHash 'StakePool)
sPool forall a b. (a -> b) -> a -> b
$ forall a. a -> StrictMaybe a
SJust forall a b. (a -> b) -> a -> b
$ v -> v -> v
combine DRep
old v
val
insertWith :: (v -> v -> v) -> k -> v -> UView k v -> UMap
insertWith :: forall v k. (v -> v -> v) -> k -> v -> UView k v -> UMap
insertWith v -> v -> v
combine k
k v
v UView k v
uview = forall k v. UView k v -> UMap
unUView forall a b. (a -> b) -> a -> b
$ forall v k. (v -> v -> v) -> k -> v -> UView k v -> UView k v
insertWith' v -> v -> v
combine k
k v
v UView k v
uview
insert' :: k -> v -> UView k v -> UView k v
insert' :: forall k v. k -> v -> UView k v -> UView k v
insert' = forall v k. (v -> v -> v) -> k -> v -> UView k v -> UView k v
insertWith' forall a b. (a -> b) -> a -> b
$ \v
_old v
new -> v
new
insert :: k -> v -> UView k v -> UMap
insert :: forall k v. k -> v -> UView k v -> UMap
insert k
k v
v UView k v
uview = forall k v. UView k v -> UMap
unUView forall a b. (a -> b) -> a -> b
$ forall k v. k -> v -> UView k v -> UView k v
insert' k
k v
v UView k v
uview
adjust :: (RDPair -> RDPair) -> k -> UView k RDPair -> UMap
adjust :: forall k. (RDPair -> RDPair) -> k -> UView k RDPair -> UMap
adjust RDPair -> RDPair
f k
k (RewDepUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems, Map Ptr (Credential 'Staking)
umPtrs :: Map Ptr (Credential 'Staking)
umPtrs :: UMap -> Map Ptr (Credential 'Staking)
umPtrs}) = Map (Credential 'Staking) UMElem
-> Map Ptr (Credential 'Staking) -> UMap
UMap (forall k a. Ord k => (a -> a) -> k -> Map k a -> Map k a
Map.adjust UMElem -> UMElem
go k
k Map (Credential 'Staking) UMElem
umElems) Map Ptr (Credential 'Staking)
umPtrs
where
go :: UMElem -> UMElem
go (UMElem (SJust RDPair
rd) Set Ptr
ptrSet StrictMaybe (KeyHash 'StakePool)
sPool StrictMaybe DRep
dRep) = StrictMaybe RDPair
-> Set Ptr
-> StrictMaybe (KeyHash 'StakePool)
-> StrictMaybe DRep
-> UMElem
UMElem (forall a. a -> StrictMaybe a
SJust (RDPair -> RDPair
f RDPair
rd)) Set Ptr
ptrSet StrictMaybe (KeyHash 'StakePool)
sPool StrictMaybe DRep
dRep
go (UMElem StrictMaybe RDPair
SNothing Set Ptr
ptrSet StrictMaybe (KeyHash 'StakePool)
sPool StrictMaybe DRep
dRep) = StrictMaybe RDPair
-> Set Ptr
-> StrictMaybe (KeyHash 'StakePool)
-> StrictMaybe DRep
-> UMElem
UMElem forall a. StrictMaybe a
SNothing Set Ptr
ptrSet StrictMaybe (KeyHash 'StakePool)
sPool StrictMaybe DRep
dRep
lookup :: k -> UView k v -> Maybe v
lookup :: forall k v. k -> UView k v -> Maybe v
lookup k
key = \case
RewDepUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} -> forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup k
key Map (Credential 'Staking) UMElem
umElems forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= UMElem -> Maybe RDPair
umElemRDPair
PtrUView UMap {Map Ptr (Credential 'Staking)
umPtrs :: Map Ptr (Credential 'Staking)
umPtrs :: UMap -> Map Ptr (Credential 'Staking)
umPtrs} -> forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup k
key Map Ptr (Credential 'Staking)
umPtrs
SPoolUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} -> forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup k
key Map (Credential 'Staking) UMElem
umElems forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= UMElem -> Maybe (KeyHash 'StakePool)
umElemSPool
DRepUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} -> forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup k
key Map (Credential 'Staking) UMElem
umElems forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= UMElem -> Maybe DRep
umElemDRep
nullUView :: UView k v -> Bool
nullUView :: forall k a. UView k a -> Bool
nullUView = \case
RewDepUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} -> forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (forall a. Maybe a -> Bool
isNothing forall b c a. (b -> c) -> (a -> b) -> a -> c
. UMElem -> Maybe RDPair
umElemRDPair) Map (Credential 'Staking) UMElem
umElems
PtrUView UMap {Map Ptr (Credential 'Staking)
umPtrs :: Map Ptr (Credential 'Staking)
umPtrs :: UMap -> Map Ptr (Credential 'Staking)
umPtrs} -> forall k a. Map k a -> Bool
Map.null Map Ptr (Credential 'Staking)
umPtrs
SPoolUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} -> forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (forall a. Maybe a -> Bool
isNothing forall b c a. (b -> c) -> (a -> b) -> a -> c
. UMElem -> Maybe (KeyHash 'StakePool)
umElemSPool) Map (Credential 'Staking) UMElem
umElems
DRepUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} -> forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (forall a. Maybe a -> Bool
isNothing forall b c a. (b -> c) -> (a -> b) -> a -> c
. UMElem -> Maybe DRep
umElemDRep) Map (Credential 'Staking) UMElem
umElems
domain :: UView k v -> Set k
domain :: forall k v. UView k v -> Set k
domain = \case
RewDepUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} -> forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Map.foldlWithKey' forall {a}. Ord a => Set a -> a -> UMElem -> Set a
accum forall a. Set a
Set.empty Map (Credential 'Staking) UMElem
umElems
where
accum :: Set a -> a -> UMElem -> Set a
accum Set a
ans a
k (UMElem (SJust RDPair
_) Set Ptr
_ StrictMaybe (KeyHash 'StakePool)
_ StrictMaybe DRep
_) = forall a. Ord a => a -> Set a -> Set a
Set.insert a
k Set a
ans
accum Set a
ans a
_ UMElem
_ = Set a
ans
PtrUView UMap {Map Ptr (Credential 'Staking)
umPtrs :: Map Ptr (Credential 'Staking)
umPtrs :: UMap -> Map Ptr (Credential 'Staking)
umPtrs} -> forall k a. Map k a -> Set k
Map.keysSet Map Ptr (Credential 'Staking)
umPtrs
SPoolUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} -> forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Map.foldlWithKey' forall {a}. Ord a => Set a -> a -> UMElem -> Set a
accum forall a. Set a
Set.empty Map (Credential 'Staking) UMElem
umElems
where
accum :: Set a -> a -> UMElem -> Set a
accum Set a
ans a
k (UMElem StrictMaybe RDPair
_ Set Ptr
_ (SJust KeyHash 'StakePool
_) StrictMaybe DRep
_) = forall a. Ord a => a -> Set a -> Set a
Set.insert a
k Set a
ans
accum Set a
ans a
_ UMElem
_ = Set a
ans
DRepUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} -> forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Map.foldlWithKey' forall {a}. Ord a => Set a -> a -> UMElem -> Set a
accum forall a. Set a
Set.empty Map (Credential 'Staking) UMElem
umElems
where
accum :: Set a -> a -> UMElem -> Set a
accum Set a
ans a
k (UMElem StrictMaybe RDPair
_ Set Ptr
_ StrictMaybe (KeyHash 'StakePool)
_ (SJust DRep
_)) = forall a. Ord a => a -> Set a -> Set a
Set.insert a
k Set a
ans
accum Set a
ans a
_ UMElem
_ = Set a
ans
range :: UView k v -> Set v
range :: forall k v. UView k v -> Set v
range = \case
RewDepUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} -> forall a b k. (a -> b -> a) -> a -> Map k b -> a
Map.foldl' Set RDPair -> UMElem -> Set RDPair
accum forall a. Set a
Set.empty Map (Credential 'Staking) UMElem
umElems
where
accum :: Set RDPair -> UMElem -> Set RDPair
accum Set RDPair
ans (UMElem (SJust RDPair
rd) Set Ptr
_ StrictMaybe (KeyHash 'StakePool)
_ StrictMaybe DRep
_) = forall a. Ord a => a -> Set a -> Set a
Set.insert RDPair
rd Set RDPair
ans
accum Set RDPair
ans UMElem
_ = Set RDPair
ans
PtrUView UMap {Map Ptr (Credential 'Staking)
umPtrs :: Map Ptr (Credential 'Staking)
umPtrs :: UMap -> Map Ptr (Credential 'Staking)
umPtrs} -> forall a. Ord a => [a] -> Set a
Set.fromList forall a b. (a -> b) -> a -> b
$ forall k a. Map k a -> [a]
Map.elems Map Ptr (Credential 'Staking)
umPtrs
SPoolUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} -> forall a b k. (a -> b -> a) -> a -> Map k b -> a
Map.foldl' Set (KeyHash 'StakePool) -> UMElem -> Set (KeyHash 'StakePool)
accum forall a. Set a
Set.empty Map (Credential 'Staking) UMElem
umElems
where
accum :: Set (KeyHash 'StakePool) -> UMElem -> Set (KeyHash 'StakePool)
accum Set (KeyHash 'StakePool)
ans (UMElem StrictMaybe RDPair
_ Set Ptr
_ (SJust KeyHash 'StakePool
sPool) StrictMaybe DRep
_) = forall a. Ord a => a -> Set a -> Set a
Set.insert KeyHash 'StakePool
sPool Set (KeyHash 'StakePool)
ans
accum Set (KeyHash 'StakePool)
ans UMElem
_ = Set (KeyHash 'StakePool)
ans
DRepUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} -> forall a b k. (a -> b -> a) -> a -> Map k b -> a
Map.foldl' Set DRep -> UMElem -> Set DRep
accum forall a. Set a
Set.empty Map (Credential 'Staking) UMElem
umElems
where
accum :: Set DRep -> UMElem -> Set DRep
accum Set DRep
ans (UMElem StrictMaybe RDPair
_ Set Ptr
_ StrictMaybe (KeyHash 'StakePool)
_ (SJust DRep
dRep)) = forall a. Ord a => a -> Set a -> Set a
Set.insert DRep
dRep Set DRep
ans
accum Set DRep
ans UMElem
_ = Set DRep
ans
unionL, (∪) :: UView k v -> (k, v) -> UMap
UView k v
view ∪ :: forall k v. UView k v -> (k, v) -> UMap
∪ (k
k, v
v) = forall v k. (v -> v -> v) -> k -> v -> UView k v -> UMap
insertWith forall a b. a -> b -> a
const k
k v
v UView k v
view
unionL :: forall k v. UView k v -> (k, v) -> UMap
unionL = forall k v. UView k v -> (k, v) -> UMap
(∪)
unionR, (⨃) :: UView k v -> Map k v -> UMap
(RewDepUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems, Map Ptr (Credential 'Staking)
umPtrs :: Map Ptr (Credential 'Staking)
umPtrs :: UMap -> Map Ptr (Credential 'Staking)
umPtrs}) ⨃ :: forall k v. UView k v -> Map k v -> UMap
⨃ Map k v
rightUmap = Map (Credential 'Staking) UMElem
-> Map Ptr (Credential 'Staking) -> UMap
UMap (forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Map.foldlWithKey' forall {k}. Ord k => Map k UMElem -> k -> RDPair -> Map k UMElem
accum Map (Credential 'Staking) UMElem
umElems Map k v
rightUmap) Map Ptr (Credential 'Staking)
umPtrs
where
accum :: Map k UMElem -> k -> RDPair -> Map k UMElem
accum !Map k UMElem
ans k
k (RDPair CompactForm Coin
r CompactForm Coin
_) = forall k a. Ord k => (a -> a) -> k -> Map k a -> Map k a
Map.adjust UMElem -> UMElem
overwrite k
k Map k UMElem
ans
where
overwrite :: UMElem -> UMElem
overwrite (UMElem (SJust (RDPair CompactForm Coin
_ CompactForm Coin
d)) Set Ptr
ptrSet StrictMaybe (KeyHash 'StakePool)
sPool StrictMaybe DRep
dRep) = StrictMaybe RDPair
-> Set Ptr
-> StrictMaybe (KeyHash 'StakePool)
-> StrictMaybe DRep
-> UMElem
UMElem (forall a. a -> StrictMaybe a
SJust (CompactForm Coin -> CompactForm Coin -> RDPair
RDPair CompactForm Coin
r CompactForm Coin
d)) Set Ptr
ptrSet StrictMaybe (KeyHash 'StakePool)
sPool StrictMaybe DRep
dRep
overwrite UMElem
x = UMElem
x
UView k v
view ⨃ Map k v
mp = forall k v. UView k v -> UMap
unUView forall a b. (a -> b) -> a -> b
$ forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Map.foldlWithKey' forall {k} {v}. UView k v -> k -> v -> UView k v
accum UView k v
view Map k v
mp
where
accum :: UView k v -> k -> v -> UView k v
accum UView k v
ans k
k v
v = forall v k. (v -> v -> v) -> k -> v -> UView k v -> UView k v
insertWith' (\v
_old v
new -> v
new) k
k v
v UView k v
ans
unionR :: forall k v. UView k v -> Map k v -> UMap
unionR = forall k v. UView k v -> Map k v -> UMap
(⨃)
unionRewAgg
, (∪+) ::
UView (Credential 'Staking) RDPair ->
Map (Credential 'Staking) (CompactForm Coin) ->
UMap
unionRewAgg :: UView (Credential 'Staking) RDPair
-> Map (Credential 'Staking) (CompactForm Coin) -> UMap
unionRewAgg UView (Credential 'Staking) RDPair
view Map (Credential 'Staking) (CompactForm Coin)
m = forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Map.foldlWithKey' UMap -> Credential 'Staking -> CompactForm Coin -> UMap
accum (forall k v. UView k v -> UMap
unUView UView (Credential 'Staking) RDPair
view) Map (Credential 'Staking) (CompactForm Coin)
m
where
accum :: UMap -> Credential 'Staking -> CompactForm Coin -> UMap
accum UMap
umap Credential 'Staking
key CompactForm Coin
ccoin = forall k. (RDPair -> RDPair) -> k -> UView k RDPair -> UMap
adjust RDPair -> RDPair
combine Credential 'Staking
key (UMap -> UView (Credential 'Staking) RDPair
RewDepUView UMap
umap)
where
combine :: RDPair -> RDPair
combine (RDPair CompactForm Coin
r CompactForm Coin
d) = CompactForm Coin -> CompactForm Coin -> RDPair
RDPair (CompactForm Coin -> CompactForm Coin -> CompactForm Coin
addCompact CompactForm Coin
r CompactForm Coin
ccoin) CompactForm Coin
d
∪+ :: UView (Credential 'Staking) RDPair
-> Map (Credential 'Staking) (CompactForm Coin) -> UMap
(∪+) = UView (Credential 'Staking) RDPair
-> Map (Credential 'Staking) (CompactForm Coin) -> UMap
unionRewAgg
unionKeyDeposits :: UView k RDPair -> Map k (CompactForm Coin) -> UMap
unionKeyDeposits :: forall k. UView k RDPair -> Map k (CompactForm Coin) -> UMap
unionKeyDeposits UView k RDPair
view Map k (CompactForm Coin)
m = forall k v. UView k v -> UMap
unUView forall a b. (a -> b) -> a -> b
$ forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Map.foldlWithKey' forall {k}.
UView k RDPair -> k -> CompactForm Coin -> UView k RDPair
accum UView k RDPair
view Map k (CompactForm Coin)
m
where
accum :: UView k RDPair -> k -> CompactForm Coin -> UView k RDPair
accum UView k RDPair
vw k
key CompactForm Coin
ccoin = forall v k. (v -> v -> v) -> k -> v -> UView k v -> UView k v
insertWith' RDPair -> RDPair -> RDPair
combine k
key (CompactForm Coin -> CompactForm Coin -> RDPair
RDPair (Word64 -> CompactForm Coin
CompactCoin Word64
0) CompactForm Coin
ccoin) UView k RDPair
vw
combine :: RDPair -> RDPair -> RDPair
combine (RDPair CompactForm Coin
r CompactForm Coin
d) (RDPair CompactForm Coin
_ CompactForm Coin
newD) = CompactForm Coin -> CompactForm Coin -> RDPair
RDPair CompactForm Coin
r (CompactForm Coin -> CompactForm Coin -> CompactForm Coin
addCompact CompactForm Coin
d CompactForm Coin
newD)
domDelete, (⋪) :: Set k -> UView k v -> UMap
Set k
set ⋪ :: forall k v. Set k -> UView k v -> UMap
⋪ UView k v
view = forall k v. UView k v -> UMap
unUView (forall a b. (a -> b -> a) -> a -> Set b -> a
Set.foldl' (forall a b c. (a -> b -> c) -> b -> a -> c
flip forall k v. k -> UView k v -> UView k v
delete') UView k v
view Set k
set)
domDelete :: forall k v. Set k -> UView k v -> UMap
domDelete = forall k v. Set k -> UView k v -> UMap
(⋪)
domDeleteAll :: Set (Credential 'Staking) -> UMap -> UMap
domDeleteAll :: Set (Credential 'Staking) -> UMap -> UMap
domDeleteAll Set (Credential 'Staking)
ks UMap
umap = forall a b. (a -> b -> b) -> b -> Set a -> b
Set.foldr' Credential 'Staking -> UMap -> UMap
deleteStakingCredential UMap
umap Set (Credential 'Staking)
ks
deleteStakingCredential :: Credential 'Staking -> UMap -> UMap
deleteStakingCredential :: Credential 'Staking -> UMap -> UMap
deleteStakingCredential Credential 'Staking
cred = forall a b. (a, b) -> b
snd forall b c a. (b -> c) -> (a -> b) -> a -> c
. Credential 'Staking -> UMap -> (Maybe UMElem, UMap)
extractStakingCredential Credential 'Staking
cred
extractStakingCredential :: Credential 'Staking -> UMap -> (Maybe UMElem, UMap)
Credential 'Staking
cred umap :: UMap
umap@UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems, Map Ptr (Credential 'Staking)
umPtrs :: Map Ptr (Credential 'Staking)
umPtrs :: UMap -> Map Ptr (Credential 'Staking)
umPtrs} =
case forall k b. Ord k => k -> Map k b -> (Maybe b, Map k b)
MapExtras.extract Credential 'Staking
cred Map (Credential 'Staking) UMElem
umElems of
(Maybe UMElem
Nothing, Map (Credential 'Staking) UMElem
_) -> (forall a. Maybe a
Nothing, UMap
umap)
(e :: Maybe UMElem
e@(Just (UMElem StrictMaybe RDPair
_ Set Ptr
ptrs StrictMaybe (KeyHash 'StakePool)
_ StrictMaybe DRep
_)), Map (Credential 'Staking) UMElem
umElems') ->
( Maybe UMElem
e
, UMap
{ umElems :: Map (Credential 'Staking) UMElem
umElems = Map (Credential 'Staking) UMElem
umElems'
, umPtrs :: Map Ptr (Credential 'Staking)
umPtrs = Map Ptr (Credential 'Staking)
umPtrs forall k a. Ord k => Map k a -> Set k -> Map k a
`Map.withoutKeys` Set Ptr
ptrs
}
)
rngDelete, (⋫) :: UView k v -> Set v -> UMap
RewDepUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems, Map Ptr (Credential 'Staking)
umPtrs :: Map Ptr (Credential 'Staking)
umPtrs :: UMap -> Map Ptr (Credential 'Staking)
umPtrs} ⋫ :: forall k v. UView k v -> Set v -> UMap
⋫ Set v
rdSet = Map (Credential 'Staking) UMElem
-> Map Ptr (Credential 'Staking) -> UMap
UMap (forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Map.foldlWithKey' Map (Credential 'Staking) UMElem
-> Credential 'Staking
-> UMElem
-> Map (Credential 'Staking) UMElem
accum Map (Credential 'Staking) UMElem
umElems Map (Credential 'Staking) UMElem
umElems) Map Ptr (Credential 'Staking)
umPtrs
where
accum :: Map (Credential 'Staking) UMElem
-> Credential 'Staking
-> UMElem
-> Map (Credential 'Staking) UMElem
accum Map (Credential 'Staking) UMElem
ans Credential 'Staking
key = \case
UMElem (SJust RDPair
rd) Set Ptr
_ StrictMaybe (KeyHash 'StakePool)
_ StrictMaybe DRep
_
| forall a. Ord a => a -> Set a -> Bool
Set.member RDPair
rd Set v
rdSet ->
let go :: UMElem -> Maybe UMElem
go (UMElem StrictMaybe RDPair
_ Set Ptr
ptrSet StrictMaybe (KeyHash 'StakePool)
sPool StrictMaybe DRep
dRep) = UMElem -> Maybe UMElem
nullUMElemMaybe forall a b. (a -> b) -> a -> b
$ StrictMaybe RDPair
-> Set Ptr
-> StrictMaybe (KeyHash 'StakePool)
-> StrictMaybe DRep
-> UMElem
UMElem forall a. StrictMaybe a
SNothing Set Ptr
ptrSet StrictMaybe (KeyHash 'StakePool)
sPool StrictMaybe DRep
dRep
in forall k a. Ord k => (a -> Maybe a) -> k -> Map k a -> Map k a
Map.update UMElem -> Maybe UMElem
go Credential 'Staking
key Map (Credential 'Staking) UMElem
ans
UMElem
_ -> Map (Credential 'Staking) UMElem
ans
PtrUView UMap
um ⋫ Set v
set = forall a b. (a -> b -> a) -> a -> Set b -> a
Set.foldl' UMap -> Credential 'Staking -> UMap
rmCred UMap
um Set v
set
where
rmCred :: UMap -> Credential 'Staking -> UMap
rmCred m :: UMap
m@UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems, Map Ptr (Credential 'Staking)
umPtrs :: Map Ptr (Credential 'Staking)
umPtrs :: UMap -> Map Ptr (Credential 'Staking)
umPtrs} Credential 'Staking
cred = case forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Credential 'Staking
cred Map (Credential 'Staking) UMElem
umElems of
Maybe UMElem
Nothing -> UMap
m
Just (UMElem StrictMaybe RDPair
_ Set Ptr
kset StrictMaybe (KeyHash 'StakePool)
_ StrictMaybe DRep
_) ->
let go :: UMElem -> Maybe UMElem
go (UMElem StrictMaybe RDPair
rd Set Ptr
_ StrictMaybe (KeyHash 'StakePool)
sPool StrictMaybe DRep
dRep) = UMElem -> Maybe UMElem
nullUMElemMaybe forall a b. (a -> b) -> a -> b
$ StrictMaybe RDPair
-> Set Ptr
-> StrictMaybe (KeyHash 'StakePool)
-> StrictMaybe DRep
-> UMElem
UMElem StrictMaybe RDPair
rd forall a. Set a
Set.empty StrictMaybe (KeyHash 'StakePool)
sPool StrictMaybe DRep
dRep
in Map (Credential 'Staking) UMElem
-> Map Ptr (Credential 'Staking) -> UMap
UMap (forall k a. Ord k => (a -> Maybe a) -> k -> Map k a -> Map k a
Map.update UMElem -> Maybe UMElem
go Credential 'Staking
cred Map (Credential 'Staking) UMElem
umElems) (forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr forall k a. Ord k => k -> Map k a -> Map k a
Map.delete Map Ptr (Credential 'Staking)
umPtrs Set Ptr
kset)
SPoolUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems, Map Ptr (Credential 'Staking)
umPtrs :: Map Ptr (Credential 'Staking)
umPtrs :: UMap -> Map Ptr (Credential 'Staking)
umPtrs} ⋫ Set v
sPoolSet = Map (Credential 'Staking) UMElem
-> Map Ptr (Credential 'Staking) -> UMap
UMap (forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Map.foldlWithKey' Map (Credential 'Staking) UMElem
-> Credential 'Staking
-> UMElem
-> Map (Credential 'Staking) UMElem
accum Map (Credential 'Staking) UMElem
umElems Map (Credential 'Staking) UMElem
umElems) Map Ptr (Credential 'Staking)
umPtrs
where
accum :: Map (Credential 'Staking) UMElem
-> Credential 'Staking
-> UMElem
-> Map (Credential 'Staking) UMElem
accum Map (Credential 'Staking) UMElem
ans Credential 'Staking
key = \case
UMElem StrictMaybe RDPair
_ Set Ptr
_ (SJust KeyHash 'StakePool
sPool) StrictMaybe DRep
_
| forall a. Ord a => a -> Set a -> Bool
Set.member KeyHash 'StakePool
sPool Set v
sPoolSet ->
let go :: UMElem -> Maybe UMElem
go (UMElem StrictMaybe RDPair
rd Set Ptr
ptrSet StrictMaybe (KeyHash 'StakePool)
_ StrictMaybe DRep
dRep) = UMElem -> Maybe UMElem
nullUMElemMaybe forall a b. (a -> b) -> a -> b
$ StrictMaybe RDPair
-> Set Ptr
-> StrictMaybe (KeyHash 'StakePool)
-> StrictMaybe DRep
-> UMElem
UMElem StrictMaybe RDPair
rd Set Ptr
ptrSet forall a. StrictMaybe a
SNothing StrictMaybe DRep
dRep
in forall k a. Ord k => (a -> Maybe a) -> k -> Map k a -> Map k a
Map.update UMElem -> Maybe UMElem
go Credential 'Staking
key Map (Credential 'Staking) UMElem
ans
UMElem
_ -> Map (Credential 'Staking) UMElem
ans
DRepUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems, Map Ptr (Credential 'Staking)
umPtrs :: Map Ptr (Credential 'Staking)
umPtrs :: UMap -> Map Ptr (Credential 'Staking)
umPtrs} ⋫ Set v
dRepSet = Map (Credential 'Staking) UMElem
-> Map Ptr (Credential 'Staking) -> UMap
UMap (forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Map.foldlWithKey' Map (Credential 'Staking) UMElem
-> Credential 'Staking
-> UMElem
-> Map (Credential 'Staking) UMElem
accum Map (Credential 'Staking) UMElem
umElems Map (Credential 'Staking) UMElem
umElems) Map Ptr (Credential 'Staking)
umPtrs
where
accum :: Map (Credential 'Staking) UMElem
-> Credential 'Staking
-> UMElem
-> Map (Credential 'Staking) UMElem
accum Map (Credential 'Staking) UMElem
ans Credential 'Staking
key = \case
UMElem StrictMaybe RDPair
_ Set Ptr
_ StrictMaybe (KeyHash 'StakePool)
_ (SJust DRep
dRep)
| forall a. Ord a => a -> Set a -> Bool
Set.member DRep
dRep Set v
dRepSet ->
let go :: UMElem -> Maybe UMElem
go (UMElem StrictMaybe RDPair
rd Set Ptr
ptrSet StrictMaybe (KeyHash 'StakePool)
sPool StrictMaybe DRep
_) = UMElem -> Maybe UMElem
nullUMElemMaybe forall a b. (a -> b) -> a -> b
$ StrictMaybe RDPair
-> Set Ptr
-> StrictMaybe (KeyHash 'StakePool)
-> StrictMaybe DRep
-> UMElem
UMElem StrictMaybe RDPair
rd Set Ptr
ptrSet StrictMaybe (KeyHash 'StakePool)
sPool forall a. StrictMaybe a
SNothing
in forall k a. Ord k => (a -> Maybe a) -> k -> Map k a -> Map k a
Map.update UMElem -> Maybe UMElem
go Credential 'Staking
key Map (Credential 'Staking) UMElem
ans
UMElem
_ -> Map (Credential 'Staking) UMElem
ans
rngDelete :: forall k v. UView k v -> Set v -> UMap
rngDelete = forall k v. UView k v -> Set v -> UMap
(⋫)
member' :: Credential 'Staking -> UMap -> Bool
member' :: Credential 'Staking -> UMap -> Bool
member' Credential 'Staking
k = forall k a. Ord k => k -> Map k a -> Bool
Map.member Credential 'Staking
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. UMap -> Map (Credential 'Staking) UMElem
umElems
member, notMember :: k -> UView k v -> Bool
member :: forall k v. k -> UView k v -> Bool
member k
k = \case
RewDepUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} -> case forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup k
k Map (Credential 'Staking) UMElem
umElems of
Just (UMElem (SJust RDPair
_) Set Ptr
_ StrictMaybe (KeyHash 'StakePool)
_ StrictMaybe DRep
_) -> Bool
True
Maybe UMElem
_ -> Bool
False
PtrUView UMap {Map Ptr (Credential 'Staking)
umPtrs :: Map Ptr (Credential 'Staking)
umPtrs :: UMap -> Map Ptr (Credential 'Staking)
umPtrs} -> forall k a. Ord k => k -> Map k a -> Bool
Map.member k
k Map Ptr (Credential 'Staking)
umPtrs
SPoolUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} -> case forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup k
k Map (Credential 'Staking) UMElem
umElems of
Just (UMElem StrictMaybe RDPair
_ Set Ptr
_ (SJust KeyHash 'StakePool
_) StrictMaybe DRep
_) -> Bool
True
Maybe UMElem
_ -> Bool
False
DRepUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} -> case forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup k
k Map (Credential 'Staking) UMElem
umElems of
Just (UMElem StrictMaybe RDPair
_ Set Ptr
_ StrictMaybe (KeyHash 'StakePool)
_ (SJust DRep
_)) -> Bool
True
Maybe UMElem
_ -> Bool
False
notMember :: forall k v. k -> UView k v -> Bool
notMember k
k UView k v
um = Bool -> Bool
not forall a b. (a -> b) -> a -> b
$ forall k v. k -> UView k v -> Bool
member k
k UView k v
um
(◁), domRestrict :: UView k v -> Map k u -> Map k u
RewDepUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} ◁ :: forall k v u. UView k v -> Map k u -> Map k u
◁ Map k u
m = forall k v2 v1.
Ord k =>
(k -> v2 -> Bool) -> Map k v1 -> Map k v2 -> Map k v1
intersectDomPLeft forall {p}. p -> UMElem -> Bool
p Map k u
m Map (Credential 'Staking) UMElem
umElems
where
p :: p -> UMElem -> Bool
p p
_ (UMElem (SJust RDPair
_) Set Ptr
_ StrictMaybe (KeyHash 'StakePool)
_ StrictMaybe DRep
_) = Bool
True
p p
_ UMElem
_ = Bool
False
PtrUView UMap {Map Ptr (Credential 'Staking)
umPtrs :: Map Ptr (Credential 'Staking)
umPtrs :: UMap -> Map Ptr (Credential 'Staking)
umPtrs} ◁ Map k u
m = forall k a b. Ord k => Map k a -> Map k b -> Map k a
Map.intersection Map k u
m Map Ptr (Credential 'Staking)
umPtrs
SPoolUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} ◁ Map k u
m = forall k v2 v1.
Ord k =>
(k -> v2 -> Bool) -> Map k v1 -> Map k v2 -> Map k v1
intersectDomPLeft forall {p}. p -> UMElem -> Bool
p Map k u
m Map (Credential 'Staking) UMElem
umElems
where
p :: p -> UMElem -> Bool
p p
_ (UMElem StrictMaybe RDPair
_ Set Ptr
_ (SJust KeyHash 'StakePool
_) StrictMaybe DRep
_) = Bool
True
p p
_ UMElem
_ = Bool
False
DRepUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} ◁ Map k u
m = forall k v2 v1.
Ord k =>
(k -> v2 -> Bool) -> Map k v1 -> Map k v2 -> Map k v1
intersectDomPLeft forall {p}. p -> UMElem -> Bool
p Map k u
m Map (Credential 'Staking) UMElem
umElems
where
p :: p -> UMElem -> Bool
p p
_ (UMElem StrictMaybe RDPair
_ Set Ptr
_ StrictMaybe (KeyHash 'StakePool)
_ (SJust DRep
_)) = Bool
True
p p
_ UMElem
_ = Bool
False
domRestrict :: forall k v u. UView k v -> Map k u -> Map k u
domRestrict = forall k v u. UView k v -> Map k u -> Map k u
(◁)
findWithDefault :: v -> k -> UView k v -> v
findWithDefault :: forall v k. v -> k -> UView k v -> v
findWithDefault v
def k
k = forall a. a -> Maybe a -> a
fromMaybe v
def forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k v. k -> UView k v -> Maybe v
lookup k
k
size :: UView k v -> Int
size :: forall k v. UView k v -> Int
size = \case
PtrUView UMap {Map Ptr (Credential 'Staking)
umPtrs :: Map Ptr (Credential 'Staking)
umPtrs :: UMap -> Map Ptr (Credential 'Staking)
umPtrs} -> forall k a. Map k a -> Int
Map.size Map Ptr (Credential 'Staking)
umPtrs
UView k v
x -> forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (\Int
count v
_v -> Int
count forall a. Num a => a -> a -> a
+ Int
1) Int
0 UView k v
x
unify ::
Map (Credential 'Staking) RDPair ->
Map Ptr (Credential 'Staking) ->
Map (Credential 'Staking) (KeyHash 'StakePool) ->
Map (Credential 'Staking) DRep ->
UMap
unify :: Map (Credential 'Staking) RDPair
-> Map Ptr (Credential 'Staking)
-> Map (Credential 'Staking) (KeyHash 'StakePool)
-> Map (Credential 'Staking) DRep
-> UMap
unify Map (Credential 'Staking) RDPair
rd Map Ptr (Credential 'Staking)
ptr Map (Credential 'Staking) (KeyHash 'StakePool)
sPool Map (Credential 'Staking) DRep
dRep = UMap
um4
where
um1 :: UMap
um1 = forall k v. UView k v -> UMap
unUView forall a b. (a -> b) -> a -> b
$ forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Map.foldlWithKey' (\UView (Credential 'Staking) RDPair
um Credential 'Staking
k RDPair
v -> forall k v. k -> v -> UView k v -> UView k v
insert' Credential 'Staking
k RDPair
v UView (Credential 'Staking) RDPair
um) (UMap -> UView (Credential 'Staking) RDPair
RewDepUView UMap
empty) Map (Credential 'Staking) RDPair
rd
um2 :: UMap
um2 = forall k v. UView k v -> UMap
unUView forall a b. (a -> b) -> a -> b
$ forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Map.foldlWithKey' (\UView (Credential 'Staking) (KeyHash 'StakePool)
um Credential 'Staking
k KeyHash 'StakePool
v -> forall k v. k -> v -> UView k v -> UView k v
insert' Credential 'Staking
k KeyHash 'StakePool
v UView (Credential 'Staking) (KeyHash 'StakePool)
um) (UMap -> UView (Credential 'Staking) (KeyHash 'StakePool)
SPoolUView UMap
um1) Map (Credential 'Staking) (KeyHash 'StakePool)
sPool
um3 :: UMap
um3 = forall k v. UView k v -> UMap
unUView forall a b. (a -> b) -> a -> b
$ forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Map.foldlWithKey' (\UView (Credential 'Staking) DRep
um Credential 'Staking
k DRep
v -> forall k v. k -> v -> UView k v -> UView k v
insert' Credential 'Staking
k DRep
v UView (Credential 'Staking) DRep
um) (UMap -> UView (Credential 'Staking) DRep
DRepUView UMap
um2) Map (Credential 'Staking) DRep
dRep
um4 :: UMap
um4 = forall k v. UView k v -> UMap
unUView forall a b. (a -> b) -> a -> b
$ forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Map.foldlWithKey' (\UView Ptr (Credential 'Staking)
um Ptr
k Credential 'Staking
v -> forall k v. k -> v -> UView k v -> UView k v
insert' Ptr
k Credential 'Staking
v UView Ptr (Credential 'Staking)
um) (UMap -> UView Ptr (Credential 'Staking)
PtrUView UMap
um3) Map Ptr (Credential 'Staking)
ptr
addCompact :: CompactForm Coin -> CompactForm Coin -> CompactForm Coin
addCompact :: CompactForm Coin -> CompactForm Coin -> CompactForm Coin
addCompact (CompactCoin Word64
x) (CompactCoin Word64
y) = Word64 -> CompactForm Coin
CompactCoin (Word64
x forall a. Num a => a -> a -> a
+ Word64
y)
sumCompactCoin :: Foldable t => t (CompactForm Coin) -> CompactForm Coin
sumCompactCoin :: forall (t :: * -> *).
Foldable t =>
t (CompactForm Coin) -> CompactForm Coin
sumCompactCoin = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' CompactForm Coin -> CompactForm Coin -> CompactForm Coin
addCompact (Word64 -> CompactForm Coin
CompactCoin Word64
0)
sumRewardsUView :: UView k RDPair -> CompactForm Coin
sumRewardsUView :: forall k. UView k RDPair -> CompactForm Coin
sumRewardsUView = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' CompactForm Coin -> RDPair -> CompactForm Coin
accum (Word64 -> CompactForm Coin
CompactCoin Word64
0)
where
accum :: CompactForm Coin -> RDPair -> CompactForm Coin
accum CompactForm Coin
ans (RDPair CompactForm Coin
r CompactForm Coin
_) = CompactForm Coin -> CompactForm Coin -> CompactForm Coin
addCompact CompactForm Coin
ans CompactForm Coin
r
sumDepositUView :: UView k RDPair -> CompactForm Coin
sumDepositUView :: forall k. UView k RDPair -> CompactForm Coin
sumDepositUView = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' CompactForm Coin -> RDPair -> CompactForm Coin
accum (Word64 -> CompactForm Coin
CompactCoin Word64
0)
where
accum :: CompactForm Coin -> RDPair -> CompactForm Coin
accum CompactForm Coin
ans (RDPair CompactForm Coin
_ CompactForm Coin
d) = CompactForm Coin -> CompactForm Coin -> CompactForm Coin
addCompact CompactForm Coin
ans CompactForm Coin
d