This project is the template we will use as a basis for developing a complete CorDapp during today's bootcamp. Our CorDapp will allow the issuance of tokens onto the ledger.
We'll develop the CorDapp using a test-driven approach. At each stage, you'll know your
CorDapp is working once it passes both sets of tests defined in src/test/java/bootcamp
.
Download and install a JDK 8 JVM (minimum supported version 8u131)
Download and install IntelliJ Community Edition (supported versions 2017.x and 2018.x)
Download the bootcamp-cordapp repository:
git clone https://github.com/corda/bootcamp-cordapp
Open IntelliJ. From the splash screen, click Import Project
, select the bootcamp— cordapp
folder and click Open
Select Import project from external model > Gradle > Next > Finish
Click File > Project Structure…
and select the Project SDK (Oracle JDK 8, 8u131+)
i. Add a new SDK if required by clicking New…
and selecting the JDK’s folder
Open the Project
view by clicking View > Tool Windows > Project
Run the test in src/test/java/java_bootcamp/ProjectImportedOKTest.java
. It should pass!
This project contains example state, contract and flow implementations:
src/main/java/java_examples/ArtState
src/main/java/java_examples/ArtContract
src/main/java/java_examples/ArtTransferFlowInitiator
src/main/java/java_examples/ArtTransferFlowResponder
There are also several web resources that you will likely find useful for this bootcamp:
docs.corda.net/key-concepts.html
)docs.corda.net/api-index.html
)docs.corda.net/cheat-sheet.html
)www.corda.net/samples
)www.stackoverflow.com/questions/tagged/corda
)Our CorDapp will have three parts:
States define shared facts on the ledger. Our state, TokenState, will define a token. It will have the following structure:
-------------------
| |
| TokenState |
| |
| - issuer |
| - owner |
| - amount |
| |
-------------------
Contracts govern how states evolve over time. Our contract, TokenContract, will define how TokenStates evolve. It will only allow the following type of TokenState transaction:
-------------------------------------------------------------------------------------
| |
| - - - - - - - - - - ------------------- |
| ▲ | | |
| | | | -► | TokenState | |
| NO ------------------- -► | | |
| | | | Issue command -► | - issuer | |
| INPUTS | signed by issuer -► | - owner | |
| | | ------------------- -► | - amount > 0 | |
| | -► | | |
| - - - - - - - - - - ▼ ------------------- |
| |
-------------------------------------------------------------------------------------
No inputs One issue command, One output,
issuer is a required signer amount is positive
To do so, TokenContract will impose the following constraints on transactions involving TokenStates:
Flows automate the process of updating the ledger. Our flow, TokenIssueFlow, will automate the following steps:
Issuer Owner Notary
| | |
Chooses a notary
| | |
Starts building
a transaction | |
|
Adds the output | |
TokenState
| | |
Adds the
Issue command | |
|
Verifies the | |
transaction
| | |
Signs the
transaction | |
|
|----------------------------------------------►|
| | |
Notarises the
| | transaction
|
|◀----------------------------------------------|
| | |
Records the
transaction | |
|
|----------------------►| |
|
| Records the |
transaction
| | |
▼ ▼ ▼
Normally, you'd interact with a CorDapp via a client or webserver. So we can focus on our CorDapp, we'll be running it via the node shell instead.
Once you've finished the CorDapp's code, run it with the following steps:
Build a test network of nodes by opening a terminal window at the root of your project and running the following command:
gradlew.bat deployNodes
./gradlew deployNodes
Start the nodes by running the following command:
build\nodes\runnodes.bat
build/nodes/runnodes
Open the nodes are started, go to the terminal of Party A (not the notary!) and run the following command to issue 99 tokens to Party B:
flow start TokenIssueFlow owner: PartyB, amount: 99
You can now see the tokens in the vaults of Party A and Party B (but not Party C!) by running the following command in their respective terminals:
run vaultQuery contractStateType: bootcamp.IouState
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。