public interface ChaincodeStub
Modifier and Type | Method and Description |
---|---|
CompositeKey |
createCompositeKey(java.lang.String objectType,
java.lang.String... attributes)
Given a set of attributes, this method combines these attributes to
return a composite key.
|
void |
delPrivateData(java.lang.String collection,
java.lang.String key)
Records the specified
key to be deleted in the private writeset of
the transaction. |
void |
delState(java.lang.String key)
Records the specified
key to be deleted in the writeset of
the transaction proposal. |
java.util.List<byte[]> |
getArgs()
Returns the arguments corresponding to the call to
Chaincode.init(ChaincodeStub) or
Chaincode.invoke(ChaincodeStub) , each argument represented as byte array. |
byte[] |
getBinding()
Returns the transaction binding.
|
java.lang.String |
getChannelId()
Returns the channel id for the current proposal.
|
byte[] |
getCreator()
Returns the identity of the agent (or user) submitting the transaction.
|
org.hyperledger.fabric.protos.peer.ChaincodeEventPackage.ChaincodeEvent |
getEvent()
Returns the CHAINCODE type event that will be posted to interested
clients when the chaincode's result is committed to the ledger.
|
java.lang.String |
getFunction()
A convenience method that returns the first argument of the chaincode
invocation for use as a function name.
|
QueryResultsIterator<KeyModification> |
getHistoryForKey(java.lang.String key)
Returns a history of key values across time.
|
java.util.List<java.lang.String> |
getParameters()
A convenience method that returns all except the first argument of the
chaincode invocation for use as the parameters to the function returned
by #
getFunction() . |
byte[] |
getPrivateData(java.lang.String collection,
java.lang.String key)
Returns the value of the specified
key from the specified
collection . |
QueryResultsIterator<KeyValue> |
getPrivateDataByPartialCompositeKey(java.lang.String collection,
CompositeKey compositeKey)
Returns all existing keys, and their values, that are prefixed by the
specified partial
CompositeKey in a given private collection. |
QueryResultsIterator<KeyValue> |
getPrivateDataByPartialCompositeKey(java.lang.String collection,
java.lang.String compositeKey)
Returns all existing keys, and their values, that are prefixed by the
specified partial
CompositeKey in a given private collection. |
QueryResultsIterator<KeyValue> |
getPrivateDataByPartialCompositeKey(java.lang.String collection,
java.lang.String objectType,
java.lang.String... attributes)
Returns all existing keys, and their values, that are prefixed by the
specified partial
CompositeKey in a given private collection. |
QueryResultsIterator<KeyValue> |
getPrivateDataByRange(java.lang.String collection,
java.lang.String startKey,
java.lang.String endKey)
Returns all existing keys, and their values, that are lexicographically
between
startkey (inclusive) and the endKey
(exclusive) in a given private collection. |
QueryResultsIterator<KeyValue> |
getPrivateDataQueryResult(java.lang.String collection,
java.lang.String query)
Perform a rich query against a given private collection.
|
default java.lang.String |
getPrivateDataUTF8(java.lang.String collection,
java.lang.String key)
Returns the byte array value specified by the key and decoded as a UTF-8
encoded string, from the sidedb collection.
|
byte[] |
getPrivateDataValidationParameter(java.lang.String collection,
java.lang.String key)
Retrieves the key-level endorsement
policy for the private data specified by
key . |
QueryResultsIterator<KeyValue> |
getQueryResult(java.lang.String query)
Performs a "rich" query against a state database.
|
QueryResultsIteratorWithMetadata<KeyValue> |
getQueryResultWithPagination(java.lang.String query,
int pageSize,
java.lang.String bookmark)
Performs a "rich" query against a state database.
|
org.hyperledger.fabric.protos.peer.ProposalPackage.SignedProposal |
getSignedProposal()
Returns the signed transaction proposal currently being executed.
|
byte[] |
getState(java.lang.String key)
Returns the value of the specified
key from the ledger. |
QueryResultsIterator<KeyValue> |
getStateByPartialCompositeKey(CompositeKey compositeKey)
Returns all existing keys, and their values, that are prefixed by the
specified partial
CompositeKey . |
QueryResultsIterator<KeyValue> |
getStateByPartialCompositeKey(java.lang.String compositeKey)
Returns all existing keys, and their values, that are prefixed by the
specified partial
CompositeKey . |
QueryResultsIterator<KeyValue> |
getStateByPartialCompositeKey(java.lang.String objectType,
java.lang.String... attributes)
Returns all existing keys, and their values, that are prefixed by the
specified partial
CompositeKey . |
QueryResultsIteratorWithMetadata<KeyValue> |
getStateByPartialCompositeKeyWithPagination(CompositeKey compositeKey,
int pageSize,
java.lang.String bookmark)
Queries the state in the ledger based on a given partial composite key.
|
QueryResultsIterator<KeyValue> |
getStateByRange(java.lang.String startKey,
java.lang.String endKey)
Returns all existing keys, and their values, that are lexicographically
between
startkey (inclusive) and the endKey
(exclusive). |
QueryResultsIteratorWithMetadata<KeyValue> |
getStateByRangeWithPagination(java.lang.String startKey,
java.lang.String endKey,
int pageSize,
java.lang.String bookmark)
Returns a range iterator over a set of keys in the ledger.
|
byte[] |
getStateValidationParameter(java.lang.String key)
retrieves the key-level endorsement policy for
key . |
java.util.List<java.lang.String> |
getStringArgs()
Returns the arguments corresponding to the call to
Chaincode.init(ChaincodeStub) or
Chaincode.invoke(ChaincodeStub) , cast to UTF-8 string. |
default java.lang.String |
getStringState(java.lang.String key)
Returns the byte array value specified by the key and decoded as a UTF-8
encoded string, from the ledger.
|
java.util.Map<java.lang.String,byte[]> |
getTransient()
Returns the transient map associated with the current transaction.
|
java.lang.String |
getTxId()
Returns the transaction id for the current chaincode invocation request.
|
java.time.Instant |
getTxTimestamp()
Returns the timestamp when the transaction was created.
|
default Chaincode.Response |
invokeChaincode(java.lang.String chaincodeName,
java.util.List<byte[]> args)
Invoke another chaincode using the same transaction context.
|
Chaincode.Response |
invokeChaincode(java.lang.String chaincodeName,
java.util.List<byte[]> args,
java.lang.String channel)
Locally calls the specified chaincode
invoke() using the
same transaction context. |
default Chaincode.Response |
invokeChaincodeWithStringArgs(java.lang.String chaincodeName,
java.util.List<java.lang.String> args)
Invoke another chaincode using the same transaction context.
|
default Chaincode.Response |
invokeChaincodeWithStringArgs(java.lang.String chaincodeName,
java.util.List<java.lang.String> args,
java.lang.String channel)
Invoke another chaincode using the same transaction context.
|
default Chaincode.Response |
invokeChaincodeWithStringArgs(java.lang.String chaincodeName,
java.lang.String... args)
Invoke another chaincode using the same transaction context.
|
void |
putPrivateData(java.lang.String collection,
java.lang.String key,
byte[] value)
Puts the specified
key and value into the transaction's
private writeset. |
default void |
putPrivateData(java.lang.String collection,
java.lang.String key,
java.lang.String value)
Writes the specified value and key into the sidedb collection
value converted to byte array.
|
void |
putState(java.lang.String key,
byte[] value)
Puts the specified
key and value into the transaction's
writeset as a data-write proposal. |
default void |
putStringState(java.lang.String key,
java.lang.String value)
Writes the specified value and key into the ledger
|
void |
setEvent(java.lang.String name,
byte[] payload)
Defines the CHAINCODE type event that will be posted to interested
clients when the chaincode's result is committed to the ledger.
|
void |
setPrivateDataValidationParameter(java.lang.String collection,
java.lang.String key,
byte[] value)
Sets the key-level endorsement policy for the private data specified by
key . |
void |
setStateValidationParameter(java.lang.String key,
byte[] value)
Sets the key-level endorsement policy for
key . |
CompositeKey |
splitCompositeKey(java.lang.String compositeKey)
Parses a composite key
CompositeKey from a string. |
java.util.List<byte[]> getArgs()
Chaincode.init(ChaincodeStub)
or
Chaincode.invoke(ChaincodeStub)
, each argument represented as byte array.java.util.List<java.lang.String> getStringArgs()
Chaincode.init(ChaincodeStub)
or
Chaincode.invoke(ChaincodeStub)
, cast to UTF-8 string.java.lang.String getFunction()
The bytes of the first argument are decoded as a UTF-8 string.
java.util.List<java.lang.String> getParameters()
getFunction()
.
The bytes of the arguments are decoded as a UTF-8 strings and returned as a list of string parameters.
java.lang.String getTxId()
The transaction id uniquely identifies the transaction within the scope of the channel.
java.lang.String getChannelId()
This would be the 'channel_id' of the transaction proposal except where the chaincode is calling another on a different channel.
Chaincode.Response invokeChaincode(java.lang.String chaincodeName, java.util.List<byte[]> args, java.lang.String channel)
invoke()
using the
same transaction context.
chaincode calling chaincode doesn't create a new transaction message.
If the called chaincode is on the same channel, it simply adds the called chaincode read set and write set to the calling transaction.
If the called chaincode is on a different channel,
only the Response is returned to the calling chaincode; any putState
calls
from the called chaincode will not have any effect on the ledger; that is,
the called chaincode on a different channel will not have its read set
and write set applied to the transaction. Only the calling chaincode's
read set and write set will be applied to the transaction. Effectively
the called chaincode on a different channel is a `Query`, which does not
participate in state validation checks in subsequent commit phase.
If `channel` is empty, the caller's channel is assumed.
Invoke another chaincode using the same transaction context.
chaincodeName
- Name of chaincode to be invoked.args
- Arguments to pass on to the called chaincode.channel
- If not specified, the caller's channel is assumed.Chaincode.Response
object returned by called chaincodebyte[] getState(java.lang.String key)
key
from the ledger.
Note that getState doesn't read data from the writeset, which has not been committed to the ledger. In other words, GetState doesn't consider data modified by PutState that has not been committed.
key
- name of the valuebyte[] getStateValidationParameter(java.lang.String key)
key
.
Note that this will introduce a read dependency on key
in the transaction's readset.key
- key to get key level endorsementvoid putState(java.lang.String key, byte[] value)
key
and value
into the transaction's
writeset as a data-write proposal.
putState doesn't effect the ledger until the transaction is validated and successfully committed. Simple keys must not be an empty string and must not start with 0x00 character, in order to avoid range query collisions with composite keys
key
- name of the valuevalue
- the value to write to the ledgervoid setStateValidationParameter(java.lang.String key, byte[] value)
key
.key
- key to set key level endorsementvalue
- endorsement policyvoid delState(java.lang.String key)
key
to be deleted in the writeset of
the transaction proposal.
The key
and its value will be deleted from
the ledger when the transaction is validated and successfully committed.
key
- name of the value to be deletedQueryResultsIterator<KeyValue> getStateByRange(java.lang.String startKey, java.lang.String endKey)
startkey
(inclusive) and the endKey
(exclusive).
The keys are returned by the iterator in lexical order. Note that startKey and endKey can be empty string, which implies unbounded range query on start or end.
Call close() on the returned AutoCloseable.close()
object when done.
startKey
- key as the start of the key range (inclusive)endKey
- key as the end of the key range (exclusive)Iterable
of KeyValue
QueryResultsIteratorWithMetadata<KeyValue> getStateByRangeWithPagination(java.lang.String startKey, java.lang.String endKey, int pageSize, java.lang.String bookmark)
startKey
(inclusive) and endKey
(exclusive).
When an empty string is passed as a value to the bookmark
argument, the returned iterator can be used to fetch
the first pageSize
keys between the startKey
and endKey
.
When the bookmark
is a non-empty string, the iterator can be used to fetch first pageSize
keys between the
bookmark
and endKey
.
Note that only the bookmark present in a prior page of query results (ChaincodeShim.QueryResponseMetadata
)
can be used as a value to the bookmark argument. Otherwise, an empty string must be passed as bookmark.
The keys are returned by the iterator in lexical order. Note that startKey
and endKey
can be empty string, which implies
unbounded range query on start or end.
This call is only supported in a read only transaction.startKey
- endKey
- pageSize
- bookmark
- QueryResultsIterator<KeyValue> getStateByPartialCompositeKey(java.lang.String compositeKey)
CompositeKey
.
If a full composite key is specified, it will not match itself, resulting in no keys being returned.
This method takes responsibility to correctly parse the CompositeKey
from a String
and behaves exactly as getStateByPartialCompositeKey(CompositeKey)
.
Call close() on the returned AutoCloseable.close()
object when done.
compositeKey
- partial composite keyIterable
of KeyValue
QueryResultsIterator<KeyValue> getStateByPartialCompositeKey(java.lang.String objectType, java.lang.String... attributes)
CompositeKey
.
It combines the attributes and the objectType to form a partial composite key.
If a full composite key is specified, it will not match itself, resulting in no keys being returned.
This method takes responsibility to correctly combine Object type and attributes
creating a CompositeKey
and behaves exactly
as getStateByPartialCompositeKey(CompositeKey)
.
AutoCloseable.close()
object when done.objectType:
- ObjectType of the compositeKeyattributes:
- Attributes of the composite keyIterable
of KeyValue
QueryResultsIterator<KeyValue> getStateByPartialCompositeKey(CompositeKey compositeKey)
CompositeKey
.
If a full composite key is specified, it will not match itself, resulting in no keys being returned.
compositeKey
- partial composite keyIterable
of KeyValue
QueryResultsIteratorWithMetadata<KeyValue> getStateByPartialCompositeKeyWithPagination(CompositeKey compositeKey, int pageSize, java.lang.String bookmark)
When an empty string is passed as a value to the bookmark
argument, the returned iterator can be used to fetch
the first pageSize
composite keys whose prefix matches the given partial composite key.
When the bookmark
is a non-empty string, the iterator can be used to fetch first pageSize
keys between the
bookmark
(inclusive) and and the last matching composite key.
Note that only the bookmark present in a prior page of query results (ChaincodeShim.QueryResponseMetadata
)
can be used as a value to the bookmark argument. Otherwise, an empty string must be passed as bookmark.
This call is only supported in a read only transaction.
compositeKey
- pageSize
- bookmark
- CompositeKey createCompositeKey(java.lang.String objectType, java.lang.String... attributes)
objectType
- A string used as the prefix of the resulting keyattributes
- List of attribute values to concatenate into the keyCompositeKey splitCompositeKey(java.lang.String compositeKey)
CompositeKey
from a string.compositeKey
- a composite key stringQueryResultsIterator<KeyValue> getQueryResult(java.lang.String query)
It is only supported for state databases that support rich query,
e.g. CouchDB. The query string is in the native syntax
of the underlying state database. An QueryResultsIterator
is returned
which can be used to iterate (next) over the query result set.
query
- query string in a syntax supported by the underlying state
databaseQueryResultsIterator
object contains query resultsjava.lang.UnsupportedOperationException
- if the underlying state database does not support rich
queries.QueryResultsIteratorWithMetadata<KeyValue> getQueryResultWithPagination(java.lang.String query, int pageSize, java.lang.String bookmark)
bookmark
argument, the returned iterator can be used to fetch
the first pageSize
of query results..
When the bookmark
is a non-empty string, the iterator can be used to fetch first pageSize
keys between the
bookmark
(inclusive) and the last key in the query result.
Note that only the bookmark present in a prior page of query results (ChaincodeShim.QueryResponseMetadata
)
can be used as a value to the bookmark argument. Otherwise, an empty string must be passed as bookmark.
This call is only supported in a read only transaction.
query
- pageSize
- bookmark
- QueryResultsIterator<KeyModification> getHistoryForKey(java.lang.String key)
For each historic key update, the historic value and associated
transaction id and timestamp are returned. The timestamp is the
timestamp provided by the client in the proposal header.
This method requires peer configuration
core.ledger.history.enableHistoryDatabase
to be true.
key
- The state variable keyIterable
of KeyModification
byte[] getPrivateData(java.lang.String collection, java.lang.String key)
key
from the specified
collection
.
Note that getPrivateData(String, String)
doesn't read data from the
private writeset, which has not been committed to the collection
. In
other words, getPrivateData(String, String)
doesn't consider data modified by putPrivateData(String, String, byte[])
* that has not been committed.
collection
- name of the collectionkey
- name of the valuebyte[] getPrivateDataValidationParameter(java.lang.String collection, java.lang.String key)
key
. Note that this introduces
a read dependency on key
in the transaction's readset.collection
- name of the collectionkey
- key to get endorsement policyvoid putPrivateData(java.lang.String collection, java.lang.String key, byte[] value)
key
and value
into the transaction's
private writeset.
Note that only hash of the private writeset goes into the
transaction proposal response (which is sent to the client who issued the
transaction) and the actual private writeset gets temporarily stored in a
transient store. putPrivateData doesn't effect the collection
until the
transaction is validated and successfully committed. Simple keys must not be
an empty string and must not start with null character (0x00), in order to
avoid range query collisions with composite keys, which internally get
prefixed with 0x00 as composite key namespace.
collection
- name of the collectionkey
- name of the valuevalue
- the value to write to the ledgervoid setPrivateDataValidationParameter(java.lang.String collection, java.lang.String key, byte[] value)
key
.collection
- name of the collectionkey
- key to set endorsement policyvalue
- endorsement policyvoid delPrivateData(java.lang.String collection, java.lang.String key)
key
to be deleted in the private writeset of
the transaction.
Note that only hash of the private writeset goes into the
transaction proposal response (which is sent to the client who issued the
transaction) and the actual private writeset gets temporarily stored in a
transient store. The key
and its value will be deleted from the collection
when the transaction is validated and successfully committed.
collection
- name of the collectionkey
- name of the value to be deletedQueryResultsIterator<KeyValue> getPrivateDataByRange(java.lang.String collection, java.lang.String startKey, java.lang.String endKey)
startkey
(inclusive) and the endKey
(exclusive) in a given private collection.
Note that startKey and endKey can be empty string, which implies unbounded range query on start or end. The query is re-executed during validation phase to ensure result set has not changed since transaction endorsement (phantom reads detected).
collection
- name of the collectionstartKey
- private data variable key as the start of the key range (inclusive)endKey
- private data variable key as the end of the key range (exclusive)Iterable
of KeyValue
QueryResultsIterator<KeyValue> getPrivateDataByPartialCompositeKey(java.lang.String collection, java.lang.String compositeKey)
CompositeKey
in a given private collection.
If a full composite key is specified, it will not match itself, resulting in no keys being returned.
The query is re-executed during validation phase to ensure result set has not changed since transaction endorsement (phantom reads detected).
This method takes responsibility to correctly parse the CompositeKey
from a String
and behaves exactly as getPrivateDataByPartialCompositeKey(String, CompositeKey)
.
collection
- name of the collectioncompositeKey
- partial composite keyIterable
of KeyValue
QueryResultsIterator<KeyValue> getPrivateDataByPartialCompositeKey(java.lang.String collection, CompositeKey compositeKey)
CompositeKey
in a given private collection.
If a full composite key is specified, it will not match itself, resulting in no keys being returned.
The query is re-executed during validation phase to ensure result set has not changed since transaction endorsement (phantom reads detected).
collection
- name of the collectioncompositeKey
- partial composite keyIterable
of KeyValue
QueryResultsIterator<KeyValue> getPrivateDataByPartialCompositeKey(java.lang.String collection, java.lang.String objectType, java.lang.String... attributes)
CompositeKey
in a given private collection.
If a full composite key is specified, it will not match itself, resulting in no keys being returned.
The query is re-executed during validation phase to ensure result set has not changed since transaction endorsement (phantom reads detected).
This method takes responsibility to correctly combine Object type and attributes
creating a CompositeKey
and behaves exactly
as getPrivateDataByPartialCompositeKey(String, CompositeKey)
.
collection
- name of the collectionobjectType:
- ObjectType of the compositeKeyattributes:
- Attributes of the composite keyIterable
of KeyValue
QueryResultsIterator<KeyValue> getPrivateDataQueryResult(java.lang.String collection, java.lang.String query)
It is only supported for state databases that support rich query, e.g.CouchDB. The query string is in the native syntax of the underlying state database. An iterator is returned which can be used to iterate (next) over the query result set. The query is NOT re-executed during validation phase, phantom reads are not detected. That is, other committed transactions may have added, updated, or removed keys that impact the result set, and this would not be detected at validation/commit time. Applications susceptible to this should therefore not use GetQueryResult as part of transactions that update ledger, and should limit use to read-only chaincode operations.
collection
- name of the collectionquery
- query string in a syntax supported by the underlying state
databaseQueryResultsIterator
object contains query resultsjava.lang.UnsupportedOperationException
- if the underlying state database does not support rich
queries.void setEvent(java.lang.String name, byte[] payload)
name
- Name of event. Cannot be null or empty string.payload
- Optional event payload.default Chaincode.Response invokeChaincode(java.lang.String chaincodeName, java.util.List<byte[]> args)
Same as invokeChaincode(String, List, String)
using channelId to null
chaincodeName
- Name of chaincode to be invoked.args
- Arguments to pass on to the called chaincode.Chaincode.Response
object returned by called chaincodedefault Chaincode.Response invokeChaincodeWithStringArgs(java.lang.String chaincodeName, java.util.List<java.lang.String> args, java.lang.String channel)
This is a convenience version of
invokeChaincode(String, List, String)
. The string args will be
encoded into as UTF-8 bytes.
chaincodeName
- Name of chaincode to be invoked.args
- Arguments to pass on to the called chaincode.channel
- If not specified, the caller's channel is assumed.Chaincode.Response
object returned by called chaincodedefault Chaincode.Response invokeChaincodeWithStringArgs(java.lang.String chaincodeName, java.util.List<java.lang.String> args)
This is a convenience version of invokeChaincode(String, List)
.
The string args will be encoded into as UTF-8 bytes.
chaincodeName
- Name of chaincode to be invoked.args
- Arguments to pass on to the called chaincode.Chaincode.Response
object returned by called chaincodedefault Chaincode.Response invokeChaincodeWithStringArgs(java.lang.String chaincodeName, java.lang.String... args)
This is a convenience version of invokeChaincode(String, List)
.
The string args will be encoded into as UTF-8 bytes.
chaincodeName
- Name of chaincode to be invoked.args
- Arguments to pass on to the called chaincode.Chaincode.Response
object returned by called chaincodedefault java.lang.String getStringState(java.lang.String key)
This is a convenience version of getState(String)
key
- name of the valuedefault void putPrivateData(java.lang.String collection, java.lang.String key, java.lang.String value)
collection
- collection namekey
- name of the valuevalue
- the value to write to the ledgerdefault java.lang.String getPrivateDataUTF8(java.lang.String collection, java.lang.String key)
collection
- collection namekey
- name of the valuedefault void putStringState(java.lang.String key, java.lang.String value)
key
- name of the valuevalue
- the value to write to the ledgerorg.hyperledger.fabric.protos.peer.ChaincodeEventPackage.ChaincodeEvent getEvent()
org.hyperledger.fabric.protos.peer.ProposalPackage.SignedProposal getSignedProposal()
java.time.Instant getTxTimestamp()
byte[] getCreator()
java.util.Map<java.lang.String,byte[]> getTransient()
byte[] getBinding()