mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 11:39:22 +00:00
unspent coins info handling improvements
This commit is contained in:
parent
e37adaece0
commit
a337bc1f9e
4 changed files with 18 additions and 18 deletions
|
@ -6,7 +6,7 @@ abstract class BaseBitcoinAddressRecord {
|
|||
BaseBitcoinAddressRecord(
|
||||
this.address, {
|
||||
required this.index,
|
||||
this.isHidden = false,
|
||||
required this.isHidden,
|
||||
int txCount = 0,
|
||||
int balance = 0,
|
||||
String name = '',
|
||||
|
@ -56,7 +56,7 @@ class BitcoinAddressRecord extends BaseBitcoinAddressRecord {
|
|||
BitcoinAddressRecord(
|
||||
super.address, {
|
||||
required super.index,
|
||||
super.isHidden = false,
|
||||
required super.isHidden,
|
||||
super.txCount = 0,
|
||||
super.balance = 0,
|
||||
super.name = '',
|
||||
|
|
|
@ -924,13 +924,13 @@ abstract class ElectrumWalletBase
|
|||
);
|
||||
} else {
|
||||
// Here, lastOutput already is change, return the amount left without the fee to the user's address.
|
||||
updatedOutputs[updatedOutputs.length - 1] = BitcoinOutput(
|
||||
updatedOutputs.last = BitcoinOutput(
|
||||
address: lastOutput.address,
|
||||
value: BigInt.from(amountLeftForChange),
|
||||
isSilentPayment: lastOutput.isSilentPayment,
|
||||
isChange: true,
|
||||
);
|
||||
outputs[outputs.length - 1] = BitcoinOutput(
|
||||
outputs.last = BitcoinOutput(
|
||||
address: lastOutput.address,
|
||||
value: BigInt.from(amountLeftForChange),
|
||||
isSilentPayment: lastOutput.isSilentPayment,
|
||||
|
@ -1377,20 +1377,16 @@ abstract class ElectrumWalletBase
|
|||
updatedUnspentCoins.addAll(await fetchUnspent(address));
|
||||
}));
|
||||
|
||||
unspentCoins = updatedUnspentCoins;
|
||||
|
||||
if (unspentCoinsInfo.length != updatedUnspentCoins.length) {
|
||||
unspentCoins.forEach((coin) => addCoinInfo(coin));
|
||||
return;
|
||||
}
|
||||
|
||||
await updateCoins(unspentCoins);
|
||||
unspentCoins = await updateCoinsWithInfoFromBox(updatedUnspentCoins);
|
||||
await _refreshUnspentCoinsInfo();
|
||||
}
|
||||
|
||||
Future<void> updateCoins(List<BitcoinUnspent> newUnspentCoins) async {
|
||||
Future<List<BitcoinUnspent>> updateCoinsWithInfoFromBox(List<BitcoinUnspent> newUnspentCoins) async {
|
||||
// this function updates and returns unspent coins list (freshly fetched from the server)
|
||||
// with info from the box, if the box doesn't have info for some of the unspents, it adds them to the box
|
||||
|
||||
if (newUnspentCoins.isEmpty) {
|
||||
return;
|
||||
return newUnspentCoins;
|
||||
}
|
||||
|
||||
newUnspentCoins.forEach((coin) {
|
||||
|
@ -1413,12 +1409,14 @@ abstract class ElectrumWalletBase
|
|||
addCoinInfo(coin);
|
||||
}
|
||||
});
|
||||
|
||||
return newUnspentCoins;
|
||||
}
|
||||
|
||||
@action
|
||||
Future<void> updateUnspentsForAddress(BitcoinAddressRecord address) async {
|
||||
final newUnspentCoins = await fetchUnspent(address);
|
||||
await updateCoins(newUnspentCoins);
|
||||
unspentCoins = await updateCoinsWithInfoFromBox(newUnspentCoins);
|
||||
}
|
||||
|
||||
@action
|
||||
|
|
|
@ -837,11 +837,11 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
|||
mwebUnspentCoins.add(unspent);
|
||||
});
|
||||
|
||||
// copy coin control attributes to mwebCoins:
|
||||
await updateCoins(mwebUnspentCoins);
|
||||
// copy coin control attributes to coinsInfo:
|
||||
mwebUnspentCoins = await updateCoinsWithInfoFromBox(mwebUnspentCoins);
|
||||
// get regular ltc unspents (this resets unspentCoins):
|
||||
await super.updateAllUnspents();
|
||||
// add the mwebCoins:
|
||||
// add back the mwebCoins:
|
||||
unspentCoins.addAll(mwebUnspentCoins);
|
||||
}
|
||||
|
||||
|
|
|
@ -106,6 +106,7 @@ abstract class LitecoinWalletAddressesBase extends ElectrumWalletAddresses with
|
|||
index: e.key,
|
||||
type: SegwitAddresType.mweb,
|
||||
network: network,
|
||||
isHidden: false,
|
||||
))
|
||||
.toList();
|
||||
addMwebAddresses(addressRecords);
|
||||
|
@ -195,6 +196,7 @@ abstract class LitecoinWalletAddressesBase extends ElectrumWalletAddresses with
|
|||
index: 0,
|
||||
type: SegwitAddresType.mweb,
|
||||
network: network,
|
||||
isHidden: true,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue