-- | Transaction queries

module Blockfrost.Client.Cardano.Transactions
  ( getTx
  , getTxUtxos
  , getTxRedeemers
  , getTxStakes
  , getTxDelegations
  , getTxWithdrawals
  , getTxMirs
  , getTxPoolUpdates
  , getTxPoolRetiring
  , getTxMetadataJSON
  , getTxMetadataCBOR
  , submitTx
  ) where

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

transactionsClient :: MonadBlockfrost m => Project -> TransactionsAPI (AsClientT m)
transactionsClient :: forall (m :: * -> *).
MonadBlockfrost m =>
Project -> TransactionsAPI (AsClientT m)
transactionsClient = 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
   :- ("txs"
       :> (Tag "Cardano \187 Transactions"
           :> ToServantApi TransactionsAPI))
_transactions forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *).
MonadBlockfrost m =>
Project -> CardanoAPI (AsClientT m)
cardanoClient

getTx_ :: MonadBlockfrost m => Project -> TxHash -> m Transaction
getTx_ :: forall (m :: * -> *).
MonadBlockfrost m =>
Project -> TxHash -> m Transaction
getTx_ = forall route.
TransactionsAPI route
-> route
   :- (Summary "Specific transaction"
       :> (Description "Return content of the requested transaction."
           :> (Capture "hash" TxHash :> Get '[JSON] Transaction)))
_tx forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *).
MonadBlockfrost m =>
Project -> TransactionsAPI (AsClientT m)
transactionsClient

-- | Get specific transaction
getTx :: MonadBlockfrost m => TxHash -> m Transaction
getTx :: forall (m :: * -> *). MonadBlockfrost m => TxHash -> m Transaction
getTx TxHash
t = forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (forall (m :: * -> *).
MonadBlockfrost m =>
Project -> TxHash -> m Transaction
`getTx_` TxHash
t)

getTxUtxos_ :: MonadBlockfrost m => Project -> TxHash -> m TransactionUtxos
getTxUtxos_ :: forall (m :: * -> *).
MonadBlockfrost m =>
Project -> TxHash -> m TransactionUtxos
getTxUtxos_ = forall route.
TransactionsAPI route
-> route
   :- (Summary "Transaction UTXOs"
       :> (Description
             "Return the inputs and UTXOs of the specific transaction."
           :> (Capture "hash" TxHash
               :> ("utxos" :> Get '[JSON] TransactionUtxos))))
_txUtxos forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *).
MonadBlockfrost m =>
Project -> TransactionsAPI (AsClientT m)
transactionsClient

-- | Get transaction UTXOs
getTxUtxos :: MonadBlockfrost m => TxHash -> m TransactionUtxos
getTxUtxos :: forall (m :: * -> *).
MonadBlockfrost m =>
TxHash -> m TransactionUtxos
getTxUtxos TxHash
t = forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (forall (m :: * -> *).
MonadBlockfrost m =>
Project -> TxHash -> m TransactionUtxos
`getTxUtxos_` TxHash
t)

getTxRedeemers_ :: MonadBlockfrost m => Project -> TxHash -> m [TransactionRedeemer]
getTxRedeemers_ :: forall (m :: * -> *).
MonadBlockfrost m =>
Project -> TxHash -> m [TransactionRedeemer]
getTxRedeemers_ = forall route.
TransactionsAPI route
-> route
   :- (Summary "Transaction redeemers"
       :> (Description "Obtain the transaction redeemers."
           :> (Capture "hash" TxHash
               :> ("redeemers" :> Get '[JSON] [TransactionRedeemer]))))
_txRedeemers forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *).
MonadBlockfrost m =>
Project -> TransactionsAPI (AsClientT m)
transactionsClient

-- | Get transaction redeemers
getTxRedeemers :: MonadBlockfrost m => TxHash -> m [TransactionRedeemer]
getTxRedeemers :: forall (m :: * -> *).
MonadBlockfrost m =>
TxHash -> m [TransactionRedeemer]
getTxRedeemers TxHash
t = forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (forall (m :: * -> *).
MonadBlockfrost m =>
Project -> TxHash -> m [TransactionRedeemer]
`getTxRedeemers_` TxHash
t)

getTxStakes_ :: MonadBlockfrost m => Project -> TxHash -> m [TransactionStake]
getTxStakes_ :: forall (m :: * -> *).
MonadBlockfrost m =>
Project -> TxHash -> m [TransactionStake]
getTxStakes_ = forall route.
TransactionsAPI route
-> route
   :- (Summary "Transaction stake addresses certificates "
       :> (Description
             "Obtain information about (de)registration of stake addresses within a transaction."
           :> (Capture "hash" TxHash
               :> ("stakes" :> Get '[JSON] [TransactionStake]))))
_txStakes forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *).
MonadBlockfrost m =>
Project -> TransactionsAPI (AsClientT m)
transactionsClient

-- | Get (de-)registrations of a stake address within a transaction
getTxStakes :: MonadBlockfrost m => TxHash -> m [TransactionStake]
getTxStakes :: forall (m :: * -> *).
MonadBlockfrost m =>
TxHash -> m [TransactionStake]
getTxStakes TxHash
t = forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (forall (m :: * -> *).
MonadBlockfrost m =>
Project -> TxHash -> m [TransactionStake]
`getTxStakes_` TxHash
t)

getTxDelegations_ :: MonadBlockfrost m => Project -> TxHash -> m [TransactionDelegation]
getTxDelegations_ :: forall (m :: * -> *).
MonadBlockfrost m =>
Project -> TxHash -> m [TransactionDelegation]
getTxDelegations_ = forall route.
TransactionsAPI route
-> route
   :- (Summary "Transaction delegation certificates"
       :> (Description
             "Obtain information about delegation certificates of a specific transaction."
           :> (Capture "hash" TxHash
               :> ("delegations" :> Get '[JSON] [TransactionDelegation]))))
_txDelegations forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *).
MonadBlockfrost m =>
Project -> TransactionsAPI (AsClientT m)
transactionsClient

-- | Get transaction delegation certificates
getTxDelegations :: MonadBlockfrost m => TxHash -> m [TransactionDelegation]
getTxDelegations :: forall (m :: * -> *).
MonadBlockfrost m =>
TxHash -> m [TransactionDelegation]
getTxDelegations TxHash
t = forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (forall (m :: * -> *).
MonadBlockfrost m =>
Project -> TxHash -> m [TransactionDelegation]
`getTxDelegations_` TxHash
t)

getTxWithdrawals_ :: MonadBlockfrost m => Project -> TxHash -> m [TransactionWithdrawal]
getTxWithdrawals_ :: forall (m :: * -> *).
MonadBlockfrost m =>
Project -> TxHash -> m [TransactionWithdrawal]
getTxWithdrawals_ = forall route.
TransactionsAPI route
-> route
   :- (Summary "Transaction withdrawal"
       :> (Description
             "Obtain information about withdrawals of a specific transaction."
           :> (Capture "hash" TxHash
               :> ("withdrawals" :> Get '[JSON] [TransactionWithdrawal]))))
_txWithdrawals forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *).
MonadBlockfrost m =>
Project -> TransactionsAPI (AsClientT m)
transactionsClient

-- | Get transaction withdrawals
getTxWithdrawals :: MonadBlockfrost m => TxHash -> m [TransactionWithdrawal]
getTxWithdrawals :: forall (m :: * -> *).
MonadBlockfrost m =>
TxHash -> m [TransactionWithdrawal]
getTxWithdrawals TxHash
t = forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (forall (m :: * -> *).
MonadBlockfrost m =>
Project -> TxHash -> m [TransactionWithdrawal]
`getTxWithdrawals_` TxHash
t)

getTxMirs_ :: MonadBlockfrost m => Project -> TxHash -> m [TransactionMir]
getTxMirs_ :: forall (m :: * -> *).
MonadBlockfrost m =>
Project -> TxHash -> m [TransactionMir]
getTxMirs_ = forall route.
TransactionsAPI route
-> route
   :- (Summary "Transaction MIRs"
       :> (Description
             "Obtain information about Move Instantaneous Rewards (MIRs) of a specific transaction."
           :> (Capture "hash" TxHash
               :> ("mirs" :> Get '[JSON] [TransactionMir]))))
_txMirs forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *).
MonadBlockfrost m =>
Project -> TransactionsAPI (AsClientT m)
transactionsClient

-- | Get transaction MIRs (Move Instantaneous Rewards)
getTxMirs :: MonadBlockfrost m => TxHash -> m [TransactionMir]
getTxMirs :: forall (m :: * -> *).
MonadBlockfrost m =>
TxHash -> m [TransactionMir]
getTxMirs TxHash
t = forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (forall (m :: * -> *).
MonadBlockfrost m =>
Project -> TxHash -> m [TransactionMir]
`getTxMirs_` TxHash
t)

getTxPoolUpdates_ :: MonadBlockfrost m => Project -> TxHash -> m [TransactionPoolUpdate]
getTxPoolUpdates_ :: forall (m :: * -> *).
MonadBlockfrost m =>
Project -> TxHash -> m [TransactionPoolUpdate]
getTxPoolUpdates_ = forall route.
TransactionsAPI route
-> route
   :- (Summary
         "Transaction stake pool registration and update certificates"
       :> (Description
             "Obtain information about stake pool registration and update certificates of a specific transaction."
           :> (Capture "hash" TxHash
               :> ("pool_updates" :> Get '[JSON] [TransactionPoolUpdate]))))
_txPoolUpdates forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *).
MonadBlockfrost m =>
Project -> TransactionsAPI (AsClientT m)
transactionsClient

-- | Get transaction stake pool registration and update certificates
getTxPoolUpdates :: MonadBlockfrost m => TxHash -> m [TransactionPoolUpdate]
getTxPoolUpdates :: forall (m :: * -> *).
MonadBlockfrost m =>
TxHash -> m [TransactionPoolUpdate]
getTxPoolUpdates TxHash
t = forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (forall (m :: * -> *).
MonadBlockfrost m =>
Project -> TxHash -> m [TransactionPoolUpdate]
`getTxPoolUpdates_` TxHash
t)

getTxPoolRetiring_ :: MonadBlockfrost m => Project -> TxHash -> m [TransactionPoolRetiring]
getTxPoolRetiring_ :: forall (m :: * -> *).
MonadBlockfrost m =>
Project -> TxHash -> m [TransactionPoolRetiring]
getTxPoolRetiring_ = forall route.
TransactionsAPI route
-> route
   :- (Summary "Transaction stake pool retirement certificates"
       :> (Description
             "Obtain information about stake pool retirements within a specific transaction."
           :> (Capture "hash" TxHash
               :> ("pool_retires" :> Get '[JSON] [TransactionPoolRetiring]))))
_txPoolRetiring forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *).
MonadBlockfrost m =>
Project -> TransactionsAPI (AsClientT m)
transactionsClient

-- | Get transaction stake pool retirement certificates
getTxPoolRetiring :: MonadBlockfrost m => TxHash -> m [TransactionPoolRetiring]
getTxPoolRetiring :: forall (m :: * -> *).
MonadBlockfrost m =>
TxHash -> m [TransactionPoolRetiring]
getTxPoolRetiring TxHash
t = forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (forall (m :: * -> *).
MonadBlockfrost m =>
Project -> TxHash -> m [TransactionPoolRetiring]
`getTxPoolRetiring_` TxHash
t)

getTxMetadataJSON_ :: MonadBlockfrost m => Project -> TxHash -> m [TransactionMetaJSON]
getTxMetadataJSON_ :: forall (m :: * -> *).
MonadBlockfrost m =>
Project -> TxHash -> m [TransactionMetaJSON]
getTxMetadataJSON_ = forall route.
TransactionsAPI route
-> route
   :- (Summary "Transaction metadata"
       :> (Description "Obtain the transaction metadata."
           :> (Capture "hash" TxHash
               :> ("metadata" :> Get '[JSON] [TransactionMetaJSON]))))
_txMetadataJSON forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *).
MonadBlockfrost m =>
Project -> TransactionsAPI (AsClientT m)
transactionsClient

-- | Get transaction metadata in JSON
getTxMetadataJSON :: MonadBlockfrost m => TxHash -> m [TransactionMetaJSON]
getTxMetadataJSON :: forall (m :: * -> *).
MonadBlockfrost m =>
TxHash -> m [TransactionMetaJSON]
getTxMetadataJSON TxHash
t = forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (forall (m :: * -> *).
MonadBlockfrost m =>
Project -> TxHash -> m [TransactionMetaJSON]
`getTxMetadataJSON_` TxHash
t)

getTxMetadataCBOR_ :: MonadBlockfrost m => Project -> TxHash -> m [TransactionMetaCBOR]
getTxMetadataCBOR_ :: forall (m :: * -> *).
MonadBlockfrost m =>
Project -> TxHash -> m [TransactionMetaCBOR]
getTxMetadataCBOR_ = forall route.
TransactionsAPI route
-> route
   :- (Summary "Transaction metadata in CBOR"
       :> (Description "Obtain the transaction metadata in CBOR."
           :> (Capture "hash" TxHash
               :> ("metadata" :> ("cbor" :> Get '[JSON] [TransactionMetaCBOR])))))
_txMetadataCBOR forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *).
MonadBlockfrost m =>
Project -> TransactionsAPI (AsClientT m)
transactionsClient

-- | Get transaction metadata in CBOR
getTxMetadataCBOR :: MonadBlockfrost m => TxHash -> m [TransactionMetaCBOR]
getTxMetadataCBOR :: forall (m :: * -> *).
MonadBlockfrost m =>
TxHash -> m [TransactionMetaCBOR]
getTxMetadataCBOR TxHash
t = forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (forall (m :: * -> *).
MonadBlockfrost m =>
Project -> TxHash -> m [TransactionMetaCBOR]
`getTxMetadataCBOR_` TxHash
t)

submitTx_ :: MonadBlockfrost m => Project -> CBORString -> m TxHash
submitTx_ :: forall (m :: * -> *).
MonadBlockfrost m =>
Project -> CBORString -> m TxHash
submitTx_ = forall route.
CardanoAPI route
-> route
   :- (Summary "Submit a transaction"
       :> (Description
             "Submit an already serialized transaction to the network."
           :> (Tag "Cardano \187 Transactions"
               :> ("tx"
                   :> ("submit"
                       :> (ReqBody '[CBOR] CBORString :> Post '[JSON] TxHash))))))
_txSubmit forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *).
MonadBlockfrost m =>
Project -> CardanoAPI (AsClientT m)
cardanoClient

-- | Submit an already serialized transaction to the network.
submitTx :: MonadBlockfrost m => CBORString -> m TxHash
submitTx :: forall (m :: * -> *). MonadBlockfrost m => CBORString -> m TxHash
submitTx CBORString
txCbor = forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (forall (m :: * -> *).
MonadBlockfrost m =>
Project -> CBORString -> m TxHash
`submitTx_` CBORString
txCbor)