From 5003af5ede1277fc170fb1854cefd30dfee19f93 Mon Sep 17 00:00:00 2001 From: Joanna Dyczka Date: Tue, 15 Oct 2024 11:19:57 +0200 Subject: [PATCH] [#1951] return isScriptBased flag from BE for listDReps and getDRepInfo --- govtool/backend/sql/get-drep-info.sql | 11 +++++++++++ govtool/backend/sql/list-dreps.sql | 2 ++ govtool/backend/src/VVA/API.hs | 6 ++++-- govtool/backend/src/VVA/API/Types.hs | 6 ++++-- govtool/backend/src/VVA/DRep.hs | 11 +++++++---- govtool/backend/src/VVA/Types.hs | 4 +++- 6 files changed, 31 insertions(+), 9 deletions(-) diff --git a/govtool/backend/sql/get-drep-info.sql b/govtool/backend/sql/get-drep-info.sql index ca4505d6c..24321095d 100644 --- a/govtool/backend/sql/get-drep-info.sql +++ b/govtool/backend/sql/get-drep-info.sql @@ -34,6 +34,15 @@ LatestRegistrationEntry AS ( drep_registration.tx_id DESC LIMIT 1 ), +IsScriptHash AS ( + SELECT + drep_hash.has_script AS value + FROM + drep_hash + CROSS JOIN DRepId + WHERE + drep_hash.raw = DRepId.raw +), IsRegisteredAsDRep AS ( SELECT (LatestRegistrationEntry.deposit IS NULL @@ -165,6 +174,7 @@ SoleVoterRetire AS ( LIMIT 1 ) SELECT + IsScriptHash.value, IsRegisteredAsDRep.value, WasRegisteredAsDRep.value, IsRegisteredAsSoleVoter.value, @@ -197,5 +207,6 @@ FROM CROSS JOIN SoleVoterRegister CROSS JOIN SoleVoterRetire CROSS JOIN LatestRegistrationEntry + CROSS JOIN IsScriptHash LEFT JOIN off_chain_vote_data ON off_chain_vote_data.voting_anchor_id = LatestRegistrationEntry.voting_anchor_id LEFT JOIN off_chain_vote_drep_data ON off_chain_vote_drep_data.off_chain_vote_data_id = off_chain_vote_data.id diff --git a/govtool/backend/sql/list-dreps.sql b/govtool/backend/sql/list-dreps.sql index 2ae88d72b..170b148ca 100644 --- a/govtool/backend/sql/list-dreps.sql +++ b/govtool/backend/sql/list-dreps.sql @@ -21,6 +21,7 @@ DRepActivity AS ( SELECT encode(dh.raw, 'hex'), dh.view, + dh.has_script, va.url, encode(va.data_hash, 'hex'), dr_deposit.deposit, @@ -130,6 +131,7 @@ GROUP BY dh.raw, second_to_newest_drep_registration.voting_anchor_id, dh.view, + dh.has_script, va.url, va.data_hash, dr_deposit.deposit, diff --git a/govtool/backend/src/VVA/API.hs b/govtool/backend/src/VVA/API.hs index 36c6551bc..29c62a210 100644 --- a/govtool/backend/src/VVA/API.hs +++ b/govtool/backend/src/VVA/API.hs @@ -106,7 +106,8 @@ mapDRepStatus Types.Inactive = Inactive drepRegistrationToDrep :: Types.DRepRegistration -> DRep drepRegistrationToDrep Types.DRepRegistration {..} = DRep - { dRepDrepId = DRepHash dRepRegistrationDRepHash, + { dRepIsScriptBased = dRepRegistrationIsScriptBased, + dRepDrepId = DRepHash dRepRegistrationDRepHash, dRepView = dRepRegistrationView, dRepUrl = dRepRegistrationUrl, dRepMetadataHash = dRepRegistrationDataHash, @@ -286,7 +287,8 @@ drepInfo (unHexText -> dRepId) = do CacheEnv {dRepInfoCache} <- asks vvaCache Types.DRepInfo {..} <- cacheRequest dRepInfoCache dRepId $ DRep.getDRepInfo dRepId return $ DRepInfoResponse - { dRepInfoResponseIsRegisteredAsDRep = dRepInfoIsRegisteredAsDRep + { dRepInfoResponseIsScriptBased = dRepInfoIsScriptBased + , dRepInfoResponseIsRegisteredAsDRep = dRepInfoIsRegisteredAsDRep , dRepInfoResponseWasRegisteredAsDRep = dRepInfoWasRegisteredAsDRep , dRepInfoResponseIsRegisteredAsSoleVoter = dRepInfoIsRegisteredAsSoleVoter , dRepInfoResponseWasRegisteredAsSoleVoter = dRepInfoWasRegisteredAsSoleVoter diff --git a/govtool/backend/src/VVA/API/Types.hs b/govtool/backend/src/VVA/API/Types.hs index 68b23fc94..1d312cad2 100644 --- a/govtool/backend/src/VVA/API/Types.hs +++ b/govtool/backend/src/VVA/API/Types.hs @@ -561,7 +561,8 @@ instance ToSchema VoteResponse where data DRepInfoResponse = DRepInfoResponse - { dRepInfoResponseIsRegisteredAsDRep :: Bool + { dRepInfoResponseIsScriptBased :: Bool + , dRepInfoResponseIsRegisteredAsDRep :: Bool , dRepInfoResponseWasRegisteredAsDRep :: Bool , dRepInfoResponseIsRegisteredAsSoleVoter :: Bool , dRepInfoResponseWasRegisteredAsSoleVoter :: Bool @@ -758,7 +759,8 @@ instance ToSchema DRepType where data DRep = DRep - { dRepDrepId :: DRepHash + { dRepIsScriptBased :: Bool + , dRepDrepId :: DRepHash , dRepView :: Text , dRepUrl :: Maybe Text , dRepMetadataHash :: Maybe Text diff --git a/govtool/backend/src/VVA/DRep.hs b/govtool/backend/src/VVA/DRep.hs index 315e9b50a..1cb35ffbe 100644 --- a/govtool/backend/src/VVA/DRep.hs +++ b/govtool/backend/src/VVA/DRep.hs @@ -61,9 +61,10 @@ listDReps = withPool $ \conn -> do results <- liftIO $ SQL.query_ conn listDRepsSql timeZone <- liftIO getCurrentTimeZone return - [ DRepRegistration drepHash drepView url dataHash (floor @Scientific deposit) votingPower status drepType txHash (localTimeToUTC timeZone date) metadataError paymentAddress givenName objectives motivations qualifications imageUrl imageHash + [ DRepRegistration drepHash drepView isScriptBased url dataHash (floor @Scientific deposit) votingPower status drepType txHash (localTimeToUTC timeZone date) metadataError paymentAddress givenName objectives motivations qualifications imageUrl imageHash | ( drepHash , drepView + , isScriptBased , url , dataHash , deposit @@ -132,7 +133,8 @@ getDRepInfo getDRepInfo drepId = withPool $ \conn -> do result <- liftIO $ SQL.query conn getDRepInfoSql (SQL.Only drepId) case result of - [ ( isRegisteredAsDRep + [ ( isScriptBased + , isRegisteredAsDRep , wasRegisteredAsDRep , isRegisteredAsSoleVoter , wasRegisteredAsSoleVoter @@ -153,7 +155,8 @@ getDRepInfo drepId = withPool $ \conn -> do , imageHash )] -> return $ DRepInfo - { dRepInfoIsRegisteredAsDRep = fromMaybe False isRegisteredAsDRep + { dRepInfoIsScriptBased = isScriptBased + , dRepInfoIsRegisteredAsDRep = fromMaybe False isRegisteredAsDRep , dRepInfoWasRegisteredAsDRep = fromMaybe False wasRegisteredAsDRep , dRepInfoIsRegisteredAsSoleVoter = fromMaybe False isRegisteredAsSoleVoter , dRepInfoWasRegisteredAsSoleVoter = fromMaybe False wasRegisteredAsSoleVoter @@ -173,4 +176,4 @@ getDRepInfo drepId = withPool $ \conn -> do , dRepInfoImageUrl = imageUrl , dRepInfoImageHash = imageHash } - [] -> return $ DRepInfo False False False False Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing + [] -> return $ DRepInfo False False False False False Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing diff --git a/govtool/backend/src/VVA/Types.hs b/govtool/backend/src/VVA/Types.hs index 669102b84..256fafb4d 100644 --- a/govtool/backend/src/VVA/Types.hs +++ b/govtool/backend/src/VVA/Types.hs @@ -72,7 +72,8 @@ data Vote data DRepInfo = DRepInfo - { dRepInfoIsRegisteredAsDRep :: Bool + { dRepInfoIsScriptBased :: Bool + , dRepInfoIsRegisteredAsDRep :: Bool , dRepInfoWasRegisteredAsDRep :: Bool , dRepInfoIsRegisteredAsSoleVoter :: Bool , dRepInfoWasRegisteredAsSoleVoter :: Bool @@ -101,6 +102,7 @@ data DRepRegistration = DRepRegistration { dRepRegistrationDRepHash :: Text , dRepRegistrationView :: Text + , dRepRegistrationIsScriptBased :: Bool , dRepRegistrationUrl :: Maybe Text , dRepRegistrationDataHash :: Maybe Text , dRepRegistrationDeposit :: Integer