Hyperledger Fabric Chaincode解析

首先看下Blockchain结构,除了header指向下一个block的hash value外,block是由一组transaction构成, Transactions --> Blocks --> Ledger

 

1. Chaincode是生成transacton的唯一方式,是外界与区块链系统交互的唯一渠道,开发Fabric区块链应用就是编写Chaincode, Chaincode就是业务逻辑实现

2. Fabric预先定义了Chaincode接口,Chaincode实际上是一种接口的实现(理论上编程语言都可以去实现这些接口,目前支持go, java),以下是必须要实现的接口

type Chaincode interface {
    // deploy transaction被调用,一般只调用一次
    Init(stub ChaincodeStubInterface) pb.Response

    // 查询或更新账本,可多次调用
    Invoke(stub ChaincodeStubInterface) pb.Response
}

 

3. Chaincode编写好后,需要部署在Fabric的节点上, 运行在Docker容器中(开发chaincode的时候建议本地调试)

4. Chaincode也称为智能合约,Chaincode就是智能合约的实现方式,两者等同。感觉上Chaincode是技术用语,智能合约(Smart Contract)是业务用语。官方文档关于两者是这样表述的:

A chaincode typically handles business logic agreed to by members of the network, so it may be considered as a “smart contract”.

5. 区块链是一个复杂的系统,涉及很多技术领域,包括密码学、分布式系统设计、数据库设计、性能、扩展性、系统集成和运营,底层的系统会变成blockchain as a service,大多数应用开发和运维人员不需要涉及底层的架构,更多的会围绕着Chaincode来做开发

 

官方文档:https://hyperledger-fabric.readthedocs.io/en/release/chaincode.html

chaincode for 开发人员: https://hyperledger-fabric.readthedocs.io/en/release/chaincode4ade.html

chaincode for 运维人员: https://hyperledger-fabric.readthedocs.io/en/release/chaincode4noah.html

 

posted @ 2018-02-02 12:22  huahuayu  阅读(762)  评论(0编辑  收藏  举报