From d086e06007b160c14ad0eadfb1d3e8c410c5d640 Mon Sep 17 00:00:00 2001 From: Mama1emon Date: Thu, 17 Oct 2024 11:50:51 +0400 Subject: [PATCH] AND-8751 Fix issues --- .../txbuilder/EthereumTWTransactionBuilder.kt | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/blockchain/src/main/java/com/tangem/blockchain/blockchains/ethereum/txbuilder/EthereumTWTransactionBuilder.kt b/blockchain/src/main/java/com/tangem/blockchain/blockchains/ethereum/txbuilder/EthereumTWTransactionBuilder.kt index 05c74369..62e79b83 100644 --- a/blockchain/src/main/java/com/tangem/blockchain/blockchains/ethereum/txbuilder/EthereumTWTransactionBuilder.kt +++ b/blockchain/src/main/java/com/tangem/blockchain/blockchains/ethereum/txbuilder/EthereumTWTransactionBuilder.kt @@ -222,16 +222,7 @@ internal class EthereumTWTransactionBuilder(wallet: Wallet) : EthereumTransactio .setMaxInclusionFeePerGas(ByteString.copyFrom(fee.priorityFee.toByteArray())) } is Fee.Ethereum.Legacy -> { - val calculateGasPrise = { - val feeValue = fee.amount.value - ?.movePointRight(fee.amount.decimals) - ?.toBigInteger() - ?: error("Transaction fee must be specified") - - feeValue.divide(fee.gasLimit) - } - - val gasPrice = fee.gasPrice.takeUnless(BigInteger::isZero) ?: calculateGasPrise() + val gasPrice = fee.gasPrice.takeUnless(BigInteger::isZero) ?: fee.calculateGasPrice() this .setTxMode(Ethereum.TransactionMode.Legacy) @@ -241,6 +232,15 @@ internal class EthereumTWTransactionBuilder(wallet: Wallet) : EthereumTransactio } } + private fun Fee.Ethereum.Legacy.calculateGasPrice(): BigInteger { + val feeValue = amount.value + ?.movePointRight(amount.decimals) + ?.toBigInteger() + ?: error("Transaction fee must be specified") + + return feeValue.divide(gasLimit) + } + private fun Ethereum.SigningInput.Builder.setTransaction( coinAmount: BigInteger, extras: EthereumTransactionExtras?, @@ -259,15 +259,17 @@ internal class EthereumTWTransactionBuilder(wallet: Wallet) : EthereumTransactio return setContractGeneric( Ethereum.Transaction.ContractGeneric.newBuilder() .setAmount(ByteString.copyFrom(coinAmount.toByteArray())) - .apply { - if (data != null) { - setData(ByteString.copyFrom(data)) - } - } + .setInputIfNotNull(data) .build(), ) } + private fun Ethereum.Transaction.ContractGeneric.Builder.setInputIfNotNull( + data: ByteArray?, + ): Ethereum.Transaction.ContractGeneric.Builder { + return if (data != null) setData(ByteString.copyFrom(data)) else this + } + private fun buildTxCompilerPreSigningOutput(input: Ethereum.SigningInput): PreSigningOutput { val txInputData = input.toByteArray() val preImageHashes = TransactionCompiler.preImageHashes(coinType, txInputData)