public class TransactionBuilder
extends java.lang.Object
Constructor and Description |
---|
TransactionBuilder(@NonNull TransactionBuilderAccount sourceAccount,
@NonNull Network network)
Construct a new transaction builder.
|
Modifier and Type | Method and Description |
---|---|
TransactionBuilder |
addMemo(@NonNull Memo memo)
Adds a memo to this transaction.
|
TransactionBuilder |
addOperation(@NonNull Operation operation)
Adds a new operation to this transaction.
|
TransactionBuilder |
addOperations(@NonNull java.util.Collection<Operation> operations)
Adds operation to this transaction.
|
TransactionBuilder |
addPreconditions(@NonNull TransactionPreconditions preconditions)
Adds preconditions.
|
Transaction |
build()
Builds a transaction and increments the sequence number on the source account after transaction
is constructed.
|
Transaction |
buildPaymentToContractTransaction(java.lang.String destination,
Asset asset,
java.math.BigDecimal amount,
SorobanDataBuilder.Resources resources,
java.lang.Long resourceFee,
java.lang.String source)
Builds a transaction to send asset to a contract.
|
Transaction |
buildPaymentToContractTransaction(java.lang.String destination,
Asset asset,
java.math.BigDecimal amount,
java.lang.String source)
An alias for
buildRestoreAssetBalanceEntryTransaction(String, Asset,
SorobanDataBuilder.Resources, Long, String) with resources set to new
SorobanDataBuilder.Resources(400_000L, 1_000L, 1_000L) and resourceFee set to 5_000_000L . |
Transaction |
buildRestoreAssetBalanceEntryTransaction(java.lang.String balanceOwner,
Asset asset,
SorobanDataBuilder.Resources resources,
java.lang.Long resourceFee,
java.lang.String source)
Builds a transaction to restore the asset balance entry.
|
Transaction |
buildRestoreAssetBalanceEntryTransaction(java.lang.String balanceOwner,
Asset asset,
java.lang.String source)
An alias for
buildRestoreAssetBalanceEntryTransaction(String, Asset,
SorobanDataBuilder.Resources, Long, String) with resources set to new
SorobanDataBuilder.Resources(0L, 500L, 500L) and resourceFee set to 4_000_000L . |
java.lang.Long |
getBaseFee() |
Network |
getNetwork() |
int |
getOperationsCount() |
TransactionBuilderAccount |
getSourceAccount() |
TransactionBuilder |
setBaseFee(long baseFee) |
TransactionBuilder |
setSorobanData(SorobanTransactionData sorobanData)
Sets the transaction's internal Soroban transaction data (resources, footprint, etc.).
|
TransactionBuilder |
setSorobanData(java.lang.String sorobanData)
Sets the transaction's internal Soroban transaction data (resources, footprint, etc.).
|
TransactionBuilder |
setTimeout(java.math.BigInteger timeout)
Because of the distributed nature of the Stellar network it is possible that the status of your
transaction will be determined after a long time if the network is highly congested.
|
TransactionBuilder |
setTimeout(long timeout)
An alias for
setTimeout(BigInteger) with timeout in seconds. |
public TransactionBuilder(@NonNull @NonNull TransactionBuilderAccount sourceAccount, @NonNull @NonNull Network network)
sourceAccount
- the source account for this transaction. This account is the account who
will use a sequence number. When build() is called, the account object's sequence number
will be incremented.network
- the testnet or pubnet network to usepublic int getOperationsCount()
public TransactionBuilder addOperation(@NonNull @NonNull Operation operation)
operation
- the operation to addOperation
public TransactionBuilder addOperations(@NonNull @NonNull java.util.Collection<Operation> operations)
operations
- list of operationsOperation
public TransactionBuilder addPreconditions(@NonNull @NonNull TransactionPreconditions preconditions)
preconditions
- the tx PreConditionspublic TransactionBuilder addMemo(@NonNull @NonNull Memo memo)
memo
- memo to addMemo
public TransactionBuilder setTimeout(java.math.BigInteger timeout)
TimeBounds
with maxTime
on the transaction (this is what
setTimeout
does internally; if there's minTime
set but no maxTime
it will be added). Call to Builder.setTimeout
is required if Transaction
does not have max_time
set. If you don't want to set timeout, use
TIMEOUT_INFINITE
. In general, you should set TIMEOUT_INFINITE
only in smart
contracts. Please note that Horizon may still return 504 Gateway Timeout
error,
even for short timeouts. In such case you need to resubmit the same transaction again without
making any changes to receive a status. This method is using the machine system time (UTC),
make sure it is set correctly.timeout
- Timeout in seconds.TimeBounds
public TransactionBuilder setTimeout(long timeout)
setTimeout(BigInteger)
with timeout
in seconds.timeout
- Timeout in seconds.public TransactionBuilder setBaseFee(long baseFee)
public Transaction build()
public TransactionBuilder setSorobanData(SorobanTransactionData sorobanData)
For non-contract(non-Soroban) transactions, this setting has no effect. In the case of
Soroban transactions, this is either an instance of SorobanTransactionData
or a
base64-encoded string of said structure. This is usually obtained from the simulation response
based on a transaction with a Soroban operation (e.g. InvokeHostFunctionOperation
, providing necessary resource and
storage footprint estimations for contract invocation.
sorobanData
- Soroban data to setpublic TransactionBuilder setSorobanData(java.lang.String sorobanData)
For non-contract(non-Soroban) transactions, this setting has no effect. In the case of
Soroban transactions, this is either an instance of SorobanTransactionData
or a
base64-encoded string of said structure. This is usually obtained from the simulation response
based on a transaction with a Soroban operation (e.g. InvokeHostFunctionOperation
, providing necessary resource and
storage footprint estimations for contract invocation.
sorobanData
- Soroban data to setpublic Transaction buildPaymentToContractTransaction(java.lang.String destination, Asset asset, java.math.BigDecimal amount, @Nullable java.lang.String source)
buildRestoreAssetBalanceEntryTransaction(String, Asset,
SorobanDataBuilder.Resources, Long, String)
with resources
set to new
SorobanDataBuilder.Resources(400_000L, 1_000L, 1_000L)
and resourceFee
set to 5_000_000L
.destination
- The contract to send the assets to. (starting with 'C')asset
- The asset to send.amount
- The amount of the asset to send.source
- The source account for the transaction.public Transaction buildPaymentToContractTransaction(java.lang.String destination, Asset asset, java.math.BigDecimal amount, SorobanDataBuilder.Resources resources, java.lang.Long resourceFee, @Nullable java.lang.String source)
The original intention of this interface design is to send assets to the contract account when the Stellar RPC server is inaccessible. Without Stellar RPC, we cannot accurately estimate the required resources, so we have preset some values that may be slightly higher than the actual resource consumption.
If you encounter the entry_archived
error when submitting this transaction, you
should consider calling the buildRestoreAssetBalanceEntryTransaction(String, Asset,
SorobanDataBuilder.Resources, Long, String)
method to restore the entry, and then use the
method to send assets again.
Note:
PaymentOperation
.
ContractClient
to build
transactions for sending tokens to contracts.
destination
- The contract to send the assets to. (starting with 'C')asset
- The asset to send.amount
- The amount of the asset to send.resources
- The resources required for the transaction.resourceFee
- The maximum fee (in stroops) that can be paid for the transaction.source
- The source account for the transaction.public Transaction buildRestoreAssetBalanceEntryTransaction(java.lang.String balanceOwner, Asset asset, @Nullable java.lang.String source)
buildRestoreAssetBalanceEntryTransaction(String, Asset,
SorobanDataBuilder.Resources, Long, String)
with resources
set to new
SorobanDataBuilder.Resources(0L, 500L, 500L)
and resourceFee
set to 4_000_000L
.balanceOwner
- The owner of the asset, it should be the same as the `destination` address
in the buildPaymentToContractTransaction(String, Asset, BigDecimal,
SorobanDataBuilder.Resources, Long, String)
method.asset
- The assetsource
- The source account for the transaction.public Transaction buildRestoreAssetBalanceEntryTransaction(java.lang.String balanceOwner, Asset asset, SorobanDataBuilder.Resources resources, java.lang.Long resourceFee, @Nullable java.lang.String source)
This method is designed to be used in conjunction with the buildPaymentToContractTransaction(String, Asset, BigDecimal, SorobanDataBuilder.Resources,
Long, String)
method.
Under Protocol 22, if the entry really needs to be restored, then this method will consume about 0.25 XLM in resource fees.
balanceOwner
- The owner of the asset, it should be the same as the `destination` address
in the buildPaymentToContractTransaction(String, Asset, BigDecimal,
SorobanDataBuilder.Resources, Long, String)
method.asset
- The assetresources
- The resources required for the transaction.resourceFee
- The maximum fee (in stroops) that can be paid for the transaction.source
- The source account for the transaction.public TransactionBuilderAccount getSourceAccount()
public java.lang.Long getBaseFee()
public Network getNetwork()