-- | 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 :: MonadBlockfrost m => Project -> AddressesAPI (AsClientT m)
addressesClient :: forall (m :: * -> *).
MonadBlockfrost m =>
Project -> AddressesAPI (AsClientT m)
addressesClient = forall (routes :: * -> *) mode.
GenericServant routes mode =>
ToServant routes mode -> routes mode
fromServant forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall route.
CardanoAPI route
-> route
   :- ("addresses"
       :> (Tag "Cardano \187 Addresses" :> ToServantApi AddressesAPI))
_addresses forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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_ = forall route.
AddressesAPI route
-> route
   :- (Summary "Specific address"
       :> (Description "Obtain information about a specific address."
           :> (Capture "address" Address :> Get '[JSON] AddressInfo)))
_addressInfo forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 = forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (forall (m :: * -> *).
MonadBlockfrost m =>
Project -> Address -> m AddressInfo
`getAddressInfo_` Address
a)

getAddressDetails_ :: MonadBlockfrost m => Project -> Address -> m AddressDetails
getAddressDetails_ :: forall (m :: * -> *).
MonadBlockfrost m =>
Project -> Address -> m AddressDetails
getAddressDetails_ = forall route.
AddressesAPI route
-> route
   :- (Summary "Address details"
       :> (Description "Obtain details about an address."
           :> (Capture "address" Address
               :> ("total" :> Get '[JSON] AddressDetails))))
_addressDetails forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 = forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (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_ = forall route.
AddressesAPI route
-> route
   :- (Summary "Address UTXOs"
       :> (Description "UTXOs of the address."
           :> (Capture "address" Address
               :> ("utxos"
                   :> (Pagination :> (Sorting :> Get '[JSON] [AddressUtxo]))))))
_addressUtxos forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 = forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (\Project
p -> 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 = forall (m :: * -> *).
MonadBlockfrost m =>
Address -> Paged -> SortOrder -> m [AddressUtxo]
getAddressUtxos' Address
a forall a. Default a => a
def 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_ = 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 forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 = forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (\Project
p -> 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 = forall (m :: * -> *).
MonadBlockfrost m =>
Address -> AssetId -> Paged -> SortOrder -> m [AddressUtxo]
getAddressUtxosAsset' Address
addr AssetId
asset forall a. Default a => a
def 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_ = 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 forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 = forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (\Project
p -> 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 = forall (m :: * -> *).
MonadBlockfrost m =>
Address
-> Paged
-> SortOrder
-> Maybe BlockIndex
-> Maybe BlockIndex
-> m [AddressTransaction]
getAddressTransactions' Address
a forall a. Default a => a
def forall a. Default a => a
def forall a. Maybe a
Nothing forall a. Maybe a
Nothing