Skip to content

Commit

Permalink
AND-8751 Fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Mama1emon committed Oct 17, 2024
1 parent e91cf88 commit f25f009
Showing 1 changed file with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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?,
Expand All @@ -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)
Expand Down

0 comments on commit f25f009

Please sign in to comment.