HyperLedger Fabric的Java Chaincode配置

一、启动开发java链上代码的过程

1.确保你有grandle工具
2.从 http://gradle.org/gradle-download/下载二进制的分布包
3.解包,移动到你想要的位置,添加grandle的bin目录到系统的Path路径
4.确保grandle -v命令能够执行,显示的版本是2.12版本或者更高
5.确保grandle daemon能够快速创建
6.确保已经安转jdk8.0,也要确保java的目录在你的路径

7.jdk的环境变量确保配置好

8.从命令行终端,到devenv子目录下,执行vagrant ssh
9.创建并且运行peer
10.接下来就可以用non-dev模式配置链上代码啦

--部署链上代码
    peer chaincode deploy -l java -p /opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/java/SimpleSample -c '{"Args": ["init", "a","100", "b", "200"]}'

--调用转换交易
peer chaincode invoke -l java \
    -n 6d9a704d95284593fe802a5de89f84e86fb975f00830bc6488713f9441b835cf32d9cd07b087b90e5cb57a88360f90a4de39521a5595545ad689cd64791679e9 \
    -c '{"Args": ["transfer", "a", "b", "10"]}'

--转换之后查询a和b的值

   peer chaincode query -l java \
    -n 6d9a704d95284593fe802a5de89f84e86fb975f00830bc6488713f9441b835cf32d9cd07b087b90e5cb57a88360f90a4de39521a5595545ad689cd64791679e9 \
    -c '{ "Args": ["query", "a"]}'
    {"Name":"a","Amount":"80"}


   peer chaincode query -l java \
    -n 6d9a704d95284593fe802a5de89f84e86fb975f00830bc6488713f9441b835cf32d9cd07b087b90e5cb57a88360f90a4de39521a5595545ad689cd64791679e9 \
    -c '{ "Args": ["query", "b"]}'
    {"Name":"b","Amount":"220"}

二、以DEV的模式部署java链上代码

1.前三步和上面的相同
2.创建并且运行peer进程
    cd $GOPATH/src/github.com/hyperledger/fabric
     make peer
     peer node start --peer-chaincodedev

3.打开第二个vagrant终端构建java的shim层并且发不到本地的Maven Repo

    cd $GOPATH/src/github.com/hyperledger/fabric/core/chaincode/shim/java
    gradle -b build.gradle clean
    gradle -b build.gradle build

4.到这个目录下java/SimpleSample创建并且运行

    cd $GOPATH/src/github.com/hyperledger/fabric/examples/chaincode/java/SimpleSample
    gradle -b build.gradle build

5.使用gradle -b build.gradle run运行SimpleSample chaincode

6.打开第三个vagrant终端在链上代码初始化和调用交易
peer chaincode deploy -l java -n SimpleSample -c ‘{“Args”: [“init”, “a”,”100”, “b”, “200”]}’
peer chaincode invoke -l java -n SimpleSample -c '{"Args": ["transfer", "a", "b", "10"]}'
peer chaincode query -l java -n SimpleSample -c '{ "Args": ["query", "a"]}'
peer chaincode query -l java -n SimpleSample -c '{"Args": ["query", "b"]}'

三、开发一个新的java链上代码

1.创建一个新的java项目
2.使用样列java链上代码项目类似examples/chaincode/java/SimpleSample来build.grade  
3. 确保你的主要类继承ChaincodeBase 类并且从基类中实现以下方法

    public String run(ChaincodeStub stub, String function, String[] args)
    public String query(ChaincodeStub stub, String function, String[] args)
    public String getChaincodeID()
    Modify the mainClassName in build.gradle to point to your new class.
    Build this project using gradle -b build.gradle build
    Run this chaincode after starting a peer in dev-mode as above using gradle -b build.gradle run








你可能感兴趣的:(Hyperledger,Fabric,区块链技术)