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
template Fleet | |
with | |
operator: Party | |
vehicles: [VehicleId] | |
where | |
signatory operator | |
key operator: Party | |
maintainer key |
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
template RideRequest | |
with | |
operator: Party | |
traveler: Party | |
origin: Location | |
destination: Location | |
maximumWaitingTime: RelTime -- Maximum time before pickup | |
where | |
signatory traveler | |
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
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) |
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
template Cash | |
with | |
issuer : Party | |
owner : Party | |
amount : Decimal | |
where | |
signatory issuer, owner | |
ensure amount > 0.0 | |
choice Transfer : ContractId cash |
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
template Swap | |
with | |
buyerCash : ContractId Cash | |
sellerCash : Cash | |
where | |
signatory buyer | |
choice Settle : (ContractId Cash, ContractId Cash) | |
with | |
sellerCashCid : ContractId Cash |
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
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)) |
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
template Swap | |
with | |
buyerCashCid : ContractId Cash | |
buyerAmount : Decimal | |
sellerCash : Cash | |
sellerAmount : Decimal | |
where | |
signatory buyer | |
choice Settle : Either Text () |
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
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) |
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
template Swap | |
with | |
buyerCashCid : ContractId Cash | |
buyerAmount : Decimal | |
sellerCash : Cash | |
sellerAmount : Decimal | |
where | |
signatory buyer | |
choice Settle : Either Text () |
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
template RockBandNFT | |
with | |
uniqueNFTId: Text | |
band : Party | |
fan : Party | |
numConcerts : Integer | |
issuedDate: Date | |
where | |
signatory band | |
observer fan |