Skip to content

Commit

Permalink
fix(#2446): fix mzero parsing error on /proposal/list
Browse files Browse the repository at this point in the history
  • Loading branch information
MSzalowski committed Dec 12, 2024
1 parent 8130ffa commit c92e8ee
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 75 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ changes.

### Fixed

-
- Fix mzero parsing error on fetching the /proposal/list [Issue 2446](https://github.com/IntersectMBO/govtool/issues/2446)

### Changed

Expand Down
29 changes: 13 additions & 16 deletions govtool/backend/src/VVA/API/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -274,29 +274,21 @@ newtype GovernanceActionDetails
deriving newtype (Show)

instance FromJSON GovernanceActionDetails where
parseJSON v@(Aeson.Object o) = do
let kvpList = map snd $ Aeson.toList o
forM_ kvpList $ \case
(Aeson.Object _) -> fail "GovernanceActionDetails cannot have nested objects"
(Aeson.Array a) -> forM_ (toList a) $ \case
(Aeson.Object _) -> fail "GovernanceActionDetails cannot have nested objects"
(Aeson.Array _) -> fail "GovernanceActionDetails cannot have nested arrays"
_ -> pure ()
_ -> pure ()
return $ GovernanceActionDetails v
parseJSON _ = fail "GovernanceActionDetails has to be an object"
parseJSON v = return $ GovernanceActionDetails v

instance ToJSON GovernanceActionDetails where
toJSON (GovernanceActionDetails g) = g

instance ToSchema GovernanceActionDetails where
declareNamedSchema _ = pure $ NamedSchema (Just "GovernanceActionDetails") $ mempty
& type_ ?~ OpenApiObject
& description ?~ "A simple JSON value, with object type values, and no nested arrays"
& example
?~ toJSON
("{\"some_key\": \"some value\", \"some_key2\": [1,2,3]}" :: Text)

& description ?~ "A JSON value that can include nested objects and arrays"
& example ?~ toJSON
(Aeson.object
[ "some_key" .= ("some value" :: String)
, "nested_key" .= Aeson.object ["inner_key" .= (1 :: Int)]
, "array_key" .= [1, 2, 3 :: Int]
])

newtype GovernanceActionMetadata
= GovernanceActionMetadata Value
Expand Down Expand Up @@ -440,6 +432,11 @@ exampleProposalResponse = "{ \"id\": \"proposalId123\","
<> "\"prevGovActionIndex\": 0,"
<> "\"prevGovActionTxHash\": \"47c14a128cd024f1b990c839d67720825921ad87ed875def42641ddd2169b39c\"}"

instance ToSchema Value where
declareNamedSchema _ = pure $ NamedSchema (Just "Value") $ mempty
& type_ ?~ OpenApiObject
& description ?~ "Arbitrary JSON value"

instance ToSchema ProposalResponse where
declareNamedSchema proxy = do
NamedSchema name_ schema_ <-
Expand Down
4 changes: 2 additions & 2 deletions govtool/backend/src/VVA/Proposal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,6 @@ getProposals mSearchTerms = withPool $ \conn -> do
)
case result of
Left (e :: SomeException) -> do
putStrLn $ "Error fetching proposals: " <> show e
return []
Right rows -> do
return rows
Right rows -> return rows
112 changes: 56 additions & 56 deletions govtool/backend/src/VVA/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -122,69 +122,69 @@ data DRepRegistration
, dRepRegistrationImageHash :: Maybe Text
}

data Proposal
data Proposal
= Proposal
{ proposalId :: Integer
, proposalTxHash :: Text
, proposalIndex :: Integer
, proposalType :: Text
, proposalDetails :: Maybe Value
, proposalExpiryDate :: Maybe LocalTime
, proposalExpiryEpochNo :: Maybe Integer
, proposalCreatedDate :: LocalTime
, proposalCreatedEpochNo :: Integer
, proposalUrl :: Text
, proposalDocHash :: Text
, proposalProtocolParams :: Maybe Value
, proposalTitle :: Maybe Text
, proposalAbstract :: Maybe Text
, proposalMotivation :: Maybe Text
, proposalRationale :: Maybe Text
, proposalDRepYesVotes :: Integer
, proposalDRepNoVotes :: Integer
, proposalDRepAbstainVotes :: Integer
, proposalPoolYesVotes :: Integer
, proposalPoolNoVotes :: Integer
, proposalPoolAbstainVotes :: Integer
, proposalCcYesVotes :: Integer
, proposalCcNoVotes :: Integer
, proposalCcAbstainVotes :: Integer
, proposalPrevGovActionIndex :: Maybe Integer
, proposalPrevGovActionTxHash :: Maybe Text
{ proposalId :: Integer
, proposalTxHash :: Text
, proposalIndex :: Integer
, proposalType :: Text
, proposalDetails :: Maybe Value
, proposalExpiryDate :: Maybe LocalTime
, proposalExpiryEpochNo :: Maybe Integer
, proposalCreatedDate :: LocalTime
, proposalCreatedEpochNo :: Integer
, proposalUrl :: Text
, proposalDocHash :: Text
, proposalProtocolParams :: Maybe Value
, proposalTitle :: Maybe Text
, proposalAbstract :: Maybe Text
, proposalMotivation :: Maybe Text
, proposalRationale :: Maybe Text
, proposalDRepYesVotes :: Integer
, proposalDRepNoVotes :: Integer
, proposalDRepAbstainVotes :: Integer
, proposalPoolYesVotes :: Integer
, proposalPoolNoVotes :: Integer
, proposalPoolAbstainVotes :: Integer
, proposalCcYesVotes :: Integer
, proposalCcNoVotes :: Integer
, proposalCcAbstainVotes :: Integer
, proposalPrevGovActionIndex :: Maybe Integer
, proposalPrevGovActionTxHash :: Maybe Text
}
deriving (Show)

instance FromRow Proposal where
fromRow =
Proposal
<$> field
<*> field
<*> (floor @Scientific <$> field)
<*> field
<*> field
<*> field
<*> field
<*> field
<*> field
<*> field
<*> field
<*> field
<*> field
<*> field
<*> field
<*> field
<*> (floor @Scientific <$> field)
<*> (floor @Scientific <$> field)
<*> (floor @Scientific <$> field)
<*> (floor @Scientific <$> field)
<*> (floor @Scientific <$> field)
<*> (floor @Scientific <$> field)
<*> (floor @Scientific <$> field)
<*> (floor @Scientific <$> field)
<*> (floor @Scientific <$> field)
<*> field
<*> field
<$> field -- proposalId
<*> field -- proposalTxHash
<*> (floor @Scientific <$> field) -- proposalIndex
<*> field -- proposalType
<*> field -- proposalDetails
<*> field -- proposalExpiryDate
<*> field -- proposalExpiryEpochNo
<*> field -- proposalCreatedDate
<*> field -- proposalCreatedEpochNo
<*> field -- proposalUrl
<*> field -- proposalDocHash
<*> field -- proposalProtocolParams
<*> field -- proposalTitle
<*> field -- proposalAbstract
<*> field -- proposalMotivation
<*> field -- proposalRationale
<*> (floor @Scientific <$> field) -- proposalDRepYesVotes
<*> (floor @Scientific <$> field) -- proposalDRepNoVotes
<*> (floor @Scientific <$> field) -- proposalDRepAbstainVotes
<*> (floor @Scientific <$> field) -- proposalPoolYesVotes
<*> (floor @Scientific <$> field) -- proposalPoolNoVotes
<*> (floor @Scientific <$> field) -- proposalPoolAbstainVotes
<*> (floor @Scientific <$> field) -- proposalCcYesVotes
<*> (floor @Scientific <$> field) -- proposalCcNoVotes
<*> (floor @Scientific <$> field) -- proposalCcAbstainVotes
<*> field -- prevGovActionIndex
<*> field -- prevGovActionTxHash

data TransactionStatus = TransactionStatus
{ transactionConfirmed :: Bool
, votingProcedure :: Maybe Value
Expand Down

0 comments on commit c92e8ee

Please sign in to comment.