From c4a5be5562d7b8d741d6bac3f5fa8f5ebd5b8b97 Mon Sep 17 00:00:00 2001 From: jotaAfonso Date: Tue, 3 Jan 2023 14:13:04 +0000 Subject: [PATCH] daml contract --- .../BasicProvenance/.dlint.yaml | 8 ++ .../BasicProvenance/.gitattributes | 3 + .../BasicProvenance/.gitignore | 3 + .../BasicProvenance/NO_AUTO_COPYRIGHT | 0 .../BasicProvenance/daml.yaml | 12 +++ .../BasicProvenance/daml/BasicProvinance.daml | 60 ++++++++++++ .../BasicProvenance/daml/Main.daml | 32 +++++++ daml/Bazaar/Bazaar/.dlint.yaml | 8 ++ daml/Bazaar/Bazaar/.gitattributes | 3 + daml/Bazaar/Bazaar/.gitignore | 3 + daml/Bazaar/Bazaar/NO_AUTO_COPYRIGHT | 0 daml/Bazaar/Bazaar/daml.yaml | 12 +++ daml/Bazaar/Bazaar/daml/Bazaar.daml | 95 +++++++++++++++++++ daml/Bazaar/Bazaar/daml/Main.daml | 12 +++ .../FrequentFlyer/.dlint.yaml | 8 ++ .../FrequentFlyer/.gitattributes | 3 + .../FrequentFlyer/.gitignore | 3 + .../FrequentFlyer/NO_AUTO_COPYRIGHT | 0 .../FrequentFlyer/daml.yaml | 12 +++ .../FrequentFlyer/daml/FrequentFlyer.daml | 65 +++++++++++++ .../FrequentFlyer/daml/Main.daml | 34 +++++++ .../HelloBlockchain/.dlint.yaml | 8 ++ .../HelloBlockchain/.gitattributes | 3 + .../HelloBlockchain/.gitignore | 3 + .../HelloBlockchain/NO_AUTO_COPYRIGHT | 0 .../HelloBlockchain/daml.yaml | 12 +++ .../HelloBlockchain/daml/HelloBlockchain.daml | 55 +++++++++++ .../HelloBlockchain/daml/Main.daml | 24 +++++ .../RoomThermostat/.dlint.yaml | 8 ++ .../RoomThermostat/.gitattributes | 3 + .../Room_Thermostat/RoomThermostat/.gitignore | 3 + .../RoomThermostat/NO_AUTO_COPYRIGHT | 0 daml/Room_Thermostat/RoomThermostat/daml.yaml | 12 +++ .../RoomThermostat/daml/Main.daml | 27 ++++++ .../RoomThermostat/daml/RoomThermostat.daml | 68 +++++++++++++ 35 files changed, 602 insertions(+) create mode 100644 daml/Basic_Provenance/BasicProvenance/.dlint.yaml create mode 100644 daml/Basic_Provenance/BasicProvenance/.gitattributes create mode 100644 daml/Basic_Provenance/BasicProvenance/.gitignore create mode 100644 daml/Basic_Provenance/BasicProvenance/NO_AUTO_COPYRIGHT create mode 100644 daml/Basic_Provenance/BasicProvenance/daml.yaml create mode 100644 daml/Basic_Provenance/BasicProvenance/daml/BasicProvinance.daml create mode 100644 daml/Basic_Provenance/BasicProvenance/daml/Main.daml create mode 100644 daml/Bazaar/Bazaar/.dlint.yaml create mode 100644 daml/Bazaar/Bazaar/.gitattributes create mode 100644 daml/Bazaar/Bazaar/.gitignore create mode 100644 daml/Bazaar/Bazaar/NO_AUTO_COPYRIGHT create mode 100644 daml/Bazaar/Bazaar/daml.yaml create mode 100644 daml/Bazaar/Bazaar/daml/Bazaar.daml create mode 100644 daml/Bazaar/Bazaar/daml/Main.daml create mode 100644 daml/Frequent_Flyer_Rewards_Calculator/FrequentFlyer/.dlint.yaml create mode 100644 daml/Frequent_Flyer_Rewards_Calculator/FrequentFlyer/.gitattributes create mode 100644 daml/Frequent_Flyer_Rewards_Calculator/FrequentFlyer/.gitignore create mode 100644 daml/Frequent_Flyer_Rewards_Calculator/FrequentFlyer/NO_AUTO_COPYRIGHT create mode 100644 daml/Frequent_Flyer_Rewards_Calculator/FrequentFlyer/daml.yaml create mode 100644 daml/Frequent_Flyer_Rewards_Calculator/FrequentFlyer/daml/FrequentFlyer.daml create mode 100644 daml/Frequent_Flyer_Rewards_Calculator/FrequentFlyer/daml/Main.daml create mode 100644 daml/Hello_Blockchain/HelloBlockchain/.dlint.yaml create mode 100644 daml/Hello_Blockchain/HelloBlockchain/.gitattributes create mode 100644 daml/Hello_Blockchain/HelloBlockchain/.gitignore create mode 100644 daml/Hello_Blockchain/HelloBlockchain/NO_AUTO_COPYRIGHT create mode 100644 daml/Hello_Blockchain/HelloBlockchain/daml.yaml create mode 100644 daml/Hello_Blockchain/HelloBlockchain/daml/HelloBlockchain.daml create mode 100644 daml/Hello_Blockchain/HelloBlockchain/daml/Main.daml create mode 100644 daml/Room_Thermostat/RoomThermostat/.dlint.yaml create mode 100644 daml/Room_Thermostat/RoomThermostat/.gitattributes create mode 100644 daml/Room_Thermostat/RoomThermostat/.gitignore create mode 100644 daml/Room_Thermostat/RoomThermostat/NO_AUTO_COPYRIGHT create mode 100644 daml/Room_Thermostat/RoomThermostat/daml.yaml create mode 100644 daml/Room_Thermostat/RoomThermostat/daml/Main.daml create mode 100644 daml/Room_Thermostat/RoomThermostat/daml/RoomThermostat.daml diff --git a/daml/Basic_Provenance/BasicProvenance/.dlint.yaml b/daml/Basic_Provenance/BasicProvenance/.dlint.yaml new file mode 100644 index 0000000..add1b60 --- /dev/null +++ b/daml/Basic_Provenance/BasicProvenance/.dlint.yaml @@ -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} diff --git a/daml/Basic_Provenance/BasicProvenance/.gitattributes b/daml/Basic_Provenance/BasicProvenance/.gitattributes new file mode 100644 index 0000000..ec8726b --- /dev/null +++ b/daml/Basic_Provenance/BasicProvenance/.gitattributes @@ -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 diff --git a/daml/Basic_Provenance/BasicProvenance/.gitignore b/daml/Basic_Provenance/BasicProvenance/.gitignore new file mode 100644 index 0000000..3b14695 --- /dev/null +++ b/daml/Basic_Provenance/BasicProvenance/.gitignore @@ -0,0 +1,3 @@ +/.daml +/log +navigator.log diff --git a/daml/Basic_Provenance/BasicProvenance/NO_AUTO_COPYRIGHT b/daml/Basic_Provenance/BasicProvenance/NO_AUTO_COPYRIGHT new file mode 100644 index 0000000..e69de29 diff --git a/daml/Basic_Provenance/BasicProvenance/daml.yaml b/daml/Basic_Provenance/BasicProvenance/daml.yaml new file mode 100644 index 0000000..ce1ec82 --- /dev/null +++ b/daml/Basic_Provenance/BasicProvenance/daml.yaml @@ -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 diff --git a/daml/Basic_Provenance/BasicProvenance/daml/BasicProvinance.daml b/daml/Basic_Provenance/BasicProvenance/daml/BasicProvinance.daml new file mode 100644 index 0000000..c49bd21 --- /dev/null +++ b/daml/Basic_Provenance/BasicProvenance/daml/BasicProvinance.daml @@ -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 + diff --git a/daml/Basic_Provenance/BasicProvenance/daml/Main.daml b/daml/Basic_Provenance/BasicProvenance/daml/Main.daml new file mode 100644 index 0000000..758165b --- /dev/null +++ b/daml/Basic_Provenance/BasicProvenance/daml/Main.daml @@ -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 \ No newline at end of file diff --git a/daml/Bazaar/Bazaar/.dlint.yaml b/daml/Bazaar/Bazaar/.dlint.yaml new file mode 100644 index 0000000..add1b60 --- /dev/null +++ b/daml/Bazaar/Bazaar/.dlint.yaml @@ -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} diff --git a/daml/Bazaar/Bazaar/.gitattributes b/daml/Bazaar/Bazaar/.gitattributes new file mode 100644 index 0000000..ec8726b --- /dev/null +++ b/daml/Bazaar/Bazaar/.gitattributes @@ -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 diff --git a/daml/Bazaar/Bazaar/.gitignore b/daml/Bazaar/Bazaar/.gitignore new file mode 100644 index 0000000..3b14695 --- /dev/null +++ b/daml/Bazaar/Bazaar/.gitignore @@ -0,0 +1,3 @@ +/.daml +/log +navigator.log diff --git a/daml/Bazaar/Bazaar/NO_AUTO_COPYRIGHT b/daml/Bazaar/Bazaar/NO_AUTO_COPYRIGHT new file mode 100644 index 0000000..e69de29 diff --git a/daml/Bazaar/Bazaar/daml.yaml b/daml/Bazaar/Bazaar/daml.yaml new file mode 100644 index 0000000..ec95fde --- /dev/null +++ b/daml/Bazaar/Bazaar/daml.yaml @@ -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 diff --git a/daml/Bazaar/Bazaar/daml/Bazaar.daml b/daml/Bazaar/Bazaar/daml/Bazaar.daml new file mode 100644 index 0000000..6ee5b99 --- /dev/null +++ b/daml/Bazaar/Bazaar/daml/Bazaar.daml @@ -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 \ No newline at end of file diff --git a/daml/Bazaar/Bazaar/daml/Main.daml b/daml/Bazaar/Bazaar/daml/Main.daml new file mode 100644 index 0000000..ff643c5 --- /dev/null +++ b/daml/Bazaar/Bazaar/daml/Main.daml @@ -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 \ No newline at end of file diff --git a/daml/Frequent_Flyer_Rewards_Calculator/FrequentFlyer/.dlint.yaml b/daml/Frequent_Flyer_Rewards_Calculator/FrequentFlyer/.dlint.yaml new file mode 100644 index 0000000..add1b60 --- /dev/null +++ b/daml/Frequent_Flyer_Rewards_Calculator/FrequentFlyer/.dlint.yaml @@ -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} diff --git a/daml/Frequent_Flyer_Rewards_Calculator/FrequentFlyer/.gitattributes b/daml/Frequent_Flyer_Rewards_Calculator/FrequentFlyer/.gitattributes new file mode 100644 index 0000000..ec8726b --- /dev/null +++ b/daml/Frequent_Flyer_Rewards_Calculator/FrequentFlyer/.gitattributes @@ -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 diff --git a/daml/Frequent_Flyer_Rewards_Calculator/FrequentFlyer/.gitignore b/daml/Frequent_Flyer_Rewards_Calculator/FrequentFlyer/.gitignore new file mode 100644 index 0000000..3b14695 --- /dev/null +++ b/daml/Frequent_Flyer_Rewards_Calculator/FrequentFlyer/.gitignore @@ -0,0 +1,3 @@ +/.daml +/log +navigator.log diff --git a/daml/Frequent_Flyer_Rewards_Calculator/FrequentFlyer/NO_AUTO_COPYRIGHT b/daml/Frequent_Flyer_Rewards_Calculator/FrequentFlyer/NO_AUTO_COPYRIGHT new file mode 100644 index 0000000..e69de29 diff --git a/daml/Frequent_Flyer_Rewards_Calculator/FrequentFlyer/daml.yaml b/daml/Frequent_Flyer_Rewards_Calculator/FrequentFlyer/daml.yaml new file mode 100644 index 0000000..bb4ee83 --- /dev/null +++ b/daml/Frequent_Flyer_Rewards_Calculator/FrequentFlyer/daml.yaml @@ -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 diff --git a/daml/Frequent_Flyer_Rewards_Calculator/FrequentFlyer/daml/FrequentFlyer.daml b/daml/Frequent_Flyer_Rewards_Calculator/FrequentFlyer/daml/FrequentFlyer.daml new file mode 100644 index 0000000..379d1a2 --- /dev/null +++ b/daml/Frequent_Flyer_Rewards_Calculator/FrequentFlyer/daml/FrequentFlyer.daml @@ -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 \ No newline at end of file diff --git a/daml/Frequent_Flyer_Rewards_Calculator/FrequentFlyer/daml/Main.daml b/daml/Frequent_Flyer_Rewards_Calculator/FrequentFlyer/daml/Main.daml new file mode 100644 index 0000000..4ebf1f1 --- /dev/null +++ b/daml/Frequent_Flyer_Rewards_Calculator/FrequentFlyer/daml/Main.daml @@ -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 + diff --git a/daml/Hello_Blockchain/HelloBlockchain/.dlint.yaml b/daml/Hello_Blockchain/HelloBlockchain/.dlint.yaml new file mode 100644 index 0000000..add1b60 --- /dev/null +++ b/daml/Hello_Blockchain/HelloBlockchain/.dlint.yaml @@ -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} diff --git a/daml/Hello_Blockchain/HelloBlockchain/.gitattributes b/daml/Hello_Blockchain/HelloBlockchain/.gitattributes new file mode 100644 index 0000000..ec8726b --- /dev/null +++ b/daml/Hello_Blockchain/HelloBlockchain/.gitattributes @@ -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 diff --git a/daml/Hello_Blockchain/HelloBlockchain/.gitignore b/daml/Hello_Blockchain/HelloBlockchain/.gitignore new file mode 100644 index 0000000..3b14695 --- /dev/null +++ b/daml/Hello_Blockchain/HelloBlockchain/.gitignore @@ -0,0 +1,3 @@ +/.daml +/log +navigator.log diff --git a/daml/Hello_Blockchain/HelloBlockchain/NO_AUTO_COPYRIGHT b/daml/Hello_Blockchain/HelloBlockchain/NO_AUTO_COPYRIGHT new file mode 100644 index 0000000..e69de29 diff --git a/daml/Hello_Blockchain/HelloBlockchain/daml.yaml b/daml/Hello_Blockchain/HelloBlockchain/daml.yaml new file mode 100644 index 0000000..69d7385 --- /dev/null +++ b/daml/Hello_Blockchain/HelloBlockchain/daml.yaml @@ -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: HelloBlockchain +source: daml +init-script: Main:setup +version: 0.0.1 +dependencies: + - daml-prim + - daml-stdlib + - daml-script diff --git a/daml/Hello_Blockchain/HelloBlockchain/daml/HelloBlockchain.daml b/daml/Hello_Blockchain/HelloBlockchain/daml/HelloBlockchain.daml new file mode 100644 index 0000000..d9ed12e --- /dev/null +++ b/daml/Hello_Blockchain/HelloBlockchain/daml/HelloBlockchain.daml @@ -0,0 +1,55 @@ +module HelloBlockchain where + +type HelloBlockChainId = ContractId HelloBlockChain + +data HelloStateType + = Request + | Respond + deriving (Eq, Show) + +template HelloBlockChain + with + requestor : Party + responder : Party + state : HelloStateType + msg : Text + where + signatory requestor + ensure msg /= "" && requestor /= responder + observer responder + choice SendResponse : HelloBlockChainId + with + newmsg : Text + controller responder + do + assertMsg "Invalid State" (this.state /= Respond) + create this with + msg = newmsg + state = Respond + choice SendRequest : HelloBlockChainId + with + newmsg : Text + controller requestor + do + assertMsg "Invalid State" (this.state /= Request) + create this with + msg = newmsg + state = Request + +template HelloBlockChainApp + with + requestor : Party + responder : Party + msg : Text + where + signatory requestor + observer responder + choice Build : HelloBlockChainId + controller requestor + do + create HelloBlockChain + with + requestor = this.requestor + responder = this.responder + state = Request + msg = this.msg \ No newline at end of file diff --git a/daml/Hello_Blockchain/HelloBlockchain/daml/Main.daml b/daml/Hello_Blockchain/HelloBlockchain/daml/Main.daml new file mode 100644 index 0000000..b91448d --- /dev/null +++ b/daml/Hello_Blockchain/HelloBlockchain/daml/Main.daml @@ -0,0 +1,24 @@ +module Main where + +import Daml.Script +import HelloBlockchain + +setup : Script HelloBlockChainId +setup = script do + alice <- allocateParty"Alice" + bob <- allocateParty "Bob" + + helloB <- submit alice do + createCmd HelloBlockChainApp with + requestor = alice + responder = bob + msg = "Test" + + helloB <- submit alice do + exerciseCmd helloB Build + + helloB <- submit bob do + exerciseCmd helloB SendResponse with newmsg = "Test response" + + submit alice do + exerciseCmd helloB SendRequest with newmsg = "Test request" \ No newline at end of file diff --git a/daml/Room_Thermostat/RoomThermostat/.dlint.yaml b/daml/Room_Thermostat/RoomThermostat/.dlint.yaml new file mode 100644 index 0000000..add1b60 --- /dev/null +++ b/daml/Room_Thermostat/RoomThermostat/.dlint.yaml @@ -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} diff --git a/daml/Room_Thermostat/RoomThermostat/.gitattributes b/daml/Room_Thermostat/RoomThermostat/.gitattributes new file mode 100644 index 0000000..ec8726b --- /dev/null +++ b/daml/Room_Thermostat/RoomThermostat/.gitattributes @@ -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 diff --git a/daml/Room_Thermostat/RoomThermostat/.gitignore b/daml/Room_Thermostat/RoomThermostat/.gitignore new file mode 100644 index 0000000..3b14695 --- /dev/null +++ b/daml/Room_Thermostat/RoomThermostat/.gitignore @@ -0,0 +1,3 @@ +/.daml +/log +navigator.log diff --git a/daml/Room_Thermostat/RoomThermostat/NO_AUTO_COPYRIGHT b/daml/Room_Thermostat/RoomThermostat/NO_AUTO_COPYRIGHT new file mode 100644 index 0000000..e69de29 diff --git a/daml/Room_Thermostat/RoomThermostat/daml.yaml b/daml/Room_Thermostat/RoomThermostat/daml.yaml new file mode 100644 index 0000000..2f09b00 --- /dev/null +++ b/daml/Room_Thermostat/RoomThermostat/daml.yaml @@ -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: RoomThermostat +source: daml +init-script: Main:setup +version: 0.0.1 +dependencies: + - daml-prim + - daml-stdlib + - daml-script diff --git a/daml/Room_Thermostat/RoomThermostat/daml/Main.daml b/daml/Room_Thermostat/RoomThermostat/daml/Main.daml new file mode 100644 index 0000000..a63be52 --- /dev/null +++ b/daml/Room_Thermostat/RoomThermostat/daml/Main.daml @@ -0,0 +1,27 @@ +module Main where + +import Daml.Script +import RoomThermostat + +setup : Script RoomThermostatId +setup = script do + alice <- allocateParty "Alice" + bob <- allocateParty"Bob" + + test <- submit alice do + createCmd RoomThermostatApp with + owner = alice + installer = bob + targetTemp = 70 + + test <- submit bob do + exerciseCmd test Build + + test <- submit bob do + exerciseCmd test StartThermostat + + test <- submit alice do + exerciseCmd test SetTargetTemperature with temp = 30 + + submit alice do + exerciseCmd test SetMode with targetMode = Auto \ No newline at end of file diff --git a/daml/Room_Thermostat/RoomThermostat/daml/RoomThermostat.daml b/daml/Room_Thermostat/RoomThermostat/daml/RoomThermostat.daml new file mode 100644 index 0000000..d153003 --- /dev/null +++ b/daml/Room_Thermostat/RoomThermostat/daml/RoomThermostat.daml @@ -0,0 +1,68 @@ +module RoomThermostat where + +type RoomThermostatId = ContractId RoomThermostat + +data RoomStateType + = CreatedState + | InUseState + deriving (Eq, Show) + +data ModeType + = Off + | On + | Heat + | Auto + deriving (Eq, Show) + +template RoomThermostat + with + owner : Party + installer : Party + mode : ModeType + targetTemp : Int + state : RoomStateType + where + signatory owner + ensure owner /= installer + observer installer + choice StartThermostat : RoomThermostatId + controller installer + do + assertMsg "Invalid State for operation." (this.state == CreatedState) + create this with + state = InUseState + choice SetTargetTemperature : RoomThermostatId + with + temp : Int + controller owner + do + assertMsg "Invalid State for operation." (this.state == InUseState) + create this with + targetTemp = temp + choice SetMode : RoomThermostatId + with + targetMode : ModeType + controller owner + do + assertMsg "Invalid State for operation." (this.state == InUseState) + create this with + mode = targetMode + +template RoomThermostatApp + with + owner : Party + installer : Party + targetTemp : Int + where + signatory owner + observer installer + choice Build : RoomThermostatId + controller installer + do + create RoomThermostat + with + owner = this.owner + installer = this.installer + targetTemp = this.targetTemp + mode = Off + state = CreatedState \ No newline at end of file