Skip to content

Commit

Permalink
Merge pull request #563 from IntersectMBO/develop
Browse files Browse the repository at this point in the history
Enhancements and Fixes: Documentation Updates, Pending Transaction Logic, and Governance Action Details
  • Loading branch information
pmbinapps authored Mar 26, 2024
2 parents cf1c0aa + aa63ed7 commit 5b943bd
Show file tree
Hide file tree
Showing 109 changed files with 4,037 additions and 2,306 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ local/

# used by haskell
govtool/backend/dist-newstyle/
govtool/backend/.stack-work/

# target environment config dir
scripts/govtool/config/target
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ changes.

## [Unreleased]

- DRep metadata builder [Issue 497](https://github.com/IntersectMBO/govtool/issues/497)
- Update Cardano Serialization Lib to 12.0.0-alpha.19 [Issue 521](https://github.com/IntersectMBO/govtool/issues/521)
- Add generate jsonld function [Issue 451](https://github.com/IntersectMBO/govtool/issues/451)
- Create GA review subbmision page [Issue 362](https://github.com/IntersectMBO/govtool/issues/362)
Expand All @@ -26,6 +27,7 @@ changes.
- Fix all the existing eslint errors [Issue 514](https://github.com/IntersectMBO/govtool/issues/514)
- Fix all the existing typescript errors [Issue 514](https://github.com/IntersectMBO/govtool/issues/514)
- Fix endless spinner on a dashboard [Issue 539](https://github.com/IntersectMBO/govtool/issues/539)
- Update frontend package readme to reflect recent changes [Issue 543](https://github.com/IntersectMBO/govtool/issues/543)

### Added

Expand Down Expand Up @@ -59,6 +61,8 @@ changes.

### Changed

- `proposal/list` returns additional data such ass `expiryEpochNo`, `createdEpochNo`, `title`, `about`, `motivation`,
`rationale`. `TreasuryWithdrawals` GAs also got nicely formated details. [Issue 372](https://github.com/IntersectMBO/govtool/issues/372)
- `drep/list` now return also `status` and `type` fields. Also it now returns the retired dreps, and you can search for given drep by name using optional query parameter. If the drep name is passed exactly, then you can even find a drep that's sole voter. [Issue 446](https://github.com/IntersectMBO/govtool/issues/446)
- `drep/list` and `drep/info` endpoints now return additional data such as metadata url and hash, and voting power [Issue 223](https://github.com/IntersectMBO/govtool/issues/223)
- `drep/info` now does not return sole voters (dreps without metadata) [Issue 317](https://github.com/IntersectMBO/govtool/issues/317)
Expand Down
2 changes: 1 addition & 1 deletion govtool/backend/Dockerfile.base
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# is a common practice in Haskell projects, as it can significantly reduce the
# time it takes to build the project.

FROM haskell:9.2-buster
FROM haskell:9.2.7-buster
WORKDIR /src
COPY . .
RUN cabal update && cabal configure && cabal install --only-dependencies && rm -rf /src/*
6 changes: 4 additions & 2 deletions govtool/backend/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ import Data.Monoid (mempty)
import qualified Data.Cache as Cache
import VVA.API.Types
import System.Clock (TimeSpec(TimeSpec))
import Data.Pool (newPool, defaultPoolConfig)
import Data.Pool (createPool)
import Database.PostgreSQL.Simple (connectPostgreSQL, close)
import Data.Text.Encoding (encodeUtf8)
import Data.Has (getter)
Expand Down Expand Up @@ -138,7 +138,7 @@ startApp vvaConfig = do
, dRepListCache
, networkMetricsCache
}
connectionPool <- newPool $ defaultPoolConfig (connectPostgreSQL (encodeUtf8 (dbSyncConnectionString $ getter vvaConfig))) close 1 60
connectionPool <- createPool (connectPostgreSQL (encodeUtf8 (dbSyncConnectionString $ getter vvaConfig))) close 1 1 60

let appEnv = AppEnv {vvaConfig=vvaConfig, vvaCache=cacheEnv, vvaConnectionPool=connectionPool}
server' <- mkVVAServer appEnv
Expand All @@ -161,6 +161,8 @@ exceptionHandler vvaConfig mRequest exception = do
(formatMessage mRequest exception)
(recordUpdate mRequest exception)



formatMessage :: Maybe Request -> SomeException -> String
formatMessage Nothing exception = "Exception before request could be parsed: " ++ show exception
formatMessage (Just request) exception = "Exception " ++ show exception ++ " while handling request " ++ show request
Expand Down
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
6 changes: 6 additions & 0 deletions govtool/backend/stack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
resolver: lts-20.24
packages:
- .

extra-deps:
- raven-haskell-0.1.4.1@sha256:9187272adc064197528645b5ad9b89163b668f386f34016d97fa646d5c790784
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
7 changes: 5 additions & 2 deletions govtool/backend/vva-be.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ executable vva-be
, lens
, cache
, clock
, resource-pool >= 0.4.0.0
, resource-pool
, postgresql-simple
, data-has
, raven-haskell >= 0.1.4.1
, bytestring
, http-client
, http-client-tls
, raven-haskell >= 0.1.4.1

hs-source-dirs: app
default-language: Haskell2010
Expand Down Expand Up @@ -97,6 +99,7 @@ library
, resource-pool
, swagger2


exposed-modules: VVA.Config
, VVA.CommandLine
, VVA.API
Expand Down
1 change: 1 addition & 0 deletions govtool/frontend/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ module.exports = {
"operator-linebreak": "off",
"implicit-arrow-linebreak": "off",
"consistent-return": "off",
"no-console": ["error", { allow: ["warn", "error"] }],
"no-shadow": "off",
"function-paren-newline": "off",
"object-curly-newline": "off",
Expand Down
Loading

0 comments on commit 5b943bd

Please sign in to comment.