-- | Address queries

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

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

addressesClient :: MonadBlockfrost m => Project -> AddressesAPI (AsClientT m)
addressesClient :: forall (m :: * -> *).
MonadBlockfrost m =>
Project -> AddressesAPI (AsClientT m)
addressesClient = (((Address -> m AddressInfo)
  :<|> ((Address -> m AddressInfoExtended)
        :<|> (Address -> m AddressDetails)))
 :<|> ((Address -> Paged -> SortOrder -> m [AddressUtxo])
       :<|> ((Address -> AssetId -> Paged -> SortOrder -> m [AddressUtxo])
             :<|> (Address
                   -> Paged
                   -> SortOrder
                   -> Maybe BlockIndex
                   -> Maybe BlockIndex
                   -> m [AddressTransaction]))))
-> AddressesAPI (AsClientT m)
ToServant AddressesAPI (AsClientT m) -> AddressesAPI (AsClientT m)
forall {k} (routes :: k -> *) (mode :: k).
GenericServant routes mode =>
ToServant routes mode -> routes mode
fromServant ((((Address -> m AddressInfo)
   :<|> ((Address -> m AddressInfoExtended)
         :<|> (Address -> m AddressDetails)))
  :<|> ((Address -> Paged -> SortOrder -> m [AddressUtxo])
        :<|> ((Address -> AssetId -> Paged -> SortOrder -> m [AddressUtxo])
              :<|> (Address
                    -> Paged
                    -> SortOrder
                    -> Maybe BlockIndex
                    -> Maybe BlockIndex
                    -> m [AddressTransaction]))))
 -> AddressesAPI (AsClientT m))
-> (Project
    -> ((Address -> m AddressInfo)
        :<|> ((Address -> m AddressInfoExtended)
              :<|> (Address -> m AddressDetails)))
       :<|> ((Address -> Paged -> SortOrder -> m [AddressUtxo])
             :<|> ((Address -> AssetId -> Paged -> SortOrder -> m [AddressUtxo])
                   :<|> (Address
                         -> Paged
                         -> SortOrder
                         -> Maybe BlockIndex
                         -> Maybe BlockIndex
                         -> m [AddressTransaction]))))
-> Project
-> AddressesAPI (AsClientT m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CardanoAPI (AsClientT m)
-> ((Address -> m AddressInfo)
    :<|> ((Address -> m AddressInfoExtended)
          :<|> (Address -> m AddressDetails)))
   :<|> ((Address -> Paged -> SortOrder -> m [AddressUtxo])
         :<|> ((Address -> AssetId -> Paged -> SortOrder -> m [AddressUtxo])
               :<|> (Address
                     -> Paged
                     -> SortOrder
                     -> Maybe BlockIndex
                     -> Maybe BlockIndex
                     -> m [AddressTransaction])))
CardanoAPI (AsClientT m)
-> AsClientT m
   :- ("addresses"
       :> (Tag "Cardano \187 Addresses" :> ToServantApi AddressesAPI))
forall route.
CardanoAPI route
-> route
   :- ("addresses"
       :> (Tag "Cardano \187 Addresses" :> ToServantApi AddressesAPI))
_addresses (CardanoAPI (AsClientT m)
 -> ((Address -> m AddressInfo)
     :<|> ((Address -> m AddressInfoExtended)
           :<|> (Address -> m AddressDetails)))
    :<|> ((Address -> Paged -> SortOrder -> m [AddressUtxo])
          :<|> ((Address -> AssetId -> Paged -> SortOrder -> m [AddressUtxo])
                :<|> (Address
                      -> Paged
                      -> SortOrder
                      -> Maybe BlockIndex
                      -> Maybe BlockIndex
                      -> m [AddressTransaction]))))
-> (Project -> CardanoAPI (AsClientT m))
-> Project
-> ((Address -> m AddressInfo)
    :<|> ((Address -> m AddressInfoExtended)
          :<|> (Address -> m AddressDetails)))
   :<|> ((Address -> Paged -> SortOrder -> m [AddressUtxo])
         :<|> ((Address -> AssetId -> Paged -> SortOrder -> m [AddressUtxo])
               :<|> (Address
                     -> Paged
                     -> SortOrder
                     -> Maybe BlockIndex
                     -> Maybe BlockIndex
                     -> m [AddressTransaction])))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Project -> CardanoAPI (AsClientT m)
forall (m :: * -> *).
MonadBlockfrost m =>
Project -> CardanoAPI (AsClientT m)
cardanoClient

getAddressInfo_ :: MonadBlockfrost m => Project -> Address -> m AddressInfo
getAddressInfo_ :: forall (m :: * -> *).
MonadBlockfrost m =>
Project -> Address -> m AddressInfo
getAddressInfo_ = AddressesAPI (AsClientT m)
-> AsClientT m
   :- (Summary "Specific address"
       :> (Description "Obtain information about a specific address."
           :> (Capture "address" Address :> Get '[JSON] AddressInfo)))
AddressesAPI (AsClientT m) -> Address -> m 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 m) -> Address -> m AddressInfo)
-> (Project -> AddressesAPI (AsClientT m))
-> Project
-> Address
-> m AddressInfo
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Project -> AddressesAPI (AsClientT m)
forall (m :: * -> *).
MonadBlockfrost m =>
Project -> AddressesAPI (AsClientT m)
addressesClient

-- | Obtain information about a specific address.
getAddressInfo :: MonadBlockfrost m => Address -> m AddressInfo
getAddressInfo :: forall (m :: * -> *). MonadBlockfrost m => Address -> m AddressInfo
getAddressInfo Address
a = (Project -> m AddressInfo) -> m AddressInfo
forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (Project -> Address -> m AddressInfo
forall (m :: * -> *).
MonadBlockfrost m =>
Project -> Address -> m AddressInfo
`getAddressInfo_` Address
a)

getAddressInfoExtended_ :: MonadBlockfrost m => Project -> Address -> m AddressInfoExtended
getAddressInfoExtended_ :: forall (m :: * -> *).
MonadBlockfrost m =>
Project -> Address -> m AddressInfoExtended
getAddressInfoExtended_ = AddressesAPI (AsClientT m)
-> AsClientT m
   :- (Summary "Specific address - extended"
       :> (Description
             "Obtain extended information about a specific address."
           :> (Capture "address" Address
               :> ("extended" :> Get '[JSON] AddressInfoExtended))))
AddressesAPI (AsClientT m) -> Address -> m AddressInfoExtended
forall route.
AddressesAPI route
-> route
   :- (Summary "Specific address - extended"
       :> (Description
             "Obtain extended information about a specific address."
           :> (Capture "address" Address
               :> ("extended" :> Get '[JSON] AddressInfoExtended))))
_addressInfoExtended (AddressesAPI (AsClientT m) -> Address -> m AddressInfoExtended)
-> (Project -> AddressesAPI (AsClientT m))
-> Project
-> Address
-> m AddressInfoExtended
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Project -> AddressesAPI (AsClientT m)
forall (m :: * -> *).
MonadBlockfrost m =>
Project -> AddressesAPI (AsClientT m)
addressesClient

-- | Obtain extended information about a specific address.
getAddressInfoExtended :: MonadBlockfrost m => Address -> m AddressInfoExtended
getAddressInfoExtended :: forall (m :: * -> *).
MonadBlockfrost m =>
Address -> m AddressInfoExtended
getAddressInfoExtended Address
a = (Project -> m AddressInfoExtended) -> m AddressInfoExtended
forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (Project -> Address -> m AddressInfoExtended
forall (m :: * -> *).
MonadBlockfrost m =>
Project -> Address -> m AddressInfoExtended
`getAddressInfoExtended_` Address
a)

getAddressDetails_ :: MonadBlockfrost m => Project -> Address -> m AddressDetails
getAddressDetails_ :: forall (m :: * -> *).
MonadBlockfrost m =>
Project -> Address -> m AddressDetails
getAddressDetails_ = AddressesAPI (AsClientT m)
-> AsClientT m
   :- (Summary "Address details"
       :> (Description "Obtain details about an address."
           :> (Capture "address" Address
               :> ("total" :> Get '[JSON] AddressDetails))))
AddressesAPI (AsClientT m) -> Address -> m 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 m) -> Address -> m AddressDetails)
-> (Project -> AddressesAPI (AsClientT m))
-> Project
-> Address
-> m AddressDetails
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Project -> AddressesAPI (AsClientT m)
forall (m :: * -> *).
MonadBlockfrost m =>
Project -> AddressesAPI (AsClientT m)
addressesClient

-- | Obtain details about an address.
getAddressDetails :: MonadBlockfrost m => Address -> m AddressDetails
getAddressDetails :: forall (m :: * -> *).
MonadBlockfrost m =>
Address -> m AddressDetails
getAddressDetails Address
a = (Project -> m AddressDetails) -> m AddressDetails
forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (Project -> Address -> m AddressDetails
forall (m :: * -> *).
MonadBlockfrost m =>
Project -> Address -> m AddressDetails
`getAddressDetails_` Address
a)

getAddressUtxos_ :: MonadBlockfrost m => Project -> Address -> Paged -> SortOrder -> m [AddressUtxo]
getAddressUtxos_ :: forall (m :: * -> *).
MonadBlockfrost m =>
Project -> Address -> Paged -> SortOrder -> m [AddressUtxo]
getAddressUtxos_ = AddressesAPI (AsClientT m)
-> AsClientT m
   :- (Summary "Address UTXOs"
       :> (Description "UTXOs of the address."
           :> (Capture "address" Address
               :> ("utxos"
                   :> (Pagination :> (Sorting :> Get '[JSON] [AddressUtxo]))))))
AddressesAPI (AsClientT m)
-> Address -> Paged -> SortOrder -> m [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 m)
 -> Address -> Paged -> SortOrder -> m [AddressUtxo])
-> (Project -> AddressesAPI (AsClientT m))
-> Project
-> Address
-> Paged
-> SortOrder
-> m [AddressUtxo]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Project -> AddressesAPI (AsClientT m)
forall (m :: * -> *).
MonadBlockfrost m =>
Project -> AddressesAPI (AsClientT m)
addressesClient

-- | UTXOs of the address.
-- Allows custom paging and ordering using 'Paged' and 'SortOrder'.
getAddressUtxos' :: MonadBlockfrost m => Address -> Paged -> SortOrder -> m [AddressUtxo]
getAddressUtxos' :: forall (m :: * -> *).
MonadBlockfrost m =>
Address -> Paged -> SortOrder -> m [AddressUtxo]
getAddressUtxos' Address
a Paged
pg SortOrder
s = (Project -> m [AddressUtxo]) -> m [AddressUtxo]
forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (\Project
p -> Project -> Address -> Paged -> SortOrder -> m [AddressUtxo]
forall (m :: * -> *).
MonadBlockfrost m =>
Project -> Address -> Paged -> SortOrder -> m [AddressUtxo]
getAddressUtxos_ Project
p Address
a Paged
pg SortOrder
s)

-- | UTXOs of the address.
--
-- Queries 100 entries. To query all entries use 'Blockfrost.Client.Core.allPages'
-- with principled variant of this function (suffixed with @'@)
-- that accepts 'Paged' argument.
getAddressUtxos :: MonadBlockfrost m => Address -> m [AddressUtxo]
getAddressUtxos :: forall (m :: * -> *).
MonadBlockfrost m =>
Address -> m [AddressUtxo]
getAddressUtxos Address
a = Address -> Paged -> SortOrder -> m [AddressUtxo]
forall (m :: * -> *).
MonadBlockfrost m =>
Address -> Paged -> SortOrder -> m [AddressUtxo]
getAddressUtxos' Address
a Paged
forall a. Default a => a
def SortOrder
forall a. Default a => a
def

getAddressUtxosAsset_ :: MonadBlockfrost m => Project -> Address -> AssetId -> Paged -> SortOrder -> m [AddressUtxo]
getAddressUtxosAsset_ :: forall (m :: * -> *).
MonadBlockfrost m =>
Project
-> Address -> AssetId -> Paged -> SortOrder -> m [AddressUtxo]
getAddressUtxosAsset_ = AddressesAPI (AsClientT m)
-> AsClientT m
   :- (Summary "Address UTXOs of a given asset"
       :> (Description "UTXOs of the address."
           :> (Capture "address" Address
               :> ("utxos"
                   :> (Capture "asset" AssetId
                       :> (Pagination :> (Sorting :> Get '[JSON] [AddressUtxo])))))))
AddressesAPI (AsClientT m)
-> Address -> AssetId -> Paged -> SortOrder -> m [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 m)
 -> Address -> AssetId -> Paged -> SortOrder -> m [AddressUtxo])
-> (Project -> AddressesAPI (AsClientT m))
-> Project
-> Address
-> AssetId
-> Paged
-> SortOrder
-> m [AddressUtxo]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Project -> AddressesAPI (AsClientT m)
forall (m :: * -> *).
MonadBlockfrost m =>
Project -> AddressesAPI (AsClientT m)
addressesClient

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

-- | UTXOs of the address containing specific asset.
--
-- Queries 100 entries. To query all entries use 'Blockfrost.Client.Core.allPages'
-- with principled variant of this function (suffixed with @'@)
-- that accepts 'Paged' argument.
getAddressUtxosAsset :: MonadBlockfrost m => Address -> AssetId -> m [AddressUtxo]
getAddressUtxosAsset :: forall (m :: * -> *).
MonadBlockfrost m =>
Address -> AssetId -> m [AddressUtxo]
getAddressUtxosAsset Address
addr AssetId
asset = Address -> AssetId -> Paged -> SortOrder -> m [AddressUtxo]
forall (m :: * -> *).
MonadBlockfrost m =>
Address -> AssetId -> Paged -> SortOrder -> m [AddressUtxo]
getAddressUtxosAsset' Address
addr AssetId
asset Paged
forall a. Default a => a
def SortOrder
forall a. Default a => a
def

getAddressTransactions_ ::
     MonadBlockfrost m
  => Project
  -> Address
  -> Paged
  -> SortOrder
  -> Maybe BlockIndex
  -> Maybe BlockIndex
  -> m [AddressTransaction]
getAddressTransactions_ :: forall (m :: * -> *).
MonadBlockfrost m =>
Project
-> Address
-> Paged
-> SortOrder
-> Maybe BlockIndex
-> Maybe BlockIndex
-> m [AddressTransaction]
getAddressTransactions_ = AddressesAPI (AsClientT m)
-> AsClientT m
   :- (Summary "Address transactions"
       :> (Description "Transactions on the address."
           :> (Capture "address" Address
               :> ("transactions"
                   :> (Pagination
                       :> (Sorting
                           :> (QueryParam "from" BlockIndex
                               :> (QueryParam "to" BlockIndex
                                   :> Get '[JSON] [AddressTransaction]))))))))
AddressesAPI (AsClientT m)
-> Address
-> Paged
-> SortOrder
-> Maybe BlockIndex
-> Maybe BlockIndex
-> m [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 m)
 -> Address
 -> Paged
 -> SortOrder
 -> Maybe BlockIndex
 -> Maybe BlockIndex
 -> m [AddressTransaction])
-> (Project -> AddressesAPI (AsClientT m))
-> Project
-> Address
-> Paged
-> SortOrder
-> Maybe BlockIndex
-> Maybe BlockIndex
-> m [AddressTransaction]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Project -> AddressesAPI (AsClientT m)
forall (m :: * -> *).
MonadBlockfrost m =>
Project -> AddressesAPI (AsClientT m)
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' ::
     MonadBlockfrost m
  => Address
  -> Paged
  -> SortOrder
  -> Maybe BlockIndex
  -> Maybe BlockIndex
  -> m [AddressTransaction]
getAddressTransactions' :: forall (m :: * -> *).
MonadBlockfrost m =>
Address
-> Paged
-> SortOrder
-> Maybe BlockIndex
-> Maybe BlockIndex
-> m [AddressTransaction]
getAddressTransactions' Address
a Paged
pg SortOrder
s Maybe BlockIndex
from Maybe BlockIndex
to = (Project -> m [AddressTransaction]) -> m [AddressTransaction]
forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (\Project
p -> Project
-> Address
-> Paged
-> SortOrder
-> Maybe BlockIndex
-> Maybe BlockIndex
-> m [AddressTransaction]
forall (m :: * -> *).
MonadBlockfrost m =>
Project
-> Address
-> Paged
-> SortOrder
-> Maybe BlockIndex
-> Maybe BlockIndex
-> m [AddressTransaction]
getAddressTransactions_ Project
p Address
a Paged
pg SortOrder
s Maybe BlockIndex
from Maybe BlockIndex
to)

-- | Transactions on the address.
--
-- Queries 100 entries. To query all entries use 'Blockfrost.Client.Core.allPages'
-- with principled variant of this function (suffixed with @'@)
-- that accepts 'Paged' argument.
getAddressTransactions :: MonadBlockfrost m => Address -> m [AddressTransaction]
getAddressTransactions :: forall (m :: * -> *).
MonadBlockfrost m =>
Address -> m [AddressTransaction]
getAddressTransactions Address
a = Address
-> Paged
-> SortOrder
-> Maybe BlockIndex
-> Maybe BlockIndex
-> m [AddressTransaction]
forall (m :: * -> *).
MonadBlockfrost m =>
Address
-> Paged
-> SortOrder
-> Maybe BlockIndex
-> Maybe BlockIndex
-> m [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