日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

Hyperledger Fabric 链码(2) 接口

發(fā)布時(shí)間:2025/3/21 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Hyperledger Fabric 链码(2) 接口 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1.Chaincode interface:每個(gè)鏈碼程序必須實(shí)現(xiàn)鏈碼接口,用以響應(yīng)接收的事務(wù)。

1.1 go語(yǔ)言的“shim ”包中,接口規(guī)范如下:

  • Init:在鏈碼實(shí)例化或者升級(jí)的時(shí)候被調(diào)用,完成數(shù)據(jù)初始化
  • Invoke:客戶端調(diào)用Invoke方法來(lái)提交交易提案,在更新或查詢提案事務(wù)中分類帳本數(shù)據(jù)狀態(tài)的時(shí)候被調(diào)用
type Chaincode interface {// Init is called during Instantiate transaction after the chaincode container// has been established for the first time, allowing the chaincode to// initialize its internal dataInit(stub ChaincodeStubInterface) pb.Response// Invoke is called to update or query the ledger in a proposal transaction.// Updated state variables are not committed to the ledger until the// transaction is committed.Invoke(stub ChaincodeStubInterface) pb.Response }

2. ChaincodeStubinterface:shim中的另一個(gè)重要接口,用于訪問(wèn)和修改帳本,以及實(shí)現(xiàn)鏈間調(diào)用

共定義了36個(gè)成員方法
eg.

  • GetFunctionAndParameters()(function string,params []string)返回被調(diào)用函數(shù)的名稱以及參數(shù)列表
  • GetStringArgs()[]string 直接返回參數(shù)列表
  • GetState(key string)([]byte,error) 根據(jù)指定的key值查詢數(shù)據(jù)狀態(tài)
  • PutState(key string,value []byte)error 根據(jù)指定的key,將對(duì)應(yīng)的value保存到帳本中
  • DelState(key) 刪除賬本中的一對(duì)鍵值。

總結(jié)

以上是生活随笔為你收集整理的Hyperledger Fabric 链码(2) 接口的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。