Deploying DAML application on a Fabric Network

Introduction

Overview

Quick Overview of Hyperledger Fabric

Fabric Network in this Demo

Daml-on-fabric

Overview

Daml-on-Fabric Repository

Demonstration

Step 1: Bring up the fabric network

git clone https://github.com/digital-asset/daml-on-fabric.git
cd daml-on-fabric
cd src/test/fixture
./restart_fabric.sh
Two peers and one Orderer are running
No channel is created yet.

Step 2: Compile Daml code

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=newOwnertemplate 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=bikeShoptemplate BikeRepairProposal
  with
    proposer: Party
    receiver: Party
    proposal: BikeRepair
  where
    signatory proposer
    controller receiver can
      Accept : ContractId BikeRepair
        do
          create proposal
cd my-proj
daml build

Step 3: Bring up daml-on-fabric

cd ../daml-on-fabric
sbt "run --port 6865 --role provision,time,ledger ../my-proj/.daml/dist/my-proj-0.0.1.dar"

Step 4: Inspection from Fabric Perspective

Both peers joined mainchannel
Ledger is consistent in both peers
This database mainchannel_daml_on_fabric keeps all state for our Daml application

Step 5: Allocation Parties to Ledger

cd my-proj
daml ledger allocate-parties --host localhost --port 6865 Martin BikeShop SwissBank

Step 6: Run Navigator

cd my-proj
daml navigator server --port 7500
Martin’s view: no active contracts as the repair service is done and money is paid
BikeShop’s view: repair service is complete (archived) and an active cash contract (paid by Martin)
SwissBank’s view: a Cash (liability to the bank) item, now owned by BikeShop.

Discussion

Summary

This article has been published from the source link without modifications to the text. Only the headline has been changed.

Source link