Skip to content

Commit

Permalink
Added GetAccountState query
Browse files Browse the repository at this point in the history
  • Loading branch information
Soupstraw committed May 3, 2024
1 parent f25ea0b commit 86a7896
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Breaking

- Add `GetAccountState` query

Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ import Ouroboros.Consensus.Shelley.Protocol.Abstract (ProtoCrypto)
import Ouroboros.Consensus.Util (ShowProxy (..))
import Ouroboros.Network.Block (Serialised (..), decodePoint,
encodePoint, mkSerialised)
import Cardano.Ledger.Shelley.LedgerState (AccountState)

{-------------------------------------------------------------------------------
QueryLedger
Expand Down Expand Up @@ -297,6 +298,9 @@ data instance BlockQuery (ShelleyBlock proto era) :: Type -> Type where
-- longer used (because mainnet has hard-forked to a newer version), it can be
-- removed.

GetAccountState
:: BlockQuery (ShelleyBlock proto era) AccountState

instance (Typeable era, Typeable proto)
=> ShowProxy (BlockQuery (ShelleyBlock proto era)) where

Expand Down Expand Up @@ -434,6 +438,8 @@ instance (ShelleyCompatible proto era, ProtoCrypto proto ~ crypto)
SL.queryCommitteeMembersState coldCreds hotCreds statuses st
GetFilteredVoteDelegatees stakeCreds ->
getFilteredVoteDelegatees st stakeCreds
GetAccountState ->
SL.queryAccountState st
where
lcfg = configLedger $ getExtLedgerCfg cfg
globals = shelleyLedgerGlobals lcfg
Expand Down Expand Up @@ -585,6 +591,8 @@ instance SameDepIndex (BlockQuery (ShelleyBlock proto era)) where
| otherwise
= Nothing
sameDepIndex GetFilteredVoteDelegatees {} _ = Nothing
sameDepIndex GetAccountState {} GetAccountState {} = Just Refl
sameDepIndex GetAccountState {} _ = Nothing

deriving instance Eq (BlockQuery (ShelleyBlock proto era) result)
deriving instance Show (BlockQuery (ShelleyBlock proto era) result)
Expand Down Expand Up @@ -620,6 +628,7 @@ instance ShelleyCompatible proto era => ShowQuery (BlockQuery (ShelleyBlock prot
GetDRepStakeDistr {} -> show
GetCommitteeMembersState {} -> show
GetFilteredVoteDelegatees {} -> show
GetAccountState {} -> show

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

decodeShelleyQuery ::
forall era proto. ShelleyBasedEra era
Expand Down Expand Up @@ -830,6 +842,7 @@ decodeShelleyQuery = do
return $ SomeSecond $ GetCommitteeMembersState coldCreds hotCreds statuses
(2, 28) -> requireCG $ do
SomeSecond . GetFilteredVoteDelegatees <$> LC.fromEraCBOR @era
(1, 29) -> requireCG $ return $ SomeSecond GetAccountState
_ -> failmsg "invalid"

encodeShelleyResult ::
Expand Down Expand Up @@ -866,6 +879,7 @@ encodeShelleyResult v query = case query of
GetDRepStakeDistr {} -> LC.toEraCBOR @era
GetCommitteeMembersState {} -> LC.toEraCBOR @era
GetFilteredVoteDelegatees {} -> LC.toEraCBOR @era
GetAccountState {} -> LC.toEraCBOR @era

decodeShelleyResult ::
forall proto era result. ShelleyCompatible proto era
Expand Down Expand Up @@ -902,6 +916,7 @@ decodeShelleyResult v query = case query of
GetDRepStakeDistr {} -> LC.fromEraCBOR @era
GetCommitteeMembersState {} -> LC.fromEraCBOR @era
GetFilteredVoteDelegatees {} -> LC.fromEraCBOR @era
GetAccountState {} -> LC.fromEraCBOR @era

currentPParamsEnDecoding ::
forall era s.
Expand Down

0 comments on commit 86a7896

Please sign in to comment.