Fix my Bike again: Deploy Daml Project in PostgreSQL-based Daml Ledger

Introduction

Overview

Demonstration Setup

Demonstration

Step 1: Install PostgreSQL

Step 2: Create a database and a user

sudo -i -u postgres
psql
CREATE DATABASE damlledger;CREATE USER daml WITH ENCRYPTED PASSWORD 'daml';GRANT ALL PRIVILEGES ON DATABASE damlledger TO daml;

Step 3: Run daml-on-sql driver accessing the database

java -jar daml-on-sql-1.11.0.jar --ledgerid=test --sql-backend-jdbcurl='jdbc:postgresql://localhost/damlledger?user=daml&password=daml'

Step 4: Deploy Daml project

daml new my-proj --template skeleton
cd my-proj
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 deploy --host localhost --port 6865

Step 5: Run Navigator

daml navigator server --port 7500

Step 6: Access Navigator

Step 7: Scenario Simulation

In Martin’s view, all contracts are archived.
In BikeShop’s view, the Cash contract is active. All repair service contracts are history.
In SwissBank’s view, there is still Cash contract, though the owner is now changed to BikeShop.

Step 8: Observe ledger persistence

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