Skip to content

Commit

Permalink
Merge branch 'release-app_5.18' into feature/AND-9180-chia-add-prefix…
Browse files Browse the repository at this point in the history
…-for-reques-params
  • Loading branch information
kozarezvlad authored Nov 26, 2024
2 parents 3c8c8ad + 04ce278 commit 21c1e19
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -71,7 +68,7 @@ class ChiaTransactionBuilder(private val walletPublicKey: ByteArray, val blockch
}

fun buildToSend(signatures: List<ByteArray>) = ChiaTransactionBody(
ChiaSpendBundle(aggregateSignatures(signatures).toHexString(), coinSpends),
ChiaSpendBundle(aggregateSignatures(signatures).toHexString().addHexPrefix(), coinSpends),
)

fun getTransactionCost(amount: Amount): Long {
Expand Down Expand Up @@ -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 = "",
)
}
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 21c1e19

Please sign in to comment.