minor code cleanup

This commit is contained in:
Matthew Fosse 2024-09-11 08:50:50 -07:00
parent 2573ca6b68
commit 1e73a517fd
2 changed files with 7 additions and 42 deletions

View file

@ -407,8 +407,6 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
);
}
bool isNew = transactionHistory.transactions[tx.id] == null;
// don't update the confirmations if the tx is updated by electrum:
if (tx.confirmations == 0 || utxo.height != 0) {
tx.height = utxo.height;
@ -416,6 +414,8 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
tx.confirmations = confirmations;
}
bool isNew = transactionHistory.transactions[tx.id] == null;
if (!(tx.outputAddresses?.contains(utxo.address) ?? false)) {
tx.outputAddresses?.add(utxo.address);
isNew = true;
@ -458,22 +458,6 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
print("SCANNING FROM HEIGHT: $restoreHeight");
final req = UtxosRequest(scanSecret: scanSecret, fromHeight: restoreHeight);
// process old utxos:
// for (final utxo in mwebUtxosBox.values) {
// if (utxo.address.isEmpty) {
// continue;
// }
// // if (walletInfo.restoreHeight > utxo.height) {
// // continue;
// // }
// // await handleIncoming(utxo, _stub);
// if (utxo.height > walletInfo.restoreHeight) {
// await walletInfo.updateRestoreHeight(utxo.height);
// }
// }
// process new utxos as they come in:
_utxoStream?.cancel();
_utxoStream = _stub.utxos(req).listen((Utxo sUtxo) async {
@ -490,12 +474,6 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
// return;
// }
// if (utxo.address.isEmpty) {
// await updateUnspent();
// await updateBalance();
// initDone = true;
// }
await updateUnspent();
await updateBalance();
@ -521,6 +499,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
.where((tx) => tx.direction == TransactionDirection.outgoing && tx.isPending)
.map(checkPendingTransaction)))
.any((x) => x));
final outputIds =
mwebUtxosBox.values.where((utxo) => utxo.height > 0).map((utxo) => utxo.outputId).toList();
@ -531,10 +510,12 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
final height = await electrumClient.getCurrentBlockChainTip();
if (height == null || status.blockHeaderHeight != height) return;
if (status.mwebUtxosHeight != height) return;
int amount = 0;
Set<String> inputAddresses = {};
var output = convert.AccumulatorSink<Digest>();
var input = sha256.startChunkedConversion(output);
for (final outputId in spent) {
final utxo = mwebUtxosBox.get(outputId);
await mwebUtxosBox.delete(outputId);
@ -549,6 +530,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
inputAddresses.add(utxo.address);
input.add(hex.decode(outputId));
}
if (inputAddresses.isEmpty) return;
input.close();
var digest = output.events.single;
@ -565,7 +547,6 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
inputAddresses: inputAddresses.toList(),
outputAddresses: [],
);
print("BEING ADDED HERE@@@@@@@@@@@@@@@@@@@@@@@2");
transactionHistory.addOne(tx);
await transactionHistory.save();
@ -674,14 +655,6 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
} catch (_) {}
// update unspent balances:
// reset coin balances and txCount to 0:
// unspentCoins.forEach((coin) {
// if (coin.bitcoinAddressRecord is! BitcoinSilentPaymentAddressRecord)
// coin.bitcoinAddressRecord.balance = 0;
// coin.bitcoinAddressRecord.txCount = 0;
// });
await updateUnspent();
for (var addressRecord in walletAddresses.allAddresses) {

View file

@ -1,7 +1,6 @@
import 'dart:async';
import 'dart:typed_data';
import 'package:bech32/bech32.dart';
import 'package:bitcoin_base/bitcoin_base.dart';
import 'package:blockchain_utils/blockchain_utils.dart';
import 'package:cw_bitcoin/bitcoin_address_record.dart';
@ -15,10 +14,6 @@ import 'package:mobx/mobx.dart';
part 'litecoin_wallet_addresses.g.dart';
String encodeMwebAddress(List<int> scriptPubKey) {
return bech32.encode(Bech32("ltcmweb1", scriptPubKey), 250);
}
class LitecoinWalletAddresses = LitecoinWalletAddressesBase with _$LitecoinWalletAddresses;
abstract class LitecoinWalletAddressesBase extends ElectrumWalletAddresses with Store {
@ -32,10 +27,7 @@ abstract class LitecoinWalletAddressesBase extends ElectrumWalletAddresses with
super.initialAddresses,
super.initialRegularAddressIndex,
super.initialChangeAddressIndex,
}) : super(walletInfo) {
// start generating mweb addresses in the background:
// initMwebAddresses();
}
}) : super(walletInfo) {}
final Bip32Slip10Secp256k1 mwebHd;
bool mwebEnabled;