From bff205bacf017fe732d1dfc2de3fa6125421e386 Mon Sep 17 00:00:00 2001 From: chyngyz Date: Wed, 27 Mar 2024 18:17:37 +0600 Subject: [PATCH] Separate unspendable balance amounts as timeLocked and notRelayed --- .../bitcoinkit/demo/BalanceFragment.kt | 2 +- .../bitcoincore/managers/UnspentOutputProvider.kt | 15 +++++++++------ .../bitcoincore/models/TransactionInfo.kt | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/horizontalsystems/bitcoinkit/demo/BalanceFragment.kt b/app/src/main/java/io/horizontalsystems/bitcoinkit/demo/BalanceFragment.kt index 3fac4efd..cbe0f98a 100644 --- a/app/src/main/java/io/horizontalsystems/bitcoinkit/demo/BalanceFragment.kt +++ b/app/src/main/java/io/horizontalsystems/bitcoinkit/demo/BalanceFragment.kt @@ -41,7 +41,7 @@ class BalanceFragment : Fragment() { } else -> { balanceValue.text = NumberFormatHelper.cryptoAmountFormat.format(balance.spendable / 100_000_000.0) - balanceUnspendableValue.text = NumberFormatHelper.cryptoAmountFormat.format(balance.unspendable / 100_000_000.0) + balanceUnspendableValue.text = NumberFormatHelper.cryptoAmountFormat.format((balance.unspendableTimeLocked + balance.unspendableNotRelayed) / 100_000_000.0) } } }) diff --git a/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/managers/UnspentOutputProvider.kt b/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/managers/UnspentOutputProvider.kt index a3d0e3ac..81e63953 100644 --- a/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/managers/UnspentOutputProvider.kt +++ b/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/managers/UnspentOutputProvider.kt @@ -18,17 +18,20 @@ class UnspentOutputProvider( } } - private fun getUnspendableUtxo(): List { - return allUtxo().filter { - !pluginManager.isSpendable(it) || it.transaction.status != Transaction.Status.RELAYED - } + private fun getUnspendableTimeLockedUtxo() = allUtxo().filter { + !pluginManager.isSpendable(it) + } + + private fun getUnspendableNotRelayedUtxo() = allUtxo().filter { + it.transaction.status != Transaction.Status.RELAYED } fun getBalance(): BalanceInfo { val spendable = getSpendableUtxo().sumOf { it.output.value } - val unspendable = getUnspendableUtxo().sumOf { it.output.value } + val unspendableTimeLocked = getUnspendableTimeLockedUtxo().sumOf { it.output.value } + val unspendableNotRelayed = getUnspendableNotRelayedUtxo().sumOf { it.output.value } - return BalanceInfo(spendable, unspendable) + return BalanceInfo(spendable, unspendableTimeLocked, unspendableNotRelayed) } // Only confirmed spendable outputs diff --git a/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/models/TransactionInfo.kt b/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/models/TransactionInfo.kt index 6b4c014f..3bea1fd6 100644 --- a/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/models/TransactionInfo.kt +++ b/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/models/TransactionInfo.kt @@ -187,4 +187,4 @@ data class BlockInfo( val timestamp: Long ) -data class BalanceInfo(val spendable: Long, val unspendable: Long) +data class BalanceInfo(val spendable: Long, val unspendableTimeLocked: Long, val unspendableNotRelayed: Long)