Skip to content

Commit

Permalink
Merge pull request #675 from IntersectMBO/develop
Browse files Browse the repository at this point in the history
Enhancements and Fixes: Automated Voting, DRep Directory, and Workflow Adjustments
  • Loading branch information
pmbinapps authored Apr 9, 2024
2 parents 987aa1e + 5eeb63f commit 7349c2b
Show file tree
Hide file tree
Showing 98 changed files with 1,905 additions and 390 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/lighthouse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@ jobs:
- name: Run build and lighthouse task
working-directory: ./govtool/frontend
run: |
npm install
VITE_BASE_URL=https://staging.govtool.byron.network/api npm run build
lhci collect
npm install
VITE_BASE_URL=https://staging.govtool.byron.network/ npm run build
lhci collect
- name: Evaluate reports
if: github.repository_owner != 'IntersectMBO'
run: |
lhci assert --preset "lighthouse:recommended"
lhci assert --preset "lighthouse:recommended"
- name: Publish reports
working-directory: ./govtool/frontend
if: github.repository_owner == 'IntersectMBO'
run: |
lhci assert --preset lighthouse:recommended || echo "LightHouse Assertion error ignored ..."
lhci upload --githubAppToken="${{ secrets.LHCI_GITHUB_APP_TOKEN }}" --token="${{ secrets.LHCI_SERVER_TOKEN }}" --serverBaseUrl=https://lighthouse.cardanoapi.io --ignoreDuplicateBuildFailure
curl -X POST https://ligththouse.cardanoapi.io/api/metrics/build-reports \
-d "@./lighthouseci/$(ls ./.lighthouseci |grep 'lhr.*\.json' | head -n 1)" \
-H "commit-hash: $(git rev-parse HEAD)" \
-H "secret-token: ${{ secrets.METRICS_SERVER_SECRET_TOKEN }}" \
-H 'Content-Type: application/json' || echo "Metric Upload error ignored ..."
lhci assert --preset lighthouse:recommended || echo "LightHouse Assertion error ignored ..."
lhci upload --githubAppToken="${{ secrets.LHCI_GITHUB_APP_TOKEN }}" --token="${{ secrets.LHCI_SERVER_TOKEN }}" --serverBaseUrl=https://lighthouse.cardanoapi.io --ignoreDuplicateBuildFailure
curl -X POST https://ligththouse.cardanoapi.io/api/metrics/build-reports \
-d "@./lighthouseci/$(ls ./.lighthouseci |grep 'lhr.*\.json' | head -n 1)" \
-H "commit-hash: $(git rev-parse HEAD)" \
-H "secret-token: ${{ secrets.METRICS_SERVER_SECRET_TOKEN }}" \
-H 'Content-Type: application/json' || echo "Metric Upload error ignored ..."
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,22 @@ changes.

## [Unreleased]

- Integrate frontend with metadata validation service [Issue 617](https://github.com/IntersectMBO/govtool/issues/617)
- Implement a loading modal for the validation of the metadata [Issue 646](https://github.com/IntersectMBO/govtool/issues/646)

### Added

- 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)
- Abandoning GA creation [Issue 359](https://github.com/IntersectMBO/govtool/issues/359)
- Choose GA type - GA Submiter [Issue 358](https://github.com/IntersectMBO/govtool/issues/358)
- Create Automated Voting Options component [Issue 216](https://github.com/IntersectMBO/govtool/issues/216)
- Change step 3 components [Issue 152](https://github.com/intersectMBO/govtool/issues/152)
- Add possibility to vote on behalf of myself - Sole Voter [Issue 119](https://github.com/IntersectMBO/govtool/issues/119)
- Create DRep registration page about roles [Issue 205](https://github.com/IntersectMBO/govtool/issues/205)
- Create Checkbox component. Improve Field and ControlledField [Issue 177](https://github.com/IntersectMBO/govtool/pull/177)
- Vitest unit tests added for utils functions [Issue 81](https://github.com/IntersectMBO/govtool/issues/81)
Expand All @@ -38,6 +48,7 @@ changes.

### Fixed

- drep/info no longer returns 500 [Issue 676](https://github.com/IntersectMBO/govtool/issues/676)
- proposal/list search is case insensitive now [Issue 582](https://github.com/IntersectMBO/govtool/issues/582)
- proposal/list now takes optional `search` query param [Issue 566](https://github.com/IntersectMBO/govtool/issues/566)
- Fix possible sql error when there would be no predefined drep voting pwoer [Issue 501](https://github.com/IntersectMBO/govtool/issues/501)
Expand Down
8 changes: 6 additions & 2 deletions govtool/backend/sql/get-drep-info.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ WITH DRepId AS (
LatestRegistrationEntry AS (
SELECT
drep_registration.voting_anchor_id AS voting_anchor_id,
deposit AS deposit
drep_registration.deposit AS deposit,
tx.hash as tx_hash
FROM
drep_registration
CROSS JOIN DrepId
JOIN drep_hash ON drep_hash.id = drep_registration.drep_hash_id
JOIN tx ON tx.id = drep_registration.tx_id
WHERE
drep_hash.raw = DRepId.raw
ORDER BY
Expand Down Expand Up @@ -95,7 +97,8 @@ SELECT
CurrentDeposit.value,
CurrentMetadata.url,
CurrentMetadata.data_hash,
CurrentVotingPower.amount
CurrentVotingPower.amount,
encode(LatestRegistrationEntry.tx_hash, 'hex') as tx_hash
FROM
IsRegisteredAsDRep
CROSS JOIN IsRegisteredAsSoleVoter
Expand All @@ -104,3 +107,4 @@ FROM
CROSS JOIN CurrentDeposit
CROSS JOIN CurrentMetadata
CROSS JOIN CurrentVotingPower
CROSS JOIN LatestRegistrationEntry
11 changes: 6 additions & 5 deletions govtool/backend/sql/get-votes.sql
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
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
select DISTINCT ON (voting_procedure.gov_action_proposal_id, voting_procedure.drep_voter) voting_procedure.gov_action_proposal_id, concat(encode(gov_action_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, encode(vote_tx.hash, 'hex') as vote_tx_hash
join gov_action_proposal
on gov_action_proposal.id = voting_procedure.gov_action_proposal_id
join drep_hash
on drep_hash.id = voting_procedure.drep_voter
left join voting_anchor
on voting_anchor.id = voting_procedure.voting_anchor_id
join tx
on tx.id = gov_action_proposal.tx_id
join tx as gov_action_tx
on gov_action_tx.id = gov_action_proposal.tx_id
join tx as vote_tx
on vote_tx.id = voting_procedure.tx_id
join block
on block.id = tx.block_id
on block.id = gov_action_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
9 changes: 6 additions & 3 deletions govtool/backend/sql/list-dreps.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ SELECT
dr_deposit.deposit,
DRepDistr.amount,
(DRepActivity.epoch_no - Max(coalesce(block.epoch_no,block_first_register.epoch_no))) <= DRepActivity.drep_activity as active,
second_to_newest_drep_registration.voting_anchor_id is not null as has_voting_anchor
second_to_newest_drep_registration.voting_anchor_id is not null as has_voting_anchor,
encode(dr_voting_anchor.tx_hash, 'hex') as tx_hash
FROM drep_hash dh
JOIN (
SELECT dr.id, dr.drep_hash_id, dr.deposit,
Expand All @@ -34,8 +35,10 @@ JOIN (
on dr_deposit.drep_hash_id = dh.id and dr_deposit.rn = 1
LEFT JOIN (
SELECT dr.id, dr.drep_hash_id, dr.voting_anchor_id,
ROW_NUMBER() OVER(PARTITION BY dr.drep_hash_id ORDER BY dr.tx_id DESC) AS rn
ROW_NUMBER() OVER(PARTITION BY dr.drep_hash_id ORDER BY dr.tx_id DESC) AS rn,
tx.hash as tx_hash
FROM drep_registration dr
JOIN tx on tx.id = dr.tx_id
) as dr_voting_anchor
on dr_voting_anchor.drep_hash_id = dh.id and dr_voting_anchor.rn = 1
LEFT JOIN (
Expand Down Expand Up @@ -65,4 +68,4 @@ on tx_first_register.id = dr_first_register.tx_id
JOIN block as block_first_register
ON block_first_register.id = tx_first_register.block_id

GROUP BY dh.raw, second_to_newest_drep_registration.voting_anchor_id, dh.view, va.url, va.data_hash, dr_deposit.deposit, DRepDistr.amount, DRepActivity.epoch_no, DRepActivity.drep_activity
GROUP BY dh.raw, second_to_newest_drep_registration.voting_anchor_id, dh.view, va.url, va.data_hash, dr_deposit.deposit, DRepDistr.amount, DRepActivity.epoch_no, DRepActivity.drep_activity, dr_voting_anchor.tx_hash
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
8 changes: 6 additions & 2 deletions govtool/backend/src/VVA/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ drepRegistrationToDrep Types.DRepRegistration {..} =
dRepDeposit = dRepRegistrationDeposit,
dRepVotingPower = dRepRegistrationVotingPower,
dRepStatus = mapDRepStatus dRepRegistrationStatus,
dRepType = mapDRepType dRepRegistrationType
dRepType = mapDRepType dRepRegistrationType,
dRepLatestTxHash = HexText <$> dRepRegistrationLatestTxHash
}

drepList :: App m => Maybe Text -> m [DRep]
Expand Down Expand Up @@ -137,6 +138,7 @@ proposalToResponse Types.Proposal {..} =
proposalResponseMotivation = proposalMotivaiton,
proposalResponseRationale = proposalRationale,
proposalResponseMetadata = GovernanceActionMetadata <$> proposalMetadata,
proposalResponseReferences = GovernanceActionReferences <$> proposalReferences,
proposalResponseYesVotes = proposalYesVotes,
proposalResponseNoVotes = proposalNoVotes,
proposalResponseAbstainVotes = proposalAbstainVotes
Expand All @@ -151,7 +153,8 @@ voteToResponse Types.Vote {..} =
voteParamsUrl = voteUrl,
voteParamsMetadataHash = HexText <$> voteDocHash,
voteParamsEpochNo = voteEpochNo,
voteParamsDate = voteDate
voteParamsDate = voteDate,
voteParamsTxHash = HexText voteTxHash
}


Expand Down Expand Up @@ -208,6 +211,7 @@ drepInfo (unHexText -> dRepId) = do
, dRepInfoResponseUrl = dRepInfoUrl
, dRepInfoResponseDataHash = HexText <$> dRepInfoDataHash
, dRepInfoResponseVotingPower = dRepInfoVotingPower
, dRepInfoResponseLatestTxHash = HexText <$> dRepInfoLatestTxHash
}

getCurrentDelegation :: App m => HexText -> m (Maybe HexText)
Expand Down
49 changes: 39 additions & 10 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 Expand Up @@ -372,6 +395,7 @@ data VoteParams
, voteParamsMetadataHash :: Maybe HexText
, voteParamsEpochNo :: Integer
, voteParamsDate :: UTCTime
, voteParamsTxHash :: HexText
}
deriving (Generic, Show)

Expand All @@ -385,7 +409,8 @@ exampleVoteParams =
<> "\"url\": \"https://vote.metadata.xyz\","
<> "\"metadataHash\": \"9af10e89979e51b8cdc827c963124a1ef4920d1253eef34a1d5cfe76438e3f11\","
<> "\"epochNo\": 0,"
<> "\"date\": \"1970-01-01T00:00:00Z\"}"
<> "\"date\": \"1970-01-01T00:00:00Z\","
<> "\"txHash\": \"47c14a128cd024f1b990c839d67720825921ad87ed875def42641ddd2169b39c\"}"

instance ToSchema VoteParams where
declareNamedSchema proxy = do
Expand Down Expand Up @@ -441,6 +466,7 @@ data DRepInfoResponse
, dRepInfoResponseUrl :: Maybe Text
, dRepInfoResponseDataHash :: Maybe HexText
, dRepInfoResponseVotingPower :: Maybe Integer
, dRepInfoResponseLatestTxHash :: Maybe HexText
}
deriving (Generic, Show)

Expand All @@ -455,7 +481,8 @@ exampleDRepInfoResponse =
<> "\"deposit\": 2000000,"
<> "\"url\": \"https://drep.metadata.xyz\","
<> "\"dataHash\": \"9af10e89979e51b8cdc827c963124a1ef4920d1253eef34a1d5cfe76438e3f11\","
<> "\"votingPower\": 1000000}"
<> "\"votingPower\": 1000000,"
<> "\"latestTxHash\": \"47c14a128cd024f1b990c839d67720825921ad87ed875def42641ddd2169b39c\"}"

instance ToSchema DRepInfoResponse where
declareNamedSchema proxy = do
Expand Down Expand Up @@ -632,6 +659,7 @@ data DRep
, dRepVotingPower :: Maybe Integer
, dRepStatus :: DRepStatus
, dRepType :: DRepType
, dRepLatestTxHash :: Maybe HexText
}
deriving (Generic, Show)

Expand All @@ -640,14 +668,15 @@ deriveJSON (jsonOptions "dRep") ''DRep

exampleDrep :: Text
exampleDrep =
"{\"drepId\": \"d3a62ffe9c214e1a6a9809f7ab2a104c117f85e1f171f8f839d94be5\","
<> "\"view\": \"drep1l8uyy66sm8u82h82gc8hkcy2xu24dl8ffsh58aa0v7d37yp48u8\","
<> "\"url\": \"https://proposal.metadata.xyz\","
<> "\"metadataHash\": \"9af10e89979e51b8cdc827c963124a1ef4920d1253eef34a1d5cfe76438e3f11\","
<> "\"deposit\": 0,"
<> "\"votingPower\": 0,"
<> "\"status\": \"Active\","
<> "\"type\": \"DRep\"}"
"{\"drepId\": \"d3a62ffe9c214e1a6a9809f7ab2a104c117f85e1f171f8f839d94be5\","
<> "\"view\": \"drep1l8uyy66sm8u82h82gc8hkcy2xu24dl8ffsh58aa0v7d37yp48u8\","
<> "\"url\": \"https://proposal.metadata.xyz\","
<> "\"metadataHash\": \"9af10e89979e51b8cdc827c963124a1ef4920d1253eef34a1d5cfe76438e3f11\","
<> "\"deposit\": 0,"
<> "\"votingPower\": 0,"
<> "\"status\": \"Active\","
<> "\"type\": \"DRep\","
<> "\"latestTxHash\": \"47c14a128cd024f1b990c839d67720825921ad87ed875def42641ddd2169b39c\"}"

-- ToSchema instance for DRep
instance ToSchema DRep where
Expand Down
14 changes: 8 additions & 6 deletions govtool/backend/src/VVA/DRep.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ listDReps ::
listDReps = withPool $ \conn -> do
results <- liftIO $ SQL.query_ conn listDRepsSql
return
[ DRepRegistration drepHash drepView url dataHash (floor @Scientific deposit) votingPower status drepType
| (drepHash, drepView, url, dataHash, deposit, votingPower, isActive, wasDRep) <- results
[ DRepRegistration drepHash drepView url dataHash (floor @Scientific deposit) votingPower status drepType txHash
| (drepHash, drepView, url, dataHash, deposit, votingPower, isActive, wasDRep, txHash) <- results
, let status = case (isActive, deposit) of
(_, d) | d < 0 -> Retired
(isActive, d) | d >= 0 && isActive -> Active
Expand All @@ -82,14 +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' epochNo' (localTimeToUTC timeZone date')
| (proposalId', govActionId', drepId', vote', url', docHash', epochNo', date') <- results
([ Vote proposalId' drepId' vote' url' docHash' epochNo' (localTimeToUTC timeZone date') voteTxHash'
| (proposalId', govActionId', drepId', vote', url', docHash', epochNo', date', voteTxHash') <- results
, govActionId' `elem` proposalsToSelect
], proposals)

Expand Down Expand Up @@ -117,6 +117,7 @@ getDRepInfo drepId = withPool $ \conn -> do
, url
, dataHash
, votingPower
, txHash
)] ->
return $ DRepInfo
{ dRepInfoIsRegisteredAsDRep = fromMaybe False isRegisteredAsDRep
Expand All @@ -127,5 +128,6 @@ getDRepInfo drepId = withPool $ \conn -> do
, dRepInfoUrl = url
, dRepInfoDataHash = dataHash
, dRepInfoVotingPower = votingPower
, dRepInfoLatestTxHash = Just txHash
}
[] -> return $ DRepInfo False False False False Nothing Nothing Nothing Nothing
[] -> return $ DRepInfo False False False False Nothing Nothing Nothing Nothing Nothing
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
Loading

0 comments on commit 7349c2b

Please sign in to comment.