-- | Script queries

module Blockfrost.Client.Cardano.Scripts
  ( listScripts
  , listScripts'
  , getScript
  , getScriptRedeemers
  , getScriptRedeemers'
  , getScriptDatum
  , getScriptDatumCBOR
  , getScriptJSON
  , getScriptCBOR
  ) where

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

scriptsClient :: MonadBlockfrost m => Project -> ScriptsAPI (AsClientT m)
scriptsClient :: forall (m :: * -> *).
MonadBlockfrost m =>
Project -> ScriptsAPI (AsClientT m)
scriptsClient = 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
   :- ("scripts"
       :> (Tag "Cardano \187 Scripts" :> ToServantApi ScriptsAPI))
_scripts forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *).
MonadBlockfrost m =>
Project -> CardanoAPI (AsClientT m)
cardanoClient

listScripts_ :: MonadBlockfrost m => Project -> Paged -> SortOrder -> m ScriptHashList
listScripts_ :: forall (m :: * -> *).
MonadBlockfrost m =>
Project -> Paged -> SortOrder -> m ScriptHashList
listScripts_ = forall route.
ScriptsAPI route
-> route
   :- (Summary "Scripts"
       :> (Description "List of scripts."
           :> (Pagination :> (Sorting :> Get '[JSON] ScriptHashList))))
_listScripts forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *).
MonadBlockfrost m =>
Project -> ScriptsAPI (AsClientT m)
scriptsClient

-- | List scripts
-- Allows custom paging and ordering using 'Paged' and 'SortOrder'.
listScripts' :: MonadBlockfrost m => Paged -> SortOrder -> m ScriptHashList
listScripts' :: forall (m :: * -> *).
MonadBlockfrost m =>
Paged -> SortOrder -> m ScriptHashList
listScripts' Paged
pg SortOrder
s = forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (\Project
p -> forall (m :: * -> *).
MonadBlockfrost m =>
Project -> Paged -> SortOrder -> m ScriptHashList
listScripts_ Project
p Paged
pg SortOrder
s)

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

getScript_ :: MonadBlockfrost m => Project -> ScriptHash -> m Script
getScript_ :: forall (m :: * -> *).
MonadBlockfrost m =>
Project -> ScriptHash -> m Script
getScript_ = forall route.
ScriptsAPI route
-> route
   :- (Summary "Specific scripts"
       :> (Description "Information about a specific script."
           :> (Capture "script_hash" ScriptHash :> Get '[JSON] Script)))
_getScript forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *).
MonadBlockfrost m =>
Project -> ScriptsAPI (AsClientT m)
scriptsClient

-- | Get specific script information
getScript :: MonadBlockfrost m => ScriptHash -> m Script
getScript :: forall (m :: * -> *). MonadBlockfrost m => ScriptHash -> m Script
getScript ScriptHash
sh = forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (forall (m :: * -> *).
MonadBlockfrost m =>
Project -> ScriptHash -> m Script
`getScript_` ScriptHash
sh)

getScriptRedeemers_ :: MonadBlockfrost m => Project -> ScriptHash -> Paged -> SortOrder -> m [ScriptRedeemer]
getScriptRedeemers_ :: forall (m :: * -> *).
MonadBlockfrost m =>
Project -> ScriptHash -> Paged -> SortOrder -> m [ScriptRedeemer]
getScriptRedeemers_ = forall route.
ScriptsAPI route
-> route
   :- (Summary "Redeemers of a specific script"
       :> (Description "List of redeemers of a specific script."
           :> (Capture "script_hash" ScriptHash
               :> (Pagination
                   :> (Sorting :> ("redeemers" :> Get '[JSON] [ScriptRedeemer]))))))
_getScriptRedeemers forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *).
MonadBlockfrost m =>
Project -> ScriptsAPI (AsClientT m)
scriptsClient

-- | Get redeemers of a specific script
-- Allows custom paging and ordering using 'Paged' and 'SortOrder'.
getScriptRedeemers' :: MonadBlockfrost m => ScriptHash -> Paged -> SortOrder -> m [ScriptRedeemer]
getScriptRedeemers' :: forall (m :: * -> *).
MonadBlockfrost m =>
ScriptHash -> Paged -> SortOrder -> m [ScriptRedeemer]
getScriptRedeemers' ScriptHash
sh Paged
pg SortOrder
s = forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (\Project
p -> forall (m :: * -> *).
MonadBlockfrost m =>
Project -> ScriptHash -> Paged -> SortOrder -> m [ScriptRedeemer]
getScriptRedeemers_ Project
p ScriptHash
sh Paged
pg SortOrder
s)

-- | Get redeemers of a specific script
--
-- Queries 100 entries. To query all entries use 'Blockfrost.Client.Core.allPages'
-- with principled variant of this function (suffixed with @'@)
-- that accepts 'Paged' argument.
getScriptRedeemers :: MonadBlockfrost m => ScriptHash -> m [ScriptRedeemer]
getScriptRedeemers :: forall (m :: * -> *).
MonadBlockfrost m =>
ScriptHash -> m [ScriptRedeemer]
getScriptRedeemers ScriptHash
sh = forall (m :: * -> *).
MonadBlockfrost m =>
ScriptHash -> Paged -> SortOrder -> m [ScriptRedeemer]
getScriptRedeemers' ScriptHash
sh forall a. Default a => a
def forall a. Default a => a
def

getScriptDatum_ :: MonadBlockfrost m => Project -> DatumHash -> m ScriptDatum
getScriptDatum_ :: forall (m :: * -> *).
MonadBlockfrost m =>
Project -> DatumHash -> m ScriptDatum
getScriptDatum_ = forall route.
ScriptsAPI route
-> route
   :- (Summary "Datum value"
       :> (Description "Query JSON value of a datum by its hash"
           :> ("datum"
               :> (Capture "datum_hash" DatumHash :> Get '[JSON] ScriptDatum))))
_getScriptDatum forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *).
MonadBlockfrost m =>
Project -> ScriptsAPI (AsClientT m)
scriptsClient

-- | Get specific datum
getScriptDatum :: MonadBlockfrost m => DatumHash -> m ScriptDatum
getScriptDatum :: forall (m :: * -> *).
MonadBlockfrost m =>
DatumHash -> m ScriptDatum
getScriptDatum DatumHash
sh = forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (forall (m :: * -> *).
MonadBlockfrost m =>
Project -> DatumHash -> m ScriptDatum
`getScriptDatum_` DatumHash
sh)

getScriptDatumCBOR_ :: MonadBlockfrost m => Project -> DatumHash -> m ScriptDatumCBOR
getScriptDatumCBOR_ :: forall (m :: * -> *).
MonadBlockfrost m =>
Project -> DatumHash -> m ScriptDatumCBOR
getScriptDatumCBOR_ = forall route.
ScriptsAPI route
-> route
   :- (Summary "Datum CBOR value"
       :> (Description "Query CBOR serialised datum by its hash"
           :> ("datum"
               :> (Capture "datum_hash" DatumHash
                   :> ("cbor" :> Get '[JSON] ScriptDatumCBOR)))))
_getScriptDatumCBOR forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *).
MonadBlockfrost m =>
Project -> ScriptsAPI (AsClientT m)
scriptsClient

-- | Get specific datum
getScriptDatumCBOR :: MonadBlockfrost m => DatumHash -> m ScriptDatumCBOR
getScriptDatumCBOR :: forall (m :: * -> *).
MonadBlockfrost m =>
DatumHash -> m ScriptDatumCBOR
getScriptDatumCBOR DatumHash
sh = forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (forall (m :: * -> *).
MonadBlockfrost m =>
Project -> DatumHash -> m ScriptDatumCBOR
`getScriptDatumCBOR_` DatumHash
sh)

getScriptJSON_ :: MonadBlockfrost m => Project -> ScriptHash -> m ScriptJSON
getScriptJSON_ :: forall (m :: * -> *).
MonadBlockfrost m =>
Project -> ScriptHash -> m ScriptJSON
getScriptJSON_ = forall route.
ScriptsAPI route
-> route
   :- (Summary "Script JSON"
       :> (Description "JSON representation of a `timelock` script"
           :> (Capture "script_hash" ScriptHash
               :> ("json" :> Get '[JSON] ScriptJSON))))
_getScriptJSON forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *).
MonadBlockfrost m =>
Project -> ScriptsAPI (AsClientT m)
scriptsClient

-- | Get a JSON representation of a `timelock` script
getScriptJSON :: MonadBlockfrost m => ScriptHash -> m ScriptJSON
getScriptJSON :: forall (m :: * -> *).
MonadBlockfrost m =>
ScriptHash -> m ScriptJSON
getScriptJSON ScriptHash
sh = forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (forall (m :: * -> *).
MonadBlockfrost m =>
Project -> ScriptHash -> m ScriptJSON
`getScriptJSON_` ScriptHash
sh)

getScriptCBOR_ :: MonadBlockfrost m => Project -> ScriptHash -> m ScriptCBOR
getScriptCBOR_ :: forall (m :: * -> *).
MonadBlockfrost m =>
Project -> ScriptHash -> m ScriptCBOR
getScriptCBOR_ = forall route.
ScriptsAPI route
-> route
   :- (Summary "Script CBOR"
       :> (Description "CBOR representation of a `plutus` script"
           :> (Capture "script_hash" ScriptHash
               :> ("cbor" :> Get '[JSON] ScriptCBOR))))
_getScriptCBOR forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *).
MonadBlockfrost m =>
Project -> ScriptsAPI (AsClientT m)
scriptsClient

-- | Get a CBOR representation of a `plutus` script
getScriptCBOR :: MonadBlockfrost m => ScriptHash -> m ScriptCBOR
getScriptCBOR :: forall (m :: * -> *).
MonadBlockfrost m =>
ScriptHash -> m ScriptCBOR
getScriptCBOR ScriptHash
sh = forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (forall (m :: * -> *).
MonadBlockfrost m =>
Project -> ScriptHash -> m ScriptCBOR
`getScriptCBOR_` ScriptHash
sh)