From 15549ae15cb8f9f6783b054e4b43cde896d7550d Mon Sep 17 00:00:00 2001 From: iMaks99 Date: Thu, 10 Oct 2024 13:02:40 +0500 Subject: [PATCH] =?UTF-8?q?AND-8727=20Fixed=20=D0=A1an't=20send=20transact?= =?UTF-8?q?ion=20to=20firefly=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../blockchains/chia/ChiaProvidersBuilder.kt | 7 ++++- .../chia/network/ChiaJsonRpcProvider.kt | 30 +++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) 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..8ac4e93fd 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, + providerType = ProviderType.Chia.Tangem, + ) } } @@ -43,6 +47,7 @@ internal class ChiaProvidersBuilder( ChiaJsonRpcProvider( baseUrl = if (isTestnet) API_CHIA_FIREACADEMY_TESTNET else API_CHIA_FIREACADEMY, key = config.chiaFireAcademyApiKey, + providerType = ProviderType.Chia.FireAcademy, ) } } 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..5663d913f 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,7 +2,9 @@ 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.network.providers.ProviderType import com.tangem.blockchain.common.toBlockchainSdkError import com.tangem.blockchain.extensions.Result import com.tangem.blockchain.extensions.SimpleResult @@ -11,7 +13,8 @@ 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, key: String, private val providerType: ProviderType) : + ChiaNetworkProvider { private val api: ChiaApi by lazy { createRetrofitInstance( @@ -62,7 +65,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 (providerType == ProviderType.Chia.FireAcademy) { + transaction.appendHexPrefix() + } else { + transaction + } + + val sendResponse = retryIO { api.sendTransaction(tx) } if (sendResponse.success) { if (sendResponse.status == SUCCESS_STATUS) { SimpleResult.Success @@ -81,6 +90,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)