Class TransactionServiceImpl
java.lang.Object
com.kryptokrauts.aeternity.sdk.service.transaction.impl.TransactionServiceImpl
- All Implemented Interfaces:
TransactionService
public class TransactionServiceImpl extends java.lang.Object implements TransactionService
-
Field Summary
Fields Modifier and Type Field Description protected static org.slf4j.Logger
_logger
-
Constructor Summary
Constructors Constructor Description TransactionServiceImpl()
-
Method Summary
Modifier and Type Method Description io.reactivex.Single<StringResultWrapper>
asyncCreateUnsignedTransaction(AbstractTransactionModel<?> tx)
asynchronously creates an unsignedTx object for further processing and especially abstracts the fee calculation for this transactionio.reactivex.Single<DryRunTransactionResults>
asyncDryRunTransactions(DryRunRequest input)
asynchronously dry run unsigned transactions to estimate gas (!) please make sure to use implementations ofList
to ensure correct order of transactions called by accountsio.reactivex.Single<PostTransactionResult>
asyncPostTransaction(AbstractTransactionModel<?> tx)
asynchronously post a transaction for given model with the private key stored in the configurationio.reactivex.Single<PostTransactionResult>
asyncPostTransaction(AbstractTransactionModel<?> tx, java.lang.String privateKey)
asynchronously post a transaction for given modelio.reactivex.Single<PostTransactionResult>
asyncPostTransaction(java.lang.String signedTx)
asynchronously post a transaction based on the given signedTx as Stringio.reactivex.Single<TransactionResult>
asyncWaitForConfirmation(java.lang.String txHash)
asynchronously wait for a transaction to be confirmedio.reactivex.Single<TransactionResult>
asyncWaitForConfirmation(java.lang.String txHash, int numOfConfirmations)
asynchronously wait for a transaction to be confirmedCheckTxInPoolResult
blockingCheckTxInPool(java.lang.String txHash)
ContractTxResult
blockingContractCreate(java.lang.String sourceCode)
convenience method to deploy a contract and return the tx-hash along with the decoded result and other useful information related to the tx.ContractTxResult
blockingContractCreate(java.lang.String sourceCode, ContractTxOptions txOptions)
convenience method to deploy a contract and return the tx-hash along with the decoded result and other useful information related to the tx.StringResultWrapper
blockingCreateUnsignedTransaction(AbstractTransactionModel<?> tx)
synchronously creates an unsignedTx object for further processing and especially abstracts the fee calculation for this transactionDryRunTransactionResult
blockingDryRunContractTx(AbstractTransactionModel<?> contractTx, boolean useZeroAddress)
convenience function to perform a dry-run for a single tx by providing one ofAbstractTransaction
DryRunTransactionResults
blockingDryRunTransactions(DryRunRequest input)
synchronously dry run unsigned transactions to estimate gas (!) please make sure to use implementations ofList
to ensure correct order of transactions called by accountsPostTransactionResult
blockingPostTransaction(AbstractTransactionModel<?> tx)
synchronously post a transaction for given model with the private key stored in the configurationPostTransactionResult
blockingPostTransaction(AbstractTransactionModel<?> tx, java.lang.String privateKey)
synchronously post a transaction for given modelPostTransactionResult
blockingPostTransaction(java.lang.String signedTx)
synchronously post a transaction based on the given signedTx as Stringjava.lang.Object
blockingReadOnlyContractCall(java.lang.String contractId, java.lang.String entrypoint, java.lang.String sourceCode)
convenience method to perform a read-only contract call and return the decoded call result.java.lang.Object
blockingReadOnlyContractCall(java.lang.String contractId, java.lang.String entrypoint, java.lang.String sourceCode, ContractTxOptions txOptions)
convenience method to perform a read-only contract call and return the decoded call result.ContractTxResult
blockingStatefulContractCall(java.lang.String contractId, java.lang.String entrypoint, java.lang.String sourceCode)
convenience method to perform a stateful contract call and return the tx-hash along with the decoded result and other useful information related to the tx.ContractTxResult
blockingStatefulContractCall(java.lang.String contractId, java.lang.String entrypoint, java.lang.String sourceCode, ContractTxOptions txOptions)
convenience method to perform a stateful contract call and return the tx-hash along with the decoded result and other useful information related to the tx.java.lang.String
computeGAInnerTxHash(AbstractTransactionModel<?> tx)
synchronously creates an unsigned transaction out of the given AbstractTransactionModel and append network data to the resulting byte array.java.lang.String
computeTxHash(AbstractTransactionModel<?> tx)
[@PURPOSE-DEBUG] synchronously compute the transaction hash for the given transaction modeljava.lang.String
signPayingForInnerTransaction(AbstractTransactionModel<?> model, java.lang.String privateKey)
sign an unsigned transaction with the given private key.java.lang.String
signTransaction(java.lang.String unsignedTx, java.lang.String privateKey)
sign an unsigned transaction with the given private keyjava.lang.String
toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Field Details
-
_logger
protected static final org.slf4j.Logger _logger
-
-
Constructor Details
-
TransactionServiceImpl
public TransactionServiceImpl()
-
-
Method Details
-
asyncCreateUnsignedTransaction
public io.reactivex.Single<StringResultWrapper> asyncCreateUnsignedTransaction(AbstractTransactionModel<?> tx)Description copied from interface:TransactionService
asynchronously creates an unsignedTx object for further processing and especially abstracts the fee calculation for this transaction- Specified by:
asyncCreateUnsignedTransaction
in interfaceTransactionService
- Parameters:
tx
- transaction typed model, one ofAbstractTransaction
- Returns:
- a single-wrapped unsignedTx object
-
blockingCreateUnsignedTransaction
Description copied from interface:TransactionService
synchronously creates an unsignedTx object for further processing and especially abstracts the fee calculation for this transaction- Specified by:
blockingCreateUnsignedTransaction
in interfaceTransactionService
- Parameters:
tx
- transaction typed model, one ofAbstractTransaction
- Returns:
- a single-wrapped unsignedTx object
-
asyncPostTransaction
public io.reactivex.Single<PostTransactionResult> asyncPostTransaction(AbstractTransactionModel<?> tx)Description copied from interface:TransactionService
asynchronously post a transaction for given model with the private key stored in the configuration- Specified by:
asyncPostTransaction
in interfaceTransactionService
- Parameters:
tx
- instance of a specific TransactionModel-class that extendsAbstractTransactionModel
- Returns:
- asynchronous result handler (RxJava Single) for
PostTransactionResult
-
asyncPostTransaction
public io.reactivex.Single<PostTransactionResult> asyncPostTransaction(AbstractTransactionModel<?> tx, java.lang.String privateKey) throws TransactionCreateExceptionDescription copied from interface:TransactionService
asynchronously post a transaction for given model- Specified by:
asyncPostTransaction
in interfaceTransactionService
- Parameters:
tx
- instance of a specific TransactionModel-class that extendsAbstractTransactionModel
privateKey
- the privateKey to sign the tx- Returns:
- asynchronous result handler (RxJava Single) for
PostTransactionResult
- Throws:
TransactionCreateException
-
blockingPostTransaction
Description copied from interface:TransactionService
synchronously post a transaction for given model with the private key stored in the configuration- Specified by:
blockingPostTransaction
in interfaceTransactionService
- Parameters:
tx
- instance of a specific TransactionModel-class that extendsAbstractTransactionModel
- Returns:
- instance of
PostTransactionResult
-
blockingPostTransaction
Description copied from interface:TransactionService
synchronously post a transaction based on the given signedTx as String- Specified by:
blockingPostTransaction
in interfaceTransactionService
- Parameters:
signedTx
- a signed and encoded transaction- Returns:
- instance of
PostTransactionResult
-
asyncPostTransaction
Description copied from interface:TransactionService
asynchronously post a transaction based on the given signedTx as String- Specified by:
asyncPostTransaction
in interfaceTransactionService
- Parameters:
signedTx
- a signed and encoded transaction- Returns:
- asynchronous result handler (RxJava Single) for
PostTransactionResult
-
blockingPostTransaction
public PostTransactionResult blockingPostTransaction(AbstractTransactionModel<?> tx, java.lang.String privateKey) throws TransactionCreateExceptionDescription copied from interface:TransactionService
synchronously post a transaction for given model- Specified by:
blockingPostTransaction
in interfaceTransactionService
- Parameters:
tx
- instance of a specific TransactionModel-class that extendsAbstractTransactionModel
privateKey
- the privateKey to sign the tx- Returns:
- instance of
PostTransactionResult
- Throws:
TransactionCreateException
-
computeTxHash
public java.lang.String computeTxHash(AbstractTransactionModel<?> tx) throws TransactionCreateExceptionDescription copied from interface:TransactionService
[@PURPOSE-DEBUG] synchronously compute the transaction hash for the given transaction model- Specified by:
computeTxHash
in interfaceTransactionService
- Parameters:
tx
- instance of a specific TransactionModel-class that extendsAbstractTransactionModel
- Returns:
- the hash from a signed and encoded transaction
- Throws:
TransactionCreateException
- if an error occurs
-
computeGAInnerTxHash
public java.lang.String computeGAInnerTxHash(AbstractTransactionModel<?> tx) throws TransactionCreateExceptionDescription copied from interface:TransactionService
synchronously creates an unsigned transaction out of the given AbstractTransactionModel and append network data to the resulting byte array. This hash is intended to be used for generalized accounts which provide their own authentication mechanism- Specified by:
computeGAInnerTxHash
in interfaceTransactionService
- Parameters:
tx
- instance of a specific TransactionModel-class that extendsAbstractTransactionModel
- Returns:
- hash of created unsigned transaction appended with network data
- Throws:
TransactionCreateException
-
blockingCheckTxInPool
- Specified by:
blockingCheckTxInPool
in interfaceTransactionService
- Parameters:
txHash
- the tx-hash of the transaction to be confirmed- Returns:
- info if tx can be included by miners or if it is blocked for some reason
-
signTransaction
public java.lang.String signTransaction(java.lang.String unsignedTx, java.lang.String privateKey) throws TransactionCreateExceptionDescription copied from interface:TransactionService
sign an unsigned transaction with the given private key- Specified by:
signTransaction
in interfaceTransactionService
- Parameters:
unsignedTx
- the encoded unsigned transactionprivateKey
- the encoded private key to sign the transaction- Returns:
- signed and encoded transaction
- Throws:
TransactionCreateException
- if an error occurs
-
signPayingForInnerTransaction
public java.lang.String signPayingForInnerTransaction(AbstractTransactionModel<?> model, java.lang.String privateKey) throws TransactionCreateExceptionDescription copied from interface:TransactionService
sign an unsigned transaction with the given private key. method uses an additional prefix and must be used to sign inner transactions of PayingForTx- Specified by:
signPayingForInnerTransaction
in interfaceTransactionService
- Parameters:
model
- of the inner tx to be signedprivateKey
- the encoded private key to sign the transaction- Returns:
- signed and encoded transaction
- Throws:
TransactionCreateException
- if an error occurs
-
asyncDryRunTransactions
Description copied from interface:TransactionService
asynchronously dry run unsigned transactions to estimate gas (!) please make sure to use implementations ofList
to ensure correct order of transactions called by accounts- Specified by:
asyncDryRunTransactions
in interfaceTransactionService
- Parameters:
input
-DryRunRequest
object- Returns:
- asynchronous result handler (RxJava Single) for
DryRunTransactionResults
-
blockingDryRunContractTx
public DryRunTransactionResult blockingDryRunContractTx(AbstractTransactionModel<?> contractTx, boolean useZeroAddress)Description copied from interface:TransactionService
convenience function to perform a dry-run for a single tx by providing one ofAbstractTransaction
using the zeroAddress for the dry-run MUST be used if no KeyPair is provided in the
ServiceConfiguration
- Specified by:
blockingDryRunContractTx
in interfaceTransactionService
- Parameters:
contractTx
- must be of typeContractCreateTransactionModel
orContractCallTransactionModel
useZeroAddress
- true to use the zero address which makes sense for a non-stateful (ready-only) contract call, false if account in configuration should be used to simulate a stateful tx- Returns:
- instance of
DryRunTransactionResult
if call was successful, otherwise throwsAException
-
blockingDryRunTransactions
Description copied from interface:TransactionService
synchronously dry run unsigned transactions to estimate gas (!) please make sure to use implementations ofList
to ensure correct order of transactions called by accounts- Specified by:
blockingDryRunTransactions
in interfaceTransactionService
- Parameters:
input
- instance ofDryRunRequest
- Returns:
- instance of
DryRunTransactionResults
-
blockingContractCreate
public ContractTxResult blockingContractCreate(java.lang.String sourceCode, ContractTxOptions txOptions)Description copied from interface:TransactionService
convenience method to deploy a contract and return the tx-hash along with the decoded result and other useful information related to the tx. performs following steps under the hood: 1. generate bytecode via compiler, 2. encode calldata via compiler, 3. sign and broadcast the ContractCreateTx with the keyPair configured in theServiceConfiguration
, 4. wait for the tx to be included in a microblock, 5. fetch the tx-info from node, 6. decode result calldata via compiler, 7. return theContractTxResult
- Specified by:
blockingContractCreate
in interfaceTransactionService
- Parameters:
sourceCode
- the source code of the contracttxOptions
- custom tx-options as defined in theContractTxOptions
class- Returns:
- the result of the contract creation (deployment) including the tx-hash and other useful information related to the tx
-
blockingContractCreate
Description copied from interface:TransactionService
convenience method to deploy a contract and return the tx-hash along with the decoded result and other useful information related to the tx. performs following steps under the hood: 1. generate bytecode via compiler, 2. encode calldata via compiler, 3. sign and broadcast the ContractCreateTx with the keyPair configured in theServiceConfiguration
, 4. wait for the tx to be included in a microblock, 5. fetch the tx-info from node, 6. decode result calldata via compiler, 7. return theContractTxResult
- Specified by:
blockingContractCreate
in interfaceTransactionService
- Parameters:
sourceCode
- the source code of the contract- Returns:
- the result of the contract creation (deployment) including the tx-hash and other useful information related to the tx
-
blockingReadOnlyContractCall
public java.lang.Object blockingReadOnlyContractCall(java.lang.String contractId, java.lang.String entrypoint, java.lang.String sourceCode, ContractTxOptions txOptions)Description copied from interface:TransactionService
convenience method to perform a read-only contract call and return the decoded call result. performs following steps under the hood: 1. encode calldata via compiler, 2. dry-run the contract call via node, 3. decode result calldata via compiler- Specified by:
blockingReadOnlyContractCall
in interfaceTransactionService
- Parameters:
contractId
- the id of the contract (ct_...)entrypoint
- the name of the entrypointsourceCode
- the source code of the contracttxOptions
- custom tx-options as defined in theContractTxOptions
class. only the attributes "params" and "filesystem" are relevant here. other attributes will be ignored- Returns:
- the decoded rawResult as String
-
blockingReadOnlyContractCall
public java.lang.Object blockingReadOnlyContractCall(java.lang.String contractId, java.lang.String entrypoint, java.lang.String sourceCode)Description copied from interface:TransactionService
convenience method to perform a read-only contract call and return the decoded call result. performs following steps under the hood: 1. encode calldata via compiler, 2. dry-run the contract call via node, 3. decode result calldata via compiler- Specified by:
blockingReadOnlyContractCall
in interfaceTransactionService
- Parameters:
contractId
- the id of the contract (ct_...)entrypoint
- the name of the entrypointsourceCode
- the source code of the contract- Returns:
- the decoded rawResult as String
-
blockingStatefulContractCall
public ContractTxResult blockingStatefulContractCall(java.lang.String contractId, java.lang.String entrypoint, java.lang.String sourceCode, ContractTxOptions txOptions)Description copied from interface:TransactionService
convenience method to perform a stateful contract call and return the tx-hash along with the decoded result and other useful information related to the tx. performs following steps under the hood: 1. encode calldata via compiler, 2. sign and broadcast the ContractCallTx with the keyPair configured in theServiceConfiguration
, 3. wait for the tx to be included in a microblock, 4. fetch the tx-info from node, 5. decode result calldata via compiler, 6. return theContractTxResult
- Specified by:
blockingStatefulContractCall
in interfaceTransactionService
- Parameters:
contractId
- the id of the contract (ct_...)entrypoint
- the name of the entrypointsourceCode
- the source code of the contracttxOptions
- custom tx-options as defined in theContractTxOptions
class- Returns:
- the result of the contract call including the tx-hash and other useful information related to the tx
-
blockingStatefulContractCall
public ContractTxResult blockingStatefulContractCall(java.lang.String contractId, java.lang.String entrypoint, java.lang.String sourceCode)Description copied from interface:TransactionService
convenience method to perform a stateful contract call and return the tx-hash along with the decoded result and other useful information related to the tx. performs following steps under the hood: 1. encode calldata via compiler, 2. sign and broadcast the ContractCallTx with the keyPair configured in theServiceConfiguration
, 3. wait for the tx to be included in a microblock, 4. fetch the tx-info from node, 5. decode result calldata via compiler, 6. return theContractTxResult
- Specified by:
blockingStatefulContractCall
in interfaceTransactionService
- Parameters:
contractId
- the id of the contract (ct_...)entrypoint
- the name of the entrypointsourceCode
- the source code of the contract- Returns:
- the result of the contract call including the tx-hash and other useful information related to the tx
-
asyncWaitForConfirmation
Description copied from interface:TransactionService
asynchronously wait for a transaction to be confirmedthe number of keyblocks to consider the transaction confirmed is defined in the property numOfConfirmations of the
AeternityServiceConfiguration
(default 10)- Specified by:
asyncWaitForConfirmation
in interfaceTransactionService
- Parameters:
txHash
- the tx-hash of the transaction to be confirmed- Returns:
- the actual
TransactionResult
of the transaction at the confirmation heightNote:
- check getRootErrorMessage(): if a rootErrorMessage is present the transaction is probably not mined.
- check getBlockHeight(): if the blockHeight is -1 it means the transaction isn't mined.
-
asyncWaitForConfirmation
public io.reactivex.Single<TransactionResult> asyncWaitForConfirmation(java.lang.String txHash, int numOfConfirmations)Description copied from interface:TransactionService
asynchronously wait for a transaction to be confirmed- Specified by:
asyncWaitForConfirmation
in interfaceTransactionService
- Parameters:
txHash
- the tx-hash of the transaction to be confirmednumOfConfirmations
- the amount of keyblocks required to consider a transaction to be confirmed/mined- Returns:
- the actual
TransactionResult
of the transaction at the confirmation heightNote: @Override
- check getRootErrorMessage(): if a rootErrorMessage is present the transaction is probably not mined.
- check getBlockHeight():if the blockHeight is -1 it means the transaction isn't mined.
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-