@@ -53,7 +53,6 @@ import qualified Data.Text.IO as Text
53
53
import Data.Text.Lazy.Builder (toLazyText )
54
54
import Data.Time.Clock
55
55
import qualified Data.Vector as Vector
56
- import qualified Data.VMap as VMap
57
56
import Formatting.Buildable (build )
58
57
import Numeric (showEFloat )
59
58
import qualified System.IO as IO
@@ -75,18 +74,14 @@ import qualified Cardano.Crypto.Hash.Blake2b as Blake2b
75
74
import qualified Cardano.Crypto.VRF as Crypto
76
75
import qualified Cardano.Ledger.Alonzo.PParams as Alonzo
77
76
import Cardano.Ledger.BaseTypes (Seed , UnitInterval )
78
- import Cardano.Ledger.Coin
79
- import Cardano.Ledger.Compactible
80
77
import qualified Cardano.Ledger.Core as Core
81
78
import qualified Cardano.Ledger.Credential as Ledger
82
79
import qualified Cardano.Ledger.Crypto as Crypto
83
80
import qualified Cardano.Ledger.Era as Era
84
81
import qualified Cardano.Ledger.Era as Ledger
85
82
import Cardano.Ledger.Keys (KeyHash (.. ), KeyRole (.. ))
86
83
import Cardano.Ledger.Shelley.Constraints
87
- import Cardano.Ledger.Shelley.EpochBoundary
88
- import Cardano.Ledger.Shelley.LedgerState (EpochState (esSnapshots ),
89
- NewEpochState (nesEs ), PState (_fPParams , _pParams , _retiring ))
84
+ import Cardano.Ledger.Shelley.LedgerState (PState (_fPParams , _pParams , _retiring ))
90
85
import qualified Cardano.Ledger.Shelley.LedgerState as SL
91
86
import qualified Cardano.Ledger.Shelley.PParams as Shelley
92
87
import Cardano.Ledger.Shelley.Scripts ()
@@ -134,6 +129,7 @@ data ShelleyQueryCmdError
134
129
FilePath
135
130
-- ^ Operational certificate of the unknown stake pool.
136
131
| ShelleyQueryCmdPoolStateDecodeError DecoderError
132
+ | ShelleyQueryCmdStakeSnapshotDecodeError DecoderError
137
133
138
134
deriving Show
139
135
@@ -171,6 +167,8 @@ renderShelleyQueryCmdError err =
171
167
" in the current epoch, you must wait until the following epoch for the registration to take place."
172
168
ShelleyQueryCmdPoolStateDecodeError decoderError ->
173
169
" Failed to decode PoolState. Error: " <> Text. pack (show decoderError)
170
+ ShelleyQueryCmdStakeSnapshotDecodeError decoderError ->
171
+ " Failed to decode StakeSnapshot. Error: " <> Text. pack (show decoderError)
174
172
175
173
runQueryCmd :: QueryCmd -> ExceptT ShelleyQueryCmdError IO ()
176
174
runQueryCmd cmd =
@@ -629,7 +627,7 @@ runQueryStakeSnapshot
629
627
-> NetworkId
630
628
-> Hash StakePoolKey
631
629
-> ExceptT ShelleyQueryCmdError IO ()
632
- runQueryStakeSnapshot (AnyConsensusModeParams cModeParams) network poolid = do
630
+ runQueryStakeSnapshot (AnyConsensusModeParams cModeParams) network poolId = do
633
631
SocketPath sockPath <- firstExceptT ShelleyQueryCmdEnvVarSocketErr readEnvSocketPath
634
632
let localNodeConnInfo = LocalNodeConnectInfo cModeParams network sockPath
635
633
@@ -640,9 +638,9 @@ runQueryStakeSnapshot (AnyConsensusModeParams cModeParams) network poolid = do
640
638
eInMode <- toEraInMode era cMode
641
639
& hoistMaybe (ShelleyQueryCmdEraConsensusModeMismatch (AnyConsensusMode cMode) anyE)
642
640
643
- let qInMode = QueryInEra eInMode . QueryInShelleyBasedEra sbe $ QueryDebugLedgerState
641
+ let qInMode = QueryInEra eInMode . QueryInShelleyBasedEra sbe $ QueryStakeSnapshot poolId
644
642
result <- executeQuery era cModeParams localNodeConnInfo qInMode
645
- obtainLedgerEraClassConstraints sbe ( writeStakeSnapshot poolid) result
643
+ obtainLedgerEraClassConstraints sbe writeStakeSnapshot result
646
644
647
645
648
646
runQueryLedgerState
@@ -794,44 +792,15 @@ writeLedgerState mOutFile qState@(SerialisedDebugLedgerState serLedgerState) =
794
792
writeStakeSnapshot :: forall era ledgerera . ()
795
793
=> ShelleyLedgerEra era ~ ledgerera
796
794
=> Era. Crypto ledgerera ~ StandardCrypto
797
- => FromCBOR (DebugLedgerState era )
798
- => PoolId
799
- -> SerialisedDebugLedgerState era
795
+ => SerialisedStakeSnapshots era
800
796
-> ExceptT ShelleyQueryCmdError IO ()
801
- writeStakeSnapshot (StakePoolKeyHash hk) qState =
802
- case decodeDebugLedgerState qState of
803
- -- In the event of decode failure print the CBOR instead
804
- Left bs -> firstExceptT ShelleyQueryCmdHelpersError $ pPrintCBOR bs
805
-
806
- Right ledgerState -> do
807
- -- Ledger State
808
- let (DebugLedgerState snapshot) = ledgerState
809
-
810
- -- The three stake snapshots, obtained from the ledger state
811
- let (SnapShots markS setS goS _) = esSnapshots $ nesEs snapshot
797
+ writeStakeSnapshot qState =
798
+ case decodeStakeSnapshot qState of
799
+ Left err -> left (ShelleyQueryCmdStakeSnapshotDecodeError err)
812
800
801
+ Right (StakeSnapshot snapshot) -> do
813
802
-- Calculate the three pool and active stake values for the given pool
814
- liftIO . LBS. putStrLn $ encodePretty $ Stakes
815
- { markPool = getPoolStake hk markS
816
- , setPool = getPoolStake hk setS
817
- , goPool = getPoolStake hk goS
818
- , markTotal = getAllStake markS
819
- , setTotal = getAllStake setS
820
- , goTotal = getAllStake goS
821
- }
822
-
823
- -- | Sum all the stake that is held by the pool
824
- getPoolStake :: KeyHash Cardano.Ledger.Keys. StakePool crypto -> SnapShot crypto -> Integer
825
- getPoolStake hash ss = pStake
826
- where
827
- Coin pStake = fold (Map. map fromCompact $ VMap. toMap s)
828
- Stake s = poolStake hash (_delegations ss) (_stake ss)
829
-
830
- -- | Sum the active stake from a snapshot
831
- getAllStake :: SnapShot crypto -> Integer
832
- getAllStake (SnapShot stake _ _) = activeStake
833
- where
834
- Coin activeStake = fold (fmap fromCompact (VMap. toMap (unStake stake)))
803
+ liftIO . LBS. putStrLn $ encodePretty snapshot
835
804
836
805
-- | This function obtains the pool parameters, equivalent to the following jq query on the output of query ledger-state
837
806
-- .nesEs.esLState._delegationState._pstate._pParams.<pool_id>
0 commit comments