fix: date on silent payments transactions (#2740)

* fix: date on silent payments transactions

* fix: clear outdated Silent Payment Addresses during initialization

* fix: streamline Silent Payments address handling by using the first record only
This commit is contained in:
Konstantin Ullrich
2025-12-20 01:58:41 +02:00
committed by GitHub
parent 6c12ed157d
commit c208e8b5ef
2 changed files with 17 additions and 19 deletions
+5 -11
View File
@@ -40,6 +40,7 @@ import 'package:cw_core/unspent_coins_info.dart';
import 'package:cw_core/utils/print_verbose.dart';
import 'package:cw_core/utils/proxy_wrapper.dart';
import 'package:cw_core/utils/socket_health_logger.dart';
import 'package:cw_core/utils/tor/abstract.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_info.dart';
import 'package:cw_core/wallet_keys_file.dart';
@@ -3009,6 +3010,7 @@ class SyncResponse {
Future<void> _handleScanSilentPayments(ScanData scanData) async {
final shouldUpdateSyncStatus = scanData.rescanHeights == null || scanData.rescanHeights!.isEmpty;
final hasForcedRescanHeights = !shouldUpdateSyncStatus;
CakeTor.instance = await CakeTorInstance.getInstance();
var node = Uri.parse("tcp://electrs.cakewallet.com:50001");
@@ -3204,19 +3206,12 @@ Future<void> _handleScanSilentPayments(ScanData scanData) async {
// So, if blockDate exists, reuse
if (isDateNow) {
try {
final rootURL = "https://cake.mempool.space";
final tweakBlockHash = await ProxyWrapper()
.get(
clearnetUri: Uri.parse(
"https://mempool.cakewallet.com/api/v1/block-height/$tweakHeight",
),
)
.get(clearnetUri: Uri.parse("$rootURL/api/block-height/$tweakHeight"))
.timeout(Duration(seconds: 15));
final blockResponse = await ProxyWrapper()
.get(
clearnetUri: Uri.parse(
"https://mempool.cakewallet.com/api/v1/block/${tweakBlockHash.body}",
),
)
.get(clearnetUri: Uri.parse("$rootURL/api/block/${tweakBlockHash.body}"))
.timeout(Duration(seconds: 15));
if (blockResponse.statusCode == 200 &&
@@ -3242,7 +3237,6 @@ Future<void> _handleScanSilentPayments(ScanData scanData) async {
fee: 0,
direction: TransactionDirection.incoming,
isReplaced: false,
// TODO: fetch block data and get the date from it
date: scanData.network == BitcoinNetwork.mainnet
? (isDateNow ? getDateByBitcoinHeight(tweakHeight) : blockDate)
: DateTime.now(),
+12 -8
View File
@@ -83,6 +83,12 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
network: network,
);
// Clean the Silent Payment Addresses if the initial addresses are the old SP Addresses
if (!silentAddresses
.any((addr) => addr.index == 0 && addr.address == silentAddress.toString())) {
silentAddresses.clear();
}
if (!silentAddresses.any((addr) => addr.index == 0 && addr.isHidden == false))
silentAddresses.add(BitcoinSilentPaymentAddressRecord(
silentAddress.toString(),
@@ -457,19 +463,17 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
addressesMap[address] = 'Active - P2WSH';
}
silentAddresses.forEach((addressRecord) {
if (addressRecord.type != SilentPaymentsAddresType.p2sp || addressRecord.isHidden) {
return;
}
final firstSilentAddressRecord = silentAddresses.firstOrNull;
if (firstSilentAddressRecord != null) {
if (addressRecord.address != address) {
addressesMap[addressRecord.address] = addressRecord.name.isEmpty
if (firstSilentAddressRecord.address != address) {
addressesMap[firstSilentAddressRecord.address] = firstSilentAddressRecord.name.isEmpty
? "Silent Payments"
: "Silent Payments - " + addressRecord.name;
: "Silent Payments - ${firstSilentAddressRecord.name}";
} else {
addressesMap[address] = 'Active - Silent Payments';
}
});
}
}
void addLitecoinAddressTypes() {