From a72fe6193d76f416dfca64cc78c99bb997b2a74c Mon Sep 17 00:00:00 2001 From: Evgenii Akentev Date: Wed, 12 Jan 2022 14:36:52 +0500 Subject: [PATCH 1/3] Fix the problem with pab-nami-demo psapigenerator #235 --- default.nix | 2 +- .../.plan.nix/plutus-pab-executables.nix | 31 +++++++++++++++++++ .../haskell/materialized-darwin/default.nix | 1 + .../.plan.nix/plutus-pab-executables.nix | 31 +++++++++++++++++++ .../haskell/materialized-linux/default.nix | 1 + .../.plan.nix/plutus-pab-executables.nix | 31 +++++++++++++++++++ .../haskell/materialized-windows/default.nix | 1 + .../demo/pab-nami/client/default.nix | 8 ++--- .../demo/pab-nami/pab/app/Generator.hs | 28 +++++++++++++++++ .../plutus-pab-executables.cabal | 31 +++++++++++++++++++ 10 files changed, 160 insertions(+), 5 deletions(-) create mode 100644 plutus-pab-executables/demo/pab-nami/pab/app/Generator.hs diff --git a/default.nix b/default.nix index 7a0e7bdfcc..69ba4601b5 100644 --- a/default.nix +++ b/default.nix @@ -56,7 +56,7 @@ rec { inherit (pkgs.callPackage ./plutus-pab-executables/demo/pab-nami/client { inherit pkgs haskell webCommon; inherit (plutus-apps.lib) buildPursPackage buildNodeModules filterNpm gitignore-nix; - }) client pab-setup-invoker pab-nami-demo-invoker generate-purescript generated-purescript start-backend; + }) client pab-setup-invoker pab-nami-demo-invoker pab-nami-demo-generator generate-purescript generated-purescript start-backend; }; plutus-use-cases = pkgs.recurseIntoAttrs (pkgs.callPackage ./plutus-use-cases { diff --git a/nix/pkgs/haskell/materialized-darwin/.plan.nix/plutus-pab-executables.nix b/nix/pkgs/haskell/materialized-darwin/.plan.nix/plutus-pab-executables.nix index 021f1e8830..e78896e0ec 100644 --- a/nix/pkgs/haskell/materialized-darwin/.plan.nix/plutus-pab-executables.nix +++ b/nix/pkgs/haskell/materialized-darwin/.plan.nix/plutus-pab-executables.nix @@ -327,6 +327,37 @@ "Main.hs" ] ++ (pkgs.lib).optional (flags.defer-plugin-errors) ""; }; + "plutus-pab-nami-demo-generator" = { + depends = [ + (hsPkgs."aeson" or (errorHandler.buildDepError "aeson")) + (hsPkgs."async" or (errorHandler.buildDepError "async")) + (hsPkgs."base" or (errorHandler.buildDepError "base")) + (hsPkgs."cardano-api" or (errorHandler.buildDepError "cardano-api")) + (hsPkgs."data-default" or (errorHandler.buildDepError "data-default")) + (hsPkgs."filepath" or (errorHandler.buildDepError "filepath")) + (hsPkgs."freer-extras" or (errorHandler.buildDepError "freer-extras")) + (hsPkgs."freer-simple" or (errorHandler.buildDepError "freer-simple")) + (hsPkgs."openapi3" or (errorHandler.buildDepError "openapi3")) + (hsPkgs."optparse-applicative" or (errorHandler.buildDepError "optparse-applicative")) + (hsPkgs."plutus-chain-index" or (errorHandler.buildDepError "plutus-chain-index")) + (hsPkgs."plutus-contract" or (errorHandler.buildDepError "plutus-contract")) + (hsPkgs."plutus-pab" or (errorHandler.buildDepError "plutus-pab")) + (hsPkgs."plutus-pab-executables".components.sublibs.plutus-pab-psgenerator or (errorHandler.buildDepError "plutus-pab-executables:plutus-pab-psgenerator")) + (hsPkgs."playground-common" or (errorHandler.buildDepError "playground-common")) + (hsPkgs."prettyprinter" or (errorHandler.buildDepError "prettyprinter")) + (hsPkgs."purescript-bridge" or (errorHandler.buildDepError "purescript-bridge")) + (hsPkgs."plutus-ledger" or (errorHandler.buildDepError "plutus-ledger")) + (hsPkgs."plutus-ledger-constraints" or (errorHandler.buildDepError "plutus-ledger-constraints")) + (hsPkgs."row-types" or (errorHandler.buildDepError "row-types")) + (hsPkgs."text" or (errorHandler.buildDepError "text")) + ]; + buildable = true; + modules = [ "DemoContract" ]; + hsSourceDirs = [ "demo/pab-nami/pab/app" ]; + mainPath = [ + "Generator.hs" + ] ++ (pkgs.lib).optional (flags.defer-plugin-errors) ""; + }; }; tests = { "plutus-pab-test-full" = { diff --git a/nix/pkgs/haskell/materialized-darwin/default.nix b/nix/pkgs/haskell/materialized-darwin/default.nix index 8f887a0808..118e7514a7 100644 --- a/nix/pkgs/haskell/materialized-darwin/default.nix +++ b/nix/pkgs/haskell/materialized-darwin/default.nix @@ -1442,6 +1442,7 @@ "aeson-casing".components.library.planned = lib.mkOverride 900 true; "cardano-crypto-tests".components.library.planned = lib.mkOverride 900 true; "cardano-wallet".components.exes."cardano-wallet".planned = lib.mkOverride 900 true; + "plutus-pab-executables".components.exes."plutus-pab-nami-demo-generator".planned = lib.mkOverride 900 true; "servant-foreign".components.library.planned = lib.mkOverride 900 true; "contravariant".components.library.planned = lib.mkOverride 900 true; "optparse-generic".components.library.planned = lib.mkOverride 900 true; diff --git a/nix/pkgs/haskell/materialized-linux/.plan.nix/plutus-pab-executables.nix b/nix/pkgs/haskell/materialized-linux/.plan.nix/plutus-pab-executables.nix index 021f1e8830..e78896e0ec 100644 --- a/nix/pkgs/haskell/materialized-linux/.plan.nix/plutus-pab-executables.nix +++ b/nix/pkgs/haskell/materialized-linux/.plan.nix/plutus-pab-executables.nix @@ -327,6 +327,37 @@ "Main.hs" ] ++ (pkgs.lib).optional (flags.defer-plugin-errors) ""; }; + "plutus-pab-nami-demo-generator" = { + depends = [ + (hsPkgs."aeson" or (errorHandler.buildDepError "aeson")) + (hsPkgs."async" or (errorHandler.buildDepError "async")) + (hsPkgs."base" or (errorHandler.buildDepError "base")) + (hsPkgs."cardano-api" or (errorHandler.buildDepError "cardano-api")) + (hsPkgs."data-default" or (errorHandler.buildDepError "data-default")) + (hsPkgs."filepath" or (errorHandler.buildDepError "filepath")) + (hsPkgs."freer-extras" or (errorHandler.buildDepError "freer-extras")) + (hsPkgs."freer-simple" or (errorHandler.buildDepError "freer-simple")) + (hsPkgs."openapi3" or (errorHandler.buildDepError "openapi3")) + (hsPkgs."optparse-applicative" or (errorHandler.buildDepError "optparse-applicative")) + (hsPkgs."plutus-chain-index" or (errorHandler.buildDepError "plutus-chain-index")) + (hsPkgs."plutus-contract" or (errorHandler.buildDepError "plutus-contract")) + (hsPkgs."plutus-pab" or (errorHandler.buildDepError "plutus-pab")) + (hsPkgs."plutus-pab-executables".components.sublibs.plutus-pab-psgenerator or (errorHandler.buildDepError "plutus-pab-executables:plutus-pab-psgenerator")) + (hsPkgs."playground-common" or (errorHandler.buildDepError "playground-common")) + (hsPkgs."prettyprinter" or (errorHandler.buildDepError "prettyprinter")) + (hsPkgs."purescript-bridge" or (errorHandler.buildDepError "purescript-bridge")) + (hsPkgs."plutus-ledger" or (errorHandler.buildDepError "plutus-ledger")) + (hsPkgs."plutus-ledger-constraints" or (errorHandler.buildDepError "plutus-ledger-constraints")) + (hsPkgs."row-types" or (errorHandler.buildDepError "row-types")) + (hsPkgs."text" or (errorHandler.buildDepError "text")) + ]; + buildable = true; + modules = [ "DemoContract" ]; + hsSourceDirs = [ "demo/pab-nami/pab/app" ]; + mainPath = [ + "Generator.hs" + ] ++ (pkgs.lib).optional (flags.defer-plugin-errors) ""; + }; }; tests = { "plutus-pab-test-full" = { diff --git a/nix/pkgs/haskell/materialized-linux/default.nix b/nix/pkgs/haskell/materialized-linux/default.nix index 6667cb224c..ef5fa1432d 100644 --- a/nix/pkgs/haskell/materialized-linux/default.nix +++ b/nix/pkgs/haskell/materialized-linux/default.nix @@ -1450,6 +1450,7 @@ "aeson-casing".components.library.planned = lib.mkOverride 900 true; "cardano-crypto-tests".components.library.planned = lib.mkOverride 900 true; "cardano-wallet".components.exes."cardano-wallet".planned = lib.mkOverride 900 true; + "plutus-pab-executables".components.exes."plutus-pab-nami-demo-generator".planned = lib.mkOverride 900 true; "servant-foreign".components.library.planned = lib.mkOverride 900 true; "contravariant".components.library.planned = lib.mkOverride 900 true; "optparse-generic".components.library.planned = lib.mkOverride 900 true; diff --git a/nix/pkgs/haskell/materialized-windows/.plan.nix/plutus-pab-executables.nix b/nix/pkgs/haskell/materialized-windows/.plan.nix/plutus-pab-executables.nix index 021f1e8830..e78896e0ec 100644 --- a/nix/pkgs/haskell/materialized-windows/.plan.nix/plutus-pab-executables.nix +++ b/nix/pkgs/haskell/materialized-windows/.plan.nix/plutus-pab-executables.nix @@ -327,6 +327,37 @@ "Main.hs" ] ++ (pkgs.lib).optional (flags.defer-plugin-errors) ""; }; + "plutus-pab-nami-demo-generator" = { + depends = [ + (hsPkgs."aeson" or (errorHandler.buildDepError "aeson")) + (hsPkgs."async" or (errorHandler.buildDepError "async")) + (hsPkgs."base" or (errorHandler.buildDepError "base")) + (hsPkgs."cardano-api" or (errorHandler.buildDepError "cardano-api")) + (hsPkgs."data-default" or (errorHandler.buildDepError "data-default")) + (hsPkgs."filepath" or (errorHandler.buildDepError "filepath")) + (hsPkgs."freer-extras" or (errorHandler.buildDepError "freer-extras")) + (hsPkgs."freer-simple" or (errorHandler.buildDepError "freer-simple")) + (hsPkgs."openapi3" or (errorHandler.buildDepError "openapi3")) + (hsPkgs."optparse-applicative" or (errorHandler.buildDepError "optparse-applicative")) + (hsPkgs."plutus-chain-index" or (errorHandler.buildDepError "plutus-chain-index")) + (hsPkgs."plutus-contract" or (errorHandler.buildDepError "plutus-contract")) + (hsPkgs."plutus-pab" or (errorHandler.buildDepError "plutus-pab")) + (hsPkgs."plutus-pab-executables".components.sublibs.plutus-pab-psgenerator or (errorHandler.buildDepError "plutus-pab-executables:plutus-pab-psgenerator")) + (hsPkgs."playground-common" or (errorHandler.buildDepError "playground-common")) + (hsPkgs."prettyprinter" or (errorHandler.buildDepError "prettyprinter")) + (hsPkgs."purescript-bridge" or (errorHandler.buildDepError "purescript-bridge")) + (hsPkgs."plutus-ledger" or (errorHandler.buildDepError "plutus-ledger")) + (hsPkgs."plutus-ledger-constraints" or (errorHandler.buildDepError "plutus-ledger-constraints")) + (hsPkgs."row-types" or (errorHandler.buildDepError "row-types")) + (hsPkgs."text" or (errorHandler.buildDepError "text")) + ]; + buildable = true; + modules = [ "DemoContract" ]; + hsSourceDirs = [ "demo/pab-nami/pab/app" ]; + mainPath = [ + "Generator.hs" + ] ++ (pkgs.lib).optional (flags.defer-plugin-errors) ""; + }; }; tests = { "plutus-pab-test-full" = { diff --git a/nix/pkgs/haskell/materialized-windows/default.nix b/nix/pkgs/haskell/materialized-windows/default.nix index 45a387bb14..65148ac901 100644 --- a/nix/pkgs/haskell/materialized-windows/default.nix +++ b/nix/pkgs/haskell/materialized-windows/default.nix @@ -1420,6 +1420,7 @@ "aeson-casing".components.library.planned = lib.mkOverride 900 true; "cardano-crypto-tests".components.library.planned = lib.mkOverride 900 true; "cardano-wallet".components.exes."cardano-wallet".planned = lib.mkOverride 900 true; + "plutus-pab-executables".components.exes."plutus-pab-nami-demo-generator".planned = lib.mkOverride 900 true; "servant-foreign".components.library.planned = lib.mkOverride 900 true; "contravariant".components.library.planned = lib.mkOverride 900 true; "optparse-generic".components.library.planned = lib.mkOverride 900 true; diff --git a/plutus-pab-executables/demo/pab-nami/client/default.nix b/plutus-pab-executables/demo/pab-nami/client/default.nix index 2e7ecb2770..6e5248a2aa 100644 --- a/plutus-pab-executables/demo/pab-nami/client/default.nix +++ b/plutus-pab-executables/demo/pab-nami/client/default.nix @@ -1,6 +1,7 @@ { pkgs, gitignore-nix, haskell, webCommon, buildPursPackage, buildNodeModules, filterNpm }: let pab-nami-demo-invoker = haskell.packages.plutus-pab-executables.components.exes.plutus-pab-nami-demo; + pab-nami-demo-generator = haskell.packages.plutus-pab-executables.components.exes.plutus-pab-nami-demo-generator; pab-setup-invoker = haskell.packages.plutus-pab-executables.components.exes.plutus-pab-setup; @@ -8,15 +9,14 @@ let generated-purescript = pkgs.runCommand "pab-nami-demo-purescript" { } '' mkdir $out ${pab-setup-invoker}/bin/plutus-pab-setup psgenerator $out - ln -s ${../pab/plutus-pab.yaml} plutus-pab.yaml - ${pab-nami-demo-invoker}/bin/plutus-pab-nami-demo --config ../pab/plutus-pab.yaml psapigenerator $out + ${pab-nami-demo-generator}/bin/plutus-pab-nami-demo-generator --output-dir $out ''; generate-purescript = pkgs.writeShellScriptBin "pab-nami-demo-generate-purs" '' generatedDir=./generated rm -rf $generatedDir $(nix-build ../../../../default.nix -A pab-nami-demo.pab-setup-invoker)/bin/plutus-pab-setup psgenerator $generatedDir - $(nix-build ../../../../default.nix -A pab-nami-demo.pab-nami-demo-invoker)/bin/plutus-pab-nami-demo --config ../pab/plutus-pab.yaml psapigenerator $generatedDir + $(nix-build ../../../../default.nix -A pab-nami-demo.pab-nami-demo-generator)/bin/plutus-pab-nami-demo-generator --output-dir $generatedDir ''; start-backend = pkgs.writeShellScriptBin "pab-nami-demo-server" '' @@ -53,5 +53,5 @@ let }); in { - inherit client pab-nami-demo-invoker pab-setup-invoker generate-purescript generated-purescript start-backend; + inherit client pab-nami-demo-invoker pab-nami-demo-generator pab-setup-invoker generate-purescript generated-purescript start-backend; } diff --git a/plutus-pab-executables/demo/pab-nami/pab/app/Generator.hs b/plutus-pab-executables/demo/pab-nami/pab/app/Generator.hs new file mode 100644 index 0000000000..88d5470211 --- /dev/null +++ b/plutus-pab-executables/demo/pab-nami/pab/app/Generator.hs @@ -0,0 +1,28 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TypeApplications #-} + +module Main + ( main + ) where + +import Data.Proxy +import DemoContract (DemoContract) +import Options.Applicative +import Plutus.PAB.Run.PSGenerator qualified as PSGenerator + +parseOptions :: IO FilePath +parseOptions = customExecParser + (prefs $ disambiguate <> showHelpOnEmpty <> showHelpOnError) + (info (helper <*> psGenOutputDirParser) idm) + +psGenOutputDirParser :: Parser FilePath +psGenOutputDirParser = option str + (long "output-dir" <> + metavar "OUTPUT_DIR" <> + help "Output directory to write PureScript files to.") + +main :: IO () +main = do + psGenOutputDir <- parseOptions + PSGenerator.generateAPIModule (Proxy :: Proxy DemoContract) psGenOutputDir + PSGenerator.generateWith @DemoContract psGenOutputDir diff --git a/plutus-pab-executables/plutus-pab-executables.cabal b/plutus-pab-executables/plutus-pab-executables.cabal index b6e338d6cb..4b6862137e 100644 --- a/plutus-pab-executables/plutus-pab-executables.cabal +++ b/plutus-pab-executables/plutus-pab-executables.cabal @@ -514,3 +514,34 @@ executable plutus-pab-nami-demo plutus-ledger-constraints -any, row-types -any, text -any, + +executable plutus-pab-nami-demo-generator + import: lang + main-is: Generator.hs + hs-source-dirs: demo/pab-nami/pab/app + other-modules: + DemoContract + ghc-options: + -threaded + build-depends: + aeson -any, + async -any, + base >= 4.9 && < 5, + cardano-api -any, + data-default -any, + filepath -any, + freer-extras -any, + freer-simple -any, + openapi3 -any, + optparse-applicative -any, + plutus-chain-index -any, + plutus-contract -any, + plutus-pab -any, + plutus-pab-psgenerator -any, + playground-common -any, + prettyprinter -any, + purescript-bridge -any, + plutus-ledger -any, + plutus-ledger-constraints -any, + row-types -any, + text -any, From b495cdb14c866bd16eed60bfe3a86d16c3111b96 Mon Sep 17 00:00:00 2001 From: Evgenii Akentev Date: Wed, 12 Jan 2022 15:34:32 +0500 Subject: [PATCH 2/3] fix --- .../materialized-darwin/.plan.nix/plutus-pab-executables.nix | 2 +- .../materialized-linux/.plan.nix/plutus-pab-executables.nix | 2 +- .../materialized-windows/.plan.nix/plutus-pab-executables.nix | 2 +- plutus-pab-executables/plutus-pab-executables.cabal | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nix/pkgs/haskell/materialized-darwin/.plan.nix/plutus-pab-executables.nix b/nix/pkgs/haskell/materialized-darwin/.plan.nix/plutus-pab-executables.nix index e78896e0ec..95ce66d85e 100644 --- a/nix/pkgs/haskell/materialized-darwin/.plan.nix/plutus-pab-executables.nix +++ b/nix/pkgs/haskell/materialized-darwin/.plan.nix/plutus-pab-executables.nix @@ -342,7 +342,7 @@ (hsPkgs."plutus-chain-index" or (errorHandler.buildDepError "plutus-chain-index")) (hsPkgs."plutus-contract" or (errorHandler.buildDepError "plutus-contract")) (hsPkgs."plutus-pab" or (errorHandler.buildDepError "plutus-pab")) - (hsPkgs."plutus-pab-executables".components.sublibs.plutus-pab-psgenerator or (errorHandler.buildDepError "plutus-pab-executables:plutus-pab-psgenerator")) + (hsPkgs."plutus-pab-executables" or (errorHandler.buildDepError "plutus-pab-executables")) (hsPkgs."playground-common" or (errorHandler.buildDepError "playground-common")) (hsPkgs."prettyprinter" or (errorHandler.buildDepError "prettyprinter")) (hsPkgs."purescript-bridge" or (errorHandler.buildDepError "purescript-bridge")) diff --git a/nix/pkgs/haskell/materialized-linux/.plan.nix/plutus-pab-executables.nix b/nix/pkgs/haskell/materialized-linux/.plan.nix/plutus-pab-executables.nix index e78896e0ec..95ce66d85e 100644 --- a/nix/pkgs/haskell/materialized-linux/.plan.nix/plutus-pab-executables.nix +++ b/nix/pkgs/haskell/materialized-linux/.plan.nix/plutus-pab-executables.nix @@ -342,7 +342,7 @@ (hsPkgs."plutus-chain-index" or (errorHandler.buildDepError "plutus-chain-index")) (hsPkgs."plutus-contract" or (errorHandler.buildDepError "plutus-contract")) (hsPkgs."plutus-pab" or (errorHandler.buildDepError "plutus-pab")) - (hsPkgs."plutus-pab-executables".components.sublibs.plutus-pab-psgenerator or (errorHandler.buildDepError "plutus-pab-executables:plutus-pab-psgenerator")) + (hsPkgs."plutus-pab-executables" or (errorHandler.buildDepError "plutus-pab-executables")) (hsPkgs."playground-common" or (errorHandler.buildDepError "playground-common")) (hsPkgs."prettyprinter" or (errorHandler.buildDepError "prettyprinter")) (hsPkgs."purescript-bridge" or (errorHandler.buildDepError "purescript-bridge")) diff --git a/nix/pkgs/haskell/materialized-windows/.plan.nix/plutus-pab-executables.nix b/nix/pkgs/haskell/materialized-windows/.plan.nix/plutus-pab-executables.nix index e78896e0ec..95ce66d85e 100644 --- a/nix/pkgs/haskell/materialized-windows/.plan.nix/plutus-pab-executables.nix +++ b/nix/pkgs/haskell/materialized-windows/.plan.nix/plutus-pab-executables.nix @@ -342,7 +342,7 @@ (hsPkgs."plutus-chain-index" or (errorHandler.buildDepError "plutus-chain-index")) (hsPkgs."plutus-contract" or (errorHandler.buildDepError "plutus-contract")) (hsPkgs."plutus-pab" or (errorHandler.buildDepError "plutus-pab")) - (hsPkgs."plutus-pab-executables".components.sublibs.plutus-pab-psgenerator or (errorHandler.buildDepError "plutus-pab-executables:plutus-pab-psgenerator")) + (hsPkgs."plutus-pab-executables" or (errorHandler.buildDepError "plutus-pab-executables")) (hsPkgs."playground-common" or (errorHandler.buildDepError "playground-common")) (hsPkgs."prettyprinter" or (errorHandler.buildDepError "prettyprinter")) (hsPkgs."purescript-bridge" or (errorHandler.buildDepError "purescript-bridge")) diff --git a/plutus-pab-executables/plutus-pab-executables.cabal b/plutus-pab-executables/plutus-pab-executables.cabal index 4b6862137e..bbcf1aecd8 100644 --- a/plutus-pab-executables/plutus-pab-executables.cabal +++ b/plutus-pab-executables/plutus-pab-executables.cabal @@ -537,7 +537,7 @@ executable plutus-pab-nami-demo-generator plutus-chain-index -any, plutus-contract -any, plutus-pab -any, - plutus-pab-psgenerator -any, + plutus-pab-executables -any, playground-common -any, prettyprinter -any, purescript-bridge -any, From 94d16edb876b867dafcbefc948a1ee082e9683c8 Mon Sep 17 00:00:00 2001 From: Evgenii Akentev Date: Wed, 12 Jan 2022 15:38:28 +0500 Subject: [PATCH 3/3] Update readme --- plutus-pab-executables/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plutus-pab-executables/README.md b/plutus-pab-executables/README.md index 91c52e3121..b1260d17ae 100644 --- a/plutus-pab-executables/README.md +++ b/plutus-pab-executables/README.md @@ -89,6 +89,8 @@ $ cabal exec plutus-pab-setup -- psgenerator generated Generates the purescript bridge code. +`psgenerator` generates only default types. If you want to generate types for your contracts you have to write your own small generator. Take a look at `plutus-pab-nami-demo-generator` for an example. It's a small executable that calls `PSGenerator.generateAPIModule` and `PSGenerator.generateWith` with a custom contract type. + #### Source - [src/Plutus/PAB/Run/PSGenerator.hs](https://github.com/input-output-hk/plutus-apps/blob/main/plutus-pab/src/Plutus/PAB/Run/PSGenerator.hs)