All Products
Search
Document Center

Blockchain as a Service:Smart Contract Java API

Last Updated:Mar 13, 2023

Chaincode API operation

Hyperledger Fabric JAVA 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.

In terms of functionality, ChaincodeStubImpl APIs can be divided into the following types:

Auxiliary function class

The name of the service method.

Migration description

public List getArgs()

Obtain the call parameters in the chaincode call request.

public List getStringArgs()

Obtain the call parameters in the chaincode call request.

public String getFunction()

Obtains the name of the function called by the chaincode. By default, the first parameter is the function name.

public List getParameters()

Obtain the call parameters in the chaincode call request.

public void setEvent(String name, byte[] payload)

Set events sent

public ChaincodeEvent getEvent()

Obtain the sent events

public CompositeKey createCompositeKey(String objectType, String… attributes)

Combine attributes to form a composite key

public CompositeKey splitCompositeKey(String compositeKey)

Split a composite key into a series of attributes

public Response invokeChaincode(final String chaincodeName, final List args, final String channel)

Call the Invoke method of other chaincodes

Acquisition of transaction information

The name of the service method.

Migration description

public String getChannelId()

Get the current channel name

public String getTxId()

Get the transaction ID of a transaction

public SignedProposal getSignedProposal()

Get all the relevant data for the transaction proposal

public Instant getTxTimestamp()

Obtain the transaction timestamp.

public byte[] getCreator()

Obtain the information of the transaction author.

public Map getTransient()

Obtain temporary information about transactions, which is mainly used by applications at the program level and is not written to ledger data.

public byte[] getBinding()

Returns the binding information of the transaction, which is mainly used to force the link between application data and temporary information.

Ledger data operations

The name of the service method.

Migration description

public byte[] getState(String key)

Obtains the value of a specified key.

public void putState(String key, byte[] value)

Add or update a pair of key values in the ledger

public void delState(String key)

Delete a pair of key values in the ledger

public byte[] getStateValidationParameter(String key)

Get the endorsement policy for a specific key value

public void setStateValidationParameter(String key, byte[] value)

Set the endorsement policy for a specific key value

public QueryResultsIterator getStateByRange(String startKey, String endKey)

Query key values within a specified range

public QueryResultsIteratorWithMetadata getStateByRangeWithPagination(String startKey, String endKey, int pageSize, String bookmark)

Query key values within a specified range by page

public QueryResultsIterator getStateByPartialCompositeKey(String compositeKey)

Query all key values that match a local composite key

public QueryResultsIterator getStateByPartialCompositeKey(String objectType, String… attributes)

Query all key values that match a local composite key

public QueryResultsIterator getStateByPartialCompositeKey(CompositeKey compositeKey)

Query all key values that match a local composite key

public QueryResultsIteratorWithMetadata getStateByPartialCompositeKeyWithPagination(CompositeKey compositeKey, int pageSize, String bookmark)

Paged query matches all key values of a local composite key

public QueryResultsIterator getQueryResult(String query)

Use rich queries to query the state database. The state database must support rich queries.

public QueryResultsIteratorWithMetadata getQueryResultWithPagination(String query, int pageSize, String bookmark){

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.

public QueryResultsIterator getHistoryForKey(String key)

Returns all historical values of the corresponding key

public byte[] getPrivateData(String collection, String key)

Gets the value of the key in the specified private dataset

public byte[] getPrivateDataHash(String collection, String key)

Gets the hash of the value of the key in the specified private dataset

public byte[] getPrivateDataValidationParameter(String collection, String key)

Gets the endorsement policy for a specified key in a private dataset

public void putPrivateData(String collection, String key, byte[] value)

Sets the value of a key in the specified private dataset

public void delPrivateData(String collection, String key)

Deletes a specified key from a specified private dataset

public void setPrivateDataValidationParameter(String collection, String key, byte[] value)

Set the endorsement policy for a specified key in a private dataset

public QueryResultsIterator getPrivateDataByRange(String collection, String startKey, String endKey)

Gets the key value of a specific range of keys in a specified private dataset

public QueryResultsIterator getPrivateDataByPartialCompositeKey(String collection, String compositeKey)

Gets the key value that matches the local composite key in the specified private data set

public QueryResultsIterator getPrivateDataByPartialCompositeKey(String collection, CompositeKey compositeKey)

Gets the key value that matches the local composite key in the specified private data set

public QueryResultsIterator getPrivateDataByPartialCompositeKey(String collection, String objectType, String… attributes)

Gets the key value that matches the local composite key in the specified private data set

public QueryResultsIterator getPrivateDataQueryResult(String collection, String query)

Query private datasets by using rich queries. The state database needs to be able to support rich queries.