Skip to content

Instantly share code, notes, and snippets.

template Fleet
with
operator: Party
vehicles: [VehicleId]
where
signatory operator
key operator: Party
maintainer key
template RideRequest
with
operator: Party
traveler: Party
origin: Location
destination: Location
maximumWaitingTime: RelTime -- Maximum time before pickup
where
signatory traveler
controller operator can
nonconsuming RideRequest_Process: Either (ContractId RideRequestRejected) (ContractId RideProposal)
do
(_, fleet) <- fetchByKey @Fleet operator
time <- getTime
-- List all the vehicles and their properties
vehiclesAndProperties <- forA fleet.vehicles (\id -> do
(_, vehicle) <- fetchByKey @Vehicle (operator, id.name)
(_, properties) <- fetchByKey @VehicleProperties (operator, id.name)
template Cash
with
issuer : Party
owner : Party
amount : Decimal
where
signatory issuer, owner
ensure amount > 0.0
choice Transfer : ContractId cash
template Swap
with
buyerCash : ContractId Cash
sellerCash : Cash
where
signatory buyer
choice Settle : (ContractId Cash, ContractId Cash)
with
sellerCashCid : ContractId Cash
choice Split : Either Text (ContractId Cash, ContractId Cash)
with
splitAmount : Decimal
controller owner
do
if splitAmount < amount
then do
s <- create this with amount = splitAmount
r <- create this with amount = this.amount - splitAmount
return (Right (r, s))
template Swap
with
buyerCashCid : ContractId Cash
buyerAmount : Decimal
sellerCash : Cash
sellerAmount : Decimal
where
signatory buyer
choice Settle : Either Text ()
exercise bs Merge with other = br
return (Left err)
Right (ss, sr) -> do
-- If successful, transfer buyer asset and handle any errors from that.
buyerTransfer <- exercise bs Transfer with newOwner = seller
case buyerTransfer of
Left err -> do -- all the tidying up
exercise bs Merge with other = br
exercise ss Merge with other = bs
return (Left err)
template Swap
with
buyerCashCid : ContractId Cash
buyerAmount : Decimal
sellerCash : Cash
sellerAmount : Decimal
where
signatory buyer
choice Settle : Either Text ()
template RockBandNFT
with
uniqueNFTId: Text
band : Party
fan : Party
numConcerts : Integer
issuedDate: Date
where
signatory band
observer fan