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 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 interface TransactionService
      Parameters:
      tx - transaction typed model, one of AbstractTransaction
      Returns:
      a single-wrapped unsignedTx object
    • blockingCreateUnsignedTransaction

      public StringResultWrapper blockingCreateUnsignedTransaction​(AbstractTransactionModel<?> tx)
      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 interface TransactionService
      Parameters:
      tx - transaction typed model, one of AbstractTransaction
      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 interface TransactionService
      Parameters:
      tx - instance of a specific TransactionModel-class that extends AbstractTransactionModel
      Returns:
      asynchronous result handler (RxJava Single) for PostTransactionResult
    • asyncPostTransaction

      public io.reactivex.Single<PostTransactionResult> asyncPostTransaction​(AbstractTransactionModel<?> tx, java.lang.String privateKey) throws TransactionCreateException
      Description copied from interface: TransactionService
      asynchronously post a transaction for given model
      Specified by:
      asyncPostTransaction in interface TransactionService
      Parameters:
      tx - instance of a specific TransactionModel-class that extends AbstractTransactionModel
      privateKey - the privateKey to sign the tx
      Returns:
      asynchronous result handler (RxJava Single) for PostTransactionResult
      Throws:
      TransactionCreateException
    • blockingPostTransaction

      public PostTransactionResult blockingPostTransaction​(AbstractTransactionModel<?> tx)
      Description copied from interface: TransactionService
      synchronously post a transaction for given model with the private key stored in the configuration
      Specified by:
      blockingPostTransaction in interface TransactionService
      Parameters:
      tx - instance of a specific TransactionModel-class that extends AbstractTransactionModel
      Returns:
      instance of PostTransactionResult
    • blockingPostTransaction

      public PostTransactionResult blockingPostTransaction​(java.lang.String signedTx)
      Description copied from interface: TransactionService
      synchronously post a transaction based on the given signedTx as String
      Specified by:
      blockingPostTransaction in interface TransactionService
      Parameters:
      signedTx - a signed and encoded transaction
      Returns:
      instance of PostTransactionResult
    • asyncPostTransaction

      public io.reactivex.Single<PostTransactionResult> asyncPostTransaction​(java.lang.String signedTx)
      Description copied from interface: TransactionService
      asynchronously post a transaction based on the given signedTx as String
      Specified by:
      asyncPostTransaction in interface TransactionService
      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 TransactionCreateException
      Description copied from interface: TransactionService
      synchronously post a transaction for given model
      Specified by:
      blockingPostTransaction in interface TransactionService
      Parameters:
      tx - instance of a specific TransactionModel-class that extends AbstractTransactionModel
      privateKey - the privateKey to sign the tx
      Returns:
      instance of PostTransactionResult
      Throws:
      TransactionCreateException
    • computeTxHash

      public java.lang.String computeTxHash​(AbstractTransactionModel<?> tx) throws TransactionCreateException
      Description copied from interface: TransactionService
      [@PURPOSE-DEBUG] synchronously compute the transaction hash for the given transaction model
      Specified by:
      computeTxHash in interface TransactionService
      Parameters:
      tx - instance of a specific TransactionModel-class that extends AbstractTransactionModel
      Returns:
      the hash from a signed and encoded transaction
      Throws:
      TransactionCreateException - if an error occurs
    • computeGAInnerTxHash

      public java.lang.String computeGAInnerTxHash​(AbstractTransactionModel<?> tx) throws TransactionCreateException
      Description 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 interface TransactionService
      Parameters:
      tx - instance of a specific TransactionModel-class that extends AbstractTransactionModel
      Returns:
      hash of created unsigned transaction appended with network data
      Throws:
      TransactionCreateException
    • blockingCheckTxInPool

      public CheckTxInPoolResult blockingCheckTxInPool​(java.lang.String txHash)
      Specified by:
      blockingCheckTxInPool in interface TransactionService
      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 TransactionCreateException
      Description copied from interface: TransactionService
      sign an unsigned transaction with the given private key
      Specified by:
      signTransaction in interface TransactionService
      Parameters:
      unsignedTx - the encoded unsigned transaction
      privateKey - 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 TransactionCreateException
      Description 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 interface TransactionService
      Parameters:
      model - of the inner tx to be signed
      privateKey - the encoded private key to sign the transaction
      Returns:
      signed and encoded transaction
      Throws:
      TransactionCreateException - if an error occurs
    • asyncDryRunTransactions

      public io.reactivex.Single<DryRunTransactionResults> asyncDryRunTransactions​(DryRunRequest input)
      Description copied from interface: TransactionService
      asynchronously dry run unsigned transactions to estimate gas (!) please make sure to use implementations of List to ensure correct order of transactions called by accounts
      Specified by:
      asyncDryRunTransactions in interface TransactionService
      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 of AbstractTransaction

      using the zeroAddress for the dry-run MUST be used if no KeyPair is provided in the ServiceConfiguration

      Specified by:
      blockingDryRunContractTx in interface TransactionService
      Parameters:
      contractTx - must be of type ContractCreateTransactionModel or ContractCallTransactionModel
      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 throws AException
    • blockingDryRunTransactions

      public DryRunTransactionResults blockingDryRunTransactions​(DryRunRequest input)
      Description copied from interface: TransactionService
      synchronously dry run unsigned transactions to estimate gas (!) please make sure to use implementations of List to ensure correct order of transactions called by accounts
      Specified by:
      blockingDryRunTransactions in interface TransactionService
      Parameters:
      input - instance of DryRunRequest
      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 the ServiceConfiguration, 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 the ContractTxResult
      Specified by:
      blockingContractCreate in interface TransactionService
      Parameters:
      sourceCode - the source code of the contract
      txOptions - custom tx-options as defined in the ContractTxOptions class
      Returns:
      the result of the contract creation (deployment) including the tx-hash and other useful information related to the tx
    • blockingContractCreate

      public ContractTxResult blockingContractCreate​(java.lang.String sourceCode)
      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 the ServiceConfiguration, 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 the ContractTxResult
      Specified by:
      blockingContractCreate in interface TransactionService
      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 interface TransactionService
      Parameters:
      contractId - the id of the contract (ct_...)
      entrypoint - the name of the entrypoint
      sourceCode - the source code of the contract
      txOptions - custom tx-options as defined in the ContractTxOptions 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 interface TransactionService
      Parameters:
      contractId - the id of the contract (ct_...)
      entrypoint - the name of the entrypoint
      sourceCode - 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 the ServiceConfiguration, 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 the ContractTxResult
      Specified by:
      blockingStatefulContractCall in interface TransactionService
      Parameters:
      contractId - the id of the contract (ct_...)
      entrypoint - the name of the entrypoint
      sourceCode - the source code of the contract
      txOptions - custom tx-options as defined in the ContractTxOptions 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 the ServiceConfiguration, 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 the ContractTxResult
      Specified by:
      blockingStatefulContractCall in interface TransactionService
      Parameters:
      contractId - the id of the contract (ct_...)
      entrypoint - the name of the entrypoint
      sourceCode - 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

      public io.reactivex.Single<TransactionResult> asyncWaitForConfirmation​(java.lang.String txHash)
      Description copied from interface: TransactionService
      asynchronously wait for a transaction to be confirmed

      the number of keyblocks to consider the transaction confirmed is defined in the property numOfConfirmations of the AeternityServiceConfiguration (default 10)

      Specified by:
      asyncWaitForConfirmation in interface TransactionService
      Parameters:
      txHash - the tx-hash of the transaction to be confirmed
      Returns:
      the actual TransactionResult of the transaction at the confirmation height

      Note:

      - 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 interface TransactionService
      Parameters:
      txHash - the tx-hash of the transaction to be confirmed
      numOfConfirmations - the amount of keyblocks required to consider a transaction to be confirmed/mined
      Returns:
      the actual TransactionResult of the transaction at the confirmation height

      Note: @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 class java.lang.Object