Skip to content

Commit

Permalink
[#586] add epochNo and date to vote response
Browse files Browse the repository at this point in the history
Signed-off-by: jankun4 <[email protected]>
  • Loading branch information
jankun4 committed Mar 28, 2024
1 parent f19d3b1 commit 3c4a32c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
4 changes: 3 additions & 1 deletion govtool/backend/sql/get-votes.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
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')
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
join gov_action_proposal
on gov_action_proposal.id = voting_procedure.gov_action_proposal_id
Expand All @@ -8,5 +8,7 @@ left join voting_anchor
on voting_anchor.id = voting_procedure.voting_anchor_id
join tx
on tx.id = gov_action_proposal.tx_id
join block
on block.id = 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
4 changes: 3 additions & 1 deletion govtool/backend/src/VVA/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ voteToResponse Types.Vote {..} =
voteParamsDrepId = HexText voteDrepId,
voteParamsVote = voteVote,
voteParamsUrl = voteUrl,
voteParamsMetadataHash = HexText <$> voteDocHash
voteParamsMetadataHash = HexText <$> voteDocHash,
voteParamsEpochNo = voteEpochNo,
voteParamsDate = voteDate
}


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

Expand All @@ -381,7 +383,9 @@ exampleVoteParams =
<> "\"drepId\": \"b4e4184bfedf920fec53cdc327de4da661ae427784c0ccca9e3c2f50\","
<> "\"vote\": \"yes\","
<> "\"url\": \"https://vote.metadata.xyz\","
<> "\"metadataHash\": \"9af10e89979e51b8cdc827c963124a1ef4920d1253eef34a1d5cfe76438e3f11\" }"
<> "\"metadataHash\": \"9af10e89979e51b8cdc827c963124a1ef4920d1253eef34a1d5cfe76438e3f11\","
<> "\"epochNo\": 0,"
<> "\"date\": \"1970-01-01T00:00:00Z\"}"

instance ToSchema VoteParams where
declareNamedSchema proxy = do
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 @@ -23,6 +23,7 @@ import Data.Scientific
import Data.String (fromString)
import Data.Text (Text, pack, unpack)
import qualified Data.Text.Encoding as Text
import Data.Time

import qualified Database.PostgreSQL.Simple as SQL

Expand Down Expand Up @@ -81,13 +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'
| (proposalId', govActionId', drepId', vote', url', docHash') <- results
([ Vote proposalId' drepId' vote' url' docHash' epochNo' (localTimeToUTC timeZone date')
| (proposalId', govActionId', drepId', vote', url', docHash', epochNo', date') <- results
, govActionId' `elem` proposalsToSelect
], proposals)

Expand Down
2 changes: 2 additions & 0 deletions govtool/backend/src/VVA/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ data Vote
, voteVote :: Text
, voteUrl :: Maybe Text
, voteDocHash :: Maybe Text
, voteEpochNo :: Integer
, voteDate :: UTCTime
}

data DRepInfo
Expand Down

0 comments on commit 3c4a32c

Please sign in to comment.