Skip to content

Commit

Permalink
Remove unused function fromLedgerScript
Browse files Browse the repository at this point in the history
  • Loading branch information
locallycompact committed Dec 8, 2024
1 parent 708f682 commit 1fc4d84
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 43 deletions.
18 changes: 0 additions & 18 deletions hydra-cardano-api/src/Hydra/Cardano/Api/PlutusScript.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,12 @@ module Hydra.Cardano.Api.PlutusScript where

import Hydra.Cardano.Api.Prelude

import Cardano.Ledger.Alonzo.Scripts qualified as Ledger
import Cardano.Ledger.Plutus.Language qualified as Ledger
import Data.ByteString.Short qualified as SBS
import PlutusLedgerApi.Common qualified as Plutus
import Test.QuickCheck (listOf)

-- * Type Conversions

-- | Convert a cardano-ledger 'Script' into a cardano-api 'PlutusScript'
--
-- NOTE: This function is unsafe in two manners:
--
-- (a) If the given script is a timelock script, it throws an impure exception;
-- (b) If the given script is in a wrong language, it silently coerces it.
fromLedgerScript ::
( HasCallStack
, Ledger.AlonzoEraScript era
) =>
Ledger.AlonzoScript era ->
PlutusScript lang
fromLedgerScript = \case
Ledger.TimelockScript{} -> error "fromLedgerScript: TimelockScript"
Ledger.PlutusScript x -> Ledger.withPlutusScript x (\(Ledger.Plutus (Ledger.PlutusBinary bytes)) -> PlutusScriptSerialised bytes)

-- | Convert a serialized plutus script into a cardano-api 'PlutusScript'.
fromPlutusScript :: Plutus.SerialisedScript -> PlutusScript lang
fromPlutusScript =
Expand Down
25 changes: 0 additions & 25 deletions hydra-cardano-api/src/Hydra/Cardano/Api/TxBody.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ import Cardano.Ledger.Api (
)
import Cardano.Ledger.Babbage.Core (redeemerPointer)
import Cardano.Ledger.BaseTypes (strictMaybeToMaybe)
import Cardano.Ledger.Core qualified as Ledger
import Cardano.Ledger.Plutus.Data qualified as Ledger
import Data.List (find)
import Data.Map qualified as Map
import Hydra.Cardano.Api.PlutusScript (fromLedgerScript)
import Hydra.Cardano.Api.PolicyId (toLedgerPolicyID, toLedgerScriptHash)
import Hydra.Cardano.Api.TxIn (toLedgerTxIn)
import PlutusLedgerApi.V3 qualified as Plutus

Expand All @@ -31,27 +27,6 @@ findRedeemerSpending (getTxBody -> ShelleyTxBody _ body _ scriptData _ _) txIn =
ptr <- strictMaybeToMaybe $ redeemerPointer body (ConwaySpending . AsItem $ toLedgerTxIn txIn)
lookupRedeemer ptr scriptData

findRedeemerMinting ::
Plutus.FromData a =>
Tx Era ->
PolicyId ->
Maybe a
findRedeemerMinting (getTxBody -> ShelleyTxBody _ body _ scriptData _ _) pid = do
ptr <- strictMaybeToMaybe $ redeemerPointer body (ConwayMinting . AsItem $ toLedgerPolicyID pid)
lookupRedeemer ptr scriptData

findScriptMinting ::
forall lang.
() =>
Tx Era ->
PolicyId ->
Maybe (PlutusScript lang)
findScriptMinting (getTxBody -> ShelleyTxBody _ _ scripts _ _ _) pid = do
fromLedgerScript @_ @lang
<$> find ((== needle) . Ledger.hashScript @(ShelleyLedgerEra Era)) scripts
where
needle = toLedgerScriptHash pid

--
-- Internals
--
Expand Down

0 comments on commit 1fc4d84

Please sign in to comment.