LoginSignup
3
4

More than 3 years have passed since last update.

Cordaで特定ノードを起動する

Last updated at Posted at 2019-06-27

2020/09/30 追記

RPCのページが404になっていたので、リンクの貼り直しを実施。

本編

どーも、のぶこふです。
今回の記事はライトに、特定ノードの起動方法について記述します。

「Cordaとは」「Cordaのインストール・セットアップ」等については、省略させていただきます。

特定ノードを起動する

公式ドキュメントでは、このページの内容になります。

確認するよ
$ pwd
/cordapp-template-kotlin
$ ll
total 88
-rw-r--r--  1 nobkovskii  staff   579  6 13 16:32 LICENCE
-rw-r--r--  1 nobkovskii  staff  4798  6 13 16:32 README.md
-rw-r--r--  1 nobkovskii  staff   232  6 13 16:32 TRADEMARK
drwxr-xr-x  7 nobkovskii  staff   224  6 27 12:08 build
-rw-r--r--  1 nobkovskii  staff  4289  6 27 12:07 build.gradle
drwxr-xr-x  5 nobkovskii  staff   160  6 27 12:07 clients
drwxr-xr-x  4 nobkovskii  staff   128  6 13 16:32 config
drwxr-xr-x  5 nobkovskii  staff   160  6 27 12:07 contracts
drwxr-xr-x  3 nobkovskii  staff    96  6 13 16:32 gradle
-rw-r--r--  1 nobkovskii  staff    65  6 13 16:32 gradle.properties
-rwxr-xr-x  1 nobkovskii  staff  5296  6 13 16:32 gradlew
-rw-r--r--  1 nobkovskii  staff  2176  6 13 16:32 gradlew.bat
drwxr-xr-x  3 nobkovskii  staff    96  6 13 16:34 logs
-rw-r--r--  1 nobkovskii  staff    57  6 13 16:32 settings.gradle
drwxr-xr-x  5 nobkovskii  staff   160  6 27 12:07 workflows
ノードをデプロイするよ
$ ./gradlew clean deployNodes
〜〜〜〜〜〜〜 諸々 〜〜〜〜〜〜〜〜〜〜
BUILD SUCCESSFUL in 40s
18 actionable tasks: 17 executed, 1 up-to-date
起動したいノードのディレクトリに移動するよ
$ cd build/nodes/PartyA/
$ ll
total 130784
drwxr-xr-x  6 nobkovskii  staff       192  6 27 12:25 additional-node-infos
drwxr-xr-x  5 nobkovskii  staff       160  6 27 12:25 certificates
-rwxr-xr-x  1 nobkovskii  staff  63718634  6 27 12:25 corda.jar
drwxr-xr-x  5 nobkovskii  staff       160  6 27 12:25 cordapps
drwxr-xr-x  3 nobkovskii  staff        96  6 27 12:25 drivers
drwxr-xr-x  4 nobkovskii  staff       128  6 27 12:25 logs
-rw-r--r--  1 nobkovskii  staff      4498  6 27 12:25 network-parameters
-rw-r--r--  1 nobkovskii  staff       474  6 27 12:25 node.conf
-rw-r--r--  1 nobkovskii  staff      4689  6 27 12:25 nodeInfo-E4477B559304AADFC0638772C0956A38FA2E2A7A5EB0E65D0D83E5884831879A
-rw-r--r--  1 nobkovskii  staff   2560000  6 27 12:25 persistence.mv.db
-rw-r--r--  1 nobkovskii  staff      8021  6 27 12:25 persistence.trace.db
ノードを起動するよ
$ java -jar corda.jar 

   ______               __
  / ____/     _________/ /___ _
 / /     __  / ___/ __  / __ `/         Kind of like a regular database but
/ /___  /_/ / /  / /_/ / /_/ /          with emojis, colours and ascii art. 😎  
\____/     /_/   \__,_/\__,_/

--- Corda Open Source 4.0 (503a2ff) -------------------------------------------------------------


Logs can be found in                    : /cordapp-template-kotlin/build/nodes/PartyA/logs
⚠️   ATTENTION: This node is running in development mode! 👩‍💻   This is not safe for production deployment.
Advertised P2P messaging addresses      : localhost:10005
RPC connection address                  : localhost:10006
RPC admin connection address            : localhost:10046
Loaded 2 CorDapp(s)                     : Contract CorDapp: Template CorDapp version 1 by vendor Corda Open Source with licence Apache License, Version 2.0, Workflow CorDapp: Template Flows version 1 by vendor Corda Open Source with licence Apache License, Version 2.0
Node for "PartyA" started up and registered in 8.82 sec


Welcome to the Corda interactive shell.
Useful commands include 'help' to see what is available, and 'bye' to shut down the node.

Thu Jun 27 12:29:33 JST 2019>>>  

特定ノードの起動は以上です。

ノードでいろいろやってみる

RPCを使用して、ノードに問合せを行えます。
提供されている関数一覧はこのページにあります。

ノードシェルの例だよ
>>> help
Try one of these commands with the -h or --help switch:                                                                                                   

NAME          DESCRIPTION                                                                                                                                 
bye           Exits, same as exit.                                                                                                                        
dashboard     a monitoring dashboard                                                                                                                      
egrep         search file(s) for lines that match a pattern                                                                                               
env           display the term env                                                                                                                        
exit          Exits.                                                                                                                                      
filter        a filter for a stream of map                                                                                                                
flow          Commands to work with flows. Flows are how you can change the ledger.                                                                       
hashLookup    Checks if a transaction with matching Id hash exists.                                                                                       
help          provides basic help                                                                                                                         
java          various java language commands                                                                                                              
jdbc          JDBC connection                                                                                                                             
jndi          Java Naming and Directory Interface                                                                                                         
jpa           Java persistance API                                                                                                                        
jul           java.util.logging commands                                                                                                                  
jvm           JVM information                                                                                                                             
less          opposite of more                                                                                                                            
man           format and display the on-line manual pages                                                                                                 
output-format Commands to inspect and update the output format.                                                                                           
repl          list the repl or change the current repl                                                                                                    
run           Runs a method from the CordaRPCOps interface on the node.                                                                                   
shell         shell related command                                                                                                                       
sleep         sleep for some time                                                                                                                         
sort          sort a map                                                                                                                                  
start         An alias for 'flow start'                                                                                                                   
system        vm system properties commands                                                                                                               
thread        JVM thread commands                 

>>> flow list
com.template.flows.Hoge
com.template.flows.Initiator
net.corda.core.flows.ContractUpgradeFlow$Authorise
net.corda.core.flows.ContractUpgradeFlow$Deauthorise
net.corda.core.flows.ContractUpgradeFlow$Initiate

>>> run vaultQuery contractStateType: com.template.states.TemplateState                                   
states: []
statesMetadata: []
totalStatesAvailable: -1
stateTypes: "UNCONSUMED"
otherResults: []

>>> run networkMapSnapshot
- addresses:
  - "localhost:10005"
  legalIdentitiesAndCerts:
  - "O=PartyA, L=London, C=GB"
  platformVersion: 4
  serial: 1561605953758
- addresses:
  - "localhost:10002"
  legalIdentitiesAndCerts:
  - "O=Notary, L=London, C=GB"
  platformVersion: 4
  serial: 1561605950491
- addresses:
  - "localhost:10011"
  legalIdentitiesAndCerts:
  - "O=PartyC, L=Tokyo, C=JP"
  platformVersion: 4
  serial: 1561605953606
- addresses:
  - "localhost:10008"
  legalIdentitiesAndCerts:
  - "O=PartyB, L=New York, C=US"
  platformVersion: 4
  serial: 1561605953669

>>> run nodeInfoFromParty party : "PartyA"
addresses:
- "localhost:10005"
legalIdentitiesAndCerts:
- "O=PartyA, L=London, C=GB"
platformVersion: 4
serial: 1561605953758

>>> run wellKnownPartyFromAnonymous party : "Notary"                   
"O=Notary, L=London, C=GB"

上記方法で複数のノードを起動して、IOUを発行する

少し見づらいですが、別ターミナルでPartyAとPartyBを上記方法で起動してみます。
※実行しているFlowは前前前回あたりの「Corda-Tutorial_HelloWorld pt2」を参照してください

複数のノードを起動して、flow_watchを確認するよ
+--------+--------------------
| PartyA |
+--------+
$ java -jar corda.jar 
+--------+--------------------
| PartyB |
+--------+
$ java -jar corda.jar 
>>> flow watch
+--------+--------------------
| PartyA |
+--------+
>>>  flow start Hoge value : 100 , otherParty : "PartyB"

 ✅   Starting
          Requesting signature by notary service
              Requesting signature by Notary service
              Validating response from Notary service
     ✅   Broadcasting transaction to participants
➡️   Done
Flow completed with result: kotlin.Unit
+--------+--------------------
| PartyB |
+--------+
Id               Flow name                        Initiator       Status                           
---------------------------------------------------------------------------------------------------
5e32759a-0d9c-44 Foo                              O=PartyA, L=Lon In progress                      
499d4584-090a-43 Foo                              O=PartyA, L=Lon In progress                      
b3699c03-4b17-4c Foo                              O=PartyA, L=Lon No return value                  
Waiting for completion or Ctrl-C ... 

+--------+
| Ctrl-C |
+--------+

>>> run vaultQuery contractStateType: com.template.states.MyState 
states:
- state:
    data: !<com.template.states.MyState>
      value: 100
      lender: "O=PartyA, L=London, C=GB"
      borrower: "O=PartyB, L=New York, C=US"
    contract: "com.template.contracts.MyContract"
    notary: "O=Notary, L=London, C=GB"
    encumbrance: null
    constraint: !<net.corda.core.contracts.SignatureAttachmentConstraint>
      key: "aSq9DsNNvGhYxYyqA9wd2eduEAZ5AXWgJTbTEw3G5d2maAq8vtLE4kZHgCs5jcB1N31cx1hpsLeqG2ngSysVHqcXhbNts6SkRWDaV7xNcr6MtcbufGUchxredBb6"
  ref:
    txhash: "D62E4C3B6D52113A6103E796558468C07684A37C316AC2629A2344D7F37CDE85"
    index: 0

別タブ実行のイメージ↓
image.png

おわり

それとなく、Cordaの使い方がわかってきました。
そろそろ、もうちょいユースケースに沿って実装していきたい今日このごろ。

今回は以上です。
ありがとうございました。

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4