Last active
September 2, 2022 09:31
-
-
Save gyorgybalazsi/d8e546eed4bee8b9c4fe539348ebe5c3 to your computer and use it in GitHub Desktop.
Ticket offer
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
module Main where | |
import DA.Assert ((===)) | |
import Daml.Script | |
template TicketOffer | |
with | |
organizer : Party | |
buyer : Party | |
price : Decimal | |
where | |
signatory organizer | |
observer buyer | |
choice Accept : ContractId TicketAgreement | |
with | |
cashId : ContractId Cash | |
controller buyer | |
do | |
cash <- fetch cashId | |
cash.amount === price | |
exercise cashId Transfer with | |
newOwner = organizer | |
create TicketAgreement with | |
organizer; owner = buyer | |
template Cash | |
with | |
issuer : Party | |
owner : Party | |
amount : Decimal | |
where | |
signatory issuer | |
observer owner | |
choice Transfer : ContractId Cash | |
with | |
newOwner : Party | |
controller owner | |
do | |
create this with owner = newOwner | |
template TicketAgreement | |
with | |
organizer : Party | |
owner : Party | |
where | |
signatory organizer, owner | |
setup : Script (ContractId TicketAgreement) | |
setup = script do | |
alice <- allocatePartyWithHint "Alice" (PartyIdHint "Alice") | |
ticketWizard <- allocatePartyWithHint "TicketWizard" (PartyIdHint "TicketWizard") | |
scroogeBank <- allocatePartyWithHint "ScroogeBank" (PartyIdHint "ScroogeBank") | |
aliceId <- validateUserId "alice" | |
ticketWizardId <- validateUserId "ticketwizard" | |
scroogeBankId <- validateUserId "scroogebank" | |
createUser (User aliceId (Some alice)) [CanActAs alice] | |
createUser (User ticketWizardId (Some ticketWizard)) [CanActAs ticketWizard] | |
createUser (User scroogeBankId (Some scroogeBank)) [CanActAs scroogeBank] | |
cashCid <- submit scroogeBank $ createCmd (Cash scroogeBank alice 10.0) | |
offerCid <- submit ticketWizard $ createCmd (TicketOffer ticketWizard alice 10.0) | |
submit alice $ exerciseCmd offerCid (Accept cashCid) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment