solution for week 9

This commit is contained in:
Lars Brünjes 2021-06-03 01:15:15 +02:00
parent 9c86f2370b
commit 0ed63b526d
No known key found for this signature in database
GPG key ID: B488B9045DC1A087
4 changed files with 88 additions and 0 deletions

View file

@ -138,6 +138,16 @@
- [`RockPaperScissors`](code/week07/src/Week07/RockPaperScissors.hs) - [`RockPaperScissors`](code/week07/src/Week07/RockPaperScissors.hs)
- [`TestRockPaperScissors`](code/week07/src/Week07/TestRockPaperScissors.hs) - [`TestRockPaperScissors`](code/week07/src/Week07/TestRockPaperScissors.hs)
- Week #8
- [`TokenSaleWithClose`](code/week08/src/Week08/TokenSaleWithClose.hs)
- [`ModelWithClose`](code/week08/test/Spec/ModelWithClose.hs)
- [`TraceWithClose`](code/week08/test/Spec/TraceWithClose.hs)
- Week #9
- [`solution`](code/week09/app/solution.hs)
## Some Plutus Modules ## Some Plutus Modules
- [`Plutus.Contract.StateMachine`](https://github.com/input-output-hk/plutus/blob/master/plutus-contract/src/Plutus/Contract/StateMachine.hs), contains types and functions for using state machines. - [`Plutus.Contract.StateMachine`](https://github.com/input-output-hk/plutus/blob/master/plutus-contract/src/Plutus/Contract/StateMachine.hs), contains types and functions for using state machines.

View file

@ -0,0 +1,47 @@
{-# LANGUAGE OverloadedStrings #-}
import Language.Marlowe.Extended
main :: IO ()
main = print . pretty $ contract "Alice" "Bob" "Charlie" $ Constant 10
choiceId :: Party -> ChoiceId
choiceId = ChoiceId "Winner"
contract :: Party -> Party -> Party -> Value -> Contract
contract alice bob charlie deposit =
When
[Case (Deposit charlie charlie ada $ AddValue deposit deposit) $
When
[ f alice bob
, f bob alice
]
20 Close
]
10 Close
where
f :: Party -> Party -> Case
f x y =
Case
(Deposit x x ada deposit
)
(When
[Case
(Deposit y y ada deposit
)
(When
[Case
(Choice (choiceId charlie) [Bound 1 2]
)
(If
(ValueEQ (ChoiceValue $ choiceId charlie) (Constant 1)
)
(Pay bob (Account alice) ada deposit Close)
(Pay alice (Account bob) ada deposit Close)
)]
40
(Pay charlie (Account alice) ada deposit $
Pay charlie (Account bob) ada deposit
Close)
)]
30 Close
)

6
code/week09/hie.yaml Normal file
View file

@ -0,0 +1,6 @@
cradle:
cabal:
- path: "./app/marlowe.hs"
component: "exe:marlowe"
- path: "./app/solution.hs"
component: "exe:solution"

View file

@ -0,0 +1,25 @@
Cabal-Version: 2.4
Name: plutus-pioneer-program-week09
Version: 0.1.0.0
Author: Lars Bruenjes
Maintainer: brunjlar@gmail.com
Build-Type: Simple
Copyright: © 2021 Lars Bruenjes
License: Apache-2.0
License-files: LICENSE
executable marlowe
hs-source-dirs: app
main-is: marlowe.hs
build-depends: base ^>=4.14.1.0
, marlowe
default-language: Haskell2010
ghc-options: -Wall -O2
executable solution
hs-source-dirs: app
main-is: solution.hs
build-depends: base ^>=4.14.1.0
, marlowe
default-language: Haskell2010
ghc-options: -Wall -O2