Skip to content

Commit c92e8ee

Browse files
committed
fix(#2446): fix mzero parsing error on /proposal/list
1 parent 8130ffa commit c92e8ee

File tree

4 files changed

+72
-75
lines changed

4 files changed

+72
-75
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ changes.
1616

1717
### Fixed
1818

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

2121
### Changed
2222

govtool/backend/src/VVA/API/Types.hs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -274,29 +274,21 @@ newtype GovernanceActionDetails
274274
deriving newtype (Show)
275275

276276
instance FromJSON GovernanceActionDetails where
277-
parseJSON v@(Aeson.Object o) = do
278-
let kvpList = map snd $ Aeson.toList o
279-
forM_ kvpList $ \case
280-
(Aeson.Object _) -> fail "GovernanceActionDetails cannot have nested objects"
281-
(Aeson.Array a) -> forM_ (toList a) $ \case
282-
(Aeson.Object _) -> fail "GovernanceActionDetails cannot have nested objects"
283-
(Aeson.Array _) -> fail "GovernanceActionDetails cannot have nested arrays"
284-
_ -> pure ()
285-
_ -> pure ()
286-
return $ GovernanceActionDetails v
287-
parseJSON _ = fail "GovernanceActionDetails has to be an object"
277+
parseJSON v = return $ GovernanceActionDetails v
288278

289279
instance ToJSON GovernanceActionDetails where
290280
toJSON (GovernanceActionDetails g) = g
291281

292282
instance ToSchema GovernanceActionDetails where
293283
declareNamedSchema _ = pure $ NamedSchema (Just "GovernanceActionDetails") $ mempty
294284
& type_ ?~ OpenApiObject
295-
& description ?~ "A simple JSON value, with object type values, and no nested arrays"
296-
& example
297-
?~ toJSON
298-
("{\"some_key\": \"some value\", \"some_key2\": [1,2,3]}" :: Text)
299-
285+
& description ?~ "A JSON value that can include nested objects and arrays"
286+
& example ?~ toJSON
287+
(Aeson.object
288+
[ "some_key" .= ("some value" :: String)
289+
, "nested_key" .= Aeson.object ["inner_key" .= (1 :: Int)]
290+
, "array_key" .= [1, 2, 3 :: Int]
291+
])
300292

301293
newtype GovernanceActionMetadata
302294
= GovernanceActionMetadata Value
@@ -440,6 +432,11 @@ exampleProposalResponse = "{ \"id\": \"proposalId123\","
440432
<> "\"prevGovActionIndex\": 0,"
441433
<> "\"prevGovActionTxHash\": \"47c14a128cd024f1b990c839d67720825921ad87ed875def42641ddd2169b39c\"}"
442434

435+
instance ToSchema Value where
436+
declareNamedSchema _ = pure $ NamedSchema (Just "Value") $ mempty
437+
& type_ ?~ OpenApiObject
438+
& description ?~ "Arbitrary JSON value"
439+
443440
instance ToSchema ProposalResponse where
444441
declareNamedSchema proxy = do
445442
NamedSchema name_ schema_ <-

govtool/backend/src/VVA/Proposal.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,6 @@ getProposals mSearchTerms = withPool $ \conn -> do
8282
)
8383
case result of
8484
Left (e :: SomeException) -> do
85+
putStrLn $ "Error fetching proposals: " <> show e
8586
return []
86-
Right rows -> do
87-
return rows
87+
Right rows -> return rows

govtool/backend/src/VVA/Types.hs

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -122,69 +122,69 @@ data DRepRegistration
122122
, dRepRegistrationImageHash :: Maybe Text
123123
}
124124

125-
data Proposal
125+
data Proposal
126126
= Proposal
127-
{ proposalId :: Integer
128-
, proposalTxHash :: Text
129-
, proposalIndex :: Integer
130-
, proposalType :: Text
131-
, proposalDetails :: Maybe Value
132-
, proposalExpiryDate :: Maybe LocalTime
133-
, proposalExpiryEpochNo :: Maybe Integer
134-
, proposalCreatedDate :: LocalTime
135-
, proposalCreatedEpochNo :: Integer
136-
, proposalUrl :: Text
137-
, proposalDocHash :: Text
138-
, proposalProtocolParams :: Maybe Value
139-
, proposalTitle :: Maybe Text
140-
, proposalAbstract :: Maybe Text
141-
, proposalMotivation :: Maybe Text
142-
, proposalRationale :: Maybe Text
143-
, proposalDRepYesVotes :: Integer
144-
, proposalDRepNoVotes :: Integer
145-
, proposalDRepAbstainVotes :: Integer
146-
, proposalPoolYesVotes :: Integer
147-
, proposalPoolNoVotes :: Integer
148-
, proposalPoolAbstainVotes :: Integer
149-
, proposalCcYesVotes :: Integer
150-
, proposalCcNoVotes :: Integer
151-
, proposalCcAbstainVotes :: Integer
152-
, proposalPrevGovActionIndex :: Maybe Integer
153-
, proposalPrevGovActionTxHash :: Maybe Text
127+
{ proposalId :: Integer
128+
, proposalTxHash :: Text
129+
, proposalIndex :: Integer
130+
, proposalType :: Text
131+
, proposalDetails :: Maybe Value
132+
, proposalExpiryDate :: Maybe LocalTime
133+
, proposalExpiryEpochNo :: Maybe Integer
134+
, proposalCreatedDate :: LocalTime
135+
, proposalCreatedEpochNo :: Integer
136+
, proposalUrl :: Text
137+
, proposalDocHash :: Text
138+
, proposalProtocolParams :: Maybe Value
139+
, proposalTitle :: Maybe Text
140+
, proposalAbstract :: Maybe Text
141+
, proposalMotivation :: Maybe Text
142+
, proposalRationale :: Maybe Text
143+
, proposalDRepYesVotes :: Integer
144+
, proposalDRepNoVotes :: Integer
145+
, proposalDRepAbstainVotes :: Integer
146+
, proposalPoolYesVotes :: Integer
147+
, proposalPoolNoVotes :: Integer
148+
, proposalPoolAbstainVotes :: Integer
149+
, proposalCcYesVotes :: Integer
150+
, proposalCcNoVotes :: Integer
151+
, proposalCcAbstainVotes :: Integer
152+
, proposalPrevGovActionIndex :: Maybe Integer
153+
, proposalPrevGovActionTxHash :: Maybe Text
154154
}
155155
deriving (Show)
156156

157157
instance FromRow Proposal where
158158
fromRow =
159159
Proposal
160-
<$> field
161-
<*> field
162-
<*> (floor @Scientific <$> field)
163-
<*> field
164-
<*> field
165-
<*> field
166-
<*> field
167-
<*> field
168-
<*> field
169-
<*> field
170-
<*> field
171-
<*> field
172-
<*> field
173-
<*> field
174-
<*> field
175-
<*> field
176-
<*> (floor @Scientific <$> field)
177-
<*> (floor @Scientific <$> field)
178-
<*> (floor @Scientific <$> field)
179-
<*> (floor @Scientific <$> field)
180-
<*> (floor @Scientific <$> field)
181-
<*> (floor @Scientific <$> field)
182-
<*> (floor @Scientific <$> field)
183-
<*> (floor @Scientific <$> field)
184-
<*> (floor @Scientific <$> field)
185-
<*> field
186-
<*> field
187-
160+
<$> field -- proposalId
161+
<*> field -- proposalTxHash
162+
<*> (floor @Scientific <$> field) -- proposalIndex
163+
<*> field -- proposalType
164+
<*> field -- proposalDetails
165+
<*> field -- proposalExpiryDate
166+
<*> field -- proposalExpiryEpochNo
167+
<*> field -- proposalCreatedDate
168+
<*> field -- proposalCreatedEpochNo
169+
<*> field -- proposalUrl
170+
<*> field -- proposalDocHash
171+
<*> field -- proposalProtocolParams
172+
<*> field -- proposalTitle
173+
<*> field -- proposalAbstract
174+
<*> field -- proposalMotivation
175+
<*> field -- proposalRationale
176+
<*> (floor @Scientific <$> field) -- proposalDRepYesVotes
177+
<*> (floor @Scientific <$> field) -- proposalDRepNoVotes
178+
<*> (floor @Scientific <$> field) -- proposalDRepAbstainVotes
179+
<*> (floor @Scientific <$> field) -- proposalPoolYesVotes
180+
<*> (floor @Scientific <$> field) -- proposalPoolNoVotes
181+
<*> (floor @Scientific <$> field) -- proposalPoolAbstainVotes
182+
<*> (floor @Scientific <$> field) -- proposalCcYesVotes
183+
<*> (floor @Scientific <$> field) -- proposalCcNoVotes
184+
<*> (floor @Scientific <$> field) -- proposalCcAbstainVotes
185+
<*> field -- prevGovActionIndex
186+
<*> field -- prevGovActionTxHash
187+
188188
data TransactionStatus = TransactionStatus
189189
{ transactionConfirmed :: Bool
190190
, votingProcedure :: Maybe Value

0 commit comments

Comments
 (0)