1 Star 0 Fork 0

GuoZhe / bootcamp-cordapp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

Corda

Bootcamp CorDapp

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.

Set up

  1. Download and install a JDK 8 JVM (minimum supported version 8u131)

  2. Download and install IntelliJ Community Edition (supported versions 2017.x and 2018.x)

  3. Download the bootcamp-cordapp repository:

    git clone https://github.com/corda/bootcamp-cordapp
  4. Open IntelliJ. From the splash screen, click Import Project, select the bootcamp— cordapp folder and click Open

  5. Select Import project from external model > Gradle > Next > Finish

  6. 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

  7. Open the Project view by clicking View > Tool Windows > Project

  8. Run the test in src/test/java/java_bootcamp/ProjectImportedOKTest.java. It should pass!

Links to useful resources

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:

  • Key Concepts docs (docs.corda.net/key-concepts.html)
  • API docs (docs.corda.net/api-index.html)
  • Cheat sheet (docs.corda.net/cheat-sheet.html)
  • Sample CorDapps (www.corda.net/samples)
  • Stack Overflow (www.stackoverflow.com/questions/tagged/corda)

What we'll be building

Our CorDapp will have three parts:

The TokenState

States define shared facts on the ledger. Our state, TokenState, will define a token. It will have the following structure:

-------------------
|                 |
|   TokenState    |
|                 |
|   - issuer      |
|   - owner       |
|   - amount      |
|                 |
-------------------

The TokenContract

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:

  • The transaction has no input states
  • The transaction has one output state
  • The transaction has one command
  • The output state is a TokenState
  • The output state has a positive amount
  • The command is an Issue command
  • The command lists the TokenState's issuer as a required signer

The TokenIssueFlow

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
          |                       |                       |
          ▼                       ▼                       ▼

Running our CorDapp

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:

    • Windows: gradlew.bat deployNodes
    • macOS: ./gradlew deployNodes
  • Start the nodes by running the following command:

    • Windows: build\nodes\runnodes.bat
    • macOS: 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

空文件

简介

取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/guozhe001/bootcamp-cordapp.git
git@gitee.com:guozhe001/bootcamp-cordapp.git
guozhe001
bootcamp-cordapp
bootcamp-cordapp
v4

搜索帮助