fix: spark coin confirmations issue

This commit is contained in:
julian 2024-12-16 19:34:59 -06:00 committed by julian-CStack
parent 1884bfbaf7
commit 2028505367
2 changed files with 16 additions and 3 deletions

View file

@ -1,3 +1,5 @@
import 'dart:math';
import 'package:isar/isar.dart';
part 'spark_coin.g.dart';
@ -59,6 +61,19 @@ class SparkCoin {
@ignore
BigInt get diversifier => BigInt.parse(diversifierIntString);
int getConfirmations(int currentChainHeight) {
if (height == null || height! <= 0) return 0;
return max(0, currentChainHeight - (height! - 1));
}
bool isConfirmed(
int currentChainHeight,
int minimumConfirms,
) {
final confirmations = getConfirmations(currentChainHeight);
return confirmations >= minimumConfirms;
}
SparkCoin({
required this.walletId,
required this.type,

View file

@ -1071,9 +1071,7 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
final spendable = Amount(
rawValue: unusedCoins
.where(
(e) =>
e.height != null &&
e.height! + cryptoCurrency.minConfirms <= currentHeight,
(e) => e.isConfirmed(currentHeight, cryptoCurrency.minConfirms),
)
.map((e) => e.value)
.fold(BigInt.zero, (prev, e) => prev + e),