|
3 | 3 | {-# LANGUAGE FlexibleContexts #-} |
4 | 4 | {-# LANGUAGE FlexibleInstances #-} |
5 | 5 | {-# LANGUAGE GADTs #-} |
| 6 | +{-# LANGUAGE InstanceSigs #-} |
6 | 7 | {-# LANGUAGE LambdaCase #-} |
7 | 8 | {-# LANGUAGE QuantifiedConstraints #-} |
8 | 9 | {-# LANGUAGE ScopedTypeVariables #-} |
9 | 10 | {-# LANGUAGE StandaloneDeriving #-} |
10 | 11 | {-# LANGUAGE TupleSections #-} |
11 | 12 | {-# LANGUAGE TypeApplications #-} |
| 13 | +{-# LANGUAGE TypeFamilies #-} |
12 | 14 | {-# LANGUAGE TypeOperators #-} |
13 | 15 | {-# LANGUAGE UndecidableInstances #-} |
14 | 16 | -- The Shelley ledger uses promoted data kinds which we have to use, but we do |
@@ -71,16 +73,23 @@ import Cardano.Api.Internal.Eon.ShelleyBasedEra |
71 | 73 | import Cardano.Api.Internal.Eras.Case |
72 | 74 | import Cardano.Api.Internal.Eras.Core |
73 | 75 | import Cardano.Api.Internal.GenesisParameters |
| 76 | +import Cardano.Api.Internal.HasTypeProxy (HasTypeProxy (..), Proxy) |
74 | 77 | import Cardano.Api.Internal.IPC.Version |
75 | 78 | import Cardano.Api.Internal.Keys.Shelley |
76 | 79 | import Cardano.Api.Internal.Modes |
77 | 80 | import Cardano.Api.Internal.NetworkId |
78 | 81 | import Cardano.Api.Internal.ProtocolParameters |
79 | 82 | import Cardano.Api.Internal.Query.Types |
80 | 83 | import Cardano.Api.Internal.ReexposeLedger qualified as Ledger |
| 84 | +import Cardano.Api.Internal.SerialiseCBOR (SerialiseAsCBOR (deserialiseFromCBOR, serialiseToCBOR)) |
| 85 | +import Cardano.Api.Internal.SerialiseTextEnvelope |
| 86 | + ( HasTextEnvelope (textEnvelopeType) |
| 87 | + , TextEnvelopeType |
| 88 | + ) |
81 | 89 | import Cardano.Api.Internal.Tx.Body |
82 | 90 | import Cardano.Api.Internal.Tx.UTxO (UTxO (..)) |
83 | 91 |
|
| 92 | +import Cardano.Binary qualified as CBOR |
84 | 93 | import Cardano.Chain.Update.Validation.Interface qualified as Byron.Update |
85 | 94 | import Cardano.Ledger.Api qualified as L |
86 | 95 | import Cardano.Ledger.Api.State.Query qualified as L |
@@ -116,13 +125,16 @@ import Ouroboros.Network.NodeToClient.Version (NodeToClientVersion (..)) |
116 | 125 | import Ouroboros.Network.PeerSelection.LedgerPeers.Type (LedgerPeerSnapshot) |
117 | 126 | import Ouroboros.Network.Protocol.LocalStateQuery.Client (Some (..)) |
118 | 127 |
|
| 128 | +import Codec.Serialise qualified as CBOR |
119 | 129 | import Control.Monad.Trans.Except |
120 | 130 | import Data.Bifunctor (bimap, first) |
| 131 | +import Data.ByteString qualified as BS |
121 | 132 | import Data.ByteString.Lazy qualified as LBS |
122 | 133 | import Data.Either.Combinators (rightToMaybe) |
123 | 134 | import Data.Map.Strict (Map) |
124 | 135 | import Data.Map.Strict qualified as Map |
125 | 136 | import Data.Maybe (mapMaybe) |
| 137 | +import Data.Reflection (give) |
126 | 138 | import Data.SOP.Constraint (SListI) |
127 | 139 | import Data.Sequence (Seq) |
128 | 140 | import Data.Set (Set) |
@@ -167,6 +179,28 @@ data EraHistory where |
167 | 179 | => History.Interpreter xs |
168 | 180 | -> EraHistory |
169 | 181 |
|
| 182 | +instance HasTypeProxy EraHistory where |
| 183 | + data AsType EraHistory = AsEraHistory |
| 184 | + |
| 185 | + proxyToAsType :: Proxy EraHistory -> AsType EraHistory |
| 186 | + proxyToAsType _ = AsEraHistory |
| 187 | + |
| 188 | +instance SerialiseAsCBOR EraHistory where |
| 189 | + serialiseToCBOR :: EraHistory -> BS.ByteString |
| 190 | + serialiseToCBOR (EraHistory interpreter) = CBOR.toStrictByteString (give History.EraParamsWithGenesisWindow (CBOR.encode interpreter)) |
| 191 | + |
| 192 | + deserialiseFromCBOR :: AsType EraHistory -> BS.ByteString -> Either DecoderError EraHistory |
| 193 | + deserialiseFromCBOR _ bs = |
| 194 | + EraHistory |
| 195 | + <$> CBOR.decodeFullDecoder' "EraHistory" (give History.EraParamsWithGenesisWindow CBOR.decode) bs |
| 196 | + |
| 197 | +-- | The @HasTextEnvelope@ instance for @EraHistory@ is required by the |
| 198 | +-- @transaction calculate-plutus-script-cost@ command in @cartdano-cli and it |
| 199 | +-- can be obtained through the @query era-history@ command. |
| 200 | +instance HasTextEnvelope EraHistory where |
| 201 | + textEnvelopeType :: AsType EraHistory -> TextEnvelopeType |
| 202 | + textEnvelopeType _ = "EraHistory" |
| 203 | + |
170 | 204 | getProgress |
171 | 205 | :: () |
172 | 206 | => SlotNo |
|
0 commit comments