module Blockfrost.Types.Shared.TxHash
( TxHash (..)
) where
import Data.Aeson (FromJSON (..), ToJSON (..))
import Data.String (IsString (..))
import Data.Text (Text)
import qualified Data.Text
import GHC.Generics
import Servant.API (Capture, FromHttpApiData (..), ToHttpApiData (..))
import Servant.Docs (DocCapture (..), ToCapture (..), ToSample (..), samples)
newtype TxHash = TxHash { TxHash -> Text
unTxHash :: Text }
deriving stock (Int -> TxHash -> ShowS
[TxHash] -> ShowS
TxHash -> String
(Int -> TxHash -> ShowS)
-> (TxHash -> String) -> ([TxHash] -> ShowS) -> Show TxHash
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TxHash -> ShowS
showsPrec :: Int -> TxHash -> ShowS
$cshow :: TxHash -> String
show :: TxHash -> String
$cshowList :: [TxHash] -> ShowS
showList :: [TxHash] -> ShowS
Show, TxHash -> TxHash -> Bool
(TxHash -> TxHash -> Bool)
-> (TxHash -> TxHash -> Bool) -> Eq TxHash
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TxHash -> TxHash -> Bool
== :: TxHash -> TxHash -> Bool
$c/= :: TxHash -> TxHash -> Bool
/= :: TxHash -> TxHash -> Bool
Eq, Eq TxHash
Eq TxHash =>
(TxHash -> TxHash -> Ordering)
-> (TxHash -> TxHash -> Bool)
-> (TxHash -> TxHash -> Bool)
-> (TxHash -> TxHash -> Bool)
-> (TxHash -> TxHash -> Bool)
-> (TxHash -> TxHash -> TxHash)
-> (TxHash -> TxHash -> TxHash)
-> Ord TxHash
TxHash -> TxHash -> Bool
TxHash -> TxHash -> Ordering
TxHash -> TxHash -> TxHash
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 :: TxHash -> TxHash -> Ordering
compare :: TxHash -> TxHash -> Ordering
$c< :: TxHash -> TxHash -> Bool
< :: TxHash -> TxHash -> Bool
$c<= :: TxHash -> TxHash -> Bool
<= :: TxHash -> TxHash -> Bool
$c> :: TxHash -> TxHash -> Bool
> :: TxHash -> TxHash -> Bool
$c>= :: TxHash -> TxHash -> Bool
>= :: TxHash -> TxHash -> Bool
$cmax :: TxHash -> TxHash -> TxHash
max :: TxHash -> TxHash -> TxHash
$cmin :: TxHash -> TxHash -> TxHash
min :: TxHash -> TxHash -> TxHash
Ord, (forall x. TxHash -> Rep TxHash x)
-> (forall x. Rep TxHash x -> TxHash) -> Generic TxHash
forall x. Rep TxHash x -> TxHash
forall x. TxHash -> Rep TxHash x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. TxHash -> Rep TxHash x
from :: forall x. TxHash -> Rep TxHash x
$cto :: forall x. Rep TxHash x -> TxHash
to :: forall x. Rep TxHash x -> TxHash
Generic)
deriving newtype (Text -> Either Text TxHash
ByteString -> Either Text TxHash
(Text -> Either Text TxHash)
-> (ByteString -> Either Text TxHash)
-> (Text -> Either Text TxHash)
-> FromHttpApiData TxHash
forall a.
(Text -> Either Text a)
-> (ByteString -> Either Text a)
-> (Text -> Either Text a)
-> FromHttpApiData a
$cparseUrlPiece :: Text -> Either Text TxHash
parseUrlPiece :: Text -> Either Text TxHash
$cparseHeader :: ByteString -> Either Text TxHash
parseHeader :: ByteString -> Either Text TxHash
$cparseQueryParam :: Text -> Either Text TxHash
parseQueryParam :: Text -> Either Text TxHash
FromHttpApiData, TxHash -> Text
TxHash -> ByteString
TxHash -> Builder
(TxHash -> Text)
-> (TxHash -> Builder)
-> (TxHash -> ByteString)
-> (TxHash -> Text)
-> (TxHash -> Builder)
-> ToHttpApiData TxHash
forall a.
(a -> Text)
-> (a -> Builder)
-> (a -> ByteString)
-> (a -> Text)
-> (a -> Builder)
-> ToHttpApiData a
$ctoUrlPiece :: TxHash -> Text
toUrlPiece :: TxHash -> Text
$ctoEncodedUrlPiece :: TxHash -> Builder
toEncodedUrlPiece :: TxHash -> Builder
$ctoHeader :: TxHash -> ByteString
toHeader :: TxHash -> ByteString
$ctoQueryParam :: TxHash -> Text
toQueryParam :: TxHash -> Text
$ctoEncodedQueryParam :: TxHash -> Builder
toEncodedQueryParam :: TxHash -> Builder
ToHttpApiData)
instance IsString TxHash where
fromString :: String -> TxHash
fromString = Text -> TxHash
TxHash (Text -> TxHash) -> (String -> Text) -> String -> TxHash
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
Data.Text.pack
instance ToJSON TxHash where
toJSON :: TxHash -> Value
toJSON = Text -> Value
forall a. ToJSON a => a -> Value
toJSON (Text -> Value) -> (TxHash -> Text) -> TxHash -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TxHash -> Text
unTxHash
toEncoding :: TxHash -> Encoding
toEncoding = Text -> Encoding
forall a. ToJSON a => a -> Encoding
toEncoding (Text -> Encoding) -> (TxHash -> Text) -> TxHash -> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TxHash -> Text
unTxHash
instance FromJSON TxHash where
parseJSON :: Value -> Parser TxHash
parseJSON = (Text -> TxHash) -> Parser Text -> Parser TxHash
forall a b. (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> TxHash
TxHash (Parser Text -> Parser TxHash)
-> (Value -> Parser Text) -> Value -> Parser TxHash
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser Text
forall a. FromJSON a => Value -> Parser a
parseJSON
instance ToSample TxHash where
toSamples :: Proxy TxHash -> [(Text, TxHash)]
toSamples Proxy TxHash
_ = [TxHash] -> [(Text, TxHash)]
forall a. [a] -> [(Text, a)]
samples ([TxHash] -> [(Text, TxHash)]) -> [TxHash] -> [(Text, TxHash)]
forall a b. (a -> b) -> a -> b
$ (Text -> TxHash) -> [Text] -> [TxHash]
forall a b. (a -> b) -> [a] -> [b]
map Text -> TxHash
TxHash
[ Text
"8788591983aa73981fc92d6cddbbe643959f5a784e84b8bee0db15823f575a5b"
, Text
"52e748c4dec58b687b90b0b40d383b9fe1f24c1a833b7395cdf07dd67859f46f"
, Text
"e8073fd5318ff43eca18a852527166aa8008bee9ee9e891f585612b7e4ba700b"
]
instance ToCapture (Capture "hash" TxHash) where
toCapture :: Proxy (Capture "hash" TxHash) -> DocCapture
toCapture Proxy (Capture "hash" TxHash)
_ = String -> String -> DocCapture
DocCapture String
"hash" String
"Hash of the requested transaction."