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

View file

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