Class Transaction<T extends Transaction<T>>
- Type Parameters:
T- The type of the transaction. Used to enable chaining.
- Direct Known Subclasses:
AbstractTokenTransferTransaction,AccountAllowanceAdjustTransaction,AccountAllowanceApproveTransaction,AccountAllowanceDeleteTransaction,AccountCreateTransaction,AccountDeleteTransaction,AccountUpdateTransaction,BatchTransaction,ChunkedTransaction,ContractCreateTransaction,ContractDeleteTransaction,ContractExecuteTransaction,ContractUpdateTransaction,EthereumTransaction,FileCreateTransaction,FileDeleteTransaction,FileUpdateTransaction,FreezeTransaction,HookStoreTransaction,LiveHashAddTransaction,LiveHashDeleteTransaction,NodeCreateTransaction,NodeDeleteTransaction,NodeUpdateTransaction,PendingAirdropLogic,PrngTransaction,RegisteredNodeCreateTransaction,RegisteredNodeDeleteTransaction,RegisteredNodeUpdateTransaction,ScheduleCreateTransaction,ScheduleDeleteTransaction,ScheduleSignTransaction,SystemDeleteTransaction,SystemUndeleteTransaction,TokenAssociateTransaction,TokenBurnTransaction,TokenCreateTransaction,TokenDeleteTransaction,TokenDissociateTransaction,TokenFeeScheduleUpdateTransaction,TokenFreezeTransaction,TokenGrantKycTransaction,TokenMintTransaction,TokenPauseTransaction,TokenRejectTransaction,TokenRevokeKycTransaction,TokenUnfreezeTransaction,TokenUnpauseTransaction,TokenUpdateNftsTransaction,TokenUpdateTransaction,TokenWipeTransaction,TopicCreateTransaction,TopicDeleteTransaction,TopicUpdateTransaction
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class com.hedera.hashgraph.sdk.Executable
Executable.GrpcRequest -
Field Summary
FieldsModifier and TypeFieldDescription(package private) List<CustomFeeLimit> (package private) static final DurationDefault auto renew duration for accounts, contracts, topics, and files (entities)protected HbarThe maximum transaction fee the client is willing to payprotected static final AccountIdDummy account ID used to assist in deserializing incomplete Transactions.protected static final TransactionIdDummy transaction ID used to assist in deserializing incomplete Transactions.protected TransactionBody.BuilderThe builder that gets re-used to build each outer transaction.protected List<SignedTransaction.Builder> An SDK [Transaction] is composed of multiple, raw protobuf transactions.protected List<Transaction> An SDK [Transaction] is composed of multiple, raw protobuf transactions.publicKeys and signers are parallel arrays.protected BooleanShould the transaction id be regeneratedpublicKeys and signers are parallel arrays.protected List<SignatureMap.Builder> A set of signatures corresponding to every unique public key used to sign the transaction.protected final TransactionBodyTransaction constructors end their work by setting sourceTransactionBody.protected LockableList<TransactionId> List of IDs for the transaction based on the operator because the transaction ID includes the operator's accountFields inherited from class com.hedera.hashgraph.sdk.Executable
attemptedAllNodes, blockingUnaryCall, grpcDeadline, logger, maxAttempts, maxBackoff, minBackoff, nodeAccountIds, nodes, random, RST_STREAM -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddSignature(PublicKey publicKey, byte[] signature) Add a signature to the transaction.addSignature(PublicKey publicKey, byte[] signature, TransactionId transactionID, AccountId nodeID) Adds a signature to the transaction for a specific transaction id and node id.final Tbatchify method is used to mark a transaction as part of a batch transaction or make it so-called inner transaction.(package private) voidBuild all the transactions.(package private) voidbuildTransaction(int index) Will build the specific transaction atindexThis function is only ever called after the transaction is frozen.protected ScheduleCreateTransactiondoSchedule(TransactionBody.Builder bodyBuilder) Converts transaction into a scheduled versionCreate aFeeEstimateQuerypre-populated with this transaction.freeze()Freeze this transaction from further modification to prepare for signing or serialization.freezeWith(Client client) Freeze this transaction from further modification to prepare for signing or serialization.static Transaction<?> fromBytes(byte[] bytes) Create the correct transaction from a byte array.static Transaction<?> Create the correct transaction from a scheduled transaction.(package private) voidgenerateTransactionIds(TransactionId initialTransactionId, int count) Generate transaction id's.Get the key that will sign the batch of which this Transaction is a part of.final HbarExtract the default maximum transaction fee.(package private) ExecutionStategetExecutionState(Status status, TransactionResponse response) Default implementation, may be overridden in subclasses (especially for query case).final booleanExtract the high-volume flag.final HbarExtract the maximum transaction fee.final BooleanShould the transaction id be regenerated.(package private) intThere must be at least one chunk.Returns a list of SignableNodeTransactionBodyBytes objects for each signed transaction in the transaction list.Extract list of account id and public keys.getSignaturesAtOffset(int offset) intThis method retrieves the transaction body sizebyte[]Extract a byte array of the transaction hash.Extract the list of account id and hash records.final TransactionIdExtract the transaction id.(package private) final TransactionIdfinal StringExtract the memo for the transaction.intThis method retrieves the size of the transactionfinal DurationExtract the valid transaction duration.(package private) static byte[]hash(byte[] bytes) Generate a hash from a byte array.protected booleanprotected booleanisFrozen()Check if transaction is frozen.protected booleanChecks if a public key is already added to the transaction(package private) final Transaction(package private) TransactionResponsemapResponse(TransactionResponse transactionResponse, AccountId nodeId, Transaction request) Called after receiving the query response from Hedera.(package private) final StatusmapResponseStatus(TransactionResponse transactionResponse) (package private) voidPrepare the transactions to be executed.(package private) CompletableFuture<Void> onExecuteAsync(Client client) (package private) abstract voidonFreeze(TransactionBody.Builder bodyBuilder) Called infreezeWith(Client)just before the transaction body is built.(package private) abstract voidonScheduled(SchedulableTransactionBody.Builder scheduled) Called inschedule()when converting transaction into a scheduled version.(package private) TransactionregenerateTransactionId(Client client) protected voidThrow an exception if the transaction is frozen.protected voidThrow an exception if there is not exactly one node id set.schedule()Extract the scheduled transaction.final TsetBatchKey(Key batchKey) Set the key that will sign the batch of which this Transaction is a part of.final TsetHighVolume(boolean highVolume) If set to true, this transaction uses high-volume throttles and pricing for entity creation.final TsetMaxTransactionFee(Hbar maxTransactionFee) Set the maximum transaction fee the operator (paying account) is willing to pay.final TsetNodeAccountIds(List<AccountId> nodeAccountIds) Set the account IDs of the nodes that this transaction will be submitted to.final TsetRegenerateTransactionId(boolean regenerateTransactionId) Regenerate the transaction id.final TsetTransactionId(TransactionId transactionId) Set the ID for this transaction.final TsetTransactionMemo(String memo) Set a note or description that should be recorded in the transaction record (maximum length of 100 characters).final TsetTransactionValidDuration(Duration validDuration) Sets the duration that this transaction is valid for.final Tsign(PrivateKey privateKey) Sign the transaction.(package private) voidsignTransaction(int index) Will sign the specific transaction atindexThis function is only ever called after the transaction is frozen.signWith(PublicKey publicKey, UnaryOperator<byte[]> transactionSigner) Sign the transaction.signWithOperator(Client client) Sign the transaction with the configured client.protected TransactionBody.BuilderspawnBodyBuilder(Client client) byte[]toBytes()Extract a byte array representation.toString()(package private) abstract voidvalidateChecksums(Client client) (package private) voidwipeTransactionLists(int requiredChunks) Wipe / reset the transaction list.Methods inherited from class com.hedera.hashgraph.sdk.Executable
advanceRequest, checkNodeAccountIds, execute, execute, executeAsync, executeAsync, executeAsync, executeAsync, executeAsync, executeAsync, getGrpcRequest, getMaxAttempts, getMaxBackoff, getMaxRetry, getMethodDescriptor, getMinBackoff, getNodeAccountIds, getNodeForExecute, grpcDeadline, logTransaction, mergeFromClient, setGrpcDeadline, setLogger, setMaxAttempts, setMaxBackoff, setMaxRetry, setMinBackoff, setNodesFromNodeAccountIds, setRequestListener, setResponseListener, shouldRetryExceptionally
-
Field Details
-
DEFAULT_AUTO_RENEW_PERIOD
Default auto renew duration for accounts, contracts, topics, and files (entities) -
DUMMY_ACCOUNT_ID
Dummy account ID used to assist in deserializing incomplete Transactions. -
DUMMY_TRANSACTION_ID
Dummy transaction ID used to assist in deserializing incomplete Transactions. -
sourceTransactionBody
Transaction constructors end their work by setting sourceTransactionBody. The expectation is that the Transaction subclass constructor will pick up where the Transaction superclass constructor left off, and will unpack the data in the transaction body. -
frozenBodyBuilder
The builder that gets re-used to build each outer transaction. freezeWith() will create the frozenBodyBuilder. The presence of frozenBodyBuilder indicates that this transaction is frozen. -
outerTransactions
An SDK [Transaction] is composed of multiple, raw protobuf transactions. These should be functionally identical, except pointing to different nodes. When retrying a transaction after a network error or retry-able status response, we try a different transaction and thus a different node. -
innerSignedTransactions
An SDK [Transaction] is composed of multiple, raw protobuf transactions. These should be functionally identical, except pointing to different nodes. When retrying a transaction after a network error or retry-able status response, we try a different transaction and thus a different node. -
sigPairLists
A set of signatures corresponding to every unique public key used to sign the transaction. -
transactionIds
List of IDs for the transaction based on the operator because the transaction ID includes the operator's account -
publicKeys
publicKeys and signers are parallel arrays. If the signer associated with a public key is null, that means that the private key associated with that public key has already contributed a signature to sigPairListBuilders, but the signer is not available (likely because this came from fromBytes()) -
signers
publicKeys and signers are parallel arrays. If the signer associated with a public key is null, that means that the private key associated with that public key has already contributed a signature to sigPairListBuilders, but the signer is not available (likely because this came from fromBytes()) -
defaultMaxTransactionFee
The maximum transaction fee the client is willing to pay -
regenerateTransactionId
Should the transaction id be regenerated -
customFeeLimits
List<CustomFeeLimit> customFeeLimits
-
-
Constructor Details
-
Transaction
Transaction()Constructor. -
Transaction
Transaction(TransactionBody txBody) Constructor.- Parameters:
txBody- protobuf TransactionBody
-
Transaction
Transaction(LinkedHashMap<TransactionId, LinkedHashMap<AccountId, throws com.google.protobuf.InvalidProtocolBufferExceptionTransaction>> txs) 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
-
-
Method Details
-
fromBytes
public static Transaction<?> fromBytes(byte[] bytes) throws com.google.protobuf.InvalidProtocolBufferException Create the correct transaction from a byte array.- Parameters:
bytes- the byte array- Returns:
- the new transaction
- Throws:
com.google.protobuf.InvalidProtocolBufferException- when there is an issue with the protobuf
-
fromScheduledTransaction
Create the correct transaction from a scheduled transaction.- Parameters:
scheduled- the scheduled transaction- Returns:
- the new transaction
-
hash
static byte[] hash(byte[] bytes) Generate a hash from a byte array.- Parameters:
bytes- the byte array- Returns:
- the hash
-
doSchedule
Converts transaction into a scheduled version- Parameters:
bodyBuilder- the transaction's body builder- Returns:
- the scheduled transaction
-
isBatchedAndNotBatchTransaction
protected boolean isBatchedAndNotBatchTransaction()- Overrides:
isBatchedAndNotBatchTransactionin classExecutable<T extends Transaction<T>,Transaction, TransactionResponse, TransactionResponse>
-
schedule
Extract the scheduled transaction.- Returns:
- the scheduled transaction
-
setNodeAccountIds
Set the account IDs of the nodes that this transaction will be submitted to.Providing an explicit node account ID interferes with client-side load balancing of the network. By default, the SDK will pre-generate a transaction for 1/3 of the nodes on the network. If a node is down, busy, or otherwise reports a fatal error, the SDK will try again with a different node.
- Overrides:
setNodeAccountIdsin classExecutable<T extends Transaction<T>,Transaction, TransactionResponse, TransactionResponse> - Parameters:
nodeAccountIds- The list of node AccountIds to be set- Returns:
this
-
getTransactionValidDuration
Extract the valid transaction duration.- Returns:
- the transaction valid duration
-
setTransactionValidDuration
Sets the duration that this transaction is valid for.This is defaulted by the SDK to 120 seconds (or two minutes).
- Parameters:
validDuration- The duration to be set- Returns:
this
-
getMaxTransactionFee
Extract the maximum transaction fee.- Returns:
- the maximum transaction fee
-
setMaxTransactionFee
Set the maximum transaction fee the operator (paying account) is willing to pay.- Parameters:
maxTransactionFee- the maximum transaction fee, in tinybars.- Returns:
this
-
getDefaultMaxTransactionFee
Extract the default maximum transaction fee.- Returns:
- the default maximum transaction fee
-
getTransactionMemo
Extract the memo for the transaction.- Returns:
- the memo for the transaction
-
setTransactionMemo
Set a note or description that should be recorded in the transaction record (maximum length of 100 characters).- Parameters:
memo- any notes or descriptions for this transaction.- Returns:
this
-
getHighVolume
public final boolean getHighVolume()Extract the high-volume flag.- Returns:
- true if high-volume throttles are enabled, false otherwise
-
setHighVolume
If set to true, this transaction uses high-volume throttles and pricing for entity creation. It only affects supported transaction types; otherwise, it is ignored.- Parameters:
highVolume- true to enable high-volume throttles, false otherwise- Returns:
this
-
batchify
batchify method is used to mark a transaction as part of a batch transaction or make it so-called inner transaction. The Transaction will be frozen and signed by the operator of the client.- Parameters:
client- sdk clientbatchKey- batch key- Returns:
this
-
setBatchKey
Set the key that will sign the batch of which this Transaction is a part of. -
getBatchKey
Get the key that will sign the batch of which this Transaction is a part of. -
toBytes
public byte[] toBytes()Extract a byte array representation.- Returns:
- the byte array representation
-
getTransactionHash
public byte[] getTransactionHash()Extract a byte array of the transaction hash.- Returns:
- the transaction hash
-
getTransactionHashPerNode
Extract the list of account id and hash records.- Returns:
- the list of account id and hash records
-
getTransactionIdInternal
- Specified by:
getTransactionIdInternalin classExecutable<T extends Transaction<T>,Transaction, TransactionResponse, TransactionResponse>
-
getTransactionId
Extract the transaction id.- Returns:
- the transaction id
-
setTransactionId
Set the ID for this transaction.The transaction ID includes the operator's account ( the account paying the transaction fee). If two transactions have the same transaction ID, they won't both have an effect. One will complete normally and the other will fail with a duplicate transaction status.
Normally, you should not use this method. Just before a transaction is executed, a transaction ID will be generated from the operator on the client.
- Parameters:
transactionId- The TransactionId to be set- Returns:
this- See Also:
-
getRegenerateTransactionId
Should the transaction id be regenerated.- Returns:
- should the transaction id be regenerated
-
setRegenerateTransactionId
Regenerate the transaction id.- Parameters:
regenerateTransactionId- should the transaction id be regenerated- Returns:
this
-
sign
Sign the transaction.- Parameters:
privateKey- the private key- Returns:
- the signed transaction
-
signWith
Sign the transaction.- Parameters:
publicKey- the public keytransactionSigner- the key list- Returns:
this
-
signWithOperator
Sign the transaction with the configured client.- Parameters:
client- the configured client- Returns:
- the signed transaction
-
keyAlreadySigned
Checks if a public key is already added to the transaction- Parameters:
key- the public key- Returns:
- if the public key is already added
-
addSignature
Add a signature to the transaction.- Parameters:
publicKey- the public keysignature- the signature- Returns:
this
-
getSignaturesAtOffset
-
getSignatures
Extract list of account id and public keys.- Returns:
- the list of account id and public keys
-
isFrozen
protected boolean isFrozen()Check if transaction is frozen.- Returns:
- is the transaction frozen
-
requireNotFrozen
protected void requireNotFrozen()Throw an exception if the transaction is frozen. -
requireOneNodeAccountId
protected void requireOneNodeAccountId()Throw an exception if there is not exactly one node id set. -
spawnBodyBuilder
-
freeze
Freeze this transaction from further modification to prepare for signing or serialization.- Returns:
this
-
freezeWith
Freeze this transaction from further modification to prepare for signing or serialization.Will use the `Client`, if available, to generate a default Transaction ID and select 1/3 nodes to prepare this transaction for.
- Parameters:
client- the configured client- Returns:
this
-
getRequiredChunks
int getRequiredChunks()There must be at least one chunk.- Returns:
- there is 1 required chunk
-
generateTransactionIds
Generate transaction id's.- Parameters:
initialTransactionId- the initial transaction idcount- the number of id's to generate.
-
wipeTransactionLists
void wipeTransactionLists(int requiredChunks) Wipe / reset the transaction list.- Parameters:
requiredChunks- the number of required chunks
-
buildAllTransactions
void buildAllTransactions()Build all the transactions. -
buildTransaction
void buildTransaction(int index) Will build the specific transaction atindexThis function is only ever called after the transaction is frozen.- Parameters:
index- the index of the transaction to be built
-
signTransaction
void signTransaction(int index) Will sign the specific transaction atindexThis function is only ever called after the transaction is frozen.- Parameters:
index- the index of the transaction to sign
-
onFreeze
Called infreezeWith(Client)just before the transaction body is built. The intent is for the derived class to assign their data variant to the transaction body. -
onScheduled
Called inschedule()when converting transaction into a scheduled version. -
makeRequest
- Specified by:
makeRequestin classExecutable<T extends Transaction<T>,Transaction, TransactionResponse, TransactionResponse>
-
mapResponse
TransactionResponse mapResponse(TransactionResponse transactionResponse, AccountId nodeId, Transaction request) Description copied from class:ExecutableCalled after receiving the query response from Hedera. The derived class should map into its output type.- Specified by:
mapResponsein classExecutable<T extends Transaction<T>,Transaction, TransactionResponse, TransactionResponse>
-
mapResponseStatus
- Specified by:
mapResponseStatusin classExecutable<T extends Transaction<T>,Transaction, TransactionResponse, TransactionResponse>
-
validateChecksums
- Throws:
BadEntityIdException
-
onExecute
Prepare the transactions to be executed.- Specified by:
onExecutein classExecutable<T extends Transaction<T>,Transaction, TransactionResponse, TransactionResponse> - Parameters:
client- the configured client
-
onExecuteAsync
- Specified by:
onExecuteAsyncin classExecutable<T extends Transaction<T>,Transaction, TransactionResponse, TransactionResponse>
-
getExecutionState
Description copied from class:ExecutableDefault implementation, may be overridden in subclasses (especially for query case). Called just after receiving the query response from Hedera. By default it triggers a retry when the pre-check status isBUSY.- Overrides:
getExecutionStatein classExecutable<T extends Transaction<T>,Transaction, TransactionResponse, TransactionResponse>
-
regenerateTransactionId
-
toString
-
estimateFee
Create aFeeEstimateQuerypre-populated with this transaction.This is a convenience method equivalent to:
new FeeEstimateQuery().setTransaction(transaction)- Returns:
- a new FeeEstimateQuery with this transaction set
-
getTransactionSize
public int getTransactionSize()This method retrieves the size of the transaction- Returns:
-
getTransactionBodySize
public int getTransactionBodySize()This method retrieves the transaction body size- Returns:
-
getSignableNodeBodyBytesList
Returns a list of SignableNodeTransactionBodyBytes objects for each signed transaction in the transaction list. The NodeID represents the node that this transaction is signed for. The TransactionID is useful for signing chunked transactions like FileAppendTransaction, since they can have multiple transaction ids.- Returns:
- List of SignableNodeTransactionBodyBytes
- Throws:
RuntimeException- if transaction is not frozen or protobuf parsing fails
-
addSignature
public T addSignature(PublicKey publicKey, byte[] signature, TransactionId transactionID, AccountId nodeID) Adds a signature to the transaction for a specific transaction id and node id. This is useful for signing chunked transactions like FileAppendTransaction, since they can have multiple transaction ids.- Parameters:
publicKey- The public key to add signature forsignature- The signature bytestransactionID- The specific transaction ID to matchnodeID- The specific node ID to match- Returns:
- The child transaction (this)
- Throws:
RuntimeException- if unmarshaling fails or invalid signed transaction
-