mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-26 20:26:02 +00:00
WIP rework of anon balance calc
This commit is contained in:
parent
02fe1103cb
commit
9725ed32be
1 changed files with 40 additions and 47 deletions
|
@ -2432,61 +2432,54 @@ class FiroWallet extends CoinServiceAPI
|
||||||
lelantusCoins.removeWhere((element) =>
|
lelantusCoins.removeWhere((element) =>
|
||||||
element.values.any((elementCoin) => elementCoin.value == 0));
|
element.values.any((elementCoin) => elementCoin.value == 0));
|
||||||
}
|
}
|
||||||
final data = await _txnData;
|
|
||||||
final lData = await db
|
|
||||||
.getTransactions(walletId)
|
|
||||||
.filter()
|
|
||||||
.isLelantusEqualTo(true)
|
|
||||||
.findAll();
|
|
||||||
final currentChainHeight = await chainHeight;
|
final currentChainHeight = await chainHeight;
|
||||||
final jindexes = firoGetJIndex();
|
final jindexes = firoGetJIndex();
|
||||||
int intLelantusBalance = 0;
|
int intLelantusBalance = 0;
|
||||||
int unconfirmedLelantusBalance = 0;
|
int unconfirmedLelantusBalance = 0;
|
||||||
|
|
||||||
for (var element in lelantusCoins) {
|
for (final element in lelantusCoins) {
|
||||||
element.forEach((key, value) {
|
element.forEach((key, lelantusCoin) {
|
||||||
isar_models.Transaction? tx;
|
isar_models.Transaction? txn = db.isar.transactions
|
||||||
try {
|
.where()
|
||||||
tx = data.firstWhere((e) => e.txid == value.txId);
|
.txidWalletIdEqualTo(
|
||||||
} catch (_) {
|
lelantusCoin.txId,
|
||||||
tx = null;
|
walletId,
|
||||||
}
|
)
|
||||||
|
.findFirstSync();
|
||||||
|
|
||||||
isar_models.Transaction? ltx;
|
if (txn == null) {
|
||||||
try {
|
// TODO: ??????????????????????????????????????
|
||||||
ltx = lData.firstWhere((e) => e.txid == value.txId);
|
} else {
|
||||||
} catch (_) {
|
bool isLelantus = txn.isLelantus == true;
|
||||||
ltx = null;
|
if (!jindexes!.contains(lelantusCoin.index) && isLelantus) {
|
||||||
}
|
if (!lelantusCoin.isUsed &&
|
||||||
|
txn.isConfirmed(currentChainHeight, MINIMUM_CONFIRMATIONS)) {
|
||||||
// Logging.instance.log("$value $tx $ltx");
|
|
||||||
if (!jindexes!.contains(value.index) && tx == null) {
|
|
||||||
if (!value.isUsed &&
|
|
||||||
ltx != null &&
|
|
||||||
ltx.isConfirmed(currentChainHeight, MINIMUM_CONFIRMATIONS)) {
|
|
||||||
// mint tx, add value to balance
|
// mint tx, add value to balance
|
||||||
intLelantusBalance += value.value;
|
intLelantusBalance += lelantusCoin.value;
|
||||||
} /* else {
|
} /* else {
|
||||||
// This coin is not confirmed and may be replaced
|
// This coin is not confirmed and may be replaced
|
||||||
}*/
|
}*/
|
||||||
} else if (jindexes.contains(value.index) &&
|
} else if (jindexes.contains(lelantusCoin.index) &&
|
||||||
tx == null &&
|
isLelantus &&
|
||||||
!value.isUsed &&
|
!lelantusCoin.isUsed &&
|
||||||
ltx != null &&
|
!txn.isConfirmed(currentChainHeight, MINIMUM_CONFIRMATIONS)) {
|
||||||
!ltx.isConfirmed(currentChainHeight, MINIMUM_CONFIRMATIONS)) {
|
unconfirmedLelantusBalance += lelantusCoin.value;
|
||||||
unconfirmedLelantusBalance += value.value;
|
} else if (jindexes.contains(lelantusCoin.index) &&
|
||||||
} else if (jindexes.contains(value.index) && !value.isUsed) {
|
!lelantusCoin.isUsed) {
|
||||||
intLelantusBalance += value.value;
|
intLelantusBalance += lelantusCoin.value;
|
||||||
} else if (!value.isUsed &&
|
} else if (!lelantusCoin.isUsed &&
|
||||||
(tx == null
|
(txn.isLelantus == true
|
||||||
? true
|
? true
|
||||||
: tx.isConfirmed(currentChainHeight, MINIMUM_CONFIRMATIONS) !=
|
: txn.isConfirmed(
|
||||||
|
currentChainHeight, MINIMUM_CONFIRMATIONS) !=
|
||||||
false)) {
|
false)) {
|
||||||
intLelantusBalance += value.value;
|
intLelantusBalance += lelantusCoin.value;
|
||||||
} else if (tx != null &&
|
} else if (!isLelantus &&
|
||||||
tx.isConfirmed(currentChainHeight, MINIMUM_CONFIRMATIONS) ==
|
txn.isConfirmed(currentChainHeight, MINIMUM_CONFIRMATIONS) ==
|
||||||
false) {
|
false) {
|
||||||
unconfirmedLelantusBalance += value.value;
|
unconfirmedLelantusBalance += lelantusCoin.value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue