Skip to content

Commit

Permalink
adjusting versions so that hls works with ormolu and ghc
Browse files Browse the repository at this point in the history
  • Loading branch information
mmontin committed Mar 25, 2024
1 parent 7e42c78 commit 5f3a830
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 42 deletions.
2 changes: 1 addition & 1 deletion cooked-validators.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.4

-- This file has been generated from package.yaml by hpack version 0.36.0.
-- This file has been generated from package.yaml by hpack version 0.35.2.
--
-- see: https://github.com/sol/hpack

Expand Down
81 changes: 59 additions & 22 deletions flake.lock

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

14 changes: 6 additions & 8 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
## We need this specific version to target HLS 2.2.0.0
## This is required because we are stuck with GHC 8.10.7 thanks to plutus-apps
inputs.nixpkgs.url = "github:NixOS/nixpkgs";
inputs.nixpkgs.url =
"github:NixOS/nixpkgs/63143ac2c9186be6d9da6035fa22620018c85932";
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
inputs.pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs";
Expand All @@ -10,7 +9,7 @@
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
hpkgs = pkgs.haskell.packages.ghc964;
hpkgs = pkgs.haskell.packages.ghc963;

pre-commit = pre-commit-hooks.lib.${system}.run {
src = ./.;
Expand All @@ -36,8 +35,7 @@

devShells = let
## The minimal dependency set to build the project with `cabal`.
buildInputs = ([ hpkgs.ghc ]) ++ (with pkgs; [
cabal-install
buildInputs = (with hpkgs; [ ghc cabal-install ]) ++ (with pkgs; [
libsodium
secp256k1
pkg-config
Expand Down Expand Up @@ -70,8 +68,8 @@
## in the `buildInputs`, so as to take precedence. This ensures that the
## version of Ormolu available in the path is that of nixpkgs and not the
## one pinned by HLS.
buildInputs = buildInputs ++ (with pkgs; [ ormolu hpack hlint ])
++ (with hpkgs; [ haskell-language-server ]);
buildInputs = buildInputs ++ (with pkgs; [ hpack hlint ])
++ (with hpkgs; [ ormolu haskell-language-server ]);

inherit LD_LIBRARY_PATH;
inherit LANG;
Expand Down
5 changes: 5 additions & 0 deletions hie.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
cradle:
cabal:
- path: "./src"
component: "lib:cooked-validators"

- path: "./tests/"
component: "cooked-validators:test:spec"
3 changes: 2 additions & 1 deletion src/Cooked/Currencies.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ module Cooked.Currencies
where

import qualified Ledger.Typed.Scripts as Scripts
import qualified Plutus.Script.Utils.Scripts as Pl
import qualified Plutus.Script.Utils.V2.Scripts as Validation
import qualified Plutus.Script.Utils.Value as Pl
import qualified Plutus.V2.Ledger.Api as Pl
import qualified PlutusLedgerApi.V3 as Pl
import qualified PlutusTx
import qualified PlutusTx.Builtins.Class as Pl
import PlutusTx.Prelude hiding (Applicative (..))
Expand Down
8 changes: 4 additions & 4 deletions src/Cooked/Output.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ import qualified Plutus.Script.Utils.Ada as Pl
import qualified Plutus.Script.Utils.Scripts as Pl hiding (validatorHash)
import qualified Plutus.Script.Utils.V2.Typed.Scripts.Validators as Pl
import qualified Plutus.Script.Utils.Value as Pl
import qualified Plutus.V2.Ledger.Api as Pl
import qualified Plutus.V2.Ledger.Tx as Pl
import qualified PlutusLedgerApi.V2.Tx as Pl
import qualified PlutusLedgerApi.V3 as Pl

-- | A generalisation of 'Pl.TxOut': With the four type families, we can lift
-- some information about
Expand Down Expand Up @@ -81,7 +81,7 @@ instance ToCredential Pl.Credential where
toCredential = id

instance ToCredential (Pl.TypedValidator a) where
toCredential = Pl.ScriptCredential . Pl.validatorHash
toCredential = Pl.ScriptCredential . toScriptHash . Pl.validatorHash

instance ToCredential Pl.PubKeyHash where
toCredential = Pl.PubKeyCredential
Expand Down Expand Up @@ -307,7 +307,7 @@ isScriptOutputFrom ::
isScriptOutputFrom validator out =
case outputAddress out of
Pl.Address (Pl.ScriptCredential scriptHash) mStCred ->
if scriptHash == Pl.validatorHash validator
if scriptHash == toScriptHash validator
then
Just $
ConcreteOutput
Expand Down
9 changes: 5 additions & 4 deletions src/Cooked/RawUPLC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ where

import qualified Data.ByteString as BS
import qualified Flat
import Ledger.Scripts (Language (PlutusV2), Script (..), Validator (..), Versioned (Versioned))
import qualified Ledger.Typed.Scripts as TScripts
import Plutus.Script.Utils.Scripts (Language (PlutusV3), Script (..), Validator (Validator), Versioned (..))
import qualified PlutusLedgerApi.V3 as Pl
import Unsafe.Coerce
import qualified UntypedPlutusCore as UPLC

Expand All @@ -35,20 +36,20 @@ unsafeTypedValidatorFromUPLC = unsafeCoerce . typedValidatorFromUPLC
typedValidatorFromUPLC ::
UPLC.Program UPLC.NamedDeBruijn UPLC.DefaultUni UPLC.DefaultFun () ->
TScripts.TypedValidator TScripts.Any
typedValidatorFromUPLC = TScripts.unsafeMkTypedValidator . flip Versioned PlutusV2 . Validator . fromPlc
typedValidatorFromUPLC = TScripts.unsafeMkTypedValidator . flip Versioned PlutusV3 . Validator . fromPlc
where
-- copied from: github.com/input-output-hk/plutus/blob/1f31e640e8a258185db01fa899da63f9018c0e85/plutus-ledger-api/src/Plutus/V1/Ledger/Scripts.hs#L169
fromPlc :: UPLC.Program UPLC.NamedDeBruijn UPLC.DefaultUni UPLC.DefaultFun () -> Script
fromPlc (UPLC.Program a v t) =
let nameless = UPLC.termMapNames UPLC.unNameDeBruijn t
in Script $ UPLC.Program a v nameless
in Script $ Pl.serialiseUPLC $ UPLC.Program a v nameless

-- | Loads a typed validator from a bytestring that was produced by 'Flat.flat' the outputs
-- of [getPlc](https://github.com/input-output-hk/plutus/blob/master/plutus-tx/src/PlutusTx/Code.hs#L84)
-- applied to a 'TScripts.mkTypedValidator'. If the compiled validator was /not/ wrapped,
-- stick to 'typedValidatorFromBS'.
unsafeTypedValidatorFromBS :: forall a. BS.ByteString -> Either String (TScripts.TypedValidator a)
unsafeTypedValidatorFromBS = either (Left . show) (Right . unsafeTypedValidatorFromUPLC) . Flat.unflat
unsafeTypedValidatorFromBS = either (Left . show) (Right . unsafeTypedValidatorFromUPLC) . undefined

-- | Loads a typed validator from a bytestring that was produced by 'Flat.flat' the outputs
-- of [getPlc](https://github.com/input-output-hk/plutus/blob/master/plutus-tx/src/PlutusTx/Code.hs#L84).
Expand Down
3 changes: 1 addition & 2 deletions src/Cooked/Wallet.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}

Expand Down Expand Up @@ -27,8 +26,8 @@ import Data.Function (on)
import Data.List (elemIndex)
import qualified Ledger.Address as Pl
import qualified Ledger.CardanoWallet as Pl
import qualified Ledger.Credential as Pl
import qualified Ledger.Crypto as Pl
import qualified PlutusLedgerApi.V3 as Pl
import Unsafe.Coerce

-- * MockChain Wallets
Expand Down

0 comments on commit 5f3a830

Please sign in to comment.