corda: developer experience – windows w/ git bash · pdf filecorda: developer experience...

34
1 Corda: Developer Experience – Windows w/ Git bash Clemens Wan Quick Start Guide

Upload: vanquynh

Post on 26-Mar-2018

241 views

Category:

Documents


5 download

TRANSCRIPT

1

Corda:DeveloperExperience–Windowsw/Gitbash

ClemensWan

QuickStartGuide

2

ContentsPre-reqInstallations................................................................................................................................................................................................................................3

CorDappTemplate(workingprototype).................................................................................................................................................................................................7

Installongit-bash................................................................................................................................................................................................................................7

Cordaothersamples(SNAPSHOTrelease)............................................................................................................................................................................................12

CloningCorda....................................................................................................................................................................................................................................12

Viacommand-line(gitbash).............................................................................................................................................................................................................13

TraderDemo.................................................................................................................................................................................................................................13

IRSDemo.......................................................................................................................................................................................................................................15

AttachmentDemo.........................................................................................................................................................................................................................18

DistributedNotary.........................................................................................................................................................................................................................20

BankofCorda................................................................................................................................................................................................................................21

SIMMDemo..................................................................................................................................................................................................................................24

NodeExplorerDemo.....................................................................................................................................................................................................................25

OnIntelliJ:..........................................................................................................................................................................................................................................32

TraderDemo.................................................................................................................................................................................................................................32

IRSDemo.......................................................................................................................................................................................................................................33

AttachmentDemo.........................................................................................................................................................................................................................33

DistributedNotary.........................................................................................................................................................................................................................33

BankofCorda................................................................................................................................................................................................................................33

SIMMDemo..................................................................................................................................................................................................................................33

NodeExplorerDemo.....................................................................................................................................................................................................................33

3

Pre-reqInstallations

Steps Process Commands1a InstallJDK

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.htmlAccepttermsanddownloadappropriatefile

1b SetupJAVA_HOME(ifneeded)

2a InstallGit

(StartusingGit-bash!)https://git-scm.com/downloadsWheninstalling,checktousegit-bash

2b Installnode.js(optional) https://nodejs.org/en/download/

4

Mostpeoplewilllikelywanttodothisbecauseit’llopenyourworldtonpm

(installintoPATH)

3a InstallIntelliJ(optional)Warning:IntelliJusesalotofRAMandwillslowdownyourmachine.Lesspowerfulmachinesshouldsticktocommand-line.

https://www.jetbrains.com/idea/download/#section=windows

3b SetupIntelliJSettheSDKtoyourJAVA_HOME

File>>ProjectStructureLeftpanel>>Project

3c UpdateRepositories

(willtakearound10minutes)File>>SettingsLeftpanel>>Build,Execution,Deployment>>BuildTools>>Maven>>Repositories

5

(ignorebintrayerrorsaswe’vemovedtojcenter/Maven–wearealsoworkingtowardsmigratingtothefreeopensourceplanofbintray)

3d Install/UpdateKotlinandotherPlugins(GitIntegrationandMavenIntegration)

File>>SettingsLeftpanel>>Plugins

4 Installh2 http://www.h2database.com/html/download.html

6

Usethisforreviewingtheh2databasestoringyourcordaobjects

Downloadthe“platform-independentzip”Installbydefault

5 Createaspaceforcordatestingprojects

$ cd ~ $ mkdir corda $ cd corda

7

CorDappTemplate(workingprototype)

Instructionsupdatedon:https://github.com/corda/cordapp-template(thisversionismorePC-specificandhasscreenshots)

Updateddetailedinstructions:https://docs.corda.net/tutorial-cordapp.html

Installongit-bash

Steps Process Commands1 Clonecordapp-template

Changedirectoriestonewlyclonedrepo

$ git clone https://github.com/corda/cordapp-template.git $ cd cordapp-template

2 Checkoutlateststablemilestonerelease(m6)Enumeratealltaggedreleases:$ git tag

$ git checkout -b [local_branch_name] tags/[tag_name] Ex:$ git checkout -b corda-m6-template tags/release-M6.0

3 Compilewithgradlew(shouldtake1-2minutes)

$ ./gradlew deployNodes

4 Changedirectorytobuild/nodes $ cd build/nodes 5 Openaregularcommandprompt

Becausegitbashdoesnothave“xterm”youwillneedtodeploythiswithincommandpromptinstead(ifyoutryfromgitbash)

$ cmd

8

6 Runtheapplication.

Thiswillcreate4newjava.exeapplicationsandrunthenetwork

(make sure in correct directory) $ runnodes.bat (Sorry it looks ugly, but looks better on Mac)

7 ThiswillstartNodeA,NodeB,NodeC,andController

Allofthesenodesarehostingtheirownservers(nodejs)andAPIs.Seethenode.conffilesforeachnode.

By default: Controller: localhost:10003 NodeA: localhost:10005 NodeB: localhost:10007 NodeC: localhost:10009

8 StaticwebcontentYoucannavigatethewebinterfaceWhencreatingorders,NotethatthePurchaseOrderContract.ktdefinesaconstraintthatlimitsthecountrycodetoonlymatch“UK”// Purchase order specific constraints.

Controller: http://localhost:10003/web/example NodeA: http://localhost:10005/web/example NodeB: http://localhost:10007/web/example NodeC: http://localhost:10009/web/example Counter-party: Select from list Order Number: 1 Delivery Date: 2018-09-15 City: London Country Code: UK Item name: Wow such item

9

"We only deliver to the UK." by (out.po.deliveryAddress.country == "UK") "You must order at least one type of item." by (out.po.items.size > 0) "You cannot order zero or negative amounts of an item." by (out.po.items.map(Item::amount).all { it > 0 }) "You can only order up to 10 items at a time." by (out.po.items.map(Item::amount).sum() <= 10) val time = tx.timestamp?.midpoint "The delivery date must be in the future." by (out.po.deliveryDate.toInstant() > time)

Item amount: 5

9 APIsavailable:

• /api/example/me • /api/example/peers • /api/example/purchase-orders • /api/example/{COUNTERPARTY}/create-purchase-

order

10 Trysendingviacurlexample echo '{"orderNumber": "1","deliveryDate": "2018-09-15","deliveryAddress": {"city": "London","country": "UK"},"items" : [{"name": "widget","amount": "3"},{"name": "thing","amount": "4"}]}' | cURL -T - -H 'Content-Type: application/json' http://localhost:10005/api/example/NodeB/create-purchase-order

11 Reviewnodestoensureitemshavebeencreatedintheappropriateareas

NodeA:

✅ Constructing proposed purchase order. ✅ Sending purchase order to seller for review. ✅ Received partially signed transaction from seller. ✅ Verifying signatures and contract constraints. ✅ Signing transaction with our private key. ✅ Obtaining notary signature. ✅ Requesting signature by Notary service

10

✅ Validating response from Notary service ✅ Recording transaction in vault. ✅ Sending fully signed transaction to seller. ✅ Done

NodeB:

✅ Receiving proposed purchase order from buyer. ✅ Generating transaction based on proposed purchase order. ✅ Signing proposed transaction with our private key. ✅ Sending partially signed transaction to buyer and wait for a response. ✅ Verifying signatures and contract constraints. ✅ Recording transaction in vault. ✅ Done

NodeC:

You shouldn't see any activity.

12 Reviewtheh2databasewebconsole $ cmd

$ cd h2/bin

$ h2.bat 13 Connecttotheh2database.Searchyourterminalwindow

tofindtheJDBCconnectionstring.

11

14 Starth2fromthepreviousinstall.UseconnectionstringfortheJDBCURL

15 ConductanySQL-likequeries

12

Cordaothersamples(SNAPSHOTrelease)

Instructionsupdatedon:https://docs.corda.r3cev.com/running-the-demos.html

Note:Thesedemosruntwo-nodenetworksdemonstratingfunctionalitysofar.Theseinclude:

• Thetraderdemo,whichshowsadelivery-vs-paymentatomicswapofcommercialpaperforcash.YoucanlearnmoreabouthowthisworksinWritingflows.

• TheIRSdemo,whichshowstwonodesestablishinganinterestrateswapbetweenthemandperformingfixingswitharatesoracle,alldrivenviatheHTTPAPI.

• TheIRSdemowebinterface-awebinterfacetotheIRSdemo.• Theattachmentdemo,whichdemonstratesuploadingattachmentstonodes.• TheSIMMvaluationdemo,alargedemowhichshowstwonodesagreeingonaportfolioandvaluingtheinitialmarginusingtheStandardInitialMargin

Model.• Thedistributednotarydemo,whichdemonstratesasinglenodegettingmultipletransactionsnotarisedbyadistributed(Raft-based)notary.• TheBankofCordademo,whichdemonstratesanodeactingasanissuerofassets(theBankofCorda)andremoteclient

• Applicationsrequestingissuance(viaRPC,HTTP)ofsomecashonbehalfofanodecalledBigCorporation.

CordaSamplesandtheirteststatusesupdated:https://github.com/corda/corda/wiki/Corda-Samples-Status

CloningCordaSteps Process Commands1 Clonecordarepository

Changedirectoriestonewlyclonedrepo

$ git clone https://github.com/corda/corda.git $ cd corda

2 Checkoutlateststablemilestonerelease(m6)Enumerateallbranches:$ git branch --all

$ git checkout -b [local_branch_name] origin/[remote_branch_name] Ex:$ git checkout -b corda-m6 origin/release-M6

13

Viacommand-line(gitbash)Werecommendusingthecommandlineifyou’relookingtosimplyrunthedemos.Fordebuggingandcoding,werecommendusingIntelliJ.

TraderDemoSteps Process Commands1 RundeployNodescommandtocreatesetofconfigsand

installsunder:samples/trader-demo/build/nodes

$ ./gradlew samples:trader-demo:deployNodes

14

2 Openanewcmdwindow

Changedirectoryto<dir>/corda/samples/trader-demo/build/nodes

$ cmd $ cd C:\Users\cleme\Documents\_Dev\corda\corda\samples\trader-demo\build\nodes

3 Runtheapplication:runnodes.batThiswillcreate4java.exeterminals

(check it’s the correct directory) $ runnodes.bat

4 GobacktothegitbashwindowRuntherunBuyer

(check it’s the corda directory) $ ./gradlew samples:trader-demo:runBuyer

15

Ifyouchecktheopenedjava.exewindows,thisshouldsetupthebuyernodewithsomeself-issuedcash.Thiswillnotprintmuch.

5 RuntherunSellercommand.Ontheopenjava.exeterminals,youcanseebothsidesofthetradersprinttheirprogressandfinaltransactionstateinthebanknodetabs/windows.

$ ./gradlew samples:trader-demo:runSeller

IRSDemoSteps Process Commands1 RundeployNodescommandtocreatesetofconfigsand

installsunder:samples/irs-demo/build/nodes

$ ./gradlew samples:irs-demo:deployNodes

16

2 Openanewcmdwindow

Changedirectoryto<dir>/corda/samples/irs-demo/build/nodes

$ cmd $ cd C:\Users\cleme\Documents\_Dev\corda\corda\samples\irs-demo\build\nodes

17

3 Runtheapplication:runnodes.batThiswillcreate3java.exeterminals

(check it’s the correct directory) $ runnodes.bat

4 GobacktothegitbashwindowRunthe“UploadRates”commandThiswillsendnewinterestratesasanoracletothefirstnode,whichactsasthenotary/oracle/networkmapnode

(in gitbash – make sure it’s the correct directory) $ cd ~/Documents/_Dev/corda/corda/samples/irs-demo/build/install/irs-demo/bin $ ./irs-demo –-role UploadRates

5 Runthe“Trade1”commandThenumberisatradeID.Whenrun,thereshouldbealotofactivityasthenodessetupthedealandnotarizeit.

(same directory as above) $ ./irs-demo –-role Trade 1

18

5 Runa“Date2017-01-05”

Thenumberisafuturedatetothetimeofcreatingthetrade.Thiswillsimulatearolloftheclockforward.Thedatechangerollstheclockforwardsandcausesthenodestoagreeonthefixingsoveraperiod.

$ ./irs-demo –-role Date 2017-01-05

6 Checkthewebinterfaceforrecenttrades NodeA: http://localhost:10005/web/irsdemo NodeB: http://localhost:10007/web/irsdemo

7 Testbycreatingsometradesviatheinterface 8 UsetheDateadjustertosimulatethearolloftheclock

forward

AttachmentDemoSteps Process Commands1 RundeployNodescommandtocreateasetofconfigs

andinstallsunder:samples/attachment-demo/build/nodes

$ ./gradlew samples:attachment-demo:deployNodes

2 OpenanewcmdwindowChangedirectoryto<dir>/corda/samples/attachment-demo/build/nodes

$ cmd $ cd C:\Users\cleme\Documents\_Dev\corda\corda\samples\attachment-demo\build\nodes

3 Runtheapplication:runnodes.bat (check it’s the correct directory) $ runnodes.bat

19

Thiswillcreate3java.exeterminals

4 GobacktothegitbashwindowRuntherunRecipientThiswillblockwaitingforsomethingtohappen

(check it’s the corda directory) $ ./gradlew samples:attachment-demo:runRecipient

5 (Inanewtransactionwindow)RuntherunSellercommand.Thiswilltriggeratransactionandtherecipientwillreceivetheoutputofthedemo.“FileReceived–we’rehappy!”

$ ./gradlew samples:attachment-demo:runSender

20

DistributedNotaryThisshowsapartygettingtransactionsnotarizedbyaRAFT-basednotaryservice.Itwillstart3distributednotarynodesandtwocounterpartynodes.Oneofthepartieswillgeneratetransactionsthatmoveaself-issuedassettoanotherpartyandsubmitthemfornotarization.

TheoutputisalistofnotarizedtransactionIDsandcorrespondingsignerpublickeys.

Steps Process Commands1 RundeployNodescommandtocreateasetofconfigs

andinstallsunder:samples/raft-notary-demo/build/nodes

$ ./gradlew samples:raft-notary-demo:deployNodes

2 OpenanewcmdwindowChangedirectoryto<dir>/corda/samples/raft-notary-demo/build/nodes

$ cmd $ cd C:\Users\cleme\Documents\_Dev\corda\corda\samples\raft-notary-demo\build\nodes

3 Runtheapplication:runnodes.batThiswillcreate5java.exeterminals

(check it’s the correct directory) $ runnodes.bat

4 Makeacalltothe“Party”nodetoinitiationnotarization

requests.Outputshouldnotarize10transactionsandshowalistoftransactionswithIDsandthesignerpublickeys

$ ./gradlew samples:raft-notary-demo:notarise

21

BankofCordaSteps Process Commands1 RundeployNodescommandtocreateasetofconfigs

andinstallsunder:samples/bank-of-corda-demo/build/nodes

$ ./gradlew samples:bank-of-corda-demo:deployNodes

2 OpenanewcmdwindowChangedirectoryto<dir>/corda/samples/bank-of-corda-demo/build/nodes

$ cmd $ cd C:\Users\cleme\Documents\_Dev\corda\corda\samples\bank-of-corda-demo\build\nodes

3 Runtheapplication:runnodes.batThiswillcreate3java.exeterminals

(check it’s the correct directory) $ runnodes.bat

22

4 CheckthebankofcordaAPIisalivewiththeURL localhost:10005/api/bank/date

5 Gobacktothegitbashwindow

RuntherunRPCCashIssuancecommandThiswilltriggeracashissuancerequest.Thisshoulddisplay:

- Awaitingissuancerequest- Self-issuingasset- Transferringassettoissuancerequester- Confirmingassetissuancetorequester

(check it’s the corda directory) $ ./gradlew samples:bank-of-corda-demo:runRPCCashIssue

6 (Inanewtransactionwindow)RuntherunWebCashIssuecommand.Thiswilltriggeranothercashissuancerequestanditshouldbeoutputtedinthedemo.

$ ./gradlew samples:bank-of-corda-demo:runWebCashIssue

23

Theclientrequestwindowwillpost“SuccessfullyprocessedCashIssuerequest”

7 Totestthebankofcorda,youcanruntheexplorertools $ ./gradlew tools:explorer:run

8 ForlogintotheBankofCordanode,useport10004

ForlogintotheBigCorporationnode,useport10006Corda Node: localhost Port: 10004 or 10006

24

Username: user1 Password: test

9 LoginasBankofCordaandpokearound.SeetheNodeExplorerDemoformoredetails.Moreinformationonthenodeexplorerisavailable:https://docs.corda.net/node-explorer.html

Video of this is available on our blogpost: https://www.corda.net/2017/01/03/the-node-explorer/

SIMMDemoForR3members,theSIMMdemowascompletedasProjectVega.Fulldocumentationisavailableontheprojectwiki:https://r3-cev.atlassian.net/wiki/pages/viewpage.action?pageId=53477761

Insummary,thisapplicationdemonstrateshowCordacanbeusedforinitialmargincalculationandagreementwithintegrationofthirdpartylibraries.

Tostartandextendthedemo,followthesesteps:

Steps Process Commands1 RundeployNodescommandtocreateasetofconfigs

andinstallsunder:samples/bank-of-corda-demo/build/nodes

$ ./gradlew samples:bank-of-corda-demo:deployNodes

25

2 OpenanewcmdwindowChangedirectoryto<dir>/corda/samples/bank-of-corda-demo/build/nodes

$ cmd $ cd C:\Users\cleme\Documents\_Dev\corda\corda\samples\bank-of-corda-demo\build\nodes

3 Runtheapplication:runnodes.batThiswillcreate3java.exeterminals

(check it’s the correct directory) $ runnodes.bat

4 Valuationdemoshouldberunningonmultiplenodes http://localhost:10005/web/simmvaluationdemo http://localhost:10007/web/simmvaluationdemo

5 Walkthroughofdemoanditsstepsareavailableonavideoonthewiki

NodeExplorerDemoUpdatedinformationonthenodeexplorerisavailable:https://docs.corda.net/node-explorer.html

Steps Process Commands1 Openacmdwindow

RunrunDemoNodescommandtostart3cordanodes.Thiscurrentlydoesnotopennewxtermwindows,butonthesafeside,we’llusewindowsterminal.

$ cmd $ gradlew.bat tools:explorer:runDemoNodes

2 Totesttheexplorer,youcanruntheexplorertoolsUI $ ./gradlew tools:explorer:run

26

3 ForlogintotheAlicenode,useport20004

ForlogintotheBobnode,useport20006Youwillnotbeabletologintothenotarynode,butitusesport20002

Corda Node: localhost Port: 20004 or 20006 Username: user1 Password: test

27

4 ReviewDashboardpage.ThisshowsstatisticsontheTransactionsandoracledata.

28

5 ReviewTransactionspage.Thisshowsalltransactionsthatwerecreated.IntheBankofCordaexample,youshouldseeadefaulttransaction.

29

6 ReviewCashpage.Thisshowsyourpositionsandallowsyoutocreatenewtransactions.

30

7 CreateanewTransaction.Thisallowsyoutopayanothermemberanamountgrantedtoyoubytheissueratthegivencurrency.Bydefault,thiswillnotbepopulatedasyouhavenotreceivedanymoney.Youcanrunthisonthebankofcordaapplicationtosimulatesendingofmoney.

31

8 ReviewtheNetworkpage.Thisshowstheactivenodesandtheirlocations.

32

OnIntelliJ:CordaSamplesalsoworkdirectlywithIntelliJ.WerecommendusingIntelliJifyou’redebuggingandcoding.

YoutubevideoavailableforIntelliJmethod:https://www.youtube.com/watch?v=f3dzpNBBT1U&feature=youtu.be

IntelliJsetupsaremucheasiersincetheexecutioncanbecontrolledfromthetopbar.

Theseshouldbestraightforwardtostart,buttheorderdoesmatterinordertoclearlyseetheresults.

Fornextsteps,pleasereferencethebashcommandlinestepsabove.

TraderDemo1. OpentheCordaprojectinIntelliJandrunthe“Install”configuration2. OpentheCordasamplesprojectinIntelliJandrunthe“TraderDemo:RunNodes”configuration3. Run“TraderDemo:RunBuyer”4. Run“TraderDemo:RunSeller”

33

IRSDemo1. OpentheCordaprojectinIntelliJandrunthe“Install”configuration2. OpentheCordasamplesprojectinIntelliJandrunthe“IRSDemo:RunNodes”configuration3. Run“IRSDemo:RunUploadRates”touploadratestotheoracle.4. Run“IRSDemo:RunTrade”tohavenodesagreeonatrade.5. Run“IRSDemo:RunDateChange”torunthefixings.

AttachmentDemo1. OpentheCordaprojectinIntelliJandrunthe“Install”configuration2. OpentheCordasamplesprojectinIntelliJandrunthe“AttachmentDemo:RunNodes”configuration3. Run“AttachmentDemo:RunRecipient”-thiswaitsforatradetostart4. Run“AttachmentDemo:RunSender”-sendstheattachment

DistributedNotary1. OpentheCordasamplesprojectinIntelliJandruntheNotaryDemo:RunNodesconfigurationtostartthenodes.Onceallnodesarestartedyouwillsee

several“Nodestartedupandregisteredin...”messages.2. RunNotaryDemo:RunNotarisationtomakeacalltothe“Party”nodetoinitiatenotarisationrequests.Inafewsecondsyouwillseeamessage

“Notarised10transactions”withalistoftransactionidsandthesignerpublickeys.

BankofCorda1. OpentheCordaprojectinIntelliJandrunthe“Install”configuration2. OpentheCordasamplesprojectinIntelliJandrunthe“BankOfCordaDemo:RunIssuer”configuration3. Run“BankOfCordaDemo:RunRPCCashIssue”-requestsissuanceofsomecashonbehalfofBigCorporationviaRPC4. Run“BankOfCordaDemo:RunWebCashIssue”-requestsissuanceofsomecashonbehalfofBigCorporationviaHTTP

SIMMDemo1. OpenthecordaprojectwithIntelliJ2. Runthesharedrunconfiguration“SIMMValuationDemo”

NodeExplorerDemo1. OpenthecordaprojectwithIntelliJ2. Runthesharedrunconfiguration“Explorer–demonodes”3. Oncerunning,Runtheconfiguration“explorer”whichisunderTornadoFX(scrolldown)

34