input-output-hk / plutus-pioneer-program

This repository hosts the lectures of the Plutus Pioneers Program. This program is a training course that the IOG Education Team provides to recruit and train software developers in Plutus, the native smart contract language for the Cardano ecosystem.
1.39k stars 987 forks source link

EnglishAuction.hs Error RE: ValidatorCtx not in scope #19

Closed top-shaman closed 3 years ago

top-shaman commented 3 years ago

Hi,

I've gotten my Plutus Playground set up in the browser-- i.e. the nix-shell's seem to be working properly. The Plutus Playground itself compiles the sample code ("Hello, world", "Starter", "Game", etc.) without any problems, so I don't think it's an issue with the playground itself. I've linked a GitHub repository with my 'plutus' folder-- it should be exactly the same as the IOHK plutus repository.

Anyway, when I copy the EnglishAuction.hs code I receive 5 compilation errors:

Compilation failed

Compilation Error, Line 113, Column 56 (jump)

error: Not in scope: type constructor or class ‘ValidatorCtx’ Perhaps you meant ‘Validator’ (imported from Ledger) | 113 | mkAuctionValidator :: AuctionDatum -> AuctionAction -> ValidatorCtx -> Bool | ^^^^^^^^^^^^

Compilation Error, Line 165, Column 20 (jump)

error: Not in scope: type constructor or class ‘TxOutInfo’ | 165 | ownOutput :: TxOutInfo | ^^^^^^^^^

Compilation Error, Line 169, Column 13 (jump)

error: Not in scope: data constructor ‘PayToPubKey’ | 169 | PayToPubKey -> traceError "wrong output type" | ^^^^^^^^^^^

Compilation Error, Line 170, Column 13 (jump)

error: Not in scope: data constructor ‘PayToScript’ | 170 | PayToScript h -> case findDatum h info of | ^^^^^^^^^^^

Compilation Error, Line 346, Column 13 (jump)

error: Not in scope: data constructor ‘PayToPubKey’ | 346 | PayToPubKey -> throwError "unexpected out type" | ^^^^^^^^^^^

Compilation Error, Line 347, Column 13 (jump)

error: Not in scope: data constructor ‘PayToScript’ | 347 | PayToScript h -> case Map.lookup h $ txData $ txOutTxTx o of

I'm wondering if I cloned the repository wrong, or if I installed ghcup/ghci/stack/cabal wrong, or if I built old/redundant repositories. Obviously I'm a noob, and I'm hoping this is the type of thing that someone can spot super easily, because I'm not too familiar with Nix or Cabal. Like I said, I was able to get the playground working, and it compiles/simulates the built-in demos. I'm just having issues with EnglishAuction.hs. I don't want to waste anybody else's time on this, but I really want to get started on the program because I've delved a LOT of hours into learning Haskell and I love the ethos/ecosystem Cardano/Plutus has to offer. Any help or pointers are welcome!

thanks, top-shaman

top-shaman commented 3 years ago

Ok-- so I did a few things to make this work. To clarify I'm on MacOS 10.14.6

  1. In the terminal I used nix-collect-garbage to clear my nix profiles
  2. Then I removed my nix files with sudo rm -rf /nix
  3. I had used ghcup to install cabal/stack/ghci, and I deleted all ghc versions and installed ghc 8.10.2-- you can see all versions installed with ghcup list, remove specific versions with ghcup rm ghc <version #>, and install with ghcup install ghc <version #>
  4. I deleted the cloned /plutus and /plutus-pioneer-program repositories, and recloned them
  5. I looked up the SHA of the plutus repository used in Week01 cabal.project of plutus-pioneer-program, ( 3746610e53654a1167aeb4c6294c6096d16b0502 ) and I created a branch with the HEAD at the SHA w/ git branch my-branch 3746610
  6. Then I reinstalled nix using sh <(curl -L https://nixos.org/nix/install) --daemon and followed all the steps, deleting/removing any file that the daemon prompted, and reran the installer
  7. Then I used spotlight search to find the /etc folder, and I opened a terminal at the /nix folder inside it
  8. To add the IOHK binary caches, in this terminal window enter ' sudo nano nix.conf '
  9. Inside the nano instance, I added:

    substituters = https://hydra.iohk.io https://iohk.cachix.org https://cache.nixos.org/ trusted-public-keys = hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= iohk.cachix.org-1:DpRUyj7h7V830dp/i6Nti+NEO2/nhblbov/8MW7Rqoo= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=

  10. Then I exited the nano instance.
  11. Inside the plutus-pioneer-program/code/week01/ file I ran cabal build
  12. After this, instead of before, I DID NOT BUILD THE HASKELL PACKAGES OR ARTIFACTS in the /plutus folder-- I just ran nix-shell in the /plutus folder and followed steps 4-9 on the Week #1 /plutus-pioneer-program README.md file. Running nix-shell, with the IOHK binary cache correctly written into the /etc/nix/nix.conf file, builds the plutus library in the shell, and before when I was doing cabal build on the plutus folder to build the plutus libraries, I was building a different version of the plutus-core with cabal, even though I was at the correct commit SHA.

If anyone else runs into the same issue I had, I hope this helps!