Fix my Bike Again: Demonstration of Navigator in Daml

Introduction

In my previous works on Daml, I keep using Daml Studio to learn, practice, and test this modeling language. Besides code editing, Daml Studio has an environment of script execution, which is good for code development and workflow simulation. Through simulation we can observe the lifecycle of contracts in the Daml ledger and make interactions with these active contracts through exercising choices.

Overview

While Daml Studio comes with everything for simulation, Navigator is a frontend of a stack, in which the Daml code is first compiled and then working with a Daml ledger. Our demonstration is using Daml Sandbox, while Navigator can work with other Daml ledgers.

Demonstration Setup

Create a project bikedemo with template empty skeleton.

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

Login with any party (say Martin). We see Martin’s view in Navigator.

Step 2: SwissBank issues Cash

We first login as SwissBank. Select Template Cash. A page is shown requesting parameters defined in the template Cash. They are issuer, owner, currency and amount.

  • owner: Martin
  • currency: CHF
  • amount: 200.0
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

Now Martin visits the BikeShop asking for a repair service for his bike. BikeShop creates a BikeRepairProposal contract with Martin.

BikeShop sees nothing on the active Cash contract.
  • receiver: Martin
  • proposal.bikeShop: BikeShop
  • proposal.bikeOwner: Martin
  • proposal.description: “Fix the bike”
  • proposal.price: 200.0
  • proposal.paymentDue: 2021–03–05
BikeRepairProposal: proposed by BikeShop.

Step 4: Martin accepts the proposal

We now see two active contracts in Martin’s view. The Cash contract issued by SwissBank, and the BikeRepairProposal contract created by BikeShop.

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

Assuming Martin is happy with the service and uses his Cash contract, issued by SwissBank, to pay BikeShop.

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

There are two observations during our demonstration.

Summary

We have repeated our demonstration in the previous article with the Navigator, which gives us a user friendly browser-based tool to interact with our model deployed in the ledger (here we are using Sandbox). Hope this brings you more information when you learn and practice with Daml. You can refer to Daml documentation for more about Navigator.

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