1
1
{-# LANGUAGE DataKinds #-}
2
+ {-# LANGUAGE DeriveAnyClass #-}
2
3
{-# LANGUAGE DerivingVia #-}
3
4
{-# LANGUAGE DisambiguateRecordFields #-}
4
5
{-# LANGUAGE EmptyCase #-}
5
6
{-# LANGUAGE FlexibleContexts #-}
6
7
{-# LANGUAGE FlexibleInstances #-}
7
8
{-# LANGUAGE GADTs #-}
9
+ {-# LANGUAGE GeneralizedNewtypeDeriving #-}
10
+ {-# LANGUAGE InstanceSigs #-}
8
11
{-# LANGUAGE LambdaCase #-}
9
12
{-# LANGUAGE RankNTypes #-}
10
13
{-# LANGUAGE ScopedTypeVariables #-}
11
14
{-# LANGUAGE StandaloneDeriving #-}
12
15
{-# LANGUAGE TypeApplications #-}
13
16
{-# LANGUAGE TypeFamilies #-}
14
17
{-# LANGUAGE TypeOperators #-}
18
+ {-# LANGUAGE UndecidableInstances #-}
15
19
16
20
module Cardano.Api.Tx.Internal.Output
17
21
( -- * Transaction outputs
@@ -62,7 +66,7 @@ import Cardano.Api.Era.Internal.Eon.BabbageEraOnwards
62
66
import Cardano.Api.Era.Internal.Eon.Convert
63
67
import Cardano.Api.Era.Internal.Eon.ShelleyBasedEra
64
68
import Cardano.Api.Error (Error (.. ), displayError )
65
- import Cardano.Api.Hash
69
+ import Cardano.Api.HasTypeProxy qualified as HTP
66
70
import Cardano.Api.Ledger.Internal.Reexport qualified as Ledger
67
71
import Cardano.Api.Monad.Error
68
72
import Cardano.Api.Parser.Text qualified as P
@@ -81,11 +85,11 @@ import Cardano.Ledger.Alonzo.Core qualified as L
81
85
import Cardano.Ledger.Api qualified as L
82
86
import Cardano.Ledger.BaseTypes (StrictMaybe (.. ))
83
87
import Cardano.Ledger.Coin qualified as L
84
- import Cardano.Ledger.Core ()
85
88
import Cardano.Ledger.Core qualified as Core
86
89
import Cardano.Ledger.Core qualified as Ledger
87
90
import Cardano.Ledger.Plutus.Data qualified as Plutus
88
91
92
+ import Codec.CBOR.Encoding (Encoding )
89
93
import Data.Aeson (object , withObject , (.:) , (.:?) , (.=) )
90
94
import Data.Aeson qualified as Aeson
91
95
import Data.Aeson.Key qualified as Aeson
@@ -99,6 +103,7 @@ import Data.Sequence.Strict qualified as Seq
99
103
import Data.Text (Text )
100
104
import Data.Text.Encoding qualified as Text
101
105
import Data.Type.Equality
106
+ import Data.Typeable (Typeable )
102
107
import Data.Word
103
108
import GHC.Exts (IsList (.. ))
104
109
import GHC.Stack
@@ -120,6 +125,24 @@ data TxOut ctx era
120
125
(TxOutValue era )
121
126
(TxOutDatum ctx era )
122
127
(ReferenceScript era )
128
+ deriving SerialiseAsCBOR
129
+
130
+ instance (Typeable ctx , IsShelleyBasedEra era ) => HTP. HasTypeProxy (TxOut ctx era ) where
131
+ data AsType (TxOut ctx era ) = AsTxOut (AsType era )
132
+ proxyToAsType :: HTP. Proxy (TxOut ctx era ) -> AsType (TxOut ctx era )
133
+ proxyToAsType _ = AsTxOut (HTP.asType @ era )
134
+
135
+ instance (Typeable ctx , IsShelleyBasedEra era ) => ToCBOR (TxOut ctx era ) where
136
+ toCBOR :: TxOut ctx era -> Encoding
137
+ toCBOR txOut =
138
+ shelleyBasedEraConstraints (shelleyBasedEra @ era ) $
139
+ Ledger. toEraCBOR @ (ShelleyLedgerEra era ) (toShelleyTxOutAny shelleyBasedEra txOut)
140
+
141
+ instance (Typeable ctx , IsShelleyBasedEra era ) => FromCBOR (TxOut ctx era ) where
142
+ fromCBOR :: Ledger. Decoder s (TxOut ctx era )
143
+ fromCBOR =
144
+ shelleyBasedEraConstraints (shelleyBasedEra @ era ) $
145
+ fromShelleyTxOut <$> pure shelleyBasedEra <*> L. fromEraCBOR @ (ShelleyLedgerEra era )
123
146
124
147
deriving instance Eq (TxOut ctx era )
125
148
0 commit comments