@@ -4,96 +4,29 @@ module Ctl.Internal.Contract.Provider
44 , providerForSelfHostedBlockfrostBackend
55 ) where
66
7- import Prelude
8-
9- import Cardano.AsCbor (encodeCbor )
107import Cardano.Blockfrost.BlockfrostBackend (BlockfrostBackend )
118import Cardano.Blockfrost.Provider (providerForBlockfrostBackend ) as Blockfrost
12- import Cardano.Blockfrost.Service
13- ( BlockfrostServiceM
14- , runBlockfrostServiceM
15- )
16- import Cardano.Kupmios.Kupo
17- ( getDatumByHash
18- , getOutputAddressesByTxHash
19- , getScriptByHash
20- , getTxAuxiliaryData
21- , getUtxoByOref
22- , isTxConfirmed
23- , utxosAt
24- ) as Kupo
25- import Cardano.Kupmios.Ogmios
26- ( evaluateTxOgmios
27- , getChainTip
28- , submitTxOgmios
29- ) as Ogmios
30- import Cardano.Kupmios.Ogmios.CurrentEpoch (getCurrentEpoch ) as Ogmios
31- import Cardano.Kupmios.Ogmios.EraSummaries (getEraSummaries ) as Ogmios
32- import Cardano.Kupmios.Ogmios.Pools
33- ( getPoolIds
34- , getPubKeyHashDelegationsAndRewards
35- , getValidatorHashDelegationsAndRewards
36- ) as Ogmios
37- import Cardano.Kupmios.Ogmios.Types (SubmitTxR (SubmitFail, SubmitTxSuccess))
38- import Cardano.Kupmios.QueryM (QueryM )
39- import Cardano.Provider.Error (ClientError (ClientOtherError))
9+ import Cardano.Blockfrost.Service (BlockfrostServiceM , runBlockfrostServiceM )
10+ import Cardano.Kupmios.KupmiosM (KupmiosM )
11+ import Cardano.Kupmios.Provider as Kupmios
4012import Cardano.Provider.Type (Provider )
41- import Cardano.Types.Transaction (hash ) as Transaction
42- import Contract.Log (logDebug' )
4313import Ctl.Internal.Contract.LogParams (LogParams )
4414import Ctl.Internal.Contract.ProviderBackend (CtlBackend )
4515import Ctl.Internal.Helpers (logWithLevel )
46- import Data.Either (Either (Left, Right))
47- import Data.Maybe (fromMaybe , isJust )
48- import Data.Newtype (unwrap , wrap )
16+ import Data.Maybe (fromMaybe )
4917import Effect.Aff (Aff )
5018
5119providerForCtlBackend
5220 :: forall rest
53- . (forall (a :: Type ). LogParams rest -> CtlBackend -> QueryM a -> Aff a )
21+ . (forall (a :: Type ). LogParams rest -> CtlBackend -> KupmiosM a -> Aff a )
5422 -> LogParams rest
5523 -> CtlBackend
5624 -> Provider
57- providerForCtlBackend runQueryM params backend =
58- { getDatumByHash: runQueryM' <<< Kupo .getDatumByHash
59- , getScriptByHash: runQueryM' <<< Kupo .getScriptByHash
60- , getUtxoByOref: runQueryM' <<< Kupo .getUtxoByOref
61- , getOutputAddressesByTxHash: runQueryM' <<< Kupo .getOutputAddressesByTxHash
62- , doesTxExist: runQueryM' <<< map (map isJust) <<< Kupo .isTxConfirmed
63- , getTxAuxiliaryData: runQueryM' <<< Kupo .getTxAuxiliaryData
64- , utxosAt: runQueryM' <<< Kupo .utxosAt
65- , getChainTip: Right <$> runQueryM' Ogmios .getChainTip
66- , getCurrentEpoch: unwrap <$> runQueryM' Ogmios .getCurrentEpoch
67- , submitTx: \tx -> runQueryM' do
68- let txHash = Transaction .hash tx
69- logDebug' $ " Pre-calculated tx hash: " <> show txHash
70- let txCborBytes = encodeCbor tx
71- result <- Ogmios .submitTxOgmios txHash txCborBytes
72- pure $ case result of
73- SubmitTxSuccess th -> do
74- if th == txHash then Right th
75- else Left
76- ( ClientOtherError
77- " Computed TransactionHash is not equal to the one returned by Ogmios, please report as bug!"
78- )
79- SubmitFail err -> Left $ ClientOtherError $ show err
80- , evaluateTx: \tx additionalUtxos ->
81- runQueryM' do
82- let txBytes = encodeCbor tx
83- Ogmios .evaluateTxOgmios txBytes (wrap additionalUtxos)
84- , getEraSummaries: Right <$> runQueryM' Ogmios .getEraSummaries
85- , getPoolIds: Right <$> runQueryM' Ogmios .getPoolIds
86- , getPubKeyHashDelegationsAndRewards: \_ pubKeyHash ->
87- Right <$> runQueryM'
88- (Ogmios .getPubKeyHashDelegationsAndRewards pubKeyHash)
89- , getValidatorHashDelegationsAndRewards: \_ validatorHash ->
90- Right <$> runQueryM'
91- (Ogmios .getValidatorHashDelegationsAndRewards $ wrap validatorHash)
92- }
93-
25+ providerForCtlBackend runKupmiosM params backend =
26+ Kupmios .providerForKupmiosBackend runKupmiosM'
9427 where
95- runQueryM ' :: forall (a :: Type ). QueryM a -> Aff a
96- runQueryM ' = runQueryM params backend
28+ runKupmiosM ' :: forall (a :: Type ). KupmiosM a -> Aff a
29+ runKupmiosM ' = runKupmiosM params backend
9730
9831providerForBlockfrostBackend
9932 :: forall rest . LogParams rest -> BlockfrostBackend -> Provider
@@ -109,18 +42,18 @@ providerForSelfHostedBlockfrostBackend
10942 :: forall rest
11043 . LogParams rest
11144 -> BlockfrostBackend
112- -> (forall (a :: Type ). LogParams rest -> CtlBackend -> QueryM a -> Aff a )
45+ -> (forall (a :: Type ). LogParams rest -> CtlBackend -> KupmiosM a -> Aff a )
11346 -> CtlBackend
11447 -> Provider
11548providerForSelfHostedBlockfrostBackend
11649 params
11750 blockfrostBackend
118- runQueryM
51+ runKupmiosM
11952 ctlBackend =
12053 let
12154 blockfrostProvider = providerForBlockfrostBackend params
12255 blockfrostBackend
123- ctlProvider = providerForCtlBackend runQueryM params ctlBackend
56+ ctlProvider = providerForCtlBackend runKupmiosM params ctlBackend
12457 in
12558 blockfrostProvider
12659 { evaluateTx = ctlProvider.evaluateTx
0 commit comments