mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 19:49: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(
|
BaseBitcoinAddressRecord(
|
||||||
this.address, {
|
this.address, {
|
||||||
required this.index,
|
required this.index,
|
||||||
this.isHidden = false,
|
required this.isHidden,
|
||||||
int txCount = 0,
|
int txCount = 0,
|
||||||
int balance = 0,
|
int balance = 0,
|
||||||
String name = '',
|
String name = '',
|
||||||
|
@ -56,7 +56,7 @@ class BitcoinAddressRecord extends BaseBitcoinAddressRecord {
|
||||||
BitcoinAddressRecord(
|
BitcoinAddressRecord(
|
||||||
super.address, {
|
super.address, {
|
||||||
required super.index,
|
required super.index,
|
||||||
super.isHidden = false,
|
required super.isHidden,
|
||||||
super.txCount = 0,
|
super.txCount = 0,
|
||||||
super.balance = 0,
|
super.balance = 0,
|
||||||
super.name = '',
|
super.name = '',
|
||||||
|
|
|
@ -924,13 +924,13 @@ abstract class ElectrumWalletBase
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// Here, lastOutput already is change, return the amount left without the fee to the user's address.
|
// 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,
|
address: lastOutput.address,
|
||||||
value: BigInt.from(amountLeftForChange),
|
value: BigInt.from(amountLeftForChange),
|
||||||
isSilentPayment: lastOutput.isSilentPayment,
|
isSilentPayment: lastOutput.isSilentPayment,
|
||||||
isChange: true,
|
isChange: true,
|
||||||
);
|
);
|
||||||
outputs[outputs.length - 1] = BitcoinOutput(
|
outputs.last = BitcoinOutput(
|
||||||
address: lastOutput.address,
|
address: lastOutput.address,
|
||||||
value: BigInt.from(amountLeftForChange),
|
value: BigInt.from(amountLeftForChange),
|
||||||
isSilentPayment: lastOutput.isSilentPayment,
|
isSilentPayment: lastOutput.isSilentPayment,
|
||||||
|
@ -1377,20 +1377,16 @@ abstract class ElectrumWalletBase
|
||||||
updatedUnspentCoins.addAll(await fetchUnspent(address));
|
updatedUnspentCoins.addAll(await fetchUnspent(address));
|
||||||
}));
|
}));
|
||||||
|
|
||||||
unspentCoins = updatedUnspentCoins;
|
unspentCoins = await updateCoinsWithInfoFromBox(updatedUnspentCoins);
|
||||||
|
|
||||||
if (unspentCoinsInfo.length != updatedUnspentCoins.length) {
|
|
||||||
unspentCoins.forEach((coin) => addCoinInfo(coin));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await updateCoins(unspentCoins);
|
|
||||||
await _refreshUnspentCoinsInfo();
|
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) {
|
if (newUnspentCoins.isEmpty) {
|
||||||
return;
|
return newUnspentCoins;
|
||||||
}
|
}
|
||||||
|
|
||||||
newUnspentCoins.forEach((coin) {
|
newUnspentCoins.forEach((coin) {
|
||||||
|
@ -1413,12 +1409,14 @@ abstract class ElectrumWalletBase
|
||||||
addCoinInfo(coin);
|
addCoinInfo(coin);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return newUnspentCoins;
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
Future<void> updateUnspentsForAddress(BitcoinAddressRecord address) async {
|
Future<void> updateUnspentsForAddress(BitcoinAddressRecord address) async {
|
||||||
final newUnspentCoins = await fetchUnspent(address);
|
final newUnspentCoins = await fetchUnspent(address);
|
||||||
await updateCoins(newUnspentCoins);
|
unspentCoins = await updateCoinsWithInfoFromBox(newUnspentCoins);
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
|
|
|
@ -837,11 +837,11 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
||||||
mwebUnspentCoins.add(unspent);
|
mwebUnspentCoins.add(unspent);
|
||||||
});
|
});
|
||||||
|
|
||||||
// copy coin control attributes to mwebCoins:
|
// copy coin control attributes to coinsInfo:
|
||||||
await updateCoins(mwebUnspentCoins);
|
mwebUnspentCoins = await updateCoinsWithInfoFromBox(mwebUnspentCoins);
|
||||||
// get regular ltc unspents (this resets unspentCoins):
|
// get regular ltc unspents (this resets unspentCoins):
|
||||||
await super.updateAllUnspents();
|
await super.updateAllUnspents();
|
||||||
// add the mwebCoins:
|
// add back the mwebCoins:
|
||||||
unspentCoins.addAll(mwebUnspentCoins);
|
unspentCoins.addAll(mwebUnspentCoins);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -106,6 +106,7 @@ abstract class LitecoinWalletAddressesBase extends ElectrumWalletAddresses with
|
||||||
index: e.key,
|
index: e.key,
|
||||||
type: SegwitAddresType.mweb,
|
type: SegwitAddresType.mweb,
|
||||||
network: network,
|
network: network,
|
||||||
|
isHidden: false,
|
||||||
))
|
))
|
||||||
.toList();
|
.toList();
|
||||||
addMwebAddresses(addressRecords);
|
addMwebAddresses(addressRecords);
|
||||||
|
@ -195,6 +196,7 @@ abstract class LitecoinWalletAddressesBase extends ElectrumWalletAddresses with
|
||||||
index: 0,
|
index: 0,
|
||||||
type: SegwitAddresType.mweb,
|
type: SegwitAddresType.mweb,
|
||||||
network: network,
|
network: network,
|
||||||
|
isHidden: true,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue