From 029c336abc26e8e2a4659d4137fa104511b27db2 Mon Sep 17 00:00:00 2001 From: gege251 Date: Thu, 20 Jan 2022 17:31:18 +0100 Subject: [PATCH 1/4] Add simple value transfer example --- examples/plutus-transfer/.gitignore | 3 + examples/plutus-transfer/README.md | 7 + examples/plutus-transfer/app/Main.hs | 68 ++++++ examples/plutus-transfer/cabal.project | 14 ++ examples/plutus-transfer/hie.yaml | 7 + .../plutus-transfer/plutus-transfer.cabal | 137 ++++++++++++ examples/plutus-transfer/protocol.json | 208 ++++++++++++++++++ examples/plutus-transfer/run.sh | 16 ++ .../src/Cardano/PlutusExample/Transfer.hs | 19 ++ 9 files changed, 479 insertions(+) create mode 100644 examples/plutus-transfer/.gitignore create mode 100644 examples/plutus-transfer/README.md create mode 100644 examples/plutus-transfer/app/Main.hs create mode 100644 examples/plutus-transfer/cabal.project create mode 100644 examples/plutus-transfer/hie.yaml create mode 100644 examples/plutus-transfer/plutus-transfer.cabal create mode 100644 examples/plutus-transfer/protocol.json create mode 100755 examples/plutus-transfer/run.sh create mode 100644 examples/plutus-transfer/src/Cardano/PlutusExample/Transfer.hs diff --git a/examples/plutus-transfer/.gitignore b/examples/plutus-transfer/.gitignore new file mode 100644 index 00000000..5dd5d31e --- /dev/null +++ b/examples/plutus-transfer/.gitignore @@ -0,0 +1,3 @@ +scripts +signing-keys +txs diff --git a/examples/plutus-transfer/README.md b/examples/plutus-transfer/README.md new file mode 100644 index 00000000..331a1d67 --- /dev/null +++ b/examples/plutus-transfer/README.md @@ -0,0 +1,7 @@ +### plutus-helloworld + +This directory contains a simple "Hello World" script. There are two versions: one using an integer literal (needed because the Plutus interpreter doesn't currently accept byte string literals) and a slighly more complicated one using a bytestring parameter. + +``plutus-helloworld'' -- very simple numeric version + +``plutus-helloworld-bytestring'' -- more compex version using bytestring constant diff --git a/examples/plutus-transfer/app/Main.hs b/examples/plutus-transfer/app/Main.hs new file mode 100644 index 00000000..65370a39 --- /dev/null +++ b/examples/plutus-transfer/app/Main.hs @@ -0,0 +1,68 @@ +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE TemplateHaskell #-} + +module Main (main) where + +import Cardano.Api (NetworkId (Testnet), NetworkMagic (..)) +import Cardano.PlutusExample.Transfer ( + TransferSchema, + transfer, + ) +import Data.Aeson qualified as JSON +import Ledger.Value (Value) +import Data.Aeson.TH (defaultOptions, deriveJSON) +import Data.ByteString.Lazy qualified as LazyByteString +import Data.Maybe (fromMaybe) +import Ledger.Crypto (PubKeyHash) +import MLabsPAB qualified +import MLabsPAB.Types ( + CLILocation (Local), + HasDefinitions (..), + LogLevel (Debug), + PABConfig (..), + SomeBuiltin (..), + endpointsToSchemas, + ) +import Playground.Types (FunctionSchema) +import Schema (FormSchema) +import Servant.Client.Core (BaseUrl (BaseUrl), Scheme (Http)) +import Prelude + +instance HasDefinitions TransferContracts where + getDefinitions :: [TransferContracts] + getDefinitions = [] + + getSchema :: TransferContracts -> [FunctionSchema FormSchema] + getSchema _ = endpointsToSchemas @TransferSchema + + getContract :: (TransferContracts -> SomeBuiltin) + getContract = \case + Transfer payments -> + SomeBuiltin $ transfer payments + +newtype TransferContracts = Transfer [(PubKeyHash, Value)] + deriving stock (Show) + +$(deriveJSON defaultOptions ''TransferContracts) + +main :: IO () +main = do + protocolParams <- + fromMaybe (error "protocol.json file not found") . JSON.decode + <$> LazyByteString.readFile "protocol.json" + let pabConf = + PABConfig + { pcCliLocation = Local + , pcNetwork = Testnet (NetworkMagic 1097911063) + , pcChainIndexUrl = BaseUrl Http "localhost" 9083 "" + , pcPort = 9080 + , pcProtocolParams = protocolParams + , pcOwnPubKeyHash = "0f45aaf1b2959db6e5ff94dbb1f823bf257680c3c723ac2d49f97546" + , pcScriptFileDir = "./scripts" + , pcSigningKeyFileDir = "./signing-keys" + , pcTxFileDir = "./txs" + , pcDryRun = True + , pcLogLevel = Debug + , pcProtocolParamsFile = "./protocol.json" + } + MLabsPAB.runPAB @TransferContracts pabConf diff --git a/examples/plutus-transfer/cabal.project b/examples/plutus-transfer/cabal.project new file mode 100644 index 00000000..85897a86 --- /dev/null +++ b/examples/plutus-transfer/cabal.project @@ -0,0 +1,14 @@ +-- Bump this if you need newer packages +index-state: 2021-10-20T00:00:00Z + +packages: + ./. + ../../. + +-- You never, ever, want this. +write-ghc-environment-files: never + +-- Always build tests and benchmarks. +tests: true +benchmarks: true + diff --git a/examples/plutus-transfer/hie.yaml b/examples/plutus-transfer/hie.yaml new file mode 100644 index 00000000..8f9e41c8 --- /dev/null +++ b/examples/plutus-transfer/hie.yaml @@ -0,0 +1,7 @@ +cradle: + cabal: + - path: "./src" + component: "lib:plutus-nft" + + - path: "./app" + component: "exe:plutus-nft-pab" diff --git a/examples/plutus-transfer/plutus-transfer.cabal b/examples/plutus-transfer/plutus-transfer.cabal new file mode 100644 index 00000000..49f1fb42 --- /dev/null +++ b/examples/plutus-transfer/plutus-transfer.cabal @@ -0,0 +1,137 @@ +cabal-version: 3.0 +name: plutus-transfer +version: 0.1.0.0 +synopsis: Simple transfer of Ada and/or native tokens +description: Simple transfer of Ada and/or native tokens +homepage: https://github.com/mlabs-haskell/mlabs-pab +bug-reports: https://github.com/mlabs-haskell/mlabs-pab +license: +license-file: +author: MLabs +maintainer: gergely@mlabs.city +copyright: TODO +build-type: Simple +tested-with: GHC ==8.10.4 +extra-source-files: README.md + +source-repository head + type: git + location: https://github.com/mlabs-haskell/mlabs-pab + +-- Common sections + +common common-lang + ghc-options: + -Wall -Wcompat -Wincomplete-record-updates + -Wincomplete-uni-patterns -Wredundant-constraints -Werror + -fobject-code -fno-ignore-interface-pragmas + -fno-omit-interface-pragmas -fplugin=RecordDotPreprocessor + + build-depends: + , base ^>=4.14 + , record-dot-preprocessor + , record-hasfield + + default-extensions: + NoImplicitPrelude + BangPatterns + BinaryLiterals + ConstraintKinds + DataKinds + DeriveFunctor + DeriveGeneric + DeriveTraversable + DerivingStrategies + DerivingVia + DuplicateRecordFields + EmptyCase + FlexibleContexts + FlexibleInstances + GADTs + GeneralizedNewtypeDeriving + HexFloatLiterals + ImportQualifiedPost + InstanceSigs + KindSignatures + LambdaCase + MultiParamTypeClasses + NumericUnderscores + OverloadedStrings + ScopedTypeVariables + StandaloneDeriving + TupleSections + TypeApplications + TypeOperators + TypeSynonymInstances + UndecidableInstances + + default-language: Haskell2010 + +-- Libraries + + +library + import: common-lang + exposed-modules: Cardano.PlutusExample.Transfer + build-depends: + , aeson ^>=1.5.0.0 + , attoparsec >=0.13.2.2 + , bytestring ^>=0.10.12.0 + , cardano-api + , cardano-crypto + , cardano-ledger-alonzo + , containers + , data-default + , data-default-class + , directory + , either + , filepath + , freer-extras + , freer-simple + , http-client + , http-types + , lens + , memory + , playground-common + , plutus-chain-index + , plutus-chain-index-core + , plutus-contract + , plutus-core + , plutus-ledger + , plutus-ledger-api + , plutus-pab + , plutus-tx + , plutus-tx-plugin + , process + , row-types + , serialise + , servant + , servant-client + , servant-server + , servant-websockets + , split + , stm + , text ^>=1.2.4.0 + , transformers + , transformers-either + , uuid + , wai + , warp + , websockets + + hs-source-dirs: src + +executable plutus-transfer-pab + import: common-lang + build-depends: + , aeson ^>=1.5.0.0 + , bytestring + , cardano-api + , mlabs-pab + , playground-common + , plutus-ledger + , plutus-transfer + , servant-client-core + + main-is: Main.hs + hs-source-dirs: app diff --git a/examples/plutus-transfer/protocol.json b/examples/plutus-transfer/protocol.json new file mode 100644 index 00000000..daa1b5f1 --- /dev/null +++ b/examples/plutus-transfer/protocol.json @@ -0,0 +1,208 @@ +{ + "txFeePerByte": 44, + "minUTxOValue": null, + "decentralization": 0.7, + "utxoCostPerWord": 34482, + "stakePoolDeposit": 0, + "poolRetireMaxEpoch": 18, + "extraPraosEntropy": null, + "collateralPercentage": 150, + "stakePoolTargetNum": 100, + "maxBlockBodySize": 65536, + "minPoolCost": 0, + "maxTxSize": 16384, + "treasuryCut": 0.1, + "maxBlockExecutionUnits": { + "memory": 50000000, + "steps": 40000000000 + }, + "maxCollateralInputs": 3, + "maxValueSize": 5000, + "maxBlockHeaderSize": 1100, + "maxTxExecutionUnits": { + "memory": 10000000, + "steps": 10000000000 + }, + "costModels": { + "PlutusScriptV1": { + "cekConstCost-exBudgetMemory": 100, + "unBData-cpu-arguments": 150000, + "divideInteger-memory-arguments-minimum": 1, + "nullList-cpu-arguments": 150000, + "cekDelayCost-exBudgetMemory": 100, + "appendByteString-cpu-arguments-slope": 621, + "sha2_256-memory-arguments": 4, + "multiplyInteger-cpu-arguments-intercept": 61516, + "iData-cpu-arguments": 150000, + "equalsString-cpu-arguments-intercept": 150000, + "trace-cpu-arguments": 150000, + "lessThanEqualsByteString-cpu-arguments-intercept": 103599, + "encodeUtf8-cpu-arguments-slope": 1000, + "equalsString-cpu-arguments-constant": 1000, + "blake2b-cpu-arguments-slope": 29175, + "consByteString-memory-arguments-intercept": 0, + "headList-cpu-arguments": 150000, + "listData-cpu-arguments": 150000, + "divideInteger-cpu-arguments-model-arguments-slope": 118, + "divideInteger-memory-arguments-slope": 1, + "bData-cpu-arguments": 150000, + "chooseData-memory-arguments": 32, + "cekBuiltinCost-exBudgetCPU": 29773, + "mkNilData-memory-arguments": 32, + "equalsInteger-cpu-arguments-intercept": 136542, + "lengthOfByteString-cpu-arguments": 150000, + "subtractInteger-cpu-arguments-slope": 0, + "unIData-cpu-arguments": 150000, + "sliceByteString-cpu-arguments-slope": 5000, + "unMapData-cpu-arguments": 150000, + "modInteger-cpu-arguments-model-arguments-slope": 118, + "lessThanInteger-cpu-arguments-intercept": 179690, + "appendString-memory-arguments-intercept": 0, + "mkCons-cpu-arguments": 150000, + "sha3_256-cpu-arguments-slope": 82363, + "ifThenElse-cpu-arguments": 1, + "mkNilPairData-cpu-arguments": 150000, + "constrData-memory-arguments": 32, + "lessThanEqualsInteger-cpu-arguments-intercept": 145276, + "addInteger-memory-arguments-slope": 1, + "chooseList-memory-arguments": 32, + "equalsData-memory-arguments": 1, + "decodeUtf8-cpu-arguments-intercept": 150000, + "bData-memory-arguments": 32, + "lessThanByteString-cpu-arguments-slope": 248, + "listData-memory-arguments": 32, + "consByteString-cpu-arguments-intercept": 150000, + "headList-memory-arguments": 32, + "subtractInteger-memory-arguments-slope": 1, + "appendByteString-memory-arguments-intercept": 0, + "unIData-memory-arguments": 32, + "remainderInteger-memory-arguments-minimum": 1, + "lengthOfByteString-memory-arguments": 4, + "encodeUtf8-memory-arguments-intercept": 0, + "cekStartupCost-exBudgetCPU": 100, + "remainderInteger-memory-arguments-slope": 1, + "multiplyInteger-memory-arguments-intercept": 0, + "cekForceCost-exBudgetCPU": 29773, + "unListData-memory-arguments": 32, + "sha2_256-cpu-arguments-slope": 29175, + "indexByteString-memory-arguments": 1, + "equalsInteger-memory-arguments": 1, + "remainderInteger-cpu-arguments-model-arguments-slope": 118, + "cekVarCost-exBudgetCPU": 29773, + "lessThanEqualsInteger-cpu-arguments-slope": 1366, + "addInteger-memory-arguments-intercept": 1, + "sndPair-cpu-arguments": 150000, + "lessThanInteger-memory-arguments": 1, + "cekLamCost-exBudgetCPU": 29773, + "chooseUnit-cpu-arguments": 150000, + "decodeUtf8-cpu-arguments-slope": 1000, + "fstPair-cpu-arguments": 150000, + "quotientInteger-memory-arguments-minimum": 1, + "lessThanEqualsInteger-memory-arguments": 1, + "chooseUnit-memory-arguments": 32, + "fstPair-memory-arguments": 32, + "quotientInteger-cpu-arguments-constant": 148000, + "mapData-cpu-arguments": 150000, + "unConstrData-cpu-arguments": 150000, + "mkPairData-cpu-arguments": 150000, + "sndPair-memory-arguments": 32, + "decodeUtf8-memory-arguments-slope": 8, + "equalsData-cpu-arguments-intercept": 150000, + "addInteger-cpu-arguments-intercept": 197209, + "modInteger-memory-arguments-intercept": 0, + "cekStartupCost-exBudgetMemory": 100, + "divideInteger-cpu-arguments-model-arguments-intercept": 425507, + "divideInteger-memory-arguments-intercept": 0, + "cekVarCost-exBudgetMemory": 100, + "consByteString-memory-arguments-slope": 1, + "cekForceCost-exBudgetMemory": 100, + "unListData-cpu-arguments": 150000, + "subtractInteger-cpu-arguments-intercept": 197209, + "indexByteString-cpu-arguments": 150000, + "equalsInteger-cpu-arguments-slope": 1326, + "lessThanByteString-memory-arguments": 1, + "blake2b-cpu-arguments-intercept": 2477736, + "encodeUtf8-cpu-arguments-intercept": 150000, + "multiplyInteger-cpu-arguments-slope": 11218, + "tailList-cpu-arguments": 150000, + "appendByteString-cpu-arguments-intercept": 396231, + "equalsString-cpu-arguments-slope": 1000, + "lessThanEqualsByteString-cpu-arguments-slope": 248, + "remainderInteger-cpu-arguments-constant": 148000, + "chooseList-cpu-arguments": 150000, + "equalsByteString-memory-arguments": 1, + "constrData-cpu-arguments": 150000, + "cekApplyCost-exBudgetCPU": 29773, + "equalsData-cpu-arguments-slope": 10000, + "decodeUtf8-memory-arguments-intercept": 0, + "modInteger-memory-arguments-slope": 1, + "addInteger-cpu-arguments-slope": 0, + "appendString-cpu-arguments-intercept": 150000, + "quotientInteger-cpu-arguments-model-arguments-slope": 118, + "unMapData-memory-arguments": 32, + "cekApplyCost-exBudgetMemory": 100, + "quotientInteger-memory-arguments-slope": 1, + "mkNilPairData-memory-arguments": 32, + "ifThenElse-memory-arguments": 1, + "equalsByteString-cpu-arguments-slope": 247, + "sliceByteString-memory-arguments-slope": 1, + "sha3_256-memory-arguments": 4, + "mkCons-memory-arguments": 32, + "verifySignature-cpu-arguments-intercept": 3345831, + "cekBuiltinCost-exBudgetMemory": 100, + "remainderInteger-memory-arguments-intercept": 0, + "lessThanEqualsByteString-memory-arguments": 1, + "mkNilData-cpu-arguments": 150000, + "equalsString-memory-arguments": 1, + "chooseData-cpu-arguments": 150000, + "remainderInteger-cpu-arguments-model-arguments-intercept": 425507, + "tailList-memory-arguments": 32, + "sha2_256-cpu-arguments-intercept": 2477736, + "multiplyInteger-memory-arguments-slope": 1, + "iData-memory-arguments": 32, + "divideInteger-cpu-arguments-constant": 148000, + "cekDelayCost-exBudgetCPU": 29773, + "encodeUtf8-memory-arguments-slope": 8, + "subtractInteger-memory-arguments-intercept": 1, + "nullList-memory-arguments": 32, + "lessThanByteString-cpu-arguments-intercept": 103599, + "appendByteString-memory-arguments-slope": 1, + "blake2b-memory-arguments": 4, + "unBData-memory-arguments": 32, + "cekConstCost-exBudgetCPU": 29773, + "consByteString-cpu-arguments-slope": 1000, + "trace-memory-arguments": 32, + "quotientInteger-memory-arguments-intercept": 0, + "mapData-memory-arguments": 32, + "verifySignature-cpu-arguments-slope": 1, + "quotientInteger-cpu-arguments-model-arguments-intercept": 425507, + "modInteger-cpu-arguments-constant": 148000, + "appendString-cpu-arguments-slope": 1000, + "unConstrData-memory-arguments": 32, + "mkPairData-memory-arguments": 32, + "equalsByteString-cpu-arguments-constant": 150000, + "equalsByteString-cpu-arguments-intercept": 112536, + "sliceByteString-memory-arguments-intercept": 0, + "lessThanInteger-cpu-arguments-slope": 497, + "verifySignature-memory-arguments": 1, + "cekLamCost-exBudgetMemory": 100, + "sliceByteString-cpu-arguments-intercept": 150000, + "modInteger-cpu-arguments-model-arguments-intercept": 425507, + "modInteger-memory-arguments-minimum": 1, + "appendString-memory-arguments-slope": 1, + "sha3_256-cpu-arguments-intercept": 0 + } + }, + "protocolVersion": { + "minor": 0, + "major": 5 + }, + "txFeeFixed": 155381, + "stakeAddressDeposit": 0, + "monetaryExpansion": 0.1, + "poolPledgeInfluence": 0, + "executionUnitPrices": { + "priceSteps": 7.21e-5, + "priceMemory": 5.77e-2 + } +} \ No newline at end of file diff --git a/examples/plutus-transfer/run.sh b/examples/plutus-transfer/run.sh new file mode 100755 index 00000000..9003c051 --- /dev/null +++ b/examples/plutus-transfer/run.sh @@ -0,0 +1,16 @@ +#!/bin/sh +CONTRACT_INST_ID=$(curl --location --request POST 'localhost:9080/api/contract/activate' \ + --header 'Content-Type: application/json' \ + --data-raw '{ + "caID": [ + [ {"getPubKeyHash": "981fc565bcf0c95c0cfa6ee6693875b60d529d87ed7082e9bf03c6a4"}, + {"getValue": [[{"unCurrencySymbol":""},[[{"unTokenName": ""}, 1500000]]]]} + ] + ] + }' | jq -r .unContractInstanceId ) + +echo $CONTRACT_INST_ID + + +echo "{ \"tag\": \"Subscribe\", \"contents\": { \"Left\": { \"unContractInstanceId\":\"$CONTRACT_INST_ID\" } } }" | websocat -n ws://localhost:9080/ws + diff --git a/examples/plutus-transfer/src/Cardano/PlutusExample/Transfer.hs b/examples/plutus-transfer/src/Cardano/PlutusExample/Transfer.hs new file mode 100644 index 00000000..615aab3e --- /dev/null +++ b/examples/plutus-transfer/src/Cardano/PlutusExample/Transfer.hs @@ -0,0 +1,19 @@ +module Cardano.PlutusExample.Transfer (TransferSchema, transfer) where + +import Control.Monad (void) +import Data.Monoid (Last (Last)) +import Data.Text (Text) +import Ledger hiding (singleton) +import Ledger.Constraints as Constraints +import Plutus.Contract (Contract, Endpoint, submitTx, tell) +import PlutusTx.Prelude hiding (Semigroup (..), unless) + +type TransferSchema = + Endpoint "transfer" [(PubKeyHash, Value)] + +transfer :: [(PubKeyHash, Value)] -> Contract (Last Text) TransferSchema Text () +transfer payments = do + tell $ Last $ Just "Contract started" + let tx = mconcat $ map (uncurry Constraints.mustPayToPubKey) payments + void $ submitTx tx + tell $ Last $ Just "Finished" From 02120dd9fcaa147494e5a68f9bbf0662d4488401 Mon Sep 17 00:00:00 2001 From: gege251 Date: Thu, 20 Jan 2022 18:43:18 +0100 Subject: [PATCH 2/4] Add example script with tokens --- examples/plutus-transfer/run2.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 examples/plutus-transfer/run2.sh diff --git a/examples/plutus-transfer/run2.sh b/examples/plutus-transfer/run2.sh new file mode 100755 index 00000000..6ee2f788 --- /dev/null +++ b/examples/plutus-transfer/run2.sh @@ -0,0 +1,22 @@ +#!/bin/sh +CONTRACT_INST_ID=$(curl --location --request POST 'localhost:9080/api/contract/activate' \ + --header 'Content-Type: application/json' \ + --data-raw '{ + "caID": [ + [ {"getPubKeyHash": "981fc565bcf0c95c0cfa6ee6693875b60d529d87ed7082e9bf03c6a4"}, + {"getValue": [[{"unCurrencySymbol":"1d6445ddeda578117f393848e685128f1e78ad0c4e48129c5964dc2e"},[[{"unTokenName": "testToken"}, 15]]]]} + ], + [ {"getPubKeyHash": "6696936bb8ae24859d0c2e4d05584106601f58a5e9466282c8561b88"}, + {"getValue": [[{"unCurrencySymbol":"1d6445ddeda578117f393848e685128f1e78ad0c4e48129c5964dc2e"},[[{"unTokenName": "testToken"}, 18]]]]} + ], + [ {"getPubKeyHash": "a11767a73ea3f59fb11f17c1627706115de75e2d2c444b0e43789567"}, + {"getValue": [[{"unCurrencySymbol":"1d6445ddeda578117f393848e685128f1e78ad0c4e48129c5964dc2e"},[[{"unTokenName": "testToken"}, 20]]]]} + ] + ] + }' | jq -r .unContractInstanceId ) + +echo $CONTRACT_INST_ID + + +echo "{ \"tag\": \"Subscribe\", \"contents\": { \"Left\": { \"unContractInstanceId\":\"$CONTRACT_INST_ID\" } } }" | websocat -n ws://localhost:9080/ws + From ca83935331494b70194edb9a903dea2f18069407 Mon Sep 17 00:00:00 2001 From: gege251 Date: Thu, 20 Jan 2022 18:49:06 +0100 Subject: [PATCH 3/4] Fix examples --- examples/plutus-game/app/Main.hs | 5 ++++- examples/plutus-nft/app/Main.hs | 5 ++++- examples/plutus-transfer/app/Main.hs | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/examples/plutus-game/app/Main.hs b/examples/plutus-game/app/Main.hs index b9854ead..d78fb336 100644 --- a/examples/plutus-game/app/Main.hs +++ b/examples/plutus-game/app/Main.hs @@ -13,6 +13,7 @@ import Cardano.PlutusExample.Game ( import Data.Aeson qualified as JSON import Data.Aeson.TH (defaultOptions, deriveJSON) import Data.ByteString.Lazy qualified as LazyByteString +import Data.Maybe (fromMaybe) import MLabsPAB qualified import MLabsPAB.Types ( CLILocation (Local), @@ -46,7 +47,9 @@ $(deriveJSON defaultOptions ''GameContracts) main :: IO () main = do - protocolParams <- JSON.decode <$> LazyByteString.readFile "protocol.json" + protocolParams <- + fromMaybe (error "protocol.json file not found") . JSON.decode + <$> LazyByteString.readFile "protocol.json" let pabConf = PABConfig { pcCliLocation = Local diff --git a/examples/plutus-nft/app/Main.hs b/examples/plutus-nft/app/Main.hs index 66af3c79..8c6a88ee 100644 --- a/examples/plutus-nft/app/Main.hs +++ b/examples/plutus-nft/app/Main.hs @@ -11,6 +11,7 @@ import Cardano.PlutusExample.NFT ( import Data.Aeson qualified as JSON import Data.Aeson.TH (defaultOptions, deriveJSON) import Data.ByteString.Lazy qualified as LazyByteString +import Data.Maybe (fromMaybe) import Ledger.Value (TokenName) import MLabsPAB qualified import MLabsPAB.Types ( @@ -46,7 +47,9 @@ $(deriveJSON defaultOptions ''MintNFTContracts) main :: IO () main = do - protocolParams <- JSON.decode <$> LazyByteString.readFile "protocol.json" + protocolParams <- + fromMaybe (error "protocol.json file not found") . JSON.decode + <$> LazyByteString.readFile "protocol.json" let pabConf = PABConfig { pcCliLocation = Local diff --git a/examples/plutus-transfer/app/Main.hs b/examples/plutus-transfer/app/Main.hs index 65370a39..f3f0bbc7 100644 --- a/examples/plutus-transfer/app/Main.hs +++ b/examples/plutus-transfer/app/Main.hs @@ -9,11 +9,11 @@ import Cardano.PlutusExample.Transfer ( transfer, ) import Data.Aeson qualified as JSON -import Ledger.Value (Value) import Data.Aeson.TH (defaultOptions, deriveJSON) import Data.ByteString.Lazy qualified as LazyByteString import Data.Maybe (fromMaybe) import Ledger.Crypto (PubKeyHash) +import Ledger.Value (Value) import MLabsPAB qualified import MLabsPAB.Types ( CLILocation (Local), From 77a9b6c05fef9104c13f54c259f4d0bc3328f502 Mon Sep 17 00:00:00 2001 From: gege251 Date: Thu, 20 Jan 2022 19:15:22 +0100 Subject: [PATCH 4/4] Rename example script files --- examples/plutus-transfer/{run.sh => ada-transfer.sh} | 0 examples/plutus-transfer/{run2.sh => token-transfer.sh} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename examples/plutus-transfer/{run.sh => ada-transfer.sh} (100%) rename examples/plutus-transfer/{run2.sh => token-transfer.sh} (100%) diff --git a/examples/plutus-transfer/run.sh b/examples/plutus-transfer/ada-transfer.sh similarity index 100% rename from examples/plutus-transfer/run.sh rename to examples/plutus-transfer/ada-transfer.sh diff --git a/examples/plutus-transfer/run2.sh b/examples/plutus-transfer/token-transfer.sh similarity index 100% rename from examples/plutus-transfer/run2.sh rename to examples/plutus-transfer/token-transfer.sh