Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Fix the problem with pab-nami-demo psapigenerator #235 #241

Merged
3 commits merged into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

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

1 change: 1 addition & 0 deletions nix/pkgs/haskell/materialized-darwin/default.nix

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

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

1 change: 1 addition & 0 deletions nix/pkgs/haskell/materialized-linux/default.nix

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

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

1 change: 1 addition & 0 deletions nix/pkgs/haskell/materialized-windows/default.nix

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

2 changes: 2 additions & 0 deletions plutus-pab-executables/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions plutus-pab-executables/demo/pab-nami/client/default.nix
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{ 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;

# TODO: Use the PS generator in the demo app
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" ''
Expand Down Expand Up @@ -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;
}
28 changes: 28 additions & 0 deletions plutus-pab-executables/demo/pab-nami/pab/app/Generator.hs
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions plutus-pab-executables/plutus-pab-executables.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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-executables -any,
playground-common -any,
prettyprinter -any,
purescript-bridge -any,
plutus-ledger -any,
plutus-ledger-constraints -any,
row-types -any,
text -any,