@@ -12,8 +12,6 @@ import Hydra.Prelude
12
12
import Hydra.Cardano.Api hiding (initialLedgerState )
13
13
import Hydra.Ledger.Cardano.Builder
14
14
15
- import Data.Aeson (object , (.:) , (.=) )
16
- import Data.Aeson qualified as Aeson
17
15
import Cardano.Api.UTxO (fromPairs , pairs )
18
16
import Cardano.Api.UTxO qualified as UTxO
19
17
import Cardano.Crypto.DSIGN qualified as CC
@@ -30,7 +28,11 @@ import Cardano.Ledger.Shelley.UTxO qualified as Ledger
30
28
import Codec.CBOR.Decoding qualified as CBOR
31
29
import Codec.CBOR.Encoding qualified as CBOR
32
30
import Control.Monad (foldM )
31
+ import Data.Aeson (object , (.:) , (.:?) , (.=) )
32
+ import Data.Aeson qualified as Aeson
33
+ import Data.Aeson.Types (withObject )
33
34
import Data.ByteString qualified as BS
35
+ import Data.ByteString.Base16 qualified as Base16
34
36
import Data.Default (def )
35
37
import Data.Map.Strict qualified as Map
36
38
import Data.Maybe (fromJust )
@@ -52,9 +54,6 @@ import Test.QuickCheck (
52
54
suchThat ,
53
55
vectorOf ,
54
56
)
55
- import qualified Data.ByteString.Base16 as Base16
56
- import Data.Aeson.Types (withObject )
57
- import Data.Aeson ((.:?) )
58
57
59
58
-- * Ledger
60
59
@@ -130,20 +129,28 @@ instance FromCBOR Tx where
130
129
(pure . fromLedgerTx)
131
130
132
131
instance ToJSON Tx where
133
- toJSON tx = object [ " cborHex" .= (Aeson. String $ decodeUtf8 $ Base16. encode $ serialiseToCBOR tx) ]
132
+ toJSON tx =
133
+ object
134
+ [ " cborHex" .= (Aeson. String $ decodeUtf8 $ Base16. encode $ serialiseToCBOR tx)
135
+ , " txId" .= (txId tx)
136
+ ]
134
137
135
138
instance FromJSON Tx where
136
- parseJSON =
137
- withObject " Tx" $ \ o -> do
138
- let TextEnvelopeType envelopeType = textEnvelopeType (proxyToAsType (Proxy @ Tx ))
139
- hexText <- o .: " cborHex"
140
- (o .:? " type" ) >>= \ case
139
+ parseJSON =
140
+ withObject " Tx" $ \ o -> do
141
+ let TextEnvelopeType envelopeType = textEnvelopeType (proxyToAsType (Proxy @ Tx ))
142
+ hexText <- o .: " cborHex"
143
+ (o .:? " type" ) >>= \ case
144
+ Nothing -> pure ()
145
+ Just x -> guard (envelopeType == x)
146
+ bytes <- decodeBase16 hexText
147
+ case deserialiseFromCBOR (proxyToAsType (Proxy @ Tx )) bytes of
148
+ Left e -> fail $ show e
149
+ Right tx -> (o .:? " txId" ) >>= \ case
141
150
Nothing -> pure ()
142
- Just x -> guard (envelopeType == x)
143
- bytes <- decodeBase16 hexText
144
- case deserialiseFromCBOR (proxyToAsType (Proxy @ Tx )) bytes of
145
- Left e -> fail $ show e
146
- Right x -> pure x
151
+ Just txid' -> do
152
+ guard (txid' == (txId tx))
153
+ pure tx
147
154
148
155
instance Arbitrary Tx where
149
156
-- TODO: shrinker!
0 commit comments