-- | Address newtype

module Blockfrost.Types.Shared.Address
  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 Address = Address Text
  deriving stock (Address -> Address -> Bool
(Address -> Address -> Bool)
-> (Address -> Address -> Bool) -> Eq Address
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Address -> Address -> Bool
== :: Address -> Address -> Bool
$c/= :: Address -> Address -> Bool
/= :: Address -> Address -> Bool
Eq, Eq Address
Eq Address =>
(Address -> Address -> Ordering)
-> (Address -> Address -> Bool)
-> (Address -> Address -> Bool)
-> (Address -> Address -> Bool)
-> (Address -> Address -> Bool)
-> (Address -> Address -> Address)
-> (Address -> Address -> Address)
-> Ord Address
Address -> Address -> Bool
Address -> Address -> Ordering
Address -> Address -> Address
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 :: Address -> Address -> Ordering
compare :: Address -> Address -> Ordering
$c< :: Address -> Address -> Bool
< :: Address -> Address -> Bool
$c<= :: Address -> Address -> Bool
<= :: Address -> Address -> Bool
$c> :: Address -> Address -> Bool
> :: Address -> Address -> Bool
$c>= :: Address -> Address -> Bool
>= :: Address -> Address -> Bool
$cmax :: Address -> Address -> Address
max :: Address -> Address -> Address
$cmin :: Address -> Address -> Address
min :: Address -> Address -> Address
Ord, Int -> Address -> ShowS
[Address] -> ShowS
Address -> String
(Int -> Address -> ShowS)
-> (Address -> String) -> ([Address] -> ShowS) -> Show Address
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Address -> ShowS
showsPrec :: Int -> Address -> ShowS
$cshow :: Address -> String
show :: Address -> String
$cshowList :: [Address] -> ShowS
showList :: [Address] -> ShowS
Show, (forall x. Address -> Rep Address x)
-> (forall x. Rep Address x -> Address) -> Generic Address
forall x. Rep Address x -> Address
forall x. Address -> Rep Address x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Address -> Rep Address x
from :: forall x. Address -> Rep Address x
$cto :: forall x. Rep Address x -> Address
to :: forall x. Rep Address x -> Address
Generic)
  deriving newtype (Text -> Either Text Address
ByteString -> Either Text Address
(Text -> Either Text Address)
-> (ByteString -> Either Text Address)
-> (Text -> Either Text Address)
-> FromHttpApiData Address
forall a.
(Text -> Either Text a)
-> (ByteString -> Either Text a)
-> (Text -> Either Text a)
-> FromHttpApiData a
$cparseUrlPiece :: Text -> Either Text Address
parseUrlPiece :: Text -> Either Text Address
$cparseHeader :: ByteString -> Either Text Address
parseHeader :: ByteString -> Either Text Address
$cparseQueryParam :: Text -> Either Text Address
parseQueryParam :: Text -> Either Text Address
FromHttpApiData, Address -> Text
Address -> ByteString
Address -> Builder
(Address -> Text)
-> (Address -> Builder)
-> (Address -> ByteString)
-> (Address -> Text)
-> (Address -> Builder)
-> ToHttpApiData Address
forall a.
(a -> Text)
-> (a -> Builder)
-> (a -> ByteString)
-> (a -> Text)
-> (a -> Builder)
-> ToHttpApiData a
$ctoUrlPiece :: Address -> Text
toUrlPiece :: Address -> Text
$ctoEncodedUrlPiece :: Address -> Builder
toEncodedUrlPiece :: Address -> Builder
$ctoHeader :: Address -> ByteString
toHeader :: Address -> ByteString
$ctoQueryParam :: Address -> Text
toQueryParam :: Address -> Text
$ctoEncodedQueryParam :: Address -> Builder
toEncodedQueryParam :: Address -> Builder
ToHttpApiData, Maybe Address
Value -> Parser [Address]
Value -> Parser Address
(Value -> Parser Address)
-> (Value -> Parser [Address]) -> Maybe Address -> FromJSON Address
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser Address
parseJSON :: Value -> Parser Address
$cparseJSONList :: Value -> Parser [Address]
parseJSONList :: Value -> Parser [Address]
$comittedField :: Maybe Address
omittedField :: Maybe Address
FromJSON, [Address] -> Value
[Address] -> Encoding
Address -> Bool
Address -> Value
Address -> Encoding
(Address -> Value)
-> (Address -> Encoding)
-> ([Address] -> Value)
-> ([Address] -> Encoding)
-> (Address -> Bool)
-> ToJSON Address
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: Address -> Value
toJSON :: Address -> Value
$ctoEncoding :: Address -> Encoding
toEncoding :: Address -> Encoding
$ctoJSONList :: [Address] -> Value
toJSONList :: [Address] -> Value
$ctoEncodingList :: [Address] -> Encoding
toEncodingList :: [Address] -> Encoding
$comitField :: Address -> Bool
omitField :: Address -> Bool
ToJSON)

mkAddress :: Text -> Address
mkAddress :: Text -> Address
mkAddress = Text -> Address
Address

unAddress :: Address -> Text
unAddress :: Address -> Text
unAddress (Address Text
a) = Text
a

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

instance ToCapture (Capture "address" Address) where
  toCapture :: Proxy (Capture "address" Address) -> DocCapture
toCapture Proxy (Capture "address" Address)
_ = String -> String -> DocCapture
DocCapture String
"address" String
"Bech32 encoded address"

instance ToCapture (Capture "stake_address" Address) where
  toCapture :: Proxy (Capture "stake_address" Address) -> DocCapture
toCapture Proxy (Capture "stake_address" Address)
_ = String -> String -> DocCapture
DocCapture String
"stake_address" String
"Bech32 stake address"

instance ToSample Address where
    toSamples :: Proxy Address -> [(Text, Address)]
toSamples = [(Text, Address)] -> Proxy Address -> [(Text, Address)]
forall a. a -> Proxy Address -> a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([(Text, Address)] -> Proxy Address -> [(Text, Address)])
-> [(Text, Address)] -> Proxy Address -> [(Text, Address)]
forall a b. (a -> b) -> a -> b
$ [Address] -> [(Text, Address)]
forall a. [a] -> [(Text, a)]
samples [
        Address
"addr1qxqs59lphg8g6qndelq8xwqn60ag3aeyfcp33c2kdp46a09re5df3pzwwmyq946axfcejy5n4x0y99wqpgtp2gd0k09qsgy6pz"
      , Address
"stake1ux3g2c9dx2nhhehyrezyxpkstartcqmu9hk63qgfkccw5rqttygt7"
      ]