From 7c547583052b74b4adc6c8d3307235c9161cef7f Mon Sep 17 00:00:00 2001 From: jankun4 Date: Mon, 25 Mar 2024 21:59:50 +0100 Subject: [PATCH] [#372] provide governance action details for TreasuryWithdrawals provide basic details (title, about, motivation and rationale) for all GA types, and extra details for TreasuryWithdrawals Signed-off-by: jankun4 --- govtool/backend/sql/list-proposals.sql | 32 ++++++++++++++++-- govtool/backend/src/VVA/API.hs | 8 ++++- govtool/backend/src/VVA/API/Types.hs | 14 +++++++- govtool/backend/src/VVA/Proposal.hs | 45 ++++++++++++++++++++++++-- govtool/backend/src/VVA/Types.hs | 8 ++++- govtool/backend/stack.yaml.lock | 19 +++++++++++ 6 files changed, 118 insertions(+), 8 deletions(-) create mode 100644 govtool/backend/stack.yaml.lock diff --git a/govtool/backend/sql/list-proposals.sql b/govtool/backend/sql/list-proposals.sql index 5c8694134..94cd4849e 100644 --- a/govtool/backend/sql/list-proposals.sql +++ b/govtool/backend/sql/list-proposals.sql @@ -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 @@ -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 @@ -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, diff --git a/govtool/backend/src/VVA/API.hs b/govtool/backend/src/VVA/API.hs index c303fe32f..aba121ba6 100644 --- a/govtool/backend/src/VVA/API.hs +++ b/govtool/backend/src/VVA/API.hs @@ -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 diff --git a/govtool/backend/src/VVA/API/Types.hs b/govtool/backend/src/VVA/API/Types.hs index efc79857d..5080cd339 100644 --- a/govtool/backend/src/VVA/API/Types.hs +++ b/govtool/backend/src/VVA/API/Types.hs @@ -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 @@ -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}" diff --git a/govtool/backend/src/VVA/Proposal.hs b/govtool/backend/src/VVA/Proposal.hs index d47e7af50..45980af7d 100644 --- a/govtool/backend/src/VVA/Proposal.hs +++ b/govtool/backend/src/VVA/Proposal.hs @@ -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 @@ -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 \ No newline at end of file diff --git a/govtool/backend/src/VVA/Types.hs b/govtool/backend/src/VVA/Types.hs index e316f34e0..499bac20a 100644 --- a/govtool/backend/src/VVA/Types.hs +++ b/govtool/backend/src/VVA/Types.hs @@ -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 diff --git a/govtool/backend/stack.yaml.lock b/govtool/backend/stack.yaml.lock new file mode 100644 index 000000000..985ab39a4 --- /dev/null +++ b/govtool/backend/stack.yaml.lock @@ -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