-- | Transaction Id

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)

-- | Id (hash) of the transaction
newtype TxHash = TxHash { TxHash -> Text
unTxHash :: Text }
  deriving stock (Int -> TxHash -> ShowS
[TxHash] -> ShowS
TxHash -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TxHash] -> ShowS
$cshowList :: [TxHash] -> ShowS
show :: TxHash -> String
$cshow :: TxHash -> String
showsPrec :: Int -> TxHash -> ShowS
$cshowsPrec :: Int -> TxHash -> ShowS
Show, TxHash -> TxHash -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TxHash -> TxHash -> Bool
$c/= :: TxHash -> TxHash -> Bool
== :: TxHash -> TxHash -> Bool
$c== :: TxHash -> TxHash -> Bool
Eq, Eq 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
min :: TxHash -> TxHash -> TxHash
$cmin :: TxHash -> TxHash -> TxHash
max :: TxHash -> TxHash -> TxHash
$cmax :: TxHash -> TxHash -> TxHash
>= :: TxHash -> TxHash -> Bool
$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
compare :: TxHash -> TxHash -> Ordering
$ccompare :: TxHash -> TxHash -> Ordering
Ord, 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
$cto :: forall x. Rep TxHash x -> TxHash
$cfrom :: forall x. TxHash -> Rep TxHash x
Generic)
  deriving newtype (ByteString -> Either Text TxHash
Text -> Either Text TxHash
forall a.
(Text -> Either Text a)
-> (ByteString -> Either Text a)
-> (Text -> Either Text a)
-> FromHttpApiData a
parseQueryParam :: Text -> Either Text TxHash
$cparseQueryParam :: Text -> Either Text TxHash
parseHeader :: ByteString -> Either Text TxHash
$cparseHeader :: ByteString -> Either Text TxHash
parseUrlPiece :: Text -> Either Text TxHash
$cparseUrlPiece :: Text -> Either Text TxHash
FromHttpApiData, TxHash -> Builder
TxHash -> ByteString
TxHash -> Text
forall a.
(a -> Text)
-> (a -> Builder)
-> (a -> ByteString)
-> (a -> Text)
-> (a -> Builder)
-> ToHttpApiData a
toEncodedQueryParam :: TxHash -> Builder
$ctoEncodedQueryParam :: TxHash -> Builder
toQueryParam :: TxHash -> Text
$ctoQueryParam :: TxHash -> Text
toHeader :: TxHash -> ByteString
$ctoHeader :: TxHash -> ByteString
toEncodedUrlPiece :: TxHash -> Builder
$ctoEncodedUrlPiece :: TxHash -> Builder
toUrlPiece :: TxHash -> Text
$ctoUrlPiece :: TxHash -> Text
ToHttpApiData)

instance IsString TxHash where
  fromString :: String -> TxHash
fromString = Text -> TxHash
TxHash forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
Data.Text.pack

instance ToJSON TxHash where
  toJSON :: TxHash -> Value
toJSON = forall a. ToJSON a => a -> Value
toJSON forall b c a. (b -> c) -> (a -> b) -> a -> c
. TxHash -> Text
unTxHash
  toEncoding :: TxHash -> Encoding
toEncoding = forall a. ToJSON a => a -> Encoding
toEncoding forall b c a. (b -> c) -> (a -> b) -> a -> c
. TxHash -> Text
unTxHash
instance FromJSON TxHash where
  parseJSON :: Value -> Parser TxHash
parseJSON = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> TxHash
TxHash forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromJSON a => Value -> Parser a
parseJSON

instance ToSample TxHash where
    toSamples :: Proxy TxHash -> [(Text, TxHash)]
toSamples Proxy TxHash
_ = forall a. [a] -> [(Text, a)]
samples forall a b. (a -> b) -> a -> b
$ 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."