Skip to content

Commit 2bfc2b4

Browse files
committed
gRPC: Add evalTx method
1 parent c718268 commit 2bfc2b4

25 files changed

Lines changed: 1251 additions & 669 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
project: cardano-api
2+
pr: 1193
3+
kind:
4+
- compatible
5+
description: |
6+
Export `evaluateTransactionExecutionUnits` from `Cardano.Api.Experimental`. Re-export `EraTxBody(..)` from `Cardano.Api.Ledger`.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
project: cardano-rpc
2+
pr: 1193
3+
kind:
4+
- feature
5+
description: |
6+
Add evalTx gRPC method to the UTxO RPC submit service, evaluating a CBOR-serialised transaction against the current ledger state and returning per-redeemer execution units, computed minimum fee, script evaluation errors, and balance check results without submitting.

cardano-api/src/Cardano/Api/Experimental.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ module Cardano.Api.Experimental
2020
, EraCommonConstraints
2121
, obtainConwayConstraints
2222
, obtainCommonConstraints
23+
, eraProtVerHigh
2324
, hashTxBody
25+
, evaluateTransactionExecutionUnits
2426
, evaluateTransactionExecutionUnitsShelley
2527
, AnchorDataFromCertificateError (..)
2628
, getAnchorDataFromCertificate

cardano-api/src/Cardano/Api/Experimental/Era.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
{-# LANGUAGE RankNTypes #-}
1111
{-# LANGUAGE ScopedTypeVariables #-}
1212
{-# LANGUAGE StandaloneDeriving #-}
13+
{-# LANGUAGE TypeApplications #-}
1314
{-# LANGUAGE TypeFamilyDependencies #-}
1415
{-# LANGUAGE TypeOperators #-}
1516

@@ -26,6 +27,7 @@ module Cardano.Api.Experimental.Era
2627
, DeprecatedEra (..)
2728
, EraCommonConstraints
2829
, obtainCommonConstraints
30+
, eraProtVerHigh
2931
, obtainConwayConstraints
3032
, eraToSbe
3133
, eraToBabbageEraOnwards
@@ -338,3 +340,8 @@ type EraConwayConstraints =
338340
, L.ShelleyEraTxCert (LedgerEra ConwayEra)
339341
, L.NativeScript (ShelleyLedgerEra ConwayEra) ~ L.Timelock (ShelleyLedgerEra ConwayEra)
340342
)
343+
344+
-- | Lookup the lower major protocol version for the era. In other words
345+
-- this is the major protocol version that the era has started in.
346+
eraProtVerHigh :: forall era. Era era -> L.Version
347+
eraProtVerHigh eon = obtainCommonConstraints eon $ L.eraProtVerHigh @(LedgerEra era)

cardano-api/src/Cardano/Api/Experimental/Tx.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ import Cardano.Api.Tx.Internal.Body qualified as Api
239239
import Cardano.Api.Tx.Internal.Sign
240240

241241
import Cardano.Crypto.Hash qualified as Hash
242-
import Cardano.Ledger.Alonzo.Tx qualified as L
243242
import Cardano.Ledger.Api qualified as L
244243
import Cardano.Ledger.Binary qualified as Ledger
245244
import Cardano.Ledger.Core qualified as Ledger

cardano-api/src/Cardano/Api/Experimental/Tx/Internal/BodyContent/New.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ import Cardano.Ledger.Alonzo.Tx qualified as L
145145
import Cardano.Ledger.Alonzo.TxBody qualified as L
146146
import Cardano.Ledger.Alonzo.TxWits qualified as L
147147
import Cardano.Ledger.Api qualified as L
148-
import Cardano.Ledger.Core qualified as L
149148
import Cardano.Ledger.Core qualified as Ledger
150149
import Cardano.Ledger.Plutus.Language (PlutusBinary (..), plutusLanguage)
151150
import Cardano.Ledger.Plutus.Language qualified as Plutus

cardano-api/src/Cardano/Api/Experimental/Tx/Internal/Fee.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ import Cardano.Ledger.Alonzo.Core qualified as Ledger
7171
import Cardano.Ledger.Api qualified as L
7272
import Cardano.Ledger.Coin qualified as L
7373
import Cardano.Ledger.Conway.Governance qualified as L
74-
import Cardano.Ledger.Core qualified as L
7574
import Cardano.Ledger.Credential as Ledger (Credential)
7675
import Cardano.Ledger.Val qualified as L
7776

cardano-api/src/Cardano/Api/Ledger/Internal/Reexport.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ module Cardano.Api.Ledger.Internal.Reexport
164164
, AsIxItem (..)
165165
, EraGov
166166
, EraTx (witsTxL, bodyTxL)
167+
, EraTxBody (..)
168+
, TopTx
167169
, Tx
168170
, TxDats (..)
169171
, costModelsValid
@@ -345,9 +347,11 @@ import Cardano.Ledger.Conway.TxCert
345347
import Cardano.Ledger.Core
346348
( Era (..)
347349
, EraPParams (..)
350+
, EraTxBody (..)
348351
, EraTxOut
349352
, PParams (..)
350353
, PoolCert (..)
354+
, TopTx
351355
, TxOut
352356
, Value
353357
, fromEraCBOR

cardano-api/src/Cardano/Api/Tx/Internal/Fee.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ import Cardano.Ledger.Alonzo.Scripts qualified as Alonzo
8686
import Cardano.Ledger.Api qualified as L
8787
import Cardano.Ledger.Coin qualified as L
8888
import Cardano.Ledger.Conway.Governance qualified as L
89-
import Cardano.Ledger.Core qualified as L
9089
import Cardano.Ledger.Credential as Ledger (Credential)
9190
import Cardano.Ledger.Plutus.Language qualified as Plutus
9291
import Ouroboros.Consensus.HardFork.History qualified as Consensus

cardano-api/src/Cardano/Api/Tx/Internal/Output.hs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ import Cardano.Ledger.Alonzo.Core qualified as L
8585
import Cardano.Ledger.Api qualified as L
8686
import Cardano.Ledger.BaseTypes (StrictMaybe (..))
8787
import Cardano.Ledger.Coin qualified as L
88-
import Cardano.Ledger.Core qualified as Core
89-
import Cardano.Ledger.Core qualified as Ledger
9088
import Cardano.Ledger.Plutus.Data qualified as Plutus
9189

9290
import Data.Aeson (object, withObject, (.:), (.:?), (.=))
@@ -186,13 +184,13 @@ convTxOuts
186184
=> ShelleyLedgerEra era ~ ledgerera
187185
=> ShelleyBasedEra era
188186
-> [TxOut ctx era]
189-
-> Seq.StrictSeq (Ledger.TxOut ledgerera)
187+
-> Seq.StrictSeq (L.TxOut ledgerera)
190188
convTxOuts sbe txOuts = fromList $ map (toShelleyTxOutAny sbe) txOuts
191189

192190
fromLedgerTxOuts
193191
:: forall era
194192
. ShelleyBasedEra era
195-
-> Ledger.TxBody Ledger.TopTx (ShelleyLedgerEra era)
193+
-> L.TxBody L.TopTx (ShelleyLedgerEra era)
196194
-> TxBodyScriptData era
197195
-> [TxOut CtxTx era]
198196
fromLedgerTxOuts sbe body scriptdata =
@@ -792,7 +790,7 @@ toShelleyTxOut
792790
=> ShelleyLedgerEra era ~ ledgerera
793791
=> ShelleyBasedEra era
794792
-> TxOut CtxUTxO era
795-
-> Ledger.TxOut ledgerera
793+
-> L.TxOut ledgerera
796794
toShelleyTxOut sbe = shelleyBasedEraConstraints sbe $ \case
797795
TxOut addr (TxOutValueShelleyBased _ value) txoutdata refScript ->
798796
caseShelleyToMaryOrAlonzoEraOnwards
@@ -826,7 +824,7 @@ toShelleyTxOutAny
826824
=> ShelleyLedgerEra era ~ ledgerera
827825
=> ShelleyBasedEra era
828826
-> TxOut ctx era
829-
-> Ledger.TxOut ledgerera
827+
-> L.TxOut ledgerera
830828
toShelleyTxOutAny sbe = shelleyBasedEraConstraints sbe $ \case
831829
TxOut addr (TxOutValueShelleyBased _ value) txoutdata refScript ->
832830
caseShelleyToMaryOrAlonzoEraOnwards
@@ -855,7 +853,7 @@ fromShelleyTxOut
855853
:: forall era ctx
856854
. ()
857855
=> ShelleyBasedEra era
858-
-> Core.TxOut (ShelleyLedgerEra era)
856+
-> L.TxOut (ShelleyLedgerEra era)
859857
-> TxOut ctx era
860858
fromShelleyTxOut sbe ledgerTxOut = shelleyBasedEraConstraints sbe $ do
861859
let txOutValue = TxOutValueShelleyBased sbe $ ledgerTxOut ^. A.valueTxOutL sbe
@@ -920,8 +918,8 @@ data TxOutValue era where
920918
:: L.Coin
921919
-> TxOutValue ByronEra
922920
TxOutValueShelleyBased
923-
:: ( Eq (Ledger.Value (ShelleyLedgerEra era))
924-
, Show (Ledger.Value (ShelleyLedgerEra era))
921+
:: ( Eq (L.Value (ShelleyLedgerEra era))
922+
, Show (L.Value (ShelleyLedgerEra era))
925923
)
926924
=> ShelleyBasedEra era
927925
-> L.Value (ShelleyLedgerEra era)

0 commit comments

Comments
 (0)