Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ changes.

### Added

- Add feature-flagged CIP-179 linked survey authoring, rendering, and vote-response submission for governance actions

### Fixed

- Fix disappearing proposals in the governance actions list for the same tx hashes [Issue 3918](https://github.com/IntersectMBO/govtool/issues/3918)
Expand Down
6 changes: 6 additions & 0 deletions govtool/backend/sql/get-survey-definition.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT encode(tx_metadata.bytes, 'hex')
FROM tx_metadata
JOIN tx ON tx.id = tx_metadata.tx_id
WHERE tx.hash = decode(?, 'hex')
AND tx_metadata.key = 17
LIMIT 1;
18 changes: 17 additions & 1 deletion govtool/backend/src/VVA/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Control.Exception (throw, throwIO)
import Control.Monad.Except (runExceptT, throwError)
import Control.Monad.Reader

import Data.Aeson (Array, ToJSON, Value (..), decode, toJSON)
import Data.Aeson (Array, ToJSON, Value (..), decode, object, toJSON, (.=))
import Data.Bool (Bool)
import Data.ByteString.Lazy (ByteString)
import qualified Data.ByteString.Lazy as BSL
Expand Down Expand Up @@ -50,6 +50,7 @@ import qualified VVA.Epoch as Epoch
import qualified VVA.Ipfs as Ipfs
import VVA.Network as Network
import qualified VVA.Proposal as Proposal
import qualified VVA.Survey as Survey
import qualified VVA.Transaction as Transaction
import qualified VVA.Types as Types
import VVA.Types (App, AppEnv (..),
Expand Down Expand Up @@ -89,6 +90,7 @@ type VVAApi =
:> QueryParam "search" Text
:> Get '[JSON] ListProposalsResponse
:<|> "proposal" :> "get" :> Capture "proposalId" GovActionId :> QueryParam "drepId" HexText :> Get '[JSON] GetProposalResponse
:<|> "survey" :> "definition" :> Capture "txId" HexText :> Capture "index" Natural :> Get '[JSON] (Headers '[Header "Cache-Control" Text] AnyValue)
:<|> "proposal" :> "enacted-details" :> QueryParam "type" GovernanceActionType :> Get '[JSON] (Maybe EnactedProposalDetailsResponse)
:<|> "epoch" :> "params" :> Get '[JSON] GetCurrentEpochParamsResponse
:<|> "transaction" :> "status" :> Capture "transactionId" HexText :> Get '[JSON] GetTransactionStatusResponse
Expand All @@ -109,6 +111,7 @@ server = upload
:<|> getStakeKeyVotingPower
:<|> listProposals
:<|> getProposal
:<|> getSurveyDefinition
:<|> getEnactedProposalDetails
:<|> getCurrentEpochParams
:<|> getTransactionStatus
Expand All @@ -118,6 +121,19 @@ server = upload
:<|> getNetworkTotalStake
:<|> getAccountInfo

getSurveyDefinition :: App m => HexText -> Natural -> m (Headers '[Header "Cache-Control" Text] AnyValue)
getSurveyDefinition (unHexText -> txId) surveyIndex = do
when (Text.length txId /= 64) $
throwError $ ValidationError "txId must be a 64-character hex string"
payloadCborHex <- Survey.getSurveyDefinition txId
pure $ addHeader "public, max-age=31536000, immutable" $ AnyValue $ Just $
object
[ "txId" .= Text.toLower txId
, "surveyIndex" .= surveyIndex
, "metadataLabel" .= (17 :: Integer)
, "payloadCborHex" .= payloadCborHex
]

upload :: App m => Maybe Text -> Text -> m UploadResponse
upload mFileName fileContentText = do
AppEnv {vvaConfig} <- ask
Expand Down
34 changes: 34 additions & 0 deletions govtool/backend/src/VVA/Survey.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}

module VVA.Survey where

import Control.Monad.Except (MonadError, throwError)
import Control.Monad.Reader
import Data.ByteString (ByteString)
import Data.FileEmbed (embedFile)
import Data.Has (Has)
import Data.String (fromString)
import Data.Text (Text, unpack)
import qualified Data.Text.Encoding as Text
import qualified Database.PostgreSQL.Simple as SQL
import VVA.Pool (ConnectionPool, withPool)
import VVA.Types (AppError (..))

sqlFrom :: ByteString -> SQL.Query
sqlFrom bs = fromString $ unpack $ Text.decodeUtf8 bs

getSurveyDefinitionSql :: SQL.Query
getSurveyDefinitionSql = sqlFrom $(embedFile "sql/get-survey-definition.sql")

getSurveyDefinition ::
(Has ConnectionPool r, MonadReader r m, MonadIO m, MonadError AppError m) =>
Text ->
m Text
getSurveyDefinition txId = withPool $ \conn -> do
result <- liftIO $ SQL.query conn getSurveyDefinitionSql (SQL.Only txId)
case result of
[SQL.Only payload] -> pure payload
_ -> throwError $ NotFoundError $
"No metadata label 17 found for transaction " <> txId
2 changes: 2 additions & 0 deletions govtool/backend/vva-be.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ extra-source-files:
sql/get-filtered-dreps-voting-power.sql
sql/get-previous-enacted-governance-action-proposal-details.sql
sql/get-account-info.sql
sql/get-survey-definition.sql
executable vva-be
main-is: Main.hs

Expand Down Expand Up @@ -131,4 +132,5 @@ library
, VVA.Network
, VVA.Account
, VVA.Ipfs
, VVA.Survey
ghc-options: -threaded
3 changes: 2 additions & 1 deletion govtool/frontend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ VITE_IS_DEV=true
VITE_USERSNAP_SPACE_API_KEY=""
VITE_IS_PROPOSAL_DISCUSSION_FORUM_ENABLED='true'
VITE_IS_GOVERNANCE_OUTCOMES_PILLAR_ENABLED='true'
VITE_IS_CIP179_ENABLED='false'
VITE_PDF_API_URL=""
VITE_OUTCOMES_API_URL=""
VITE_IPFS_GATEWAY=""
VITE_IPFS_PROJECT_ID=""
VITE_IPFS_PROJECT_ID=""
145 changes: 145 additions & 0 deletions govtool/frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions govtool/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@
"blakejs": "^1.2.1",
"buffer": "^6.0.3",
"cbor-web": "^10.0.3",
"cip-179": "0.2.0",
"date-fns": "^2.30.0",
"esbuild": "^0.25.0",
"i18next": "^23.7.19",
"jsonld": "^9.0.0",
"@mattpiz/tlock-js": "0.10.0",
"katex": "^0.16.21",
"keen-slider": "^6.8.5",
"patch-package": "^8.0.0",
Expand Down
Loading