Skip to content

Commit

Permalink
[#1951] return isScriptBased flag from BE for listDReps and getDRepInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
j-dyczka committed Oct 17, 2024
1 parent 8616572 commit 59df9f6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
10 changes: 10 additions & 0 deletions govtool/backend/sql/get-drep-info.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ WITH DRepId AS (
SELECT
decode(?, 'hex') AS raw
),
IsScriptHash AS (
SELECT
drep_hash.has_script AS value
FROM
drep_hash
WHERE
drep_hash.raw = DRepId.raw
),
AllRegistrationEntries AS (
SELECT
drep_registration.voting_anchor_id AS voting_anchor_id,
Expand Down Expand Up @@ -165,6 +173,7 @@ SoleVoterRetire AS (
LIMIT 1
)
SELECT
IsScriptHash.value,
IsRegisteredAsDRep.value,
WasRegisteredAsDRep.value,
IsRegisteredAsSoleVoter.value,
Expand Down Expand Up @@ -197,5 +206,6 @@ FROM
CROSS JOIN SoleVoterRegister
CROSS JOIN SoleVoterRetire
CROSS JOIN LatestRegistrationEntry
LEFT 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
2 changes: 2 additions & 0 deletions govtool/backend/sql/list-dreps.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 7 additions & 4 deletions govtool/backend/src/VVA/DRep.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
4 changes: 3 additions & 1 deletion govtool/backend/src/VVA/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ data Vote

data DRepInfo
= DRepInfo
{ dRepInfoIsRegisteredAsDRep :: Bool
{ dRepInfoIsScriptBased :: Bool
, dRepInfoIsRegisteredAsDRep :: Bool
, dRepInfoWasRegisteredAsDRep :: Bool
, dRepInfoIsRegisteredAsSoleVoter :: Bool
, dRepInfoWasRegisteredAsSoleVoter :: Bool
Expand Down Expand Up @@ -101,6 +102,7 @@ data DRepRegistration
= DRepRegistration
{ dRepRegistrationDRepHash :: Text
, dRepRegistrationView :: Text
, dRepIsScriptBased :: Bool
, dRepRegistrationUrl :: Maybe Text
, dRepRegistrationDataHash :: Maybe Text
, dRepRegistrationDeposit :: Integer
Expand Down

0 comments on commit 59df9f6

Please sign in to comment.