Skip to content

Commit

Permalink
Import plutus-script-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
locallycompact committed Sep 30, 2024
1 parent fdc85ed commit 30ec6db
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 43 deletions.
10 changes: 10 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,13 @@ benchmarks: True

-- Always show detailed output for tests
test-show-details: direct

source-repository-package
type: git
location: https://github.com/IntersectMBO/cardano-node-emulator
tag: 20f3faf2ef9ca97edcdb7b037507b35a5d76673b
--sha256: sha256-bhaJsWqjhojpbwxLX1+vVPSPz86tbhDcBUHk6M1HPzU=
subdir:
plutus-script-utils
plutus-ledger

32 changes: 2 additions & 30 deletions hydra-plutus-extras/src/Hydra/Plutus/Extras.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,17 @@ import Cardano.Api (
import Cardano.Api.Shelley (PlutusScript (PlutusScriptSerialised))
import PlutusLedgerApi.Common (SerialisedScript)
import PlutusLedgerApi.V2 (ScriptHash (..))
import PlutusTx (BuiltinData, UnsafeFromData (..))
import PlutusTx.Prelude (BuiltinUnit, check, toBuiltin)
import PlutusTx (BuiltinData)
import PlutusTx.Prelude (BuiltinUnit, toBuiltin)

-- * Vendored from plutus-ledger

-- | Signature of an untyped validator script.
type ValidatorType = BuiltinData -> BuiltinData -> BuiltinData -> BuiltinUnit

-- | Wrap a typed validator to get the basic `ValidatorType` signature which can
-- be passed to `PlutusTx.compile`.
-- REVIEW: There might be better ways to name this than "wrap"
mkUntypedValidator ::
(UnsafeFromData datum, UnsafeFromData redeemer, UnsafeFromData context) =>
(datum -> redeemer -> context -> Bool) ->
ValidatorType
mkUntypedValidator f d r c =
check $ f datum redeemer context
where
datum = unsafeFromBuiltinData d
redeemer = unsafeFromBuiltinData r
context = unsafeFromBuiltinData c
{-# INLINEABLE mkUntypedValidator #-}

-- | Signature of an untyped minting policy script.
type MintingPolicyType = BuiltinData -> BuiltinData -> BuiltinUnit

-- | Wrap a typed minting policy to get the basic `MintingPolicyType` signature
-- which can be passed to `PlutusTx.compile`.
mkUntypedMintingPolicy ::
(UnsafeFromData redeemer, UnsafeFromData context) =>
(redeemer -> context -> Bool) ->
MintingPolicyType
mkUntypedMintingPolicy f r c =
check $ f redeemer context
where
redeemer = unsafeFromBuiltinData r
context = unsafeFromBuiltinData c
{-# INLINEABLE mkUntypedMintingPolicy #-}

-- * Similar utilities as plutus-ledger

-- | Compute the on-chain 'ScriptHash' for a given serialised plutus script. Use
Expand Down
1 change: 1 addition & 0 deletions hydra-plutus/hydra-plutus.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ library
, hydra-prelude
, plutus-core ^>=1.30
, plutus-ledger-api ^>=1.30
, plutus-script-utils
, plutus-tx ^>=1.30
, plutus-tx-plugin ^>=1.30
, QuickCheck
Expand Down
5 changes: 3 additions & 2 deletions hydra-plutus/src/Hydra/Contract/Commit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import Hydra.Cardano.Api.Network (Network)
import Hydra.Contract.CommitError (CommitError (..), errorCode)
import Hydra.Contract.Util (hasST, mustBurnST)
import Hydra.Data.Party (Party)
import Hydra.Plutus.Extras (ValidatorType, mkUntypedValidator, scriptValidatorHash)
import Hydra.Plutus.Extras (ValidatorType, scriptValidatorHash)
import Hydra.ScriptContext (ScriptContext (..), TxInfo (..))
import Plutus.Script.Utils.Typed (mkUntypedValidator)
import PlutusLedgerApi.V2 (
CurrencySymbol,
Datum (..),
Expand Down Expand Up @@ -111,7 +112,7 @@ compiledValidator :: CompiledCode ValidatorType
compiledValidator =
$$(PlutusTx.compile [||wrap validator||])
where
wrap = mkUntypedValidator @DatumType @RedeemerType
wrap = mkUntypedValidator @ScriptContext @DatumType @RedeemerType

validatorScript :: SerialisedScript
validatorScript = serialiseCompiledCode compiledValidator
Expand Down
5 changes: 3 additions & 2 deletions hydra-plutus/src/Hydra/Contract/Deposit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import Hydra.Contract.DepositError (
)
import Hydra.Contract.Error (errorCode)
import Hydra.Contract.Head (hashPreSerializedCommits, hashTxOuts)
import Hydra.Plutus.Extras (ValidatorType, mkUntypedValidator, scriptValidatorHash)
import Hydra.Plutus.Extras (ValidatorType, scriptValidatorHash)
import Plutus.Script.Utils.Typed (mkUntypedValidator)
import PlutusLedgerApi.V2 (
CurrencySymbol,
Datum (Datum),
Expand Down Expand Up @@ -91,7 +92,7 @@ compiledValidator :: CompiledCode ValidatorType
compiledValidator =
$$(PlutusTx.compile [||wrap validator||])
where
wrap = mkUntypedValidator @DepositDatum @DepositRedeemer
wrap = mkUntypedValidator @ScriptContext @DepositDatum @DepositRedeemer

validatorScript :: SerialisedScript
validatorScript = serialiseCompiledCode compiledValidator
Expand Down
5 changes: 3 additions & 2 deletions hydra-plutus/src/Hydra/Contract/Hash.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import PlutusTx.Prelude
import Hydra.Prelude qualified as Haskell

import Hydra.Cardano.Api (PlutusScriptVersion (PlutusScriptV2))
import Hydra.Plutus.Extras (ValidatorType, mkUntypedValidator, scriptValidatorHash)
import Hydra.Plutus.Extras (ValidatorType, scriptValidatorHash)
import Plutus.Script.Utils.Typed (mkUntypedValidator)
import PlutusLedgerApi.Common (SerialisedScript, serialiseCompiledCode)
import PlutusLedgerApi.V2 (
Datum (Datum),
Expand Down Expand Up @@ -54,7 +55,7 @@ compiledValidator :: CompiledCode ValidatorType
compiledValidator =
$$(PlutusTx.compile [||wrap validator||])
where
wrap = mkUntypedValidator @DatumType @RedeemerType
wrap = mkUntypedValidator @ScriptContext @DatumType @RedeemerType

validatorScript :: SerialisedScript
validatorScript = serialiseCompiledCode compiledValidator
Expand Down
5 changes: 3 additions & 2 deletions hydra-plutus/src/Hydra/Contract/Head.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import Hydra.Contract.HeadState (CloseRedeemer (..), ClosedDatum (..), ContestRe
import Hydra.Contract.Util (hasST, mustBurnAllHeadTokens, mustNotMintOrBurn, (===))
import Hydra.Data.ContestationPeriod (ContestationPeriod, addContestationPeriod, milliseconds)
import Hydra.Data.Party (Party (vkey))
import Hydra.Plutus.Extras (ValidatorType, mkUntypedValidator, scriptValidatorHash)
import Hydra.Plutus.Extras (ValidatorType, scriptValidatorHash)
import Plutus.Script.Utils.Typed (mkUntypedValidator)
import PlutusLedgerApi.Common (SerialisedScript, serialiseCompiledCode)
import PlutusLedgerApi.V1.Time (fromMilliSeconds)
import PlutusLedgerApi.V1.Value (valueOf)
Expand Down Expand Up @@ -687,7 +688,7 @@ compiledValidator :: CompiledCode ValidatorType
compiledValidator =
$$(PlutusTx.compile [||wrap headValidator||])
where
wrap = mkUntypedValidator @DatumType @RedeemerType
wrap = mkUntypedValidator @ScriptContext @DatumType @RedeemerType

validatorScript :: SerialisedScript
validatorScript = serialiseCompiledCode compiledValidator
Expand Down
3 changes: 2 additions & 1 deletion hydra-plutus/src/Hydra/Contract/HeadTokens.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ import Hydra.Contract.HeadTokensError (HeadTokensError (..), errorCode)
import Hydra.Contract.Initial qualified as Initial
import Hydra.Contract.MintAction (MintAction (Burn, Mint))
import Hydra.Contract.Util (hasST)
import Hydra.Plutus.Extras (MintingPolicyType, mkUntypedMintingPolicy)
import Hydra.Plutus.Extras (MintingPolicyType)
import Hydra.ScriptContext (ScriptContext (..), TxInfo (txInfoInputs, txInfoMint), ownCurrencySymbol, scriptOutputsAt)
import Plutus.Script.Utils.Typed (mkUntypedMintingPolicy)
import PlutusCore.Core (plcVersion100)
import PlutusLedgerApi.V2 (
Datum (getDatum),
Expand Down
5 changes: 3 additions & 2 deletions hydra-plutus/src/Hydra/Contract/Initial.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Hydra.Contract.Commit qualified as Commit
import Hydra.Contract.Error (errorCode)
import Hydra.Contract.InitialError (InitialError (..))
import Hydra.Contract.Util (mustBurnST)
import Hydra.Plutus.Extras (ValidatorType, mkUntypedValidator, scriptValidatorHash)
import Hydra.Plutus.Extras (ValidatorType, scriptValidatorHash)
import Hydra.ScriptContext (
ScriptContext (..),
TxInfo (txInfoMint, txInfoSignatories),
Expand All @@ -26,6 +26,7 @@ import Hydra.ScriptContext (
scriptOutputsAt,
valueLockedBy,
)
import Plutus.Script.Utils.Typed (mkUntypedValidator)
import PlutusCore.Core (plcVersion100)
import PlutusLedgerApi.Common (SerialisedScript, serialiseCompiledCode)
import PlutusLedgerApi.V1.Value (geq, isZero)
Expand Down Expand Up @@ -181,7 +182,7 @@ compiledValidator =
$$(PlutusTx.compile [||wrap . validator||])
`PlutusTx.unsafeApplyCode` PlutusTx.liftCode plcVersion100 Commit.validatorHash
where
wrap = mkUntypedValidator @DatumType @RedeemerType
wrap = mkUntypedValidator @ScriptContext @DatumType @RedeemerType

validatorScript :: SerialisedScript
validatorScript = serialiseCompiledCode compiledValidator
Expand Down
3 changes: 3 additions & 0 deletions hydra-plutus/src/Hydra/ScriptContext.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import PlutusLedgerApi.V2.Contexts hiding (
)
import PlutusTx.Prelude

import Plutus.Script.Utils.Typed (IsScriptContext (..))
import PlutusLedgerApi.V2 (
Address (..),
Credential (..),
Expand Down Expand Up @@ -74,6 +75,8 @@ data ScriptContext = ScriptContext

makeIsDataIndexed ''ScriptContext [('ScriptContext, 0)]

instance IsScriptContext ScriptContext

-- * Utilities

-- | Get the list of 'TxOut' outputs of the pending transaction at
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import PlutusLedgerApi.V1 (
Value (..),
)

import Hydra.Plutus.Extras (mkUntypedValidator)
import Plutus.Script.Utils.Typed (mkUntypedValidator)
import PlutusLedgerApi.Common (SerialisedScript, serialiseCompiledCode)
import PlutusTx qualified as Plutus

Expand Down
1 change: 1 addition & 0 deletions plutus-cbor/plutus-cbor.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ executable encoding-cost
, hydra-test-utils >=0.10.0
, plutus-cbor
, plutus-ledger-api >=1.1.0.0
, plutus-script-utils
, plutus-tx
, plutus-tx-plugin
, QuickCheck
Expand Down
2 changes: 1 addition & 1 deletion plutus-merkle-tree/bench/Validators.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ module Validators where

import PlutusTx.Prelude

import Hydra.Plutus.Extras (mkUntypedValidator)
import Plutus.MerkleTree qualified as MT
import Plutus.Script.Utils.Typed (mkUntypedValidator)
import PlutusLedgerApi.Common (SerialisedScript, serialiseCompiledCode)
import PlutusLedgerApi.V2 (ScriptContext)
import PlutusTx qualified as Plutus
Expand Down
1 change: 1 addition & 0 deletions plutus-merkle-tree/plutus-merkle-tree.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ benchmark on-chain-cost
, hydra-test-utils >=0.10.0
, plutus-ledger-api >=1.1.0.0
, plutus-merkle-tree
, plutus-script-utils
, plutus-tx
, plutus-tx-plugin
, QuickCheck

0 comments on commit 30ec6db

Please sign in to comment.