Class ChunkedTransaction<T extends ChunkedTransaction<T>>

Direct Known Subclasses:
FileAppendTransaction, TopicMessageSubmitTransaction

abstract class ChunkedTransaction<T extends ChunkedTransaction<T>> extends Transaction<T>
A common base for file and topic message transactions.
  • Field Details

    • data

      protected com.google.protobuf.ByteString data
      The transaction data
  • Constructor Details

    • ChunkedTransaction

      ChunkedTransaction(LinkedHashMap<TransactionId,LinkedHashMap<AccountId,Transaction>> txs) throws com.google.protobuf.InvalidProtocolBufferException
      Constructor.
      Parameters:
      txs - Compound list of transaction id's list of (AccountId, Transaction) records
      Throws:
      com.google.protobuf.InvalidProtocolBufferException - when there is an issue with the protobuf
    • ChunkedTransaction

      ChunkedTransaction(TransactionBody txBody)
      Constructor.
      Parameters:
      txBody - protobuf TransactionBody
    • ChunkedTransaction

      ChunkedTransaction()
      Constructor.
  • Method Details

    • getData

      com.google.protobuf.ByteString getData()
      Extract the data.
      Returns:
      the data
    • setData

      T setData(byte[] data)
      Assign the data via a byte array.
      Parameters:
      data - the byte array
      Returns:
      this
    • setData

      T setData(com.google.protobuf.ByteString data)
      Assign the data via a byte string.
      Parameters:
      data - the byte string
      Returns:
      this
    • setData

      T setData(String text)
      Assign the data via a string.
      Parameters:
      text - the byte array
      Returns:
      this
    • getMaxChunks

      public int getMaxChunks()
      Retrieve the maximum number of chunks.
      Returns:
      the number of chunks
    • setMaxChunks

      public T setMaxChunks(int maxChunks)
      Assign the max number of chunks.
      Parameters:
      maxChunks - the number of chunks
      Returns:
      this
    • getChunkSize

      public int getChunkSize()
      Retrieve the chunk size.
      Returns:
      the chunk size
    • setChunkSize

      public T setChunkSize(int chunkSize)
      Assign the chunk size.
      Parameters:
      chunkSize - the chunk size
      Returns:
      this
    • getTransactionHash

      public byte[] getTransactionHash()
      Description copied from class: Transaction
      Extract a byte array of the transaction hash.
      Overrides:
      getTransactionHash in class Transaction<T extends ChunkedTransaction<T>>
      Returns:
      the transaction hash
    • getTransactionHashPerNode

      public Map<AccountId,byte[]> getTransactionHashPerNode()
      Description copied from class: Transaction
      Extract the list of account id and hash records.
      Overrides:
      getTransactionHashPerNode in class Transaction<T extends ChunkedTransaction<T>>
      Returns:
      the list of account id and hash records
    • getAllTransactionHashesPerNode

      public final List<Map<AccountId,byte[]>> getAllTransactionHashesPerNode()
      Extract the list of transaction hashes.
      Returns:
      the list of transaction hashes
    • addSignature

      public T addSignature(PublicKey publicKey, byte[] signature)
      Description copied from class: Transaction
      Add a signature to the transaction.
      Overrides:
      addSignature in class Transaction<T extends ChunkedTransaction<T>>
      Parameters:
      publicKey - the public key
      signature - the signature
      Returns:
      this
    • getSignatures

      public Map<AccountId,Map<PublicKey,byte[]>> getSignatures()
      Description copied from class: Transaction
      Extract list of account id and public keys.
      Overrides:
      getSignatures in class Transaction<T extends ChunkedTransaction<T>>
      Returns:
      the list of account id and public keys
    • getAllSignatures

      public List<Map<AccountId,Map<PublicKey,byte[]>>> getAllSignatures()
      Extract the list of all signers.
      Returns:
      the list of all signatures
    • execute

      public TransactionResponse execute(Client client, Duration timeoutPerChunk) throws TimeoutException, PrecheckStatusException
      Description copied from class: Executable
      Execute this transaction or query with a timeout
      Overrides:
      execute in class Executable<T extends ChunkedTransaction<T>,Transaction,TransactionResponse,TransactionResponse>
      Parameters:
      client - The client with which this will be executed.
      timeoutPerChunk - The timeout after which the execution attempt will be cancelled.
      Returns:
      Result of execution
      Throws:
      TimeoutException - when the transaction times out
      PrecheckStatusException - when the precheck fails
    • executeAll

      Execute this transaction or query
      Parameters:
      client - The client with which this will be executed.
      Returns:
      Result of execution for each chunk
      Throws:
      TimeoutException - when the transaction times out
      PrecheckStatusException - when the precheck fails
    • executeAll

      public List<TransactionResponse> executeAll(Client client, Duration timeoutPerChunk) throws PrecheckStatusException, TimeoutException
      Execute this transaction or query
      Parameters:
      client - The client with which this will be executed.
      timeoutPerChunk - The timeout after which the execution attempt will be cancelled.
      Returns:
      Result of execution for each chunk
      Throws:
      TimeoutException - when the transaction times out
      PrecheckStatusException - when the precheck fails
    • executeAllAsync

      public CompletableFuture<List<TransactionResponse>> executeAllAsync(Client client)
      Execute this transaction or query asynchronously.
      Parameters:
      client - The client with which this will be executed.
      Returns:
      Future result of execution for each chunk
    • executeAllAsync

      public CompletableFuture<List<TransactionResponse>> executeAllAsync(Client client, Duration timeoutPerChunk)
      Execute this transaction or query asynchronously.
      Parameters:
      client - The client with which this will be executed.
      timeoutPerChunk - The timeout after which the execution attempt will be cancelled.
      Returns:
      Future result of execution for each chunk
    • executeAllAsync

      public void executeAllAsync(Client client, BiConsumer<List<TransactionResponse>,Throwable> callback)
      Execute this transaction or query asynchronously.
      Parameters:
      client - The client with which this will be executed.
      callback - a BiConsumer which handles the result or error.
    • executeAllAsync

      public void executeAllAsync(Client client, Duration timeout, BiConsumer<List<TransactionResponse>,Throwable> callback)
      Execute this transaction or query asynchronously.
      Parameters:
      client - The client with which this will be executed.
      timeout - The timeout after which the execution attempt will be cancelled.
      callback - a BiConsumer which handles the result or error.
    • executeAllAsync

      public void executeAllAsync(Client client, Consumer<List<TransactionResponse>> onSuccess, Consumer<Throwable> onFailure)
      Execute this transaction or query asynchronously.
      Parameters:
      client - The client with which this will be executed.
      onSuccess - a Consumer which consumes the result on success.
      onFailure - a Consumer which consumes the error on failure.
    • executeAllAsync

      public void executeAllAsync(Client client, Duration timeout, Consumer<List<TransactionResponse>> onSuccess, Consumer<Throwable> onFailure)
      Execute this transaction or query asynchronously.
      Parameters:
      client - The client with which this will be executed.
      timeout - The timeout after which the execution attempt will be cancelled.
      onSuccess - a Consumer which consumes the result on success.
      onFailure - a Consumer which consumes the error on failure.
    • executeAsync

      public CompletableFuture<TransactionResponse> executeAsync(Client client, Duration timeoutPerChunk)
      Description copied from class: Executable
      Execute this transaction or query asynchronously.

      Note: This method requires API level 33 or higher. It will not work on devices running API versions below 31 because it uses features introduced in API level 31 (Android 12).

      *
      Overrides:
      executeAsync in class Executable<T extends ChunkedTransaction<T>,Transaction,TransactionResponse,TransactionResponse>
      Parameters:
      client - The client with which this will be executed.
      timeoutPerChunk - The timeout after which the execution attempt will be cancelled.
      Returns:
      Future result of execution
    • schedule

      public ScheduleCreateTransaction schedule()
      Description copied from class: Transaction
      Extract the scheduled transaction.
      Overrides:
      schedule in class Transaction<T extends ChunkedTransaction<T>>
      Returns:
      the scheduled transaction
    • getRequiredChunks

      int getRequiredChunks()
      Description copied from class: Transaction
      There must be at least one chunk.
      Overrides:
      getRequiredChunks in class Transaction<T extends ChunkedTransaction<T>>
      Returns:
      there is 1 required chunk
    • wipeTransactionLists

      void wipeTransactionLists(int requiredChunks)
      Description copied from class: Transaction
      Wipe / reset the transaction list.
      Overrides:
      wipeTransactionLists in class Transaction<T extends ChunkedTransaction<T>>
      Parameters:
      requiredChunks - the number of required chunks
    • onFreezeChunk

      abstract void onFreezeChunk(TransactionBody.Builder body, @Nullable TransactionID initialTransactionId, int startIndex, int endIndex, int chunk, int total)
      A common base for file and topic message transactions.
    • shouldGetReceipt

      boolean shouldGetReceipt()
      Should the receipt be retrieved?
      Returns:
      by default do not get a receipt
    • bodySizeAllChunks

      public List<Integer> bodySizeAllChunks()
      Get the body sizes for all chunks in a FileAppendTransaction. For transactions with multiple chunks (like large file appends), this returns an array containing the size of each chunk's transaction body. The size is calculated by encoding the transaction body to protobuf format.
      Returns:
      List of integers that represent the size of each chunk