mirror of
https://github.com/digital-asset/daml.git
synced 2024-09-11 04:45:57 +03:00
Remove //language-support/js (#691)
The JavaScript ecosystem support is being spun off in its own repository. The new home is https://github.com/digital-asset/daml-js For further details, here is the counterpart issue in the new repo: https://github.com/digital-asset/daml-js/issues/1
This commit is contained in:
parent
f9a438ffb7
commit
7ac438e87b
@ -158,7 +158,6 @@ genrule(
|
||||
"//daml-foundations/daml-ghc:daml-base-rst-docs",
|
||||
"//daml-foundations/daml-ghc:daml-base-hoogle-docs",
|
||||
"//language-support/java:javadocs",
|
||||
"//language-support/js/docs",
|
||||
],
|
||||
outs = ["html-only.tar.gz"],
|
||||
cmd = ("""
|
||||
@ -190,10 +189,6 @@ genrule(
|
||||
# Copy Javadoc
|
||||
tar -zxf ../$(locations //language-support/java:javadocs) -C html/app-dev/bindings-java
|
||||
|
||||
# Copy in JS docs
|
||||
tar -zxf ../$(location //language-support/js/docs) -C html/app-dev/bindings-js
|
||||
mv html/app-dev/bindings-js/docs html/app-dev/bindings-js/reference
|
||||
|
||||
# Copy in hoogle DB
|
||||
mkdir -p html/hoogle_db
|
||||
cp -rL ../$(location //daml-foundations/daml-ghc:daml-base-hoogle-docs) html/hoogle_db/base.txt
|
||||
|
@ -1,41 +0,0 @@
|
||||
.. Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
.. SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
.. _bindings-js-daml-as-json:
|
||||
|
||||
DAML as JSON
|
||||
############
|
||||
|
||||
The Node.js bindings accept as parameters and return as results plain JavaScript objects.
|
||||
|
||||
More specifically, these objects are subset that is fully compatible with the JSON data-interchange format. This means that any request and response to and from the ledger can be easily used with other services that accept JSON as an input format.
|
||||
|
||||
The `reference documentation`_ is more specific about the expected shape of objects sent to and received from the ledger, but to give you a sense of how these objects look, the following represents the creation of a ``Pvp`` record.
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
{
|
||||
create: {
|
||||
templateId: { packageId: '934023fa9c89e8f89b8a', name: 'Pvp.Pvp' },
|
||||
arguments: {
|
||||
recordId: { packageId: '934023fa9c89e8f89b8a', name: 'Pvp.Pvp' },
|
||||
fields: {
|
||||
buyer : { party: 'some-buyer' },
|
||||
seller : { party: 'some-seller' },
|
||||
baseIssuer : { party: 'some-base-issuer' },
|
||||
baseCurrency : { text: 'CHF' },
|
||||
baseAmount : { decimal: '1000000.00' },
|
||||
baseIouCid : { variant: { variantId: { packageId: 'ba777d8d7c88e87f7', name: 'Maybe' }, constructor: 'Just', value: { contractId: '76238b8998a98d98e978f' } } },
|
||||
quoteIssuer : { party: 'some-quote-issuer' },
|
||||
quoteCurrency: { text: 'USD' },
|
||||
quoteAmount : { decimal: '1000001.00' },
|
||||
quoteIouCid : { variant: { variantId: { packageId: 'ba777d8d7c88e87f7', name: 'Maybe' }, constructor: 'Just', value: { contractId: '76238b8998a98d98e978f' } } },
|
||||
settleTime : { timestamp: 93641099000000000 }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Notice that fields of a template are represented as keys in ``fields``. Each value is then another object, where the key is the type. This is necessary for the ledger to disambiguate between, for example, strings that represent ``text`` and strings that represent a ``decimal``.
|
||||
|
||||
.. _reference documentation: ./reference/index.html
|
@ -1,41 +0,0 @@
|
||||
.. Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
.. SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
.. _bindings-js-getting-started:
|
||||
|
||||
Getting started
|
||||
###############
|
||||
|
||||
1. Set up NPM
|
||||
*************
|
||||
|
||||
The Node.js bindings are published on NPM.
|
||||
|
||||
To set up NPM:
|
||||
|
||||
1. `login to Bintray`_
|
||||
2. go to the `Digital Asset NPM repository home page on Bintray`_
|
||||
3. click on the "Set me up!" button
|
||||
4. follow the instructions for scoped packages with scope `da`
|
||||
|
||||
2. Start a new project
|
||||
**********************
|
||||
|
||||
Use ``npm init`` to create a new project.
|
||||
|
||||
3. Install the bindings
|
||||
***********************
|
||||
|
||||
Use the NPM command line interface:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
npm install @da/daml-ledger
|
||||
|
||||
4. Start coding
|
||||
***************
|
||||
|
||||
To guide you through using the Node.js bindings, we provide a tutorial template and a :doc:`tutorial <tutorial>`.
|
||||
|
||||
.. _login to Bintray: https://bintray.com/login?forwardedFrom=%2Fdigitalassetsdk
|
||||
.. _Digital Asset NPM repository home page on Bintray: https://bintray.com/digitalassetsdk/npm
|
@ -1,22 +0,0 @@
|
||||
.. Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
.. SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
Node.js bindings
|
||||
################
|
||||
|
||||
.. toctree::
|
||||
:hidden:
|
||||
|
||||
getting-started
|
||||
tutorial
|
||||
daml-as-json
|
||||
|
||||
The Node.js bindings let you access the Ledger API from Node.js code.
|
||||
|
||||
The Installing page guides you through the process of :doc:`getting-started`.
|
||||
|
||||
After that, a tutorial teaches you :doc:`how to build a simple application from scratch <tutorial>`.
|
||||
|
||||
Finally, `the API reference documentation`_ and :doc:`an introduction to DAML as JSON <daml-as-json>` are also available.
|
||||
|
||||
.. _the API reference documentation: ./reference/index.html
|
@ -1,951 +0,0 @@
|
||||
.. Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
.. SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
.. _bindings-js-tutorial:
|
||||
|
||||
Tutorial
|
||||
########
|
||||
|
||||
This tutorial guides you through a series of steps to write a simple application.
|
||||
|
||||
The purpose is to learn the basics of how to use the Node.js bindings.
|
||||
|
||||
The task is to build an application able to send and receive "ping" messages.
|
||||
|
||||
The focus is not on the complexity of the model, but rather on how to use the bindings to interact with the ledger.
|
||||
|
||||
Create the project
|
||||
******************
|
||||
|
||||
Start from the skeleton available `here <https://github.com/digital-asset/ex-tutorial-nodejs>`_.
|
||||
|
||||
To set it up, clone the repo:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
git clone https://github.com/digital-asset/ex-tutorial-nodejs.git
|
||||
cd ex-tutorial-nodejs
|
||||
|
||||
The skeleton includes ``daml/PingPong.daml``, which is the source for a DAML module with two templates: ``Ping`` and ``Pong``. The app uses these.
|
||||
|
||||
Run the sandbox
|
||||
***************
|
||||
|
||||
Use the sandbox to run and test your application.
|
||||
|
||||
Now that you created the project and you're in its directory, start the sandbox by running:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
da sandbox
|
||||
|
||||
Starting the sandbox automatically compiles ``PingPong.daml`` and loads it.
|
||||
|
||||
Run the skeleton app
|
||||
********************
|
||||
|
||||
You are now set to write your own application. The template includes a skeleton app that connects to a running ledger and quits.
|
||||
|
||||
1. Install the dependencies for your package (including the bindings):
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
npm install
|
||||
|
||||
2. Start the application:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
npm start
|
||||
|
||||
3. Verify the output is correct
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
hello from <LEDGER_ID>
|
||||
|
||||
Understand the skeleton
|
||||
***********************
|
||||
|
||||
The code for the script you just ran is ``index.js``.
|
||||
|
||||
Let's go through the skeleton part by part to understand what's going on:
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
const da = require('@da/daml-ledger').data;
|
||||
|
||||
const uuidv4 = require('uuid/v4');
|
||||
|
||||
The first line loads the bindings and allows you to refer to them through the ``da`` object.
|
||||
|
||||
The second one introduces a dependency that is going to be later used to generate unique identifiers; no need to worry about it now.
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
let [, , host, port] = process.argv;
|
||||
|
||||
host = host || 'localhost';
|
||||
port = port || 6865;
|
||||
|
||||
These lines read the command-line arguments and provide some sensible defaults.
|
||||
|
||||
Now to the juicy part:
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
da.DamlLedgerClient.connect({ host: host, port: port }, (error, client) => {
|
||||
if (error) throw error;
|
||||
console.log('hello from', client.ledgerId);
|
||||
});
|
||||
|
||||
Here the application connects to the ledger with the ``DamlLedgerClient.connect`` method.
|
||||
|
||||
It accepts two arguments:
|
||||
|
||||
- an object with the connection options
|
||||
- a callback to be invoked when the connection either fails or succeeds
|
||||
|
||||
The connection options require you to pass the ``host`` and ``port`` of the ledger instance you are connecting to.
|
||||
|
||||
The callback follows the common pattern in Node.js of being invoked with two arguments: the first is an error in case of failure while the latter is the response in case of success.
|
||||
|
||||
In this case in particular, the response in case of success is a ``client`` object that can be used to communicate with the ledger.
|
||||
|
||||
The skeleton application just prints the greeting message with the ledger identifier and quits.
|
||||
|
||||
Retrieve the package identifiers
|
||||
********************************
|
||||
|
||||
Now that the sandbox is running, the ``PingPong.daml`` file has been compiled and the module loaded onto the ledger.
|
||||
|
||||
In order for you to refer to the templates therein you need its package identifier.
|
||||
|
||||
This template includes a script that connects to a running ledger instance and downloads the package identifiers for the templates.
|
||||
|
||||
Run it now:
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
npm run fetch-template-ids
|
||||
|
||||
If the program ran successfully, the project root now contains the ``template-ids.json`` file.
|
||||
|
||||
It's time to write some code to verify that you're good to go. Open the ``index.js`` file and edit it.
|
||||
|
||||
First of all, right after the first ``require`` statement, add a new one to load the ``template-ids.json`` file that has just been created.
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
const da = require('@da/daml-ledger').data;
|
||||
const templateIds = require('./template-ids.json');
|
||||
|
||||
Right beneath that line, initialize two constants to hold the ``Ping`` and ``Pong`` template identifiers:
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
const PING = templateIds['PingPong.Ping'];
|
||||
const PONG = templateIds['PingPong.Pong'];
|
||||
|
||||
Finally print the template identifiers:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
da.DamlLedgerClient.connect({ host: host, port: port }, (error, client) => {
|
||||
if (error) throw error;
|
||||
console.log('hello from', client.ledgerId);
|
||||
console.log('Ping', PING);
|
||||
console.log('Pong', PONG);
|
||||
});
|
||||
|
||||
Run the application again (``npm start``) to see an output like the following:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
hello from sandbox-3957952d-f475-4d2f-be89-245a0799d2c0
|
||||
Ping { packageId:
|
||||
'5976641aeea761fa8946ea004b318a74d869ee305fafcdc6bf98d31fa354304d',
|
||||
name: 'PingPong.Ping' }
|
||||
Pong { packageId:
|
||||
'5976641aeea761fa8946ea004b318a74d869ee305fafcdc6bf98d31fa354304d',
|
||||
name: 'PingPong.Pong' }
|
||||
|
||||
The ``PingPong`` module
|
||||
***********************
|
||||
|
||||
Before moving on to the implementation of the application, have a look at ``daml/PingPong.daml`` to understand the module the app uses.
|
||||
|
||||
``Ping`` and ``Pong`` are almost identical. Looking at them in detail:
|
||||
|
||||
- both have a ``sender`` signatory and a ``receiver`` observer
|
||||
- the receiver of a ``Ping`` can exercise the ``ReplyPong`` choice, creating a ``Pong`` contract with swapped ``sender`` and ``receiver``
|
||||
- symmetrically, the receiver of a ``Pong`` contract can exercise the ``ReplyPing`` choice, creating a ``Ping`` contract with swapped parties
|
||||
|
||||
Note that the contracts carry a counter: when the counter reaches 3, no new contract is created and the exchange stops.
|
||||
|
||||
Pass the parties as parameters
|
||||
******************************
|
||||
|
||||
Everything's now ready to start working. Edit the ``index.js`` file.
|
||||
|
||||
Each contract has a sender and a receiver, so your application needs to establish it.
|
||||
|
||||
Read those from the command line by editing the part where the arguments are read as follows:
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
let [, , sender, receiver, host, port] = process.argv;
|
||||
host = host || 'localhost';
|
||||
port = port || 6865;
|
||||
if (!sender || !receiver) {
|
||||
console.log('Missing sender and/or receiver arguments, exiting.');
|
||||
process.exit(-1);
|
||||
}
|
||||
|
||||
Try to run it without arguments (or with just one) to see the error popping up.
|
||||
|
||||
Try to run it with both arguments to see the application working just as it did before.
|
||||
|
||||
Create a contract
|
||||
*****************
|
||||
|
||||
To kickstart the exchange between two parties you have to first make one party *"send"* the initial ping to the other.
|
||||
|
||||
To do this you need to create a ``Ping`` contract.
|
||||
|
||||
This requires you to submit a command to the ledger. For this, use the ``CommandService``.
|
||||
|
||||
The ``client`` object returned by the ``DamlLedgerClient.connect`` method contains a reference to all services exposed by the ledger, including the ``CommandService``.
|
||||
|
||||
First of all, the following is the ``request`` for the ``CommandService``. Have a look at it:
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
const request = {
|
||||
commands: {
|
||||
applicationId: 'PingPongApp',
|
||||
workflowId: `Ping-${sender}`,
|
||||
commandId: uuidv4(),
|
||||
ledgerEffectiveTime: { seconds: 0, nanoseconds: 0 },
|
||||
maximumRecordTime: { seconds: 5, nanoseconds: 0 },
|
||||
party: sender,
|
||||
list: [
|
||||
{
|
||||
create: {
|
||||
templateId: PING,
|
||||
arguments: {
|
||||
fields: {
|
||||
sender: { party: sender },
|
||||
receiver: { party: receiver },
|
||||
count: { int64: 0 }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
This object represents the submission of a set of commands to be applied atomically. Let's see what each bit of it means:
|
||||
|
||||
- ``applicationId``
|
||||
the name of your application
|
||||
- ``commandId``
|
||||
a unique identifier for the set of submitted commands
|
||||
- ``workflowId``
|
||||
an (optional) identifier you can use to group together commands pertaining to one of your workflows
|
||||
- ``ledgerEffectiveTime``
|
||||
the time at which the set of submitted commands are applied; normally the client's current epoch time, but, since the sandbox (by default) runs with a static time fixed at epoch 0, use this value
|
||||
- ``maximumRecordTime``
|
||||
the time at which the command is considered expired if it's not been applied yet; the difference with the ``maximumRecordTime`` is the time-to-live (TTL) of the command
|
||||
- ``party``
|
||||
who's submitting the command
|
||||
|
||||
Finally, ``list`` contains all the commands to be applied. In this case, it submits a ``create`` command.
|
||||
|
||||
Have a look at the only command:
|
||||
|
||||
- ``templateId``
|
||||
the identifier of the template of the contract you wish to create (``Ping``)
|
||||
- ``arguments``
|
||||
an object containing the ``fields`` necessary to create the contract
|
||||
|
||||
The keys of the ``fields`` object are the template parameter names as they appear on ``daml/PingPong.daml``, while the values are a pair with the type and the value being passed (in this case two parties).
|
||||
|
||||
The request can now be passed to the ``CommandService`` as follows:
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
client.commandClient.submitAndWait(request, (error, _) => {
|
||||
if (error) throw error;
|
||||
console.log(`Created Ping contract from ${sender} to ${receiver}.`);
|
||||
});
|
||||
|
||||
This is already a sizeable chunk of code that performs a clearly defined task. Within the body of the ``connect`` callback, wrap the code from this section in a function called ``createFirstPing`` and call it.
|
||||
|
||||
The code should now look like the following:
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
da.DamlLedgerClient.connect({ host: host, port: port }, (error, client) => {
|
||||
if (error) throw error;
|
||||
|
||||
createFirstPing();
|
||||
|
||||
function createFirstPing() {
|
||||
const request = {
|
||||
commands: {
|
||||
applicationId: 'PingPongApp',
|
||||
workflowId: `Ping-${sender}`,
|
||||
commandId: uuidv4(),
|
||||
ledgerEffectiveTime: { seconds: 0, nanoseconds: 0 },
|
||||
maximumRecordTime: { seconds: 5, nanoseconds: 0 },
|
||||
party: sender,
|
||||
list: [
|
||||
{
|
||||
create: {
|
||||
templateId: PING,
|
||||
arguments: {
|
||||
fields: {
|
||||
sender: { party: sender },
|
||||
receiver: { party: receiver },
|
||||
count: { int64: 0 }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
client.commandClient.submitAndWait(request, (error, _) => {
|
||||
if (error) throw error;
|
||||
console.log(`Created Ping contract from ${sender} to ${receiver}.`);
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Time to test your application. Run it like this:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
npm start Alice Bob
|
||||
|
||||
You should see the following output:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
Created Ping contract from Alice to Bob.
|
||||
|
||||
Your application now successfully creates a ``Ping`` contract on the ledger, congratulations!
|
||||
|
||||
Read the transactions
|
||||
*********************
|
||||
|
||||
Now that the application can create a contract to send a *ping*, it must also be able to listen to *pongs* on the ledger so that it can react to those.
|
||||
|
||||
The ``TransactionService`` exposes the functionality to read transactions from the ledger via the ``getTransactions`` method.
|
||||
|
||||
This method takes the following request:
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
const filtersByParty = {};
|
||||
filtersByParty[sender] = { inclusive: { templateIds: [PING, PONG] } };
|
||||
const request = {
|
||||
begin: { boundary: da.LedgerOffset.Boundary.END },
|
||||
filter: { filtersByParty: filtersByParty }
|
||||
};
|
||||
|
||||
Have a look at the request:
|
||||
|
||||
- ``begin``
|
||||
the offset at which you'll start reading transactions from the ledger. In this case you want to listen starting from the latest one (represented by the constant ``da.LedgerOffset.Boundary.END``)
|
||||
- ``end``
|
||||
the optional offset at which you want the reads to end -- if absent (as in this case) the application keeps listening to incoming transactions
|
||||
- ``filter``
|
||||
represents which contracts you want the ledger to show you: in this case you are asking for the transactions visible to ``sender`` containing contracts whose ``templateId`` matches either ``PING`` or ``PONG``.
|
||||
|
||||
When the ``getTransactions`` method is invoked with this request the application listens to the latest transactions coming to the ledger.
|
||||
|
||||
The output of this method is a Node.js stream. As such, you can register callbacks on the ``'data'`` and ``'error'`` events.
|
||||
|
||||
The following code prints the incoming transaction and quits in case of ``'error'``.
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
const transactions = client.transactionClient.getTransactions(request);
|
||||
console.log(`${sender} starts reading transactions.`);
|
||||
transactions.on('data', response => {
|
||||
for (const transaction of response.transactions) {
|
||||
console.log('Transaction read:', transaction.transactionId);
|
||||
}
|
||||
});
|
||||
transactions.on('error', error => {
|
||||
console.error(`${sender} encountered an error while processing transactions!`);
|
||||
console.error(error);
|
||||
process.exit(-1);
|
||||
});
|
||||
|
||||
.. note::
|
||||
|
||||
If your request specified an ``end``, it would most probably make sense to register an ``'end'`` event callback on the stream as well.
|
||||
|
||||
Again, this code represents a sizeable chunk of code with a clearly defined purpose.
|
||||
|
||||
Wrap this code in a new function called ``listenForTransactions``, place it within the ``connect`` callback and call ``listenForTransactions`` right before you call ``createFirstPing``.
|
||||
|
||||
When you are done, your code should look like the following:
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
da.DamlLedgerClient.connect({ host: host, port: port }, (error, client) => {
|
||||
if (error) throw error;
|
||||
|
||||
listenForTransactions();
|
||||
createFirstPing();
|
||||
|
||||
function createFirstPing() {
|
||||
const request = {
|
||||
commands: {
|
||||
applicationId: 'PingPongApp',
|
||||
workflowId: `Ping-${sender}`,
|
||||
commandId: uuidv4(),
|
||||
ledgerEffectiveTime: { seconds: 0, nanoseconds: 0 },
|
||||
maximumRecordTime: { seconds: 5, nanoseconds: 0 },
|
||||
party: sender,
|
||||
list: [
|
||||
{
|
||||
create: {
|
||||
templateId: PING,
|
||||
arguments: {
|
||||
fields: {
|
||||
sender: { party: sender },
|
||||
receiver: { party: receiver },
|
||||
count: { int64: 0 }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
client.commandClient.submitAndWait(request, error => {
|
||||
if (error) throw error;
|
||||
console.log(`Created Ping contract from ${sender} to ${receiver}.`);
|
||||
});
|
||||
}
|
||||
|
||||
function listenForTransactions() {
|
||||
console.log(`${sender} starts reading transactions.`);
|
||||
const filtersByParty = {};
|
||||
filtersByParty[sender] = { inclusive: { templateIds: [PING, PONG] } };
|
||||
const request = {
|
||||
begin: { boundary: da.LedgerOffset.Boundary.END },
|
||||
filter: { filtersByParty: filtersByParty }
|
||||
};
|
||||
const transactions = client.transactionClient.getTransactions(request);
|
||||
transactions.on('data', response => {
|
||||
for (const transaction of response.transactions) {
|
||||
console.log('Transaction read:', transaction.transactionId);
|
||||
}
|
||||
});
|
||||
transactions.on('error', error => {
|
||||
console.error(`${sender} encountered an error while processing transactions!`);
|
||||
console.error(error);
|
||||
process.exit(-1);
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Your application now should:
|
||||
|
||||
- start listening to pings and pongs visible to the sender
|
||||
- create the first ping
|
||||
- receive the ping it created and print its transaction identifer
|
||||
|
||||
If you now run
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
npm start Alice Bob
|
||||
|
||||
You should see an output like the following:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
Alice starts reading transactions.
|
||||
Created Ping contract from Alice to Bob.
|
||||
Transaction read: 1
|
||||
|
||||
Your application is now able to create contracts and listen to transactions on the ledger. Very good!
|
||||
You can now hit CTRL-C to quit the application.
|
||||
|
||||
Exercise a choice
|
||||
*****************
|
||||
|
||||
The last piece of functionality you need consists of reacting to pings and pongs that you read from the ledger, represented by the creation of contracts.
|
||||
|
||||
For this, use again the ``submitAndWait`` method.
|
||||
|
||||
In particular, make your program exercise a choice: ``ReplyPing`` when you receive a ``Pong`` and vice versa.
|
||||
|
||||
You need to react to events in transactions as they are received in the ``listenForTransactions`` function.
|
||||
|
||||
The ``transaction`` object whose ``transactionId`` you printed so far contains an array of ``event`` objects, each representing an ``archived`` or ``created`` event on a contract.
|
||||
|
||||
What you want to do is loop through the events in the transaction and extract the ``receiver`` and ``count`` fields from ``created`` events.
|
||||
|
||||
You then want to decide which reply to give (either ``ReplyPing`` or ``ReplyPong``) based on the contract that has been read.
|
||||
|
||||
For each created event, you want to send a command that reacts to it, specifying that you want to either exercise the ``ReplyPing`` choice of a ``Pong`` contract or vice versa.
|
||||
|
||||
The following snippet of code does precisely this.
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
const reactions = [];
|
||||
for (const event of events) {
|
||||
const { receiver: { party: receiver }, count: { int64: count } } = event.arguments.fields;
|
||||
if (receiver === sender) {
|
||||
const templateId = event.templateId;
|
||||
const contractId = event.contractId;
|
||||
const reaction = templateId.name == PING.name ? 'ReplyPong' : 'ReplyPing';
|
||||
console.log(`${sender} (workflow ${workflowId}): ${reaction} at count ${count}`);
|
||||
reactions.push({
|
||||
exercise: {
|
||||
templateId: templateId,
|
||||
contractId: contractId,
|
||||
choice: reaction,
|
||||
argument: { record: { fields: {} } }
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
You can now use the ``submitAndWait`` command to send the ``reactions`` to the ledger.
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
if (reactions.length > 0) {
|
||||
const request = {
|
||||
commands: {
|
||||
applicationId: 'PingPongApp',
|
||||
workflowId: workflowId,
|
||||
commandId: uuidv4(),
|
||||
ledgerEffectiveTime: { seconds: 0, nanoseconds: 0 },
|
||||
maximumRecordTime: { seconds: 5, nanoseconds: 0 },
|
||||
party: sender,
|
||||
list: reactions
|
||||
}
|
||||
}
|
||||
client.commandClient.submitAndWait(request, error => {
|
||||
if (error) throw error;
|
||||
});
|
||||
}
|
||||
|
||||
Wrap this code into a new function ``react`` that takes a ``workflowId`` and an ``events`` array with the ``created`` events. Then edit the ``listenForTransactions`` function to:
|
||||
|
||||
- accept one parameter called ``callback``
|
||||
- instead of printing the transaction identifier, for each transaction
|
||||
|
||||
* push the ``created`` events to an array
|
||||
* pass that array to the ``callback`` (along with the workflow identifier)
|
||||
|
||||
Finally, pass the ``react`` function as a parameter to the only call of ``listenForTransactions``.
|
||||
|
||||
Your code should now look like the following:
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
da.DamlLedgerClient.connect({ host: host, port: port }, (error, client) => {
|
||||
if (error) throw error;
|
||||
|
||||
listenForTransactions(react);
|
||||
createFirstPing();
|
||||
|
||||
function createFirstPing() {
|
||||
const request = {
|
||||
commands: {
|
||||
applicationId: 'PingPongApp',
|
||||
workflowId: `Ping-${sender}`,
|
||||
commandId: uuidv4(),
|
||||
ledgerEffectiveTime: { seconds: 0, nanoseconds: 0 },
|
||||
maximumRecordTime: { seconds: 5, nanoseconds: 0 },
|
||||
party: sender,
|
||||
list: [
|
||||
{
|
||||
create: {
|
||||
templateId: PING,
|
||||
arguments: {
|
||||
fields: {
|
||||
sender: { party: sender },
|
||||
receiver: { party: receiver },
|
||||
count: { int64: 0 }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
client.commandClient.submitAndWait(request, error => {
|
||||
if (error) throw error;
|
||||
console.log(`Created Ping contract from ${sender} to ${receiver}.`);
|
||||
});
|
||||
}
|
||||
|
||||
function listenForTransactions(callback) {
|
||||
console.log(`${sender} starts reading transactions.`);
|
||||
const filtersByParty = {};
|
||||
filtersByParty[sender] = { inclusive: { templateIds: [PING, PONG] } };
|
||||
const request = {
|
||||
begin: { boundary: da.LedgerOffset.Boundary.END },
|
||||
filter: { filtersByParty: filtersByParty }
|
||||
};
|
||||
const transactions = client.transactionClient.getTransactions(request);
|
||||
transactions.on('data', response => {
|
||||
for (const transaction of response.transactions) {
|
||||
const events = [];
|
||||
for (const event of transaction.events) {
|
||||
if (event.created) {
|
||||
events.push(event.created);
|
||||
}
|
||||
}
|
||||
if (events.length > 0) {
|
||||
callback(transaction.workflowId, events);
|
||||
}
|
||||
}
|
||||
});
|
||||
transactions.on('error', error => {
|
||||
console.error(`${sender} encountered an error while processing transactions!`);
|
||||
console.error(error);
|
||||
process.exit(-1);
|
||||
});
|
||||
}
|
||||
|
||||
function react(workflowId, events) {
|
||||
const reactions = [];
|
||||
for (const event of events) {
|
||||
const { receiver: { party: receiver }, count: { int64: count } } = event.arguments.fields;
|
||||
if (receiver === sender) {
|
||||
const templateId = event.templateId;
|
||||
const contractId = event.contractId;
|
||||
const reaction = templateId.name == PING.name ? 'ReplyPong' : 'ReplyPing';
|
||||
console.log(`${sender} (workflow ${workflowId}): ${reaction} at count ${count}`);
|
||||
reactions.push({
|
||||
exercise: {
|
||||
templateId: templateId,
|
||||
contractId: contractId,
|
||||
choice: reaction,
|
||||
argument: { record: { fields: {} } }
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
if (reactions.length > 0) {
|
||||
const request = {
|
||||
commands: {
|
||||
applicationId: 'PingPongApp',
|
||||
workflowId: workflowId,
|
||||
commandId: uuidv4(),
|
||||
ledgerEffectiveTime: { seconds: 0, nanoseconds: 0 },
|
||||
maximumRecordTime: { seconds: 5, nanoseconds: 0 },
|
||||
party: sender,
|
||||
list: reactions
|
||||
}
|
||||
}
|
||||
client.commandClient.submitAndWait(request, error => {
|
||||
if (error) throw error;
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
To test your code you need to run two different commands in two different terminals.
|
||||
|
||||
First, run:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
npm start Alice Bob
|
||||
|
||||
After starting this, the application creates a ping contract on the ledger and waits for replies.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
Alice starts reading transactions.
|
||||
Created Ping contract from Alice to Bob.
|
||||
|
||||
Keep this command running, open a new shell and run the following command:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
npm start Bob Alice
|
||||
|
||||
You should now see the exchange happening on both terminals.
|
||||
|
||||
``npm start Alice Bob``
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
Alice starts reading transactions.
|
||||
Created Ping contract from Alice to Bob.
|
||||
Alice (workflow Ping-Bob): Pong at count 0
|
||||
Alice (workflow Ping-Bob): Pong at count 2
|
||||
|
||||
``npm start Bob Alice``
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
Bob starts reading transactions.
|
||||
Created Ping contract from Bob to Alice.
|
||||
Bob (workflow Ping-Bob): Ping at count 1
|
||||
Bob (workflow Ping-Bob): Ping at count 3
|
||||
|
||||
You can now close both applications.
|
||||
|
||||
Your application is now able to complete the full exchange. Very well done!
|
||||
|
||||
|
||||
The Active Contracts Service
|
||||
****************************
|
||||
|
||||
So far so good, but there is a flaw. You might have noticed that the application is subscribing for transactions using ``boundary: da.LedgerOffset.Boundary.END``. This means that wherever the ledger is at that time, the application is going to see transactions only after that, missing contracts created earlier. This problem could be addressed by subscribing for transactions from ``boundary: da.LedgerOffset.Boundary.BEGIN``, but then in case of a downtime your application would need to be prepared to handle contracts it has already processed before. To make this recovery easier the API offers a service which returns the set of active contracts on the ledger and an offset with which one can subscribe for transactions. This facilitates ramping up new applications and you can be sure to see contracts only once.
|
||||
|
||||
In this new example the application first processes the current active contracts. Since that process is asynchronous the rest of the program should be passed in as a callback.
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
function processActiveContracts(transactionFilter, callback, onComplete) {
|
||||
const request = { filter: transactionFilter };
|
||||
const activeContracts = client.activeContractsClient.getActiveContracts(request);
|
||||
let offset = undefined;
|
||||
activeContracts.on('data', response => {
|
||||
if (response.activeContracts) {
|
||||
const events = [];
|
||||
for (const activeContract of response.activeContracts) {
|
||||
events.push(activeContract);
|
||||
}
|
||||
|
||||
if (events.length > 0) {
|
||||
callback(response.workflowId, events);
|
||||
}
|
||||
}
|
||||
|
||||
if (response.offset) {
|
||||
offset = response.offset;
|
||||
}
|
||||
});
|
||||
|
||||
activeContracts.on('error', error => {
|
||||
console.error(`${sender} encountered an error while processing active contracts!`);
|
||||
console.error(error);
|
||||
process.exit(-1);
|
||||
});
|
||||
|
||||
activeContracts.on('end', () => onComplete(offset));
|
||||
}
|
||||
|
||||
|
||||
Note that the transaction filter was factored out as it can be shared. The final code would look like this:
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
const da = require('@da/daml-ledger').data;
|
||||
const templateIds = require('./template-ids.json');
|
||||
|
||||
const PING = templateIds['PingPong.Ping'];
|
||||
const PONG = templateIds['PingPong.Pong'];
|
||||
|
||||
const uuidv4 = require('uuid/v4');
|
||||
|
||||
let [, , sender, receiver, host, port] = process.argv;
|
||||
host = host || 'localhost';
|
||||
port = port || 6865;
|
||||
if (!sender || !receiver) {
|
||||
console.log('Missing sender and/or receiver arguments, exiting.');
|
||||
process.exit(-1);
|
||||
}
|
||||
|
||||
da.DamlLedgerClient.connect({ host: host, port: port }, (error, client) => {
|
||||
if (error) throw error;
|
||||
|
||||
const filtersByParty = {};
|
||||
filtersByParty[sender] = { inclusive: { templateIds: [PING, PONG] } };
|
||||
const transactionFilter = { filtersByParty: filtersByParty };
|
||||
|
||||
processActiveContracts(transactionFilter, react, offset => {
|
||||
listenForTransactions(offset, transactionFilter, react);
|
||||
createFirstPing();
|
||||
});
|
||||
|
||||
function createFirstPing() {
|
||||
const request = {
|
||||
commands: {
|
||||
applicationId: 'PingPongApp',
|
||||
workflowId: `Ping-${sender}`,
|
||||
commandId: uuidv4(),
|
||||
ledgerEffectiveTime: { seconds: 0, nanoseconds: 0 },
|
||||
maximumRecordTime: { seconds: 5, nanoseconds: 0 },
|
||||
party: sender,
|
||||
list: [
|
||||
{
|
||||
create: {
|
||||
templateId: PING,
|
||||
arguments: {
|
||||
fields: {
|
||||
sender: { party: sender },
|
||||
receiver: { party: receiver },
|
||||
count: { int64: 0 }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
client.commandClient.submitAndWait(request, error => {
|
||||
if (error) throw error;
|
||||
console.log(`Created Ping contract from ${sender} to ${receiver}.`);
|
||||
});
|
||||
}
|
||||
|
||||
function listenForTransactions(offset, transactionFilter, callback) {
|
||||
console.log(`${sender} starts reading transactions from offset: ${offset.absolute}.`);
|
||||
const request = {
|
||||
begin: { boundary: da.LedgerOffset.Boundary.END },
|
||||
filter: transactionFilter
|
||||
};
|
||||
const transactions = client.transactionClient.getTransactions(request);
|
||||
transactions.on('data', response => {
|
||||
for (const transaction of response.transactions) {
|
||||
const events = [];
|
||||
for (const event of transaction.events) {
|
||||
if (event.created) {
|
||||
events.push(event.created);
|
||||
}
|
||||
}
|
||||
if (events.length > 0) {
|
||||
callback(transaction.workflowId, events);
|
||||
}
|
||||
}
|
||||
});
|
||||
transactions.on('error', error => {
|
||||
console.error(`${sender} encountered an error while processing transactions!`);
|
||||
console.error(error);
|
||||
process.exit(-1);
|
||||
});
|
||||
}
|
||||
|
||||
function processActiveContracts(transactionFilter, callback, onComplete) {
|
||||
console.log(`processing active contracts for ${sender}`);
|
||||
const request = { filter: transactionFilter };
|
||||
const activeContracts = client.activeContractsClient.getActiveContracts(request);
|
||||
let offset = undefined;
|
||||
activeContracts.on('data', response => {
|
||||
if (response.activeContracts) {
|
||||
const events = [];
|
||||
for (const activeContract of response.activeContracts) {
|
||||
events.push(activeContract);
|
||||
}
|
||||
if (events.length > 0) {
|
||||
callback(response.workflowId, events);
|
||||
}
|
||||
}
|
||||
|
||||
if (response.offset) {
|
||||
offset = response.offset;
|
||||
}
|
||||
});
|
||||
|
||||
activeContracts.on('error', error => {
|
||||
console.error(`${sender} encountered an error while processing active contracts!`);
|
||||
console.error(error);
|
||||
process.exit(-1);
|
||||
});
|
||||
|
||||
activeContracts.on('end', () => onComplete(offset));
|
||||
}
|
||||
|
||||
function react(workflowId, events) {
|
||||
const reactions = [];
|
||||
for (const event of events) {
|
||||
const { receiver: { party: receiver }, count: { int64: count } } = event.arguments.fields;
|
||||
if (receiver === sender) {
|
||||
const templateId = event.templateId;
|
||||
const contractId = event.contractId;
|
||||
const reaction = templateId.name == PING.name ? 'ReplyPong' : 'ReplyPing';
|
||||
console.log(`${sender} (workflow ${workflowId}): ${reaction} at count ${count}`);
|
||||
reactions.push({
|
||||
exercise: {
|
||||
templateId: templateId,
|
||||
contractId: contractId,
|
||||
choice: reaction,
|
||||
argument: { record: { fields: {} } }
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
if (reactions.length > 0) {
|
||||
const request = {
|
||||
commands: {
|
||||
applicationId: 'PingPongApp',
|
||||
workflowId: workflowId,
|
||||
commandId: uuidv4(),
|
||||
ledgerEffectiveTime: { seconds: 0, nanoseconds: 0 },
|
||||
maximumRecordTime: { seconds: 5, nanoseconds: 0 },
|
||||
party: sender,
|
||||
list: reactions
|
||||
}
|
||||
};
|
||||
client.commandClient.submitAndWait(request, error => {
|
||||
if (error) throw error;
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Before running this you should start with a clean ledger to avoid being confused by the unprocessed contracts from previous examples.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
da stop
|
||||
da sandbox
|
||||
|
||||
Then run:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
npm start Alice Bob
|
||||
|
||||
in another shell:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
npm start Bob Alice
|
||||
|
||||
You should see the following outputs respectively:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
processing active contracts for Alice
|
||||
Alice starts reading transactions from offset: 0.
|
||||
Created Ping contract from Alice to Bob.
|
||||
Alice (workflow Ping-Bob): Pong at count 0
|
||||
Alice (workflow Ping-Alice): Ping at count 1
|
||||
Alice (workflow Ping-Bob): Pong at count 2
|
||||
Alice (workflow Ping-Alice): Ping at count 3
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
processing active contracts for Bob
|
||||
Bob (workflow Ping-Alice): Pong at count 0
|
||||
Bob starts reading transactions from offset: 1.
|
||||
Created Ping contract from Bob to Alice.
|
||||
Bob (workflow Ping-Bob): Ping at count 1
|
||||
Bob (workflow Ping-Alice): Pong at count 2
|
||||
Bob (workflow Ping-Bob): Ping at count 3
|
||||
|
||||
Alice joining an empty ledger has no active contracts to process. Bob however, who joins later, will see Alice's ``Ping`` contract and process it. Afterwards he will continue listening to transactions from offset 1.
|
@ -10,7 +10,6 @@ The tools described in this section are actively being designed and are subject
|
||||
:titlesonly:
|
||||
:maxdepth: 2
|
||||
|
||||
/app-dev/bindings-js/index
|
||||
Navigator Console </tools/navigator/console>
|
||||
Navigator Database </tools/navigator/database>
|
||||
Extractor </tools/extractor>
|
||||
Extractor </tools/extractor>
|
||||
|
@ -9,6 +9,8 @@ This page contains release notes for the SDK.
|
||||
HEAD — ongoing
|
||||
--------------
|
||||
|
||||
- Node.js bindings have been moved `here <https://github.com/digital-asset/daml-js>``
|
||||
|
||||
0.12.10 — 2019-04-25
|
||||
--------------------
|
||||
|
||||
|
@ -15,9 +15,9 @@ We plan to update this roadmap roughly every three months.
|
||||
`More about this on GitHub <https://github.com/digital-asset/daml/issues/116>`__.
|
||||
- **JavaScript / TypeScript ecosystem**
|
||||
|
||||
Improve the currently experimental :doc:`JavaScript bindings </app-dev/bindings-js/index>` so they are stable, and add TypeScript code generation to generate code from DAML types.
|
||||
Improve the currently experimental `Node.js bindings <https://github.com/digital-asset/daml-js>`__ so they are stable, and add TypeScript code generation to generate code from DAML types.
|
||||
|
||||
`More about this on GitHub <https://github.com/digital-asset/daml/milestone/8>`__.
|
||||
`More about this on GitHub <https://github.com/digital-asset/daml-js>`__.
|
||||
- **Simplified da assistant**
|
||||
|
||||
Rewritten :doc:`command line for the SDK </tools/assistant>` with improved usability.
|
||||
|
@ -1,38 +0,0 @@
|
||||
load("@build_bazel_rules_typescript//:defs.bzl", "ts_config", "ts_library")
|
||||
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary", "nodejs_test", "npm_package")
|
||||
|
||||
nodejs_binary(
|
||||
name = "grpc_tools_node_protoc",
|
||||
data = [
|
||||
"@npm//grpc-tools",
|
||||
],
|
||||
entry_point = "grpc-tools/bin/protoc.js",
|
||||
visibility = ["//language-support/js:__subpackages__"],
|
||||
)
|
||||
|
||||
nodejs_binary(
|
||||
name = "grpc_tools_node_protoc_js",
|
||||
data = [
|
||||
"@npm//grpc-tools",
|
||||
],
|
||||
entry_point = "grpc-tools/bin/protoc_plugin.js",
|
||||
visibility = ["//language-support/js:__subpackages__"],
|
||||
)
|
||||
|
||||
nodejs_binary(
|
||||
name = "grpc_tools_node_protoc_ts",
|
||||
data = [
|
||||
"@npm//grpc_tools_node_protoc_ts",
|
||||
],
|
||||
entry_point = "grpc_tools_node_protoc_ts/bin/protoc-gen-ts",
|
||||
visibility = ["//language-support/js:__subpackages__"],
|
||||
)
|
||||
|
||||
nodejs_binary(
|
||||
name = "tsc",
|
||||
data = [
|
||||
"@npm//typescript",
|
||||
],
|
||||
entry_point = "typescript/bin/tsc",
|
||||
visibility = ["//language-support/js:__subpackages__"],
|
||||
)
|
@ -1,21 +0,0 @@
|
||||
# language-support/js
|
||||
|
||||
Official DAML Ledger API support for JavaScript and TypeScript on the Node.js platform.
|
||||
|
||||
---
|
||||
|
||||
**WARNING:** The support is currently shipped as an **EXPERIMENTAL** feature.
|
||||
|
||||
---
|
||||
|
||||
## Prepare the development environment
|
||||
|
||||
As with the rest of the repository, Bazel is used as a build system.
|
||||
|
||||
The build rules currently used have Bazel managing the dependencies centrally throughout the repository.
|
||||
|
||||
The following step is optional but it enables IDEs and editors to pick up the dependencies between packages within this project; in order to build the modules locally and install them in the `node_modules` directory of each package, run the [install.sh](install.sh) script:
|
||||
|
||||
language-support/js/install.sh
|
||||
|
||||
Re-run the script every time you make a change that affects other projects (e.g.: something changes in `daml-grpc` that needs to be picked up by `daml-ledger`).
|
@ -1,15 +0,0 @@
|
||||
# Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
bazel build //language-support/js/daml-codegen
|
||||
|
||||
mkdir -p daml-codegen/target/
|
||||
tar xzf ../../bazel-genfiles/language-support/js/daml-codegen/daml-codegen.tgz --strip-components=1 -C daml-codegen/target
|
||||
|
||||
node daml-codegen/target/dist/index.js "$@"
|
@ -1,46 +0,0 @@
|
||||
load("@build_bazel_rules_typescript//:defs.bzl", "ts_config")
|
||||
|
||||
ts_config(
|
||||
name = "tsconfig",
|
||||
src = "tsconfig.json",
|
||||
deps = ["//:tsconfig.json"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "src",
|
||||
srcs = glob(["*.ts"]),
|
||||
)
|
||||
|
||||
# ts_library does not accept arbitrary inputs, so we use a genrule
|
||||
genrule(
|
||||
name = "daml-codegen",
|
||||
srcs = [
|
||||
":src",
|
||||
"//language-support/js/daml-grpc",
|
||||
"//language-support/js/daml-ledger",
|
||||
"package.json",
|
||||
":tsconfig",
|
||||
"@npm//@types/google-protobuf",
|
||||
"@npm//@types/node",
|
||||
"@npm//google-protobuf",
|
||||
"@npm//grpc",
|
||||
"@npm//typescript",
|
||||
],
|
||||
outs = ["daml-codegen.tgz"],
|
||||
cmd = """
|
||||
set -e
|
||||
ln -s external/npm/node_modules
|
||||
mkdir -p node_modules/daml-grpc
|
||||
tar xzf $(location //language-support/js/daml-grpc) --strip-components=1 -C node_modules/daml-grpc
|
||||
mkdir -p node_modules/daml-ledger
|
||||
tar xzf $(location //language-support/js/daml-ledger) --strip-components=1 -C node_modules/daml-ledger
|
||||
$(execpath //language-support/js:tsc) --build $(location tsconfig)
|
||||
mkdir -p package
|
||||
cp -R language-support/js/daml-codegen/dist package
|
||||
cp $(location package.json) package
|
||||
tar czf $@ package
|
||||
""",
|
||||
tools = [
|
||||
"//language-support/js:tsc",
|
||||
],
|
||||
)
|
@ -1,44 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as opts from './options';
|
||||
import { OptionsReadError } from './options';
|
||||
import * as fs from 'fs';
|
||||
import * as ts from 'typescript';
|
||||
import { DalfProcessor } from './processor';
|
||||
|
||||
const options = opts.read(process.argv.slice(2));
|
||||
|
||||
if (typeof options === 'number') {
|
||||
switch (options) {
|
||||
case OptionsReadError.PARSE_MISSING_INPUT:
|
||||
console.log('no parameter for -i flag');
|
||||
break;
|
||||
case OptionsReadError.PARSE_MISSING_OUTPUT:
|
||||
console.log('no parameter for -o flag');
|
||||
break;
|
||||
case OptionsReadError.PARSE_UNRECOGNIZED:
|
||||
console.log('unrecognized option');
|
||||
break;
|
||||
case OptionsReadError.READ_INPUT_IS_MISSING:
|
||||
console.log('input file is missing');
|
||||
break;
|
||||
case OptionsReadError.READ_INPUT_DOES_NOT_EXIST:
|
||||
console.log('input file does not exist');
|
||||
break;
|
||||
case OptionsReadError.READ_OUTPUT_DIRECTORY_DOES_NOT_EXIST:
|
||||
console.log('output directory does not exist');
|
||||
break;
|
||||
}
|
||||
console.log(`usage ${process.argv[0]} ${process.argv[1]} -i <input.dalf> [-o output.ts]`)
|
||||
process.exit(1);
|
||||
} else {
|
||||
fs.readFile(options.inputDalf, (error, data) => {
|
||||
if (error) throw error;
|
||||
const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
|
||||
const processor = new DalfProcessor(options.outputTs, printer);
|
||||
const source = processor.process(data);
|
||||
console.log(source.text);
|
||||
printer.printFile(source);
|
||||
});
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { lf } from 'daml-grpc';
|
||||
|
||||
export interface ModuleTree {
|
||||
children: Record<string, ModuleTree>,
|
||||
modules: lf.v1.Module[]
|
||||
}
|
||||
|
||||
function empty(): ModuleTree {
|
||||
return {
|
||||
children: {},
|
||||
modules: []
|
||||
};
|
||||
}
|
||||
|
||||
function insert(module: lf.v1.Module, tree: ModuleTree, depth: number = 0): void {
|
||||
const segments = module.getName().getSegmentsList();
|
||||
const last = segments.length - 1;
|
||||
if (depth < last) {
|
||||
const segment = segments[depth];
|
||||
if (!tree.children[segment]) {
|
||||
tree.children[segment] = empty();
|
||||
}
|
||||
insert(module, tree.children[segment], depth + 1);
|
||||
} else {
|
||||
tree.modules.push(module);
|
||||
}
|
||||
}
|
||||
|
||||
export function treeify(modules: lf.v1.Module[]): ModuleTree {
|
||||
const tree: ModuleTree = empty();
|
||||
for (const m of modules) {
|
||||
insert(m, tree);
|
||||
}
|
||||
return tree;
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
interface OptionsBuffer {
|
||||
inputDalf?: string
|
||||
outputTs?: string
|
||||
}
|
||||
|
||||
export interface Options {
|
||||
inputDalf: string
|
||||
outputTs: string
|
||||
}
|
||||
|
||||
export enum OptionsReadError {
|
||||
PARSE_MISSING_INPUT,
|
||||
PARSE_MISSING_OUTPUT,
|
||||
PARSE_UNRECOGNIZED,
|
||||
READ_INPUT_IS_MISSING,
|
||||
READ_INPUT_DOES_NOT_EXIST,
|
||||
READ_OUTPUT_DIRECTORY_DOES_NOT_EXIST
|
||||
}
|
||||
|
||||
function parse(argv: string[]): OptionsBuffer | OptionsReadError {
|
||||
const buffer: OptionsBuffer = {};
|
||||
for (let i = 0; i < argv.length; i++) {
|
||||
switch (argv[i]) {
|
||||
case '-i':
|
||||
if (i + 1 >= argv.length) {
|
||||
return OptionsReadError.PARSE_MISSING_INPUT;
|
||||
}
|
||||
buffer.inputDalf = argv[++i];
|
||||
break;
|
||||
case '-o':
|
||||
if (i + 1 >= argv.length) {
|
||||
return OptionsReadError.PARSE_MISSING_OUTPUT;
|
||||
}
|
||||
buffer.outputTs = argv[++i];
|
||||
break;
|
||||
default:
|
||||
return OptionsReadError.PARSE_UNRECOGNIZED;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
function interpret(buffer: OptionsBuffer): Options | OptionsReadError {
|
||||
if (!buffer.inputDalf) {
|
||||
return OptionsReadError.READ_INPUT_IS_MISSING;
|
||||
} else if (!fs.existsSync(buffer.inputDalf)) {
|
||||
return OptionsReadError.READ_INPUT_DOES_NOT_EXIST;
|
||||
} else if (!buffer.outputTs) {
|
||||
const { root, dir, name } = path.parse(buffer.inputDalf)
|
||||
buffer.outputTs = path.resolve(root, dir, `${name}.ts`);
|
||||
return {
|
||||
inputDalf: buffer.inputDalf,
|
||||
outputTs: buffer.outputTs
|
||||
};
|
||||
} else if (!fs.statSync(path.dirname(buffer.outputTs)).isDirectory()) {
|
||||
return OptionsReadError.READ_OUTPUT_DIRECTORY_DOES_NOT_EXIST;
|
||||
} else {
|
||||
return {
|
||||
inputDalf: buffer.inputDalf,
|
||||
outputTs: buffer.outputTs
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function read(argv: string[]): Options | OptionsReadError {
|
||||
const parseResult = parse(argv);
|
||||
if (typeof parseResult === 'number') {
|
||||
return parseResult;
|
||||
} else {
|
||||
return interpret(parseResult);
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
{
|
||||
"name": "daml-codegen",
|
||||
"version": "0.5.0",
|
||||
"description": "DAML Ledger API Node.js code generation",
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/digital-asset/daml",
|
||||
"directory": "language-support/js/daml-codegen"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"author": "Digital Asset (Switzerland) GmbH and/or its affiliates",
|
||||
"contributors": [
|
||||
"Stefano Baghino <stefano.baghino@daml.com>"
|
||||
],
|
||||
"dependencies": {
|
||||
"daml-ledger": "0.5.0",
|
||||
"typescript": "3.1.6"
|
||||
}
|
||||
}
|
||||
|
@ -1,131 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as ts from 'typescript';
|
||||
import { lf } from 'daml-grpc';
|
||||
import { ModuleTree, treeify } from './module_tree';
|
||||
|
||||
export class DalfProcessor {
|
||||
private readonly src: ts.SourceFile;
|
||||
private readonly printer: ts.Printer;
|
||||
constructor(outputPath: string, printer: ts.Printer) {
|
||||
this.src = ts.createSourceFile(outputPath, '', ts.ScriptTarget.ES2015);
|
||||
this.printer = printer;
|
||||
}
|
||||
|
||||
process(dalf: Buffer): ts.SourceFile {
|
||||
const payload = lf.Archive.deserializeBinary(dalf).getPayload_asU8();
|
||||
const modules = lf.ArchivePayload.deserializeBinary(payload).getDamlLf1().getModulesList();
|
||||
this.src.text += generate(treeify(modules)).map(decl => this.printer.printNode(ts.EmitHint.Unspecified, decl, this.src)).join('\n\n');
|
||||
return this.src;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function generate(tree: ModuleTree): ts.ModuleDeclaration[] {
|
||||
const declarations: ts.ModuleDeclaration[] = [];
|
||||
for (const lfModuleName in tree.children) {
|
||||
const child = tree.children[lfModuleName];
|
||||
const tsModuleName = ts.createIdentifier(lfModuleName);
|
||||
declarations.push(ts.createModuleDeclaration([], [], tsModuleName, ts.createModuleBlock(generate(child))));
|
||||
}
|
||||
for (const lfModule of tree.modules) {
|
||||
const lfModuleName = lfModule.getName().getSegmentsList();
|
||||
const tsModuleName = ts.createIdentifier(lfModuleName[lfModuleName.length - 1]);
|
||||
const templates = lfModule.getTemplatesList().map(t => generateTemplate(t));
|
||||
const dataTypes = lfModule.getDataTypesList().map(t => generateDataType(t));
|
||||
declarations.push(ts.createModuleDeclaration([], [], tsModuleName, ts.createModuleBlock([...templates, ...dataTypes])));
|
||||
}
|
||||
return declarations;
|
||||
}
|
||||
|
||||
function generateTemplate(template: lf.v1.DefTemplate): ts.ClassDeclaration {
|
||||
const templateNameSegments = template.getTycon().getSegmentsList();
|
||||
const templateName = templateNameSegments[templateNameSegments.length - 1];
|
||||
const choices = template.getChoicesList().map(c => ts.createMethod([], [], undefined, c.getName(), undefined, [], [], undefined, undefined));
|
||||
return ts.createClassDeclaration([], [], templateName, [], [], choices);
|
||||
}
|
||||
|
||||
function generateDataType(dataType: lf.v1.DefDataType): ts.ClassDeclaration {
|
||||
const typeNameSegments = dataType.getName().getSegmentsList();
|
||||
const typeName = typeNameSegments[typeNameSegments.length - 1];
|
||||
const members: ts.ClassElement[] = [];
|
||||
if (dataType.hasRecord()) {
|
||||
const fields = dataType.getRecord().getFieldsList();
|
||||
for (const field of fields) {
|
||||
const lfType = field.getType();
|
||||
const tsType = generateType(lfType);
|
||||
members.push(ts.createProperty([], [], field.getField(), undefined, tsType, undefined));
|
||||
}
|
||||
}
|
||||
return ts.createClassDeclaration([], [], typeName, [], [], members);
|
||||
}
|
||||
|
||||
function generateType(lfType: lf.v1.Type): ts.TypeNode {
|
||||
if (lfType.hasPrim()) {
|
||||
switch (lfType.getPrim().getPrim()) {
|
||||
case lf.v1.PrimType.UNIT:
|
||||
return ts.createTypeReferenceNode('MISSING', []);
|
||||
throw new Error(`unsupported type ${lfType}`);
|
||||
break;
|
||||
case lf.v1.PrimType.BOOL:
|
||||
return ts.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword);
|
||||
break;
|
||||
case lf.v1.PrimType.INT64:
|
||||
return ts.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword);
|
||||
break;
|
||||
case lf.v1.PrimType.DECIMAL:
|
||||
return ts.createKeywordTypeNode(ts.SyntaxKind.StringKeyword);
|
||||
break;
|
||||
case lf.v1.PrimType.TEXT:
|
||||
return ts.createKeywordTypeNode(ts.SyntaxKind.StringKeyword);
|
||||
break;
|
||||
case lf.v1.PrimType.TIMESTAMP:
|
||||
return ts.createTypeReferenceNode('Date', []);
|
||||
break;
|
||||
case lf.v1.PrimType.PARTY:
|
||||
return ts.createKeywordTypeNode(ts.SyntaxKind.StringKeyword);
|
||||
break;
|
||||
case lf.v1.PrimType.LIST:
|
||||
return ts.createTypeReferenceNode('MISSING', []);
|
||||
throw new Error(`unsupported type ${lfType}`);
|
||||
break;
|
||||
case lf.v1.PrimType.UPDATE:
|
||||
return ts.createTypeReferenceNode('MISSING', []);
|
||||
throw new Error(`unsupported type ${lfType}`);
|
||||
break;
|
||||
case lf.v1.PrimType.SCENARIO:
|
||||
return ts.createTypeReferenceNode('MISSING', []);
|
||||
throw new Error(`unsupported type ${lfType}`);
|
||||
break;
|
||||
case lf.v1.PrimType.DATE:
|
||||
return ts.createTypeReferenceNode('Date', []);
|
||||
break;
|
||||
case lf.v1.PrimType.CONTRACT_ID:
|
||||
return ts.createTypeReferenceNode('MISSING', []);
|
||||
throw new Error(`unsupported type ${lfType}`);
|
||||
break;
|
||||
case lf.v1.PrimType.OPTIONAL:
|
||||
return ts.createTypeReferenceNode('MISSING', []);
|
||||
throw new Error(`unsupported type ${lfType}`);
|
||||
break;
|
||||
case lf.v1.PrimType.ARROW:
|
||||
return ts.createTypeReferenceNode('MISSING', []);
|
||||
throw new Error(`unsupported type ${lfType}`);
|
||||
break;
|
||||
default:
|
||||
return ts.createTypeReferenceNode('MISSING', []);
|
||||
throw new Error(`unsupported type ${lfType}`);
|
||||
break;
|
||||
}
|
||||
} else if (lfType.hasCon()) {
|
||||
return ts.createTypeReferenceNode('MISSING', []);
|
||||
throw new Error(`unsupported type ${lfType}`);
|
||||
} else if (lfType.hasTuple()) {
|
||||
return ts.createTypeReferenceNode('MISSING', []);
|
||||
throw new Error(`unsupported type ${lfType}`);
|
||||
} else {
|
||||
return ts.createTypeReferenceNode('MISSING', []);
|
||||
throw new Error(`unsupported type ${lfType}`);
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"sourceMap": true,
|
||||
"outDir": "./dist/",
|
||||
"lib": [ "es2015" ]
|
||||
}
|
||||
}
|
@ -1,184 +0,0 @@
|
||||
load("@build_bazel_rules_typescript//:defs.bzl", "ts_config")
|
||||
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary")
|
||||
load("//bazel_tools:proto.bzl", "proto_gen")
|
||||
|
||||
proto_gen(
|
||||
name = "ledger-api-nodejs",
|
||||
srcs = ["//ledger-api/grpc-definitions:protos"],
|
||||
plugin_exec = "//language-support/js:grpc_tools_node_protoc_js",
|
||||
plugin_name = "js",
|
||||
plugin_options = [
|
||||
"import_style=commonjs",
|
||||
"binary",
|
||||
],
|
||||
deps = [
|
||||
"@com_github_googleapis_googleapis//google/rpc:status_proto",
|
||||
"@com_google_protobuf//:any_proto",
|
||||
"@com_google_protobuf//:descriptor_proto",
|
||||
"@com_google_protobuf//:duration_proto",
|
||||
"@com_google_protobuf//:empty_proto",
|
||||
"@com_google_protobuf//:timestamp_proto",
|
||||
"@com_google_protobuf//:wrappers_proto",
|
||||
],
|
||||
)
|
||||
|
||||
proto_gen(
|
||||
name = "ledger-api-nodejs-grpc",
|
||||
srcs = ["//ledger-api/grpc-definitions:protos"],
|
||||
plugin_exec = "//language-support/js:grpc_tools_node_protoc_js",
|
||||
plugin_name = "grpc",
|
||||
deps = [
|
||||
"@com_github_googleapis_googleapis//google/rpc:status_proto",
|
||||
"@com_google_protobuf//:any_proto",
|
||||
"@com_google_protobuf//:descriptor_proto",
|
||||
"@com_google_protobuf//:duration_proto",
|
||||
"@com_google_protobuf//:empty_proto",
|
||||
"@com_google_protobuf//:timestamp_proto",
|
||||
"@com_google_protobuf//:wrappers_proto",
|
||||
],
|
||||
)
|
||||
|
||||
proto_gen(
|
||||
name = "ledger-api-d.ts",
|
||||
srcs = ["//ledger-api/grpc-definitions:protos"],
|
||||
plugin_exec = "//language-support/js:grpc_tools_node_protoc_ts",
|
||||
plugin_name = "ts",
|
||||
deps = [
|
||||
"@com_github_googleapis_googleapis//google/rpc:status_proto",
|
||||
"@com_google_protobuf//:any_proto",
|
||||
"@com_google_protobuf//:descriptor_proto",
|
||||
"@com_google_protobuf//:duration_proto",
|
||||
"@com_google_protobuf//:empty_proto",
|
||||
"@com_google_protobuf//:timestamp_proto",
|
||||
"@com_google_protobuf//:wrappers_proto",
|
||||
],
|
||||
)
|
||||
|
||||
proto_gen(
|
||||
name = "daml_lf_proto-nodejs",
|
||||
srcs = ["//daml-lf/archive:daml_lf_proto"],
|
||||
plugin_exec = "//language-support/js:grpc_tools_node_protoc_js",
|
||||
plugin_name = "js",
|
||||
plugin_options = [
|
||||
"import_style=commonjs",
|
||||
"binary",
|
||||
],
|
||||
)
|
||||
|
||||
proto_gen(
|
||||
name = "daml_lf_proto-d.ts",
|
||||
srcs = ["//daml-lf/archive:daml_lf_proto"],
|
||||
plugin_exec = "//language-support/js:grpc_tools_node_protoc_ts",
|
||||
plugin_name = "ts",
|
||||
)
|
||||
|
||||
proto_gen(
|
||||
name = "com_google_protobuf-nodejs",
|
||||
srcs = [
|
||||
"@com_github_googleapis_googleapis//google/rpc:status_proto",
|
||||
],
|
||||
plugin_exec = "//language-support/js:grpc_tools_node_protoc_js",
|
||||
plugin_name = "js",
|
||||
plugin_options = [
|
||||
"import_style=commonjs",
|
||||
"binary",
|
||||
],
|
||||
deps = [
|
||||
"@com_google_protobuf//:any_proto",
|
||||
"@com_google_protobuf//:descriptor_proto",
|
||||
"@com_google_protobuf//:duration_proto",
|
||||
"@com_google_protobuf//:empty_proto",
|
||||
"@com_google_protobuf//:timestamp_proto",
|
||||
"@com_google_protobuf//:wrappers_proto",
|
||||
],
|
||||
)
|
||||
|
||||
proto_gen(
|
||||
name = "com_google_protobuf-d.ts",
|
||||
srcs = [
|
||||
"@com_github_googleapis_googleapis//google/rpc:status_proto",
|
||||
],
|
||||
plugin_exec = "//language-support/js:grpc_tools_node_protoc_ts",
|
||||
plugin_name = "ts",
|
||||
deps = [
|
||||
"@com_google_protobuf//:any_proto",
|
||||
"@com_google_protobuf//:descriptor_proto",
|
||||
"@com_google_protobuf//:duration_proto",
|
||||
"@com_google_protobuf//:empty_proto",
|
||||
"@com_google_protobuf//:timestamp_proto",
|
||||
"@com_google_protobuf//:wrappers_proto",
|
||||
],
|
||||
)
|
||||
|
||||
ts_config(
|
||||
name = "tsconfig",
|
||||
src = "tsconfig.json",
|
||||
deps = ["//:tsconfig.json"],
|
||||
)
|
||||
|
||||
# ts_library does not accept arbitrary inputs, so we use a genrule
|
||||
genrule(
|
||||
name = "daml-grpc",
|
||||
srcs = [
|
||||
"index.ts",
|
||||
"lf/index.ts",
|
||||
"testing/index.ts",
|
||||
":ledger-api-nodejs",
|
||||
":ledger-api-nodejs-grpc",
|
||||
":ledger-api-d.ts",
|
||||
":daml_lf_proto-nodejs",
|
||||
":daml_lf_proto-d.ts",
|
||||
":com_google_protobuf-nodejs",
|
||||
":com_google_protobuf-d.ts",
|
||||
"package.json",
|
||||
":tsconfig",
|
||||
"@npm//@types/google-protobuf",
|
||||
"@npm//@types/node",
|
||||
"@npm//google-protobuf",
|
||||
"@npm//grpc",
|
||||
],
|
||||
outs = ["daml-grpc.tgz"],
|
||||
cmd = """
|
||||
set -e
|
||||
ln -s external/npm/node_modules
|
||||
unzip -q $(location ledger-api-nodejs) -d language-support/js/daml-grpc/
|
||||
unzip -q $(location ledger-api-nodejs-grpc) -d language-support/js/daml-grpc/
|
||||
unzip -q $(location ledger-api-d.ts) -d language-support/js/daml-grpc/
|
||||
unzip -q $(location daml_lf_proto-nodejs) -d language-support/js/daml-grpc/
|
||||
unzip -q $(location daml_lf_proto-d.ts) -d language-support/js/daml-grpc/
|
||||
unzip -q $(location com_google_protobuf-nodejs) -d language-support/js/daml-grpc/
|
||||
unzip -q $(location com_google_protobuf-d.ts) -d language-support/js/daml-grpc/
|
||||
$(execpath //language-support/js:tsc) --build $(location tsconfig)
|
||||
cp -R language-support/js/daml-grpc/dist package
|
||||
cp -RL language-support/js/daml-grpc/com package
|
||||
cp -RL language-support/js/daml-grpc/da package
|
||||
cp -RL language-support/js/daml-grpc/google package
|
||||
cp -RL language-support/js/daml-grpc/grpc package
|
||||
cp $(location package.json) package
|
||||
tar czf $@ package
|
||||
""",
|
||||
tools = [
|
||||
"//language-support/js:tsc",
|
||||
],
|
||||
visibility = ["//:__subpackages__"],
|
||||
)
|
||||
|
||||
# nodejs_test does not support mocha, so we use sh_test
|
||||
sh_test(
|
||||
name = "test",
|
||||
srcs = ["test.sh"],
|
||||
data = [
|
||||
"test.ts",
|
||||
":daml-grpc",
|
||||
"@nodejs//:node",
|
||||
"@npm//@types/chai",
|
||||
"@npm//@types/google-protobuf",
|
||||
"@npm//@types/mocha",
|
||||
"@npm//@types/node",
|
||||
"@npm//chai",
|
||||
"@npm//google-protobuf",
|
||||
"@npm//grpc",
|
||||
"@npm//mocha",
|
||||
"@npm//ts-node",
|
||||
],
|
||||
)
|
@ -1,50 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as testing from './testing';
|
||||
export { testing };
|
||||
|
||||
import * as lf from './lf';
|
||||
export { lf };
|
||||
|
||||
export { ActiveContractsServiceService as ActiveContractsService, ActiveContractsServiceClient as ActiveContractsClient, IActiveContractsServiceClient as IActiveContractsClient } from './com/digitalasset/ledger/api/v1/active_contracts_service_grpc_pb';
|
||||
export { GetActiveContractsRequest, GetActiveContractsResponse } from './com/digitalasset/ledger/api/v1/active_contracts_service_pb';
|
||||
|
||||
export { CommandCompletionServiceService as CommandCompletionService, CommandCompletionServiceClient as CommandCompletionClient, ICommandCompletionServiceClient as ICommandCompletionClient } from './com/digitalasset/ledger/api/v1/command_completion_service_grpc_pb';
|
||||
export { Checkpoint, CompletionEndRequest, CompletionEndResponse, CompletionStreamRequest, CompletionStreamResponse } from './com/digitalasset/ledger/api/v1/command_completion_service_pb';
|
||||
|
||||
export { CommandServiceService as CommandService, CommandServiceClient as CommandClient, ICommandServiceClient as ICommandClient } from './com/digitalasset/ledger/api/v1/command_service_grpc_pb';
|
||||
export { SubmitAndWaitRequest } from './com/digitalasset/ledger/api/v1/command_service_pb';
|
||||
|
||||
export { CommandSubmissionServiceService as CommandSubmissionService, CommandSubmissionServiceClient as CommandSubmissionClient, ICommandSubmissionServiceClient as ICommandSubmissionClient } from './com/digitalasset/ledger/api/v1/command_submission_service_grpc_pb';
|
||||
export { SubmitRequest } from './com/digitalasset/ledger/api/v1/command_submission_service_pb';
|
||||
|
||||
export { Command, Commands, CreateCommand, ExerciseCommand } from './com/digitalasset/ledger/api/v1/commands_pb';
|
||||
|
||||
export { Completion } from './com/digitalasset/ledger/api/v1/completion_pb';
|
||||
|
||||
export { ArchivedEvent, CreatedEvent, Event, ExercisedEvent } from './com/digitalasset/ledger/api/v1/event_pb';
|
||||
|
||||
export { LedgerConfigurationServiceService as LedgerConfigurationService, LedgerConfigurationServiceClient as LedgerConfigurationClient, ILedgerConfigurationServiceClient as ILedgerConfigurationClient } from './com/digitalasset/ledger/api/v1/ledger_configuration_service_grpc_pb';
|
||||
export { GetLedgerConfigurationRequest, GetLedgerConfigurationResponse, LedgerConfiguration } from './com/digitalasset/ledger/api/v1/ledger_configuration_service_pb';
|
||||
|
||||
export { LedgerIdentityServiceService as LedgerIdentityService, LedgerIdentityServiceClient as LedgerIdentityClient, ILedgerIdentityServiceClient as ILedgerIdentityClient } from './com/digitalasset/ledger/api/v1/ledger_identity_service_grpc_pb';
|
||||
export { GetLedgerIdentityRequest, GetLedgerIdentityResponse } from './com/digitalasset/ledger/api/v1/ledger_identity_service_pb';
|
||||
|
||||
export { LedgerOffset } from './com/digitalasset/ledger/api/v1/ledger_offset_pb'
|
||||
|
||||
export { PackageServiceService as PackageService, PackageServiceClient as PackageClient, IPackageServiceClient as IPackageClient } from './com/digitalasset/ledger/api/v1/package_service_grpc_pb';
|
||||
export { GetPackageRequest, GetPackageResponse, GetPackageStatusRequest, GetPackageStatusResponse, HashFunction, ListPackagesRequest, ListPackagesResponse, PackageStatus } from './com/digitalasset/ledger/api/v1/package_service_pb';
|
||||
|
||||
export { TraceContext } from './com/digitalasset/ledger/api/v1/trace_context_pb';
|
||||
|
||||
export { Filters, InclusiveFilters, TransactionFilter } from './com/digitalasset/ledger/api/v1/transaction_filter_pb';
|
||||
|
||||
export { Transaction, TransactionTree, TreeEvent } from './com/digitalasset/ledger/api/v1/transaction_pb';
|
||||
|
||||
export { TransactionServiceService as TransactionService, TransactionServiceClient as TransactionClient, ITransactionServiceClient as ITransactionClient } from './com/digitalasset/ledger/api/v1/transaction_service_grpc_pb';
|
||||
export { GetLedgerEndRequest, GetLedgerEndResponse, GetTransactionByEventIdRequest, GetTransactionByIdRequest, GetTransactionResponse, GetTransactionsRequest, GetTransactionsResponse, GetTransactionTreesResponse } from './com/digitalasset/ledger/api/v1/transaction_service_pb';
|
||||
|
||||
export { Identifier, List, Optional, Record, RecordField, Value, Variant } from './com/digitalasset/ledger/api/v1/value_pb';
|
||||
|
||||
export { Status } from './google/rpc/status_pb';
|
@ -1,9 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { Archive, ArchivePayload, HashFunction } from '../da/daml_lf_pb';
|
||||
|
||||
import * as v0 from '../da/daml_lf_0_pb';
|
||||
import * as v1 from '../da/daml_lf_1_pb';
|
||||
import * as dev from '../da/daml_lf_dev_pb';
|
||||
export { v0, v1, dev };
|
@ -1,22 +0,0 @@
|
||||
{
|
||||
"name": "daml-grpc",
|
||||
"version": "0.5.0",
|
||||
"description": "DAML Ledger API Node.js gRPC bindings",
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/digital-asset/daml",
|
||||
"directory": "language-support/js/daml-grpc"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"author": "Digital Asset (Switzerland) GmbH and/or its affiliates",
|
||||
"contributors": [
|
||||
"Stefano Baghino <stefano.baghino@daml.com>",
|
||||
"Mario Pastorelli <mario.pastorelli@daml.com>"
|
||||
],
|
||||
"dependencies": {
|
||||
"google-protobuf": "3.6.1",
|
||||
"grpc": "1.15.1"
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
set -ex
|
||||
|
||||
export PATH=$PATH:external/nodejs/bin:external/npm/node_modules/mocha/bin
|
||||
ln -s external/npm/node_modules
|
||||
|
||||
mkdir -p node_modules/daml-grpc
|
||||
tar xzf language-support/js/daml-grpc/daml-grpc.tgz --strip-components=1 -C node_modules/daml-grpc
|
||||
|
||||
echo '{"compilerOptions":{"lib":["es2015"]}}' > tsconfig.json
|
||||
|
||||
# Resolve the symbolic link to have the test import statements point to
|
||||
# the generated code folder so that the dependencies on generated code can
|
||||
# be resolved
|
||||
cp -L language-support/js/daml-grpc/test.ts .
|
||||
|
||||
mocha -r ts-node/register test.ts
|
@ -1,97 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as ledger from 'daml-grpc';
|
||||
import { expect } from 'chai';
|
||||
|
||||
describe('daml-grpc', () => {
|
||||
|
||||
it('should include all necessary definitions', () => {
|
||||
expect(ledger.testing).to.not.be.undefined;
|
||||
expect(ledger.testing.TimeService).to.not.be.undefined;
|
||||
expect(ledger.testing.TimeClient).to.not.be.undefined;
|
||||
expect(ledger.testing.GetTimeRequest).to.not.be.undefined;
|
||||
expect(ledger.testing.GetTimeResponse).to.not.be.undefined;
|
||||
expect(ledger.testing.SetTimeRequest).to.not.be.undefined;
|
||||
expect(ledger.testing.ResetService).to.not.be.undefined;
|
||||
expect(ledger.testing.ResetClient).to.not.be.undefined;
|
||||
expect(ledger.testing.ResetRequest).to.not.be.undefined;
|
||||
expect(ledger.ActiveContractsService).to.not.be.undefined;
|
||||
expect(ledger.ActiveContractsClient).to.not.be.undefined;
|
||||
expect(ledger.GetActiveContractsRequest).to.not.be.undefined;
|
||||
expect(ledger.GetActiveContractsResponse).to.not.be.undefined;
|
||||
expect(ledger.CommandCompletionService).to.not.be.undefined;
|
||||
expect(ledger.CommandCompletionClient).to.not.be.undefined;
|
||||
expect(ledger.Checkpoint).to.not.be.undefined;
|
||||
expect(ledger.CompletionEndRequest).to.not.be.undefined;
|
||||
expect(ledger.CompletionEndResponse).to.not.be.undefined;
|
||||
expect(ledger.CompletionStreamRequest).to.not.be.undefined;
|
||||
expect(ledger.CompletionStreamResponse).to.not.be.undefined;
|
||||
expect(ledger.CommandService).to.not.be.undefined;
|
||||
expect(ledger.CommandClient).to.not.be.undefined;
|
||||
expect(ledger.SubmitAndWaitRequest).to.not.be.undefined;
|
||||
expect(ledger.CommandSubmissionService).to.not.be.undefined;
|
||||
expect(ledger.CommandSubmissionClient).to.not.be.undefined;
|
||||
expect(ledger.SubmitRequest).to.not.be.undefined;
|
||||
expect(ledger.Command).to.not.be.undefined;
|
||||
expect(ledger.Commands).to.not.be.undefined;
|
||||
expect(ledger.CreateCommand).to.not.be.undefined;
|
||||
expect(ledger.ExerciseCommand).to.not.be.undefined;
|
||||
expect(ledger.Completion).to.not.be.undefined;
|
||||
expect(ledger.ArchivedEvent).to.not.be.undefined;
|
||||
expect(ledger.CreatedEvent).to.not.be.undefined;
|
||||
expect(ledger.Event).to.not.be.undefined;
|
||||
expect(ledger.ExercisedEvent).to.not.be.undefined;
|
||||
expect(ledger.LedgerConfigurationService).to.not.be.undefined;
|
||||
expect(ledger.LedgerConfigurationClient).to.not.be.undefined;
|
||||
expect(ledger.GetLedgerConfigurationRequest).to.not.be.undefined;
|
||||
expect(ledger.GetLedgerConfigurationResponse).to.not.be.undefined;
|
||||
expect(ledger.LedgerConfiguration).to.not.be.undefined;
|
||||
expect(ledger.LedgerIdentityService).to.not.be.undefined;
|
||||
expect(ledger.LedgerIdentityClient).to.not.be.undefined;
|
||||
expect(ledger.GetLedgerIdentityRequest).to.not.be.undefined;
|
||||
expect(ledger.GetLedgerIdentityResponse).to.not.be.undefined;
|
||||
expect(ledger.LedgerOffset).to.not.be.undefined;
|
||||
expect(ledger.PackageService).to.not.be.undefined;
|
||||
expect(ledger.PackageClient).to.not.be.undefined;
|
||||
expect(ledger.GetPackageRequest).to.not.be.undefined;
|
||||
expect(ledger.GetPackageResponse).to.not.be.undefined;
|
||||
expect(ledger.GetPackageStatusRequest).to.not.be.undefined;
|
||||
expect(ledger.GetPackageStatusResponse).to.not.be.undefined;
|
||||
expect(ledger.HashFunction).to.not.be.undefined;
|
||||
expect(ledger.ListPackagesRequest).to.not.be.undefined;
|
||||
expect(ledger.ListPackagesResponse).to.not.be.undefined;
|
||||
expect(ledger.PackageStatus).to.not.be.undefined;
|
||||
expect(ledger.TraceContext).to.not.be.undefined;
|
||||
expect(ledger.Filters).to.not.be.undefined;
|
||||
expect(ledger.InclusiveFilters).to.not.be.undefined;
|
||||
expect(ledger.TransactionFilter).to.not.be.undefined;
|
||||
expect(ledger.Transaction).to.not.be.undefined;
|
||||
expect(ledger.TransactionTree).to.not.be.undefined;
|
||||
expect(ledger.TreeEvent).to.not.be.undefined;
|
||||
expect(ledger.TransactionService).to.not.be.undefined;
|
||||
expect(ledger.TransactionClient).to.not.be.undefined;
|
||||
expect(ledger.GetLedgerEndRequest).to.not.be.undefined;
|
||||
expect(ledger.GetLedgerEndResponse).to.not.be.undefined;
|
||||
expect(ledger.GetTransactionByEventIdRequest).to.not.be.undefined;
|
||||
expect(ledger.GetTransactionByIdRequest).to.not.be.undefined;
|
||||
expect(ledger.GetTransactionResponse).to.not.be.undefined;
|
||||
expect(ledger.GetTransactionsRequest).to.not.be.undefined;
|
||||
expect(ledger.GetTransactionsResponse).to.not.be.undefined;
|
||||
expect(ledger.GetTransactionTreesResponse).to.not.be.undefined;
|
||||
expect(ledger.TransactionTree).to.not.be.undefined;
|
||||
expect(ledger.Identifier).to.not.be.undefined;
|
||||
expect(ledger.List).to.not.be.undefined;
|
||||
expect(ledger.Optional).to.not.be.undefined;
|
||||
expect(ledger.Record).to.not.be.undefined;
|
||||
expect(ledger.RecordField).to.not.be.undefined;
|
||||
expect(ledger.Value).to.not.be.undefined;
|
||||
expect(ledger.Variant).to.not.be.undefined;
|
||||
expect(ledger.Status).to.not.be.undefined;
|
||||
expect(ledger.lf).to.not.be.undefined;
|
||||
expect(ledger.lf.Archive).to.not.be.undefined;
|
||||
expect(ledger.lf.ArchivePayload).to.not.be.undefined;
|
||||
expect(ledger.lf.HashFunction).to.not.be.undefined;
|
||||
});
|
||||
|
||||
});
|
@ -1,8 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { TimeServiceService as TimeService, TimeServiceClient as TimeClient, ITimeServiceClient as ITimeClient } from '../com/digitalasset/ledger/api/v1/testing/time_service_grpc_pb';
|
||||
export { GetTimeRequest, GetTimeResponse, SetTimeRequest } from '../com/digitalasset/ledger/api/v1/testing/time_service_pb';
|
||||
|
||||
export { ResetServiceService as ResetService, ResetServiceClient as ResetClient, IResetServiceClient as IResetClient } from '../com/digitalasset/ledger/api/v1/testing/reset_service_grpc_pb';
|
||||
export { ResetRequest } from '../com/digitalasset/ledger/api/v1/testing/reset_service_pb';
|
@ -1,10 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"sourceMap": true,
|
||||
"outDir": "./dist/",
|
||||
"lib": [ "es2015" ]
|
||||
}
|
||||
}
|
@ -1,80 +0,0 @@
|
||||
load("@build_bazel_rules_typescript//:defs.bzl", "ts_config")
|
||||
|
||||
ts_config(
|
||||
name = "tsconfig",
|
||||
src = "tsconfig.json",
|
||||
deps = ["//:tsconfig.json"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "README",
|
||||
srcs = ["README.md"],
|
||||
visibility = ["//language-support/js:__subpackages__"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "src",
|
||||
srcs = glob(["src/**/*.ts"]),
|
||||
visibility = ["//language-support/js:__subpackages__"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "tests",
|
||||
srcs = glob(["tests/**/*"]),
|
||||
)
|
||||
|
||||
# ts_library does not accept arbitrary inputs, so we use a genrule
|
||||
genrule(
|
||||
name = "daml-ledger",
|
||||
srcs = [
|
||||
":src",
|
||||
"//language-support/js/daml-grpc",
|
||||
"package.json",
|
||||
":tsconfig",
|
||||
"@npm//@types/google-protobuf",
|
||||
"@npm//@types/node",
|
||||
"@npm//google-protobuf",
|
||||
"@npm//grpc",
|
||||
],
|
||||
outs = ["daml-ledger.tgz"],
|
||||
cmd = """
|
||||
set -e
|
||||
ln -s external/npm/node_modules
|
||||
mkdir -p node_modules/daml-grpc
|
||||
tar xzf $(location //language-support/js/daml-grpc) --strip-components=1 -C node_modules/daml-grpc
|
||||
$(execpath //language-support/js:tsc) --build $(location tsconfig)
|
||||
mkdir -p package
|
||||
cp -R language-support/js/daml-ledger/dist package
|
||||
cp $(location package.json) package
|
||||
tar czf $@ package
|
||||
""",
|
||||
tools = [
|
||||
"//language-support/js:tsc",
|
||||
],
|
||||
visibility = ["//:__subpackages__"],
|
||||
)
|
||||
|
||||
# nodejs_test does not support mocha, so we use sh_test
|
||||
sh_test(
|
||||
name = "test",
|
||||
srcs = ["test.sh"],
|
||||
data = [
|
||||
":src",
|
||||
":tests",
|
||||
"//language-support/js/daml-grpc",
|
||||
"@nodejs//:node",
|
||||
"@npm//@types/chai",
|
||||
"@npm//@types/google-protobuf",
|
||||
"@npm//@types/mocha",
|
||||
"@npm//@types/node",
|
||||
"@npm//@types/sinon",
|
||||
"@npm//chai",
|
||||
"@npm//google-protobuf",
|
||||
"@npm//grpc",
|
||||
"@npm//jsverify",
|
||||
"@npm//mocha",
|
||||
"@npm//sinon",
|
||||
"@npm//ts-node",
|
||||
"@npm//typescript",
|
||||
],
|
||||
)
|
@ -1,4 +0,0 @@
|
||||
# language-support/js/daml-ledger
|
||||
|
||||
This are the bindings for the Ledger API for JavaScript, targeting the Node.js runtime environment.
|
||||
|
@ -1,16 +0,0 @@
|
||||
# Unreleased changes
|
||||
|
||||
All notable unreleased changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
||||
|
||||
Summarizing, for every big change the contributor adds a corresponding entry into this
|
||||
file (`UNRELEASED.md`). Once a release is ready, the maintainer needs to move entries
|
||||
from this file into the section with the corresponding version number and release date
|
||||
in [`CHANGELOG.md`](CHANGELOG.md).
|
||||
|
||||
## Unreleased
|
||||
|
||||
### Changed
|
||||
- support Ledger API 1.5.0
|
@ -1,31 +0,0 @@
|
||||
# JavaScript bindings client-side validation
|
||||
|
||||
This document outlines the scope of client-side validation in the JS bindings.
|
||||
|
||||
## Scope
|
||||
|
||||
The chosen serialization format, Protocol Buffers, provides no way to enforce
|
||||
whether some part of a message is required or optional, delegating this check
|
||||
to the application layer.
|
||||
|
||||
As the glue that binds together the code generated by Protocol Buffers and the
|
||||
client-side applications, the bindings are the perfect place to enforce this
|
||||
kind of semantics on our APIs.
|
||||
|
||||
The bindings can serve as the layer to:
|
||||
- ensure only well-formed message are sent to the server
|
||||
- report error information which:
|
||||
- covers all detected discrepancies at once
|
||||
- is propagated via callbacks and streams (rather than exceptions)
|
||||
|
||||
By "well-formed" we mean a message that contains:
|
||||
- if it represents a plain object:
|
||||
- all the required fields, each with the correct type
|
||||
- zero or more optional fields, each with the correct type
|
||||
- if it represents a union:
|
||||
- exactly one field, with the correct type
|
||||
- in any case:
|
||||
- no unknown (i.e. extra) field (to easily catch crass mistakes)
|
||||
|
||||
Any other kind of check is delegated to the server as the ultimate judge of the
|
||||
semantics of messages.
|
@ -1,21 +0,0 @@
|
||||
{
|
||||
"name": "daml-ledger",
|
||||
"version": "0.5.0",
|
||||
"description": "DAML Ledger API Node.js bindings",
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/digital-asset/daml",
|
||||
"directory": "language-support/js/daml-ledger"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"author": "Digital Asset (Switzerland) GmbH and/or its affiliates",
|
||||
"contributors": [
|
||||
"Stefano Baghino <stefano.baghino@daml.com>",
|
||||
"Mario Pastorelli <mario.pastorelli@daml.com>"
|
||||
],
|
||||
"dependencies": {
|
||||
"daml-grpc": "0.5.0"
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { ClientUnaryCall } from "grpc";
|
||||
|
||||
/**
|
||||
* @interface ClientCancellableCall
|
||||
* @memberof ledger
|
||||
*/
|
||||
export class ClientCancellableCall {
|
||||
|
||||
private readonly wrapped: ClientUnaryCall | undefined;
|
||||
|
||||
private constructor(wrapped?: ClientUnaryCall) {
|
||||
this.wrapped = wrapped;
|
||||
}
|
||||
|
||||
public static accept(wrapped: ClientUnaryCall) {
|
||||
return new ClientCancellableCall(wrapped);
|
||||
}
|
||||
|
||||
public static readonly rejected = new ClientCancellableCall();
|
||||
|
||||
/**
|
||||
* Cancel the ongoing call. Results in the call ending with a CANCELLED status,
|
||||
* unless it has already ended with some other status.
|
||||
*
|
||||
* @method cancel
|
||||
* @memberof ledger.ClientCancellableCall
|
||||
* @instance
|
||||
*/
|
||||
cancel(): void {
|
||||
if (this.wrapped) {
|
||||
this.wrapped.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the endpoint this call/stream is connected to.
|
||||
*
|
||||
* @method getPeer
|
||||
* @memberof ledger.ClientCancellableCall
|
||||
* @instance
|
||||
* @returns {string} The URI of the endpoint or an empty string if the call never reached the server
|
||||
*/
|
||||
getPeer(): string {
|
||||
if (this.wrapped !== undefined) {
|
||||
return this.wrapped.getPeer();
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,88 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { Readable, ReadableOptions } from "stream";
|
||||
import { Mapping } from "../mapping";
|
||||
import { ClientReadableStream } from "grpc";
|
||||
import { MappingTransform } from "./mapping_transform";
|
||||
|
||||
/**
|
||||
* A stream of objects that are pushed from the server and are readable from
|
||||
* the client. It it a {@link external:Readble} Node.js stream and wraps the
|
||||
* call to gRPC.
|
||||
*
|
||||
* @interface ClientReadableObjectStream
|
||||
* @memberof ledger
|
||||
*/
|
||||
export class ClientReadableObjectStream<O> extends Readable {
|
||||
|
||||
private readonly wrapped?: ClientReadableStream<any>
|
||||
private readonly mapped?: MappingTransform<any, O>
|
||||
|
||||
private constructor(wrapped: Error | ClientReadableStream<any>, mapping?: Mapping<any, O>, opts?: ReadableOptions) {
|
||||
super(Object.assign(opts || {}, { objectMode: true }));
|
||||
if (!(wrapped instanceof Error) && mapping !== undefined) {
|
||||
this.wrapped = wrapped;
|
||||
this.mapped = this.wrapped.pipe(new MappingTransform(mapping));
|
||||
this.mapped.on('readable', () => this._read());
|
||||
this.mapped.on('finish', () => this.emit('end'));
|
||||
} else if (wrapped instanceof Error) {
|
||||
process.nextTick(() => {
|
||||
this.emit('error', wrapped);
|
||||
process.nextTick(() => {
|
||||
this.emit('end');
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static from<O>(wrapped: Error): ClientReadableObjectStream<O>
|
||||
static from<T, O>(wrapped: ClientReadableStream<T>, mapping: Mapping<T, O>, opts?: ReadableOptions): ClientReadableObjectStream<O>
|
||||
static from<O>(wrapped: Error | ClientReadableStream<any>, mapping?: Mapping<any, O>, opts?: ReadableOptions): ClientReadableObjectStream<O>{
|
||||
if (wrapped instanceof Error) {
|
||||
return new ClientReadableObjectStream<O>(wrapped);
|
||||
} else {
|
||||
return new ClientReadableObjectStream<O>(wrapped, mapping, opts);
|
||||
}
|
||||
}
|
||||
|
||||
_read(): void {
|
||||
if (this.mapped) {
|
||||
const object = this.mapped.read();
|
||||
if (object) {
|
||||
this.push(object);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel the ongoing call. Results in the call ending with a CANCELLED status,
|
||||
* unless it has already ended with some other status.
|
||||
*
|
||||
* @method cancel
|
||||
* @memberof ledger.ClientReadableObjectStream
|
||||
* @instance
|
||||
*/
|
||||
cancel(): void {
|
||||
if (this.wrapped) {
|
||||
this.wrapped.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the endpoint this call/stream is connected to.
|
||||
*
|
||||
* @method getPeer
|
||||
* @memberof ledger.ClientReadableObjectStream
|
||||
* @returns {string} The URI of the endpoint
|
||||
* @instance
|
||||
*/
|
||||
getPeer(): string {
|
||||
if (this.wrapped) {
|
||||
return this.wrapped.getPeer();
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { ClientCancellableCall } from './client_cancellable_call';
|
||||
export { ClientReadableObjectStream } from './client_readable_object_stream';
|
@ -1,26 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { Transform, TransformOptions } from "stream";
|
||||
import { Mapping } from "../mapping";
|
||||
|
||||
export class MappingTransform<M, O> extends Transform {
|
||||
|
||||
private readonly mapping: Mapping<M, O>
|
||||
|
||||
constructor(mapping: Mapping<M, O>, opts?: TransformOptions) {
|
||||
super(Object.assign(opts || {}, { objectMode: true }));
|
||||
this.mapping = mapping;
|
||||
}
|
||||
|
||||
_transform(message: M, _encoding: string, callback: Function): void {
|
||||
try {
|
||||
const next = message ? this.mapping.toObject(message) : null;
|
||||
this.push(next);
|
||||
callback();
|
||||
} catch (error) {
|
||||
callback(error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as grpc from 'daml-grpc';
|
||||
import * as ledger from '..';
|
||||
import * as mapping from '../mapping';
|
||||
import * as reporting from '../reporting';
|
||||
import * as validation from '../validation';
|
||||
import { ClientReadableObjectStream } from '../call/client_readable_object_stream';
|
||||
|
||||
/**
|
||||
* Allows clients to initialize themselves according to a fairly recent state
|
||||
* of the ledger without reading through all transactions that were committed
|
||||
* since the ledger's creation.
|
||||
*
|
||||
* @class ActiveContractsClient
|
||||
* @memberof ledger
|
||||
* @param {string} ledgerId
|
||||
* @param {grpc.IActiveContractsClient} client
|
||||
*/
|
||||
export class ActiveContractsClient {
|
||||
|
||||
private readonly ledgerId: string;
|
||||
private readonly client: grpc.IActiveContractsClient;
|
||||
private readonly reporter: reporting.Reporter;
|
||||
|
||||
constructor(ledgerId: string, client: grpc.IActiveContractsClient, reporter: reporting.Reporter) {
|
||||
this.ledgerId = ledgerId;
|
||||
this.client = client;
|
||||
this.reporter = reporter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a stream of the latest snapshot of active contracts. Getting an
|
||||
* empty stream means that the active contracts set is empty and the client
|
||||
* should listen to transactions using LEDGER_BEGIN.
|
||||
*
|
||||
* Clients SHOULD NOT assume that the set of active contracts they receive
|
||||
* reflects the state at the ledger end.
|
||||
*
|
||||
* @method getActiveContracts
|
||||
* @memberof ledger.ActiveContractsClient
|
||||
* @instance
|
||||
* @param {ledger.GetActiveContractsRequest} requestObject
|
||||
* @returns {ledger.ClientReadableObjectStream<ledger.GetActiveContractsResponse>}
|
||||
*/
|
||||
getActiveContracts(requestObject: ledger.GetActiveContractsRequest): ClientReadableObjectStream<ledger.GetActiveContractsResponse> {
|
||||
const tree = validation.GetActiveContractsRequest.validate(requestObject);
|
||||
if (validation.ok(tree)) {
|
||||
const request = mapping.GetActiveContractsRequest.toMessage(requestObject);
|
||||
request.setLedgerId(this.ledgerId);
|
||||
if (requestObject.verbose === undefined) {
|
||||
request.setVerbose(true);
|
||||
}
|
||||
return ClientReadableObjectStream.from(this.client.getActiveContracts(request), mapping.GetActiveContractsResponse);
|
||||
} else {
|
||||
return ClientReadableObjectStream.from(this.reporter(tree));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as grpc from 'daml-grpc';
|
||||
import * as ledger from '..';
|
||||
import * as mapping from '../mapping';
|
||||
import * as reporting from '../reporting';
|
||||
import * as validation from '../validation';
|
||||
|
||||
import { ClientCancellableCall } from '../call/client_cancellable_call';
|
||||
import { Callback } from '../util';
|
||||
import { justForward } from '../util/callback';
|
||||
|
||||
/**
|
||||
* Command Service is able to correlate submitted commands with completion
|
||||
* ledger, identify timeouts, and return contextual information with each
|
||||
* tracking result. This supports the implementation of stateless clients.
|
||||
*
|
||||
* @class CommandClient
|
||||
* @memberof ledger
|
||||
* @param {string} ledgerId
|
||||
* @param {grpc.ICommandClient} client
|
||||
*/
|
||||
export class CommandClient {
|
||||
|
||||
private readonly ledgerId: string
|
||||
private readonly client: grpc.ICommandClient
|
||||
private readonly reporter: reporting.Reporter
|
||||
|
||||
constructor(ledgerId: string, client: grpc.ICommandClient, reporter: reporting.Reporter) {
|
||||
this.ledgerId = ledgerId;
|
||||
this.client = client;
|
||||
this.reporter = reporter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Submits a single composite command and waits for its result.
|
||||
*
|
||||
* Returns RESOURCE_EXHAUSTED if the number of in-flight commands reached
|
||||
* the maximum (if a limit is configured).
|
||||
*
|
||||
* Propagates the gRPC error of failed submissions including DAML
|
||||
* interpretation errors.
|
||||
*
|
||||
* @method submitAndWait
|
||||
* @memberof ledger.CommandClient
|
||||
* @instance
|
||||
* @param {ledger.SubmitAndWaitRequest} requestObject
|
||||
* @param {util.Callback<null>} callback
|
||||
* @returns {ledger.ClientCancellableCall}
|
||||
*/
|
||||
submitAndWait(requestObject: ledger.SubmitAndWaitRequest, callback: Callback<null>): ClientCancellableCall {
|
||||
const tree = validation.SubmitAndWaitRequest.validate(requestObject);
|
||||
if (validation.ok(tree)) {
|
||||
const request = mapping.SubmitAndWaitRequest.toMessage(requestObject);
|
||||
if (request.hasCommands()) {
|
||||
request.getCommands()!.setLedgerId(this.ledgerId);
|
||||
}
|
||||
return ClientCancellableCall.accept(this.client.submitAndWait(request, (error, _) => {
|
||||
justForward(callback, error, null)
|
||||
}));
|
||||
} else {
|
||||
setImmediate(() => callback(this.reporter(tree)));
|
||||
return ClientCancellableCall.rejected;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,102 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as grpc from 'daml-grpc';
|
||||
import * as ledger from '..';
|
||||
import * as mapping from '../mapping';
|
||||
import * as reporting from '../reporting';
|
||||
import * as validation from '../validation';
|
||||
import { ClientReadableObjectStream } from '../call/client_readable_object_stream';
|
||||
import { ClientCancellableCall } from '../call/client_cancellable_call';
|
||||
import { Callback } from '../util';
|
||||
import { forward } from '../util/callback';
|
||||
|
||||
/**
|
||||
* Allows clients to observe the status of their submissions.
|
||||
*
|
||||
* Commands may be submitted via the Command Submission Service.
|
||||
*
|
||||
* The on-ledger effects of their submissions are disclosed by the
|
||||
* Transaction Service.
|
||||
*
|
||||
* Commands may fail in 4 distinct manners:
|
||||
*
|
||||
* 1. INVALID_PARAMETER gRPC error on malformed payloads and missing
|
||||
* required fields.
|
||||
*
|
||||
* 2. Failure communicated in the SubmitResponse.
|
||||
*
|
||||
* 3. Failure communicated in a Completion.
|
||||
*
|
||||
* 4. A Checkpoint with record_time > command mrt arrives through the
|
||||
* Completion Stream, and the command's Completion was not visible
|
||||
* before. In this case the command is lost.
|
||||
*
|
||||
* Clients that do not receive a successful completion about their
|
||||
* submission MUST NOT assume that it was successful.
|
||||
*
|
||||
* Clients SHOULD subscribe to the CompletionStream before starting to
|
||||
* submit commands to prevent race conditions.
|
||||
*
|
||||
* Interprocess tracing of command submissions may be achieved via Zipkin
|
||||
* by filling out the trace_context field.
|
||||
*
|
||||
* The server will return a child context of the submitted one, (or a new
|
||||
* one if the context was missing) on both the Completion and Transaction streams.
|
||||
*
|
||||
* @class CommandCompletionClient
|
||||
* @memberof ledger
|
||||
* @param {string} ledgerId
|
||||
* @param {grpc.ICommandCompletionClient} client
|
||||
*/
|
||||
export class CommandCompletionClient {
|
||||
|
||||
private readonly completionEndRequest: grpc.CompletionEndRequest
|
||||
private readonly client: grpc.ICommandCompletionClient
|
||||
private readonly ledgerId: string
|
||||
private readonly reporter: reporting.Reporter
|
||||
|
||||
constructor(ledgerId: string, client: grpc.ICommandCompletionClient, reporter: reporting.Reporter) {
|
||||
this.completionEndRequest = new grpc.CompletionEndRequest();
|
||||
this.completionEndRequest.setLedgerId(ledgerId);
|
||||
this.ledgerId = ledgerId;
|
||||
this.client = client;
|
||||
this.reporter = reporter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribe to command completion events.
|
||||
*
|
||||
* @method completionStream
|
||||
* @memberof ledger.CommandCompletionClient
|
||||
* @instance
|
||||
* @param {ledger.CompletionStreamRequest} requestObject
|
||||
* @returns {ledger.ClientReadableObjectStream<ledger.CompletionStreamResponse>}
|
||||
*/
|
||||
completionStream(requestObject: ledger.CompletionStreamRequest): ClientReadableObjectStream<ledger.CompletionStreamResponse> {
|
||||
const tree = validation.CompletionStreamRequest.validate(requestObject);
|
||||
if (validation.ok(tree)) {
|
||||
const request = mapping.CompletionStreamRequest.toMessage(requestObject);
|
||||
request.setLedgerId(this.ledgerId);
|
||||
return ClientReadableObjectStream.from(this.client.completionStream(request), mapping.CompletionStreamResponse);
|
||||
} else {
|
||||
return ClientReadableObjectStream.from(this.reporter(tree));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the offset after the latest completion.
|
||||
*
|
||||
* @method completionEnd
|
||||
* @memberof ledger.CommandCompletionClient
|
||||
* @instance
|
||||
* @param {util.Callback<ledger.CompletionEndResponse>} callback
|
||||
* @returns {ledger.ClientCancellableCall}
|
||||
*/
|
||||
completionEnd(callback: Callback<ledger.CompletionEndResponse>): ClientCancellableCall {
|
||||
return ClientCancellableCall.accept(this.client.completionEnd(this.completionEndRequest, (error, response) => {
|
||||
forward(callback, error, response, mapping.CompletionEndResponse.toObject);
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
@ -1,93 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as grpc from 'daml-grpc';
|
||||
import * as ledger from '..';
|
||||
import * as mapping from '../mapping';
|
||||
import * as reporting from '../reporting';
|
||||
import * as validation from '../validation';
|
||||
|
||||
import { Callback } from '../util';
|
||||
import { ClientCancellableCall } from '../call/client_cancellable_call';
|
||||
import { justForward } from '../util/callback';
|
||||
|
||||
/**
|
||||
* Allows clients to attempt advancing the ledger's state by submitting
|
||||
* commands.
|
||||
*
|
||||
* The final states of their submissions are disclosed by the Command
|
||||
* Completion Service.
|
||||
*
|
||||
* The on-ledger effects of their submissions are disclosed by the
|
||||
* Transaction Service.
|
||||
*
|
||||
* Commands may fail in 4 distinct manners:
|
||||
*
|
||||
* 1) INVALID_PARAMETER gRPC error on malformed payloads and missing
|
||||
* required fields.
|
||||
*
|
||||
* 2) Failure communicated in the SubmitResponse.
|
||||
*
|
||||
* 3) Failure communicated in a Completion.
|
||||
*
|
||||
* 4) A Checkoint with record_time > command mrt arrives through the
|
||||
* Completion Stream, and the command's Completion was not visible
|
||||
* before. In this case the command is lost.
|
||||
*
|
||||
* Clients that do not receive a successful completion about their
|
||||
* submission MUST NOT assume that it was successful.
|
||||
*
|
||||
* Clients SHOULD subscribe to the CompletionStream before starting to
|
||||
* submit commands to prevent race conditions.
|
||||
*
|
||||
* Interprocess tracing of command submissions may be achieved via Zipkin
|
||||
* by filling out the trace_context field.
|
||||
*
|
||||
* The server will return a child context of the submitted one, (or a new
|
||||
* one if the context was missing) on both the Completion and Transaction
|
||||
* streams.
|
||||
*
|
||||
* @class CommandSubmissionClient
|
||||
* @memberof ledger
|
||||
* @param {string} ledgerId
|
||||
* @param {grpc.ICommandSubmissionClient} client
|
||||
*/
|
||||
export class CommandSubmissionClient {
|
||||
|
||||
private readonly ledgerId: string;
|
||||
private readonly client: grpc.ICommandSubmissionClient;
|
||||
private readonly reporter: reporting.Reporter;
|
||||
|
||||
constructor(ledgerId: string, client: grpc.ICommandSubmissionClient, reporter: reporting.Reporter) {
|
||||
this.ledgerId = ledgerId;
|
||||
this.client = client;
|
||||
this.reporter = reporter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit a single composite command.
|
||||
*
|
||||
* @method submit
|
||||
* @memberof ledger.CommandSubmissionClient
|
||||
* @instance
|
||||
* @param {ledger.SubmitRequest} requestObject
|
||||
* @param {util.Callback<null>} callback
|
||||
* @returns {ledger.ClientCancellableCall}
|
||||
*/
|
||||
submit(requestObject: ledger.SubmitRequest, callback: Callback<null>): ClientCancellableCall {
|
||||
const tree = validation.SubmitRequest.validate(requestObject);
|
||||
if (validation.ok(tree)) {
|
||||
const request = mapping.SubmitRequest.toMessage(requestObject);
|
||||
if (request.hasCommands()) {
|
||||
request.getCommands()!.setLedgerId(this.ledgerId);
|
||||
}
|
||||
return ClientCancellableCall.accept(this.client.submit(request, (error, _) => {
|
||||
justForward(callback, error, null);
|
||||
}));
|
||||
} else {
|
||||
setImmediate(() => callback(this.reporter(tree)));
|
||||
return ClientCancellableCall.rejected;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as testing from './testing';
|
||||
export { testing };
|
||||
|
||||
export { ActiveContractsClient } from './active_contracts_client';
|
||||
export { CommandClient } from './command_client';
|
||||
export { CommandCompletionClient } from './command_completion_client';
|
||||
export { CommandSubmissionClient } from './command_submission_client';
|
||||
export { LedgerConfigurationClient } from './ledger_configuration_client';
|
||||
export { LedgerIdentityClient } from './ledger_identity_client';
|
||||
export { PackageClient } from './package_client';
|
||||
export { TransactionClient } from './transaction_client';
|
@ -1,42 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as grpc from 'daml-grpc';
|
||||
import * as ledger from '..';
|
||||
import * as mapping from '../mapping';
|
||||
|
||||
import { ClientReadableObjectStream } from '../call/client_readable_object_stream';
|
||||
|
||||
/**
|
||||
* LedgerConfigurationService allows clients to subscribe to changes of
|
||||
* the ledger configuration.
|
||||
*
|
||||
* @class LedgerConfigurationClient
|
||||
* @memberof ledger
|
||||
* @param {string} ledgerId
|
||||
* @param {grpc.ILedgerConfigurationClient} client
|
||||
*/
|
||||
export class LedgerConfigurationClient {
|
||||
|
||||
private readonly request: grpc.GetLedgerConfigurationRequest
|
||||
private readonly client: grpc.ILedgerConfigurationClient
|
||||
|
||||
constructor(ledgerId: string, client: grpc.ILedgerConfigurationClient) {
|
||||
this.request = new grpc.GetLedgerConfigurationRequest()
|
||||
this.request.setLedgerId(ledgerId);
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
/**
|
||||
* GetLedgerConfiguration returns the latest configuration as the first response, and publishes configuration updates in the same stream.
|
||||
*
|
||||
* @method getLedgerConfiguration
|
||||
* @memberof ledger.LedgerConfigurationClient
|
||||
* @instance
|
||||
* @returns {ledger.ClientReadableObjectStream<ledger.GetLedgerConfigurationResponse>}
|
||||
*/
|
||||
getLedgerConfiguration(): ClientReadableObjectStream<ledger.GetLedgerConfigurationResponse> {
|
||||
return ClientReadableObjectStream.from(this.client.getLedgerConfiguration(this.request), mapping.GetLedgerConfigurationResponse);
|
||||
}
|
||||
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as grpc from 'daml-grpc';
|
||||
import * as ledger from '..';
|
||||
import * as mapping from '../mapping';
|
||||
|
||||
import { Callback } from '../util';
|
||||
import { ClientCancellableCall } from '../call/client_cancellable_call';
|
||||
import { forward } from '../util/callback';
|
||||
|
||||
/**
|
||||
* Allows clients to verify that the server they are communicating with
|
||||
* exposes the ledger they wish to operate on.
|
||||
*
|
||||
* Note that every ledger has a unique id.
|
||||
*
|
||||
* @class LedgerIdentityClient
|
||||
* @memberof ledger
|
||||
* @param {grpc.ILedgerIdentityClient} client
|
||||
*/
|
||||
export class LedgerIdentityClient {
|
||||
|
||||
private static request = new grpc.GetLedgerIdentityRequest();
|
||||
|
||||
private readonly client: grpc.ILedgerIdentityClient
|
||||
|
||||
constructor(client: grpc.ILedgerIdentityClient) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clients may call this RPC to return the identifier of the ledger they
|
||||
* are connected to.
|
||||
*
|
||||
* @method getLedgerIdentity
|
||||
* @memberof ledger.LedgerIdentityClient
|
||||
* @instance
|
||||
* @param {util.Callback<ledger.GetLedgerIdentityResponse>} callback
|
||||
* @returns {ledger.ClientCancellableCall}
|
||||
*/
|
||||
getLedgerIdentity(callback: Callback<ledger.GetLedgerIdentityResponse>): ClientCancellableCall {
|
||||
return ClientCancellableCall.accept(this.client.getLedgerIdentity(LedgerIdentityClient.request, (error, response) => {
|
||||
forward(callback, error, response, mapping.GetLedgerIdentityResponse.toObject);
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
@ -1,88 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as grpc from 'daml-grpc';
|
||||
import * as ledger from '..';
|
||||
import * as mapping from '../mapping';
|
||||
|
||||
import { Callback } from '../util';
|
||||
import { ClientCancellableCall } from '../call/client_cancellable_call';
|
||||
import { forward } from '../util/callback';
|
||||
|
||||
/**
|
||||
* Allows clients to query the DAML LF packages that are supported by the
|
||||
* server.
|
||||
*
|
||||
* @class PackageClient
|
||||
* @memberof ledger
|
||||
* @param {string} ledgerId
|
||||
* @param {grpc.IPackageClient} client
|
||||
*/
|
||||
export class PackageClient {
|
||||
|
||||
private ledgerId: string;
|
||||
private listPackagesRequest: grpc.ListPackagesRequest
|
||||
private client: grpc.IPackageClient;
|
||||
|
||||
constructor(ledgerId: string, client: grpc.IPackageClient) {
|
||||
this.client = client;
|
||||
this.ledgerId = ledgerId;
|
||||
this.listPackagesRequest = new grpc.ListPackagesRequest();
|
||||
this.listPackagesRequest.setLedgerId(this.ledgerId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the identifiers of all supported packages.
|
||||
*
|
||||
* @method listPackages
|
||||
* @memberof ledger.PackageClient
|
||||
* @instance
|
||||
* @param {util.Callback<ledger.ListPackagesResponse>} callback
|
||||
* @returns {ledger.ClientCancellableCall}
|
||||
*/
|
||||
listPackages(callback: Callback<ledger.ListPackagesResponse>): ClientCancellableCall {
|
||||
return ClientCancellableCall.accept(this.client.listPackages(this.listPackagesRequest, (error, response) => {
|
||||
forward(callback, error, response, mapping.ListPackagesResponse.toObject);
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the contents of a single package, or a NOT_FOUND error if the
|
||||
* requested package is unknown.
|
||||
*
|
||||
* @method getPackage
|
||||
* @memberof ledger.PackageClient
|
||||
* @instance
|
||||
* @param {string} packageId
|
||||
* @param {util.Callback<ledger.GetPackageResponse>} callback
|
||||
* @returns {ledger.ClientCancellableCall}
|
||||
*/
|
||||
getPackage(packageId: string, callback: Callback<ledger.GetPackageResponse>): ClientCancellableCall {
|
||||
const request = new grpc.GetPackageRequest();
|
||||
request.setLedgerId(this.ledgerId);
|
||||
request.setPackageId(packageId);
|
||||
return ClientCancellableCall.accept(this.client.getPackage(request, (error, response) => {
|
||||
forward(callback, error, response, mapping.GetPackageResponse.toObject);
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the status of a single package.
|
||||
*
|
||||
* @method getPackageStatus
|
||||
* @memberof ledger.PackageClient
|
||||
* @instance
|
||||
* @param {string} packageId
|
||||
* @param {util.Callback<ledger.GetPackageStatusResponse>} callback
|
||||
* @returns {ledger.ClientCancellableCall}
|
||||
*/
|
||||
getPackageStatus(packageId: string, callback: Callback<ledger.GetPackageStatusResponse>): ClientCancellableCall {
|
||||
const request = new grpc.GetPackageStatusRequest();
|
||||
request.setLedgerId(this.ledgerId);
|
||||
request.setPackageId(packageId);
|
||||
return ClientCancellableCall.accept(this.client.getPackageStatus(request, (error, response) => {
|
||||
forward(callback, error, response, mapping.GetPackageStatusResponse.toObject);
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/**
|
||||
* @namespace ledger.testing
|
||||
*/
|
||||
|
||||
export { TimeClient } from './time_client';
|
||||
export { ResetClient } from './reset_client';
|
@ -1,26 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as grpc from 'daml-grpc';
|
||||
import { ClientCancellableCall } from '../../call';
|
||||
import { Callback } from '../../util';
|
||||
import { justForward } from '../../util/callback';
|
||||
|
||||
export class ResetClient {
|
||||
|
||||
private readonly request: grpc.testing.ResetRequest
|
||||
private readonly client: grpc.testing.IResetClient
|
||||
|
||||
constructor(ledgerId: string, client: grpc.testing.IResetClient) {
|
||||
this.client = client;
|
||||
this.request = new grpc.testing.ResetRequest();
|
||||
this.request.setLedgerId(ledgerId);
|
||||
}
|
||||
|
||||
reset(callback: Callback<null>) {
|
||||
return ClientCancellableCall.accept(this.client.reset(this.request, (error, _) => {
|
||||
justForward(callback, error, null)
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as grpc from 'daml-grpc';
|
||||
import * as ledger from '../..';
|
||||
import * as mapping from '../../mapping';
|
||||
import * as reporting from '../../reporting';
|
||||
import * as validation from '../../validation';
|
||||
import { ClientReadableObjectStream, ClientCancellableCall } from '../../call';
|
||||
import { Callback } from '../../util';
|
||||
import { justForward } from '../../util/callback';
|
||||
|
||||
/**
|
||||
* Optional service, exposed for testing static time scenarios.
|
||||
*
|
||||
* @class TimeClient
|
||||
* @memberof ledger.testing
|
||||
* @param {string} ledgerId
|
||||
* @param {grpc.testing.ITimeClient} client
|
||||
*/
|
||||
export class TimeClient {
|
||||
|
||||
private readonly ledgerId: string
|
||||
private readonly client: grpc.testing.ITimeClient
|
||||
private readonly reporter: reporting.Reporter;
|
||||
|
||||
constructor(ledgerId: string, client: grpc.testing.ITimeClient, reporter: reporting.Reporter) {
|
||||
this.ledgerId = ledgerId;
|
||||
this.client = client;
|
||||
this.reporter = reporter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a stream of time updates.
|
||||
*
|
||||
* Always returns at least one response, where the first one is the current
|
||||
* time.
|
||||
*
|
||||
* Subsequent responses are emitted whenever the ledger server's time is
|
||||
* updated.
|
||||
*
|
||||
* @method getTime
|
||||
* @memberof ledger.testing.TimeClient
|
||||
* @instance
|
||||
* @returns {ledger.ClientReadableObjectStream<ledger.GetTimeResponse>}
|
||||
*/
|
||||
getTime(): ClientReadableObjectStream<ledger.GetTimeResponse> {
|
||||
const request = new grpc.testing.GetTimeRequest();
|
||||
request.setLedgerId(this.ledgerId);
|
||||
return ClientReadableObjectStream.from(this.client.getTime(request), mapping.GetTimeResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows clients to change the ledger's clock in an atomic get-and-set
|
||||
* operation.
|
||||
*
|
||||
* @method setTime
|
||||
* @memberof ledger.testing.TimeClient
|
||||
* @instance
|
||||
* @param {ledger.SetTimeRequest} requestObject
|
||||
* @param {util.Callback<null>} callback
|
||||
*/
|
||||
setTime(requestObject: ledger.SetTimeRequest, callback: Callback<null>): ClientCancellableCall {
|
||||
const tree = validation.SetTimeRequest.validate(requestObject);
|
||||
if (validation.ok(tree)) {
|
||||
const request = mapping.SetTimeRequest.toMessage(requestObject);
|
||||
request.setLedgerId(this.ledgerId);
|
||||
return ClientCancellableCall.accept(this.client.setTime(request, (error, _) => {
|
||||
justForward(callback, error, null)
|
||||
}));
|
||||
} else {
|
||||
setImmediate(() => { callback(this.reporter(tree)); });
|
||||
return ClientCancellableCall.rejected;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,150 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as grpc from 'daml-grpc';
|
||||
import * as ledger from '..';
|
||||
import * as mapping from '../mapping';
|
||||
import * as validation from '../validation';
|
||||
import * as reporting from '../reporting';
|
||||
|
||||
import { Callback } from '../util';
|
||||
import { ClientReadableObjectStream } from '../call/client_readable_object_stream';
|
||||
import { ClientCancellableCall } from '../call/client_cancellable_call';
|
||||
import { forward } from '../util/callback';
|
||||
|
||||
/**
|
||||
* Allows clients to read transactions from the ledger.
|
||||
*
|
||||
* @class TransactionClient
|
||||
* @memberof ledger
|
||||
* @param {string} ledgerId
|
||||
* @param {grpc.ITransactionClient} client
|
||||
*/
|
||||
export class TransactionClient {
|
||||
|
||||
private readonly ledgerId: string;
|
||||
private readonly client: grpc.ITransactionClient;
|
||||
private readonly reporter: reporting.Reporter;
|
||||
|
||||
constructor(ledgerId: string, client: grpc.ITransactionClient, reporter: reporting.Reporter) {
|
||||
this.ledgerId = ledgerId;
|
||||
this.client = client;
|
||||
this.reporter = reporter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current ledger end.
|
||||
*
|
||||
* Subscriptions started with the returned offset will serve transactions
|
||||
* created after this RPC was called.
|
||||
*
|
||||
* @method getLedgerEnd
|
||||
* @memberof ledger.TransactionClient
|
||||
* @instance
|
||||
* @param {util.Callback<ledger.GetLedgerEndResponse>} callback
|
||||
* @returns {ledger.ClientCancellableCall}
|
||||
*/
|
||||
getLedgerEnd(callback: Callback<ledger.GetLedgerEndResponse>): ClientCancellableCall {
|
||||
const request = new grpc.GetLedgerEndRequest();
|
||||
request.setLedgerId(this.ledgerId);
|
||||
return ClientCancellableCall.accept(this.client.getLedgerEnd(request, (error, response) => {
|
||||
forward(callback, error, response, mapping.GetLedgerEndResponse.toObject);
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup a transaction by the ID of an event that appears within it.
|
||||
*
|
||||
* This call is a future extension point and is currently not supported.
|
||||
*
|
||||
* Returns NOT_FOUND if no such transaction exists.
|
||||
*
|
||||
* @method getTransactionByEventId
|
||||
* @memberof ledger.TransactionClient
|
||||
* @instance
|
||||
* @param {ledger.GetTransactionByEventIdRequest} requestObject
|
||||
* @param {util.Callback<ledger.GetTransactionResponse>} callback
|
||||
* @returns {ledger.ClientCancellableCall}
|
||||
*/
|
||||
getTransactionByEventId(requestObject: ledger.GetTransactionByEventIdRequest, callback: Callback<ledger.GetTransactionResponse>): ClientCancellableCall {
|
||||
const tree = validation.GetTransactionByEventIdRequest.validate(requestObject);
|
||||
if (validation.ok(tree)) {
|
||||
const request = mapping.GetTransactionByEventIdRequest.toMessage(requestObject);
|
||||
request.setLedgerId(this.ledgerId);
|
||||
return ClientCancellableCall.accept(this.client.getTransactionByEventId(request, (error, response) => {
|
||||
forward(callback, error, response, mapping.GetTransactionResponse.toObject);
|
||||
}));
|
||||
} else {
|
||||
setImmediate(() => callback(this.reporter(tree)));
|
||||
return ClientCancellableCall.rejected;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup a transaction by its ID.
|
||||
*
|
||||
* This call is a future extension point and is currently not supported.
|
||||
*
|
||||
* Returns NOT_FOUND if no such transaction exists.
|
||||
*
|
||||
* @method getTransactionById
|
||||
* @memberof ledger.TransactionClient
|
||||
* @instance
|
||||
* @param {ledger.GetTransactionByIdRequest} requestObject
|
||||
* @param {util.Callback<ledger.GetTransactionResponse>} callback
|
||||
* @returns {ledger.ClientCancellableCall}
|
||||
*/
|
||||
getTransactionById(requestObject: ledger.GetTransactionByIdRequest, callback: Callback<ledger.GetTransactionResponse>): ClientCancellableCall {
|
||||
const request = mapping.GetTransactionByIdRequest.toMessage(requestObject);
|
||||
request.setLedgerId(this.ledgerId);
|
||||
return ClientCancellableCall.accept(this.client.getTransactionById(request, (error, response) => {
|
||||
forward(callback, error, response, mapping.GetTransactionResponse.toObject);
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the ledger's filtered transaction stream for a set of parties.
|
||||
*
|
||||
* @method getTransactions
|
||||
* @memberof ledger.TransactionClient
|
||||
* @instance
|
||||
* @param {ledger.GetTransactionsRequest} requestObject
|
||||
* @returns {ledger.ClientReadableObjectStream<ledger.GetTransactionsResponse>}
|
||||
*/
|
||||
getTransactions(requestObject: ledger.GetTransactionsRequest): ClientReadableObjectStream<ledger.GetTransactionsResponse> {
|
||||
const tree = validation.GetTransactionsRequest.validate(requestObject);
|
||||
if (validation.ok(tree)) {
|
||||
const request = mapping.GetTransactionsRequest.toMessage(requestObject);
|
||||
request.setLedgerId(this.ledgerId);
|
||||
if (requestObject.verbose === undefined) {
|
||||
request.setVerbose(true);
|
||||
}
|
||||
return ClientReadableObjectStream.from(this.client.getTransactions(request), mapping.GetTransactionsResponse);
|
||||
} else {
|
||||
return ClientReadableObjectStream.from(this.reporter(tree));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the ledger's complete transaction stream for a set of parties.
|
||||
*
|
||||
* This call is a future extension point and is currently not supported.
|
||||
*
|
||||
* @method getTransactionTrees
|
||||
* @memberof ledger.TransactionClient
|
||||
* @instance
|
||||
* @param {ledger.GetTransactionsRequest} requestObject
|
||||
* @returns {ledger.ClientReadableObjectStream<ledger.GetTransactionTreesResponse>}
|
||||
*/
|
||||
getTransactionTrees(requestObject: ledger.GetTransactionsRequest): ClientReadableObjectStream<ledger.GetTransactionTreesResponse> {
|
||||
const tree = validation.GetTransactionsRequest.validate(requestObject);
|
||||
if (validation.ok(tree)) {
|
||||
const request = mapping.GetTransactionsRequest.toMessage(requestObject);
|
||||
request.setLedgerId(this.ledgerId);
|
||||
return ClientReadableObjectStream.from(this.client.getTransactionTrees(request), mapping.GetTransactionTreesResponse);
|
||||
} else {
|
||||
return ClientReadableObjectStream.from(this.reporter(tree));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,133 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { ChannelCredentials, credentials } from 'grpc';
|
||||
|
||||
import * as ledger from '.';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
import { Callback, forward } from './util/callback';
|
||||
|
||||
/**
|
||||
* A {@link ledger.LedgerClient} implementation that connects to an existing Ledger and provides clients to query it. To use the {@link ledger.DamlLedgerClient}
|
||||
* call the static `connect` method, passing an instance of {@link ledger.Options} with the host, port and (for secure connection) the
|
||||
* necessary certificates.
|
||||
*
|
||||
* @interface DamlLedgerClient
|
||||
* @memberof ledger
|
||||
* @implements ledger.LedgerClient
|
||||
*/
|
||||
export class DamlLedgerClient implements ledger.LedgerClient {
|
||||
|
||||
/**
|
||||
* Connects a new instance of the {@link ledger.DamlLedgerClient} to the Ledger.
|
||||
*
|
||||
* @method connect
|
||||
* @memberof ledger.DamlLedgerClient
|
||||
* @param {ledger.LedgerClient.Options} options The host, port and certificates needed to reach the ledger
|
||||
* @param {util.Callback<ledger.LedgerClient>} callback A callback that will be either passed an error or the LedgerClient instance in case of successfull connection
|
||||
*/
|
||||
static connect(options: ledger.LedgerClient.Options, callback: Callback<ledger.LedgerClient>): void {
|
||||
|
||||
let creds: ChannelCredentials;
|
||||
if (!options.certChain && !options.privateKey && !options.rootCerts) {
|
||||
creds = credentials.createInsecure();
|
||||
} else if (options.certChain && options.privateKey && options.rootCerts) {
|
||||
creds = credentials.createSsl(options.rootCerts, options.privateKey, options.certChain)
|
||||
} else {
|
||||
setImmediate(() => {
|
||||
callback(new Error(`Incomplete information provided to establish a secure connection (certChain: ${!!options.certChain}, privateKey: ${!!options.privateKey}, rootCerts: ${!!options.rootCerts})`));
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const reporter = options.reporter || ledger.reporting.SimpleReporter;
|
||||
const address = `${options.host}:${options.port}`;
|
||||
const client = new grpc.LedgerIdentityClient(address, creds);
|
||||
|
||||
client.getLedgerIdentity(new grpc.GetLedgerIdentityRequest(), (error, response) => {
|
||||
forward(callback, error, response, (response) => {
|
||||
return new DamlLedgerClient(response.getLedgerId(), address, creds, reporter);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public readonly ledgerId: string;
|
||||
|
||||
private readonly _activeContractsClient: ledger.ActiveContractsClient;
|
||||
private readonly _commandClient: ledger.CommandClient;
|
||||
private readonly _commandCompletionClient: ledger.CommandCompletionClient;
|
||||
private readonly _commandSubmissionClient: ledger.CommandSubmissionClient;
|
||||
private readonly _ledgerIdentityClient: ledger.LedgerIdentityClient;
|
||||
private readonly _packageClient: ledger.PackageClient;
|
||||
private readonly _ledgerConfigurationClient: ledger.LedgerConfigurationClient;
|
||||
private readonly _timeClient: ledger.testing.TimeClient;
|
||||
private readonly _transactionClient: ledger.TransactionClient;
|
||||
private readonly _resetClient: ledger.testing.ResetClient;
|
||||
|
||||
private constructor(ledgerId: string, address: string, creds: ChannelCredentials, reporter: ledger.reporting.Reporter) {
|
||||
this.ledgerId = ledgerId;
|
||||
this._activeContractsClient =
|
||||
new ledger.ActiveContractsClient(ledgerId, new grpc.ActiveContractsClient(address, creds), reporter);
|
||||
this._commandClient =
|
||||
new ledger.CommandClient(ledgerId, new grpc.CommandClient(address, creds), reporter);
|
||||
this._commandCompletionClient =
|
||||
new ledger.CommandCompletionClient(ledgerId, new grpc.CommandCompletionClient(address, creds), reporter);
|
||||
this._commandSubmissionClient =
|
||||
new ledger.CommandSubmissionClient(ledgerId, new grpc.CommandSubmissionClient(address, creds), reporter);
|
||||
this._ledgerIdentityClient =
|
||||
new ledger.LedgerIdentityClient(new grpc.LedgerIdentityClient(address, creds));
|
||||
this._packageClient =
|
||||
new ledger.PackageClient(ledgerId, new grpc.PackageClient(address, creds));
|
||||
this._ledgerConfigurationClient =
|
||||
new ledger.LedgerConfigurationClient(ledgerId, new grpc.LedgerConfigurationClient(address, creds));
|
||||
this._timeClient =
|
||||
new ledger.testing.TimeClient(ledgerId, new grpc.testing.TimeClient(address, creds), reporter);
|
||||
this._transactionClient =
|
||||
new ledger.TransactionClient(ledgerId, new grpc.TransactionClient(address, creds), reporter);
|
||||
this._resetClient =
|
||||
new ledger.testing.ResetClient(ledgerId, new grpc.testing.ResetClient(address, creds));
|
||||
}
|
||||
|
||||
get activeContractsClient(): ledger.ActiveContractsClient {
|
||||
return this._activeContractsClient;
|
||||
}
|
||||
|
||||
get commandClient(): ledger.CommandClient {
|
||||
return this._commandClient;
|
||||
}
|
||||
|
||||
get commandCompletionClient(): ledger.CommandCompletionClient {
|
||||
return this._commandCompletionClient;
|
||||
}
|
||||
|
||||
get commandSubmissionClient(): ledger.CommandSubmissionClient {
|
||||
return this._commandSubmissionClient;
|
||||
}
|
||||
|
||||
get ledgerIdentityClient(): ledger.LedgerIdentityClient {
|
||||
return this._ledgerIdentityClient;
|
||||
}
|
||||
|
||||
get packageClient(): ledger.PackageClient {
|
||||
return this._packageClient;
|
||||
}
|
||||
|
||||
get ledgerConfigurationClient(): ledger.LedgerConfigurationClient {
|
||||
return this._ledgerConfigurationClient;
|
||||
}
|
||||
|
||||
get timeClient(): ledger.testing.TimeClient {
|
||||
return this._timeClient;
|
||||
}
|
||||
|
||||
get transactionClient(): ledger.TransactionClient {
|
||||
return this._transactionClient;
|
||||
}
|
||||
|
||||
get resetClient(): ledger.testing.ResetClient {
|
||||
return this._resetClient;
|
||||
}
|
||||
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/**
|
||||
* @namespace ledger
|
||||
*/
|
||||
|
||||
export * from './model';
|
||||
|
||||
export * from './call';
|
||||
|
||||
export * from './client';
|
||||
|
||||
export * from './ledger_client';
|
||||
export * from './daml_ledger_client';
|
||||
|
||||
import * as reporting from './reporting';
|
||||
export { reporting };
|
@ -1,130 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as ledger from ".";
|
||||
|
||||
export namespace LedgerClient {
|
||||
|
||||
/**
|
||||
* The ledger required to connect to a {@link ledger.LedgerClient}
|
||||
*
|
||||
* @interface Options
|
||||
* @memberof ledger.LedgerClient
|
||||
*/
|
||||
export interface Options {
|
||||
/**
|
||||
* @member {string} host
|
||||
* @memberof ledger.LedgerClient.Options
|
||||
* @instance
|
||||
*/
|
||||
host: string
|
||||
/**
|
||||
* @member {number} port
|
||||
* @memberof ledger.LedgerClient.Options
|
||||
* @instance
|
||||
*/
|
||||
port: number
|
||||
/**
|
||||
* @member {ledger.reporting.Reporter} reporter
|
||||
* @memberof ledger.LedgerClient.Options
|
||||
* @instance
|
||||
*/
|
||||
reporter?: ledger.reporting.Reporter
|
||||
/**
|
||||
* @member {Buffer} rootCerts The root certificate ledger
|
||||
* @memberof ledger.LedgerClient.Options
|
||||
* @instance
|
||||
*/
|
||||
rootCerts?: Buffer
|
||||
/**
|
||||
* @member {Buffer} privateKey The client certificate private key
|
||||
* @memberof ledger.LedgerClient.Options
|
||||
* @instance
|
||||
*/
|
||||
privateKey?: Buffer
|
||||
/**
|
||||
* @member {Buffer} certChain The client certificate cert chain
|
||||
* @memberof ledger.LedgerClient.Options
|
||||
* @instance
|
||||
*/
|
||||
certChain?: Buffer
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains the set of services provided by a ledger implementation
|
||||
*
|
||||
* @interface LedgerClient
|
||||
* @memberof ledger
|
||||
*/
|
||||
export interface LedgerClient {
|
||||
/**
|
||||
* The identifier of the ledger connected to this {@link LedgerClient}
|
||||
*
|
||||
* @member {string} ledgerId
|
||||
* @memberof ledger.LedgerClient
|
||||
* @instance
|
||||
*/
|
||||
ledgerId: string
|
||||
/**
|
||||
* @member {ledger.ActiveContractsClient} activeContractsClient
|
||||
* @memberof ledger.LedgerClient
|
||||
* @instance
|
||||
*/
|
||||
activeContractsClient: ledger.ActiveContractsClient
|
||||
/**
|
||||
* @member {ledger.CommandClient} commandClient
|
||||
* @memberof ledger.LedgerClient
|
||||
* @instance
|
||||
*/
|
||||
commandClient: ledger.CommandClient
|
||||
/**
|
||||
* @member {ledger.CommandCompletionClient} commandCompletionClient
|
||||
* @memberof ledger.LedgerClient
|
||||
* @instance
|
||||
*/
|
||||
commandCompletionClient: ledger.CommandCompletionClient
|
||||
/**
|
||||
* @member {ledger.CommandSubmissionClient} commandSubmissionClient
|
||||
* @memberof ledger.LedgerClient
|
||||
* @instance
|
||||
*/
|
||||
commandSubmissionClient: ledger.CommandSubmissionClient
|
||||
/**
|
||||
* @member {ledger.LedgerIdentityClient} ledgerIdentityClient
|
||||
* @memberof ledger.LedgerClient
|
||||
* @instance
|
||||
*/
|
||||
ledgerIdentityClient: ledger.LedgerIdentityClient
|
||||
/**
|
||||
* @member {ledger.PackageClient} packageClient
|
||||
* @memberof ledger.LedgerClient
|
||||
* @instance
|
||||
*/
|
||||
packageClient: ledger.PackageClient
|
||||
/**
|
||||
* @member {ledger.LedgerConfigurationClient} ledgerConfigurationClient
|
||||
* @memberof ledger.LedgerClient
|
||||
* @instance
|
||||
*/
|
||||
ledgerConfigurationClient: ledger.LedgerConfigurationClient
|
||||
/**
|
||||
* @member {ledger.testing.TimeClient} timeClient
|
||||
* @memberof ledger.LedgerClient
|
||||
* @instance
|
||||
*/
|
||||
timeClient: ledger.testing.TimeClient
|
||||
/**
|
||||
* @member {ledger.TransactionClient} transactionClient
|
||||
* @memberof ledger.LedgerClient
|
||||
* @instance
|
||||
*/
|
||||
transactionClient: ledger.TransactionClient
|
||||
/**
|
||||
* @member {ledger.testing.ResetClient} resetClient
|
||||
* @memberof ledger.LedgerClient
|
||||
* @instance
|
||||
*/
|
||||
resetClient: ledger.testing.ResetClient
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as protobuf from 'google-protobuf/google/protobuf/any_pb';
|
||||
|
||||
export const Any: mapping.Mapping<protobuf.Any, ledger.Any> = {
|
||||
toObject(message: protobuf.Any): ledger.Any {
|
||||
return {
|
||||
value: message.getValue_asB64(),
|
||||
typeUrl: message.getTypeUrl()
|
||||
}
|
||||
},
|
||||
toMessage(object: ledger.Any): protobuf.Any {
|
||||
const message = new protobuf.Any();
|
||||
message.setValue(object.value);
|
||||
message.setTypeUrl(object.typeUrl);
|
||||
return message;
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const ArchivedEvent: mapping.Mapping<grpc.ArchivedEvent, ledger.ArchivedEvent> = {
|
||||
toObject(message: grpc.ArchivedEvent): ledger.ArchivedEvent {
|
||||
return {
|
||||
contractId: message.getContractId(),
|
||||
eventId: message.getEventId(),
|
||||
templateId: mapping.Identifier.toObject(message.getTemplateId()!),
|
||||
witnessParties: message.getWitnessPartiesList()
|
||||
};
|
||||
},
|
||||
toMessage(object: ledger.ArchivedEvent): grpc.ArchivedEvent {
|
||||
const message = new grpc.ArchivedEvent();
|
||||
message.setContractId(object.contractId);
|
||||
message.setEventId(object.eventId);
|
||||
message.setTemplateId(mapping.Identifier.toMessage(object.templateId));
|
||||
message.setWitnessPartiesList(object.witnessParties);
|
||||
return message;
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const Checkpoint: mapping.Mapping<grpc.Checkpoint, ledger.Checkpoint> = {
|
||||
toObject(message: grpc.Checkpoint): ledger.Checkpoint {
|
||||
return {
|
||||
offset: mapping.LedgerOffset.toObject(message.getOffset()!),
|
||||
recordTime: mapping.Timestamp.toObject(message.getRecordTime()!)
|
||||
};
|
||||
},
|
||||
toMessage(object: ledger.Checkpoint): grpc.Checkpoint {
|
||||
const message = new grpc.Checkpoint();
|
||||
message.setOffset(mapping.LedgerOffset.toMessage(object.offset));
|
||||
message.setRecordTime(mapping.Timestamp.toMessage(object.recordTime));
|
||||
return message;
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
import { inspect } from 'util';
|
||||
|
||||
export const Command: mapping.Mapping<grpc.Command, ledger.Command> = {
|
||||
toObject(command: grpc.Command): ledger.Command {
|
||||
if (command.hasCreate()) {
|
||||
return { create: mapping.CreateCommand.toObject(command.getCreate()!) };
|
||||
} else if (command.hasExercise()) {
|
||||
return { exercise: mapping.ExerciseCommand.toObject(command.getExercise()!) };
|
||||
} else {
|
||||
throw new Error(`Expected either CreateCommand or ExerciseCommand, found ${inspect(command)}`);
|
||||
}
|
||||
},
|
||||
toMessage(command: ledger.Command): grpc.Command {
|
||||
const result = new grpc.Command();
|
||||
if (command.create !== undefined) {
|
||||
result.setCreate(mapping.CreateCommand.toMessage(command.create));
|
||||
} else if (command.exercise !== undefined) {
|
||||
result.setExercise(mapping.ExerciseCommand.toMessage(command.exercise));
|
||||
} else {
|
||||
throw new Error(`Expected either LedgerOffset Absolute or LedgerOffset Boundary, found ${inspect(command)}`);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const Commands: mapping.Mapping<grpc.Commands, ledger.Commands> = {
|
||||
toObject(commands: grpc.Commands): ledger.Commands {
|
||||
const result: ledger.Commands = {
|
||||
applicationId: commands.getApplicationId(),
|
||||
commandId: commands.getCommandId(),
|
||||
party: commands.getParty(),
|
||||
ledgerEffectiveTime: mapping.Timestamp.toObject(commands.getLedgerEffectiveTime()!),
|
||||
maximumRecordTime: mapping.Timestamp.toObject(commands.getMaximumRecordTime()!),
|
||||
list: commands.getCommandsList().map((command) => mapping.Command.toObject(command))
|
||||
};
|
||||
const workflowId = commands.getWorkflowId();
|
||||
if (workflowId !== undefined && workflowId !== '') {
|
||||
result.workflowId = workflowId;
|
||||
}
|
||||
return result;
|
||||
},
|
||||
toMessage(commands: ledger.Commands): grpc.Commands {
|
||||
const result = new grpc.Commands();
|
||||
result.setCommandId(commands.commandId);
|
||||
result.setParty(commands.party);
|
||||
result.setLedgerEffectiveTime(mapping.Timestamp.toMessage(commands.ledgerEffectiveTime));
|
||||
result.setMaximumRecordTime(mapping.Timestamp.toMessage(commands.maximumRecordTime));
|
||||
result.setCommandsList(commands.list.map(mapping.Command.toMessage));
|
||||
if (commands.workflowId) {
|
||||
result.setWorkflowId(commands.workflowId);
|
||||
}
|
||||
if (commands.applicationId) {
|
||||
result.setApplicationId(commands.applicationId);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const Completion: mapping.Mapping<grpc.Completion, ledger.Completion> = {
|
||||
toObject(message: grpc.Completion): ledger.Completion {
|
||||
const completion: ledger.Completion = {
|
||||
commandId: message.getCommandId()
|
||||
}
|
||||
const status = message.getStatus();
|
||||
if (status !== undefined) {
|
||||
completion.status = mapping.Status.toObject(status);
|
||||
}
|
||||
return completion;
|
||||
},
|
||||
toMessage(object: ledger.Completion): grpc.Completion {
|
||||
const message = new grpc.Completion();
|
||||
message.setCommandId(object.commandId);
|
||||
if (object.status) {
|
||||
message.setStatus(mapping.Status.toMessage(object.status));
|
||||
}
|
||||
return message;
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const CompletionEndResponse: mapping.Mapping<grpc.CompletionEndResponse, ledger.CompletionEndResponse> = {
|
||||
toObject(message: grpc.CompletionEndResponse): ledger.CompletionEndResponse {
|
||||
return {
|
||||
offset: mapping.LedgerOffset.toObject(message.getOffset()!)
|
||||
};
|
||||
},
|
||||
toMessage(response: ledger.CompletionEndResponse): grpc.CompletionEndResponse {
|
||||
const result = new grpc.CompletionEndResponse();
|
||||
result.setOffset(mapping.LedgerOffset.toMessage(response.offset));
|
||||
return result;
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const CompletionStreamRequest: mapping.Mapping<grpc.CompletionStreamRequest, ledger.CompletionStreamRequest> = {
|
||||
toObject(message: grpc.CompletionStreamRequest): ledger.CompletionStreamRequest {
|
||||
return {
|
||||
applicationId: message.getApplicationId(),
|
||||
offset: mapping.LedgerOffset.toObject(message.getOffset()!),
|
||||
parties: message.getPartiesList()
|
||||
};
|
||||
},
|
||||
toMessage(object: ledger.CompletionStreamRequest): grpc.CompletionStreamRequest {
|
||||
const result = new grpc.CompletionStreamRequest();
|
||||
result.setApplicationId(object.applicationId);
|
||||
result.setOffset(mapping.LedgerOffset.toMessage(object.offset));
|
||||
result.setPartiesList(object.parties);
|
||||
return result;
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const CompletionStreamResponse: mapping.Mapping<grpc.CompletionStreamResponse, ledger.CompletionStreamResponse> = {
|
||||
toObject(message: grpc.CompletionStreamResponse): ledger.CompletionStreamResponse {
|
||||
const response: ledger.CompletionStreamResponse = {};
|
||||
const completions = message.getCompletionsList();
|
||||
if (completions) {
|
||||
response.completions = completions.map(c => mapping.Completion.toObject(c));
|
||||
}
|
||||
if (message.hasCheckpoint()) {
|
||||
response.checkpoint = mapping.Checkpoint.toObject(message.getCheckpoint()!)
|
||||
}
|
||||
return response;
|
||||
},
|
||||
toMessage(object: ledger.CompletionStreamResponse): grpc.CompletionStreamResponse {
|
||||
const result = new grpc.CompletionStreamResponse();
|
||||
if (object.checkpoint) {
|
||||
result.setCheckpoint(mapping.Checkpoint.toMessage(object.checkpoint));
|
||||
}
|
||||
if (object.completions) {
|
||||
result.setCompletionsList(object.completions.map((c: ledger.Completion) => mapping.Completion.toMessage(c)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const CreateCommand: mapping.Mapping<grpc.CreateCommand, ledger.CreateCommand> = {
|
||||
toObject(command: grpc.CreateCommand): ledger.CreateCommand {
|
||||
return {
|
||||
templateId: mapping.Identifier.toObject(command.getTemplateId()!),
|
||||
arguments: mapping.Record.toObject(command.getCreateArguments()!)
|
||||
}
|
||||
},
|
||||
toMessage(command: ledger.CreateCommand): grpc.CreateCommand {
|
||||
const result = new grpc.CreateCommand();
|
||||
result.setTemplateId(mapping.Identifier.toMessage(command.templateId));
|
||||
result.setCreateArguments(mapping.Record.toMessage(command.arguments));
|
||||
return result;
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const CreatedEvent: mapping.Mapping<grpc.CreatedEvent, ledger.CreatedEvent> = {
|
||||
toObject(event: grpc.CreatedEvent): ledger.CreatedEvent {
|
||||
return {
|
||||
eventId: event.getEventId(),
|
||||
contractId: event.getContractId(),
|
||||
templateId: mapping.Identifier.toObject(event.getTemplateId()!),
|
||||
arguments: mapping.Record.toObject(event.getCreateArguments()!),
|
||||
witnessParties: event.getWitnessPartiesList()
|
||||
};
|
||||
},
|
||||
toMessage(event: ledger.CreatedEvent): grpc.CreatedEvent {
|
||||
const result = new grpc.CreatedEvent();
|
||||
result.setEventId(event.eventId);
|
||||
result.setContractId(event.contractId);
|
||||
result.setTemplateId(mapping.Identifier.toMessage(event.templateId));
|
||||
result.setCreateArguments(mapping.Record.toMessage(event.arguments));
|
||||
result.setWitnessPartiesList(event.witnessParties);
|
||||
return result;
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as protobuf from 'google-protobuf/google/protobuf/duration_pb';
|
||||
|
||||
export const Duration: mapping.Mapping<protobuf.Duration, ledger.Duration> = {
|
||||
toObject(message: protobuf.Duration): ledger.Duration {
|
||||
return {
|
||||
seconds: message.getSeconds(),
|
||||
nanoseconds: message.getNanos()
|
||||
};
|
||||
},
|
||||
toMessage(object: ledger.Duration): protobuf.Duration {
|
||||
const message = new protobuf.Duration();
|
||||
message.setSeconds(object.seconds);
|
||||
message.setNanos(object.nanoseconds);
|
||||
return message;
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
import { inspect } from 'util';
|
||||
|
||||
export const Event: mapping.Mapping<grpc.Event, ledger.Event> = {
|
||||
toObject(message: grpc.Event): ledger.Event {
|
||||
if (message.hasArchived()) {
|
||||
return {
|
||||
archived: mapping.ArchivedEvent.toObject(message.getArchived()!)
|
||||
}
|
||||
} else if (message.hasCreated()) {
|
||||
return {
|
||||
created: mapping.CreatedEvent.toObject(message.getCreated()!)
|
||||
}
|
||||
} else if (message.hasExercised()) {
|
||||
return {
|
||||
exercised: mapping.ExercisedEvent.toObject(message.getExercised()!)
|
||||
}
|
||||
} else {
|
||||
throw new Error(`Expected one of ArchivedEvent, CreatedEvent or ExercisedEvent, found ${inspect(message)}`);
|
||||
}
|
||||
},
|
||||
toMessage(object: ledger.Event): grpc.Event {
|
||||
const message = new grpc.Event();
|
||||
if (object.archived !== undefined) {
|
||||
message.setArchived(mapping.ArchivedEvent.toMessage(object.archived));
|
||||
} else if (object.created !== undefined) {
|
||||
message.setCreated(mapping.CreatedEvent.toMessage(object.created));
|
||||
} else if (object.exercised !== undefined) {
|
||||
message.setExercised(mapping.ExercisedEvent.toMessage(object.exercised));
|
||||
} else {
|
||||
throw new Error(`Expected one of ArchivedEvent, CreatedEvent or ExercisedEvent, found ${inspect(object)}`);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const ExerciseCommand: mapping.Mapping<grpc.ExerciseCommand, ledger.ExerciseCommand> = {
|
||||
toObject(command: grpc.ExerciseCommand): ledger.ExerciseCommand {
|
||||
return {
|
||||
templateId: mapping.Identifier.toObject(command.getTemplateId()!),
|
||||
contractId: command.getContractId(),
|
||||
choice: command.getChoice(),
|
||||
argument: mapping.Value.toObject(command.getChoiceArgument()!),
|
||||
};
|
||||
},
|
||||
toMessage(command: ledger.ExerciseCommand): grpc.ExerciseCommand {
|
||||
const result = new grpc.ExerciseCommand();
|
||||
result.setTemplateId(mapping.Identifier.toMessage(command.templateId));
|
||||
result.setContractId(command.contractId);
|
||||
result.setChoice(command.choice);
|
||||
result.setChoiceArgument(mapping.Value.toMessage(command.argument));
|
||||
return result;
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const ExercisedEvent: mapping.Mapping<grpc.ExercisedEvent, ledger.ExercisedEvent> = {
|
||||
toObject(message: grpc.ExercisedEvent): ledger.ExercisedEvent {
|
||||
const event: ledger.ExercisedEvent = {
|
||||
actingParties: message.getActingPartiesList(),
|
||||
choice: message.getChoice(),
|
||||
argument: mapping.Value.toObject(message.getChoiceArgument()!),
|
||||
consuming: message.getConsuming(),
|
||||
contractCreatingEventId: message.getContractCreatingEventId(),
|
||||
contractId: message.getContractId(),
|
||||
eventId: message.getEventId(),
|
||||
templateId: mapping.Identifier.toObject(message.getTemplateId()!),
|
||||
witnessParties: message.getWitnessPartiesList()
|
||||
};
|
||||
const childEventIds = message.getChildEventIdsList();
|
||||
if (childEventIds) {
|
||||
event.childEventIds = [...childEventIds];
|
||||
}
|
||||
return event;
|
||||
},
|
||||
toMessage(object: ledger.ExercisedEvent): grpc.ExercisedEvent {
|
||||
const message = new grpc.ExercisedEvent();
|
||||
message.setActingPartiesList(object.actingParties);
|
||||
message.setChoice(object.choice);
|
||||
message.setChoiceArgument(mapping.Value.toMessage(object.argument));
|
||||
message.setConsuming(object.consuming);
|
||||
message.setContractCreatingEventId(object.contractCreatingEventId);
|
||||
message.setContractId(object.contractId);
|
||||
message.setEventId(object.eventId);
|
||||
message.setTemplateId(mapping.Identifier.toMessage(object.templateId));
|
||||
message.setWitnessPartiesList(object.witnessParties)
|
||||
if (object.childEventIds) {
|
||||
message.setChildEventIdsList([...object.childEventIds]);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const Filters: mapping.Mapping<grpc.Filters, ledger.Filters> = {
|
||||
toObject(filters: grpc.Filters): ledger.Filters {
|
||||
let result: ledger.Filters = {};
|
||||
if (filters.hasInclusive()) {
|
||||
result.inclusive = mapping.InclusiveFilters.toObject(filters.getInclusive()!);
|
||||
}
|
||||
return result;
|
||||
},
|
||||
toMessage(filter: ledger.Filters): grpc.Filters {
|
||||
const result = new grpc.Filters();
|
||||
if (filter.inclusive) {
|
||||
result.setInclusive(mapping.InclusiveFilters.toMessage(filter.inclusive));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const GetActiveContractsRequest: mapping.Mapping<grpc.GetActiveContractsRequest, ledger.GetActiveContractsRequest> = {
|
||||
toObject(message: grpc.GetActiveContractsRequest): ledger.GetActiveContractsRequest {
|
||||
const object: ledger.GetActiveContractsRequest = {
|
||||
filter: mapping.TransactionFilter.toObject(message.getFilter()!)
|
||||
}
|
||||
const verbose = message.getVerbose();
|
||||
if (verbose !== undefined) {
|
||||
object.verbose = verbose;
|
||||
}
|
||||
return object;
|
||||
},
|
||||
toMessage(object: ledger.GetActiveContractsRequest): grpc.GetActiveContractsRequest {
|
||||
const result = new grpc.GetActiveContractsRequest();
|
||||
if (object.verbose) {
|
||||
result.setVerbose(object.verbose);
|
||||
}
|
||||
result.setFilter(mapping.TransactionFilter.toMessage(object.filter));
|
||||
return result;
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const GetActiveContractsResponse: mapping.Mapping<grpc.GetActiveContractsResponse, ledger.GetActiveContractsResponse> = {
|
||||
toObject(response: grpc.GetActiveContractsResponse): ledger.GetActiveContractsResponse {
|
||||
const result: ledger.GetActiveContractsResponse = {
|
||||
offset: { absolute: response.getOffset() },
|
||||
};
|
||||
const workflowId = response.getWorkflowId();
|
||||
if (response.getWorkflowId() !== undefined && response.getWorkflowId() !== '') {
|
||||
result.workflowId = workflowId;
|
||||
}
|
||||
const activeContracts = response.getActiveContractsList();
|
||||
if (activeContracts) {
|
||||
result.activeContracts = activeContracts.map(event => mapping.CreatedEvent.toObject(event));
|
||||
}
|
||||
return result;
|
||||
},
|
||||
toMessage(response: ledger.GetActiveContractsResponse): grpc.GetActiveContractsResponse {
|
||||
const result = new grpc.GetActiveContractsResponse();
|
||||
result.setOffset(response.offset.absolute!);
|
||||
if (response.activeContracts) {
|
||||
result.setActiveContractsList(response.activeContracts.map(mapping.CreatedEvent.toMessage));
|
||||
}
|
||||
if (response.workflowId) {
|
||||
result.setWorkflowId(response.workflowId)
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const GetLedgerConfigurationResponse: mapping.Mapping<grpc.GetLedgerConfigurationResponse, ledger.GetLedgerConfigurationResponse> = {
|
||||
toObject(message: grpc.GetLedgerConfigurationResponse): ledger.GetLedgerConfigurationResponse {
|
||||
return {
|
||||
config: mapping.LedgerConfiguration.toObject(message.getLedgerConfiguration()!)
|
||||
};
|
||||
},
|
||||
toMessage(object: ledger.GetLedgerConfigurationResponse): grpc.GetLedgerConfigurationResponse {
|
||||
const message = new grpc.GetLedgerConfigurationResponse();
|
||||
message.setLedgerConfiguration(mapping.LedgerConfiguration.toMessage(object.config));
|
||||
return message;
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const GetLedgerEndResponse: mapping.Mapping<grpc.GetLedgerEndResponse, ledger.GetLedgerEndResponse> = {
|
||||
toObject(message: grpc.GetLedgerEndResponse): ledger.GetLedgerEndResponse {
|
||||
return {
|
||||
offset: mapping.LedgerOffset.toObject(message.getOffset()!)
|
||||
};
|
||||
},
|
||||
toMessage(object: ledger.GetLedgerEndResponse): grpc.GetLedgerEndResponse {
|
||||
const message = new grpc.GetLedgerEndResponse();
|
||||
message.setOffset(mapping.LedgerOffset.toMessage(object.offset));
|
||||
return message;
|
||||
}
|
||||
};
|
@ -1,19 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const GetLedgerIdentityResponse: mapping.Mapping<grpc.GetLedgerIdentityResponse, ledger.GetLedgerIdentityResponse> = {
|
||||
toObject(response: grpc.GetLedgerIdentityResponse): ledger.GetLedgerIdentityResponse {
|
||||
return {
|
||||
ledgerId: response.getLedgerId()
|
||||
}
|
||||
},
|
||||
toMessage(response: ledger.GetLedgerIdentityResponse): grpc.GetLedgerIdentityResponse {
|
||||
const result = new grpc.GetLedgerIdentityResponse();
|
||||
result.setLedgerId(response.ledgerId);
|
||||
return result;
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const GetPackageResponse: mapping.Mapping<grpc.GetPackageResponse, ledger.GetPackageResponse> = {
|
||||
toObject(response: grpc.GetPackageResponse): ledger.GetPackageResponse {
|
||||
return {
|
||||
hash: response.getHash(),
|
||||
hashFunction: ledger.HashFunction.SHA256,
|
||||
archivePayload: response.getArchivePayload_asB64()
|
||||
}
|
||||
},
|
||||
toMessage(response: ledger.GetPackageResponse): grpc.GetPackageResponse {
|
||||
const result = new grpc.GetPackageResponse();
|
||||
result.setHash(response.hash);
|
||||
result.setHashFunction(response.hashFunction);
|
||||
result.setArchivePayload(response.archivePayload);
|
||||
return result;
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const GetPackageStatusResponse: mapping.Mapping<grpc.GetPackageStatusResponse, ledger.GetPackageStatusResponse> = {
|
||||
toObject(response: grpc.GetPackageStatusResponse): ledger.GetPackageStatusResponse {
|
||||
return {
|
||||
status: mapping.PackageStatus.toObject(response.getPackageStatus())
|
||||
};
|
||||
},
|
||||
toMessage(response: ledger.GetPackageStatusResponse): grpc.GetPackageStatusResponse {
|
||||
const result = new grpc.GetPackageStatusResponse();
|
||||
result.setPackageStatus(mapping.PackageStatus.toMessage(response.status));
|
||||
return result;
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const GetTimeResponse: mapping.Mapping<grpc.testing.GetTimeResponse, ledger.GetTimeResponse> = {
|
||||
toObject(message: grpc.testing.GetTimeResponse): ledger.GetTimeResponse {
|
||||
return {
|
||||
currentTime: mapping.Timestamp.toObject(message.getCurrentTime()!)
|
||||
};
|
||||
},
|
||||
toMessage(object: ledger.GetTimeResponse) {
|
||||
const message = new grpc.testing.GetTimeResponse();
|
||||
message.setCurrentTime(mapping.Timestamp.toMessage(object.currentTime));
|
||||
return message;
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const GetTransactionByEventIdRequest: mapping.Mapping<grpc.GetTransactionByEventIdRequest, ledger.GetTransactionByEventIdRequest> = {
|
||||
toObject(message: grpc.GetTransactionByEventIdRequest): ledger.GetTransactionByEventIdRequest {
|
||||
return {
|
||||
eventId: message.getEventId(),
|
||||
requestingParties: message.getRequestingPartiesList()
|
||||
};
|
||||
},
|
||||
toMessage(object: ledger.GetTransactionByEventIdRequest): grpc.GetTransactionByEventIdRequest {
|
||||
const message = new grpc.GetTransactionByEventIdRequest();
|
||||
message.setEventId(object.eventId);
|
||||
message.setRequestingPartiesList(object.requestingParties);
|
||||
return message;
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const GetTransactionByIdRequest: mapping.Mapping<grpc.GetTransactionByIdRequest, ledger.GetTransactionByIdRequest> = {
|
||||
toObject(message: grpc.GetTransactionByIdRequest): ledger.GetTransactionByIdRequest {
|
||||
return {
|
||||
transactionId: message.getTransactionId(),
|
||||
requestingParties: message.getRequestingPartiesList()
|
||||
};
|
||||
},
|
||||
toMessage(object: ledger.GetTransactionByIdRequest): grpc.GetTransactionByIdRequest {
|
||||
const message = new grpc.GetTransactionByIdRequest();
|
||||
message.setTransactionId(object.transactionId);
|
||||
message.setRequestingPartiesList(object.requestingParties);
|
||||
return message;
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const GetTransactionResponse: mapping.Mapping<grpc.GetTransactionResponse, ledger.GetTransactionResponse> = {
|
||||
toObject(message: grpc.GetTransactionResponse): ledger.GetTransactionResponse {
|
||||
return {
|
||||
transaction: mapping.TransactionTree.toObject(message.getTransaction()!)
|
||||
};
|
||||
},
|
||||
toMessage(object: ledger.GetTransactionResponse): grpc.GetTransactionResponse {
|
||||
const message = new grpc.GetTransactionResponse();
|
||||
message.setTransaction(mapping.TransactionTree.toMessage(object.transaction));
|
||||
return message;
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const GetTransactionTreesResponse: mapping.Mapping<grpc.GetTransactionTreesResponse, ledger.GetTransactionTreesResponse> = {
|
||||
toObject(message: grpc.GetTransactionTreesResponse): ledger.GetTransactionTreesResponse {
|
||||
return {
|
||||
transactions: message.getTransactionsList().map(t => mapping.TransactionTree.toObject(t))
|
||||
};
|
||||
},
|
||||
toMessage(object: ledger.GetTransactionTreesResponse): grpc.GetTransactionTreesResponse {
|
||||
const message = new grpc.GetTransactionTreesResponse();
|
||||
message.setTransactionsList(object.transactions.map(t => mapping.TransactionTree.toMessage(t)))
|
||||
return message;
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const GetTransactionsRequest: mapping.Mapping<grpc.GetTransactionsRequest, ledger.GetTransactionsRequest> = {
|
||||
toObject(request: grpc.GetTransactionsRequest): ledger.GetTransactionsRequest {
|
||||
const result: ledger.GetTransactionsRequest = {
|
||||
begin: mapping.LedgerOffset.toObject(request.getBegin()!),
|
||||
filter: mapping.TransactionFilter.toObject(request.getFilter()!)
|
||||
};
|
||||
if (request.hasEnd()) {
|
||||
result.end = mapping.LedgerOffset.toObject(request.getEnd()!);
|
||||
}
|
||||
const verbose = request.getVerbose();
|
||||
if (verbose !== undefined) {
|
||||
result.verbose = verbose;
|
||||
}
|
||||
return result;
|
||||
},
|
||||
toMessage(request: ledger.GetTransactionsRequest): grpc.GetTransactionsRequest {
|
||||
const result = new grpc.GetTransactionsRequest();
|
||||
result.setBegin(mapping.LedgerOffset.toMessage(request.begin));
|
||||
if (request.end) {
|
||||
result.setEnd(mapping.LedgerOffset.toMessage(request.end));
|
||||
}
|
||||
result.setFilter(mapping.TransactionFilter.toMessage(request.filter));
|
||||
if (request.verbose !== undefined) {
|
||||
result.setVerbose(request.verbose);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const GetTransactionsResponse: mapping.Mapping<grpc.GetTransactionsResponse, ledger.GetTransactionsResponse> = {
|
||||
toObject(message: grpc.GetTransactionsResponse): ledger.GetTransactionsResponse {
|
||||
return {
|
||||
transactions: message.getTransactionsList().map((t: grpc.Transaction) => mapping.Transaction.toObject(t))
|
||||
};
|
||||
},
|
||||
toMessage(object: ledger.GetTransactionsResponse): grpc.GetTransactionsResponse {
|
||||
const message = new grpc.GetTransactionsResponse();
|
||||
message.setTransactionsList(object.transactions.map((t: ledger.Transaction) => mapping.Transaction.toMessage(t)))
|
||||
return message;
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const Identifier: mapping.Mapping<grpc.Identifier, ledger.Identifier> = {
|
||||
toObject(identifier: grpc.Identifier): ledger.Identifier {
|
||||
return {
|
||||
packageId: identifier.getPackageId(),
|
||||
moduleName: identifier.getModuleName(),
|
||||
entityName: identifier.getEntityName()
|
||||
};
|
||||
},
|
||||
toMessage(identifier: ledger.Identifier): grpc.Identifier {
|
||||
const value = new grpc.Identifier();
|
||||
value.setPackageId(identifier.packageId);
|
||||
value.setModuleName(identifier.moduleName);
|
||||
value.setEntityName(identifier.entityName);
|
||||
return value;
|
||||
}
|
||||
};
|
@ -1,19 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const InclusiveFilters: mapping.Mapping<grpc.InclusiveFilters, ledger.InclusiveFilters> = {
|
||||
toObject(inclusiveFilters: grpc.InclusiveFilters): ledger.InclusiveFilters {
|
||||
return {
|
||||
templateIds: inclusiveFilters.getTemplateIdsList().map((id) => mapping.Identifier.toObject(id))
|
||||
}
|
||||
},
|
||||
toMessage(inclusiveFilters: ledger.InclusiveFilters): grpc.InclusiveFilters {
|
||||
const result = new grpc.InclusiveFilters();
|
||||
result.setTemplateIdsList(inclusiveFilters.templateIds.map((id) => mapping.Identifier.toMessage(id)));
|
||||
return result;
|
||||
}
|
||||
};
|
@ -1,52 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { Any } from './any';
|
||||
export { ArchivedEvent } from './archived_event';
|
||||
export { Checkpoint } from './checkpoint';
|
||||
export { Command } from './command';
|
||||
export { Commands } from './commands';
|
||||
export { CompletionEndResponse } from './completion_end_response';
|
||||
export { CompletionStreamRequest } from './completion_stream_request';
|
||||
export { CompletionStreamResponse } from './completion_stream_response';
|
||||
export { Completion } from './completion';
|
||||
export { CreateCommand } from './create_command';
|
||||
export { CreatedEvent } from './created_event';
|
||||
export { Duration } from './duration';
|
||||
export { Event } from './event';
|
||||
export { ExerciseCommand } from './exercise_command';
|
||||
export { ExercisedEvent } from './exercised_event';
|
||||
export { Filters } from './filters';
|
||||
export { GetActiveContractsRequest } from './get_active_contracts_request';
|
||||
export { GetActiveContractsResponse } from './get_active_contracts_response';
|
||||
export { GetLedgerConfigurationResponse } from './get_ledger_configuration_response';
|
||||
export { GetLedgerEndResponse } from './get_ledger_end_response';
|
||||
export { GetLedgerIdentityResponse } from './get_ledger_identity_response';
|
||||
export { GetPackageResponse } from './get_package_response';
|
||||
export { GetPackageStatusResponse } from './get_package_status_response';
|
||||
export { GetTimeResponse } from './get_time_response';
|
||||
export { GetTransactionByEventIdRequest } from './get_transaction_by_event_id_request';
|
||||
export { GetTransactionByIdRequest } from './get_transaction_by_id_request';
|
||||
export { GetTransactionResponse } from './get_transaction_response';
|
||||
export { GetTransactionTreesResponse } from './get_transaction_trees_response';
|
||||
export { GetTransactionsRequest } from './get_transactions_request';
|
||||
export { GetTransactionsResponse } from './get_transactions_response';
|
||||
export { Identifier } from './identifier';
|
||||
export { InclusiveFilters } from './inclusive_filters';
|
||||
export { Optional } from './optional';
|
||||
export { LedgerConfiguration } from './ledger_configuration';
|
||||
export { LedgerOffset } from './ledger_offset';
|
||||
export { ListPackagesResponse } from './list_packages_response';
|
||||
export { Mapping } from './mapping';
|
||||
export { PackageStatus } from './package_status';
|
||||
export { Record } from './record';
|
||||
export { SetTimeRequest } from './set_time_request';
|
||||
export { Status } from './status';
|
||||
export { SubmitAndWaitRequest } from './submit_and_wait_request';
|
||||
export { SubmitRequest } from './submit_request';
|
||||
export { Timestamp } from './timestamp';
|
||||
export { TreeEvent } from './tree_event';
|
||||
export { Transaction } from './transaction';
|
||||
export { TransactionFilter } from './transaction_filter';
|
||||
export { TransactionTree } from './transaction_tree';
|
||||
export { Value } from './value';
|
@ -1,21 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const LedgerConfiguration: mapping.Mapping<grpc.LedgerConfiguration, ledger.LedgerConfiguration> = {
|
||||
toObject(message: grpc.LedgerConfiguration): ledger.LedgerConfiguration {
|
||||
return {
|
||||
minTtl: mapping.Duration.toObject(message.getMinTtl()!),
|
||||
maxTtl: mapping.Duration.toObject(message.getMaxTtl()!)
|
||||
};
|
||||
},
|
||||
toMessage(object: ledger.LedgerConfiguration): grpc.LedgerConfiguration {
|
||||
const message = new grpc.LedgerConfiguration();
|
||||
message.setMinTtl(mapping.Duration.toMessage(object.minTtl));
|
||||
message.setMaxTtl(mapping.Duration.toMessage(object.maxTtl));
|
||||
return message;
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
import { inspect } from 'util';
|
||||
|
||||
export const LedgerOffset: mapping.Mapping<grpc.LedgerOffset, ledger.LedgerOffset> = {
|
||||
toObject(ledgerOffset: grpc.LedgerOffset): ledger.LedgerOffset {
|
||||
if (ledgerOffset.hasAbsolute()) {
|
||||
return { absolute: ledgerOffset.getAbsolute() }
|
||||
} else if (ledgerOffset.hasBoundary()) {
|
||||
const boundary = ledgerOffset.getBoundary();
|
||||
switch (boundary) {
|
||||
case grpc.LedgerOffset.LedgerBoundary.LEDGER_BEGIN: {
|
||||
return { boundary: ledger.LedgerOffset.Boundary.BEGIN }
|
||||
}
|
||||
case grpc.LedgerOffset.LedgerBoundary.LEDGER_END: {
|
||||
return { boundary: ledger.LedgerOffset.Boundary.END }
|
||||
}
|
||||
default: {
|
||||
throw new Error(`Expected LedgerOffset Boundary, found ${inspect(boundary)}`);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new Error(`Expected either LedgerOffset Absolute or LedgerOffset Boundary, found ${inspect(ledgerOffset)}`);
|
||||
}
|
||||
},
|
||||
toMessage(ledgerOffset: ledger.LedgerOffset): grpc.LedgerOffset {
|
||||
const result = new grpc.LedgerOffset();
|
||||
if (ledgerOffset.boundary !== undefined) {
|
||||
switch (ledgerOffset.boundary) {
|
||||
case ledger.LedgerOffset.Boundary.BEGIN: {
|
||||
result.setBoundary(grpc.LedgerOffset.LedgerBoundary.LEDGER_BEGIN);
|
||||
break;
|
||||
}
|
||||
case ledger.LedgerOffset.Boundary.END: {
|
||||
result.setBoundary(grpc.LedgerOffset.LedgerBoundary.LEDGER_END);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw new Error(`Expected boundary, found ${inspect(ledgerOffset.boundary!)}`);
|
||||
}
|
||||
}
|
||||
} else if (ledgerOffset.absolute) {
|
||||
result.setAbsolute(ledgerOffset.absolute);
|
||||
} else {
|
||||
throw new Error(`Expected either LedgerOffset Absolute or LedgerOffset Boundary, found ${inspect(ledgerOffset)}`);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const ListPackagesResponse: mapping.Mapping<grpc.ListPackagesResponse, ledger.ListPackagesResponse> = {
|
||||
toObject(response: grpc.ListPackagesResponse): ledger.ListPackagesResponse {
|
||||
return {
|
||||
packageIds: response.getPackageIdsList()
|
||||
}
|
||||
},
|
||||
toMessage(response: ledger.ListPackagesResponse): grpc.ListPackagesResponse {
|
||||
const result = new grpc.ListPackagesResponse();
|
||||
result.setPackageIdsList(response.packageIds);
|
||||
return result;
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/**
|
||||
* A Mapping between a Protocol Buffers message M and a plain object specified by an interface O
|
||||
*/
|
||||
export interface Mapping<M, O> {
|
||||
|
||||
/**
|
||||
* Converts a plain JS object to a Protocol Buffers message following this mapping
|
||||
* @param object A plain JS object
|
||||
*/
|
||||
toMessage(object: O): M
|
||||
|
||||
/**
|
||||
* Converts a Protocol Buffers message to a plain JS object following this mapping
|
||||
*/
|
||||
toObject(message: M): O
|
||||
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const Optional: mapping.Mapping<grpc.Optional, ledger.Optional> = {
|
||||
toObject(message: grpc.Optional): ledger.Optional {
|
||||
const object: ledger.Optional = {};
|
||||
if (message.hasValue()) {
|
||||
object.value = mapping.Value.toObject(message.getValue()!);
|
||||
}
|
||||
return object;
|
||||
},
|
||||
toMessage(object: ledger.Optional): grpc.Optional {
|
||||
const message = new grpc.Optional();
|
||||
if (object.value !== undefined) {
|
||||
message.setValue(mapping.Value.toMessage(object.value));
|
||||
}
|
||||
return message;
|
||||
}
|
||||
};
|
@ -1,28 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const PackageStatus: mapping.Mapping<grpc.PackageStatus, ledger.PackageStatus> = {
|
||||
toObject(status: grpc.PackageStatus): ledger.PackageStatus {
|
||||
if (status === grpc.PackageStatus.REGISTERED) {
|
||||
return ledger.PackageStatus.REGISTERED;
|
||||
} else if (status === grpc.PackageStatus.UNKNOWN) {
|
||||
return ledger.PackageStatus.UNKNOWN;
|
||||
} else {
|
||||
throw new Error(`Unknown PackageStatus ${status}`);
|
||||
}
|
||||
},
|
||||
toMessage(status: ledger.PackageStatus): grpc.PackageStatus {
|
||||
if (status === ledger.PackageStatus.REGISTERED) {
|
||||
return grpc.PackageStatus.REGISTERED;
|
||||
} else if (status === ledger.PackageStatus.UNKNOWN) {
|
||||
return grpc.PackageStatus.UNKNOWN;
|
||||
} else {
|
||||
throw new Error(`Unknown PackageStatus ${status}`);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const Record: mapping.Mapping<grpc.Record, ledger.Record> = {
|
||||
toObject(record: grpc.Record): ledger.Record {
|
||||
let fieldIndex = 0; // used for records returned in non-verbose mode
|
||||
const fields: {[k: string]: ledger.Value} = {};
|
||||
record.getFieldsList().forEach((field: grpc.RecordField) => {
|
||||
fields[field.getLabel() || fieldIndex++] = mapping.Value.toObject(field.getValue()!);
|
||||
});
|
||||
const result: ledger.Record = { fields: fields }
|
||||
if (record.hasRecordId()) {
|
||||
result.recordId = mapping.Identifier.toObject(record.getRecordId()!);
|
||||
}
|
||||
return result;
|
||||
},
|
||||
toMessage(record: ledger.Record): grpc.Record {
|
||||
const result = new grpc.Record();
|
||||
if (record.recordId) {
|
||||
result.setRecordId(mapping.Identifier.toMessage(record.recordId));
|
||||
}
|
||||
const list: grpc.RecordField[] = []
|
||||
Object.keys(record.fields).forEach((label: string) => {
|
||||
const value = mapping.Value.toMessage(record.fields[label]);
|
||||
const field = new grpc.RecordField();
|
||||
field.setLabel(label);
|
||||
field.setValue(value);
|
||||
list.push(field);
|
||||
});
|
||||
result.setFieldsList(list);
|
||||
return result;
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const SetTimeRequest: mapping.Mapping<grpc.testing.SetTimeRequest, ledger.SetTimeRequest> = {
|
||||
toObject(message: grpc.testing.SetTimeRequest): ledger.SetTimeRequest {
|
||||
return {
|
||||
currentTime: mapping.Timestamp.toObject(message.getCurrentTime()!),
|
||||
newTime: mapping.Timestamp.toObject(message.getNewTime()!)
|
||||
};
|
||||
},
|
||||
toMessage(object: ledger.SetTimeRequest): grpc.testing.SetTimeRequest {
|
||||
const message = new grpc.testing.SetTimeRequest();
|
||||
message.setCurrentTime(mapping.Timestamp.toMessage(object.currentTime));
|
||||
message.setNewTime(mapping.Timestamp.toMessage(object.newTime));
|
||||
return message;
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
import * as protobuf from 'google-protobuf/google/protobuf/any_pb';
|
||||
|
||||
export const Status: mapping.Mapping<grpc.Status, ledger.Status> = {
|
||||
toObject(message: grpc.Status): ledger.Status {
|
||||
return {
|
||||
code: message.getCode(),
|
||||
message: message.getMessage(),
|
||||
details: message.getDetailsList().map((a: protobuf.Any) => mapping.Any.toObject(a))
|
||||
};
|
||||
},
|
||||
toMessage(object: ledger.Status): grpc.Status {
|
||||
const message = new grpc.Status();
|
||||
message.setCode(object.code);
|
||||
message.setMessage(object.message);
|
||||
message.setDetailsList(object.details.map((a: ledger.Any) => mapping.Any.toMessage(a)));
|
||||
return message;
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const SubmitAndWaitRequest: mapping.Mapping<grpc.SubmitAndWaitRequest, ledger.SubmitAndWaitRequest> = {
|
||||
toObject(request: grpc.SubmitAndWaitRequest): ledger.SubmitAndWaitRequest {
|
||||
return {
|
||||
commands: mapping.Commands.toObject(request.getCommands()!)
|
||||
};
|
||||
},
|
||||
toMessage(request: ledger.SubmitAndWaitRequest): grpc.SubmitAndWaitRequest {
|
||||
const result = new grpc.SubmitAndWaitRequest();
|
||||
result.setCommands(mapping.Commands.toMessage(request.commands));
|
||||
return result;
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const SubmitRequest: mapping.Mapping<grpc.SubmitRequest, ledger.SubmitRequest> = {
|
||||
toObject(request: grpc.SubmitRequest): ledger.SubmitRequest {
|
||||
return {
|
||||
commands: mapping.Commands.toObject(request.getCommands()!)
|
||||
};
|
||||
},
|
||||
toMessage(request: ledger.SubmitRequest): grpc.SubmitRequest {
|
||||
const result = new grpc.SubmitRequest();
|
||||
result.setCommands(mapping.Commands.toMessage(request.commands));
|
||||
return result;
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as protobuf from 'google-protobuf/google/protobuf/timestamp_pb';
|
||||
|
||||
export const Timestamp: mapping.Mapping<protobuf.Timestamp, ledger.Timestamp> = {
|
||||
toObject(timestamp: protobuf.Timestamp): ledger.Timestamp {
|
||||
return {
|
||||
seconds: timestamp.getSeconds(),
|
||||
nanoseconds: timestamp.getNanos()
|
||||
}
|
||||
},
|
||||
toMessage(timestamp: ledger.Timestamp): protobuf.Timestamp {
|
||||
const result = new protobuf.Timestamp();
|
||||
result.setSeconds(timestamp.seconds);
|
||||
result.setNanos(timestamp.nanoseconds);
|
||||
return result;
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const Transaction: mapping.Mapping<grpc.Transaction, ledger.Transaction> = {
|
||||
toObject(message: grpc.Transaction): ledger.Transaction {
|
||||
const transaction: ledger.Transaction = {
|
||||
effectiveAt: mapping.Timestamp.toObject(message.getEffectiveAt()!),
|
||||
events: message.getEventsList().map((e: grpc.Event) => mapping.Event.toObject(e)),
|
||||
offset: message.getOffset(),
|
||||
transactionId: message.getTransactionId(),
|
||||
};
|
||||
const commandId = message.getCommandId();
|
||||
if (commandId !== undefined && commandId !== '') {
|
||||
transaction.commandId = commandId;
|
||||
}
|
||||
const workflowId = message.getWorkflowId();
|
||||
if (workflowId !== undefined && workflowId !== '') {
|
||||
transaction.workflowId = workflowId;
|
||||
}
|
||||
return transaction;
|
||||
},
|
||||
toMessage(object: ledger.Transaction): grpc.Transaction {
|
||||
const message = new grpc.Transaction();
|
||||
message.setEffectiveAt(mapping.Timestamp.toMessage(object.effectiveAt));
|
||||
message.setEventsList(object.events.map((e: ledger.Event) => mapping.Event.toMessage(e)));
|
||||
message.setOffset(object.offset);
|
||||
message.setTransactionId(object.transactionId);
|
||||
if (object.commandId) {
|
||||
message.setCommandId(object.commandId);
|
||||
}
|
||||
if (object.workflowId) {
|
||||
message.setWorkflowId(object.workflowId);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const TransactionFilter: mapping.Mapping<grpc.TransactionFilter, ledger.TransactionFilter> = {
|
||||
toObject(transactionFilter: grpc.TransactionFilter): ledger.TransactionFilter {
|
||||
let filtersByParty: {[k: string]: ledger.Filters} = {};
|
||||
transactionFilter.getFiltersByPartyMap().forEach((filters: grpc.Filters, party: string) => {
|
||||
filtersByParty[party] = mapping.Filters.toObject(filters);
|
||||
});
|
||||
return { filtersByParty: filtersByParty };
|
||||
},
|
||||
toMessage(transactionFilter: ledger.TransactionFilter): grpc.TransactionFilter {
|
||||
const result = new grpc.TransactionFilter();
|
||||
const map = result.getFiltersByPartyMap();
|
||||
Object.keys(transactionFilter.filtersByParty).forEach((party: string) => {
|
||||
map.set(party, mapping.Filters.toMessage(transactionFilter.filtersByParty[party]));
|
||||
});
|
||||
return result;
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const TransactionTree: mapping.Mapping<grpc.TransactionTree, ledger.TransactionTree> = {
|
||||
toObject(message: grpc.TransactionTree): ledger.TransactionTree {
|
||||
const eventsById: Record<string, ledger.TreeEvent> = {};
|
||||
message.getEventsByIdMap().forEach((event, id) => {
|
||||
eventsById[id] = mapping.TreeEvent.toObject(event);
|
||||
});
|
||||
const transactionTree: ledger.TransactionTree = {
|
||||
effectiveAt: mapping.Timestamp.toObject(message.getEffectiveAt()!),
|
||||
eventsById: eventsById,
|
||||
rootEventIds: [...message.getRootEventIdsList()],
|
||||
offset: message.getOffset(),
|
||||
transactionId: message.getTransactionId(),
|
||||
};
|
||||
const commandId = message.getCommandId();
|
||||
if (commandId !== undefined && commandId !== '') {
|
||||
transactionTree.commandId = commandId;
|
||||
}
|
||||
const workflowId = message.getWorkflowId();
|
||||
if (workflowId !== undefined && workflowId !== '') {
|
||||
transactionTree.workflowId = workflowId;
|
||||
}
|
||||
return transactionTree;
|
||||
},
|
||||
toMessage(object: ledger.TransactionTree): grpc.TransactionTree {
|
||||
const message = new grpc.TransactionTree();
|
||||
message.setEffectiveAt(mapping.Timestamp.toMessage(object.effectiveAt));
|
||||
for (const id in object.eventsById) {
|
||||
const event = mapping.TreeEvent.toMessage(object.eventsById[id]);
|
||||
message.getEventsByIdMap().set(id, event);
|
||||
}
|
||||
message.setRootEventIdsList([... object.rootEventIds]);
|
||||
message.setOffset(object.offset);
|
||||
message.setTransactionId(object.transactionId);
|
||||
if (object.commandId) {
|
||||
message.setCommandId(object.commandId);
|
||||
}
|
||||
if (object.workflowId) {
|
||||
message.setWorkflowId(object.workflowId);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
|
||||
export const TreeEvent: mapping.Mapping<grpc.TreeEvent, ledger.TreeEvent> = {
|
||||
toObject(message: grpc.TreeEvent): ledger.TreeEvent {
|
||||
const object: ledger.TreeEvent = {};
|
||||
if (message.hasCreated()) {
|
||||
object.created = mapping.CreatedEvent.toObject(message.getCreated()!);
|
||||
}
|
||||
if (message.hasExercised()) {
|
||||
object.exercised = mapping.ExercisedEvent.toObject(message.getExercised()!);
|
||||
}
|
||||
return object;
|
||||
},
|
||||
toMessage(object: ledger.TreeEvent): grpc.TreeEvent {
|
||||
const message = new grpc.TreeEvent();
|
||||
if (object.created) {
|
||||
message.setCreated(mapping.CreatedEvent.toMessage(object.created));
|
||||
}
|
||||
if (object.exercised) {
|
||||
message.setExercised(mapping.ExercisedEvent.toMessage(object.exercised));
|
||||
}
|
||||
return message;
|
||||
}
|
||||
}
|
@ -1,100 +0,0 @@
|
||||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as mapping from '.';
|
||||
import * as ledger from '..';
|
||||
import * as grpc from 'daml-grpc';
|
||||
import * as protobuf from 'google-protobuf/google/protobuf/empty_pb';
|
||||
|
||||
import { inspect } from 'util';
|
||||
|
||||
export const Value: mapping.Mapping<grpc.Value, ledger.Value> = {
|
||||
toObject(value: grpc.Value): ledger.Value {
|
||||
if (value.hasBool()) {
|
||||
return { bool: value.getBool() }
|
||||
} else if (value.hasContractId()) {
|
||||
return { contractId: value.getContractId() }
|
||||
} else if (value.hasDate()) {
|
||||
return { date: '' + value.getDate() }
|
||||
} else if (value.hasDecimal()) {
|
||||
return { decimal: value.getDecimal() }
|
||||
} else if (value.hasInt64()) {
|
||||
return { int64: value.getInt64() }
|
||||
} else if (value.hasList()) {
|
||||
const values: ledger.Value[] = [];
|
||||
if (value.hasList()) {
|
||||
value.getList()!.getElementsList().forEach(v => {
|
||||
values.push(Value.toObject(v));
|
||||
});
|
||||
}
|
||||
return { list: values }
|
||||
} else if (value.hasParty()) {
|
||||
return { party: value.getParty() }
|
||||
} else if (value.hasRecord()) {
|
||||
return { record: mapping.Record.toObject(value.getRecord()!) }
|
||||
} else if (value.hasText()) {
|
||||
return { text: value.getText() }
|
||||
} else if (value.hasTimestamp()) {
|
||||
return { timestamp: value.getTimestamp() }
|
||||
} else if (value.hasUnit()) {
|
||||
return { unit: {} }
|
||||
} else if (value.hasVariant()) {
|
||||
const variant = value.getVariant()!;
|
||||
const result: ledger.Variant = {
|
||||
constructor: variant.getConstructor(),
|
||||
value: Value.toObject(variant.getValue()!),
|
||||
}
|
||||
if (variant.hasVariantId()) {
|
||||
result.variantId = mapping.Identifier.toObject(variant.getVariantId()!);
|
||||
}
|
||||
return { variant: result }
|
||||
} else if (value.hasOptional()) {
|
||||
return { optional: mapping.Optional.toObject(value.getOptional()!) }
|
||||
} else {
|
||||
throw new Error(`Message Value of unknown type '${inspect(value)}'`);
|
||||
}
|
||||
},
|
||||
toMessage(value: ledger.Value): grpc.Value {
|
||||
const result = new grpc.Value();
|
||||
if (value.bool !== undefined) {
|
||||
result.setBool(value.bool);
|
||||
} else if (value.contractId !== undefined) {
|
||||
result.setContractId(value.contractId);
|
||||
} else if (value.date !== undefined) {
|
||||
result.setDate(parseInt(value.date));
|
||||
} else if (value.decimal !== undefined) {
|
||||
result.setDecimal(value.decimal);
|
||||
} else if (value.int64 !== undefined) {
|
||||
result.setInt64(value.int64);
|
||||
} else if (value.list !== undefined) {
|
||||
const values: grpc.Value[] = []
|
||||
value.list.forEach(v => values.push(Value.toMessage(v)));
|
||||
const list = new grpc.List();
|
||||
list.setElementsList(values);
|
||||
result.setList(list);
|
||||
} else if (value.party !== undefined) {
|
||||
result.setParty(value.party);
|
||||
} else if (value.record !== undefined) {
|
||||
result.setRecord(mapping.Record.toMessage(value.record));
|
||||
} else if (value.text !== undefined) {
|
||||
result.setText(value.text);
|
||||
} else if (value.timestamp !== undefined) {
|
||||
result.setTimestamp(value.timestamp);
|
||||
} else if (value.unit !== undefined) {
|
||||
result.setUnit(new protobuf.Empty());
|
||||
} else if (value.variant !== undefined) {
|
||||
const variant = new grpc.Variant();
|
||||
variant.setConstructor(value.variant.constructor);
|
||||
variant.setValue(Value.toMessage(value.variant.value));
|
||||
if (value.variant.variantId) {
|
||||
variant.setVariantId(mapping.Identifier.toMessage(value.variant.variantId));
|
||||
}
|
||||
result.setVariant(variant);
|
||||
} else if (value.optional) {
|
||||
result.setOptional(mapping.Optional.toMessage(value.optional));
|
||||
} else {
|
||||
throw new Error(`Object Value of unknown type '${inspect(value)}'`);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user