Skip to content

Commit

Permalink
[#626] add to endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
jankun4 committed Apr 8, 2024
1 parent 8426b3d commit 921a074
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ changes.
- Integrate frontend with metadata validation service [Issue 617](https://github.com/IntersectMBO/govtool/issues/617)

### Added

- addded latestTxHash to the `drep/info` and `drep/list` endpoints [Issue 627](https://github.com/IntersectMBO/govtool/issues/627)
- added `txHash` to `drep/getVotes` [Issue 626](https://github.com/IntersectMBO/govtool/issues/626)
- 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
11 changes: 6 additions & 5 deletions govtool/backend/sql/get-votes.sql
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
select DISTINCT ON (voting_procedure.gov_action_proposal_id, voting_procedure.drep_voter) voting_procedure.gov_action_proposal_id, concat(encode(tx.hash,'hex'),'#',gov_action_proposal.index), encode(drep_hash.raw, 'hex'), voting_procedure.vote::text, voting_anchor.url, encode(voting_anchor.data_hash, 'hex'), block.epoch_no as epoch_no, block.time as time
from voting_procedure
select DISTINCT ON (voting_procedure.gov_action_proposal_id, voting_procedure.drep_voter) voting_procedure.gov_action_proposal_id, concat(encode(gov_action_tx.hash,'hex'),'#',gov_action_proposal.index), encode(drep_hash.raw, 'hex'), voting_procedure.vote::text, voting_anchor.url, encode(voting_anchor.data_hash, 'hex'), block.epoch_no as epoch_no, block.time as time, encode(vote_tx.hash, 'hex') as vote_tx_hash
join gov_action_proposal
on gov_action_proposal.id = voting_procedure.gov_action_proposal_id
join drep_hash
on drep_hash.id = voting_procedure.drep_voter
left join voting_anchor
on voting_anchor.id = voting_procedure.voting_anchor_id
join tx
on tx.id = gov_action_proposal.tx_id
join tx as gov_action_tx
on gov_action_tx.id = gov_action_proposal.tx_id
join tx as vote_tx
on vote_tx.id = voting_procedure.tx_id
join block
on block.id = tx.block_id
on block.id = gov_action_tx.block_id
where drep_hash.raw = decode(?, 'hex')
order by voting_procedure.gov_action_proposal_id, voting_procedure.drep_voter, voting_procedure.id desc
3 changes: 2 additions & 1 deletion govtool/backend/src/VVA/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ voteToResponse Types.Vote {..} =
voteParamsUrl = voteUrl,
voteParamsMetadataHash = HexText <$> voteDocHash,
voteParamsEpochNo = voteEpochNo,
voteParamsDate = voteDate
voteParamsDate = voteDate,
voteParamsTxHash = HexText voteTxHash
}


Expand Down
4 changes: 3 additions & 1 deletion govtool/backend/src/VVA/API/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ data VoteParams
, voteParamsMetadataHash :: Maybe HexText
, voteParamsEpochNo :: Integer
, voteParamsDate :: UTCTime
, voteParamsTxHash :: HexText
}
deriving (Generic, Show)

Expand All @@ -385,7 +386,8 @@ exampleVoteParams =
<> "\"url\": \"https://vote.metadata.xyz\","
<> "\"metadataHash\": \"9af10e89979e51b8cdc827c963124a1ef4920d1253eef34a1d5cfe76438e3f11\","
<> "\"epochNo\": 0,"
<> "\"date\": \"1970-01-01T00:00:00Z\"}"
<> "\"date\": \"1970-01-01T00:00:00Z\","
<> "\"txHash\": \"47c14a128cd024f1b990c839d67720825921ad87ed875def42641ddd2169b39c\"}"

instance ToSchema VoteParams where
declareNamedSchema proxy = do
Expand Down
6 changes: 3 additions & 3 deletions govtool/backend/src/VVA/DRep.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ getVotes ::
getVotes drepId selectedProposals = withPool $ \conn -> do
results <- liftIO $ SQL.query conn getVotesSql (SQL.Only drepId)
let proposalsToSelect = if null selectedProposals
then [ govActionId | (_, govActionId, _, _, _, _, _, _) <- results]
then [ govActionId | (_, govActionId, _, _, _, _, _, _, _) <- results]
else selectedProposals
proposals <- Proposal.getProposals (Just proposalsToSelect)
let proposalMap = M.fromList $ map (\x -> (proposalId x, x)) proposals
timeZone <- liftIO getCurrentTimeZone
return
([ Vote proposalId' drepId' vote' url' docHash' epochNo' (localTimeToUTC timeZone date')
| (proposalId', govActionId', drepId', vote', url', docHash', epochNo', date') <- results
([ Vote proposalId' drepId' vote' url' docHash' epochNo' (localTimeToUTC timeZone date') voteTxHash'
| (proposalId', govActionId', drepId', vote', url', docHash', epochNo', date', voteTxHash') <- results
, govActionId' `elem` proposalsToSelect
], proposals)

Expand Down
1 change: 1 addition & 0 deletions govtool/backend/src/VVA/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ data Vote
, voteDocHash :: Maybe Text
, voteEpochNo :: Integer
, voteDate :: UTCTime
, voteTxHash :: Text
}

data DRepInfo
Expand Down

0 comments on commit 921a074

Please sign in to comment.