Skip to content

Commit

Permalink
Bogus fixes for balance-tx
Browse files Browse the repository at this point in the history
  • Loading branch information
paolino committed Mar 21, 2024
1 parent 7324abd commit d5cfcef
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
22 changes: 12 additions & 10 deletions lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE UndecidableSuperClasses #-}

-- remove TODO node890
{-# OPTIONS_GHC -Wno-unused-imports #-}
{-# OPTIONS_GHC -Wno-unused-matches #-}
{-# OPTIONS_GHC -Wno-unused-local-binds #-}

-- |
-- Copyright: © 2022 IOHK
-- License: Apache-2.0
Expand Down Expand Up @@ -153,10 +158,6 @@ import Cardano.Crypto.Hash
import Cardano.Ledger.Allegra.Scripts
( translateTimelock
)
import Cardano.Ledger.Alonzo.Plutus.TxInfo
( EraPlutusContext
, ExtendedUTxO
)
import Cardano.Ledger.Alonzo.Scripts
( AlonzoScript (..)
)
Expand Down Expand Up @@ -344,11 +345,11 @@ type RecentEraConstraints era =
, Core.Tx era ~ Babbage.AlonzoTx era
, Core.Value era ~ Value
, Core.TxWits era ~ AlonzoTxWits era
, ExtendedUTxO era
-- , ExtendedUTxO era
, Alonzo.AlonzoEraPParams era
, Ledger.AlonzoEraTx era
, ScriptsNeeded era ~ AlonzoScriptsNeeded era
, EraPlutusContext 'PlutusV1 era
-- , EraPlutusContext 'PlutusV1 era
, Eq (TxOut era)
, Ledger.Crypto (Core.EraCrypto era)
, Show (TxOut era)
Expand Down Expand Up @@ -535,7 +536,7 @@ type ScriptHash = Core.ScriptHash StandardCrypto
type Value = MaryValue StandardCrypto

unsafeAddressFromBytes :: ByteString -> Address
unsafeAddressFromBytes bytes = case Ledger.deserialiseAddr bytes of
unsafeAddressFromBytes bytes = case Ledger.decodeAddr bytes of
Just addr -> addr
Nothing -> error "unsafeAddressFromBytes: failed to deserialise"

Expand Down Expand Up @@ -599,8 +600,8 @@ recentEraToBabbageTxOut (TxOutInRecentEra addr val datum mscript) =
castScript = \case
Alonzo.TimelockScript timelockEra ->
Alonzo.TimelockScript (translateTimelock timelockEra)
Alonzo.PlutusScript bs ->
Alonzo.PlutusScript bs
Alonzo.PlutusScript _bs ->
Alonzo.PlutusScript (error "TODO node890")

--
-- MinimumUTxO
Expand Down Expand Up @@ -804,7 +805,8 @@ evaluateMinimumFee pp tx kwc =
KeyWitnessCounts {nKeyWits, nBootstrapWits} = kwc

mainFee :: Coin
mainFee = Shelley.evaluateTransactionFee pp tx nKeyWits
mainFee = error "TODO node890"
-- Shelley.evaluateTransactionFee pp tx nKeyWits

FeePerByte feePerByte = getFeePerByte pp

Expand Down
22 changes: 9 additions & 13 deletions lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Redeemers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ module Internal.Cardano.Write.Tx.Redeemers

import Prelude

import Cardano.Ledger.Alonzo.Plutus.TxInfo
( TranslationError
)
import Cardano.Ledger.Api
( Tx
, bodyTxL
Expand Down Expand Up @@ -100,17 +97,16 @@ import Internal.Cardano.Write.Tx.TimeTranslation
, systemStartTime
)

import qualified Cardano.Ledger.Alonzo.PlutusScriptApi as Alonzo
import qualified Cardano.Ledger.Alonzo.Scripts as Alonzo
import qualified Cardano.Ledger.Alonzo.Tx as Alonzo
import qualified Cardano.Ledger.Alonzo.TxWits as Alonzo
import qualified Cardano.Ledger.Api as Ledger
import qualified Cardano.Ledger.Plutus.Data as Alonzo
import qualified Data.ByteString.Lazy as BL
import qualified Data.Map as Map
import qualified Data.Map.Merge.Strict as Map
import qualified Data.Set as Set
import qualified Data.Text as T
import qualified Cardano.Ledger.Api as Alonzo

data ErrAssignRedeemers
= ErrAssignRedeemersScriptFailure Redeemer String
Expand Down Expand Up @@ -150,7 +146,7 @@ assignScriptRedeemers pparams timeTranslation utxo redeemers tx = do
assignNullRedeemers
:: Tx era
-> Either ErrAssignRedeemers
( Map Alonzo.RdmrPtr Redeemer
( Map xxx Redeemer
, Tx era
)
assignNullRedeemers ledgerTx = do
Expand Down Expand Up @@ -180,10 +176,10 @@ assignScriptRedeemers pparams timeTranslation utxo redeemers tx = do
-- | Evaluate execution units of each script/redeemer in the transaction.
-- This may fail for each script.
evaluateExecutionUnits
:: Map Alonzo.RdmrPtr Redeemer
:: Map xxx Redeemer
-> Tx era
-> Either ErrAssignRedeemers
(Map Alonzo.RdmrPtr (Either ErrAssignRedeemers Alonzo.ExUnits))
(Map xxx (Either ErrAssignRedeemers Alonzo.ExUnits))
evaluateExecutionUnits indexedRedeemers ledgerTx =
Ledger.evalTxExUnits
pparams ledgerTx utxo epochInformation systemStart
Expand All @@ -193,16 +189,16 @@ assignScriptRedeemers pparams timeTranslation utxo redeemers tx = do

hoistScriptFailure
:: Show scriptFailure
=> Map Alonzo.RdmrPtr Redeemer
-> Map Alonzo.RdmrPtr (Either scriptFailure a)
-> Map Alonzo.RdmrPtr (Either ErrAssignRedeemers a)
=> Map xxx Redeemer
-> Map xxx (Either scriptFailure a)
-> Map xxx (Either ErrAssignRedeemers a)
hoistScriptFailure indexedRedeemers = Map.mapWithKey $ \ptr -> left $ \e ->
ErrAssignRedeemersScriptFailure (indexedRedeemers ! ptr) (show e)

-- | Change execution units for each redeemers in the transaction to what
-- they ought to be.
assignExecutionUnits
:: Map Alonzo.RdmrPtr (Either ErrAssignRedeemers Alonzo.ExUnits)
:: Map xxx (Either ErrAssignRedeemers Alonzo.ExUnits)
-> Tx era
-> Either ErrAssignRedeemers (Tx era)
assignExecutionUnits exUnits ledgerTx = do
Expand Down Expand Up @@ -273,7 +269,7 @@ redeemerData = \case
toScriptPurpose
:: IsRecentEra era
=> Redeemer
-> Alonzo.ScriptPurpose era
-> yyy era
toScriptPurpose = \case
RedeemerSpending _ txin ->
Alonzo.Spending txin
Expand Down

0 comments on commit d5cfcef

Please sign in to comment.