Skip to content

Commit

Permalink
[#627] add latestTxHash to drep/list and drep/info endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
jankun4 committed Apr 7, 2024
1 parent aff3fa2 commit 410cae6
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 26 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ changes.
## [Unreleased]

### Added

- addded latestTxHash to the `drep/info` and `drep/list` endpoints [Issue 627](https://github.com/IntersectMBO/govtool/issues/627)
- added `epochNo` and `date` to `drep/getVotes` and `proposal/get`
- Added `isRegisteredAsSoleVoter` and `wasRegisteredAsSoleVoter` fields to the drep/info response [Issue 212](https://github.com/IntersectMBO/govtool/issues/212)
- Abandoning registration as DRep [Issue 151](https://github.com/IntersectMBO/govtool/issues/151)
Expand Down
5 changes: 4 additions & 1 deletion govtool/backend/sql/get-drep-info.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ LatestRegistrationEntry AS (
SELECT
drep_registration.voting_anchor_id AS voting_anchor_id,
deposit AS deposit
tx.hash as tx_hash
FROM
drep_registration
CROSS JOIN DrepId
JOIN drep_hash ON drep_hash.id = drep_registration.drep_hash_id
JOIN tx ON tx.id = drep_registration.tx_id
WHERE
drep_hash.raw = DRepId.raw
ORDER BY
Expand Down Expand Up @@ -95,7 +97,8 @@ SELECT
CurrentDeposit.value,
CurrentMetadata.url,
CurrentMetadata.data_hash,
CurrentVotingPower.amount
CurrentVotingPower.amount,
LatestRegistrationEntry.tx_hash
FROM
IsRegisteredAsDRep
CROSS JOIN IsRegisteredAsSoleVoter
Expand Down
9 changes: 6 additions & 3 deletions govtool/backend/sql/list-dreps.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ SELECT
dr_deposit.deposit,
DRepDistr.amount,
(DRepActivity.epoch_no - Max(coalesce(block.epoch_no,block_first_register.epoch_no))) <= DRepActivity.drep_activity as active,
second_to_newest_drep_registration.voting_anchor_id is not null as has_voting_anchor
second_to_newest_drep_registration.voting_anchor_id is not null as has_voting_anchor,
encode(dr_voting_anchor.tx_hash, 'hex') as tx_hash
FROM drep_hash dh
JOIN (
SELECT dr.id, dr.drep_hash_id, dr.deposit,
Expand All @@ -34,8 +35,10 @@ JOIN (
on dr_deposit.drep_hash_id = dh.id and dr_deposit.rn = 1
LEFT JOIN (
SELECT dr.id, dr.drep_hash_id, dr.voting_anchor_id,
ROW_NUMBER() OVER(PARTITION BY dr.drep_hash_id ORDER BY dr.tx_id DESC) AS rn
ROW_NUMBER() OVER(PARTITION BY dr.drep_hash_id ORDER BY dr.tx_id DESC) AS rn,
tx.hash as tx_hash
FROM drep_registration dr
JOIN tx on tx.id = dr.tx_id
) as dr_voting_anchor
on dr_voting_anchor.drep_hash_id = dh.id and dr_voting_anchor.rn = 1
LEFT JOIN (
Expand Down Expand Up @@ -65,4 +68,4 @@ on tx_first_register.id = dr_first_register.tx_id
JOIN block as block_first_register
ON block_first_register.id = tx_first_register.block_id

GROUP BY dh.raw, second_to_newest_drep_registration.voting_anchor_id, dh.view, va.url, va.data_hash, dr_deposit.deposit, DRepDistr.amount, DRepActivity.epoch_no, DRepActivity.drep_activity
GROUP BY dh.raw, second_to_newest_drep_registration.voting_anchor_id, dh.view, va.url, va.data_hash, dr_deposit.deposit, DRepDistr.amount, DRepActivity.epoch_no, DRepActivity.drep_activity, dr_voting_anchor.tx_hash
4 changes: 3 additions & 1 deletion govtool/backend/src/VVA/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ drepRegistrationToDrep Types.DRepRegistration {..} =
dRepDeposit = dRepRegistrationDeposit,
dRepVotingPower = dRepRegistrationVotingPower,
dRepStatus = mapDRepStatus dRepRegistrationStatus,
dRepType = mapDRepType dRepRegistrationType
dRepType = mapDRepType dRepRegistrationType,
dRepLatestTxHash = HexText <$> dRepRegistrationLatestTxHash
}

drepList :: App m => Maybe Text -> m [DRep]
Expand Down Expand Up @@ -208,6 +209,7 @@ drepInfo (unHexText -> dRepId) = do
, dRepInfoResponseUrl = dRepInfoUrl
, dRepInfoResponseDataHash = HexText <$> dRepInfoDataHash
, dRepInfoResponseVotingPower = dRepInfoVotingPower
, dRepInfoResponseLatestTxHash = HexText <$> dRepInfoLatestTxHash
}

getCurrentDelegation :: App m => HexText -> m (Maybe HexText)
Expand Down
22 changes: 13 additions & 9 deletions govtool/backend/src/VVA/API/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ data DRepInfoResponse
, dRepInfoResponseUrl :: Maybe Text
, dRepInfoResponseDataHash :: Maybe HexText
, dRepInfoResponseVotingPower :: Maybe Integer
, dRepInfoResponseLatestTxHash :: Maybe HexText
}
deriving (Generic, Show)

Expand All @@ -455,7 +456,8 @@ exampleDRepInfoResponse =
<> "\"deposit\": 2000000,"
<> "\"url\": \"https://drep.metadata.xyz\","
<> "\"dataHash\": \"9af10e89979e51b8cdc827c963124a1ef4920d1253eef34a1d5cfe76438e3f11\","
<> "\"votingPower\": 1000000}"
<> "\"votingPower\": 1000000,"
<> "\"latestTxHash\": \"47c14a128cd024f1b990c839d67720825921ad87ed875def42641ddd2169b39c\"}"

instance ToSchema DRepInfoResponse where
declareNamedSchema proxy = do
Expand Down Expand Up @@ -632,6 +634,7 @@ data DRep
, dRepVotingPower :: Maybe Integer
, dRepStatus :: DRepStatus
, dRepType :: DRepType
, dRepLatestTxHash :: Maybe HexText
}
deriving (Generic, Show)

Expand All @@ -640,14 +643,15 @@ deriveJSON (jsonOptions "dRep") ''DRep

exampleDrep :: Text
exampleDrep =
"{\"drepId\": \"d3a62ffe9c214e1a6a9809f7ab2a104c117f85e1f171f8f839d94be5\","
<> "\"view\": \"drep1l8uyy66sm8u82h82gc8hkcy2xu24dl8ffsh58aa0v7d37yp48u8\","
<> "\"url\": \"https://proposal.metadata.xyz\","
<> "\"metadataHash\": \"9af10e89979e51b8cdc827c963124a1ef4920d1253eef34a1d5cfe76438e3f11\","
<> "\"deposit\": 0,"
<> "\"votingPower\": 0,"
<> "\"status\": \"Active\","
<> "\"type\": \"DRep\"}"
"{\"drepId\": \"d3a62ffe9c214e1a6a9809f7ab2a104c117f85e1f171f8f839d94be5\","
<> "\"view\": \"drep1l8uyy66sm8u82h82gc8hkcy2xu24dl8ffsh58aa0v7d37yp48u8\","
<> "\"url\": \"https://proposal.metadata.xyz\","
<> "\"metadataHash\": \"9af10e89979e51b8cdc827c963124a1ef4920d1253eef34a1d5cfe76438e3f11\","
<> "\"deposit\": 0,"
<> "\"votingPower\": 0,"
<> "\"status\": \"Active\","
<> "\"type\": \"DRep\","
<> "\"latestTxHash\": \"47c14a128cd024f1b990c839d67720825921ad87ed875def42641ddd2169b39c\"}"

-- ToSchema instance for DRep
instance ToSchema DRep where
Expand Down
8 changes: 5 additions & 3 deletions govtool/backend/src/VVA/DRep.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ listDReps ::
listDReps = withPool $ \conn -> do
results <- liftIO $ SQL.query_ conn listDRepsSql
return
[ DRepRegistration drepHash drepView url dataHash (floor @Scientific deposit) votingPower status drepType
| (drepHash, drepView, url, dataHash, deposit, votingPower, isActive, wasDRep) <- results
[ DRepRegistration drepHash drepView url dataHash (floor @Scientific deposit) votingPower status drepType txHash
| (drepHash, drepView, url, dataHash, deposit, votingPower, isActive, wasDRep, txHash) <- results
, let status = case (isActive, deposit) of
(_, d) | d < 0 -> Retired
(isActive, d) | d >= 0 && isActive -> Active
Expand Down Expand Up @@ -117,6 +117,7 @@ getDRepInfo drepId = withPool $ \conn -> do
, url
, dataHash
, votingPower
, txHash
)] ->
return $ DRepInfo
{ dRepInfoIsRegisteredAsDRep = fromMaybe False isRegisteredAsDRep
Expand All @@ -127,5 +128,6 @@ getDRepInfo drepId = withPool $ \conn -> do
, dRepInfoUrl = url
, dRepInfoDataHash = dataHash
, dRepInfoVotingPower = votingPower
, dRepInfoLatestTxHash = Just txHash
}
[] -> return $ DRepInfo False False False False Nothing Nothing Nothing Nothing
[] -> return $ DRepInfo False False False False Nothing Nothing Nothing Nothing Nothing
18 changes: 10 additions & 8 deletions govtool/backend/src/VVA/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ data DRepInfo
, dRepInfoUrl :: Maybe Text
, dRepInfoDataHash :: Maybe Text
, dRepInfoVotingPower :: Maybe Integer
, dRepInfoLatestTxHash :: Maybe Text
}

data DRepStatus = Retired | Active | Inactive
Expand All @@ -82,14 +83,15 @@ data DRepType = DRep | SoleVoter

data DRepRegistration
= DRepRegistration
{ dRepRegistrationDRepHash :: Text
, dRepRegistrationView :: Text
, dRepRegistrationUrl :: Maybe Text
, dRepRegistrationDataHash :: Maybe Text
, dRepRegistrationDeposit :: Integer
, dRepRegistrationVotingPower :: Maybe Integer
, dRepRegistrationStatus :: DRepStatus
, dRepRegistrationType :: DRepType
{ dRepRegistrationDRepHash :: Text
, dRepRegistrationView :: Text
, dRepRegistrationUrl :: Maybe Text
, dRepRegistrationDataHash :: Maybe Text
, dRepRegistrationDeposit :: Integer
, dRepRegistrationVotingPower :: Maybe Integer
, dRepRegistrationStatus :: DRepStatus
, dRepRegistrationType :: DRepType
, dRepRegistrationLatestTxHash :: Maybe Text
}

data Proposal
Expand Down

0 comments on commit 410cae6

Please sign in to comment.