From c208e8b5ef64f7999b19242912e50554661daa75 Mon Sep 17 00:00:00 2001 From: Konstantin Ullrich Date: Sat, 20 Dec 2025 00:58:41 +0100 Subject: [PATCH] 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 --- cw_bitcoin/lib/electrum_wallet.dart | 16 +++++---------- cw_bitcoin/lib/electrum_wallet_addresses.dart | 20 +++++++++++-------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/cw_bitcoin/lib/electrum_wallet.dart b/cw_bitcoin/lib/electrum_wallet.dart index 298ccc5d0..08ca9f234 100644 --- a/cw_bitcoin/lib/electrum_wallet.dart +++ b/cw_bitcoin/lib/electrum_wallet.dart @@ -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 _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 _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 _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(), diff --git a/cw_bitcoin/lib/electrum_wallet_addresses.dart b/cw_bitcoin/lib/electrum_wallet_addresses.dart index e91428717..d4927e7a2 100644 --- a/cw_bitcoin/lib/electrum_wallet_addresses.dart +++ b/cw_bitcoin/lib/electrum_wallet_addresses.dart @@ -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() {