Fix my Bike Again: Demonstration of Navigator in Daml

Introduction

Overview

Demonstration Setup

daml new bikedemo --template empty-skeleton
cd bikedemo
sdk-version: 1.10.0
name: bikedemo
source: daml
parties:
- Martin
- BikeShop
- SwissBank

version: 0.0.1
dependencies:
- daml-prim
- daml-stdlib
- daml-script
sandbox-options:
- --wall-clock-time
module BikeShop wheredata Currency = USD | EUR | GBP | CHF
deriving (Eq, Show)
template Cash
with
issuer: Party
owner: Party
currency: Currency
amount: Decimal
where
signatory issuer
controller owner can
Transfer : ContractId Cash
with
newOwner: Party
do
create this with owner=newOwner
template BikeRepair
with
bikeShop: Party
bikeOwner: Party
description: Text
price: Decimal
paymentDue: Date
where
signatory bikeShop, bikeOwner
controller bikeOwner can
Pay : ContractId Cash
with
cashCid: ContractId Cash
do
cash <- fetch cashCid
assert (
cash.currency == CHF &&
cash.amount == price)
exercise cashCid Transfer with newOwner=bikeShop
template BikeRepairProposal
with
proposer: Party
receiver: Party
proposal: BikeRepair
where
signatory proposer
controller receiver can
Accept : ContractId BikeRepair
do
create proposal
daml start
Launch Daml Sandbox and Navigator with one command
Navigator

Demonstration

Step 1: Quick introduction of Navigator

Step 2: SwissBank issues Cash

An active Cash contract in the ledger.
Details of this Cash contract, and choices available
Martin sees the same result as an observer

Step 3: BikeShop proposes a service offer to Martin

BikeShop sees nothing on the active Cash contract.
BikeRepairProposal: proposed by BikeShop.

Step 4: Martin accepts the proposal

Martin sees the BikeRepairProposal contract
The BikeRepairProposal (middle, grey in colour) gets archived after acceptance by Martin.
Same BikeRepair contract, binding both Martin and BikeShop.

Step 5: Martin pays BikeShop after the service is complete

A Cash Contract ID is needed to exercise the Pay choice.
Martin’s Cash Contract ID: 000c3d9…
Fill in the Cash Contract ID and click Submit
No more active contracts in Martin’s view
All previous active contracts got archived (grey in colour)
BikeShop sees an active Cash contract
BikeRepair contract is archived (grey in colour)
SwissBank only sees Cash contracts.

Observation

Summary

Visit http://www.ledgertech.biz/kcarticles.html for all my works. Reach me on https://www.linkedin.com/in/ktam1/ or follow me @kctheservant in Twitter.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store