Skip to content

Commit ba1531c

Browse files
qnikstlehins
authored andcommitted
Remove non-canonical types
1 parent d59f858 commit ba1531c

File tree

5 files changed

+13
-130
lines changed

5 files changed

+13
-130
lines changed

libs/cardano-ledger-canonical-state/cardano-ledger-canonical-state.cabal

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ library
3737
exposed-modules:
3838
Cardano.Ledger.CanonicalState.BasicTypes
3939
Cardano.Ledger.CanonicalState.Namespace.Blocks.V0
40-
Cardano.Ledger.CanonicalState.Namespace.Pots.V0
4140
Cardano.Ledger.CanonicalState.Namespace.UTxO.V0
4241

4342
hs-source-dirs: src
@@ -51,7 +50,6 @@ library
5150
scls-cardano,
5251
scls-cbor,
5352
scls-core,
54-
text,
5553

5654
library conway
5755
import: warnings
@@ -80,7 +78,6 @@ library testlib
8078
cardano-ledger-canonical-state:{cardano-ledger-canonical-state, conway},
8179
cardano-ledger-conway:testlib,
8280
cardano-ledger-core,
83-
generic-random,
8481

8582
test-suite tests
8683
import: warnings

libs/cardano-ledger-canonical-state/src/Cardano/Ledger/CanonicalState/BasicTypes.hs

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ module Cardano.Ledger.CanonicalState.BasicTypes (
1414
OnChain (..),
1515
DecodeOnChain (..),
1616
CanonicalCoin (..),
17-
IsCanonicalCoin (..),
1817
) where
1918

20-
import Cardano.Ledger.Coin (Coin (..), CompactForm (..))
19+
import Cardano.Ledger.Coin (Coin (..), CompactForm (CompactCoin))
2120
import Cardano.SCLS.CBOR.Canonical (CanonicalDecoder)
2221
import Cardano.SCLS.CBOR.Canonical.Decoder (FromCanonicalCBOR (..))
2322
import Cardano.SCLS.CBOR.Canonical.Encoder (ToCanonicalCBOR (..))
@@ -60,33 +59,17 @@ instance DecodeOnChain v a => FromCanonicalCBOR v (OnChain a) where
6059
class DecodeOnChain (v :: Symbol) (a :: Type) where
6160
decodeOnChain :: BS.ByteString -> CanonicalDecoder s a
6261

63-
-- | Wrapper for the coin type
64-
newtype CanonicalCoin = CanonicalCoin {unCoin :: Integer}
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}
6569
deriving (Eq, Ord, Show, Generic)
6670

67-
-- | We introduce type class here because Coin can be created from multiple types.
68-
class IsCanonicalCoin a where
69-
mkCanonicalCoin :: a -> CanonicalCoin
70-
fromCanonicalCoin :: CanonicalCoin -> a
71-
72-
instance IsCanonicalCoin CanonicalCoin where
73-
mkCanonicalCoin = id
74-
fromCanonicalCoin = id
75-
76-
instance IsCanonicalCoin Coin where
77-
mkCanonicalCoin Coin {..} = CanonicalCoin {..}
78-
fromCanonicalCoin (CanonicalCoin i) = Coin i
79-
80-
instance IsCanonicalCoin (CompactForm Coin) where
81-
mkCanonicalCoin (CompactCoin ci) = CanonicalCoin (fromIntegral ci)
82-
fromCanonicalCoin (CanonicalCoin ci) = CompactCoin (fromIntegral ci)
83-
84-
instance IsCanonicalCoin Integer where
85-
mkCanonicalCoin = CanonicalCoin
86-
fromCanonicalCoin (CanonicalCoin ci) = ci
71+
instance FromCanonicalCBOR v CanonicalCoin where
72+
fromCanonicalCBOR = fmap (CanonicalCoin . CompactCoin) <$> fromCanonicalCBOR
8773

8874
instance ToCanonicalCBOR v CanonicalCoin where
89-
toCanonicalCBOR v (CanonicalCoin ci) = toCanonicalCBOR v ci
90-
91-
instance FromCanonicalCBOR v CanonicalCoin where
92-
fromCanonicalCBOR = fmap CanonicalCoin <$> fromCanonicalCBOR
75+
toCanonicalCBOR v (CanonicalCoin (CompactCoin c)) = toCanonicalCBOR v c

libs/cardano-ledger-canonical-state/src/Cardano/Ledger/CanonicalState/Namespace/Pots/V0.hs

Lines changed: 0 additions & 88 deletions
This file was deleted.

libs/cardano-ledger-canonical-state/test/Test/Cardano/Ledger/CanonicalState/Spec.hs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ module Test.Cardano.Ledger.CanonicalState.Spec (spec) where
99

1010
import Cardano.Ledger.CanonicalState.Conway ()
1111
import qualified Cardano.Ledger.CanonicalState.Namespace.Blocks.V0 as Blocks.V0
12-
import qualified Cardano.Ledger.CanonicalState.Namespace.Pots.V0 as Pots.V0
1312
import qualified Cardano.Ledger.CanonicalState.Namespace.UTxO.V0 as UTxO.V0
1413
import Cardano.Ledger.Conway (ConwayEra)
1514
import Cardano.SCLS.CBOR.Canonical.Encoder (ToCanonicalCBOR (..))
@@ -25,15 +24,11 @@ spec = do
2524
describe "blocks/v0" $ do
2625
isCanonical @"blocks/v0" @Blocks.V0.BlockOut
2726
validateType @"blocks/v0" @Blocks.V0.BlockOut "record_entry"
28-
describe "pots/v0" $ do
29-
isCanonical @"pots/v0" @Pots.V0.PotsOut
30-
validateType @"pots/v0" @Pots.V0.PotsOut "record_entry"
3127
describe "utxo/v0" $ do
3228
isCanonical @"utxo/v0" @(UTxO.V0.UtxoOut ConwayEra)
3329
validateType @"utxo/v0" @(UTxO.V0.UtxoOut ConwayEra) "record_entry"
3430
describe "namespaces" $ do
3531
testNS @"blocks/v0"
36-
testNS @"pots/v0"
3732
testNS @"utxo/v0"
3833

3934
isCanonical ::

libs/cardano-ledger-canonical-state/testlib/Test/Cardano/Ledger/CanonicalState/Arbitrary.hs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ module Test.Cardano.Ledger.CanonicalState.Arbitrary () where
1010
import Cardano.Ledger.CanonicalState.BasicTypes (CanonicalCoin (..))
1111
import Cardano.Ledger.CanonicalState.Conway ()
1212
import qualified Cardano.Ledger.CanonicalState.Namespace.Blocks.V0 as Blocks.V0
13-
import qualified Cardano.Ledger.CanonicalState.Namespace.Pots.V0 as Pots.V0
1413
import qualified Cardano.Ledger.CanonicalState.Namespace.UTxO.V0 as UtxoOut.V0
14+
import Cardano.Ledger.Coin (CompactForm (CompactCoin))
1515
import Cardano.Ledger.Core (Era, EraTxOut, TxOut)
16-
import Generic.Random (genericArbitraryU)
1716
import Test.Cardano.Ledger.Conway.Arbitrary ()
1817
import Test.QuickCheck (Arbitrary (..), Positive (..))
1918

@@ -26,7 +25,4 @@ instance (EraTxOut era, Arbitrary (TxOut era), Era era) => Arbitrary (UtxoOut.V0
2625
arbitrary = UtxoOut.V0.mkUtxo <$> arbitrary
2726

2827
instance Arbitrary CanonicalCoin where
29-
arbitrary = CanonicalCoin . fromIntegral . getPositive @Integer <$> arbitrary
30-
31-
instance Arbitrary Pots.V0.PotsOut where
32-
arbitrary = genericArbitraryU
28+
arbitrary = CanonicalCoin . CompactCoin <$> arbitrary

0 commit comments

Comments
 (0)