Skip to content

Commit 720a430

Browse files
committed
Added GetAccountState query
1 parent f25ea0b commit 720a430

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
### Breaking
2+
3+
- Add `GetAccountState` query
4+

ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger/Query.hs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import qualified Cardano.Ledger.EpochBoundary as SL
4545
import Cardano.Ledger.Keys (KeyHash, KeyRole (..))
4646
import qualified Cardano.Ledger.Shelley.API as SL
4747
import qualified Cardano.Ledger.Shelley.Core as LC
48+
import Cardano.Ledger.Shelley.LedgerState (AccountState)
4849
import qualified Cardano.Ledger.Shelley.LedgerState as SL (RewardAccounts,
4950
newEpochStateGovStateL)
5051
import qualified Cardano.Ledger.Shelley.PParams as SL (emptyPPPUpdates)
@@ -283,6 +284,9 @@ data instance BlockQuery (ShelleyBlock proto era) :: Type -> Type where
283284
=> Set (SL.Credential 'SL.Staking (EraCrypto era))
284285
-> BlockQuery (ShelleyBlock proto era) (VoteDelegatees (EraCrypto era))
285286

287+
GetAccountState
288+
:: BlockQuery (ShelleyBlock proto era) AccountState
289+
286290
-- WARNING: please add new queries to the end of the list and stick to this
287291
-- order in all other pattern matches on queries. This helps in particular
288292
-- with the en/decoders, as we want the CBOR tags to be ordered.
@@ -434,6 +438,8 @@ instance (ShelleyCompatible proto era, ProtoCrypto proto ~ crypto)
434438
SL.queryCommitteeMembersState coldCreds hotCreds statuses st
435439
GetFilteredVoteDelegatees stakeCreds ->
436440
getFilteredVoteDelegatees st stakeCreds
441+
GetAccountState ->
442+
SL.queryAccountState st
437443
where
438444
lcfg = configLedger $ getExtLedgerCfg cfg
439445
globals = shelleyLedgerGlobals lcfg
@@ -585,6 +591,8 @@ instance SameDepIndex (BlockQuery (ShelleyBlock proto era)) where
585591
| otherwise
586592
= Nothing
587593
sameDepIndex GetFilteredVoteDelegatees {} _ = Nothing
594+
sameDepIndex GetAccountState {} GetAccountState {} = Just Refl
595+
sameDepIndex GetAccountState {} _ = Nothing
588596

589597
deriving instance Eq (BlockQuery (ShelleyBlock proto era) result)
590598
deriving instance Show (BlockQuery (ShelleyBlock proto era) result)
@@ -620,6 +628,7 @@ instance ShelleyCompatible proto era => ShowQuery (BlockQuery (ShelleyBlock prot
620628
GetDRepStakeDistr {} -> show
621629
GetCommitteeMembersState {} -> show
622630
GetFilteredVoteDelegatees {} -> show
631+
GetAccountState {} -> show
623632

624633
-- | Is the given query supported by the given 'ShelleyNodeToClientVersion'?
625634
querySupportedVersion :: BlockQuery (ShelleyBlock proto era) result -> ShelleyNodeToClientVersion -> Bool
@@ -653,6 +662,7 @@ querySupportedVersion = \case
653662
GetDRepStakeDistr {} -> (>= v8)
654663
GetCommitteeMembersState {} -> (>= v8)
655664
GetFilteredVoteDelegatees {} -> (>= v8)
665+
GetAccountState {} -> (>= v8)
656666
-- WARNING: when adding a new query, a new @ShelleyNodeToClientVersionX@
657667
-- must be added. See #2830 for a template on how to do this.
658668
where
@@ -774,6 +784,8 @@ encodeShelleyQuery query = case query of
774784
CBOR.encodeListLen 4 <> CBOR.encodeWord8 27 <> toCBOR coldCreds <> toCBOR hotCreds <> LC.toEraCBOR @era statuses
775785
GetFilteredVoteDelegatees stakeCreds ->
776786
CBOR.encodeListLen 2 <> CBOR.encodeWord8 28 <> LC.toEraCBOR @era stakeCreds
787+
GetAccountState ->
788+
CBOR.encodeListLen 1 <> CBOR.encodeWord8 29
777789

778790
decodeShelleyQuery ::
779791
forall era proto. ShelleyBasedEra era
@@ -830,6 +842,7 @@ decodeShelleyQuery = do
830842
return $ SomeSecond $ GetCommitteeMembersState coldCreds hotCreds statuses
831843
(2, 28) -> requireCG $ do
832844
SomeSecond . GetFilteredVoteDelegatees <$> LC.fromEraCBOR @era
845+
(1, 29) -> return $ SomeSecond GetAccountState
833846
_ -> failmsg "invalid"
834847

835848
encodeShelleyResult ::
@@ -866,6 +879,7 @@ encodeShelleyResult v query = case query of
866879
GetDRepStakeDistr {} -> LC.toEraCBOR @era
867880
GetCommitteeMembersState {} -> LC.toEraCBOR @era
868881
GetFilteredVoteDelegatees {} -> LC.toEraCBOR @era
882+
GetAccountState {} -> LC.toEraCBOR @era
869883

870884
decodeShelleyResult ::
871885
forall proto era result. ShelleyCompatible proto era
@@ -902,6 +916,7 @@ decodeShelleyResult v query = case query of
902916
GetDRepStakeDistr {} -> LC.fromEraCBOR @era
903917
GetCommitteeMembersState {} -> LC.fromEraCBOR @era
904918
GetFilteredVoteDelegatees {} -> LC.fromEraCBOR @era
919+
GetAccountState {} -> LC.fromEraCBOR @era
905920

906921
currentPParamsEnDecoding ::
907922
forall era s.

0 commit comments

Comments
 (0)