Skip to content

Commit

Permalink
Tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Apr 13, 2021
1 parent dc37517 commit 6b4456c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 30 deletions.
32 changes: 12 additions & 20 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -463,22 +463,15 @@ writeStakeSnapshot poolId qState =
let (SnapShots markS setS goS _) = esSnapshots $ nesEs snapshot

-- Calculate the three pool and active stake values for the given pool
let markStake = getPoolStake hk markS
let setStake = getPoolStake hk setS
let goStake = getPoolStake hk goS

let markTotal = getAllStake markS
let setTotal = getAllStake setS
let goTotal = getAllStake goS

liftIO . LBS.putStrLn $ encodePretty $ Stakes
{ markpool = markStake
, setpool = setStake
, gopool = goStake
, marktot = markTotal
, settot = setTotal
, gotot = goTotal
{ markPool = getPoolStake hk markS
, setPool = getPoolStake hk setS
, goPool = getPoolStake hk goS
, markTotal = getAllStake markS
, setTotal = getAllStake setS
, goTotal = getAllStake goS
}

Nothing -> left $ ShelleyQueryCmdPoolIdError poolId

-- | Sum all the stake that is held by the pool
Expand Down Expand Up @@ -514,17 +507,16 @@ writePoolParams poolId qState =
case KeyHash <$> hashFromStringAsHex (filter (/= '"') (show poolId)) of
Just hk -> do
-- Pool parameters
let poolparams = Map.lookup hk $ _pParams poolState
let fpoolparams = Map.lookup hk $ _fPParams poolState
let poolParams = Map.lookup hk $ _pParams poolState
let fPoolParams = Map.lookup hk $ _fPParams poolState
let retiring = Map.lookup hk $ _retiring poolState

liftIO . LBS.putStrLn $ encodePretty $ Params poolparams fpoolparams retiring
liftIO . LBS.putStrLn $ encodePretty $ Params poolParams fPoolParams retiring

Nothing -> left $ ShelleyQueryCmdPoolIdError poolId

decodeLedgerState ::
forall era.
FromCBOR (LedgerState era)
decodeLedgerState :: forall era. ()
=> FromCBOR (LedgerState era)
=> SerialisedLedgerState era
-> Either LBS.ByteString (LedgerState era)
decodeLedgerState (SerialisedLedgerState (Serialised ls)) = first (const ls) (decodeFull ls)
Expand Down
22 changes: 12 additions & 10 deletions cardano-cli/src/Cardano/CLI/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,19 @@ data QueryFilter
deriving (Eq, Show)

-- | This data structure is used to allow nicely formatted output within the query stake-snapshot command.
-- "markpool", "setpool", "gopool" are the three ledger state stake snapshots (most recent to least recent)
--
-- "markPool", "setPool", "goPool" are the three ledger state stake snapshots (from most recent to least recent)
-- go is the snapshot that is used for the current epoch, set will be used in the next epoch,
-- mark for the epoch after that. "marktot", "setttot", "gotot" record the total active stake for each snapshot
-- mark for the epoch after that. "markTotal", "setTotal", "goTotal" record the total active stake for each snapshot.
--
-- This information can be used by community tools to calculate upcoming leader schedules.
data Stakes = Stakes
{ markpool :: Integer
, setpool :: Integer
, gopool :: Integer
, marktot :: Integer
, settot :: Integer
, gotot :: Integer
{ markPool :: Integer
, setPool :: Integer
, goPool :: Integer
, markTotal :: Integer
, setTotal :: Integer
, goTotal :: Integer
} deriving Show

-- | Pretty printing for stake information
Expand All @@ -108,8 +110,8 @@ instance ToJSON Stakes where
-- params are the current pool parameter settings, futureparams are new parameters, retiringEpoch is the
-- epoch that has been set for pool retirement. Any of these may be Nothing.
data Params crypto = Params
{ poolparameters :: Maybe (PoolParams crypto)
, futurepoolparameters :: Maybe (PoolParams crypto)
{ poolParameters :: Maybe (PoolParams crypto)
, futurePoolParameters :: Maybe (PoolParams crypto)
, retiringEpoch :: Maybe EpochNo
} deriving Show

Expand Down

0 comments on commit 6b4456c

Please sign in to comment.