-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5e4fad2
commit 00cdefe
Showing
11 changed files
with
223 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module Test where |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# This file controls the behaviour of the dlint linting tool. Below are two | ||
# examples of how to enable or disable a rule. | ||
|
||
# This rule is enabled by default. Uncomment to disable. | ||
#- ignore: {name: Use fewer imports} | ||
|
||
# This rule is disabled by default. Uncomment to enable. | ||
#- suggest: {name: Use module export list} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# This tells GitHub to highlight Daml files as if they were Haskell. It's not | ||
# perfect, but it's better than no syntax highlighting at all. | ||
*.daml linguist-language=Haskell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/.daml | ||
/log | ||
navigator.log |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# for config file options, refer to | ||
# https://docs.daml.com/tools/assistant.html#project-config-file-daml-yaml | ||
|
||
sdk-version: 2.4.2 | ||
name: simpleMarketPlace | ||
source: daml | ||
init-script: Main:setup | ||
version: 0.0.1 | ||
dependencies: | ||
- daml-prim | ||
- daml-stdlib | ||
- daml-script |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
module Main where | ||
|
||
import SimpleMarketplace | ||
import Daml.Script | ||
|
||
setup : Script SimpleMarketPlaceId | ||
setup = script do | ||
-- user_setup_begin | ||
alice <- allocateParty "Alice" | ||
bob <- allocateParty "Bob" | ||
|
||
test <- submit alice do | ||
createCmd SimpleMarketPlace with | ||
owner = alice | ||
buyer = [] | ||
offerPrice = 0 | ||
state = ItemAvailable | ||
|
||
test <- submit alice do | ||
exerciseCmd test RegisterP with buyerParticipant = bob | ||
|
||
test <- submit bob do | ||
exerciseCmd test MakeOffer with offerPriceParam = 6 | ||
|
||
test <- submit alice do | ||
exerciseCmd test RejectOffer | ||
|
||
test <- submit bob do | ||
exerciseCmd test MakeOffer with offerPriceParam = 6 | ||
|
||
submit alice do | ||
exerciseCmd test AcceptOffer |
61 changes: 61 additions & 0 deletions
61
daml/draft_simple_market/simpleMarketPlace/daml/SimpleMarketplace.daml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
module SimpleMarketplace where | ||
|
||
import DA.List.Total | ||
import DA.Optional | ||
|
||
type SimpleMarketPlaceId = ContractId SimpleMarketPlace | ||
|
||
data StateType | ||
= ItemAvailable | ||
| OfferPlaced | ||
| Accepted | ||
deriving (Eq, Show) | ||
|
||
template SimpleMarketPlace | ||
with | ||
owner : Party | ||
buyer : [Party] | ||
offerPrice : Int | ||
state : StateType | ||
|
||
where | ||
signatory owner | ||
observer buyer | ||
|
||
choice RegisterP : SimpleMarketPlaceId | ||
with | ||
buyerParticipant : Party | ||
controller owner | ||
do | ||
assertMsg "Already has a buyer registered." (isNone (init buyer)) | ||
create SimpleMarketPlace with | ||
buyer = [buyerParticipant] | ||
.. | ||
|
||
choice MakeOffer : SimpleMarketPlaceId | ||
with | ||
offerPriceParam : Int | ||
controller buyer | ||
do | ||
assertMsg "Item is not available for an offer." (this.state == ItemAvailable) | ||
|
||
create SimpleMarketPlace with | ||
offerPrice = offerPriceParam | ||
state = OfferPlaced | ||
.. | ||
|
||
choice AcceptOffer : SimpleMarketPlaceId | ||
controller owner | ||
do | ||
assertMsg "Offer was not placed." (this.state == OfferPlaced) | ||
create this with | ||
state = Accepted | ||
|
||
choice RejectOffer : SimpleMarketPlaceId | ||
controller owner | ||
do | ||
assertMsg "Invalid state of contract." (this.state == OfferPlaced) | ||
create SimpleMarketPlace with | ||
offerPrice = 0 | ||
state = ItemAvailable | ||
.. |