Skip to content

Commit

Permalink
Merge pull request #52 from mlabs-haskell/koz/bump
Browse files Browse the repository at this point in the history
Bump to latest Plutarch
  • Loading branch information
TotallyNotChase authored Sep 14, 2024
2 parents efeb0ba + a2c379a commit 79fdedb
Show file tree
Hide file tree
Showing 20 changed files with 188 additions and 127 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 0.7.0 - Bump plutus version to 1.30.0.0

- Renamed `ValidatorRole` and `MintingPolicyRole` to `ThreeArgumentScript` and `TwoArgumentScript`.
- Dropped V1 support for `Ply.Plutarch`.

# 0.6.0 - Bump plutus version to 1.7.0.0

# 0.5.0 - More detailed parameter type encoding that supports data encoded parameters.
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ Ply allows you to serialize your Plutarch validators/minting policies (with opti

This facilitates the onchain/offchain split that is often utilized, without forcing the user to manage the intricacies of the types and their UPLC representation when it comes to parameterized scripts. i.e scripts that take extra parameters before being submitted to the chain.

> N.B: Ply currently integrates with Plutarch 1.3, **with a minor revision**. You **MUST** ensure you're using a commit that includes [this patch](https://github.com/Plutonomicon/plutarch-plutus/pull/601).
# Goals

- Efficiency: Applying constants with `Ply` should be equally efficient as using `pconstant`/`pconstantData` in the Plutarch function body directly.
Expand Down
6 changes: 3 additions & 3 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ repository cardano-haskell-packages

source-repository-package
type: git
--sha256: sha256-aeaZMW5Y3r5GdSyrfrrKOuGahcL5MVkDUNggunbmtv0=
--sha256: sha256-Vg0U0QHolNHhBH2EaMHmFxeMt+Mv+thbY58PuVpWRlQ=
location: https://github.com/Plutonomicon/plutarch-plutus.git
tag: 288d9140468ae98abe1c9a4c0bb1c19a82eb7cd6
tag: 7913e2d883530f569b16c02878989d3394bab727
subdir:
.
plutarch-ledger-api
plutarch-extra

write-ghc-environment-files: never
Expand All @@ -32,7 +33,6 @@ test-show-details: direct

constraints:
, dependent-sum >= 0.7.1.0
, plutus-core >= 1.7.0.0

package nothunks
flags: +vector
4 changes: 2 additions & 2 deletions example/compiler-app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ module Main (main) where

import System.FilePath ((</>))

import Plutarch (Config (Config, tracingMode), TracingMode (DoTracing))
import Plutarch (Config (Tracing), LogLevel (LogInfo), TracingMode (DoTracing))
import Ply.Plutarch

import Example.NftM (nftMp)

main :: IO ()
main =
writeTypedScript
(Config {tracingMode = DoTracing})
(Tracing LogInfo DoTracing)
"NFT Minting Policy (DoTracing)"
("compiled" </> "nftMp.plutus")
nftMp
1 change: 1 addition & 0 deletions example/example.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ common common-deps
build-depends:
, base
, plutarch
, plutarch-ledger-api
, plutus-core
, plutus-ledger-api
, plutus-tx
Expand Down
4 changes: 2 additions & 2 deletions example/reader-app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import qualified Data.ByteString.Base16 as Base16
import qualified Data.ByteString.Short as SBS
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
import PlutusLedgerApi.V1
import PlutusLedgerApi.V2
import Ply
import UntypedPlutusCore

Expand All @@ -21,7 +21,7 @@ instance Show MintingPolicy where
. serialiseUPLC
. (\(MintingPolicy x) -> x)

toMintingPolicy :: TypedScript 'MintingPolicyRole '[] -> MintingPolicy
toMintingPolicy :: TypedScript 'TwoArgumentScript '[] -> MintingPolicy
toMintingPolicy (TypedScript _ s) = MintingPolicy s

usePolicy :: MintingPolicy -> IO ()
Expand Down
9 changes: 3 additions & 6 deletions example/src/Example/NftM.hs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module Example.NftM (nftMp) where

import Plutarch.Api.V1
import qualified Plutarch.Api.V1.Value as PValue
import Plutarch.LedgerApi.V2
import qualified Plutarch.LedgerApi.Value as PValue
import Plutarch.Prelude

nftMp :: ClosedTerm (PTxOutRef :--> PTokenName :--> PMintingPolicy)
nftMp :: ClosedTerm (PTxOutRef :--> PTokenName :--> PData :--> PScriptContext :--> POpaque)
nftMp = plam $ \ref tn _ ctx' -> popaque $
unTermCont $ do
ctx <- tcont $ pletFields @'["txInfo", "purpose"] ctx'
Expand All @@ -17,6 +17,3 @@ nftMp = plam $ \ref tn _ ctx' -> popaque $
pguardC "Wrong NFT mint amount" $
PValue.pvalueOf # getField @"mint" txInfo # ownSym # tn #== 1
pure $ pconstant ()

pguardC :: Term s PString -> Term s PBool -> TermCont s ()
pguardC s cond = tcont $ \f -> pif cond (f ()) $ ptraceError s
97 changes: 93 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
flake = false;
};
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
iohk-nix.url = "github:input-output-hk/iohk-nix";
};

outputs = { nixpkgs, flake-utils, haskellNix, CHaP, pre-commit-hooks, ... }:
outputs = { nixpkgs, flake-utils, haskellNix, CHaP, pre-commit-hooks, iohk-nix, ... }:
let
# NOTE: nix flake (show | check) --allow-import-from-derivation --impure
systems =
Expand Down Expand Up @@ -45,13 +46,15 @@
inherit system;
overlays = [
haskellNix.overlay
iohk-nix.overlays.crypto
iohk-nix.overlays.haskell-nix-crypto
];
inherit (haskellNix) config;
};

ply = pkgs.haskell-nix.cabalProject' {
src = ./.;
compiler-nix-name = "ghc963";
compiler-nix-name = "ghc96";
shell = {
# This is used by `nix develop .` to open a shell for use with
# `cabal`, `hlint` and `haskell-language-server` etc
Expand Down
2 changes: 1 addition & 1 deletion genPurs/genPurs.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.0
name: ply-ctl
version: 0.6.0
version: 0.7.0
author: Seungheon <Seungheon@mlabs.city>
license: MIT

Expand Down
2 changes: 1 addition & 1 deletion ply-core/ply-core.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.0
name: ply-core
version: 0.6.0
version: 0.7.0
author: Chase <chase@mlabs.city>
license: MIT

Expand Down
4 changes: 2 additions & 2 deletions ply-core/src/Ply.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import Ply.Core.Typename (plyTypeName)
import Ply.Core.Types (
AsData (..),
ScriptReaderException (..),
ScriptRole (MintingPolicyRole, ValidatorRole),
ScriptRole (ThreeArgumentScript, TwoArgumentScript),
ScriptVersion (..),
TypedScript (TypedScriptConstr),
TypedScriptEnvelope (..),
Expand All @@ -47,7 +47,7 @@ For example, if using 'plutus-apps' - you can create a function that determines
`plutusV1OtherScript` or `plutusV2OtherScript` in your script lookups:
@
unifiedOtherScript :: TypedScript ValidatorRole '[] -> ScriptLookups a
unifiedOtherScript :: TypedScript ThreeArgumentScript '[] -> ScriptLookups a
unifiedOtherScript (TypedScript ver s) = (if ver == ScriptV1 then plutusV1OtherScript else plutusV2OtherScript) vald
where
ver = Ply.getPlutusVersion ts
Expand Down
6 changes: 3 additions & 3 deletions ply-core/src/Ply/Core/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Data.Text (Text)
import GHC.TypeLits (ErrorMessage (ShowType, Text))
import Ply.Core.Types (AsData (AsData))

import PlutusCore (DefaultUni, Includes, Some, ValueOf)
import PlutusCore (DefaultUni, HasTermLevel, Some, ValueOf)
import qualified PlutusCore as PLC
import qualified PlutusTx.AssocMap as PlutusMap

Expand Down Expand Up @@ -53,7 +53,7 @@ As a result, 'toBuiltinArg' is partial for types that don't hold their invariant
4. 'toBuiltinArgData' implementation must perform the same validations/normalizations as 'toBuiltinArg'.
-}
class DefaultUni `Includes` UPLCRep a => PlyArg a where
class DefaultUni `HasTermLevel` UPLCRep a => PlyArg a where
type UPLCRep a :: Type
type ToDataConstraint a :: Constraint
type ToDataConstraint a = ()
Expand Down Expand Up @@ -153,7 +153,7 @@ instance PlyArg Value where
( \(cs, tkMap) ->
( toBuiltinArgData cs
, toBuiltinArgData
. PlutusMap.fromList
. PlutusMap.unsafeFromList
$ map (bimap toBuiltinArg toBuiltinArg) tkMap
)
)
Expand Down
8 changes: 4 additions & 4 deletions ply-core/src/Ply/Core/Internal/Reify.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ instance ReifyVersion ScriptV1 where
instance ReifyVersion ScriptV2 where
reifyVersion _ = ScriptV2

instance ReifyRole ValidatorRole where
reifyRole _ = ValidatorRole
instance ReifyRole ThreeArgumentScript where
reifyRole _ = ThreeArgumentScript

instance ReifyRole MintingPolicyRole where
reifyRole _ = MintingPolicyRole
instance ReifyRole TwoArgumentScript where
reifyRole _ = TwoArgumentScript

instance ReifyTypenames '[] where
reifyTypenames _ = []
Expand Down
4 changes: 2 additions & 2 deletions ply-core/src/Ply/Core/TypedReader.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Ply.Core.Deserialize (readEnvelope)
import Ply.Core.Internal.Reify
import Ply.Core.Types (
ScriptReaderException (ScriptRoleError, ScriptTypeError),
ScriptRole (ValidatorRole),
ScriptRole (ThreeArgumentScript),
TypedScript (TypedScriptConstr),
TypedScriptEnvelope (..),
)
Expand All @@ -34,7 +34,7 @@ mkTypedScript ::
TypedScriptEnvelope ->
Either ScriptReaderException (TypedScript rl params)
mkTypedScript (TypedScriptEnvelope ver rol params _ prog) = do
unless (rol == reifyRole (Proxy @rl)) . Left $ ScriptRoleError ValidatorRole rol
unless (rol == reifyRole (Proxy @rl)) . Left $ ScriptRoleError ThreeArgumentScript rol
let expectedParams = reifyTypenames $ Proxy @params
unless (expectedParams == params) . Left $ ScriptTypeError expectedParams params
pure $ TypedScriptConstr ver prog
Expand Down
2 changes: 1 addition & 1 deletion ply-core/src/Ply/Core/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ data TypedScript r a = TypedScriptConstr !ScriptVersion !UPLCProgram
deriving stock (Show)

-- | Script role: either a validator or a minting policy.
data ScriptRole = ValidatorRole | MintingPolicyRole
data ScriptRole = ThreeArgumentScript | TwoArgumentScript
deriving stock (Bounded, Enum, Eq, Ord, Show, Generic)
deriving anyclass (ToJSON, FromJSON)

Expand Down
Loading

0 comments on commit 79fdedb

Please sign in to comment.