Plutus Pioneer in the wild. Questions and observations

Hello, hello, hello
Is there anybody out there
Just reply if you read this …

I’ve been going thru the wonderful Plutus PIoneer videos on youtube. I’m a Haskell newbie and have questions. Some are fundamental Haskell but others are about the Plutus processing model and how to be more efficient self learner. I posted some to the YouTube video comment and posted (1) here about a week ago but have yet to get response to any. So feeling kind of lonely.

Perhaps this is the wrong place for the questions below. If so, can someone point to appropo resource?

Questions:

– Is there a way to interact with the simulated Cardano node via the command line? Is so where might one find resources.

– So far the client code ( offchain ) and script/validator code ( onchain ) are in the same file and logic are tightly coupled.

The Homework2 example:

mkValidator :: PubKeyHash → Slot → () → ScriptContext → Bool

hints at a separation of concerns, i.e. what the wallet needs to know ( it’s own key ) and what the script needs to know ( the vesting window, i.e. SlotRange ).

But even here the script is wallet/client aware. This seems to be different from ol’school client/server model – where server exposes APIs and client builds views/services leveraging those APIs. Is this a premature or wrong interpretation?

– How does one inspect all the functions ( APIs ) for a given data structure.

For example ScriptContext, ctx, there exists a helper" function/api:

scriptContextTxInfo ctx

that returns the TxInfo for the given context.

That’s sweet but for the curious how does one inspect the docs to find all the “helper” functions/api given a ScriptContext. Also are there any helper functions to construct a default/dummy ScriptContext?

Observations(s):

Not a JavaScript person but working thru the Plutus Pioneer examples, it seems there is a lot of Plutus jargon to help the compiler ( for type safety ), so Plutus feels like Haskell-izing Javascript. Which is OK except there is already TypeScript. So wondering if there are deeper motivations for using Haskell ( is the body of academic provable code around Haskell? If so are these external tools or built into the Plutus platform.

Won’t be holding my breath for answers but will keep plugging along.

:slight_smile:

If you have hoogle installed and set to index the Plutus code, then you can query to find everywhere a particular type is used or function is defined. (Hoogle is often integrated into IDEs.) For example,

$ hoogle scriptContextTxInfo
Plutus.V1.Ledger.Api scriptContextTxInfo :: ScriptContext -> TxInfo
Plutus.V1.Ledger.Contexts scriptContextTxInfo :: ScriptContext -> TxInfo

$ hoogle ScriptContext
Plutus.V1.Ledger.Api data ScriptContext
Plutus.V1.Ledger.Api ScriptContext :: TxInfo -> ScriptPurpose -> ScriptContext
Plutus.V1.Ledger.Contexts data ScriptContext
Plutus.V1.Ledger.Contexts ScriptContext :: TxInfo -> ScriptPurpose -> ScriptContext
Plutus.V1.Ledger.Api scriptContextPurpose :: ScriptContext -> ScriptPurpose
Plutus.V1.Ledger.Api scriptContextTxInfo :: ScriptContext -> TxInfo
Plutus.V1.Ledger.Contexts scriptContextPurpose :: ScriptContext -> ScriptPurpose
Plutus.V1.Ledger.Contexts scriptContextTxInfo :: ScriptContext -> TxInfo

You can also browse the Plutus documentation or its index online, but I don’t know if that is always up to date. If you build the documentation locally, then it will be in sync with your installed version of Plutus.

P.S. The hoogle server command will run a local web server so you can search and browser the documentation.

:+1: sweet! thanks

Ha! Should have said “thanks for the pain”. :slight_smile:

Curious what version of hoogle you are using.

Me:

$ hoogle --version
Hoogle 5.0.18.1, https://hoogle.haskell.org/

Maybe suboptimal but here is my journey to get this working:

$ cabal install hoogle
//generate Haskell hoogle DB
$ hoogle generate

$ ls ~/.hoogle/
default-haskell-5.0.18.hoo input-haskell-hoogle.tar.gz
input-haskell-stackage-lts.txt default-haskell-5.0.18.warn input-haskell-cabal.tar.gz input-haskell-platform.txt input-haskell-stackage-nightly.txt

In the cloned plutus directory, ran:

$ cabal haddock --haddock-hoogle plutus-contract plutus-core plutus-errors plutus-ledger-api plutus-tx

Found all the plutus .txt databases:

$ find dist-newstyle -name *.txt -print | grep plutus
dist-newstyle/build/x86_64-linux/ghc-8.10.2/plutus-contract-0.1.0.0/doc/html/plutus-contract/plutus-contract.txt
dist-newstyle/build/x86_64-linux/ghc-8.10.2/plutus-ledger-api-0.1.0.0/doc/html/plutus-ledger-api/plutus-ledger-api.txt
dist-newstyle/build/x86_64-linux/ghc-8.10.2/plutus-core-0.1.0.0/doc/html/plutus-core/plutus-core.txt
dist-newstyle/build/x86_64-linux/ghc-8.10.2/plutus-tx-0.1.0.0/doc/html/plutus-tx/plutus-tx.txt
dist-newstyle/build/x86_64-linux/ghc-8.10.2/plutus-tx-plugin-0.1.0.0/doc/html/plutus-tx-plugin/plutus-tx-plugin.txt
dist-newstyle/build/x86_64-linux/ghc-8.10.2/plutus-errors-0.1.0.0/doc/html/plutus-errors/plutus-errors.txt

Collected them into a plutus folder

$ ls plutus
plutus-contract.txt plutus-core.txt plutus-errors.txt plutus-ledger-api.txt plutus-tx-plugin.txt plutus-tx.txt

Then generated a plutus.hoo database:

$ hoogle generate --local=foo --database plutus.hoo

Now can query:

$ hoogle ScriptContext --database=plutus.hoo
Plutus.V1.Ledger.Api data ScriptContext
Plutus.V1.Ledger.Api ScriptContext :: TxInfo → ScriptPurpose → ScriptContext
Plutus.V1.Ledger.Contexts data ScriptContext
Plutus.V1.Ledger.Contexts ScriptContext :: TxInfo → ScriptPurpose → ScriptContext
Plutus.V1.Ledger.Api scriptContextPurpose :: ScriptContext → ScriptPurpose
Plutus.V1.Ledger.Api scriptContextTxInfo :: ScriptContext → TxInfo
Plutus.V1.Ledger.Contexts scriptContextPurpose :: ScriptContext → ScriptPurpose
Plutus.V1.Ledger.Contexts scriptContextTxInfo :: ScriptContext → TxInfo$ ls ~/.hoogle/

Kind of a hassle but hopefully worth it as I like to see what options are available to manipulate data structures both to learn and to give idea about what is possible.

1 Like

I’m glad to see you got Hoogle set up for Plutus, even though it was painful. Your setup looks reasonable optimal.

Working with Plutus or cardano-node, I find myself using hoogle very frequently to navigate the API, especially since the API is changing. BTW, the --info and --link options are sometimes helpful, as is hoogle server for viewing the full documentation online locally.

I’m using Hoogle 5.0.17.15, but doing so in NixOS. Because Plutus comes with the Nix derivations for all of the Plutus and Marlowe stuff, I just need to execute nix-shell with the following file shell.nix in the folder above where plutus/ resides. Nix will automatically build (or fetch from caches) Plutus and its documentation, and wire that into Hoogle. The key to this is the Nix function ghcWithHoogle. So there is a less painful way, but to get there one has to experience the alternative pain of setting up Nix.

{
  system ? builtins.currentSystem
, config ? { allowUnfreePredicate = (import ./plutus/nix/unfree.nix).unfreePredicate; }
, packages ? import ./plutus { inherit system config ; }
}:
let
  inherit (packages) pkgs;
  ghc = packages.plutus.haskell.project.ghcWithHoogle (ps: with ps; [
    marlowe-playground-server
    plutus-playground-server
  ]);
in
  pkgs.stdenv.mkDerivation {
    name = "plutus-env";
    buildInputs = [
      pkgs.cabal-install
      ghc
    ];
  }

tha! reminded me that dev environments are like eggs, coffee and loading the dishwasher – everyone has their way and why their way makes the most sense.

thanks again – i think :slight_smile:

1 Like

https://github.com/input-output-hk/plutus/tree/master/plutus-ledger-api/src/Plutus/V1/Ledger

1 Like

Here are two more resources: