diff --git a/cw_bitcoin/lib/electrum_wallet.dart b/cw_bitcoin/lib/electrum_wallet.dart index 17e9880e9..6794d93c5 100644 --- a/cw_bitcoin/lib/electrum_wallet.dart +++ b/cw_bitcoin/lib/electrum_wallet.dart @@ -740,7 +740,7 @@ abstract class ElectrumWalletBase Future makePath() async => pathForWallet(name: walletInfo.name, type: walletInfo.type); - Future updateUnspent() async { + Future updateUnspentCoins() async { List updatedUnspentCoins = []; final addressesSet = walletAddresses.allAddresses.map((addr) => addr.address).toSet(); @@ -759,6 +759,10 @@ abstract class ElectrumWalletBase })))); unspentCoins = updatedUnspentCoins; + } + + Future updateUnspent() async { + await updateUnspentCoins(); if (unspentCoinsInfo.isEmpty) { unspentCoins.forEach((coin) => _addCoinInfo(coin)); diff --git a/cw_bitcoin/lib/litecoin_wallet.dart b/cw_bitcoin/lib/litecoin_wallet.dart index 547a2dda5..1ff5b5ac9 100644 --- a/cw_bitcoin/lib/litecoin_wallet.dart +++ b/cw_bitcoin/lib/litecoin_wallet.dart @@ -4,6 +4,7 @@ import 'package:crypto/crypto.dart'; import 'package:bitcoin_base/bitcoin_base.dart'; import 'package:cw_bitcoin/bitcoin_mnemonic.dart'; import 'package:cw_bitcoin/bitcoin_transaction_priority.dart'; +import 'package:cw_bitcoin/bitcoin_unspent.dart'; import 'package:cw_bitcoin/electrum_transaction_info.dart'; import 'package:cw_core/crypto_currency.dart'; import 'package:cw_core/sync_status.dart'; @@ -169,6 +170,8 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store { outputAddresses: [utxo.address]); transactionHistory.addOne(tx); await transactionHistory.save(); + await updateUnspent(); + await updateBalance(); } } @@ -210,6 +213,36 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store { await transactionHistory.save(); } + @override + Future updateUnspentCoins() async { + await super.updateUnspentCoins(); + await checkMwebUtxosSpent(); + final mwebAddrs = (walletAddresses as LitecoinWalletAddresses).mwebAddrs; + mwebUtxos.forEach((outputId, utxo) { + final addressRecord = walletAddresses.allAddresses.firstWhere( + (addressRecord) => addressRecord.address == utxo.address); + unspentCoins.add(BitcoinUnspent(addressRecord, outputId, + utxo.value.toInt(), mwebAddrs.indexOf(utxo.address))); + }); + } + + @override + Future updateBalance() async { + await super.updateBalance(); + var confirmed = balance[currency]!.confirmed; + var unconfirmed = balance[currency]!.unconfirmed; + mwebUtxos.values.forEach((utxo) { + if (utxo.height > 0) + confirmed += utxo.value.toInt(); + else + unconfirmed += utxo.value.toInt(); + }); + balance[currency] = ElectrumBalance( + confirmed: confirmed, unconfirmed: unconfirmed, + frozen: balance[currency]!.frozen); + await save(); + } + @override int feeRate(TransactionPriority priority) { if (priority is LitecoinTransactionPriority) {