Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GetUTxO to the shelley QueryLedger instance #2110

Merged
merged 1 commit into from May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -316,6 +316,8 @@ instance TPraosCrypto c => QueryLedger (ShelleyBlock c) where
GetFilteredUTxO
:: Set (SL.Addr c)
-> Query (ShelleyBlock c) (SL.UTxO c)
GetUTxO
:: Query (ShelleyBlock c) (SL.UTxO c)

answerQuery cfg query st = case query of
GetLedgerTip -> ledgerTip st
Expand All @@ -326,6 +328,7 @@ instance TPraosCrypto c => QueryLedger (ShelleyBlock c) where
GetProposedPParamsUpdates -> getProposedPPUpdates $ shelleyState st
GetStakeDistribution -> SL.nesPd $ shelleyState st
GetFilteredUTxO addrs -> SL.getFilteredUTxO (shelleyState st) addrs
GetUTxO -> SL.getUTxO $ shelleyState st
where
globals = shelleyLedgerGlobals cfg

Expand Down Expand Up @@ -363,6 +366,11 @@ instance TPraosCrypto c => QueryLedger (ShelleyBlock c) where
= Nothing
eqQuery (GetFilteredUTxO _) _
= Nothing
eqQuery GetUTxO GetUTxO
= Just Refl
eqQuery GetUTxO _
= Nothing


deriving instance Eq (Query (ShelleyBlock c) result)
deriving instance Show (Query (ShelleyBlock c) result)
Expand All @@ -375,6 +383,7 @@ instance Crypto c => ShowQuery (Query (ShelleyBlock c)) where
showResult GetProposedPParamsUpdates = show
showResult GetStakeDistribution = show
showResult (GetFilteredUTxO {}) = show
showResult GetUTxO = show

{-------------------------------------------------------------------------------
ValidateEnvelope
Expand Down Expand Up @@ -468,6 +477,8 @@ encodeShelleyQuery query = case query of
CBOR.encodeListLen 1 <> CBOR.encodeWord8 5
GetFilteredUTxO addrs ->
CBOR.encodeListLen 2 <> CBOR.encodeWord8 6 <> toCBOR addrs
GetUTxO ->
CBOR.encodeListLen 1 <> CBOR.encodeWord8 7
Jimbo4350 marked this conversation as resolved.
Show resolved Hide resolved

decodeShelleyQuery :: Crypto c => Decoder s (Some (Query (ShelleyBlock c)))
decodeShelleyQuery = do
Expand All @@ -481,6 +492,7 @@ decodeShelleyQuery = do
(1, 4) -> return $ Some GetProposedPParamsUpdates
(1, 5) -> return $ Some GetStakeDistribution
(2, 6) -> Some . GetFilteredUTxO <$> fromCBOR
(1, 7) -> return $ Some GetUTxO
_ -> fail $
"decodeShelleyQuery: invalid (len, tag): (" <>
show len <> ", " <> show tag <> ")"
Expand All @@ -496,6 +508,7 @@ encodeShelleyResult query = case query of
GetProposedPParamsUpdates -> toCBOR
GetStakeDistribution -> toCBOR
GetFilteredUTxO {} -> toCBOR
GetUTxO -> toCBOR

decodeShelleyResult
:: Crypto c
Expand All @@ -509,3 +522,4 @@ decodeShelleyResult query = case query of
GetProposedPParamsUpdates -> fromCBOR
GetStakeDistribution -> fromCBOR
GetFilteredUTxO {} -> fromCBOR
GetUTxO -> fromCBOR
Expand Up @@ -624,5 +624,7 @@ instance Eq (Some (Query Block)) where
Some (GetFilteredUTxO addrs) == Some (GetFilteredUTxO addrs') =
addrs == addrs'
Some (GetFilteredUTxO _) == _ = False
Some GetUTxO == Some GetUTxO = True
Some GetUTxO == _ = False

deriving instance Show (Some (Query Block))