Skip to content

Commit

Permalink
[#372] provide governance action details for TreasuryWithdrawals
Browse files Browse the repository at this point in the history
provide basic details (title, about, motivation and rationale) for all GA types, and extra details for TreasuryWithdrawals

Signed-off-by: jankun4 <[email protected]>
  • Loading branch information
jankun4 committed Mar 26, 2024
1 parent 221318e commit 7c54758
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 8 deletions.
32 changes: 30 additions & 2 deletions govtool/backend/sql/list-proposals.sql
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,27 @@ SELECT
encode(creator_tx.hash, 'hex'),
gov_action_proposal.index,
gov_action_proposal.type::text,
gov_action_proposal.description::json,
(
case when gov_action_proposal.type = 'TreasuryWithdrawals' then
json_build_object('Reward Address', stake_address.view, 'Amount', treasury_withdrawal.amount)

when gov_action_proposal.type::text = 'InfoAction' then
json_build_object()
else
null
end
) as description,
epoch_utils.last_epoch_end_time + epoch_utils.epoch_duration *(gov_action_proposal.expiration - epoch_utils.last_epoch_no),
gov_action_proposal.expiration,
creator_block.time,
creator_block.epoch_no,
/* created date */
voting_anchor.url,
encode(voting_anchor.data_hash, 'hex'),
off_chain_vote_data.title,
off_chain_vote_data.abstract,
off_chain_vote_data.motivation,
off_chain_vote_data.rationale,
coalesce(Sum(ldd.amount) FILTER (WHERE voting_procedure.vote::text = 'Yes'), 0) +(
CASE WHEN gov_action_proposal.type = 'NoConfidence' THEN
always_no_confidence_voting_power.amount
Expand All @@ -59,12 +74,18 @@ SELECT
coalesce(Sum(ldd.amount) FILTER (WHERE voting_procedure.vote::text = 'Abstain'), 0) + always_abstain_voting_power.amount "abstain_votes"
FROM
gov_action_proposal
LEFT JOIN treasury_withdrawal
on gov_action_proposal.id = treasury_withdrawal.gov_action_proposal_id
LEFT JOIN stake_address
on stake_address.id = treasury_withdrawal.stake_address_id

CROSS JOIN EpochUtils AS epoch_utils
CROSS JOIN always_no_confidence_voting_power
CROSS JOIN always_abstain_voting_power
JOIN tx AS creator_tx ON creator_tx.id = gov_action_proposal.tx_id
JOIN block AS creator_block ON creator_block.id = creator_tx.block_id
JOIN voting_anchor ON voting_anchor.id = gov_action_proposal.voting_anchor_id
LEFT JOIN voting_anchor ON voting_anchor.id = gov_action_proposal.voting_anchor_id
LEFT JOIN off_chain_vote_data ON off_chain_vote_data.voting_anchor_id = voting_anchor.id
LEFT JOIN voting_procedure ON voting_procedure.gov_action_proposal_id = gov_action_proposal.id
LEFT JOIN LatestDrepDistr ldd ON ldd.hash_id = voting_procedure.drep_voter
AND ldd.rn = 1
Expand All @@ -81,6 +102,13 @@ AND gov_action_proposal.expired_epoch IS NULL
AND gov_action_proposal.dropped_epoch IS NULL
GROUP BY
(gov_action_proposal.id,
stake_address.view,
treasury_withdrawal.amount,
creator_block.epoch_no,
off_chain_vote_data.title,
off_chain_vote_data.abstract,
off_chain_vote_data.motivation,
off_chain_vote_data.rationale,
gov_action_proposal.index,
creator_tx.hash,
creator_block.time,
Expand Down
8 changes: 7 additions & 1 deletion govtool/backend/src/VVA/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,17 @@ proposalToResponse Types.Proposal {..} =
proposalResponseTxHash = HexText proposalTxHash,
proposalResponseIndex = proposalIndex,
proposalResponseType = fromMaybe InfoAction $ readMaybe $ unpack proposalType,
proposalResponseDetails = GovernanceActionDetails proposalDetails,
proposalResponseDetails = GovernanceActionDetails <$> proposalDetails,
proposalResponseExpiryDate = proposalExpiryDate,
proposalResponseExpiryEpochNo = proposalExpiryEpochNo,
proposalResponseCreatedDate = proposalCreatedDate,
proposalResponseCreatedEpochNo = proposalCreatedEpochNo,
proposalResponseUrl = proposalUrl,
proposalResponseMetadataHash = HexText proposalDocHash,
proposalResponseTitle = proposalTitle,
proposalResponseAbout = proposalAbout,
proposalResponseMotivation = proposalMotivaiton,
proposalResponseRationale = proposalRationale,
proposalResponseYesVotes = proposalYesVotes,
proposalResponseNoVotes = proposalNoVotes,
proposalResponseAbstainVotes = proposalAbstainVotes
Expand Down
14 changes: 13 additions & 1 deletion govtool/backend/src/VVA/API/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,17 @@ data ProposalResponse = ProposalResponse
proposalResponseTxHash :: HexText,
proposalResponseIndex :: Integer,
proposalResponseType :: GovernanceActionType,
proposalResponseDetails :: GovernanceActionDetails,
proposalResponseDetails :: Maybe GovernanceActionDetails,
proposalResponseExpiryDate :: Maybe UTCTime,
proposalResponseExpiryEpochNo :: Maybe Integer,
proposalResponseCreatedDate :: UTCTime,
proposalResponseCreatedEpochNo :: Integer,
proposalResponseUrl :: Text,
proposalResponseMetadataHash :: HexText,
proposalResponseTitle :: Maybe Text,
proposalResponseAbout :: Maybe Text,
proposalResponseMotivation :: Maybe Text,
proposalResponseRationale :: Maybe Text,
proposalResponseYesVotes :: Integer,
proposalResponseNoVotes :: Integer,
proposalResponseAbstainVotes :: Integer
Expand All @@ -258,9 +264,15 @@ exampleProposalResponse = "{ \"id\": \"proposalId123\","
<> "\"type\": \"InfoAction\","
<> "\"details\": \"some details\","
<> "\"expiryDate\": \"1970-01-01T00:00:00Z\","
<> "\"expiryEpochNo\": 0,"
<> "\"createdDate\": \"1970-01-01T00:00:00Z\","
<> "\"createdEpochNo\": 0,"
<> "\"url\": \"https://proposal.metadata.xyz\","
<> "\"metadataHash\": \"9af10e89979e51b8cdc827c963124a1ef4920d1253eef34a1d5cfe76438e3f11\","
<> "\"title\": \"Proposal Title\","
<> "\"about\": \"Proposal About\","
<> "\"motivation\": \"Proposal Motivation\","
<> "\"rationale\": \"Proposal Rationale\","
<> "\"yesVotes\": 0,"
<> "\"noVotes\": 0,"
<> "\"abstainVotes\": 0}"
Expand Down
45 changes: 42 additions & 3 deletions govtool/backend/src/VVA/Proposal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ import VVA.Pool (ConnectionPool, withPool)
import Control.Exception (throw)
import VVA.Types (Proposal(..), AppError(..))

import Data.Aeson
import Data.Aeson.Types (parseMaybe, Parser)
import Data.Text (Text)

sqlFrom :: ByteString -> SQL.Query
sqlFrom bs = fromString $ unpack $ Text.decodeUtf8 bs
Expand Down Expand Up @@ -67,10 +70,46 @@ getProposals mProposalIds = withPool $ \conn -> do

timeZone <- liftIO getCurrentTimeZone
return $ map
( \(id', txHash', index', type', details', expiryDate', createdDate', url', docHash', yesVotes', noVotes', abstainVotes') ->
( \( id'
, txHash'
, index'
, type'
, details'
, expiryDate'
, expiryEpochNo'
, createdDate'
, createdEpochNo'
, url'
, docHash'
, title'
, about'
, motivation'
, rationale'
, yesVotes'
, noVotes'
, abstainVotes'
) ->
let eDate = localTimeToUTC timeZone <$> expiryDate'
cDate = localTimeToUTC timeZone createdDate'
in
Proposal id' txHash' (floor @Scientific index') type' details' eDate cDate url' docHash' (floor @Scientific yesVotes') (floor @Scientific noVotes') (floor @Scientific abstainVotes')
Proposal
id'
txHash'
(floor @Scientific index')
type'
details'
eDate
expiryEpochNo'
cDate
createdEpochNo'
url'
docHash'
title'
about'
motivation'
rationale'
(floor @Scientific yesVotes')
(floor @Scientific noVotes')
(floor @Scientific abstainVotes')
)
proposalResults
proposalResults
8 changes: 7 additions & 1 deletion govtool/backend/src/VVA/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,17 @@ data Proposal = Proposal
proposalTxHash :: Text,
proposalIndex :: Integer,
proposalType :: Text,
proposalDetails :: Value,
proposalDetails :: Maybe Value,
proposalExpiryDate :: Maybe UTCTime,
proposalExpiryEpochNo :: Maybe Integer,
proposalCreatedDate :: UTCTime,
proposalCreatedEpochNo :: Integer,
proposalUrl :: Text,
proposalDocHash :: Text,
proposalTitle :: Maybe Text,
proposalAbout :: Maybe Text,
proposalMotivaiton :: Maybe Text,
proposalRationale :: Maybe Text,
proposalYesVotes :: Integer,
proposalNoVotes :: Integer,
proposalAbstainVotes :: Integer
Expand Down
19 changes: 19 additions & 0 deletions govtool/backend/stack.yaml.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file was autogenerated by Stack.
# You should not edit this file by hand.
# For more information, please see the documentation at:
# https://docs.haskellstack.org/en/stable/lock_files

packages:
- completed:
hackage: raven-haskell-0.1.4.1@sha256:9187272adc064197528645b5ad9b89163b668f386f34016d97fa646d5c790784,1479
pantry-tree:
sha256: e8f14bfed6b055dc95933257441ba97d3d779cbe08a0e82c3c2dff5d69c8c48f
size: 632
original:
hackage: raven-haskell-0.1.4.1@sha256:9187272adc064197528645b5ad9b89163b668f386f34016d97fa646d5c790784
snapshots:
- completed:
sha256: e019cd29e3f7f9dbad500225829a3f7a50f73c674614f2f452e21bb8bf5d99ea
size: 650253
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/20/24.yaml
original: lts-20.24

0 comments on commit 7c54758

Please sign in to comment.