mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-09 12:19:24 +00:00
fix: spark coin confirmations issue
This commit is contained in:
parent
1884bfbaf7
commit
2028505367
2 changed files with 16 additions and 3 deletions
|
@ -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,
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Reference in a new issue