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