@@ -11,35 +11,17 @@ module Hydra.Ledger.Cardano.Json where
11
11
import Hydra.Cardano.Api
12
12
import Hydra.Prelude
13
13
14
- import Cardano.Binary (serialize )
15
14
import Cardano.Ledger.Api (Babbage )
16
- import Cardano.Ledger.Api qualified as Ledger
17
15
import Cardano.Ledger.Api.Era (eraProtVerLow )
18
16
import Cardano.Ledger.Babbage.PParams (BabbagePParams (.. ))
19
17
import Cardano.Ledger.Babbage.PParams qualified as Ledger
20
- import Cardano.Ledger.Babbage.Tx qualified as Ledger
21
- import Cardano.Ledger.Binary (
22
- DecCBOR ,
23
- EncCBOR ,
24
- decCBOR ,
25
- decodeFullAnnotator ,
26
- decodeFullDecoder ,
27
- )
28
- import Cardano.Ledger.Binary.Decoding (Annotator )
29
18
import Cardano.Ledger.Shelley.API qualified as Ledger
30
19
import Data.Aeson (
31
- Value (String ),
32
- withObject ,
33
- withText ,
34
20
(.!=) ,
35
21
(.:) ,
36
22
(.:?) ,
37
23
)
38
24
import Data.Aeson qualified as Aeson
39
- import Data.Aeson.Types (
40
- Parser ,
41
- )
42
- import Data.ByteString.Base16 qualified as Base16
43
25
44
26
-- XXX: Maybe use babbagePParamsHKDPairs?
45
27
instance FromJSON (Ledger. BabbagePParams Identity era ) where
@@ -92,80 +74,3 @@ instance FromJSON (Ledger.BabbagePParams Identity era) where
92
74
.: " collateralPercentage"
93
75
<*> obj
94
76
.: " maxCollateralInputs"
95
-
96
- --
97
- -- AlonzoTx
98
- --
99
-
100
- instance
101
- ( EncCBOR (Ledger. TxBody era )
102
- , EncCBOR (Ledger. TxWits era )
103
- , EncCBOR (Ledger. TxAuxData era )
104
- , Ledger. EraTxBody era
105
- , Ledger. Era era
106
- ) =>
107
- ToJSON (Ledger. AlonzoTx era )
108
- where
109
- toJSON = Aeson. String . decodeUtf8 . Base16. encode . toStrict . serialize
110
-
111
- instance
112
- ( DecCBOR (Annotator (Ledger. TxBody era ))
113
- , DecCBOR (Annotator (Ledger. TxWits era ))
114
- , DecCBOR (Annotator (Ledger. TxAuxData era ))
115
- , Ledger. Era era
116
- ) =>
117
- FromJSON (Ledger. AlonzoTx era )
118
- where
119
- parseJSON value =
120
- -- We accept transactions in three forms:
121
- --
122
- -- (1) As a JSON 'text-envelope', which is a format defined and produced by
123
- -- the cardano-cli, wrapping base16-encoded strings as JSON objects with
124
- -- tags.
125
- parseAsEnvelopedBase16CBOR value
126
- -- (2) As base16 string representing a CBOR-serialized transaction, since
127
- -- this is the most common medium of exchange used for transactions.
128
- <|> parseHexEncodedCborAnnotated @ era " Tx" value
129
- where
130
- parseAsEnvelopedBase16CBOR =
131
- withObject " Tx" $ \ o -> do
132
- let TextEnvelopeType envelopeType = textEnvelopeType (proxyToAsType (Proxy @ Tx ))
133
- str <- o .: " cborHex"
134
- guard . (== envelopeType) =<< (o .: " type" )
135
- parseHexEncodedCborAnnotated @ era " Tx" (String str)
136
-
137
- -- | Parse a hex-encoded CBOR value in given 'era'.
138
- parseHexEncodedCbor ::
139
- forall era a .
140
- (Ledger. Era era , DecCBOR a ) =>
141
- Text ->
142
- Aeson. Value ->
143
- Parser a
144
- parseHexEncodedCbor lbl =
145
- withText (toString lbl) $ \ t ->
146
- case Base16. decode $ encodeUtf8 t of
147
- Left e -> fail $ " failed to decode from base16: " <> show e
148
- Right bs ->
149
- case decodeFullDecoder version lbl decCBOR (fromStrict bs) of
150
- Left err -> fail $ show err
151
- Right v -> pure v
152
- where
153
- version = Ledger. eraProtVerLow @ era
154
-
155
- -- | Parse a hex-encoded, annotated CBOR value in given 'era'.
156
- parseHexEncodedCborAnnotated ::
157
- forall era a .
158
- (Ledger. Era era , DecCBOR (Annotator a )) =>
159
- Text ->
160
- Aeson. Value ->
161
- Parser a
162
- parseHexEncodedCborAnnotated lbl =
163
- withText (toString lbl) $ \ t ->
164
- case Base16. decode $ encodeUtf8 t of
165
- Left e -> fail $ " failed to decode from base16: " <> show e
166
- Right bs ->
167
- case decodeFullAnnotator version lbl decCBOR (fromStrict bs) of
168
- Left err -> fail $ show err
169
- Right v -> pure v
170
- where
171
- version = Ledger. eraProtVerLow @ era
0 commit comments