Chaincode API operation
Hyperledger Fabric Go language version chaincodes have rich API interfaces through which user chaincodes directly interact with distributed ledgers. For more information about code implementation, see API code implementation. For more information, see the official documentation.
In terms of functionality, ChaincodeStubInterface APIs can be divided into the following types:
Auxiliary function class
The operation that you want to perform. | Migration description |
GetArgs() [][]byte | Obtain the call parameters in the chaincode call request. |
GetStringArgs() []string | Obtain the call parameters in the chaincode call request. |
GetFunctionAndParameters() (string, []string) | Obtain the function name and call parameters of the chaincode call. By default, the first parameter is the function name |
GetArgsSlice() ([]byte, error) | Obtain the call parameters in the chaincode call request. |
InvokeChaincode(chaincodeName string, args [][]byte, channel string) pb.Response | Call the Invoke method of other chaincodes |
CreateCompositeKey(objectType string, attributes []string) (string, error) | Combine attributes to form a composite key |
SplitCompositeKey(compositeKey string) (string, []string, error) | Split a composite key into a series of attributes |
SetEvent(name string, payload []byte) error | Set events sent |
Acquisition of transaction information
The operation that you want to perform. | Migration description |
GetTxID() string | Get the transaction ID of a transaction |
GetChannelID() string | Get the current channel name |
GetCreator() ([]byte, error) | Obtain the information of the transaction author. |
GetTransient() (map[string][]byte, error) | Obtain temporary information about transactions, which is mainly used by applications at the program level and is not written to ledger data. |
GetBinding() ([]byte, error) | Returns the binding information of the transaction, which is mainly used to force the link between application data and temporary information. |
GetDecorations() map[string][]byte | Get additional information about the transaction |
GetSignedProposal() (*pb.SignedProposal, error) | Get all the relevant data for the transaction proposal |
GetTxTimestamp() (*timestamp.Timestamp, error) | Obtain the transaction timestamp. |
Ledger data operations
The operation that you want to perform. | Migration description |
GetState(key string) ([]byte, error) | Obtains the value of a specified key. |
PutState(key string, value []byte) error | Add or update a pair of key values in the ledger |
DelState(key string) error | Delete a pair of key values in the ledger |
SetStateValidationParameter(key string, ep []byte) error | Set the endorsement policy for a specific key value |
GetStateValidationParameter(key string) ([]byte, error) | Get the endorsement policy for a specific key value |
GetStateByRange(startKey, endKey string) (StateQueryIteratorInterface, error) | Query key values within a specified range |
GetStateByRangeWithPagination(startKey, endKey string, pageSize int32, bookmark string) (StateQueryIteratorInterface, *pb.QueryResponseMetadata, error) | Query key values within a specified range by page |
GetStateByPartialCompositeKey(objectType string, keys []string) (StateQueryIteratorInterface, error) | Query all key values that match a local composite key |
GetStateByPartialCompositeKeyWithPagination(objectType string, keys []string, pageSize int32, bookmark string) (StateQueryIteratorInterface, *pb.QueryResponseMetadata, error) | Paged query matches all key values of a local composite key |
GetQueryResult(query string) (StateQueryIteratorInterface, error) | Use rich queries to query the state database. The state database must support rich queries. |
GetQueryResultWithPagination(query string, pageSize int32, bookmark string) (StateQueryIteratorInterface, *pb.QueryResponseMetadata, error) | Use the rich query mode to query the status database by page. The status database needs to be able to support the rich query function. |
GetHistoryForKey(key string) (HistoryQueryIteratorInterface, error) | Returns all historical values of the corresponding key |
GetPrivateData(collection, key string) ([]byte, error) | Gets the value of the key in the specified private dataset |
GetPrivateDataHash(collection, key string) ([]byte, error) | Gets the hash of the value of the key in the specified private dataset |
PutPrivateData(collection string, key string, value []byte) error | Sets the value of a key in the specified private dataset |
DelPrivateData(collection, key string) error | Deletes a specified key from a specified private dataset |
SetPrivateDataValidationParameter(collection, key string, ep []byte) error | Set the endorsement policy for a specified key in a private dataset |
GetPrivateDataValidationParameter(collection, key string) ([]byte, error) | Gets the endorsement policy for a specified key in a private dataset |
GetPrivateDataByRange(collection, startKey, endKey string) (StateQueryIteratorInterface, error) | Gets the key value of a specific range of keys in a specified private dataset |
GetPrivateDataByPartialCompositeKey(collection, objectType string, keys []string) (StateQueryIteratorInterface, error) | Gets the key value that matches the local composite key in the specified private data set |
GetPrivateDataQueryResult(collection, query string) (StateQueryIteratorInterface, error) | Query private datasets by using rich queries. The state database needs to be able to support rich queries. |