mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-31 06:55:59 +00:00
Update balance
This commit is contained in:
parent
4fc1de8cb6
commit
50ef9185f5
2 changed files with 38 additions and 1 deletions
|
@ -740,7 +740,7 @@ abstract class ElectrumWalletBase
|
||||||
|
|
||||||
Future<String> makePath() async => pathForWallet(name: walletInfo.name, type: walletInfo.type);
|
Future<String> makePath() async => pathForWallet(name: walletInfo.name, type: walletInfo.type);
|
||||||
|
|
||||||
Future<void> updateUnspent() async {
|
Future<void> updateUnspentCoins() async {
|
||||||
List<BitcoinUnspent> updatedUnspentCoins = [];
|
List<BitcoinUnspent> updatedUnspentCoins = [];
|
||||||
|
|
||||||
final addressesSet = walletAddresses.allAddresses.map((addr) => addr.address).toSet();
|
final addressesSet = walletAddresses.allAddresses.map((addr) => addr.address).toSet();
|
||||||
|
@ -759,6 +759,10 @@ abstract class ElectrumWalletBase
|
||||||
}))));
|
}))));
|
||||||
|
|
||||||
unspentCoins = updatedUnspentCoins;
|
unspentCoins = updatedUnspentCoins;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> updateUnspent() async {
|
||||||
|
await updateUnspentCoins();
|
||||||
|
|
||||||
if (unspentCoinsInfo.isEmpty) {
|
if (unspentCoinsInfo.isEmpty) {
|
||||||
unspentCoins.forEach((coin) => _addCoinInfo(coin));
|
unspentCoins.forEach((coin) => _addCoinInfo(coin));
|
||||||
|
|
|
@ -4,6 +4,7 @@ import 'package:crypto/crypto.dart';
|
||||||
import 'package:bitcoin_base/bitcoin_base.dart';
|
import 'package:bitcoin_base/bitcoin_base.dart';
|
||||||
import 'package:cw_bitcoin/bitcoin_mnemonic.dart';
|
import 'package:cw_bitcoin/bitcoin_mnemonic.dart';
|
||||||
import 'package:cw_bitcoin/bitcoin_transaction_priority.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_bitcoin/electrum_transaction_info.dart';
|
||||||
import 'package:cw_core/crypto_currency.dart';
|
import 'package:cw_core/crypto_currency.dart';
|
||||||
import 'package:cw_core/sync_status.dart';
|
import 'package:cw_core/sync_status.dart';
|
||||||
|
@ -169,6 +170,8 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
||||||
outputAddresses: [utxo.address]);
|
outputAddresses: [utxo.address]);
|
||||||
transactionHistory.addOne(tx);
|
transactionHistory.addOne(tx);
|
||||||
await transactionHistory.save();
|
await transactionHistory.save();
|
||||||
|
await updateUnspent();
|
||||||
|
await updateBalance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,6 +213,36 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
||||||
await transactionHistory.save();
|
await transactionHistory.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> 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<void> 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
|
@override
|
||||||
int feeRate(TransactionPriority priority) {
|
int feeRate(TransactionPriority priority) {
|
||||||
if (priority is LitecoinTransactionPriority) {
|
if (priority is LitecoinTransactionPriority) {
|
||||||
|
|
Loading…
Reference in a new issue