Skip to content

Commit 00219f4

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

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
@@ -50,6 +50,7 @@ import Test.QuickCheck (
5050
suchThat,
5151
vectorOf,
5252
)
53+
import qualified Data.Aeson as Aeson
5354

5455
-- * Ledger
5556

@@ -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)