2016-10-31 11:30:57 +00:00
|
|
|
|
.. highlight:: kotlin
|
|
|
|
|
.. raw:: html
|
|
|
|
|
|
|
|
|
|
<script type="text/javascript" src="_static/jquery.js"></script>
|
|
|
|
|
<script type="text/javascript" src="_static/codesets.js"></script>
|
|
|
|
|
|
2017-02-08 10:34:54 +00:00
|
|
|
|
The example CorDapp
|
|
|
|
|
===================
|
2016-10-31 11:30:57 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
.. contents::
|
2017-02-08 10:34:54 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
The example CorDapp allows nodes to agree IOUs with each other. Nodes will always agree to the creation of a new IOU
|
2017-09-22 15:51:32 +00:00
|
|
|
|
if:
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
* Its value is strictly positive
|
|
|
|
|
* The node is not trying to issue the IOU to itself
|
2016-11-29 13:45:58 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
We will deploy the CorDapp on 4 test nodes:
|
2016-12-12 18:48:35 +00:00
|
|
|
|
|
2018-03-02 08:22:25 +00:00
|
|
|
|
* **Notary**, which hosts a validating notary service
|
2017-09-22 15:51:32 +00:00
|
|
|
|
* **PartyA**
|
|
|
|
|
* **PartyB**
|
|
|
|
|
* **PartyC**
|
2016-12-12 18:48:35 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
Because data is only propagated on a need-to-know basis, any IOUs agreed between PartyA and PartyB become "shared
|
|
|
|
|
facts" between PartyA and PartyB only. PartyC won't be aware of these IOUs.
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
Downloading the example CorDapp
|
|
|
|
|
-------------------------------
|
2017-09-22 15:51:32 +00:00
|
|
|
|
We need to download the example CorDapp from GitHub.
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
* Set up your machine by following the :doc:`quickstart guide <getting-set-up>`
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
* Clone the example CorDapp from the `cordapp-example repository <https://github.com/corda/cordapp-example>`_ using
|
|
|
|
|
the following command: ``git clone https://github.com/corda/cordapp-example``
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
* Change directories to the freshly cloned repo: ``cd cordapp-example``
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
.. note:: If you wish to build off the latest, unstable version of the codebase, follow the instructions in
|
2017-09-22 15:51:32 +00:00
|
|
|
|
:doc:`building against Master <building-against-master>` instead.
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
Opening the example CorDapp in IntelliJ
|
|
|
|
|
---------------------------------------
|
2017-09-22 15:51:32 +00:00
|
|
|
|
Let's open the example CorDapp in IntelliJ IDEA.
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
**If opening a fresh IntelliJ instance**
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
* Open IntelliJ
|
|
|
|
|
* A dialogue box will appear:
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
.. image:: resources/intellij-welcome.png
|
|
|
|
|
:width: 400
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
* Click open, navigate to the folder where you cloned the ``cordapp-example``, and click OK
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
* IntelliJ will show several pop-up windows, one of which requires our attention:
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
.. image:: resources/unlinked-gradle-project.png
|
|
|
|
|
:width: 400
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
* Click the 'import gradle project' link. Press OK on the dialogue that pops up
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
* Gradle will now download all the project dependencies and perform some indexing. This usually takes a minute or so.
|
|
|
|
|
|
|
|
|
|
* If the 'import gradle project' pop-up does not appear, click the small green speech bubble at the bottom-right of
|
|
|
|
|
the IDE, or simply close and re-open IntelliJ again to make it reappear.
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
|
|
|
|
**If you already have IntelliJ open**
|
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
* Open the ``File`` menu
|
|
|
|
|
|
|
|
|
|
* Navigate to ``Open ...``
|
|
|
|
|
|
|
|
|
|
* Navigate to the directory where you cloned the ``cordapp-example``
|
|
|
|
|
|
|
|
|
|
* Click OK
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
Project structure
|
|
|
|
|
-----------------
|
|
|
|
|
The example CorDapp has the following directory structure:
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
.. sourcecode:: none
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
.
|
|
|
|
|
├── config
|
|
|
|
|
│ ├── dev
|
|
|
|
|
│ │ └── log4j2.xml
|
|
|
|
|
│ └── test
|
|
|
|
|
│ └── log4j2.xml
|
|
|
|
|
├── doc
|
|
|
|
|
│ └── example_flow.plantuml
|
|
|
|
|
├── gradle
|
|
|
|
|
│ └── wrapper
|
|
|
|
|
│ ├── gradle-wrapper.jar
|
|
|
|
|
│ └── gradle-wrapper.properties
|
2017-09-22 15:51:32 +00:00
|
|
|
|
├── lib
|
|
|
|
|
│ ├── README.txt
|
|
|
|
|
│ └── quasar.jar
|
2017-07-21 11:33:31 +00:00
|
|
|
|
├── java-source
|
|
|
|
|
│ └── ...
|
|
|
|
|
├── kotlin-source
|
|
|
|
|
│ ├── build.gradle
|
|
|
|
|
│ └── src
|
|
|
|
|
│ ├── main
|
|
|
|
|
│ │ ├── kotlin
|
|
|
|
|
│ │ │ └── com
|
|
|
|
|
│ │ │ └── example
|
|
|
|
|
│ │ │ ├── api
|
|
|
|
|
│ │ │ │ └── ExampleApi.kt
|
|
|
|
|
│ │ │ ├── client
|
|
|
|
|
│ │ │ │ └── ExampleClientRPC.kt
|
|
|
|
|
│ │ │ ├── contract
|
|
|
|
|
│ │ │ │ └── IOUContract.kt
|
|
|
|
|
│ │ │ ├── flow
|
|
|
|
|
│ │ │ │ └── ExampleFlow.kt
|
|
|
|
|
│ │ │ ├── model
|
|
|
|
|
│ │ │ │ └── IOU.kt
|
|
|
|
|
│ │ │ ├── plugin
|
|
|
|
|
│ │ │ │ └── ExamplePlugin.kt
|
|
|
|
|
│ │ │ ├── schema
|
|
|
|
|
│ │ │ │ └── IOUSchema.kt
|
|
|
|
|
│ │ │ └── state
|
|
|
|
|
│ │ │ └── IOUState.kt
|
|
|
|
|
│ │ └── resources
|
|
|
|
|
│ │ ├── META-INF
|
|
|
|
|
│ │ │ └── services
|
|
|
|
|
│ │ │ └── net.corda.webserver.services.WebServerPluginRegistry
|
|
|
|
|
│ │ ├── certificates
|
|
|
|
|
│ │ │ ├── readme.txt
|
|
|
|
|
│ │ │ ├── sslkeystore.jks
|
|
|
|
|
│ │ │ └── truststore.jks
|
|
|
|
|
│ │ └── exampleWeb
|
|
|
|
|
│ │ ├── index.html
|
|
|
|
|
│ │ └── js
|
|
|
|
|
│ │ └── angular-module.js
|
|
|
|
|
│ └── test
|
|
|
|
|
│ └── kotlin
|
|
|
|
|
│ └── com
|
|
|
|
|
│ └── example
|
|
|
|
|
│ ├── Main.kt
|
|
|
|
|
│ ├── contract
|
|
|
|
|
│ │ └── IOUContractTests.kt
|
|
|
|
|
│ └── flow
|
|
|
|
|
│ └── IOUFlowTests.kt
|
2017-09-22 15:51:32 +00:00
|
|
|
|
├── .gitignore
|
|
|
|
|
├── LICENCE
|
|
|
|
|
├── README.md
|
|
|
|
|
├── TRADEMARK
|
|
|
|
|
├── build.gradle
|
|
|
|
|
├── gradle.properties
|
|
|
|
|
├── gradlew
|
|
|
|
|
├── gradlew.bat
|
2017-07-21 11:33:31 +00:00
|
|
|
|
└── settings.gradle
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
The key files and directories are as follows:
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
* The **root directory** contains some gradle files, a README and a LICENSE
|
|
|
|
|
* **config** contains log4j configs
|
|
|
|
|
* **gradle** contains the gradle wrapper, which allows the use of Gradle without installing it yourself and worrying
|
|
|
|
|
about which version is required
|
2017-09-22 15:51:32 +00:00
|
|
|
|
* **lib** contains the Quasar jar which rewrites our CorDapp's flows to be checkpointable
|
2017-07-21 11:33:31 +00:00
|
|
|
|
* **kotlin-source** contains the source code for the example CorDapp written in Kotlin
|
|
|
|
|
* **kotlin-source/src/main/kotlin** contains the source code for the example CorDapp
|
|
|
|
|
* **kotlin-source/src/main/resources** contains the certificate store, some static web content to be served by the
|
|
|
|
|
nodes and the WebServerPluginRegistry file
|
|
|
|
|
* **kotlin-source/src/test/kotlin** contains unit tests for the contracts and flows, and the driver to run the nodes
|
|
|
|
|
via IntelliJ
|
2017-09-22 15:51:32 +00:00
|
|
|
|
* **java-source** contains the same source code, but written in Java. CorDapps can be developed in any language
|
|
|
|
|
targeting the JVM
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
Running the example CorDapp
|
|
|
|
|
---------------------------
|
|
|
|
|
There are two ways to run the example CorDapp:
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
* Via the terminal
|
|
|
|
|
* Via IntelliJ
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
In both cases, we will deploy a set of test nodes with our CorDapp installed, then run the nodes. You can read more
|
2017-11-29 17:07:13 +00:00
|
|
|
|
about how we define the nodes to be deployed :doc:`here <generating-a-node>`.
|
2017-09-22 15:51:32 +00:00
|
|
|
|
|
|
|
|
|
Terminal
|
|
|
|
|
~~~~~~~~
|
|
|
|
|
|
|
|
|
|
Building the example CorDapp
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
* Open a terminal window in the ``cordapp-example`` directory
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
* Build the test nodes with our CorDapp using the following command:
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
* Unix/Mac OSX: ``./gradlew deployNodes``
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
* Windows: ``gradlew.bat deployNodes``
|
2016-12-12 18:48:35 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
This will automatically build four pre-configured nodes with our CorDapp installed. These nodes are meant for local
|
|
|
|
|
testing only
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
.. note:: CorDapps can be written in any language targeting the JVM. In our case, we've provided the example source in
|
|
|
|
|
both Kotlin (``/kotlin-source/src``) and Java (``/java-source/src``) Since both sets of source files are
|
|
|
|
|
functionally identical, we will refer to the Kotlin build throughout the documentation.
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
* After the build process has finished, you will see the newly-build nodes in the ``kotlin-source/build/nodes`` folder
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
* There will be one folder generated for each node you built, plus a ``runnodes`` shell script (or batch file on
|
|
|
|
|
Windows) to run all the nodes simultaneously
|
|
|
|
|
|
|
|
|
|
* Each node in the ``nodes`` folder has the following structure:
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
.. sourcecode:: none
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
. nodeName
|
|
|
|
|
├── corda.jar
|
|
|
|
|
├── node.conf
|
2017-10-13 14:01:24 +00:00
|
|
|
|
└── cordapps
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-10-13 14:01:24 +00:00
|
|
|
|
``corda.jar`` is the Corda runtime, ``cordapps`` contains our node's CorDapps, and the node's configuration is
|
2017-09-22 15:51:32 +00:00
|
|
|
|
given by ``node.conf``
|
|
|
|
|
|
|
|
|
|
Running the example CorDapp
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
Start the nodes by running the following command from the root of the ``cordapp-example`` folder:
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
* Unix/Mac OSX: ``kotlin-source/build/nodes/runnodes``
|
|
|
|
|
* Windows: ``call kotlin-source\build\nodes\runnodes.bat``
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
.. warn:: On Unix/Mac OSX, do not click/change focus until all seven additional terminal windows have opened, or some
|
|
|
|
|
nodes may fail to start.
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
For each node, the ``runnodes`` script creates a node tab/window:
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
|
|
|
|
.. sourcecode:: none
|
|
|
|
|
|
2018-03-02 18:05:09 +00:00
|
|
|
|
______ __
|
|
|
|
|
/ ____/ _________/ /___ _
|
|
|
|
|
/ / __ / ___/ __ / __ `/ Top tip: never say "oops", instead
|
|
|
|
|
/ /___ /_/ / / / /_/ / /_/ / always say "Ah, Interesting!"
|
|
|
|
|
\____/ /_/ \__,_/\__,_/
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2018-03-02 18:05:09 +00:00
|
|
|
|
--- Corda Open Source corda-3.0 (4157c25) -----------------------------------------------
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
|
|
|
|
|
2018-03-02 18:05:09 +00:00
|
|
|
|
Logs can be found in : /Users/joeldudley/Desktop/cordapp-example/kotlin-source/build/nodes/PartyA/logs
|
|
|
|
|
Database connection url is : jdbc:h2:tcp://localhost:59472/node
|
2018-05-11 09:06:49 +00:00
|
|
|
|
Incoming connection address : localhost:10007
|
|
|
|
|
Listening on port : 10007
|
2018-03-02 18:05:09 +00:00
|
|
|
|
Loaded CorDapps : corda-finance-corda-3.0, cordapp-example-0.1, corda-core-corda-3.0
|
|
|
|
|
Node for "PartyA" started up and registered in 38.59 sec
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
|
|
|
|
|
2018-03-02 18:05:09 +00:00
|
|
|
|
Welcome to the Corda interactive shell.
|
|
|
|
|
Useful commands include 'help' to see what is available, and 'bye' to shut down the node.
|
2017-07-21 11:33:31 +00:00
|
|
|
|
|
2018-03-02 18:05:09 +00:00
|
|
|
|
Fri Mar 02 17:34:02 GMT 2018>>>
|
2017-07-21 11:33:31 +00:00
|
|
|
|
|
2018-03-02 08:22:25 +00:00
|
|
|
|
For every node except the notary, the script also creates a webserver terminal tab/window:
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
|
|
|
|
.. sourcecode:: none
|
|
|
|
|
|
2018-05-11 09:06:49 +00:00
|
|
|
|
Logs can be found in /Users/username/Desktop/cordapp-example/kotlin-source/build/nodes/PartyA/logs/web
|
|
|
|
|
Starting as webserver: localhost:10009
|
2017-07-21 11:33:31 +00:00
|
|
|
|
Webserver started up in 42.02 sec
|
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
It usually takes around 60 seconds for the nodes to finish starting up. To ensure that all the nodes are running OK,
|
|
|
|
|
you can query the 'status' end-point located at ``http://localhost:[port]/api/status`` (e.g.
|
2018-05-11 09:06:49 +00:00
|
|
|
|
``http://localhost:10009/api/status`` for ``PartyA``).
|
2017-07-21 11:33:31 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
IntelliJ
|
|
|
|
|
~~~~~~~~
|
|
|
|
|
* Select the ``Run Example CorDapp - Kotlin`` run configuration from the drop-down menu at the top right-hand side of
|
|
|
|
|
the IDE
|
2016-10-31 11:30:57 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
* Click the green arrow to start the nodes:
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
.. image:: resources/run-config-drop-down.png
|
|
|
|
|
:width: 400
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
The node driver defined in ``/src/test/kotlin/com/example/Main.kt`` allows you to specify how many nodes you would like
|
|
|
|
|
to run and the configuration settings for each node. For the example CorDapp, the driver starts up four nodes
|
2018-01-25 15:14:32 +00:00
|
|
|
|
and adds an RPC user for all but the network map/notary node:
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
.. sourcecode:: kotlin
|
2017-07-21 11:33:31 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
fun main(args: Array<String>) {
|
|
|
|
|
// No permissions required as we are not invoking flows.
|
|
|
|
|
val user = User("user1", "test", permissions = setOf())
|
2017-11-06 14:24:27 +00:00
|
|
|
|
driver(isDebug = true, waitForNodesToFinish = true) {
|
2018-01-25 15:14:32 +00:00
|
|
|
|
startNode(getX500Name(O="NetworkMapAndNotary",L="London",C='GB"), setOf(ServiceInfo(ValidatingNotaryService.type)))
|
2017-09-22 15:51:32 +00:00
|
|
|
|
val (nodeA, nodeB, nodeC) = Futures.allAsList(
|
|
|
|
|
startNode(getX500Name(O="PartyA",L="London",C="GB"), rpcUsers = listOf(user)),
|
|
|
|
|
startNode(getX500Name(O="PartyB",L="New York",C="US"), rpcUsers = listOf(user)),
|
|
|
|
|
startNode(getX500Name(O="PartyC",L="Paris",C="FR"), rpcUsers = listOf(user))).getOrThrow()
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
startWebserver(nodeA)
|
|
|
|
|
startWebserver(nodeB)
|
|
|
|
|
startWebserver(nodeC)
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
* To stop the nodes, press the red square button at the top right-hand side of the IDE, next to the run configurations
|
2017-07-21 11:33:31 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
Later, we'll look at how the node driver can be useful for `debugging your CorDapp`_.
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-02-08 10:34:54 +00:00
|
|
|
|
Interacting with the example CorDapp
|
|
|
|
|
------------------------------------
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2016-12-12 18:48:35 +00:00
|
|
|
|
Via HTTP
|
2017-01-06 11:05:37 +00:00
|
|
|
|
~~~~~~~~
|
2017-09-22 15:51:32 +00:00
|
|
|
|
The CorDapp defines several HTTP API end-points and a web front-end. The end-points allow you to list the IOUs a node
|
|
|
|
|
is involved in, agree new IOUs, and see who is on the network.
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
The nodes are running locally on the following ports:
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2018-05-11 09:06:49 +00:00
|
|
|
|
* PartyA: ``localhost:10009``
|
|
|
|
|
* PartyB: ``localhost:10012``
|
|
|
|
|
* PartyC: ``localhost:10015``
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
These ports are defined in build.gradle and in each node's node.conf file under ``kotlin-source/build/nodes/NodeX``.
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
As the nodes start up, they should tell you which port their embedded web server is running on. The available API
|
|
|
|
|
endpoints are:
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2016-11-29 13:45:58 +00:00
|
|
|
|
* ``/api/example/me``
|
|
|
|
|
* ``/api/example/peers``
|
2017-02-08 10:34:54 +00:00
|
|
|
|
* ``/api/example/ious``
|
2017-09-25 16:01:14 +00:00
|
|
|
|
* ``/api/example/create-iou`` with parameters ``iouValue`` and ``partyName`` which is CN name of a node
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
The web front-end is served from ``/web/example``.
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
An IOU can be created by sending a PUT request to the ``api/example/create-iou`` end-point directly, or by using the
|
2016-11-17 18:31:17 +00:00
|
|
|
|
the web form hosted at ``/web/example``.
|
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
.. warning:: The content in ``web/example`` is only available for demonstration purposes and does not implement
|
|
|
|
|
anti-XSS, anti-XSRF or any other security techniques. Do not use this code in production.
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
Creating an IOU via the endpoint
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
To create an IOU between PartyA and PartyB, run the following command from the command line:
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
|
|
|
|
.. sourcecode:: bash
|
|
|
|
|
|
2018-05-11 09:06:49 +00:00
|
|
|
|
curl -X PUT 'http://localhost:10009/api/example/create-iou?iouValue=1&partyName=O=PartyB,L=New%20York,C=US'
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2018-05-11 09:06:49 +00:00
|
|
|
|
Note that both PartyA's port number (``10009``) and PartyB are referenced in the PUT request path. This command
|
2017-09-22 15:51:32 +00:00
|
|
|
|
instructs PartyA to agree an IOU with PartyB. Once the process is complete, both nodes will have a signed, notarised
|
|
|
|
|
copy of the IOU. PartyC will not.
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
Submitting an IOU via the web front-end
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
To create an IOU between PartyA and PartyB, navigate to ``/web/example``, click the "create IOU" button at the top-left
|
|
|
|
|
of the page, and enter the IOU details into the web-form. The IOU must have a positive value. For example:
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
|
|
|
|
.. sourcecode:: none
|
|
|
|
|
|
|
|
|
|
Counter-party: Select from list
|
2017-07-21 11:33:31 +00:00
|
|
|
|
Value (Int): 5
|
2017-02-08 10:34:54 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
And click submit. Upon clicking submit, the modal dialogue will close, and the nodes will agree the IOU.
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
Once an IOU has been submitted
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
Assuming all went well, you should see some activity in PartyA's web-server terminal window:
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
|
|
|
|
.. sourcecode:: none
|
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
>> Signing transaction with our private key.
|
|
|
|
|
>> Gathering the counterparty's signature.
|
2018-03-06 16:10:48 +00:00
|
|
|
|
>> Collecting signatures from counterparties.
|
2017-09-22 15:51:32 +00:00
|
|
|
|
>> Verifying collected signatures.
|
|
|
|
|
>> Done
|
|
|
|
|
>> Obtaining notary signature and recording transaction.
|
|
|
|
|
>> Requesting signature by notary service
|
|
|
|
|
>> Broadcasting transaction to participants
|
|
|
|
|
>> Done
|
|
|
|
|
>> Done
|
|
|
|
|
|
|
|
|
|
You can view the newly-created IOU by accessing the vault of PartyA or PartyB:
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
*Via the HTTP API:*
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2018-05-11 09:06:49 +00:00
|
|
|
|
* PartyA's vault: Navigate to http://localhost:10009/api/example/ious
|
|
|
|
|
* PartyB's vault: Navigate to http://localhost:10012/api/example/ious
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
*Via web/example:*
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2018-05-11 09:06:49 +00:00
|
|
|
|
* PartyA: Navigate to http://localhost:10009/web/example and hit the "refresh" button
|
|
|
|
|
* PartyA: Navigate to http://localhost:10012/web/example and hit the "refresh" button
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2018-05-11 09:06:49 +00:00
|
|
|
|
The vault and web front-end of PartyC (at ``localhost:10015``) will not display any IOUs. This is because PartyC was
|
2017-09-22 15:51:32 +00:00
|
|
|
|
not involved in this transaction.
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
Via the interactive shell (terminal only)
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2017-09-22 15:51:32 +00:00
|
|
|
|
Nodes started via the terminal will display an interactive shell:
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
.. sourcecode:: none
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
Welcome to the Corda interactive shell.
|
|
|
|
|
Useful commands include 'help' to see what is available, and 'bye' to shut down the node.
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
Fri Jul 07 16:36:29 BST 2017>>>
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
Type ``flow list`` in the shell to see a list of the flows that your node can run. In our case, this will return the
|
|
|
|
|
following list:
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
.. sourcecode:: none
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
com.example.flow.ExampleFlow$Initiator
|
|
|
|
|
net.corda.core.flows.ContractUpgradeFlow$Initiator
|
|
|
|
|
net.corda.core.flows.ContractUpgradeFlow$Initiator
|
|
|
|
|
net.corda.finance.flows.CashExitFlow
|
|
|
|
|
net.corda.finance.flows.CashIssueAndPaymentFlow
|
|
|
|
|
net.corda.finance.flows.CashIssueFlow
|
|
|
|
|
net.corda.finance.flows.CashPaymentFlow
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
We can create a new IOU using the ``ExampleFlow$Initiator`` flow. For example, from the interactive shell of PartyA,
|
|
|
|
|
you can agree an IOU of 50 with PartyB by running
|
|
|
|
|
``flow start ExampleFlow$Initiator iouValue: 50, otherParty: "O=PartyB,L=New York,C=US"``.
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
This will print out the following progress steps:
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
.. sourcecode:: none
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
✅ Generating transaction based on new IOU.
|
|
|
|
|
✅ Verifying contract constraints.
|
|
|
|
|
✅ Signing transaction with our private key.
|
|
|
|
|
✅ Gathering the counterparty's signature.
|
2018-03-06 16:10:48 +00:00
|
|
|
|
✅ Collecting signatures from counterparties.
|
2017-07-21 11:33:31 +00:00
|
|
|
|
✅ Verifying collected signatures.
|
|
|
|
|
✅ Obtaining notary signature and recording transaction.
|
|
|
|
|
✅ Requesting signature by notary service
|
|
|
|
|
Requesting signature by Notary service
|
|
|
|
|
Validating response from Notary service
|
|
|
|
|
✅ Broadcasting transaction to participants
|
|
|
|
|
✅ Done
|
2016-11-17 18:31:17 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
We can also issue RPC operations to the node via the interactive shell. Type ``run`` to see the full list of available
|
|
|
|
|
operations.
|
2016-10-31 11:30:57 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
Via the h2 web console
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
You can connect directly to your node's database to see its stored states, transactions and attachments. To do so,
|
|
|
|
|
please follow the instructions in :doc:`node-database`.
|
2016-10-31 11:30:57 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
Using the example RPC client
|
2017-01-06 11:05:37 +00:00
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2017-07-21 11:33:31 +00:00
|
|
|
|
The ``/src/main/kotlin-source/com/example/client/ExampleClientRPC.kt`` file is a simple utility that uses the client
|
|
|
|
|
RPC library to connect to a node. It will log any existing IOUs and listen for any future IOUs. If you haven't created
|
|
|
|
|
any IOUs when you first connect to one of the nodes, the client will simply log any future IOUs that are agreed.
|
2016-10-31 11:30:57 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
*Running the client via IntelliJ:*
|
2016-10-31 11:30:57 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
Select the 'Run Example RPC Client' run configuration which, by default, connects to PartyA. Click the green arrow to
|
|
|
|
|
run the client. You can edit the run configuration to connect on a different port.
|
2016-10-31 11:30:57 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
*Running the client via the command line:*
|
2016-10-31 11:30:57 +00:00
|
|
|
|
|
2016-11-17 18:31:17 +00:00
|
|
|
|
Run the following gradle task:
|
2016-10-31 11:30:57 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
``./gradlew runExampleClientRPCKotlin``
|
|
|
|
|
|
|
|
|
|
This will connect the RPC client to PartyA and log their past and future IOU activity.
|
2017-07-21 11:33:31 +00:00
|
|
|
|
|
|
|
|
|
You can close the application using ``ctrl+C``.
|
2016-10-31 11:30:57 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
For more information on the client RPC interface and how to build an RPC client application, see:
|
2016-10-31 15:52:10 +00:00
|
|
|
|
|
2016-11-17 18:31:17 +00:00
|
|
|
|
* :doc:`Client RPC documentation <clientrpc>`
|
|
|
|
|
* :doc:`Client RPC tutorial <tutorial-clientrpc-api>`
|
2016-10-31 11:30:57 +00:00
|
|
|
|
|
2016-12-12 18:48:35 +00:00
|
|
|
|
Running Nodes Across Machines
|
2017-07-21 11:33:31 +00:00
|
|
|
|
-----------------------------
|
2018-03-02 08:22:25 +00:00
|
|
|
|
The nodes can be split across different machines and configured to communicate across the network.
|
2016-12-12 18:48:35 +00:00
|
|
|
|
|
2018-03-02 08:22:25 +00:00
|
|
|
|
After deploying the nodes, navigate to the build folder (``kotlin-source/build/nodes``) and for each node that needs to
|
|
|
|
|
be moved to another machine open its config file and change the Artemis messaging address to the IP address of the machine
|
2018-05-11 09:06:49 +00:00
|
|
|
|
where the node will run (e.g. ``p2pAddress="10.18.0.166:10007"``).
|
2016-12-12 18:48:35 +00:00
|
|
|
|
|
2018-03-02 08:22:25 +00:00
|
|
|
|
These changes require new node-info files to be distributed amongst the nodes. Use the network bootstrapper tool
|
|
|
|
|
(see :doc:`setting-up-a-corda-network` for more information on this and how to built it) to update the files and have
|
|
|
|
|
them distributed locally.
|
2016-12-12 18:48:35 +00:00
|
|
|
|
|
2018-03-02 08:22:25 +00:00
|
|
|
|
``java -jar network-bootstrapper.jar kotlin-source/build/nodes``
|
2016-12-12 18:48:35 +00:00
|
|
|
|
|
2018-03-02 08:22:25 +00:00
|
|
|
|
Once that's done move the node folders to their designated machines (e.g. using a USB key). It is important that none of the
|
|
|
|
|
nodes - including the notary - end up on more than one machine. Each computer should also have a copy of ``runnodes``
|
|
|
|
|
and ``runnodes.bat``.
|
2016-12-12 18:48:35 +00:00
|
|
|
|
|
2018-03-02 08:22:25 +00:00
|
|
|
|
For example, you may end up with the following layout:
|
|
|
|
|
|
|
|
|
|
* Machine 1: ``Notary``, ``PartyA``, ``runnodes``, ``runnodes.bat``
|
|
|
|
|
* Machine 2: ``PartyB``, ``PartyC``, ``runnodes``, ``runnodes.bat``
|
2016-12-12 18:48:35 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
After starting each node, the nodes will be able to see one another and agree IOUs among themselves.
|
2016-12-12 18:48:35 +00:00
|
|
|
|
|
2016-11-17 18:31:17 +00:00
|
|
|
|
Debugging your CorDapp
|
2017-07-21 11:33:31 +00:00
|
|
|
|
----------------------
|
|
|
|
|
Debugging is done via IntelliJ as follows:
|
2016-10-31 15:52:10 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
1. Edit the node driver code in ``Main.kt`` based on the number of nodes you wish to start, along with any other
|
|
|
|
|
configuration options. For example, the code below starts 4 nodes, with one being the network map service and
|
|
|
|
|
notary. It also sets up RPC credentials for the three non-notary nodes
|
2016-10-31 15:52:10 +00:00
|
|
|
|
|
|
|
|
|
.. sourcecode:: kotlin
|
|
|
|
|
|
2016-11-17 18:31:17 +00:00
|
|
|
|
fun main(args: Array<String>) {
|
|
|
|
|
// No permissions required as we are not invoking flows.
|
|
|
|
|
val user = User("user1", "test", permissions = setOf())
|
2017-11-06 14:24:27 +00:00
|
|
|
|
driver(isDebug = true, waitForNodesToFinish = true) {
|
2018-01-25 15:14:32 +00:00
|
|
|
|
startNode(getX500Name(O="NetworkMapAndNotary",L="London",C="GB"), setOf(ServiceInfo(ValidatingNotaryService.type)))
|
2017-07-21 11:33:31 +00:00
|
|
|
|
val (nodeA, nodeB, nodeC) = Futures.allAsList(
|
2017-09-22 15:51:32 +00:00
|
|
|
|
startNode(getX500Name(O="PartyA",L=London,C=GB"), rpcUsers = listOf(user)),
|
|
|
|
|
startNode(getX500Name(O="PartyB",L=New York,C=US"), rpcUsers = listOf(user)),
|
|
|
|
|
startNode(getX500Name(O="PartyC",L=Paris,C=FR"), rpcUsers = listOf(user))).getOrThrow()
|
2017-07-21 11:33:31 +00:00
|
|
|
|
|
|
|
|
|
startWebserver(nodeA)
|
|
|
|
|
startWebserver(nodeB)
|
|
|
|
|
startWebserver(nodeC)
|
|
|
|
|
}
|
2016-11-17 18:31:17 +00:00
|
|
|
|
}
|
2016-10-31 15:52:10 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
2. Select and run the “Run Example CorDapp” run configuration in IntelliJ
|
2017-09-22 15:51:32 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
3. IntelliJ will build and run the CorDapp. The remote debug ports for each node will be automatically generated and
|
|
|
|
|
printed to the terminal. For example:
|
2016-10-31 15:52:10 +00:00
|
|
|
|
|
2016-11-17 18:31:17 +00:00
|
|
|
|
.. sourcecode:: none
|
2016-10-31 15:52:10 +00:00
|
|
|
|
|
2017-09-22 15:51:32 +00:00
|
|
|
|
[INFO ] 15:27:59.533 [main] Node.logStartupInfo - Working Directory: /Users/joeldudley/cordapp-example/build/20170707142746/PartyA
|
2017-07-21 11:33:31 +00:00
|
|
|
|
[INFO ] 15:27:59.533 [main] Node.logStartupInfo - Debug port: dt_socket:5007
|
2016-10-31 15:52:10 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
4. Edit the “Debug CorDapp” run configuration with the port of the node you wish to connect to
|
2017-09-22 15:51:32 +00:00
|
|
|
|
|
2017-07-21 11:33:31 +00:00
|
|
|
|
5. Run the “Debug CorDapp” run configuration
|
2017-09-22 15:51:32 +00:00
|
|
|
|
|
|
|
|
|
6. Set your breakpoints and start interacting with the node you wish to connect to. When the node hits a breakpoint,
|
|
|
|
|
execution will pause
|