|
6 | 6 | {-# LANGUAGE GeneralizedNewtypeDeriving #-} |
7 | 7 | {-# LANGUAGE KindSignatures #-} |
8 | 8 | {-# LANGUAGE MultiParamTypeClasses #-} |
| 9 | +{-# LANGUAGE RecordWildCards #-} |
9 | 10 | {-# LANGUAGE ScopedTypeVariables #-} |
10 | 11 | {-# LANGUAGE TypeApplications #-} |
11 | 12 |
|
12 | 13 | module Cardano.Ledger.CanonicalState.BasicTypes ( |
13 | 14 | OnChain (..), |
14 | 15 | DecodeOnChain (..), |
| 16 | + CanonicalCoin (..), |
15 | 17 | ) where |
16 | 18 |
|
| 19 | +import Cardano.Ledger.Coin (Coin (..), CompactForm (CompactCoin)) |
17 | 20 | import Cardano.SCLS.CBOR.Canonical (CanonicalDecoder) |
18 | 21 | import Cardano.SCLS.CBOR.Canonical.Decoder (FromCanonicalCBOR (..)) |
19 | 22 | import Cardano.SCLS.CBOR.Canonical.Encoder (ToCanonicalCBOR (..)) |
@@ -55,3 +58,18 @@ instance DecodeOnChain v a => FromCanonicalCBOR v (OnChain a) where |
55 | 58 | -- `toPlainDecoder`. |
56 | 59 | class DecodeOnChain (v :: Symbol) (a :: Type) where |
57 | 60 | decodeOnChain :: BS.ByteString -> CanonicalDecoder s a |
| 61 | + |
| 62 | +-- | Wrapper for the coin type. |
| 63 | +-- |
| 64 | +-- Despite the fact that Coin is on-chain type, we do not want to use |
| 65 | +-- 'OnChain' wrapper for it. Because it's expected that if we keep chain |
| 66 | +-- structure like transaction in canonical state, then we should keep entire |
| 67 | +-- structure there and keep that as a whole, like 'UTxOut'. |
| 68 | +newtype CanonicalCoin = CanonicalCoin {unCoin :: CompactForm Coin} |
| 69 | + deriving (Eq, Ord, Show, Generic) |
| 70 | + |
| 71 | +instance FromCanonicalCBOR v CanonicalCoin where |
| 72 | + fromCanonicalCBOR = fmap (CanonicalCoin . CompactCoin) <$> fromCanonicalCBOR |
| 73 | + |
| 74 | +instance ToCanonicalCBOR v CanonicalCoin where |
| 75 | + toCanonicalCBOR v (CanonicalCoin (CompactCoin c)) = toCanonicalCBOR v c |
0 commit comments