-- | Asset queries

module Blockfrost.Client.Cardano.Assets
  ( getAssets
  , getAssets'
  , getAssetDetails
  , getAssetHistory
  , getAssetHistory'
  , getAssetTransactions
  , getAssetTransactions'
  , getAssetAddresses
  , getAssetAddresses'
  , getAssetsByPolicy
  , getAssetsByPolicy'
  , parseStandardMetadata
  ) where

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

assetsClient :: MonadBlockfrost m => Project -> AssetsAPI (AsClientT m)
assetsClient :: forall (m :: * -> *).
MonadBlockfrost m =>
Project -> AssetsAPI (AsClientT m)
assetsClient = (((Paged -> SortOrder -> m [AssetInfo])
  :<|> ((AssetId -> m AssetDetails)
        :<|> (AssetId -> Paged -> SortOrder -> m [AssetHistory])))
 :<|> ((AssetId -> Paged -> SortOrder -> m [AssetTransaction])
       :<|> ((AssetId -> Paged -> SortOrder -> m [AssetAddress])
             :<|> (PolicyId -> Paged -> SortOrder -> m [AssetInfo]))))
-> AssetsAPI (AsClientT m)
ToServant AssetsAPI (AsClientT m) -> AssetsAPI (AsClientT m)
forall {k} (routes :: k -> *) (mode :: k).
GenericServant routes mode =>
ToServant routes mode -> routes mode
fromServant ((((Paged -> SortOrder -> m [AssetInfo])
   :<|> ((AssetId -> m AssetDetails)
         :<|> (AssetId -> Paged -> SortOrder -> m [AssetHistory])))
  :<|> ((AssetId -> Paged -> SortOrder -> m [AssetTransaction])
        :<|> ((AssetId -> Paged -> SortOrder -> m [AssetAddress])
              :<|> (PolicyId -> Paged -> SortOrder -> m [AssetInfo]))))
 -> AssetsAPI (AsClientT m))
-> (Project
    -> ((Paged -> SortOrder -> m [AssetInfo])
        :<|> ((AssetId -> m AssetDetails)
              :<|> (AssetId -> Paged -> SortOrder -> m [AssetHistory])))
       :<|> ((AssetId -> Paged -> SortOrder -> m [AssetTransaction])
             :<|> ((AssetId -> Paged -> SortOrder -> m [AssetAddress])
                   :<|> (PolicyId -> Paged -> SortOrder -> m [AssetInfo]))))
-> Project
-> AssetsAPI (AsClientT m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CardanoAPI (AsClientT m)
-> ((Paged -> SortOrder -> m [AssetInfo])
    :<|> ((AssetId -> m AssetDetails)
          :<|> (AssetId -> Paged -> SortOrder -> m [AssetHistory])))
   :<|> ((AssetId -> Paged -> SortOrder -> m [AssetTransaction])
         :<|> ((AssetId -> Paged -> SortOrder -> m [AssetAddress])
               :<|> (PolicyId -> Paged -> SortOrder -> m [AssetInfo])))
CardanoAPI (AsClientT m)
-> AsClientT m
   :- ("assets"
       :> (Tag "Cardano \187 Assets" :> ToServantApi AssetsAPI))
forall route.
CardanoAPI route
-> route
   :- ("assets"
       :> (Tag "Cardano \187 Assets" :> ToServantApi AssetsAPI))
_assets (CardanoAPI (AsClientT m)
 -> ((Paged -> SortOrder -> m [AssetInfo])
     :<|> ((AssetId -> m AssetDetails)
           :<|> (AssetId -> Paged -> SortOrder -> m [AssetHistory])))
    :<|> ((AssetId -> Paged -> SortOrder -> m [AssetTransaction])
          :<|> ((AssetId -> Paged -> SortOrder -> m [AssetAddress])
                :<|> (PolicyId -> Paged -> SortOrder -> m [AssetInfo]))))
-> (Project -> CardanoAPI (AsClientT m))
-> Project
-> ((Paged -> SortOrder -> m [AssetInfo])
    :<|> ((AssetId -> m AssetDetails)
          :<|> (AssetId -> Paged -> SortOrder -> m [AssetHistory])))
   :<|> ((AssetId -> Paged -> SortOrder -> m [AssetTransaction])
         :<|> ((AssetId -> Paged -> SortOrder -> m [AssetAddress])
               :<|> (PolicyId -> Paged -> SortOrder -> m [AssetInfo])))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Project -> CardanoAPI (AsClientT m)
forall (m :: * -> *).
MonadBlockfrost m =>
Project -> CardanoAPI (AsClientT m)
cardanoClient

getAssets_ :: MonadBlockfrost m => Project -> Paged -> SortOrder -> m [AssetInfo]
getAssets_ :: forall (m :: * -> *).
MonadBlockfrost m =>
Project -> Paged -> SortOrder -> m [AssetInfo]
getAssets_ = AssetsAPI (AsClientT m)
-> AsClientT m
   :- (Summary "Assets"
       :> (Description "List of assets."
           :> (Pagination :> (Sorting :> Get '[JSON] [AssetInfo]))))
AssetsAPI (AsClientT m) -> Paged -> SortOrder -> m [AssetInfo]
forall route.
AssetsAPI route
-> route
   :- (Summary "Assets"
       :> (Description "List of assets."
           :> (Pagination :> (Sorting :> Get '[JSON] [AssetInfo]))))
_listAssets (AssetsAPI (AsClientT m) -> Paged -> SortOrder -> m [AssetInfo])
-> (Project -> AssetsAPI (AsClientT m))
-> Project
-> Paged
-> SortOrder
-> m [AssetInfo]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Project -> AssetsAPI (AsClientT m)
forall (m :: * -> *).
MonadBlockfrost m =>
Project -> AssetsAPI (AsClientT m)
assetsClient

-- | List all assets
-- Allows custom paging and ordering using 'Paged' and 'SortOrder'.
getAssets' :: MonadBlockfrost m => Paged -> SortOrder -> m [AssetInfo]
getAssets' :: forall (m :: * -> *).
MonadBlockfrost m =>
Paged -> SortOrder -> m [AssetInfo]
getAssets' Paged
pg SortOrder
s = (Project -> m [AssetInfo]) -> m [AssetInfo]
forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (\Project
p -> Project -> Paged -> SortOrder -> m [AssetInfo]
forall (m :: * -> *).
MonadBlockfrost m =>
Project -> Paged -> SortOrder -> m [AssetInfo]
getAssets_ Project
p Paged
pg SortOrder
s)

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

getAssetDetails_ :: MonadBlockfrost m => Project -> AssetId -> m AssetDetails
getAssetDetails_ :: forall (m :: * -> *).
MonadBlockfrost m =>
Project -> AssetId -> m AssetDetails
getAssetDetails_ = AssetsAPI (AsClientT m)
-> AsClientT m
   :- (Summary "Specific asset"
       :> (Description "Information about a specific asset."
           :> (Capture "asset" AssetId :> Get '[JSON] AssetDetails)))
AssetsAPI (AsClientT m) -> AssetId -> m AssetDetails
forall route.
AssetsAPI route
-> route
   :- (Summary "Specific asset"
       :> (Description "Information about a specific asset."
           :> (Capture "asset" AssetId :> Get '[JSON] AssetDetails)))
_assetDetails (AssetsAPI (AsClientT m) -> AssetId -> m AssetDetails)
-> (Project -> AssetsAPI (AsClientT m))
-> Project
-> AssetId
-> m AssetDetails
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Project -> AssetsAPI (AsClientT m)
forall (m :: * -> *).
MonadBlockfrost m =>
Project -> AssetsAPI (AsClientT m)
assetsClient

-- | Information about a specific asset
getAssetDetails :: MonadBlockfrost m => AssetId -> m AssetDetails
getAssetDetails :: forall (m :: * -> *).
MonadBlockfrost m =>
AssetId -> m AssetDetails
getAssetDetails AssetId
a =  AssetDetails -> AssetDetails
parseStandardMetadataInDetails (AssetDetails -> AssetDetails) -> m AssetDetails -> m AssetDetails
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Project -> m AssetDetails) -> m AssetDetails
forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (Project -> AssetId -> m AssetDetails
forall (m :: * -> *).
MonadBlockfrost m =>
Project -> AssetId -> m AssetDetails
`getAssetDetails_` AssetId
a)

getAssetHistory_ :: MonadBlockfrost m => Project -> AssetId -> Paged -> SortOrder -> m [AssetHistory]
getAssetHistory_ :: forall (m :: * -> *).
MonadBlockfrost m =>
Project -> AssetId -> Paged -> SortOrder -> m [AssetHistory]
getAssetHistory_ = AssetsAPI (AsClientT m)
-> AsClientT m
   :- (Summary "Asset history"
       :> (Description "History of a specific asset."
           :> (Capture "asset" AssetId
               :> ("history"
                   :> (Pagination :> (Sorting :> Get '[JSON] [AssetHistory]))))))
AssetsAPI (AsClientT m)
-> AssetId -> Paged -> SortOrder -> m [AssetHistory]
forall route.
AssetsAPI route
-> route
   :- (Summary "Asset history"
       :> (Description "History of a specific asset."
           :> (Capture "asset" AssetId
               :> ("history"
                   :> (Pagination :> (Sorting :> Get '[JSON] [AssetHistory]))))))
_assetHistory (AssetsAPI (AsClientT m)
 -> AssetId -> Paged -> SortOrder -> m [AssetHistory])
-> (Project -> AssetsAPI (AsClientT m))
-> Project
-> AssetId
-> Paged
-> SortOrder
-> m [AssetHistory]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Project -> AssetsAPI (AsClientT m)
forall (m :: * -> *).
MonadBlockfrost m =>
Project -> AssetsAPI (AsClientT m)
assetsClient

-- | History of a specific asset
-- Allows custom paging and ordering using 'Paged' and 'SortOrder'.
getAssetHistory' :: MonadBlockfrost m => AssetId -> Paged -> SortOrder -> m [AssetHistory]
getAssetHistory' :: forall (m :: * -> *).
MonadBlockfrost m =>
AssetId -> Paged -> SortOrder -> m [AssetHistory]
getAssetHistory' AssetId
a Paged
pg SortOrder
s = (Project -> m [AssetHistory]) -> m [AssetHistory]
forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (\Project
p -> Project -> AssetId -> Paged -> SortOrder -> m [AssetHistory]
forall (m :: * -> *).
MonadBlockfrost m =>
Project -> AssetId -> Paged -> SortOrder -> m [AssetHistory]
getAssetHistory_ Project
p AssetId
a Paged
pg SortOrder
s)

-- | History of a 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.
getAssetHistory :: MonadBlockfrost m => AssetId -> m [AssetHistory]
getAssetHistory :: forall (m :: * -> *).
MonadBlockfrost m =>
AssetId -> m [AssetHistory]
getAssetHistory AssetId
a = AssetId -> Paged -> SortOrder -> m [AssetHistory]
forall (m :: * -> *).
MonadBlockfrost m =>
AssetId -> Paged -> SortOrder -> m [AssetHistory]
getAssetHistory' AssetId
a Paged
forall a. Default a => a
def SortOrder
forall a. Default a => a
def

getAssetTransactions_ :: MonadBlockfrost m => Project -> AssetId -> Paged -> SortOrder -> m [AssetTransaction]
getAssetTransactions_ :: forall (m :: * -> *).
MonadBlockfrost m =>
Project -> AssetId -> Paged -> SortOrder -> m [AssetTransaction]
getAssetTransactions_ = AssetsAPI (AsClientT m)
-> AsClientT m
   :- (Summary "Asset transactions"
       :> (Description "List of a specific asset transactions"
           :> (Capture "asset" AssetId
               :> ("transactions"
                   :> (Pagination :> (Sorting :> Get '[JSON] [AssetTransaction]))))))
AssetsAPI (AsClientT m)
-> AssetId -> Paged -> SortOrder -> m [AssetTransaction]
forall route.
AssetsAPI route
-> route
   :- (Summary "Asset transactions"
       :> (Description "List of a specific asset transactions"
           :> (Capture "asset" AssetId
               :> ("transactions"
                   :> (Pagination :> (Sorting :> Get '[JSON] [AssetTransaction]))))))
_assetTransactions (AssetsAPI (AsClientT m)
 -> AssetId -> Paged -> SortOrder -> m [AssetTransaction])
-> (Project -> AssetsAPI (AsClientT m))
-> Project
-> AssetId
-> Paged
-> SortOrder
-> m [AssetTransaction]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Project -> AssetsAPI (AsClientT m)
forall (m :: * -> *).
MonadBlockfrost m =>
Project -> AssetsAPI (AsClientT m)
assetsClient

-- | List of a specific asset transactions
-- Allows custom paging and ordering using 'Paged' and 'SortOrder'.
getAssetTransactions' :: MonadBlockfrost m => AssetId -> Paged -> SortOrder -> m [AssetTransaction]
getAssetTransactions' :: forall (m :: * -> *).
MonadBlockfrost m =>
AssetId -> Paged -> SortOrder -> m [AssetTransaction]
getAssetTransactions' AssetId
a Paged
pg SortOrder
s = (Project -> m [AssetTransaction]) -> m [AssetTransaction]
forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (\Project
p -> Project -> AssetId -> Paged -> SortOrder -> m [AssetTransaction]
forall (m :: * -> *).
MonadBlockfrost m =>
Project -> AssetId -> Paged -> SortOrder -> m [AssetTransaction]
getAssetTransactions_ Project
p AssetId
a Paged
pg SortOrder
s)

-- | List of a specific asset transactions
--
-- Queries 100 entries. To query all entries use 'Blockfrost.Client.Core.allPages'
-- with principled variant of this function (suffixed with @'@)
-- that accepts 'Paged' argument.
getAssetTransactions :: MonadBlockfrost m => AssetId -> m [AssetTransaction]
getAssetTransactions :: forall (m :: * -> *).
MonadBlockfrost m =>
AssetId -> m [AssetTransaction]
getAssetTransactions AssetId
a = AssetId -> Paged -> SortOrder -> m [AssetTransaction]
forall (m :: * -> *).
MonadBlockfrost m =>
AssetId -> Paged -> SortOrder -> m [AssetTransaction]
getAssetTransactions' AssetId
a Paged
forall a. Default a => a
def SortOrder
forall a. Default a => a
def

getAssetAddresses_ :: MonadBlockfrost m => Project -> AssetId -> Paged -> SortOrder -> m [AssetAddress]
getAssetAddresses_ :: forall (m :: * -> *).
MonadBlockfrost m =>
Project -> AssetId -> Paged -> SortOrder -> m [AssetAddress]
getAssetAddresses_ = AssetsAPI (AsClientT m)
-> AsClientT m
   :- (Summary "Asset addresses"
       :> (Description "List of a addresses containing a specific asset"
           :> (Capture "asset" AssetId
               :> ("addresses"
                   :> (Pagination :> (Sorting :> Get '[JSON] [AssetAddress]))))))
AssetsAPI (AsClientT m)
-> AssetId -> Paged -> SortOrder -> m [AssetAddress]
forall route.
AssetsAPI route
-> route
   :- (Summary "Asset addresses"
       :> (Description "List of a addresses containing a specific asset"
           :> (Capture "asset" AssetId
               :> ("addresses"
                   :> (Pagination :> (Sorting :> Get '[JSON] [AssetAddress]))))))
_assetAddresses (AssetsAPI (AsClientT m)
 -> AssetId -> Paged -> SortOrder -> m [AssetAddress])
-> (Project -> AssetsAPI (AsClientT m))
-> Project
-> AssetId
-> Paged
-> SortOrder
-> m [AssetAddress]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Project -> AssetsAPI (AsClientT m)
forall (m :: * -> *).
MonadBlockfrost m =>
Project -> AssetsAPI (AsClientT m)
assetsClient

-- | List of a addresses containing a specific asset
-- Allows custom paging and ordering using 'Paged' and 'SortOrder'.
getAssetAddresses' :: MonadBlockfrost m => AssetId -> Paged -> SortOrder -> m [AssetAddress]
getAssetAddresses' :: forall (m :: * -> *).
MonadBlockfrost m =>
AssetId -> Paged -> SortOrder -> m [AssetAddress]
getAssetAddresses' AssetId
a Paged
pg SortOrder
s = (Project -> m [AssetAddress]) -> m [AssetAddress]
forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (\Project
p -> Project -> AssetId -> Paged -> SortOrder -> m [AssetAddress]
forall (m :: * -> *).
MonadBlockfrost m =>
Project -> AssetId -> Paged -> SortOrder -> m [AssetAddress]
getAssetAddresses_ Project
p AssetId
a Paged
pg SortOrder
s)

-- | List of a addresses containing a 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.
getAssetAddresses :: MonadBlockfrost m => AssetId -> m [AssetAddress]
getAssetAddresses :: forall (m :: * -> *).
MonadBlockfrost m =>
AssetId -> m [AssetAddress]
getAssetAddresses AssetId
a = AssetId -> Paged -> SortOrder -> m [AssetAddress]
forall (m :: * -> *).
MonadBlockfrost m =>
AssetId -> Paged -> SortOrder -> m [AssetAddress]
getAssetAddresses' AssetId
a Paged
forall a. Default a => a
def SortOrder
forall a. Default a => a
def

getAssetsByPolicy_ :: MonadBlockfrost m => Project -> PolicyId -> Paged -> SortOrder -> m [AssetInfo]
getAssetsByPolicy_ :: forall (m :: * -> *).
MonadBlockfrost m =>
Project -> PolicyId -> Paged -> SortOrder -> m [AssetInfo]
getAssetsByPolicy_ = AssetsAPI (AsClientT m)
-> AsClientT m
   :- (Summary "Assets of a specific policy"
       :> (Description "List of asset minted under a specific policy."
           :> ("policy"
               :> (Capture "policy_id" PolicyId
                   :> (Pagination :> (Sorting :> Get '[JSON] [AssetInfo]))))))
AssetsAPI (AsClientT m)
-> PolicyId -> Paged -> SortOrder -> m [AssetInfo]
forall route.
AssetsAPI route
-> route
   :- (Summary "Assets of a specific policy"
       :> (Description "List of asset minted under a specific policy."
           :> ("policy"
               :> (Capture "policy_id" PolicyId
                   :> (Pagination :> (Sorting :> Get '[JSON] [AssetInfo]))))))
_listAssetsPolicy (AssetsAPI (AsClientT m)
 -> PolicyId -> Paged -> SortOrder -> m [AssetInfo])
-> (Project -> AssetsAPI (AsClientT m))
-> Project
-> PolicyId
-> Paged
-> SortOrder
-> m [AssetInfo]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Project -> AssetsAPI (AsClientT m)
forall (m :: * -> *).
MonadBlockfrost m =>
Project -> AssetsAPI (AsClientT m)
assetsClient

-- | List of asset minted under a specific policy
-- Allows custom paging and ordering using 'Paged' and 'SortOrder'.
getAssetsByPolicy' :: MonadBlockfrost m => PolicyId -> Paged -> SortOrder -> m [AssetInfo]
getAssetsByPolicy' :: forall (m :: * -> *).
MonadBlockfrost m =>
PolicyId -> Paged -> SortOrder -> m [AssetInfo]
getAssetsByPolicy' PolicyId
a Paged
pg SortOrder
s = (Project -> m [AssetInfo]) -> m [AssetInfo]
forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (\Project
p -> Project -> PolicyId -> Paged -> SortOrder -> m [AssetInfo]
forall (m :: * -> *).
MonadBlockfrost m =>
Project -> PolicyId -> Paged -> SortOrder -> m [AssetInfo]
getAssetsByPolicy_ Project
p PolicyId
a Paged
pg SortOrder
s)

-- | List of asset minted under a specific policy
--
-- Queries 100 entries. To query all entries use 'Blockfrost.Client.Core.allPages'
-- with principled variant of this function (suffixed with @'@)
-- that accepts 'Paged' argument.
getAssetsByPolicy :: MonadBlockfrost m => PolicyId -> m [AssetInfo]
getAssetsByPolicy :: forall (m :: * -> *).
MonadBlockfrost m =>
PolicyId -> m [AssetInfo]
getAssetsByPolicy PolicyId
a = PolicyId -> Paged -> SortOrder -> m [AssetInfo]
forall (m :: * -> *).
MonadBlockfrost m =>
PolicyId -> Paged -> SortOrder -> m [AssetInfo]
getAssetsByPolicy' PolicyId
a Paged
forall a. Default a => a
def SortOrder
forall a. Default a => a
def