org.hyperledger.fabric.gateway

## 接口 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.

- - ### 方法概要

    所有方法 实例方法 抽象方法
    限定符和类型 | 方法和说明
    --- | ---
    `byte[]` | `evaluate(String... args)` Evaluate a transaction function and return its results.
    `String` | `getName()` Get the fully qualified name of the transaction function.
    `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, 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(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(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.

- - ### 方法详细资料

    - #### getName

          String getName()

      Get the fully qualified name of the transaction function.
      返回:
        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.
      返回:
        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.
      参数:
        `transientData` - A Map containing the transient data.
      返回:
        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.
      参数:
        `timeout` - the maximum time to wait.
        `timeUnit` - the time unit of the timeout argument.
      返回:
        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.
      参数:
        `commitHandler` - A commit handler implementation.
      返回:
        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...)`.
      参数:
        `peers` - Endorsing peers.
      返回:
        this transaction object to allow method chaining.

    - #### submit

          byte[] submit(String... args)
                 throws ContractException,
                        TimeoutException,
                        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.
      参数:
        `args` - Transaction function arguments.
      返回:
        Payload response from the transaction function.
      抛出:
        `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.
      参数:
        `args` - Transaction function arguments.
      返回:
        Payload response from the transaction function.
      抛出:
        `ContractException` - if no peers are reachable or an error response is returned.
        `GatewayRuntimeException` - if an underlying infrastructure failure occurs.

Copyright © 2023. All rights reserved.