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

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      byte[] evaluate​(java.lang.String... args)
      Evaluate a transaction function and return its results.
      java.lang.String getName()
      Get the fully qualified name of the transaction function.
      java.lang.String getTransactionId()
      Get the transaction ID that will be used when submitting this transaction.
      Transaction setCommitHandler​(CommitHandlerFactory commitHandler)
      Set the commit handler to use for this transaction invocation instead of the default handler configured for the gateway.
      Transaction setCommitTimeout​(long timeout, java.util.concurrent.TimeUnit timeUnit)
      Set the maximum length of time to wait for commit events to be received after submitting a transaction to the orderer.
      Transaction setEndorsingPeers​(java.util.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...).
      Transaction setTransient​(java.util.Map<java.lang.String,​byte[]> transientData)
      Set transient data that will be passed to the transaction function but will not be stored on the ledger.
      byte[] submit​(java.lang.String... args)
      Submit a transaction to the ledger.
    • Method Detail

      • getName

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

        java.lang.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​(java.util.Map<java.lang.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,
                                     java.util.concurrent.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​(java.util.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

        byte[] submit​(java.lang.String... args)
               throws ContractException,
                      java.util.concurrent.TimeoutException,
                      java.lang.InterruptedException
        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.
        java.util.concurrent.TimeoutException - if the transaction was successfully submitted to the orderer but timed out before a commit event was received from peers.
        java.lang.InterruptedException - if the current thread is interrupted while waiting.
        GatewayRuntimeException - if an underlying infrastructure failure occurs.
      • evaluate

        byte[] evaluate​(java.lang.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.