minor code cleanup and minor peg-out fix

This commit is contained in:
fossephate 2024-11-04 14:51:27 -08:00
parent d9df5be3af
commit 579b9de496
2 changed files with 1 additions and 11 deletions

View file

@ -1956,10 +1956,9 @@ abstract class ElectrumWalletBase
// that matches this received transaction, mark it as being from a peg out:
for (final tx2 in transactionHistory.transactions.values) {
final heightDiff = ((tx2.height ?? 0) - (tx.height ?? 0)).abs();
// this isn't a perfect matching algorithm since we don't have the right input/output information from these transaction models (the addresses are in different formats), but this should be more than good enough for now as it's extremely unlikely a user receives the EXACT same amount from 2 different sources and one of them is a peg out and the other isn't AND the fees are also exactly the same within 5 blocks of each other
// this isn't a perfect matching algorithm since we don't have the right input/output information from these transaction models (the addresses are in different formats), but this should be more than good enough for now as it's extremely unlikely a user receives the EXACT same amount from 2 different sources and one of them is a peg out and the other isn't WITHIN 5 blocks of each other
if (tx2.additionalInfo["isPegOut"] == true &&
tx2.amount == tx.amount &&
tx2.fee == tx.fee &&
heightDiff <= 5) {
tx.additionalInfo["fromPegOut"] = true;
}

View file

@ -1039,7 +1039,6 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
bool hasMwebInput = false;
bool hasMwebOutput = false;
bool hasRegularInput = false;
bool hasRegularOutput = false;
for (final output in transactionCredentials.outputs) {
@ -1067,9 +1066,6 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
if (utxo.utxo.scriptType == SegwitAddresType.mweb) {
hasMwebInput = true;
}
if (utxo.utxo.scriptType == SegwitAddresType.p2wpkh) {
hasRegularInput = true;
}
}
bool isPegIn = !hasMwebInput && hasMwebOutput;
@ -1127,18 +1123,13 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
return tx
..addListener((transaction) async {
print(
"@@@@@@@@@@@@@@@@@@@@@@@@@############################# transaction: ${transaction.outputAddresses}");
final addresses = <String>{};
transaction.inputAddresses?.forEach((id) async {
print("@@@@@@@@@@@@@@@@@@@@@@@@@ input address: $id");
final utxo = mwebUtxosBox.get(id);
// await mwebUtxosBox.delete(id); // gets deleted in checkMwebUtxosSpent
if (utxo == null) return;
// mark utxo as spent so we add it to the unconfirmed balance (as negative):
utxo.spent = true;
print(
"@@@@@@@@@@@@@@@@@@@@@@@@@ spent utxo: ${utxo.outputId} ${utxo.height} ${utxo.value}");
await mwebUtxosBox.put(id, utxo);
final addressRecord = walletAddresses.allAddresses
.firstWhere((addressRecord) => addressRecord.address == utxo.address);