Skip to content

Commit

Permalink
Replace ToJSON/FromJSON Tx with cbor encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
locallycompact committed Jan 9, 2024
1 parent a1b4e90 commit ad6089a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions hydra-node/src/Hydra/Ledger/Cardano.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import Cardano.Ledger.Shelley.UTxO qualified as Ledger
import Codec.CBOR.Decoding qualified as CBOR
import Codec.CBOR.Encoding qualified as CBOR
import Control.Monad (foldM)
import Data.Aeson qualified as Aeson
import Data.ByteString qualified as BS
import Data.Default (def)
import Data.Map.Strict qualified as Map
Expand Down Expand Up @@ -125,10 +126,13 @@ instance FromCBOR Tx where
(pure . fromLedgerTx)

instance ToJSON Tx where
toJSON = toJSON . toLedgerTx
toJSON tx = Aeson.String $ decodeUtf8 @Text $ serialiseToCBOR tx

instance FromJSON Tx where
parseJSON = fmap fromLedgerTx . parseJSON
parseJSON v = do
bytes <- encodeUtf8 @Text <$> parseJSON v
let cbor = deserialiseFromCBOR (proxyToAsType @Tx Proxy) bytes
either (fail . show) pure cbor

instance Arbitrary Tx where
-- TODO: shrinker!
Expand Down

0 comments on commit ad6089a

Please sign in to comment.