Skip to content

Commit

Permalink
[#636] add references to all proposal related endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
jankun4 committed Apr 9, 2024
1 parent 3a1cf02 commit e9cdbea
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ changes.

- 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 `references` to all proposal related endpoints
- 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
1 change: 1 addition & 0 deletions govtool/backend/sql/list-proposals.sql
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ SELECT
off_chain_vote_data.motivation,
off_chain_vote_data.rationale,
off_chain_vote_data.json,
off_chain_vote_data.json#>'{body, references}' as references,
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 Down
1 change: 1 addition & 0 deletions govtool/backend/src/VVA/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ proposalToResponse Types.Proposal {..} =
proposalResponseMotivation = proposalMotivaiton,
proposalResponseRationale = proposalRationale,
proposalResponseMetadata = GovernanceActionMetadata <$> proposalMetadata,
proposalResponseReferences = GovernanceActionReferences <$> proposalReferences,
proposalResponseYesVotes = proposalYesVotes,
proposalResponseNoVotes = proposalNoVotes,
proposalResponseAbstainVotes = proposalAbstainVotes
Expand Down
23 changes: 23 additions & 0 deletions govtool/backend/src/VVA/API/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,27 @@ instance ToSchema GovernanceActionMetadata where



newtype GovernanceActionReferences
= GovernanceActionReferences Value
deriving newtype (Show)

instance FromJSON GovernanceActionReferences where
parseJSON v@(Aeson.Array a) = pure (GovernanceActionReferences v)
parseJSON _ = fail "GovernanceActionReferences has to be an array"

instance ToJSON GovernanceActionReferences where
toJSON (GovernanceActionReferences g) = g

instance ToSchema GovernanceActionReferences where
declareNamedSchema _ = pure $ NamedSchema (Just "GovernanceActionReferences") $ mempty
& type_ ?~ OpenApiObject
& description ?~ "A Governance Action References"
& example
?~ toJSON
("[{\"uri\": \"google.com\", \"@type\": \"Other\", \"label\": \"example label\"}]" :: Text)



data ProposalResponse
= ProposalResponse
{ proposalResponseId :: Text
Expand All @@ -285,6 +306,7 @@ data ProposalResponse
, proposalResponseMotivation :: Maybe Text
, proposalResponseRationale :: Maybe Text
, proposalResponseMetadata :: Maybe GovernanceActionMetadata
, proposalResponseReferences :: Maybe GovernanceActionReferences
, proposalResponseYesVotes :: Integer
, proposalResponseNoVotes :: Integer
, proposalResponseAbstainVotes :: Integer
Expand All @@ -310,6 +332,7 @@ exampleProposalResponse = "{ \"id\": \"proposalId123\","
<> "\"motivation\": \"Proposal Motivation\","
<> "\"rationale\": \"Proposal Rationale\","
<> "\"metadata\": {\"key\": \"value\"},"
<> "\"references\": [{\"uri\": \"google.com\", \"@type\": \"Other\", \"label\": \"example label\"}],"
<> "\"yesVotes\": 0,"
<> "\"noVotes\": 0,"
<> "\"abstainVotes\": 0}"
Expand Down
2 changes: 2 additions & 0 deletions govtool/backend/src/VVA/Proposal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ getProposals mProposalIds = withPool $ \conn -> do
, motivation'
, rationale'
, metadataJson'
, references'
, yesVotes'
, noVotes'
, abstainVotes'
Expand All @@ -111,6 +112,7 @@ getProposals mProposalIds = withPool $ \conn -> do
motivation'
rationale'
metadataJson'
references'
(floor @Scientific yesVotes')
(floor @Scientific noVotes')
(floor @Scientific abstainVotes')
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 @@ -113,6 +113,7 @@ data Proposal
, proposalMotivaiton :: Maybe Text
, proposalRationale :: Maybe Text
, proposalMetadata :: Maybe Value
, proposalReferences :: Maybe Value
, proposalYesVotes :: Integer
, proposalNoVotes :: Integer
, proposalAbstainVotes :: Integer
Expand Down

0 comments on commit e9cdbea

Please sign in to comment.