Skip to content

Commit

Permalink
Fix golden spec for draft empty commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ffakenz committed Apr 16, 2024
1 parent 934703e commit c0f24ae
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions hydra-node/src/Hydra/API/HTTPServer.hs
Expand Up @@ -6,7 +6,7 @@ module Hydra.API.HTTPServer where
import Hydra.Prelude

import Cardano.Ledger.Core (PParams)
import Data.Aeson (KeyValue ((.=)), object, withEmbeddedJSON, withObject, (.:))
import Data.Aeson (KeyValue ((.=)), object, withObject, (.:))
import Data.Aeson qualified as Aeson
import Data.Aeson.Types (parseFail)
import Data.ByteString.Lazy qualified as LBS
Expand Down Expand Up @@ -87,20 +87,19 @@ instance IsTx tx => ToJSON (DraftCommitTxRequest tx) where
toJSON utxoToCommit

instance IsTx tx => FromJSON (DraftCommitTxRequest tx) where
parseJSON js = fullVariant js <|> simpleVariant js <|> emptyVariant js
parseJSON js = asum [fullVariant js, simpleVariant js]
where
fullVariant = withObject "FullCommitRequest" $ \o -> do
blueprintTx :: tx <- o .: "blueprintTx"
utxo <- o .: "utxo"
pure FullCommitRequest{blueprintTx, utxo}

simpleVariant = withEmbeddedJSON "SimpleCommitRequest" $ \v -> do
SimpleCommitRequest <$> parseJSON v

emptyVariant = withObject "EmptyCommit" $ \o -> do
if o == mempty
then pure $ SimpleCommitRequest mempty
else parseFail "Failed to parse JSON as SimpleCommitRequest"
simpleVariant = withObject "SimpleCommitRequest" $ \o -> do
if null o
then pure (SimpleCommitRequest mempty)
else case Aeson.decode $ Aeson.encode o of
Nothing -> parseFail "Failed to parse json as SimpleCommitRequest"
Just utxoToCommit -> pure (SimpleCommitRequest utxoToCommit)

instance (Arbitrary tx, Arbitrary (UTxOType tx)) => Arbitrary (DraftCommitTxRequest tx) where
arbitrary = genericArbitrary
Expand Down

0 comments on commit c0f24ae

Please sign in to comment.