Skip to content

Instantly share code, notes, and snippets.

@gyorgybalazsi
Last active September 2, 2022 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gyorgybalazsi/d8e546eed4bee8b9c4fe539348ebe5c3 to your computer and use it in GitHub Desktop.
Save gyorgybalazsi/d8e546eed4bee8b9c4fe539348ebe5c3 to your computer and use it in GitHub Desktop.
Ticket offer
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