Skip to content

Commit

Permalink
Separate unspendable balance amounts
Browse files Browse the repository at this point in the history
as timeLocked and notRelayed
  • Loading branch information
omurovch committed Mar 28, 2024
1 parent d0d3283 commit 8322e5c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@ class UnspentOutputProvider(
}
}

private fun getUnspendableUtxo(): List<UnspentOutput> {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 8322e5c

Please sign in to comment.