Skip to content

Commit 219f497

Browse files
committed
Use HTTP version of evaluateTx
1 parent 12896f5 commit 219f497

File tree

4 files changed

+30
-93
lines changed

4 files changed

+30
-93
lines changed

src/Internal/Contract/Provider.purs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import Ctl.Internal.Contract.LogParams (LogParams)
1616
import Ctl.Internal.Contract.ProviderBackend (BlockfrostBackend, CtlBackend)
1717
import Ctl.Internal.Helpers (logWithLevel)
1818
import Ctl.Internal.QueryM (QueryM)
19-
import Ctl.Internal.QueryM (evaluateTxOgmios) as QueryM
2019
import Ctl.Internal.QueryM.CurrentEpoch (getCurrentEpoch) as OgmiosHttp
2120
import Ctl.Internal.QueryM.EraSummaries (getEraSummaries) as OgmiosHttp
2221
import Ctl.Internal.QueryM.Kupo
@@ -30,7 +29,8 @@ import Ctl.Internal.QueryM.Kupo
3029
) as Kupo
3130
import Ctl.Internal.QueryM.Ogmios (SubmitTxR(SubmitFail, SubmitTxSuccess))
3231
import Ctl.Internal.QueryM.OgmiosHttp
33-
( getChainTip
32+
( evaluateTxOgmios
33+
, getChainTip
3434
, submitTxOgmios
3535
) as OgmiosHttp
3636
import Ctl.Internal.QueryM.Pools
@@ -78,10 +78,10 @@ providerForCtlBackend runQueryM params backend =
7878
"Computed TransactionHash is not equal to the one returned by Ogmios, please report as bug!"
7979
)
8080
SubmitFail err -> Left $ ClientOtherError $ show err
81-
, evaluateTx: \tx additionalUtxos -> unwrap <$>
81+
, evaluateTx: \tx additionalUtxos ->
8282
runQueryM' do
8383
let txBytes = encodeCbor tx
84-
QueryM.evaluateTxOgmios txBytes (wrap additionalUtxos)
84+
OgmiosHttp.evaluateTxOgmios txBytes (wrap additionalUtxos)
8585
, getEraSummaries: Right <$> runQueryM' OgmiosHttp.getEraSummaries
8686
, getPoolIds: Right <$> runQueryM' OgmiosHttp.getPoolIds
8787
, getPubKeyHashDelegationsAndRewards: \_ pubKeyHash ->

src/Internal/QueryM.purs

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ module Ctl.Internal.QueryM
66
( QueryM
77
, ParQueryM
88
, QueryMT(QueryMT)
9-
, evaluateTxOgmios
109
, handleAffjaxResponse
1110
) where
1211

@@ -19,7 +18,6 @@ import Cardano.Provider.Error
1918
( ClientError(ClientHttpError, ClientHttpResponseError, ClientDecodeJsonError)
2019
, ServiceError(ServiceOtherError)
2120
)
22-
import Cardano.Types.CborBytes (CborBytes)
2321
import Control.Alt (class Alt)
2422
import Control.Alternative (class Alternative)
2523
import Control.Monad.Error.Class (class MonadError, class MonadThrow)
@@ -30,20 +28,11 @@ import Control.Monad.Rec.Class (class MonadRec)
3028
import Control.Parallel (class Parallel, parallel, sequential)
3129
import Control.Plus (class Plus)
3230
import Ctl.Internal.Helpers (logWithLevel)
33-
import Ctl.Internal.Logging (mkLogger)
34-
import Ctl.Internal.QueryM.Ogmios (AdditionalUtxoSet, OgmiosTxEvaluationR)
35-
import Ctl.Internal.QueryM.Ogmios as Ogmios
36-
import Ctl.Internal.QueryM.OgmiosWebsocket.Mempool
37-
( listeners
38-
, mkRequestAff
39-
, underlyingWebSocket
40-
)
4131
import Ctl.Internal.QueryM.OgmiosWebsocket.Queries (QueryEnv)
4232
import Data.Bifunctor (lmap)
4333
import Data.Either (Either(Left, Right))
4434
import Data.Maybe (fromMaybe)
4535
import Data.Newtype (class Newtype, unwrap, wrap)
46-
import Data.Tuple.Nested ((/\))
4736
import Effect.Aff (Aff, ParAff)
4837
import Effect.Aff.Class (class MonadAff, liftAff)
4938
import Effect.Class (class MonadEffect)
@@ -101,25 +90,6 @@ instance Parallel (QueryMT ParAff) (QueryMT Aff) where
10190
sequential :: QueryMT ParAff ~> QueryMT Aff
10291
sequential = wrap <<< sequential <<< unwrap
10392

104-
--------------------------------------------------------------------------------
105-
-- Ogmios Local Tx Submission Protocol
106-
--------------------------------------------------------------------------------
107-
108-
evaluateTxOgmios
109-
:: CborBytes -> AdditionalUtxoSet -> QueryM OgmiosTxEvaluationR
110-
evaluateTxOgmios cbor additionalUtxos = do
111-
ws <- asks $ underlyingWebSocket <<< _.ogmiosWs <<< _.runtime
112-
listeners' <- asks $ listeners <<< _.ogmiosWs <<< _.runtime
113-
cfg <- asks _.config
114-
liftAff $ mkRequestAff listeners' ws (mkLogger cfg.logLevel cfg.customLogger)
115-
Ogmios.evaluateTxCall
116-
_.evaluate
117-
(cbor /\ additionalUtxos)
118-
119-
--------------------------------------------------------------------------------
120-
-- Ogmios Local Tx Monitor Protocol
121-
--------------------------------------------------------------------------------
122-
12393
--------------------------------------------------------------------------------
12494
-- Affjax
12595
--------------------------------------------------------------------------------

src/Internal/QueryM/Ogmios.purs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ module Ctl.Internal.QueryM.Ogmios
2525
, MaybeMempoolTransaction(MaybeMempoolTransaction)
2626
, OgmiosTxEvaluationR(OgmiosTxEvaluationR)
2727
, aesonObject
28-
, aesonArray
29-
, evaluateTxCall
3028
, submitSuccessPartialResp
3129
, parseIpv6String
3230
, rationalToSubcoin
@@ -84,7 +82,6 @@ import Cardano.Types
8482
import Cardano.Types.AssetName (unAssetName)
8583
import Cardano.Types.BigNum (BigNum)
8684
import Cardano.Types.BigNum (fromBigInt, fromString) as BigNum
87-
import Cardano.Types.CborBytes (CborBytes)
8885
import Cardano.Types.Coin (Coin(Coin))
8986
import Cardano.Types.CostModel (CostModel(CostModel))
9087
import Cardano.Types.Ed25519KeyHash (Ed25519KeyHash)
@@ -131,12 +128,9 @@ import Control.Alternative (guard)
131128
import Ctl.Internal.Helpers (encodeMap, showWithParens)
132129
import Ctl.Internal.QueryM.JsonRpc2
133130
( class DecodeOgmios
134-
, JsonRpc2Call
135-
, JsonRpc2Request
136131
, OgmiosError
137132
, decodeErrorOrResult
138133
, decodeResult
139-
, mkCallType
140134
)
141135
import Ctl.Internal.Types.ProtocolParameters
142136
( ProtocolParameters(ProtocolParameters)
@@ -178,37 +172,8 @@ import JS.BigInt as BigInt
178172
import Untagged.TypeCheck (class HasRuntimeType)
179173
import Untagged.Union (type (|+|), toEither1)
180174

181-
--------------------------------------------------------------------------------
182-
-- Local Tx Submission Protocol
183-
-- https://ogmios.dev/mini-protocols/local-tx-submission/
184175
--------------------------------------------------------------------------------
185176

186-
-- | Evaluates the execution units of scripts present in a given transaction,
187-
-- | without actually submitting the transaction.
188-
evaluateTxCall
189-
:: JsonRpc2Call (CborBytes /\ AdditionalUtxoSet) OgmiosTxEvaluationR
190-
evaluateTxCall = mkOgmiosCallType
191-
{ method: "evaluateTransaction"
192-
, params: \(cbor /\ utxoqr) ->
193-
{ transaction: { cbor: byteArrayToHex $ unwrap cbor }
194-
, additionalUtxo: utxoqr
195-
}
196-
}
197-
198-
--------------------------------------------------------------------------------
199-
-- Helpers
200-
--------------------------------------------------------------------------------
201-
202-
mkOgmiosCallType
203-
:: forall (a :: Type) (i :: Type) (o :: Type)
204-
. EncodeAeson (JsonRpc2Request a)
205-
=> DecodeOgmios o
206-
=> { method :: String, params :: i -> a }
207-
-> JsonRpc2Call i o
208-
mkOgmiosCallType =
209-
mkCallType { jsonrpc: "2.0" }
210-
211-
--------------------------------------------------------------------------------
212177
-- Local Tx Monitor Query Response & Parsing
213178
--------------------------------------------------------------------------------
214179

src/Internal/QueryM/OgmiosHttp.purs

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module Ctl.Internal.QueryM.OgmiosHttp
99
, delegationsAndRewards
1010
, eraSummaries
1111
, getProtocolParameters
12-
-- , evaluateTxOgmios
12+
, evaluateTxOgmios
1313
) where
1414

1515
import Prelude
@@ -104,11 +104,13 @@ import Ctl.Internal.QueryM.JsonRpc2
104104
, pprintOgmiosDecodeError
105105
)
106106
import Ctl.Internal.QueryM.Ogmios
107-
( CurrentEpoch
107+
( AdditionalUtxoSet
108+
, CurrentEpoch
108109
, DelegationsAndRewardsR(DelegationsAndRewardsR)
109110
, OgmiosEraSummaries
110111
, OgmiosProtocolParameters
111112
, OgmiosSystemStart
113+
, OgmiosTxEvaluationR
112114
, PoolParametersR
113115
, SubmitTxR
114116
) as Ogmios
@@ -272,28 +274,28 @@ delegationsAndRewards rewardAccounts = do
272274
}
273275
)
274276

275-
-- evaluateTxOgmios
276-
-- :: CborBytes -> AdditionalUtxoSet -> QueryM Provider.TxEvaluationR
277-
-- evaluateTxOgmios cbor additionalUtxos = ogmiosErrorHandlerWithArg
278-
-- evaluateTx
279-
-- (cbor /\ additionalUtxos)
280-
-- where
281-
-- evaluateTx
282-
-- :: CborBytes /\ AdditionalUtxoSet
283-
-- -> Aff (Either OgmiosDecodeError Provider.TxEvaluationR)
284-
-- evaluateTx (cbor /\ utxoqr) = do
285-
-- handleAffjaxOgmiosResponse <$>
286-
-- ( ogmiosPostRequest
287-
-- $ Aeson.encodeAeson
288-
-- { jsonrpc: "2.0"
289-
-- , id: "evaluateTxOgmios"
290-
-- , method: "evaluateTransaction"
291-
-- , params:
292-
-- { transaction: { cbor: byteArrayToHex $ unwrap cbor }
293-
-- , additionalUtxo: utxoqr
294-
-- }
295-
-- }
296-
-- )
277+
evaluateTxOgmios
278+
:: CborBytes -> Ogmios.AdditionalUtxoSet -> QueryM Provider.TxEvaluationR
279+
evaluateTxOgmios cbor additionalUtxos = unwrap <$> ogmiosErrorHandlerWithArg
280+
evaluateTx
281+
(cbor /\ additionalUtxos)
282+
where
283+
evaluateTx
284+
:: CborBytes /\ Ogmios.AdditionalUtxoSet
285+
-> QueryM (Either OgmiosDecodeError Ogmios.OgmiosTxEvaluationR)
286+
evaluateTx (cbor_ /\ utxoqr) = do
287+
handleAffjaxOgmiosResponse <$>
288+
( ogmiosPostRequest
289+
$ Aeson.encodeAeson
290+
{ jsonrpc: "2.0"
291+
, id: "evaluateTxOgmios"
292+
, method: "evaluateTransaction"
293+
, params:
294+
{ transaction: { cbor: byteArrayToHex $ unwrap cbor_ }
295+
, additionalUtxo: utxoqr
296+
}
297+
}
298+
)
297299

298300
instance DecodeOgmios TxEvaluationR where
299301
decodeOgmios = decodeErrorOrResult

0 commit comments

Comments
 (0)