Skip to content

Commit ad6089a

Browse files
Replace ToJSON/FromJSON Tx with cbor encoding
1 parent a1b4e90 commit ad6089a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

hydra-node/src/Hydra/Ledger/Cardano.hs

+6-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import Cardano.Ledger.Shelley.UTxO qualified as Ledger
2828
import Codec.CBOR.Decoding qualified as CBOR
2929
import Codec.CBOR.Encoding qualified as CBOR
3030
import Control.Monad (foldM)
31+
import Data.Aeson qualified as Aeson
3132
import Data.ByteString qualified as BS
3233
import Data.Default (def)
3334
import Data.Map.Strict qualified as Map
@@ -125,10 +126,13 @@ instance FromCBOR Tx where
125126
(pure . fromLedgerTx)
126127

127128
instance ToJSON Tx where
128-
toJSON = toJSON . toLedgerTx
129+
toJSON tx = Aeson.String $ decodeUtf8 @Text $ serialiseToCBOR tx
129130

130131
instance FromJSON Tx where
131-
parseJSON = fmap fromLedgerTx . parseJSON
132+
parseJSON v = do
133+
bytes <- encodeUtf8 @Text <$> parseJSON v
134+
let cbor = deserialiseFromCBOR (proxyToAsType @Tx Proxy) bytes
135+
either (fail . show) pure cbor
132136

133137
instance Arbitrary Tx where
134138
-- TODO: shrinker!

0 commit comments

Comments
 (0)