More about Contracts in DAML: Exploring Proposal-Acceptance Workflow in DAML

Introduction

In my previous work several important concepts like template, contract and transaction about DAML were introduced, with a very simple IOU demonstrating the relationship between them. We have seen how a new contract instance of the same template is created through choices. Here we make it more interesting and realistic: how two contracts are interacting with each other in DAML through choices.

Templates

IOU Template for Simple Transfer Model

In my previous work, the Iou only makes issuer as signatory, and the choice is Transfer. And whenever Transfer is exercised, a new IOU contract instance is created (becomes active) with new owner given, while the previous IOU contract gets archived.

IOU template taken from my previous work

IOU Template for Propose-Accept Model

To achieve the proposal-acceptance model, we first modify the Iou template by adding owner as signatory, and change the choice to ProposeTransfer. (Note that choice is reformatted for better illustration. The effect is the same.)

IOU template for proposal-acceptance pattern

IOU Transfer Proposal Template

Here is the newly created template, IouTransferProposal.

IouTransferProposal template handling the proposal of transfer
  1. The new owner can reject the proposal.
  2. The new owner can accept the proposal.

Proposal-Acceptance Workflow

These illustrations show the proposal and acceptance of an IOU, and how IouTransferProposal contract works in between. It is assumed that 1-Bank issues and IOU and the current owner is Alice, and Alice plans to transfer this IOU to Bob.

When ProposeTransfer is exercised in an IOU contract, the IOU contract gets archived, and a IouTransferProposal contact is instantiated.
When AcceptProposal is exercised in IouTransferProposal contract, the proposal contract gets archived, and a new IOU contract is instantiated with new owner.

Scenario: Simulating the Flow

As in previous work, we are using “scenario” to demonstrate the proposal-acceptance flow. Here are the steps.

Demonstration Flow

Step 1: 1-Bank issues an IOU of amount 100.0.

Discussion

This proposal-acceptance is seen in our business world. Here we can address some questions about it.

Summary

Hope this small illustration gives you more idea how a more realistic workflow for digital assets is modeled in DAML. We need more templates to achieve some specific pattern such as proposal-acceptance, and DAML provides flexibility when implementing these patterns.

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