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 18, 2024
1 parent 27915e9 commit daedc37
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 18 deletions.
1 change: 1 addition & 0 deletions govtool/backend/sql/get-current-delegation.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ select
else encode(drep_hash.raw,'hex')
end as drep_raw,
drep_hash.view as drep_view,
drep_hash.has_script,
encode(tx.hash, 'hex')
from delegation_vote
join tx on tx.id = delegation_vote.tx_id
Expand Down
11 changes: 11 additions & 0 deletions govtool/backend/sql/get-drep-info.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -165,6 +174,7 @@ SoleVoterRetire AS (
LIMIT 1
)
SELECT
IsScriptHash.value,
IsRegisteredAsDRep.value,
WasRegisteredAsDRep.value,
IsRegisteredAsSoleVoter.value,
Expand Down Expand Up @@ -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
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 @@ -137,6 +138,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
7 changes: 5 additions & 2 deletions govtool/backend/src/VVA/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -131,6 +132,7 @@ delegationToResponse Types.Delegation {..} =
DelegationResponse
{ delegationResponseDRepHash = HexText <$> delegationDRepHash,
delegationResponseDRepView = delegationDRepView,
delegationResponseIsDRepScriptBased = delegationIsDRepScriptBased,
delegationResponseTxHash = HexText delegationTxHash
}

Expand Down Expand Up @@ -286,7 +288,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
Expand Down
13 changes: 8 additions & 5 deletions govtool/backend/src/VVA/API/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,8 @@ instance ToSchema VoteResponse where

data DRepInfoResponse
= DRepInfoResponse
{ dRepInfoResponseIsRegisteredAsDRep :: Bool
{ dRepInfoResponseIsScriptBased :: Bool
, dRepInfoResponseIsRegisteredAsDRep :: Bool
, dRepInfoResponseWasRegisteredAsDRep :: Bool
, dRepInfoResponseIsRegisteredAsSoleVoter :: Bool
, dRepInfoResponseWasRegisteredAsSoleVoter :: Bool
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -855,9 +857,10 @@ instance ToSchema ListDRepsResponse where

data DelegationResponse
= DelegationResponse
{ delegationResponseDRepHash :: Maybe HexText
, delegationResponseDRepView :: Text
, delegationResponseTxHash :: HexText
{ delegationResponseDRepHash :: Maybe HexText
, delegationResponseDRepView :: Text
, delegationResponseIsDRepScriptBased :: Bool
, delegationResponseTxHash :: HexText
}
deriveJSON (jsonOptions "delegationResponse") ''DelegationResponse

Expand Down
6 changes: 3 additions & 3 deletions govtool/backend/src/VVA/AdaHolder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ getCurrentDelegation ::
getCurrentDelegation stakeKey = withPool $ \conn -> do
result <- liftIO $ SQL.query conn getCurrentDelegationSql (SQL.Only stakeKey)
case result of
[] -> return Nothing
[(mDRepHash, dRepView, txHash)] -> return $ Just $ Delegation mDRepHash dRepView txHash
_ -> error ("multiple delegations for stake key: " <> unpack stakeKey)
[] -> return Nothing
[(mDRepHash, dRepView, isDRepScriptBased, txHash)] -> return $ Just $ Delegation mDRepHash dRepView isDRepScriptBased txHash
_ -> error ("multiple delegations for stake key: " <> unpack stakeKey)

getVotingPowerSql :: SQL.Query
getVotingPowerSql = sqlFrom $(embedFile "sql/get-stake-key-voting-power.sql")
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
11 changes: 7 additions & 4 deletions 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
, dRepRegistrationIsScriptBased :: Bool
, dRepRegistrationUrl :: Maybe Text
, dRepRegistrationDataHash :: Maybe Text
, dRepRegistrationDeposit :: Integer
Expand Down Expand Up @@ -215,7 +217,8 @@ data NetworkMetrics

data Delegation
= Delegation
{ delegationDRepHash :: Maybe Text
, delegationDRepView :: Text
, delegationTxHash :: Text
{ delegationDRepHash :: Maybe Text
, delegationDRepView :: Text
, delegationIsDRepScriptBased :: Bool
, delegationTxHash :: Text
}

0 comments on commit daedc37

Please sign in to comment.