1. 程式人生 > >Hyperledger Fabric Chaincode是什麽,智能合約是什麽

Hyperledger Fabric Chaincode是什麽,智能合約是什麽

eas https erl 應用 運行 支持 pos 編程語言 type

首先看下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

Hyperledger Fabric Chaincode是什麽,智能合約是什麽