module Cometa.Transaction.Datum (Datum (..), Hash32, hashFromBytes, hashBytes) where
import Cometa.Error (Error (..))
import Cometa.PlutusData (EncodedPlutusData)
import Data.ByteString (ByteString)
import qualified Data.ByteString as B
newtype Hash32 = Hash32 ByteString deriving (Hash32 -> Hash32 -> Bool
(Hash32 -> Hash32 -> Bool)
-> (Hash32 -> Hash32 -> Bool) -> Eq Hash32
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Hash32 -> Hash32 -> Bool
== :: Hash32 -> Hash32 -> Bool
$c/= :: Hash32 -> Hash32 -> Bool
/= :: Hash32 -> Hash32 -> Bool
Eq, Eq Hash32
Eq Hash32 =>
(Hash32 -> Hash32 -> Ordering)
-> (Hash32 -> Hash32 -> Bool)
-> (Hash32 -> Hash32 -> Bool)
-> (Hash32 -> Hash32 -> Bool)
-> (Hash32 -> Hash32 -> Bool)
-> (Hash32 -> Hash32 -> Hash32)
-> (Hash32 -> Hash32 -> Hash32)
-> Ord Hash32
Hash32 -> Hash32 -> Bool
Hash32 -> Hash32 -> Ordering
Hash32 -> Hash32 -> Hash32
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Hash32 -> Hash32 -> Ordering
compare :: Hash32 -> Hash32 -> Ordering
$c< :: Hash32 -> Hash32 -> Bool
< :: Hash32 -> Hash32 -> Bool
$c<= :: Hash32 -> Hash32 -> Bool
<= :: Hash32 -> Hash32 -> Bool
$c> :: Hash32 -> Hash32 -> Bool
> :: Hash32 -> Hash32 -> Bool
$c>= :: Hash32 -> Hash32 -> Bool
>= :: Hash32 -> Hash32 -> Bool
$cmax :: Hash32 -> Hash32 -> Hash32
max :: Hash32 -> Hash32 -> Hash32
$cmin :: Hash32 -> Hash32 -> Hash32
min :: Hash32 -> Hash32 -> Hash32
Ord, Int -> Hash32 -> ShowS
[Hash32] -> ShowS
Hash32 -> String
(Int -> Hash32 -> ShowS)
-> (Hash32 -> String) -> ([Hash32] -> ShowS) -> Show Hash32
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Hash32 -> ShowS
showsPrec :: Int -> Hash32 -> ShowS
$cshow :: Hash32 -> String
show :: Hash32 -> String
$cshowList :: [Hash32] -> ShowS
showList :: [Hash32] -> ShowS
Show)
data Datum
=
NoDatum
|
DatumHash !Hash32
|
InlineDatum !EncodedPlutusData
deriving (Datum -> Datum -> Bool
(Datum -> Datum -> Bool) -> (Datum -> Datum -> Bool) -> Eq Datum
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Datum -> Datum -> Bool
== :: Datum -> Datum -> Bool
$c/= :: Datum -> Datum -> Bool
/= :: Datum -> Datum -> Bool
Eq, Eq Datum
Eq Datum =>
(Datum -> Datum -> Ordering)
-> (Datum -> Datum -> Bool)
-> (Datum -> Datum -> Bool)
-> (Datum -> Datum -> Bool)
-> (Datum -> Datum -> Bool)
-> (Datum -> Datum -> Datum)
-> (Datum -> Datum -> Datum)
-> Ord Datum
Datum -> Datum -> Bool
Datum -> Datum -> Ordering
Datum -> Datum -> Datum
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Datum -> Datum -> Ordering
compare :: Datum -> Datum -> Ordering
$c< :: Datum -> Datum -> Bool
< :: Datum -> Datum -> Bool
$c<= :: Datum -> Datum -> Bool
<= :: Datum -> Datum -> Bool
$c> :: Datum -> Datum -> Bool
> :: Datum -> Datum -> Bool
$c>= :: Datum -> Datum -> Bool
>= :: Datum -> Datum -> Bool
$cmax :: Datum -> Datum -> Datum
max :: Datum -> Datum -> Datum
$cmin :: Datum -> Datum -> Datum
min :: Datum -> Datum -> Datum
Ord, Int -> Datum -> ShowS
[Datum] -> ShowS
Datum -> String
(Int -> Datum -> ShowS)
-> (Datum -> String) -> ([Datum] -> ShowS) -> Show Datum
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Datum -> ShowS
showsPrec :: Int -> Datum -> ShowS
$cshow :: Datum -> String
show :: Datum -> String
$cshowList :: [Datum] -> ShowS
showList :: [Datum] -> ShowS
Show)
hashFromBytes :: ByteString -> Either Error Hash32
hashFromBytes :: ByteString -> Either Error Hash32
hashFromBytes ByteString
bytes
| ByteString -> Int
B.length ByteString
bytes Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
32 = Hash32 -> Either Error Hash32
forall a b. b -> Either a b
Right (ByteString -> Hash32
Hash32 ByteString
bytes)
| Bool
otherwise = Error -> Either Error Hash32
forall a b. a -> Either a b
Left (Int -> Error
InvalidTransactionHashLength (ByteString -> Int
B.length ByteString
bytes))
hashBytes :: Hash32 -> ByteString
hashBytes :: Hash32 -> ByteString
hashBytes (Hash32 ByteString
bytes) = ByteString
bytes