module Blockfrost.Types.Shared.TxHash
( TxHash (..)
, TxHashObject (..)
) where
import Data.Aeson (FromJSON (..), ToJSON (..), object, (.=), withObject, (.:))
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."
newtype TxHashObject = TxHashObject { TxHashObject -> Text
unTxHashObject :: Text }
deriving stock (Int -> TxHashObject -> ShowS
[TxHashObject] -> ShowS
TxHashObject -> String
(Int -> TxHashObject -> ShowS)
-> (TxHashObject -> String)
-> ([TxHashObject] -> ShowS)
-> Show TxHashObject
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TxHashObject -> ShowS
showsPrec :: Int -> TxHashObject -> ShowS
$cshow :: TxHashObject -> String
show :: TxHashObject -> String
$cshowList :: [TxHashObject] -> ShowS
showList :: [TxHashObject] -> ShowS
Show, TxHashObject -> TxHashObject -> Bool
(TxHashObject -> TxHashObject -> Bool)
-> (TxHashObject -> TxHashObject -> Bool) -> Eq TxHashObject
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TxHashObject -> TxHashObject -> Bool
== :: TxHashObject -> TxHashObject -> Bool
$c/= :: TxHashObject -> TxHashObject -> Bool
/= :: TxHashObject -> TxHashObject -> Bool
Eq, Eq TxHashObject
Eq TxHashObject =>
(TxHashObject -> TxHashObject -> Ordering)
-> (TxHashObject -> TxHashObject -> Bool)
-> (TxHashObject -> TxHashObject -> Bool)
-> (TxHashObject -> TxHashObject -> Bool)
-> (TxHashObject -> TxHashObject -> Bool)
-> (TxHashObject -> TxHashObject -> TxHashObject)
-> (TxHashObject -> TxHashObject -> TxHashObject)
-> Ord TxHashObject
TxHashObject -> TxHashObject -> Bool
TxHashObject -> TxHashObject -> Ordering
TxHashObject -> TxHashObject -> TxHashObject
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 :: TxHashObject -> TxHashObject -> Ordering
compare :: TxHashObject -> TxHashObject -> Ordering
$c< :: TxHashObject -> TxHashObject -> Bool
< :: TxHashObject -> TxHashObject -> Bool
$c<= :: TxHashObject -> TxHashObject -> Bool
<= :: TxHashObject -> TxHashObject -> Bool
$c> :: TxHashObject -> TxHashObject -> Bool
> :: TxHashObject -> TxHashObject -> Bool
$c>= :: TxHashObject -> TxHashObject -> Bool
>= :: TxHashObject -> TxHashObject -> Bool
$cmax :: TxHashObject -> TxHashObject -> TxHashObject
max :: TxHashObject -> TxHashObject -> TxHashObject
$cmin :: TxHashObject -> TxHashObject -> TxHashObject
min :: TxHashObject -> TxHashObject -> TxHashObject
Ord, (forall x. TxHashObject -> Rep TxHashObject x)
-> (forall x. Rep TxHashObject x -> TxHashObject)
-> Generic TxHashObject
forall x. Rep TxHashObject x -> TxHashObject
forall x. TxHashObject -> Rep TxHashObject x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. TxHashObject -> Rep TxHashObject x
from :: forall x. TxHashObject -> Rep TxHashObject x
$cto :: forall x. Rep TxHashObject x -> TxHashObject
to :: forall x. Rep TxHashObject x -> TxHashObject
Generic)
deriving newtype (Text -> Either Text TxHashObject
ByteString -> Either Text TxHashObject
(Text -> Either Text TxHashObject)
-> (ByteString -> Either Text TxHashObject)
-> (Text -> Either Text TxHashObject)
-> FromHttpApiData TxHashObject
forall a.
(Text -> Either Text a)
-> (ByteString -> Either Text a)
-> (Text -> Either Text a)
-> FromHttpApiData a
$cparseUrlPiece :: Text -> Either Text TxHashObject
parseUrlPiece :: Text -> Either Text TxHashObject
$cparseHeader :: ByteString -> Either Text TxHashObject
parseHeader :: ByteString -> Either Text TxHashObject
$cparseQueryParam :: Text -> Either Text TxHashObject
parseQueryParam :: Text -> Either Text TxHashObject
FromHttpApiData, TxHashObject -> Text
TxHashObject -> ByteString
TxHashObject -> Builder
(TxHashObject -> Text)
-> (TxHashObject -> Builder)
-> (TxHashObject -> ByteString)
-> (TxHashObject -> Text)
-> (TxHashObject -> Builder)
-> ToHttpApiData TxHashObject
forall a.
(a -> Text)
-> (a -> Builder)
-> (a -> ByteString)
-> (a -> Text)
-> (a -> Builder)
-> ToHttpApiData a
$ctoUrlPiece :: TxHashObject -> Text
toUrlPiece :: TxHashObject -> Text
$ctoEncodedUrlPiece :: TxHashObject -> Builder
toEncodedUrlPiece :: TxHashObject -> Builder
$ctoHeader :: TxHashObject -> ByteString
toHeader :: TxHashObject -> ByteString
$ctoQueryParam :: TxHashObject -> Text
toQueryParam :: TxHashObject -> Text
$ctoEncodedQueryParam :: TxHashObject -> Builder
toEncodedQueryParam :: TxHashObject -> Builder
ToHttpApiData)
instance IsString TxHashObject where
fromString :: String -> TxHashObject
fromString = Text -> TxHashObject
TxHashObject (Text -> TxHashObject)
-> (String -> Text) -> String -> TxHashObject
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
Data.Text.pack
instance ToJSON TxHashObject where
toJSON :: TxHashObject -> Value
toJSON TxHashObject
hash = [Pair] -> Value
object [Key
"tx_hash" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TxHashObject -> Text
unTxHashObject TxHashObject
hash]
instance FromJSON TxHashObject where
parseJSON :: Value -> Parser TxHashObject
parseJSON = String
-> (Object -> Parser TxHashObject) -> Value -> Parser TxHashObject
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"TxHashObject" ((Object -> Parser TxHashObject) -> Value -> Parser TxHashObject)
-> (Object -> Parser TxHashObject) -> Value -> Parser TxHashObject
forall a b. (a -> b) -> a -> b
$ \Object
o -> Text -> TxHashObject
TxHashObject (Text -> TxHashObject) -> Parser Text -> Parser TxHashObject
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"tx_hash"