mirror of
https://github.com/corda/corda.git
synced 2025-01-22 04:18:31 +00:00
Updated RPC Tutorial docs and gradle file.
This commit is contained in:
parent
3a353cb7f4
commit
b4f7dfdf24
@ -1,11 +1,6 @@
|
|||||||
apply plugin: 'kotlin'
|
apply plugin: 'kotlin'
|
||||||
apply plugin: 'application'
|
apply plugin: 'application'
|
||||||
|
apply plugin: 'net.corda.plugins.cordformation'
|
||||||
buildscript {
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
@ -35,9 +30,9 @@ dependencies {
|
|||||||
compile("org.graphstream:gs-ui:1.3") {
|
compile("org.graphstream:gs-ui:1.3") {
|
||||||
exclude group: "bouncycastle"
|
exclude group: "bouncycastle"
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
mainClassName = "net.corda.docs.ClientRpcTutorialKt"
|
runtime "net.corda:corda:$corda_version"
|
||||||
|
}
|
||||||
|
|
||||||
task getClientRpcTutorial(type: CreateStartScripts) {
|
task getClientRpcTutorial(type: CreateStartScripts) {
|
||||||
dependsOn(classes)
|
dependsOn(classes)
|
||||||
@ -52,3 +47,31 @@ applicationDistribution.into("bin") {
|
|||||||
from(getClientRpcTutorial)
|
from(getClientRpcTutorial)
|
||||||
fileMode = 0755
|
fileMode = 0755
|
||||||
}
|
}
|
||||||
|
|
||||||
|
task deployNodes(type: net.corda.plugins.Cordform, dependsOn: [':install', 'build']) {
|
||||||
|
directory "./build/nodes"
|
||||||
|
networkMap "Notary"
|
||||||
|
node {
|
||||||
|
name "Notary"
|
||||||
|
dirName "notary"
|
||||||
|
nearestCity "London"
|
||||||
|
advertisedServices = ["corda.notary.validating"]
|
||||||
|
artemisPort 10002
|
||||||
|
webPort 10003
|
||||||
|
cordapps = []
|
||||||
|
}
|
||||||
|
node {
|
||||||
|
name "Alice"
|
||||||
|
dirName "alice"
|
||||||
|
nearestCity "London"
|
||||||
|
advertisedServices = []
|
||||||
|
artemisPort 10004
|
||||||
|
webPort 10005
|
||||||
|
cordapps = []
|
||||||
|
rpcUsers = [
|
||||||
|
['user' : "user",
|
||||||
|
'password' : "password",
|
||||||
|
'permissions' : ["StartFlow.net.corda.flows.CashFlow"]]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
@ -32,9 +32,13 @@ We start generating transactions in a different thread (``generateTransactions``
|
|||||||
:start-after: interface CordaRPCOps
|
:start-after: interface CordaRPCOps
|
||||||
:end-before: }
|
:end-before: }
|
||||||
|
|
||||||
|
.. warning:: This API is evolving and will continue to grow as new functionality and features added to Corda are made
|
||||||
|
available to RPC clients.
|
||||||
|
|
||||||
The one we need in order to dump the transaction graph is ``verifiedTransactions``. The type signature tells us that the
|
The one we need in order to dump the transaction graph is ``verifiedTransactions``. The type signature tells us that the
|
||||||
RPC will return a list of transactions and an Observable stream. This is a general pattern, we query some data and the
|
RPC will return a list of transactions and an Observable stream. This is a general pattern, we query some data and the
|
||||||
node will return the current snapshot and future updates done to it.
|
node will return the current snapshot and future updates done to it. Observables are described in further detail in
|
||||||
|
:doc:`clientrpc`
|
||||||
|
|
||||||
.. literalinclude:: example-code/src/main/kotlin/net/corda/docs/ClientRpcTutorial.kt
|
.. literalinclude:: example-code/src/main/kotlin/net/corda/docs/ClientRpcTutorial.kt
|
||||||
:language: kotlin
|
:language: kotlin
|
||||||
@ -67,8 +71,11 @@ The RPC we need to initiate a Cash transaction is ``startProtocolDynamic`` which
|
|||||||
Finally we have everything in place: we start a couple of nodes, connect to them, and start creating transactions while listening on successfully created ones, which are dumped to the console. We just need to run it!:
|
Finally we have everything in place: we start a couple of nodes, connect to them, and start creating transactions while listening on successfully created ones, which are dumped to the console. We just need to run it!:
|
||||||
|
|
||||||
# Build the example
|
# Build the example
|
||||||
|
|
||||||
./gradlew docs/source/example-code:installDist
|
./gradlew docs/source/example-code:installDist
|
||||||
|
|
||||||
# Start it
|
# Start it
|
||||||
|
|
||||||
./docs/source/example-code/build/install/docs/source/example-code/bin/client-rpc-tutorial Print
|
./docs/source/example-code/build/install/docs/source/example-code/bin/client-rpc-tutorial Print
|
||||||
|
|
||||||
Now let's try to visualise the transaction graph. We will use a graph drawing library called graphstream_
|
Now let's try to visualise the transaction graph. We will use a graph drawing library called graphstream_
|
||||||
@ -81,7 +88,7 @@ Now let's try to visualise the transaction graph. We will use a graph drawing li
|
|||||||
If we run the client with ``Visualise`` we should see a simple random graph being drawn as new transactions are being created.
|
If we run the client with ``Visualise`` we should see a simple random graph being drawn as new transactions are being created.
|
||||||
|
|
||||||
Registering classes from your Cordapp with RPC Kryo
|
Registering classes from your Cordapp with RPC Kryo
|
||||||
--------------------------------------------------
|
---------------------------------------------------
|
||||||
|
|
||||||
As described in :doc:`clientrpc`, you currently have to register any additional classes you add that are needed in RPC
|
As described in :doc:`clientrpc`, you currently have to register any additional classes you add that are needed in RPC
|
||||||
requests or responses with the `Kryo` instance RPC uses. Here's an example of how you do this for an example class.
|
requests or responses with the `Kryo` instance RPC uses. Here's an example of how you do this for an example class.
|
||||||
@ -95,3 +102,47 @@ See more on plugins in :doc:`creating-a-cordapp`.
|
|||||||
|
|
||||||
.. warning:: We will be replacing the use of Kryo in RPC with a stable message format and this will mean that this plugin
|
.. warning:: We will be replacing the use of Kryo in RPC with a stable message format and this will mean that this plugin
|
||||||
customisation point will either go away completely or change.
|
customisation point will either go away completely or change.
|
||||||
|
|
||||||
|
Security
|
||||||
|
--------
|
||||||
|
RPC credentials associated with a Client must match the permission set configured on the server Node.
|
||||||
|
This refers to both authentication (username and password) and role-based authorisation (the set of flows an
|
||||||
|
authenticated user is entitled to run).
|
||||||
|
|
||||||
|
In the instructions above the server node permissions are configured programmatically in the driver code:
|
||||||
|
|
||||||
|
.. code-block:: text
|
||||||
|
|
||||||
|
driver(driverDirectory = baseDirectory) {
|
||||||
|
val user = User("user", "password", permissions = setOf(startProtocolPermission<CashProtocol>()))
|
||||||
|
val node = startNode("Alice", rpcUsers = listOf(user)).get()
|
||||||
|
|
||||||
|
When starting a standalone node using a configuration file we must supply the RPC credentials as follows:
|
||||||
|
|
||||||
|
.. code-block:: text
|
||||||
|
|
||||||
|
rpcUsers : [
|
||||||
|
{ user=user, password=password, permissions=[ StartFlow.net.corda.flows.CashFlow ] }
|
||||||
|
]
|
||||||
|
|
||||||
|
When using the gradle Cordformation plugin to configure and deploy a node you must supply the RPC credentials in a similar manner:
|
||||||
|
|
||||||
|
.. code-block:: text
|
||||||
|
|
||||||
|
rpcUsers = [
|
||||||
|
['user' : "user",
|
||||||
|
'password' : "password",
|
||||||
|
'permissions' : ["StartFlow.net.corda.flows.CashFlow"]]
|
||||||
|
]
|
||||||
|
|
||||||
|
You can then deploy and launch the nodes (Notary and Alice) as follows:
|
||||||
|
|
||||||
|
1. Run ``./gradlew docs/source/example-code:deployNodes`` to create a set of configs and installs under ``docs/source/example-code/build/nodes``
|
||||||
|
2. Run ``./docs/source/example-code/build/nodes/runnodes`` (or ``runnodes.bat`` on Windows) to open up two new terminals with the two nodes.
|
||||||
|
|
||||||
|
followed by the same commands as before:
|
||||||
|
3. ./docs/source/example-code/build/install/docs/source/example-code/bin/client-rpc-tutorial Print
|
||||||
|
4. ./docs/source/example-code/build/install/docs/source/example-code/bin/client-rpc-tutorial Visualise
|
||||||
|
|
||||||
|
See more on security in :doc:`secure-coding-guidelines`, node configuration in :doc:`corda-configuration-files` and
|
||||||
|
Cordformation in doc:`creating-a-cordapp`
|
||||||
|
Loading…
Reference in New Issue
Block a user