fix: incorrect number of confirms for monero (and wownero) outputs and transactions

This commit is contained in:
julian 2025-01-13 17:13:25 -06:00 committed by julian-CStack
parent ad667025ac
commit 0d1bf5895d
3 changed files with 19 additions and 5 deletions

View file

@ -77,7 +77,9 @@ class UTXO {
int getConfirmations(int currentChainHeight) { int getConfirmations(int currentChainHeight) {
if (blockTime == null || blockHash == null) return 0; if (blockTime == null || blockHash == null) return 0;
if (blockHeight == null || blockHeight! <= 0) return 0; if (blockHeight == null || blockHeight! <= 0) return 0;
return max(0, currentChainHeight - (blockHeight! - 1)); return _isMonero()
? max(0, currentChainHeight - (blockHeight!))
: max(0, currentChainHeight - (blockHeight! - 1));
} }
bool isConfirmed( bool isConfirmed(
@ -90,6 +92,11 @@ class UTXO {
(isCoinbase ? minimumCoinbaseConfirms : minimumConfirms); (isCoinbase ? minimumCoinbaseConfirms : minimumConfirms);
} }
// fuzzy
bool _isMonero() {
return keyImage != null;
}
@ignore @ignore
String? get keyImage { String? get keyImage {
if (otherData == null) { if (otherData == null) {
@ -98,7 +105,7 @@ class UTXO {
try { try {
final map = jsonDecode(otherData!) as Map; final map = jsonDecode(otherData!) as Map;
return map["keyImage"] as String; return map[UTXOOtherDataKeys.keyImage] as String;
} catch (_) { } catch (_) {
return null; return null;
} }
@ -169,3 +176,8 @@ class UTXO {
@ignore @ignore
int get hashCode => Object.hashAll([walletId, txid, vout]); int get hashCode => Object.hashAll([walletId, txid, vout]);
} }
abstract final class UTXOOtherDataKeys {
static const keyImage = "keyImage";
static const spent = "spent";
}

View file

@ -109,7 +109,9 @@ class TransactionV2 {
int getConfirmations(int currentChainHeight) { int getConfirmations(int currentChainHeight) {
if (height == null || height! <= 0) return 0; if (height == null || height! <= 0) return 0;
return max(0, currentChainHeight - (height! - 1)); return _isMonero()
? max(0, currentChainHeight - (height!))
: max(0, currentChainHeight - (height! - 1));
} }
bool isConfirmed( bool isConfirmed(

View file

@ -1017,8 +1017,8 @@ abstract class LibMoneroWallet<T extends CryptonoteCurrency>
.findFirst(); .findFirst();
final otherDataMap = { final otherDataMap = {
"keyImage": rawUTXO.keyImage, UTXOOtherDataKeys.keyImage: rawUTXO.keyImage,
"spent": rawUTXO.spent, UTXOOtherDataKeys.spent: rawUTXO.spent,
}; };
final utxo = UTXO( final utxo = UTXO(