diff --git a/blockchain/src/main/java/com/tangem/blockchain/blockchains/chia/ChiaProvidersBuilder.kt b/blockchain/src/main/java/com/tangem/blockchain/blockchains/chia/ChiaProvidersBuilder.kt index 5c5d56b43..d19425123 100644 --- a/blockchain/src/main/java/com/tangem/blockchain/blockchains/chia/ChiaProvidersBuilder.kt +++ b/blockchain/src/main/java/com/tangem/blockchain/blockchains/chia/ChiaProvidersBuilder.kt @@ -34,7 +34,11 @@ internal class ChiaProvidersBuilder( private fun createTangemProvider(): ChiaNetworkProvider? { return config.chiaTangemApiKey?.letNotBlank { - ChiaJsonRpcProvider(baseUrl = API_CHIA_TANGEM, key = it) + ChiaJsonRpcProvider( + baseUrl = API_CHIA_TANGEM, + key = it, + isRequiredHexPrefixForTx = false, + ) } } @@ -43,6 +47,7 @@ internal class ChiaProvidersBuilder( ChiaJsonRpcProvider( baseUrl = if (isTestnet) API_CHIA_FIREACADEMY_TESTNET else API_CHIA_FIREACADEMY, key = config.chiaFireAcademyApiKey, + isRequiredHexPrefixForTx = true, ) } } diff --git a/blockchain/src/main/java/com/tangem/blockchain/blockchains/chia/network/ChiaJsonRpcProvider.kt b/blockchain/src/main/java/com/tangem/blockchain/blockchains/chia/network/ChiaJsonRpcProvider.kt index c4981ae8e..bb14e1c1c 100644 --- a/blockchain/src/main/java/com/tangem/blockchain/blockchains/chia/network/ChiaJsonRpcProvider.kt +++ b/blockchain/src/main/java/com/tangem/blockchain/blockchains/chia/network/ChiaJsonRpcProvider.kt @@ -2,6 +2,7 @@ package com.tangem.blockchain.blockchains.chia.network import com.tangem.blockchain.common.Blockchain import com.tangem.blockchain.common.BlockchainSdkError +import com.tangem.blockchain.common.HEX_PREFIX import com.tangem.blockchain.common.logging.AddHeaderInterceptor import com.tangem.blockchain.common.toBlockchainSdkError import com.tangem.blockchain.extensions.Result @@ -11,7 +12,12 @@ import com.tangem.blockchain.network.createRetrofitInstance import java.math.BigDecimal import java.math.RoundingMode -open class ChiaJsonRpcProvider(override val baseUrl: String, key: String) : ChiaNetworkProvider { +open class ChiaJsonRpcProvider( + override val baseUrl: String, + private val isRequiredHexPrefixForTx: Boolean, + key: String, +) : + ChiaNetworkProvider { private val api: ChiaApi by lazy { createRetrofitInstance( @@ -62,7 +68,13 @@ open class ChiaJsonRpcProvider(override val baseUrl: String, key: String) : Chia override suspend fun sendTransaction(transaction: ChiaTransactionBody): SimpleResult { return try { - val sendResponse = retryIO { api.sendTransaction(transaction) } + val tx = if (isRequiredHexPrefixForTx) { + transaction.appendHexPrefix() + } else { + transaction + } + + val sendResponse = retryIO { api.sendTransaction(tx) } if (sendResponse.success) { if (sendResponse.status == SUCCESS_STATUS) { SimpleResult.Success @@ -81,6 +93,23 @@ open class ChiaJsonRpcProvider(override val baseUrl: String, key: String) : Chia } } + private fun ChiaTransactionBody.appendHexPrefix(): ChiaTransactionBody { + val aggregatedSignature = spendBundle.aggregatedSignature + val coinSpends = spendBundle.coinSpends + return copy( + spendBundle = spendBundle.copy( + aggregatedSignature = "$HEX_PREFIX$aggregatedSignature", + coinSpends = coinSpends.map { + ChiaCoinSpend( + coin = it.coin, + puzzleReveal = "$HEX_PREFIX${it.puzzleReveal}", + solution = "$HEX_PREFIX${it.solution}", + ) + }, + ), + ) + } + companion object { // time in seconds, 1 minute only, 5 minutes gives bad estimate now private val ESTIMATE_FEE_TARGET_TIMES = listOf(60)