From 1e73a517fdd2e74006820055e0facb287cd549e9 Mon Sep 17 00:00:00 2001 From: Matthew Fosse Date: Wed, 11 Sep 2024 08:50:50 -0700 Subject: [PATCH] minor code cleanup --- cw_bitcoin/lib/litecoin_wallet.dart | 39 +++---------------- cw_bitcoin/lib/litecoin_wallet_addresses.dart | 10 +---- 2 files changed, 7 insertions(+), 42 deletions(-) diff --git a/cw_bitcoin/lib/litecoin_wallet.dart b/cw_bitcoin/lib/litecoin_wallet.dart index c5ddad44a..7de93bdf3 100644 --- a/cw_bitcoin/lib/litecoin_wallet.dart +++ b/cw_bitcoin/lib/litecoin_wallet.dart @@ -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 inputAddresses = {}; var output = convert.AccumulatorSink(); 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) { diff --git a/cw_bitcoin/lib/litecoin_wallet_addresses.dart b/cw_bitcoin/lib/litecoin_wallet_addresses.dart index 51944a71c..04a7ab5cc 100644 --- a/cw_bitcoin/lib/litecoin_wallet_addresses.dart +++ b/cw_bitcoin/lib/litecoin_wallet_addresses.dart @@ -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 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;