-- | Address queries

module Blockfrost.Client.Cardano.Addresses
  ( getAddressInfo
  , getAddressDetails
  , getAddressUtxos
  , getAddressUtxos'
  , getAddressUtxosAsset
  , getAddressUtxosAsset'
  , getAddressTransactions
  , getAddressTransactions'
  ) where

import Blockfrost.API
import Blockfrost.Client.Types
import Blockfrost.Types

addressesClient :: Project -> AddressesAPI (AsClientT BlockfrostClient)
addressesClient :: Project -> AddressesAPI (AsClientT BlockfrostClient)
addressesClient = (((Address
   -> ExceptT BlockfrostError (ReaderT ClientConfig IO) AddressInfo)
  :<|> (Address
        -> ExceptT
             BlockfrostError (ReaderT ClientConfig IO) AddressDetails))
 :<|> ((Address
        -> Paged
        -> SortOrder
        -> ExceptT BlockfrostError (ReaderT ClientConfig IO) [AddressUtxo])
       :<|> ((Address
              -> AssetId
              -> Paged
              -> SortOrder
              -> ExceptT BlockfrostError (ReaderT ClientConfig IO) [AddressUtxo])
             :<|> (Address
                   -> Paged
                   -> SortOrder
                   -> Maybe BlockIndex
                   -> Maybe BlockIndex
                   -> ExceptT
                        BlockfrostError (ReaderT ClientConfig IO) [AddressTransaction]))))
-> AddressesAPI (AsClientT BlockfrostClient)
forall (routes :: * -> *) mode.
GenericServant routes mode =>
ToServant routes mode -> routes mode
fromServant ((((Address
    -> ExceptT BlockfrostError (ReaderT ClientConfig IO) AddressInfo)
   :<|> (Address
         -> ExceptT
              BlockfrostError (ReaderT ClientConfig IO) AddressDetails))
  :<|> ((Address
         -> Paged
         -> SortOrder
         -> ExceptT BlockfrostError (ReaderT ClientConfig IO) [AddressUtxo])
        :<|> ((Address
               -> AssetId
               -> Paged
               -> SortOrder
               -> ExceptT BlockfrostError (ReaderT ClientConfig IO) [AddressUtxo])
              :<|> (Address
                    -> Paged
                    -> SortOrder
                    -> Maybe BlockIndex
                    -> Maybe BlockIndex
                    -> ExceptT
                         BlockfrostError (ReaderT ClientConfig IO) [AddressTransaction]))))
 -> AddressesAPI (AsClientT BlockfrostClient))
-> (Project
    -> ((Address
         -> ExceptT BlockfrostError (ReaderT ClientConfig IO) AddressInfo)
        :<|> (Address
              -> ExceptT
                   BlockfrostError (ReaderT ClientConfig IO) AddressDetails))
       :<|> ((Address
              -> Paged
              -> SortOrder
              -> ExceptT BlockfrostError (ReaderT ClientConfig IO) [AddressUtxo])
             :<|> ((Address
                    -> AssetId
                    -> Paged
                    -> SortOrder
                    -> ExceptT BlockfrostError (ReaderT ClientConfig IO) [AddressUtxo])
                   :<|> (Address
                         -> Paged
                         -> SortOrder
                         -> Maybe BlockIndex
                         -> Maybe BlockIndex
                         -> ExceptT
                              BlockfrostError (ReaderT ClientConfig IO) [AddressTransaction]))))
-> Project
-> AddressesAPI (AsClientT BlockfrostClient)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CardanoAPI (AsClientT BlockfrostClient)
-> ((Address
     -> ExceptT BlockfrostError (ReaderT ClientConfig IO) AddressInfo)
    :<|> (Address
          -> ExceptT
               BlockfrostError (ReaderT ClientConfig IO) AddressDetails))
   :<|> ((Address
          -> Paged
          -> SortOrder
          -> ExceptT BlockfrostError (ReaderT ClientConfig IO) [AddressUtxo])
         :<|> ((Address
                -> AssetId
                -> Paged
                -> SortOrder
                -> ExceptT BlockfrostError (ReaderT ClientConfig IO) [AddressUtxo])
               :<|> (Address
                     -> Paged
                     -> SortOrder
                     -> Maybe BlockIndex
                     -> Maybe BlockIndex
                     -> ExceptT
                          BlockfrostError (ReaderT ClientConfig IO) [AddressTransaction])))
forall route.
CardanoAPI route
-> route
   :- ("addresses"
       :> (Tag "Cardano \187 Addresses" :> ToServantApi AddressesAPI))
_addresses (CardanoAPI (AsClientT BlockfrostClient)
 -> ((Address
      -> ExceptT BlockfrostError (ReaderT ClientConfig IO) AddressInfo)
     :<|> (Address
           -> ExceptT
                BlockfrostError (ReaderT ClientConfig IO) AddressDetails))
    :<|> ((Address
           -> Paged
           -> SortOrder
           -> ExceptT BlockfrostError (ReaderT ClientConfig IO) [AddressUtxo])
          :<|> ((Address
                 -> AssetId
                 -> Paged
                 -> SortOrder
                 -> ExceptT BlockfrostError (ReaderT ClientConfig IO) [AddressUtxo])
                :<|> (Address
                      -> Paged
                      -> SortOrder
                      -> Maybe BlockIndex
                      -> Maybe BlockIndex
                      -> ExceptT
                           BlockfrostError (ReaderT ClientConfig IO) [AddressTransaction]))))
-> (Project -> CardanoAPI (AsClientT BlockfrostClient))
-> Project
-> ((Address
     -> ExceptT BlockfrostError (ReaderT ClientConfig IO) AddressInfo)
    :<|> (Address
          -> ExceptT
               BlockfrostError (ReaderT ClientConfig IO) AddressDetails))
   :<|> ((Address
          -> Paged
          -> SortOrder
          -> ExceptT BlockfrostError (ReaderT ClientConfig IO) [AddressUtxo])
         :<|> ((Address
                -> AssetId
                -> Paged
                -> SortOrder
                -> ExceptT BlockfrostError (ReaderT ClientConfig IO) [AddressUtxo])
               :<|> (Address
                     -> Paged
                     -> SortOrder
                     -> Maybe BlockIndex
                     -> Maybe BlockIndex
                     -> ExceptT
                          BlockfrostError (ReaderT ClientConfig IO) [AddressTransaction])))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Project -> CardanoAPI (AsClientT BlockfrostClient)
cardanoClient

getAddressInfo_ :: Project -> Address -> BlockfrostClient AddressInfo
getAddressInfo_ :: Project
-> Address
-> ExceptT BlockfrostError (ReaderT ClientConfig IO) AddressInfo
getAddressInfo_ = AddressesAPI (AsClientT BlockfrostClient)
-> Address
-> ExceptT BlockfrostError (ReaderT ClientConfig IO) AddressInfo
forall route.
AddressesAPI route
-> route
   :- (Summary "Specific address"
       :> (Description "Obtain information about a specific address."
           :> (Capture "address" Address :> Get '[JSON] AddressInfo)))
_addressInfo (AddressesAPI (AsClientT BlockfrostClient)
 -> Address
 -> ExceptT BlockfrostError (ReaderT ClientConfig IO) AddressInfo)
-> (Project -> AddressesAPI (AsClientT BlockfrostClient))
-> Project
-> Address
-> ExceptT BlockfrostError (ReaderT ClientConfig IO) AddressInfo
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Project -> AddressesAPI (AsClientT BlockfrostClient)
addressesClient

-- | Obtain information about a specific address.
getAddressInfo :: Address -> BlockfrostClient AddressInfo
getAddressInfo :: Address
-> ExceptT BlockfrostError (ReaderT ClientConfig IO) AddressInfo
getAddressInfo Address
a = (Project
 -> ExceptT BlockfrostError (ReaderT ClientConfig IO) AddressInfo)
-> ExceptT BlockfrostError (ReaderT ClientConfig IO) AddressInfo
forall a. (Project -> BlockfrostClient a) -> BlockfrostClient a
go (Project
-> Address
-> ExceptT BlockfrostError (ReaderT ClientConfig IO) AddressInfo
`getAddressInfo_` Address
a)

getAddressDetails_ :: Project -> Address -> BlockfrostClient AddressDetails
getAddressDetails_ :: Project
-> Address
-> ExceptT BlockfrostError (ReaderT ClientConfig IO) AddressDetails
getAddressDetails_ = AddressesAPI (AsClientT BlockfrostClient)
-> Address
-> ExceptT BlockfrostError (ReaderT ClientConfig IO) AddressDetails
forall route.
AddressesAPI route
-> route
   :- (Summary "Address details"
       :> (Description "Obtain details about an address."
           :> (Capture "address" Address
               :> ("total" :> Get '[JSON] AddressDetails))))
_addressDetails (AddressesAPI (AsClientT BlockfrostClient)
 -> Address
 -> ExceptT
      BlockfrostError (ReaderT ClientConfig IO) AddressDetails)
-> (Project -> AddressesAPI (AsClientT BlockfrostClient))
-> Project
-> Address
-> ExceptT BlockfrostError (ReaderT ClientConfig IO) AddressDetails
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Project -> AddressesAPI (AsClientT BlockfrostClient)
addressesClient

-- | Obtain details about an address.
getAddressDetails :: Address -> BlockfrostClient AddressDetails
getAddressDetails :: Address
-> ExceptT BlockfrostError (ReaderT ClientConfig IO) AddressDetails
getAddressDetails Address
a = (Project
 -> ExceptT
      BlockfrostError (ReaderT ClientConfig IO) AddressDetails)
-> ExceptT BlockfrostError (ReaderT ClientConfig IO) AddressDetails
forall a. (Project -> BlockfrostClient a) -> BlockfrostClient a
go (Project
-> Address
-> ExceptT BlockfrostError (ReaderT ClientConfig IO) AddressDetails
`getAddressDetails_` Address
a)

getAddressUtxos_ :: Project -> Address -> Paged -> SortOrder -> BlockfrostClient [AddressUtxo]
getAddressUtxos_ :: Project
-> Address
-> Paged
-> SortOrder
-> ExceptT BlockfrostError (ReaderT ClientConfig IO) [AddressUtxo]
getAddressUtxos_ = AddressesAPI (AsClientT BlockfrostClient)
-> Address
-> Paged
-> SortOrder
-> ExceptT BlockfrostError (ReaderT ClientConfig IO) [AddressUtxo]
forall route.
AddressesAPI route
-> route
   :- (Summary "Address UTXOs"
       :> (Description "UTXOs of the address."
           :> (Capture "address" Address
               :> ("utxos"
                   :> (Pagination :> (Sorting :> Get '[JSON] [AddressUtxo]))))))
_addressUtxos (AddressesAPI (AsClientT BlockfrostClient)
 -> Address
 -> Paged
 -> SortOrder
 -> ExceptT BlockfrostError (ReaderT ClientConfig IO) [AddressUtxo])
-> (Project -> AddressesAPI (AsClientT BlockfrostClient))
-> Project
-> Address
-> Paged
-> SortOrder
-> ExceptT BlockfrostError (ReaderT ClientConfig IO) [AddressUtxo]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Project -> AddressesAPI (AsClientT BlockfrostClient)
addressesClient

-- | UTXOs of the address.
-- Allows custom paging and ordering using @Paged@ and @SortOrder@.
getAddressUtxos' :: Address -> Paged -> SortOrder -> BlockfrostClient [AddressUtxo]
getAddressUtxos' :: Address
-> Paged
-> SortOrder
-> ExceptT BlockfrostError (ReaderT ClientConfig IO) [AddressUtxo]
getAddressUtxos' Address
a Paged
pg SortOrder
s = (Project
 -> ExceptT BlockfrostError (ReaderT ClientConfig IO) [AddressUtxo])
-> ExceptT BlockfrostError (ReaderT ClientConfig IO) [AddressUtxo]
forall a. (Project -> BlockfrostClient a) -> BlockfrostClient a
go (\Project
p -> Project
-> Address
-> Paged
-> SortOrder
-> ExceptT BlockfrostError (ReaderT ClientConfig IO) [AddressUtxo]
getAddressUtxos_ Project
p Address
a Paged
pg SortOrder
s)

-- | UTXOs of the address.
getAddressUtxos :: Address -> BlockfrostClient [AddressUtxo]
getAddressUtxos :: Address
-> ExceptT BlockfrostError (ReaderT ClientConfig IO) [AddressUtxo]
getAddressUtxos Address
a = Address
-> Paged
-> SortOrder
-> ExceptT BlockfrostError (ReaderT ClientConfig IO) [AddressUtxo]
getAddressUtxos' Address
a Paged
forall a. Default a => a
def SortOrder
forall a. Default a => a
def

getAddressUtxosAsset_ :: Project -> Address -> AssetId -> Paged -> SortOrder -> BlockfrostClient [AddressUtxo]
getAddressUtxosAsset_ :: Project
-> Address
-> AssetId
-> Paged
-> SortOrder
-> ExceptT BlockfrostError (ReaderT ClientConfig IO) [AddressUtxo]
getAddressUtxosAsset_ = AddressesAPI (AsClientT BlockfrostClient)
-> Address
-> AssetId
-> Paged
-> SortOrder
-> ExceptT BlockfrostError (ReaderT ClientConfig IO) [AddressUtxo]
forall route.
AddressesAPI route
-> route
   :- (Summary "Address UTXOs of a given asset"
       :> (Description "UTXOs of the address."
           :> (Capture "address" Address
               :> ("utxos"
                   :> (Capture "asset" AssetId
                       :> (Pagination :> (Sorting :> Get '[JSON] [AddressUtxo])))))))
_addressUtxosAsset (AddressesAPI (AsClientT BlockfrostClient)
 -> Address
 -> AssetId
 -> Paged
 -> SortOrder
 -> ExceptT BlockfrostError (ReaderT ClientConfig IO) [AddressUtxo])
-> (Project -> AddressesAPI (AsClientT BlockfrostClient))
-> Project
-> Address
-> AssetId
-> Paged
-> SortOrder
-> ExceptT BlockfrostError (ReaderT ClientConfig IO) [AddressUtxo]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Project -> AddressesAPI (AsClientT BlockfrostClient)
addressesClient

-- | UTXOs of the address containing specific asset.
-- Allows custom paging and ordering using @Paged@ and @SortOrder@.
getAddressUtxosAsset' :: Address -> AssetId-> Paged -> SortOrder -> BlockfrostClient [AddressUtxo]
getAddressUtxosAsset' :: Address
-> AssetId
-> Paged
-> SortOrder
-> ExceptT BlockfrostError (ReaderT ClientConfig IO) [AddressUtxo]
getAddressUtxosAsset' Address
addr AssetId
asset Paged
pg SortOrder
s = (Project
 -> ExceptT BlockfrostError (ReaderT ClientConfig IO) [AddressUtxo])
-> ExceptT BlockfrostError (ReaderT ClientConfig IO) [AddressUtxo]
forall a. (Project -> BlockfrostClient a) -> BlockfrostClient a
go (\Project
p -> Project
-> Address
-> AssetId
-> Paged
-> SortOrder
-> ExceptT BlockfrostError (ReaderT ClientConfig IO) [AddressUtxo]
getAddressUtxosAsset_ Project
p Address
addr AssetId
asset Paged
pg SortOrder
s)

-- | UTXOs of the address containing specific asset.
getAddressUtxosAsset :: Address -> AssetId -> BlockfrostClient [AddressUtxo]
getAddressUtxosAsset :: Address
-> AssetId
-> ExceptT BlockfrostError (ReaderT ClientConfig IO) [AddressUtxo]
getAddressUtxosAsset Address
addr AssetId
asset = Address
-> AssetId
-> Paged
-> SortOrder
-> ExceptT BlockfrostError (ReaderT ClientConfig IO) [AddressUtxo]
getAddressUtxosAsset' Address
addr AssetId
asset Paged
forall a. Default a => a
def SortOrder
forall a. Default a => a
def

getAddressTransactions_ ::
--- Project -> Address -> BlockfrostClient [AddressTransaction]
     Project
  -> Address
  -> Paged
  -> SortOrder
  -> Maybe BlockIndex
  -> Maybe BlockIndex
  -> BlockfrostClient [AddressTransaction]
getAddressTransactions_ :: Project
-> Address
-> Paged
-> SortOrder
-> Maybe BlockIndex
-> Maybe BlockIndex
-> ExceptT
     BlockfrostError (ReaderT ClientConfig IO) [AddressTransaction]
getAddressTransactions_ = AddressesAPI (AsClientT BlockfrostClient)
-> Address
-> Paged
-> SortOrder
-> Maybe BlockIndex
-> Maybe BlockIndex
-> ExceptT
     BlockfrostError (ReaderT ClientConfig IO) [AddressTransaction]
forall route.
AddressesAPI route
-> route
   :- (Summary "Address transactions"
       :> (Description "Transactions on the address."
           :> (Capture "address" Address
               :> ("transactions"
                   :> (Pagination
                       :> (Sorting
                           :> (QueryParam "from" BlockIndex
                               :> (QueryParam "to" BlockIndex
                                   :> Get '[JSON] [AddressTransaction]))))))))
_addressTransactions (AddressesAPI (AsClientT BlockfrostClient)
 -> Address
 -> Paged
 -> SortOrder
 -> Maybe BlockIndex
 -> Maybe BlockIndex
 -> ExceptT
      BlockfrostError (ReaderT ClientConfig IO) [AddressTransaction])
-> (Project -> AddressesAPI (AsClientT BlockfrostClient))
-> Project
-> Address
-> Paged
-> SortOrder
-> Maybe BlockIndex
-> Maybe BlockIndex
-> ExceptT
     BlockfrostError (ReaderT ClientConfig IO) [AddressTransaction]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Project -> AddressesAPI (AsClientT BlockfrostClient)
addressesClient

-- | Transactions on the address.
-- Allows custom paging and ordering using @Paged@ and @SortOrder@.
-- Also allows support for limiting block ranges using `from`/`to`
-- @BlockIndex@es.
getAddressTransactions' ::
     Address
  -> Paged
  -> SortOrder
  -> Maybe BlockIndex
  -> Maybe BlockIndex
  -> BlockfrostClient [AddressTransaction]
getAddressTransactions' :: Address
-> Paged
-> SortOrder
-> Maybe BlockIndex
-> Maybe BlockIndex
-> ExceptT
     BlockfrostError (ReaderT ClientConfig IO) [AddressTransaction]
getAddressTransactions' Address
a Paged
pg SortOrder
s Maybe BlockIndex
from Maybe BlockIndex
to = (Project
 -> ExceptT
      BlockfrostError (ReaderT ClientConfig IO) [AddressTransaction])
-> ExceptT
     BlockfrostError (ReaderT ClientConfig IO) [AddressTransaction]
forall a. (Project -> BlockfrostClient a) -> BlockfrostClient a
go (\Project
p -> Project
-> Address
-> Paged
-> SortOrder
-> Maybe BlockIndex
-> Maybe BlockIndex
-> ExceptT
     BlockfrostError (ReaderT ClientConfig IO) [AddressTransaction]
getAddressTransactions_ Project
p Address
a Paged
pg SortOrder
s Maybe BlockIndex
from Maybe BlockIndex
to)

-- | Transactions on the address.
getAddressTransactions :: Address -> BlockfrostClient [AddressTransaction]
getAddressTransactions :: Address
-> ExceptT
     BlockfrostError (ReaderT ClientConfig IO) [AddressTransaction]
getAddressTransactions Address
a = Address
-> Paged
-> SortOrder
-> Maybe BlockIndex
-> Maybe BlockIndex
-> ExceptT
     BlockfrostError (ReaderT ClientConfig IO) [AddressTransaction]
getAddressTransactions' Address
a Paged
forall a. Default a => a
def SortOrder
forall a. Default a => a
def Maybe BlockIndex
forall a. Maybe a
Nothing Maybe BlockIndex
forall a. Maybe a
Nothing