鏈碼API介面
Hyperledger Fabric Go 語言版本鏈碼有豐富的 API 介面,使用者鏈碼通過這些介面直接完成與分散式總帳的互動。代碼實現詳情可以參考 API 介面代碼實現,文檔可以參考官方文檔說明。
從功能方面劃分,可將 ChaincodeStubInterface 的 API 劃分為以下類型:
協助工具功能類
介面名稱 | 說明 |
|---|---|
GetArgs() [][]byte | 擷取鏈碼調用請求中調用參數 |
GetStringArgs() []string | 擷取鏈碼調用請求中調用參數 |
GetFunctionAndParameters() (string, []string) | 擷取鏈碼調用的函數名和調用參數, 預設第一個參數為函數名 |
GetArgsSlice() ([]byte, error) | 擷取鏈碼調用請求中調用參數 |
InvokeChaincode(chaincodeName string, args [][]byte, channel string) pb.Response | 調用其它鏈碼的 Invoke 方法 |
CreateCompositeKey(objectType string, attributes []string) (string, error) | 組合屬性,形成複合鍵 |
SplitCompositeKey(compositeKey string) (string, []string, error) | 將複合鍵拆分成一系列屬性 |
SetEvent(name string, payload []byte) error | 設定發送的事件 |
交易資訊擷取
介面名稱 | 說明 |
|---|---|
GetTxID() string | 擷取交易的交易 ID |
GetChannelID() string | 擷取當前的通道名稱 |
GetCreator() ([]byte, error) | 擷取交易提交者資訊 |
GetTransient() (map[string][]byte, error) | 擷取交易的臨時資訊,這類資訊主要用於應用在程式級,並不寫入賬本資料 |
GetBinding() ([]byte, error) | 返回交易的綁定資訊,這類綁定主要用於強制應用程式資料與臨時資訊的連結 |
GetDecorations() map[string][]byte | 擷取交易的額外資訊 |
GetSignedProposal() (*pb.SignedProposal, error) | 擷取交易提案所有相關資料 |
GetTxTimestamp() (*timestamp.Timestamp, error) | 擷取交易時間戳記 |
賬本資料操作
介面名稱 | 說明 |
|---|---|
GetState(key string) ([]byte, error) | 擷取指定鍵對應的值 |
PutState(key string, value []byte) error | 在賬本中添加或者更新一對索引值 |
DelState(key string) error | 在賬本中刪除一對索引值 |
SetStateValidationParameter(key string, ep []byte) error | 設定特定索引值的背書策略 |
GetStateValidationParameter(key string) ([]byte, error) | 擷取特定索引值的背書策略 |
GetStateByRange(startKey, endKey string) (StateQueryIteratorInterface, error) | 查詢指定範圍內的索引值 |
GetStateByRangeWithPagination(startKey, endKey string, pageSize int32, bookmark string) (StateQueryIteratorInterface, *pb.QueryResponseMetadata, error) | 分頁查詢指定範圍內的索引值 |
GetStateByPartialCompositeKey(objectType string, keys []string) (StateQueryIteratorInterface, error) | 查詢匹配局部複合鍵的所有索引值 |
GetStateByPartialCompositeKeyWithPagination(objectType string, keys []string, pageSize int32, bookmark string) (StateQueryIteratorInterface, *pb.QueryResponseMetadata, error) | 分頁查詢匹配局部複合鍵的所有索引值 |
GetQueryResult(query string) (StateQueryIteratorInterface, error) | 使用富查詢方式查詢狀態資料庫,狀態資料庫需要能夠支援富查詢功能 |
GetQueryResultWithPagination(query string, pageSize int32, bookmark string) (StateQueryIteratorInterface, *pb.QueryResponseMetadata, error) | 使用富查詢方式分頁查詢狀態資料庫,狀態資料庫需要能夠支援富查詢功能 |
GetHistoryForKey(key string) (HistoryQueryIteratorInterface, error) | 返回對應鍵的所有歷史值 |
GetPrivateData(collection, key string) ([]byte, error) | 擷取指定私人資料集中的鍵的值 |
GetPrivateDataHash(collection, key string) ([]byte, error) | 擷取指定私人資料集中的鍵的值的 hash |
PutPrivateData(collection string, key string, value []byte) error | 設定指定私人資料集中鍵的值 |
DelPrivateData(collection, key string) error | 刪除指定私人資料集中指定的鍵 |
SetPrivateDataValidationParameter(collection, key string, ep []byte) error | 設定私人資料集中指定鍵的背書策略 |
GetPrivateDataValidationParameter(collection, key string) ([]byte, error) | 擷取私人資料集中指定鍵的背書策略 |
GetPrivateDataByRange(collection, startKey, endKey string) (StateQueryIteratorInterface, error) | 擷取指定私人資料集中特定範圍鍵的索引值 |
GetPrivateDataByPartialCompositeKey(collection, objectType string, keys []string) (StateQueryIteratorInterface, error) | 擷取指定私人資料集中匹配局部複合鍵的索引值 |
GetPrivateDataQueryResult(collection, query string) (StateQueryIteratorInterface, error) | 通過富查詢方式查詢私人資料集,狀態資料庫需要能夠支援富查詢功能 |