module Michelson.Typed.CValue
( CVal (..)
, ToCVal
, FromCVal
, toCVal
, fromCVal
) where
import Michelson.Typed.T (CT(..), ToCT)
import Tezos.Address (Address)
import Tezos.Core (Mutez, Timestamp)
import Tezos.Crypto (KeyHash)
data CVal t where
CvInt :: Integer -> CVal 'CInt
CvNat :: Natural -> CVal 'CNat
CvString :: Text -> CVal 'CString
CvBytes :: ByteString -> CVal 'CBytes
CvMutez :: Mutez -> CVal 'CMutez
CvBool :: Bool -> CVal 'CBool
CvKeyHash :: KeyHash -> CVal 'CKeyHash
CvTimestamp :: Timestamp -> CVal 'CTimestamp
CvAddress :: Address -> CVal 'CAddress
deriving instance Show (CVal t)
deriving instance Eq (CVal t)
deriving instance Ord (CVal t)
class ToCVal a where
toCVal :: a -> CVal (ToCT a)
class FromCVal t where
fromCVal :: CVal (ToCT t) -> t
instance FromCVal Integer where
fromCVal (CvInt i) = i
instance FromCVal Natural where
fromCVal (CvNat i) = i
instance FromCVal Text where
fromCVal (CvString s) = s
instance FromCVal Bool where
fromCVal (CvBool b) = b
instance FromCVal ByteString where
fromCVal (CvBytes b) = b
instance FromCVal Mutez where
fromCVal (CvMutez m) = m
instance FromCVal KeyHash where
fromCVal (CvKeyHash k) = k
instance FromCVal Timestamp where
fromCVal (CvTimestamp t) = t
instance FromCVal Address where
fromCVal (CvAddress a) = a
instance ToCVal Integer where
toCVal = CvInt
instance ToCVal Int where
toCVal = CvInt . fromIntegral
instance ToCVal Word64 where
toCVal = CvNat . fromIntegral
instance ToCVal Natural where
toCVal = CvNat
instance ToCVal Text where
toCVal = CvString
instance ToCVal ByteString where
toCVal = CvBytes
instance ToCVal Bool where
toCVal = CvBool
instance ToCVal Mutez where
toCVal = CvMutez
instance ToCVal KeyHash where
toCVal = CvKeyHash
instance ToCVal Timestamp where
toCVal = CvTimestamp
instance ToCVal Address where
toCVal = CvAddress