DAML SDK Documentation

Total Page:16

File Type:pdf, Size:1020Kb

DAML SDK Documentation DAML SDK Documentation Digital Asset Version : 1.3.0-snapshot.20200706.4664.0.5db06051 0 Copyright 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. Any unauthorized use, duplication or distribution is strictly prohibited. Table of contents Table of contents i 1 Getting started 1 1.1 Installing the SDK ............................................. 1 1.1.1 1. Install the dependencies .................................. 1 1.1.2 2. Install the SDK ......................................... 3 1.1.3 Next steps ............................................. 3 1.1.4 Alternative: manual download ................................ 3 1.2 Getting Started with DAML ........................................ 5 1.2.1 Prerequisites ........................................... 5 1.2.2 Running the app ......................................... 5 1.3 Testing Your App .............................................. 8 1.3.1 Setting up our tests ....................................... 9 1.3.2 Example: Logging in and out ................................. 9 1.3.3 Accessing UI elements ..................................... 10 1.3.4 Writing CSS Selectors ...................................... 10 1.3.5 The Full Test Suite ........................................ 10 2 Writing DAML 12 2.1 An introduction to DAML ......................................... 12 2.1.1 1 Basic contracts ......................................... 12 2.1.2 2 Testing templates using scenarios ............................ 14 2.1.3 3 Data types ............................................ 19 2.1.4 4 Transforming data using choices ............................. 34 2.1.5 5 Adding constraints to a contract ............................. 40 2.1.6 6 Parties and authority ..................................... 49 2.1.7 7 Composing choices ...................................... 58 2.2 Language reference docs ......................................... 66 2.2.1 Overview: template structure ................................. 66 2.2.2 Reference: templates ...................................... 69 2.2.3 Reference: choices ........................................ 72 2.2.4 Reference: updates ....................................... 76 2.2.5 Reference: data types ...................................... 80 2.2.6 Reference: built-in functions ................................. 86 2.2.7 Reference: expressions ..................................... 88 2.2.8 Reference: functions ...................................... 91 2.2.9 Reference: scenarios ...................................... 93 2.2.10 Reference: DAML file structure ................................ 94 2.2.11 Reference: DAML packages .................................. 95 2.2.12 Contract keys ........................................... 102 i 2.3 DAML Studio ................................................. 108 2.3.1 Installing .............................................. 108 2.3.2 Creating your first DAML file ................................. 108 2.3.3 Supported features ....................................... 110 2.3.4 Common scenario errors .................................... 113 2.3.5 Working with multiple packages .............................. 116 2.4 Testing using scenarios ......................................... 117 2.4.1 Scenario syntax .......................................... 118 2.4.2 Running scenarios in DAML Studio ............................. 118 2.4.3 Examples .............................................. 118 2.5 Troubleshooting ............................................... 120 2.5.1 Error: 0<X> is not authorized to commit an update0 .................. 120 2.5.2 Error 0Argument is not of serializable type0 ....................... 121 2.5.3 Modelling questions ....................................... 121 2.5.4 Testing questions ........................................ 123 2.6 Good design patterns ........................................... 124 2.6.1 Initiate and Accept ........................................ 124 2.6.2 Multiple party agreement ................................... 126 2.6.3 Delegation ............................................. 128 2.6.4 Authorization ........................................... 131 2.6.5 Locking ............................................... 133 2.6.6 Diagram legends ......................................... 141 3 Building applications 143 3.1 Application architecture ......................................... 143 3.1.1 Backend .............................................. 145 3.1.2 Frontend .............................................. 145 3.1.3 Authentication .......................................... 146 3.1.4 Developer workflow ....................................... 146 3.2 JavaScript Client Libraries ........................................ 148 3.2.1 JavaScript Code Generator ................................... 148 3.2.2 @daml/react ........................................... 153 3.2.3 @daml/ledger ........................................... 153 3.2.4 @daml/types ........................................... 153 3.3 HTTP JSON API Service ........................................... 153 3.3.1 DAML-LF JSON Encoding .................................... 154 3.3.2 Query language .......................................... 160 3.3.3 How to start ............................................ 162 3.3.4 Example session ......................................... 165 3.3.5 Choosing a party ......................................... 165 3.3.6 Error Reporting .......................................... 166 3.3.7 Create a new Contract ...................................... 168 3.3.8 Create a new Contract with an optional meta field ................... 169 3.3.9 Exercise by Contract ID ..................................... 170 3.3.10 Exercise by Contract Key .................................... 171 3.3.11 Create and Exercise in the Same Transaction ...................... 172 3.3.12 Fetch Contract by Contract ID ................................. 174 3.3.13 Fetch Contract by Key ...................................... 175 3.3.14 Contract Search, All Templates ................................ 176 3.3.15 Contract Search ......................................... 177 3.3.16 Fetch Parties by Identifiers .................................. 179 3.3.17 Fetch All Known Parties ..................................... 180 3.3.18 Allocate a New Party ....................................... 180 3.3.19 List All DALF Packages ..................................... 181 3.3.20 Download a DALF Package ................................... 181 3.3.21 Upload a DAR File ......................................... 182 3.3.22 Streaming API ........................................... 183 3.4 DAML Script ................................................. 188 3.4.1 DAML Script Library ....................................... 188 3.4.2 Usage ................................................ 190 3.4.3 Using DAML Script for Ledger Initialization ........................ 194 3.4.4 Using DAML Script in Distributed Topologies ....................... 194 3.4.5 Running DAML Script against Authenticated Ledgers ................. 195 3.4.6 Running DAML Script against the HTTP JSON API .................... 195 3.5 Upgrading and extending DAML applications ........................... 196 3.5.1 Automating the Upgrade Process .............................. 196 3.5.2 Structuring upgrade contracts ................................ 199 3.5.3 Building and deploying coin-1.0.0 .............................. 201 3.5.4 Create some coin-1.0.0 coins ................................. 201 3.5.5 Building and deploying coin-2.0.0 .............................. 202 3.5.6 Building and deploying coin-upgrade ........................... 202 3.5.7 Upgrade existing coins from coin-1.0.0 to coin-2.0.0 .................. 203 3.5.8 Further Steps ........................................... 203 3.6 Authentication ............................................... 203 3.6.1 Introduction ............................................ 203 3.6.2 Access tokens and claims ................................... 205 3.6.3 Getting access tokens ..................................... 205 3.6.4 Using access tokens ...................................... 206 3.7 The Ledger API ................................................ 206 3.7.1 The Ledger API services ..................................... 206 3.7.2 gRPC ................................................. 210 3.7.3 Ledger API Reference ...................................... 212 3.7.4 How DAML types are translated to protobuf ........................ 246 3.7.5 How DAML types are translated to DAML-LF ........................ 252 3.7.6 Java bindings ........................................... 256 3.7.7 Scala bindings .......................................... 288 3.7.8 Node.js bindings ......................................... 292 3.7.9 Creating your own bindings .................................. 292 3.7.10 What’s in the Ledger API .................................... 295 3.7.11 DAML-LF ............................................... 296 4 Deploying to DAML ledgers 297 4.1 Overview of DAML ledgers ........................................ 297 4.1.1 Commercial Integrations ................................... 297 4.1.2 Open Source Integrations ................................... 297 4.1.3 DAML Ledgers in Development ................................ 297 4.2 Deploying to a generic DAML ledger .................................. 298 4.2.1 Connecting via TLS ........................................ 299 4.3 DAML Ledger Topologies ........................................
Recommended publications
  • Component Design Recall: Problem with Subclassing
    the gamedesigninitiative at cornell university Lecture 8 Component Design Recall: Problem with Subclassing Games have lots of classes Each game entity is different NPC Needs its own functionality (e.g. object methods) Human Orc Want to avoid redundancies Makes code hard to change Common source of bugs Human Human Orc Orc Warrior Archer Warrior Archer Might be tempted to subclass Common behavior in parents Redundant Behavior Specific behavior in children the gamedesigninitiative 2 Architecture Patterns at cornell university Recall: Problem with Subclassing Games have lots of classes Each game entity is different NPC Needs its own functionality (e.g. object methods) Warrior Archer Want to avoid redundancies Makes code hard to change Common source of bugs Human Orc Human Orc Warrior Warrior Archer Archer Might be tempted to subclass Common behavior in parents Redundant Behavior Specific behavior in children the gamedesigninitiative 3 Architecture Patterns at cornell university Alternative: Decorator Pattern New Functionality OriginalReference to Original Request Decorator Object Functionalitybase object Object the gamedesigninitiative 4 Architecture Patterns at cornell university Alternate: Delegation Pattern Original Reference to Request Delegate Object delegate Object Forward Request Inversion of the Decorator Pattern the gamedesigninitiative 5 Architecture Patterns at cornell university Issues with Static Typing Method in original class Original object class obj.request(arg1,…, argn) Original Reference to Request Delegate
    [Show full text]
  • Game Architecture Revisited Recall: the Game Loop
    the gamedesigninitiative at cornell university Lecture 8 Game Architecture Revisited Recall: The Game Loop Receive player input Process player actions Update 60 times/s Process NPC actions Interactions (e.g. physics) = 16.7 ms Cull non-visible objects Transform visible objects Draw Draw to backing buffer Display backing buffer the gamedesigninitiative 2 Architecture Revisited at cornell university The Game Loop Receive player input Process player actions Update Process NPC actions Interactions (e.g. physics) Almost everything is in loop Draw Except asynchronous actions Is enough for simple games How do we organize this loop? Do not want spaghetti code Distribute over programmers the gamedesigninitiative 3 Architecture Revisited at cornell university Model-View-Controller Pattern Controller Calls the • Updates model in methods of response to events • Updates view with model changes Model View • Defines/manages • Displays model the program data to the user/player • Responds to the • Provides interface controller requests for the controller the gamedesigninitiative 4 Architecture Revisited at cornell university The Game Loop and MVC Model: The game state Value of game resources Location of game objects Update View: The draw phase Rendering commands only Major computation in update Draw Controller: The update phase Alters the game state Vast majority of your code the gamedesigninitiative 5 Architecture Revisited at cornell university Application Structure Root Controller Ownership Subcontroller Subcontroller View Model Model
    [Show full text]
  • Transmit Processing in MIMO Wireless Systems
    IEEE 6th CAS Symp. on Emerging Technologies: Mobile and Wireless Comm Shanghai, China, May 31-June 2,2004 Transmit Processing in MIMO Wireless Systems Josef A. Nossek, Michael Joham, and Wolfgang Utschick Institute for Circuit Theory and Signal Processing, Munich University of Technology, 80333 Munich, Germany Phone: +49 (89) 289-28501, Email: [email protected] Abstract-By restricting the receive filter to he scalar, we weighted by a scalar in Section IV. In Section V, we compare derive the optimizations for linear transmit processing from the linear transmit and receive processing. respective joint optimizations of transmit and receive filters. We A popular nonlinear transmit processing scheme is Tom- can identify three filter types similar to receive processing: the nmamit matched filter (TxMF), the transmit zero-forcing filter linson Harashima precoding (THP) originally proposed for (TxZE), and the transmil Menerfilter (TxWF). The TxW has dispersive single inpur single output (SISO) systems in [IO], similar convergence properties as the receive Wiener filter, i.e. [Ill, but can also be applied to MlMO systems [12], [13]. it converges to the matched filter and the zero-forcing Pter for THP is similar to decision feedback equalization (DFE), hut low and high signal to noise ratio, respectively. Additionally, the contrary to DFE, THP feeds back the already transmitted mean square error (MSE) of the TxWF is a lower hound for the MSEs of the TxMF and the TxZF. symbols to reduce the interference caused by these symbols The optimizations for the linear transmit filters are extended at the receivers. Although THP is based on the application of to obtain the respective Tomlinson-Harashimp precoding (THP) nonlinear modulo operators at the receivers and the transmitter, solutions.
    [Show full text]
  • Download the Basketballplayer.Ngql Fle Here
    Nebula Graph Database Manual v1.2.1 Min Wu, Amber Zhang, XiaoDan Huang 2021 Vesoft Inc. Table of contents Table of contents 1. Overview 4 1.1 About This Manual 4 1.2 Welcome to Nebula Graph 1.2.1 Documentation 5 1.3 Concepts 10 1.4 Quick Start 18 1.5 Design and Architecture 32 2. Query Language 43 2.1 Reader 43 2.2 Data Types 44 2.3 Functions and Operators 47 2.4 Language Structure 62 2.5 Statement Syntax 76 3. Build Develop and Administration 128 3.1 Build 128 3.2 Installation 134 3.3 Configuration 141 3.4 Account Management Statement 161 3.5 Batch Data Management 173 3.6 Monitoring and Statistics 192 3.7 Development and API 199 4. Data Migration 200 4.1 Nebula Exchange 200 5. Nebula Graph Studio 224 5.1 Change Log 224 5.2 About Nebula Graph Studio 228 5.3 Deploy and connect 232 5.4 Quick start 237 5.5 Operation guide 248 6. Contributions 272 6.1 Contribute to Documentation 272 6.2 Cpp Coding Style 273 6.3 How to Contribute 274 6.4 Pull Request and Commit Message Guidelines 277 7. Appendix 278 7.1 Comparison Between Cypher and nGQL 278 - 2/304 - 2021 Vesoft Inc. Table of contents 7.2 Comparison Between Gremlin and nGQL 283 7.3 Comparison Between SQL and nGQL 298 7.4 Vertex Identifier and Partition 303 - 3/304 - 2021 Vesoft Inc. 1. Overview 1. Overview 1.1 About This Manual This is the Nebula Graph User Manual.
    [Show full text]
  • Design Specification for Delegation and Incentives in Cardano
    Engineering Design Specification for Delegation and Incentives in Cardano–Shelley AN IOHK TECHNICAL REPORT Philipp Kant Lars Brunjes¨ Duncan Coutts [email protected] [email protected] [email protected] [email protected] April 11, 2019 Abstract This document describes the requirements and design for a delegation and incentives mechanism to be used in the Shelley release of Cardano. List of Contributors Lars Brunjes,¨ Jared Corduan, Duncan Coutts, Philipp Kant, Dimitris Karakostas, Aggelos Kiayias, Elias Koutsoupias, Mario Larangeira, Damian Nadales, Aikaterini-Panagiota Stouka. Contents 1 Purpose 4 2 Requirements 5 2.1 Functional Requirements . .5 2.1.1 Proof of Eligibility . .5 2.1.2 Visibility of Delegation on the Blockchain . .5 2.1.3 Restricting Chain Delegation . .5 2.1.4 Cheap Re-Delegation . .5 2.1.5 Neutral Addresses . .5 2.2 Security Requirements . .6 2.2.1 Sybil Attack Protection at Stake Pool Level . .6 2.2.2 Address Non-malleability . .6 2.2.3 Public Spending Keys Should not be Disclosed Prematurely . .6 2.2.4 Mitigate Key Exposure . .6 2.2.5 Handle Inactive Stake Pools . .6 2.2.6 Avoid Hard Transition . .6 2.2.7 Change Delegation Without Spending Key . .7 2.3 Non-functional Requirements . .7 2.3.1 Asymptotic space and time complexity . .7 2.3.2 Minimise economic attacks . .7 2.4 Requirements to Preserve Existing Features . .7 2.4.1 Master Recovery Key . .7 1 2.4.2 Address Recognition . .7 2.4.3 Wallet should be Runnable on Independent Devices . .7 2.4.4 Maintain Privacy .
    [Show full text]
  • Three Methods of Finding Remainder on the Operation of Modular
    Zin Mar Win, Khin Mar Cho; International Journal of Advance Research and Development (Volume 5, Issue 5) Available online at: www.ijarnd.com Three methods of finding remainder on the operation of modular exponentiation by using calculator 1Zin Mar Win, 2Khin Mar Cho 1University of Computer Studies, Myitkyina, Myanmar 2University of Computer Studies, Pyay, Myanmar ABSTRACT The primary purpose of this paper is that the contents of the paper were to become a learning aid for the learners. Learning aids enhance one's learning abilities and help to increase one's learning potential. They may include books, diagram, computer, recordings, notes, strategies, or any other appropriate items. In this paper we would review the types of modulo operations and represent the knowledge which we have been known with the easiest ways. The modulo operation is finding of the remainder when dividing. The modulus operator abbreviated “mod” or “%” in many programming languages is useful in a variety of circumstances. It is commonly used to take a randomly generated number and reduce that number to a random number on a smaller range, and it can also quickly tell us if one number is a factor of another. If we wanted to know if a number was odd or even, we could use modulus to quickly tell us by asking for the remainder of the number when divided by 2. Modular exponentiation is a type of exponentiation performed over a modulus. The operation of modular exponentiation calculates the remainder c when an integer b rose to the eth power, bᵉ, is divided by a positive integer m such as c = be mod m [1].
    [Show full text]
  • The Best of Both Worlds?
    The Best of Both Worlds? Reimplementing an Object-Oriented System with Functional Programming on the .NET Platform and Comparing the Two Paradigms Erik Bugge Thesis submitted for the degree of Master in Informatics: Programming and Networks 60 credits Department of Informatics Faculty of mathematics and natural sciences UNIVERSITY OF OSLO Autumn 2019 The Best of Both Worlds? Reimplementing an Object-Oriented System with Functional Programming on the .NET Platform and Comparing the Two Paradigms Erik Bugge © 2019 Erik Bugge The Best of Both Worlds? http://www.duo.uio.no/ Printed: Reprosentralen, University of Oslo Abstract Programming paradigms are categories that classify languages based on their features. Each paradigm category contains rules about how the program is built. Comparing programming paradigms and languages is important, because it lets developers make more informed decisions when it comes to choosing the right technology for a system. Making meaningful comparisons between paradigms and languages is challenging, because the subjects of comparison are often so dissimilar that the process is not always straightforward, or does not always yield particularly valuable results. Therefore, multiple avenues of comparison must be explored in order to get meaningful information about the pros and cons of these technologies. This thesis looks at the difference between the object-oriented and functional programming paradigms on a higher level, before delving in detail into a development process that consisted of reimplementing parts of an object- oriented system into functional code. Using results from major comparative studies, exploring high-level differences between the two paradigms’ tools for modular programming and general program decompositions, and looking at the development process described in detail in this thesis in light of the aforementioned findings, a comparison on multiple levels was done.
    [Show full text]
  • Functional C
    Functional C Pieter Hartel Henk Muller January 3, 1999 i Functional C Pieter Hartel Henk Muller University of Southampton University of Bristol Revision: 6.7 ii To Marijke Pieter To my family and other sources of inspiration Henk Revision: 6.7 c 1995,1996 Pieter Hartel & Henk Muller, all rights reserved. Preface The Computer Science Departments of many universities teach a functional lan- guage as the first programming language. Using a functional language with its high level of abstraction helps to emphasize the principles of programming. Func- tional programming is only one of the paradigms with which a student should be acquainted. Imperative, Concurrent, Object-Oriented, and Logic programming are also important. Depending on the problem to be solved, one of the paradigms will be chosen as the most natural paradigm for that problem. This book is the course material to teach a second paradigm: imperative pro- gramming, using C as the programming language. The book has been written so that it builds on the knowledge that the students have acquired during their first course on functional programming, using SML. The prerequisite of this book is that the principles of programming are already understood; this book does not specifically aim to teach `problem solving' or `programming'. This book aims to: ¡ Familiarise the reader with imperative programming as another way of imple- menting programs. The aim is to preserve the programming style, that is, the programmer thinks functionally while implementing an imperative pro- gram. ¡ Provide understanding of the differences between functional and imperative pro- gramming. Functional programming is a high level activity.
    [Show full text]
  • Fast Integer Division – a Differentiated Offering from C2000 Product Family
    Application Report SPRACN6–July 2019 Fast Integer Division – A Differentiated Offering From C2000™ Product Family Prasanth Viswanathan Pillai, Himanshu Chaudhary, Aravindhan Karuppiah, Alex Tessarolo ABSTRACT This application report provides an overview of the different division and modulo (remainder) functions and its associated properties. Later, the document describes how the different division functions can be implemented using the C28x ISA and intrinsics supported by the compiler. Contents 1 Introduction ................................................................................................................... 2 2 Different Division Functions ................................................................................................ 2 3 Intrinsic Support Through TI C2000 Compiler ........................................................................... 4 4 Cycle Count................................................................................................................... 6 5 Summary...................................................................................................................... 6 6 References ................................................................................................................... 6 List of Figures 1 Truncated Division Function................................................................................................ 2 2 Floored Division Function................................................................................................... 3 3 Euclidean
    [Show full text]
  • Title: Foundation Patterns Authors: Dwight Deugo E-Mail: Deugo@Scs
    Title: Foundation Patterns Authors: Dwight Deugo E-mail: [email protected] Address: School of Computer Science Carleton University 1125 Colonel By Drive Ottawa, Ontario, Canada, K1S 5B6 Telephone: (613) 520-2600 ext. 8438 (613) 520-4333 Fax: (613) 520-4334 Abstract: Many patterns depended on one important distinction: the distinction between an object's class and its type. For example, many patterns rely on interface inheritance, although, on examining their structures, most are described using implementation inheritance. The making of this implicit distinction gives evidence that there are patterns, fundamental to many, that live within other patterns and are at the foundation of good object-oriented principles. I give these patterns the name foundation patterns. I discuss two such foundation patterns: delegation and substitution, separating the two into their rightful positions, making clear what each patterns' role is in object-oriented design. Foundation Patterns Dwight Deugo [email protected] School of Computer Science Carleton University Introduction Although not mentioned, many patterns depend on one important distinction. This is the distinction between an object's class and its type. Stated another way, these patterns rely on interface inheritance rather than on implementation inheritance. Nevertheless, on examining their structures, most pattern descriptions use implementation inheritance. This is not surprising, since languages like Smalltalk and C++ do not explicitly support the notion of a type or a subtype within the language. Java is the exception to this, directly supporting interfaces and their inheritance, bringing attention to these well deserving topics. The making of this implicit distinction gives evidence that there are other patterns, fundamental to many, if not all patterns, which are either assumed and undocumented or still waiting to be discovered.
    [Show full text]
  • Strength Reduction of Integer Division and Modulo Operations
    Strength Reduction of Integer Division and Modulo Operations Saman Amarasinghe, Walter Lee, Ben Greenwald M.I.T. Laboratory for Computer Science Cambridge, MA 02139, U.S.A. g fsaman,walt,beng @lcs.mit.edu http://www.cag.lcs.mit.edu/raw Abstract Integer division, modulo, and remainder operations are expressive and useful operations. They are logical candidates to express complex data accesses such as the wrap-around behavior in queues using ring buffers, array address calculations in data distribution, and cache locality compiler-optimizations. Experienced application programmers, however, avoid them because they are slow. Furthermore, while advances in both hardware and software have improved the performance of many parts of a program, few are applicable to division and modulo operations. This trend makes these operations increasingly detrimental to program performance. This paper describes a suite of optimizations for eliminating division, modulo, and remainder operations from programs. These techniques are analogous to strength reduction techniques used for multiplications. In addition to some algebraic simplifications, we present a set of optimization techniques which eliminates division and modulo operations that are functions of loop induction variables and loop constants. The optimizations rely on number theory, integer programming and loop transformations. 1 Introduction This paper describes a suite of optimizations for eliminating division, modulo, and remainder operations from pro- grams. In addition to some algebraic simplifications, we present a set of optimization techniques which eliminates division and modulo operations that are functions of loop induction variables and loop constants. These techniques are analogous to strength reduction techniques used for multiplications. Integer division, modulo, and remainder are expressive and useful operations.
    [Show full text]
  • Computing Mod Without Mod
    Computing Mod Without Mod Mark A. Will and Ryan K. L. Ko Cyber Security Lab The University of Waikato, New Zealand fwillm,[email protected] Abstract. Encryption algorithms are designed to be difficult to break without knowledge of the secrets or keys. To achieve this, the algorithms require the keys to be large, with some algorithms having a recommend size of 2048-bits or more. However most modern processors only support computation on 64-bits at a time. Therefore standard operations with large numbers are more complicated to implement. One operation that is particularly challenging to implement efficiently is modular reduction. In this paper we propose a highly-efficient algorithm for solving large modulo operations; it has several advantages over current approaches as it supports the use of a variable sized lookup table, has good spatial and temporal locality allowing data to be streamed, and only requires basic processor instructions. Our proposed algorithm is theoretically compared to widely used modular algorithms, before practically compared against the state-of-the-art GNU Multiple Precision (GMP) large number li- brary. 1 Introduction Modular reduction, also known as the modulo or mod operation, is a value within Y, such that it is the remainder after Euclidean division of X by Y. This operation is heavily used in encryption algorithms [6][8][14], since it can \hide" values within large prime numbers, often called keys. Encryption algorithms also make use of the modulo operation because it involves more computation when compared to other operations like add. Meaning that computing the modulo operation is not as simple as just adding bits.
    [Show full text]