-
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
c2d8191
commit c4a5be5
Showing
35 changed files
with
602 additions
and
0 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
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: BasicProvenance | ||
source: daml | ||
init-script: Main:setup | ||
version: 0.0.1 | ||
dependencies: | ||
- daml-prim | ||
- daml-stdlib | ||
- daml-script |
60 changes: 60 additions & 0 deletions
60
daml/Basic_Provenance/BasicProvenance/daml/BasicProvinance.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,60 @@ | ||
module BasicProvinance where | ||
|
||
type ProvinanceId = ContractId Provinance | ||
|
||
data ProvinanceStateType | ||
= CreatedState | ||
| InTransitState | ||
| CompletedState | ||
deriving (Eq, Show) | ||
|
||
template Provinance | ||
with | ||
initiater : Party | ||
counter : Party | ||
previouscounter : Party | ||
chainOwner : Party | ||
chainObserver : Party | ||
state : ProvinanceStateType | ||
where | ||
signatory initiater | ||
observer counter | ||
choice TransferResponsibility : ProvinanceId | ||
with | ||
newCounter : Party | ||
controller counter | ||
do | ||
assertMsg "Invalid state of contract." (this.state /= CompletedState) | ||
create this with | ||
previouscounter = this.counter | ||
counter = newCounter | ||
state = InTransitState | ||
choice Complete : ProvinanceId | ||
controller chainOwner | ||
do | ||
assertMsg "Invalid state of contract." (this.state /= CompletedState) | ||
create this with | ||
previouscounter = this.counter | ||
counter = this.chainOwner | ||
state = CompletedState | ||
|
||
|
||
template ProvinanceApp | ||
with | ||
initiater : Party | ||
chainOwner : Party | ||
chainObserver : Party | ||
where | ||
signatory initiater | ||
choice Build : ProvinanceId | ||
controller initiater | ||
do | ||
create Provinance | ||
with | ||
initiater = this.initiater | ||
counter = this.initiater | ||
previouscounter = this.initiater | ||
chainOwner = this.chainOwner | ||
chainObserver = this.chainObserver | ||
state = CreatedState | ||
|
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,32 @@ | ||
module Main where | ||
|
||
import BasicProvinance | ||
import Daml.Script | ||
|
||
setup : Script ProvinanceId | ||
setup = script do | ||
-- user_setup_begin | ||
alice <- allocateParty "Alice" | ||
bob <- allocateParty"Bob" | ||
-- user_setup_end | ||
|
||
test <- submit alice do | ||
createCmd ProvinanceApp with | ||
initiater = alice | ||
chainOwner = alice | ||
chainObserver = bob | ||
|
||
test <- submit alice do | ||
exerciseCmd test Build | ||
|
||
test <- submit alice do | ||
exerciseCmd test TransferResponsibility with newCounter = bob | ||
|
||
test <- submit bob do | ||
exerciseCmd test TransferResponsibility with newCounter = alice | ||
|
||
test <- submit alice do | ||
exerciseCmd test TransferResponsibility with newCounter = bob | ||
|
||
submit alice do | ||
exerciseCmd test Complete |
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: Bazaar | ||
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,95 @@ | ||
module Bazaar where | ||
|
||
type BazaarId = ContractId Bazaar | ||
type ItemListingId = ContractId ItemListing | ||
|
||
data AccountInfo | ||
= AccountInfo { | ||
account : Party, | ||
balance : Int | ||
} deriving (Eq, Show) | ||
|
||
data ItemInfo | ||
= ItemInfo { | ||
name : Text, | ||
price : Int | ||
} deriving (Eq, Show) | ||
|
||
data BazaarStateType | ||
= PartyProvisioned | ||
| ItemListed | ||
| CurrentSaleFinalized | ||
deriving (Eq, Show) | ||
|
||
data ItemStateType | ||
= ItemAvailable | ||
| ItemSold | ||
deriving (Eq, Show) | ||
|
||
template ItemListing | ||
with | ||
owner : AccountInfo | ||
item : ItemInfo | ||
state : ItemStateType | ||
bazar : BazaarId | ||
buyer : AccountInfo | ||
where | ||
signatory owner.account | ||
observer buyer.account | ||
choice BuyItem : ItemListingId | ||
controller buyer.account | ||
do | ||
assertMsg "Not enough funds." (this.item.price > this.buyer.balance) | ||
exercise bazar UpdateBalance | ||
create this with | ||
state = ItemSold | ||
|
||
template Bazaar | ||
with | ||
seller : AccountInfo | ||
buyer : AccountInfo | ||
item : ItemInfo | ||
state : BazaarStateType | ||
where | ||
signatory seller.account | ||
observer buyer.account | ||
choice Listing : BazaarId | ||
controller buyer.account | ||
do | ||
newC <- create this with | ||
state = ItemListed | ||
|
||
item <- create ItemListing with | ||
owner = this.seller | ||
item = this.item | ||
state = ItemAvailable | ||
bazar = newC | ||
buyer = this.buyer | ||
-- imporve | ||
create this with | ||
state = ItemListed | ||
choice UpdateBalance : BazaarId | ||
controller buyer.account | ||
do | ||
create this with | ||
seller = AccountInfo this.seller.account (this.seller.balance + this.item.price) | ||
buyer = AccountInfo this.buyer.account (this.buyer.balance - this.item.price) | ||
state = CurrentSaleFinalized | ||
|
||
|
||
template BazaarApp | ||
with | ||
seller : Party | ||
buyer : Party | ||
where | ||
signatory seller | ||
observer buyer | ||
choice Build : BazaarId | ||
controller seller | ||
do | ||
create Bazaar | ||
with | ||
seller = AccountInfo seller 10 | ||
buyer = AccountInfo buyer 10 | ||
item = ItemInfo "ItemName" 5 | ||
state = PartyProvisioned |
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 @@ | ||
module Main where | ||
|
||
import Daml.Script | ||
import Bazaar | ||
|
||
setup : Script (ContractId BazaarApp) | ||
setup = script do | ||
alice <- allocateParty "Alice" | ||
bob <- allocateParty"Bob" | ||
|
||
submit alice do | ||
createCmd BazaarApp with seller = alice, buyer = bob |
8 changes: 8 additions & 0 deletions
8
daml/Frequent_Flyer_Rewards_Calculator/FrequentFlyer/.dlint.yaml
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} |
3 changes: 3 additions & 0 deletions
3
daml/Frequent_Flyer_Rewards_Calculator/FrequentFlyer/.gitattributes
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 |
3 changes: 3 additions & 0 deletions
3
daml/Frequent_Flyer_Rewards_Calculator/FrequentFlyer/.gitignore
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.
12 changes: 12 additions & 0 deletions
12
daml/Frequent_Flyer_Rewards_Calculator/FrequentFlyer/daml.yaml
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: FrequentFlyer | ||
source: daml | ||
init-script: Main:setup | ||
version: 0.0.1 | ||
dependencies: | ||
- daml-prim | ||
- daml-stdlib | ||
- daml-script |
65 changes: 65 additions & 0 deletions
65
daml/Frequent_Flyer_Rewards_Calculator/FrequentFlyer/daml/FrequentFlyer.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,65 @@ | ||
module FrequentFlyer where | ||
|
||
type FrequentFlyerId = ContractId FrequentFlyer | ||
|
||
data FlyerStateType | ||
= SetFlyerReward | ||
| MilesAdded | ||
deriving (Eq, Show) | ||
|
||
data TotalRewardsState | ||
= Behind | ||
| UpToDate | ||
deriving (Eq, Show) | ||
|
||
template FrequentFlyer | ||
with | ||
flyer : Party | ||
airlineRep : Party | ||
rewardsPMile: Int | ||
miles : [Int] | ||
state : FlyerStateType | ||
rewardsState: TotalRewardsState | ||
totalRewards: Int | ||
where | ||
signatory airlineRep | ||
ensure flyer /= airlineRep | ||
observer flyer | ||
choice AddMiles : FrequentFlyerId | ||
with | ||
millesAdd : [Int] | ||
controller flyer | ||
do | ||
create this with | ||
miles = (++) millesAdd this.miles | ||
state = MilesAdded | ||
rewardsState = Behind | ||
choice ComputeTotalRewards : FrequentFlyerId | ||
controller flyer | ||
do | ||
assertMsg "Invalid state of contract." (this.state == MilesAdded) | ||
create this with | ||
totalRewards = sum (fmap (*this.rewardsPMile) miles) | ||
rewardsState = UpToDate | ||
|
||
|
||
template FrequentFlyerApp | ||
with | ||
flyer : Party | ||
airlineRep : Party | ||
rewardsPMile: Int | ||
where | ||
signatory airlineRep | ||
observer flyer | ||
choice Build : FrequentFlyerId | ||
controller airlineRep | ||
do | ||
create FrequentFlyer | ||
with | ||
flyer = this.flyer | ||
airlineRep = this.airlineRep | ||
rewardsPMile= this.rewardsPMile | ||
miles = [] | ||
state = SetFlyerReward | ||
rewardsState= UpToDate | ||
totalRewards= 0 |
34 changes: 34 additions & 0 deletions
34
daml/Frequent_Flyer_Rewards_Calculator/FrequentFlyer/daml/Main.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,34 @@ | ||
module Main where | ||
|
||
import FrequentFlyer | ||
import Daml.Script | ||
|
||
setup : Script FrequentFlyerId | ||
setup = script do | ||
alice <- allocateParty "Alice" | ||
bob <- allocateParty "Bob" | ||
|
||
test <- submit bob do | ||
createCmd FrequentFlyerApp with | ||
flyer = alice | ||
airlineRep = bob | ||
rewardsPMile = 10 | ||
|
||
test <- submit bob do | ||
exerciseCmd test Build | ||
|
||
test <- submit alice do | ||
exerciseCmd test AddMiles with millesAdd = [1] | ||
|
||
test <- submit alice do | ||
exerciseCmd test AddMiles with millesAdd = [2] | ||
|
||
test <- submit alice do | ||
exerciseCmd test ComputeTotalRewards | ||
|
||
test <- submit alice do | ||
exerciseCmd test AddMiles with millesAdd = [3] | ||
|
||
submit alice do | ||
exerciseCmd test ComputeTotalRewards | ||
|
Oops, something went wrong.