diff --git a/blockchain/src/main/java/com/tangem/blockchain/blockchains/chia/ChiaTransactionBuilder.kt b/blockchain/src/main/java/com/tangem/blockchain/blockchains/chia/ChiaTransactionBuilder.kt index d30b01f1..dc2bf30c 100644 --- a/blockchain/src/main/java/com/tangem/blockchain/blockchains/chia/ChiaTransactionBuilder.kt +++ b/blockchain/src/main/java/com/tangem/blockchain/blockchains/chia/ChiaTransactionBuilder.kt @@ -9,10 +9,7 @@ import com.tangem.blockchain.blockchains.chia.network.ChiaCoin import com.tangem.blockchain.blockchains.chia.network.ChiaCoinSpend import com.tangem.blockchain.blockchains.chia.network.ChiaSpendBundle import com.tangem.blockchain.blockchains.chia.network.ChiaTransactionBody -import com.tangem.blockchain.common.Amount -import com.tangem.blockchain.common.Blockchain -import com.tangem.blockchain.common.BlockchainSdkError -import com.tangem.blockchain.common.TransactionData +import com.tangem.blockchain.common.* import com.tangem.blockchain.extensions.Result import com.tangem.blstlib.generated.P2 import com.tangem.blstlib.generated.P2_Affine @@ -71,7 +68,7 @@ class ChiaTransactionBuilder(private val walletPublicKey: ByteArray, val blockch } fun buildToSend(signatures: List) = ChiaTransactionBody( - ChiaSpendBundle(aggregateSignatures(signatures).toHexString(), coinSpends), + ChiaSpendBundle(aggregateSignatures(signatures).toHexString().addHexPrefix(), coinSpends), ) fun getTransactionCost(amount: Amount): Long { @@ -113,7 +110,7 @@ class ChiaTransactionBuilder(private val walletPublicKey: ByteArray, val blockch val coinSpends = unspentCoins.map { ChiaCoinSpend( coin = it, - puzzleReveal = ChiaAddressService.getPuzzle(walletPublicKey).toHexString(), + puzzleReveal = ChiaAddressService.getPuzzle(walletPublicKey).toHexString().addHexPrefix(), solution = "", ) } @@ -131,10 +128,10 @@ class ChiaTransactionBuilder(private val walletPublicKey: ByteArray, val blockch null } - coinSpends[0].solution = listOfNotNull(sendCondition, changeCondition).toSolution().toHexString() + coinSpends[0].solution = listOfNotNull(sendCondition, changeCondition).toSolution().toHexString().addHexPrefix() for (coinSpend in coinSpends.drop(1)) { - coinSpend.solution = listOf(RemarkCondition()).toSolution().toHexString() + coinSpend.solution = listOf(RemarkCondition()).toSolution().toHexString().addHexPrefix() } return coinSpends @@ -160,6 +157,15 @@ class ChiaTransactionBuilder(private val walletPublicKey: ByteArray, val blockch return P2().hash_to(walletPublicKey + this, AUG_SCHEME_DST, ByteArray(0)).compress() } + private fun String.addHexPrefix(): String { + if (this.isEmpty()) return this + return if (this.startsWith(HEX_PREFIX)) { + this + } else { + HEX_PREFIX + this + } + } + companion object { // costs were calculated with get_fee_estimate API method with real transactions of currently use format private const val COIN_SPEND_COST = 4500000L