public interface Contract
getContract
method.
The Contract allows applications to:
submitTransaction(String, String...)
.evaluateTransaction(String, String...)
.addContractListener(Consumer)
.addContractListener(long, Consumer)
.If more control over transaction invocation is required, such as including transient data, createTransaction(String)
can be used to build a transaction request that is submitted to or evaluated by the smart contract.
限定符和类型 | 方法和说明 |
---|---|
Consumer<ContractEvent> |
addContractListener(Checkpointer checkpointer,
Consumer<ContractEvent> listener)
Add a listener to receive all contract events emitted by committed transactions with checkpointing.
|
Consumer<ContractEvent> |
addContractListener(Checkpointer checkpointer,
Consumer<ContractEvent> listener,
Pattern eventNamePattern)
Add a listener to receive contract events emitted by committed transactions with checkpointing.
|
Consumer<ContractEvent> |
addContractListener(Checkpointer checkpointer,
Consumer<ContractEvent> listener,
String eventName)
Add a listener to receive contract events emitted by committed transactions with checkpointing.
|
Consumer<ContractEvent> |
addContractListener(Consumer<ContractEvent> listener)
Add a listener to receive all contract events emitted by committed transactions.
|
Consumer<ContractEvent> |
addContractListener(Consumer<ContractEvent> listener,
Pattern eventNamePattern)
Add a listener to receive contract events emitted by committed transactions.
|
Consumer<ContractEvent> |
addContractListener(Consumer<ContractEvent> listener,
String eventName)
Add a listener to receive contract events emitted by committed transactions.
|
Consumer<ContractEvent> |
addContractListener(long startBlock,
Consumer<ContractEvent> listener)
Add a listener to replay contract events emitted by committed transactions.
|
Consumer<ContractEvent> |
addContractListener(long startBlock,
Consumer<ContractEvent> listener,
Pattern eventNamePattern)
Add a listener to replay contract events emitted by committed transactions.
|
Consumer<ContractEvent> |
addContractListener(long startBlock,
Consumer<ContractEvent> listener,
String eventName)
Add a listener to replay contract events emitted by committed transactions.
|
Transaction |
createTransaction(String name)
Create an object representing a specific invocation of a transaction
function implemented by this contract, and provides more control over
the transaction invocation.
|
byte[] |
evaluateTransaction(String name,
String... args)
Evaluate a transaction function and return its results.
|
void |
removeContractListener(Consumer<ContractEvent> listener)
Remove a previously registered contract listener.
|
byte[] |
submitTransaction(String name,
String... args)
Submit a transaction to the ledger.
|
Transaction createTransaction(String name)
name
- Transaction function name.byte[] submitTransaction(String name, String... args) throws ContractException, TimeoutException, InterruptedException
name
will be evaluated on the endorsing peers and then submitted to the ordering service
for committing to the ledger.
This function is equivalent to calling createTransaction(name).submit()
.name
- Transaction function name.args
- Transaction function arguments.ContractException
- if the transaction is rejected.TimeoutException
- If the transaction was successfully submitted to the orderer but
timed out before a commit event was received from peers.InterruptedException
- if the current thread is interrupted while waiting.GatewayRuntimeException
- if an underlying infrastructure failure occurs.byte[] evaluateTransaction(String name, String... args) throws ContractException
name
will be evaluated on the endorsing peers but the responses will not be sent to
the ordering service and hence will not be committed to the ledger.
This is used for querying the world state.
This function is equivalent to calling createTransaction(name).evaluate()
.name
- Transaction function name.args
- Transaction function arguments.ContractException
- if no peers are reachable or an error response is returned.Consumer<ContractEvent> addContractListener(Consumer<ContractEvent> listener)
listener
- A contract listener.Consumer<ContractEvent> addContractListener(Consumer<ContractEvent> listener, String eventName)
listener
- A contract listener.eventName
- Event name.Consumer<ContractEvent> addContractListener(Consumer<ContractEvent> listener, Pattern eventNamePattern)
listener
- A contract listener.eventNamePattern
- Event name pattern.Consumer<ContractEvent> addContractListener(Checkpointer checkpointer, Consumer<ContractEvent> listener) throws IOException
checkpointer
- Checkpointer to persist block and transaction position.listener
- A contract listener.IOException
- if an error occurs establishing checkpointing.GatewayRuntimeException
- if an underlying infrastructure failure occurs.Consumer<ContractEvent> addContractListener(Checkpointer checkpointer, Consumer<ContractEvent> listener, String eventName) throws IOException
checkpointer
- Checkpointer to persist block and transaction position.listener
- A contract listener.eventName
- Event name.IOException
- if an error occurs establishing checkpointing.GatewayRuntimeException
- if an underlying infrastructure failure occurs.Consumer<ContractEvent> addContractListener(Checkpointer checkpointer, Consumer<ContractEvent> listener, Pattern eventNamePattern) throws IOException
checkpointer
- Checkpointer to persist block and transaction position.listener
- A contract listener.eventNamePattern
- Event name pattern.IOException
- if an error occurs establishing checkpointing.GatewayRuntimeException
- if an underlying infrastructure failure occurs.Consumer<ContractEvent> addContractListener(long startBlock, Consumer<ContractEvent> listener)
startBlock
- The number of the block from which events should be replayed.listener
- A contract listener.GatewayRuntimeException
- if an underlying infrastructure failure occurs.Consumer<ContractEvent> addContractListener(long startBlock, Consumer<ContractEvent> listener, String eventName)
startBlock
- The number of the block from which events should be replayed.listener
- A contract listener.eventName
- Event name.GatewayRuntimeException
- if an underlying infrastructure failure occurs.Consumer<ContractEvent> addContractListener(long startBlock, Consumer<ContractEvent> listener, Pattern eventNamePattern)
startBlock
- The number of the block from which events should be replayed.listener
- A contract listener.eventNamePattern
- Event name pattern.GatewayRuntimeException
- if an underlying infrastructure failure occurs.void removeContractListener(Consumer<ContractEvent> listener)
listener
- A contract listener.Copyright © 2023. All rights reserved.