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

Commit

Permalink
PLT-5413 Work in progress: compiles, but does not run.
Browse files Browse the repository at this point in the history
FIXME:

1. Correct computation of script hash.
2. Diagnose and fix `Right ([],Left (IncompatibleVersionError (Version
   {_versionMajor = 1, _versionMinor = 1, _versionPatch = 0})))`
3. Complete `ScriptContext` for simple tests.
  • Loading branch information
bwbush committed Mar 27, 2023
1 parent 53548f5 commit 736e312
Show file tree
Hide file tree
Showing 22 changed files with 1,267 additions and 3,330 deletions.
16 changes: 1 addition & 15 deletions README.md
@@ -1,15 +1 @@
# Marlowe: financial contracts on Cardano Computation Layer

Here we present a reference implementation of Marlowe, domain-specific language targeted at
the execution of financial contracts in the style of Peyton Jones et al
on Cardano Computation Layer.

The implementation is based on semantics described in paper
['Marlowe: financial contracts on blockchain'](https://iohk.io/research/papers/#2WHKDRA8)
by Simon Thompson and Pablo Lamela Seijas

To run tests, from this folder:
```bash
nix run ../.#marlowe.haskell.packages.marlowe.components.tests.marlowe-test
```

# Experimental version of Marlowe validator for Cardano, with minimal dependencies
61 changes: 61 additions & 0 deletions app/Main.hs
@@ -0,0 +1,61 @@

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeApplications #-}


module Main (
main
) where


import Control.Monad.Except (runExcept)
import Control.Monad.Writer (runWriterT)
import Data.Bifunctor (bimap)
import Data.Maybe (fromJust)
import Language.Marlowe.Core.V1.Semantics.Types (Token(..))
import Language.Marlowe.Scripts -- (marloweValidatorBytes, marloweValidatorHash, rolePayoutValidatorBytes, rolePayoutValidatorHash)
import PlutusLedgerApi.V2
import PlutusCore.Evaluation.Machine.ExBudgetingDefaults (defaultCostModelParams)

import qualified Data.ByteString as BS
import qualified Data.ByteString.Base16 as B16
import qualified Data.ByteString.Short as SBS
import qualified Data.Map.Strict as M


main :: IO ()
main =
do
putStrLn $ "Semantics validator hash: " <> show marloweValidatorHash
putStrLn $ "Role-payout validator hash: " <> show rolePayoutValidatorHash
BS.writeFile "marlowe-semantics.plutus"
$ "{\"type\": \"PlutusScriptV2\", \"description\": \"\", \"cborHex\": \""
<> B16.encode (SBS.fromShort marloweValidatorBytes) <> "\"}"
BS.writeFile "marlowe-rolepayout.plutus"
$ "{\"type\": \"PlutusScriptV2\", \"description\": \"\", \"cborHex\": \""
<> B16.encode (SBS.fromShort rolePayoutValidatorBytes) <> "\"}"
print test


test :: Either String (LogOutput, Either EvaluationError ExBudget)
test =
let
roleToken = Token "" ""
-- FIXME: Work in progress. Running this results in
-- `Right ([],Left (IncompatibleVersionError (Version {_versionMajor = 1, _versionMinor = 1, _versionPatch = 0})))`
in
case evaluationContext of
Left message -> Left message
Right ec -> Right
$ evaluateScriptCounting (ProtocolVersion 8 0) Verbose ec rolePayoutValidatorBytes
[toData roleToken, toData (), toData ScriptContext{..}]


evaluationContext :: Either String EvaluationContext
evaluationContext =
let
costParams = M.elems $ fromJust defaultCostModelParams
costModel = take (length ([minBound..maxBound] :: [ParamName])) costParams
in
bimap show fst . runExcept . runWriterT $ mkEvaluationContext costModel
45 changes: 45 additions & 0 deletions cabal.project
@@ -0,0 +1,45 @@
repository cardano-haskell-packages
url: https://input-output-hk.github.io/cardano-haskell-packages
secure: True
root-keys:
3e0cce471cf09815f930210f7827266fd09045445d65923e6d0238a6cd15126f
443abb7fb497a134c343faf52f0b659bd7999bc06b7f63fa76dc99d631f9bea1
a86a1f6ce86c449c46666bda44268677abf29b5b2d2eb5ec7af903ec2f117a82
bcec67e8e99cabfa7764d75ad9b158d72bfacf70ca1d0ec8bc6b4406d1bf8413
c00aae8461a256275598500ea0e187588c35a5d5d7454fb57eac18d9edb86a56
d4a35cd3121aa00d18544bb0ac01c3e1691d618f462c46129271bccf39f7e8ee

index-state: 2023-03-24T00:00:00Z
index-state:
-- Bump this if you need newer packages from Hackage
, hackage.haskell.org 2023-03-24T00:00:00Z
-- Bump this if you need newer packages from CHaP
, cardano-haskell-packages 2023-03-24T00:00:00Z

packages: .

-- FIXME: Move to the Nix flake.
source-repository-package
type: git
location: https://github.com/input-output-hk/plutus
tag: 411cf29bfbffbab6a4e6a31ef783cd52362affdf
--sha256: 0fzwcpyw8sqkd37jiimdkkylnbc9vqkfvvjk03b29z0ajz45ar7d
subdir: plutus-core
plutus-ledger-api
plutus-tx
plutus-tx-plugin

write-ghc-environment-files: never

tests: true
benchmarks: true

test-show-details: direct

package plutus-core
flags: +with-inline-r

package nothunks
flags: +vector

extra-packages: ieee, filemanip

0 comments on commit 736e312

Please sign in to comment.