Interface Transaction


public interface Transaction
A Transaction represents a specific invocation of a transaction function, and provides flexibility over how that transaction is invoked. Applications should obtain instances of this class from a Contract using the createTransaction method.
Instances of this class are stateful. A new instance must be created for each transaction invocation.
  • Method Summary

    Modifier and Type
    Method
    Description
    byte[]
    evaluate(String... args)
    Evaluate a transaction function and return its results.
    Get the fully qualified name of the transaction function.
    Get the transaction ID that will be used when submitting this transaction.
    Set the commit handler to use for this transaction invocation instead of the default handler configured for the gateway.
    setCommitTimeout(long timeout, TimeUnit timeUnit)
    Set the maximum length of time to wait for commit events to be received after submitting a transaction to the orderer.
    setEndorsingPeers(Collection<org.hyperledger.fabric.sdk.Peer> peers)
    Set the peers that should be used for endorsement of transaction submitted to the ledger using submit(String...).
    setTransient(Map<String,byte[]> transientData)
    Set transient data that will be passed to the transaction function but will not be stored on the ledger.
    byte[]
    submit(String... args)
    Submit a transaction to the ledger.
  • Method Details

    • getName

      String getName()
      Get the fully qualified name of the transaction function.
      Returns:
      Transaction name.
    • getTransactionId

      String getTransactionId()
      Get the transaction ID that will be used when submitting this transaction. This can be useful for:
      • Asynchronously listening for commit events for this transaction when using the DefaultCommitHandlers.NONE commit handler.
      • Correlating client application operations with activity in Fabric peers and orderers.
      Returns:
      A transaction ID.
    • setTransient

      Transaction setTransient(Map<String,byte[]> transientData)
      Set transient data that will be passed to the transaction function but will not be stored on the ledger. This can be used to pass private data to a transaction function.
      Parameters:
      transientData - A Map containing the transient data.
      Returns:
      this transaction object to allow method chaining.
    • setCommitTimeout

      Transaction setCommitTimeout(long timeout, TimeUnit timeUnit)
      Set the maximum length of time to wait for commit events to be received after submitting a transaction to the orderer.
      Parameters:
      timeout - the maximum time to wait.
      timeUnit - the time unit of the timeout argument.
      Returns:
      this transaction object to allow method chaining.
    • setCommitHandler

      Transaction setCommitHandler(CommitHandlerFactory commitHandler)
      Set the commit handler to use for this transaction invocation instead of the default handler configured for the gateway.
      Parameters:
      commitHandler - A commit handler implementation.
      Returns:
      this transaction object to allow method chaining.
    • setEndorsingPeers

      Transaction setEndorsingPeers(Collection<org.hyperledger.fabric.sdk.Peer> peers)
      Set the peers that should be used for endorsement of transaction submitted to the ledger using submit(String...).
      Parameters:
      peers - Endorsing peers.
      Returns:
      this transaction object to allow method chaining.
    • submit

      Submit a transaction to the ledger. The transaction function represented by this object will be evaluated on the endorsing peers and then submitted to the ordering service for committing to the ledger.
      Parameters:
      args - Transaction function arguments.
      Returns:
      Payload response from the transaction function.
      Throws:
      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.
    • evaluate

      byte[] evaluate(String... args) throws ContractException
      Evaluate a transaction function and return its results. The transaction function 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.
      Parameters:
      args - Transaction function arguments.
      Returns:
      Payload response from the transaction function.
      Throws:
      ContractException - if no peers are reachable or an error response is returned.
      GatewayRuntimeException - if an underlying infrastructure failure occurs.