mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-23 03:59:23 +00:00
fix: unspents & balance updating
This commit is contained in:
parent
f446f95a01
commit
9d6b90759c
1 changed files with 14 additions and 12 deletions
|
@ -181,11 +181,10 @@ abstract class ElectrumWalletBase
|
||||||
await for (var message in receivePort) {
|
await for (var message in receivePort) {
|
||||||
if (message is BitcoinUnspent) {
|
if (message is BitcoinUnspent) {
|
||||||
unspentCoins.add(message);
|
unspentCoins.add(message);
|
||||||
_addCoinInfo(message);
|
await _addCoinInfo(message);
|
||||||
|
balance[currency] = await _fetchBalances();
|
||||||
await walletInfo.save();
|
await walletInfo.save();
|
||||||
await save();
|
await save();
|
||||||
|
|
||||||
_subscribeForUpdates();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if is a SyncStatus type since "is SyncStatus" doesn't work here
|
// check if is a SyncStatus type since "is SyncStatus" doesn't work here
|
||||||
|
@ -856,20 +855,22 @@ abstract class ElectrumWalletBase
|
||||||
}
|
}
|
||||||
|
|
||||||
var totalFrozen = 0;
|
var totalFrozen = 0;
|
||||||
|
var totalConfirmed = 0;
|
||||||
|
var totalUnconfirmed = 0;
|
||||||
|
|
||||||
unspentCoinsInfo.values.forEach((info) {
|
unspentCoinsInfo.values.forEach((info) {
|
||||||
unspentCoins.forEach((element) {
|
unspentCoins.forEach((element) {
|
||||||
if (element.hash == info.hash &&
|
if (element.hash == info.hash &&
|
||||||
info.isFrozen &&
|
|
||||||
element.bitcoinAddressRecord.address == info.address &&
|
element.bitcoinAddressRecord.address == info.address &&
|
||||||
element.value == info.value) {
|
element.value == info.value) {
|
||||||
totalFrozen += element.value;
|
if (info.isFrozen) totalFrozen += element.value;
|
||||||
|
if (element.bitcoinAddressRecord.silentPaymentTweak != null)
|
||||||
|
totalConfirmed += element.value;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
final balances = await Future.wait(balanceFutures);
|
final balances = await Future.wait(balanceFutures);
|
||||||
var totalConfirmed = 0;
|
|
||||||
var totalUnconfirmed = 0;
|
|
||||||
|
|
||||||
for (var i = 0; i < balances.length; i++) {
|
for (var i = 0; i < balances.length; i++) {
|
||||||
final addressRecord = addresses[i];
|
final addressRecord = addresses[i];
|
||||||
|
@ -1160,7 +1161,7 @@ Future<void> startRefresh(ScanData scanData) async {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<Uint8List, bitcoin.Outpoint> outpointsByP2TRpubkey = {};
|
Map<String, bitcoin.Outpoint> outpointsByP2TRpubkey = {};
|
||||||
for (var i = 0; i < (tx["vout"] as List<dynamic>).length; i++) {
|
for (var i = 0; i < (tx["vout"] as List<dynamic>).length; i++) {
|
||||||
final output = tx["vout"][i];
|
final output = tx["vout"][i];
|
||||||
if (output["scriptpubkey_type"] != "v1_p2tr") {
|
if (output["scriptpubkey_type"] != "v1_p2tr") {
|
||||||
|
@ -1185,7 +1186,7 @@ Future<void> startRefresh(ScanData scanData) async {
|
||||||
|
|
||||||
// print(["Verifying taproot address:", address]);
|
// print(["Verifying taproot address:", address]);
|
||||||
|
|
||||||
outpointsByP2TRpubkey[script.sublist(2)] =
|
outpointsByP2TRpubkey[script.sublist(2).hex] =
|
||||||
bitcoin.Outpoint(txid: txid, index: i, value: output["value"] as int);
|
bitcoin.Outpoint(txid: txid, index: i, value: output["value"] as int);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1203,7 +1204,7 @@ Future<void> startRefresh(ScanData scanData) async {
|
||||||
bitcoin.PublicKey.fromHex(curve, scanData.spendPubkeyCompressed.hex),
|
bitcoin.PublicKey.fromHex(curve, scanData.spendPubkeyCompressed.hex),
|
||||||
bitcoin.getSumInputPubKeys(pubkeys),
|
bitcoin.getSumInputPubKeys(pubkeys),
|
||||||
outpointHash,
|
outpointHash,
|
||||||
outpointsByP2TRpubkey.keys.toList(),
|
outpointsByP2TRpubkey.keys.map((e) => e.fromHex).toList(),
|
||||||
labels: scanData.labels,
|
labels: scanData.labels,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1220,7 +1221,7 @@ Future<void> startRefresh(ScanData scanData) async {
|
||||||
print(result);
|
print(result);
|
||||||
|
|
||||||
result.forEach((key, value) {
|
result.forEach((key, value) {
|
||||||
final outpoint = outpointsByP2TRpubkey[key.fromHex];
|
final outpoint = outpointsByP2TRpubkey[key];
|
||||||
|
|
||||||
if (outpoint == null) {
|
if (outpoint == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -1229,7 +1230,8 @@ Future<void> startRefresh(ScanData scanData) async {
|
||||||
// found utxo for tx
|
// found utxo for tx
|
||||||
scanData.sendPort.send(BitcoinUnspent(
|
scanData.sendPort.send(BitcoinUnspent(
|
||||||
BitcoinAddressRecord(
|
BitcoinAddressRecord(
|
||||||
key,
|
bitcoin.P2trAddress(program: key, network: scanData.networkType)
|
||||||
|
.toAddress(scanData.networkType),
|
||||||
index: 0,
|
index: 0,
|
||||||
isHidden: false,
|
isHidden: false,
|
||||||
isUsed: true,
|
isUsed: true,
|
||||||
|
|
Loading…
Reference in a new issue