/
Constraints.hs
112 lines (101 loc) · 2.94 KB
/
Constraints.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
module Cardano.Ledger.Shelley.Constraints where
import Cardano.Binary (FromCBOR (..), ToCBOR (..))
import Cardano.Ledger.Compactible (Compactible (..))
import Cardano.Ledger.Core
( AnnotatedData,
AuxiliaryData,
ChainData,
Script,
SerialisableData,
TxBody,
TxOut,
Value,
)
import Cardano.Ledger.Era (Crypto, Era)
import Cardano.Ledger.Torsor (Torsor (..))
import Cardano.Ledger.Val (DecodeMint, DecodeNonNegative, EncodeMint, Val)
import Data.Kind (Constraint, Type)
import Data.Proxy (Proxy)
import GHC.Records (HasField)
import Shelley.Spec.Ledger.Address (Addr)
import Shelley.Spec.Ledger.CompactAddr (CompactAddr)
import Shelley.Spec.Ledger.Hashing
( EraIndependentTxBody,
HashAnnotated (..),
)
--------------------------------------------------------------------------------
-- Shelley Era
--------------------------------------------------------------------------------
type UsesTxBody era =
( Era era,
ChainData (TxBody era),
AnnotatedData (TxBody era),
HashAnnotated (TxBody era) era,
HashIndex (TxBody era) ~ EraIndependentTxBody
)
class
( Era era,
Val (Value era),
Compactible (Value era),
ChainData (Value era),
ChainData (Delta (Value era)),
SerialisableData (Value era),
SerialisableData (Delta (Value era)),
DecodeNonNegative (Value era),
EncodeMint (Value era),
DecodeMint (Value era),
Torsor (Value era)
) =>
UsesValue era
class
( Era era,
ChainData (TxOut era),
ToCBOR (TxOut era),
FromCBOR (TxOut era),
HasField "address" (TxOut era) (Addr (Crypto era)),
HasField "compactAddress" (TxOut era) (CompactAddr (Crypto era)),
HasField "value" (TxOut era) (Value era)
) =>
UsesTxOut era
where
makeTxOut :: Proxy era -> Addr (Crypto era) -> Value era -> TxOut era
type UsesScript era =
( Era era,
Eq (Script era),
Show (Script era),
AnnotatedData (Script era)
)
type UsesAuxiliary era =
( Era era,
Eq (AuxiliaryData era),
Show (AuxiliaryData era),
AnnotatedData (AuxiliaryData era)
)
-- | Apply 'c' to all the types transitively involved with Value when
-- (Core.Value era) is an instance of Compactible and Torsor
type TransValue (c :: Type -> Constraint) era =
( Era era,
Compactible (Value era),
Torsor (Value era),
c (Value era),
c (Delta (Value era))
)
-- | General constraints that will hold true for ledgers which are based on
-- Shelley, and share similar serialisation formats"
type ShelleyBased era =
( -- Value constraints
UsesValue era,
-- TxBody constraints
UsesTxBody era,
-- Script constraints
UsesScript era,
-- AuxiliaryData constraints
UsesAuxiliary era
)
{-# LANGUAGE Deprecated ShelleyBased "Use appropriate 'Uses' constraits (e.g. `UsesValue`) instead." #-}