mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-10 04:34:34 +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';
|
import 'package:isar/isar.dart';
|
||||||
|
|
||||||
part 'spark_coin.g.dart';
|
part 'spark_coin.g.dart';
|
||||||
|
@ -59,6 +61,19 @@ class SparkCoin {
|
||||||
@ignore
|
@ignore
|
||||||
BigInt get diversifier => BigInt.parse(diversifierIntString);
|
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({
|
SparkCoin({
|
||||||
required this.walletId,
|
required this.walletId,
|
||||||
required this.type,
|
required this.type,
|
||||||
|
|
|
@ -1071,9 +1071,7 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
|
||||||
final spendable = Amount(
|
final spendable = Amount(
|
||||||
rawValue: unusedCoins
|
rawValue: unusedCoins
|
||||||
.where(
|
.where(
|
||||||
(e) =>
|
(e) => e.isConfirmed(currentHeight, cryptoCurrency.minConfirms),
|
||||||
e.height != null &&
|
|
||||||
e.height! + cryptoCurrency.minConfirms <= currentHeight,
|
|
||||||
)
|
)
|
||||||
.map((e) => e.value)
|
.map((e) => e.value)
|
||||||
.fold(BigInt.zero, (prev, e) => prev + e),
|
.fold(BigInt.zero, (prev, e) => prev + e),
|
||||||
|
|
Loading…
Reference in a new issue