From d3d925c7ff78c1de807b32b575cdd3a6f4f9ae57 Mon Sep 17 00:00:00 2001 From: Rafael Saes Date: Thu, 30 Nov 2023 16:19:15 -0300 Subject: [PATCH] feat: use silent payment address regex --- cw_bitcoin/lib/electrum_wallet.dart | 5 +++-- lib/core/address_validator.dart | 4 +--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/cw_bitcoin/lib/electrum_wallet.dart b/cw_bitcoin/lib/electrum_wallet.dart index cdb2d03bd..4e8c2e945 100644 --- a/cw_bitcoin/lib/electrum_wallet.dart +++ b/cw_bitcoin/lib/electrum_wallet.dart @@ -465,11 +465,12 @@ abstract class ElectrumWalletBase final outputAmount = hasMultiDestination ? item.formattedCryptoAmount : amount; final outputAddress = item.isParsedAddress ? item.extractedAddress! : item.address; - // TODO: silent payments regex - if (outputAddress.startsWith('tsp1')) { + if (bitcoin.SilentPaymentAddress.REGEX.hasMatch(outputAddress)) { + // Add all silent payment destinations to a list and generate outputs later silentPaymentDestinations .add(bitcoin.SilentPaymentDestination.fromAddress(outputAddress, outputAmount!)); } else { + // Add all non-silent payment destinations to the transaction txb.addOutput(addressToOutputScript(outputAddress, networkType), outputAmount!); } }); diff --git a/lib/core/address_validator.dart b/lib/core/address_validator.dart index 290177c03..2f2a3e381 100644 --- a/lib/core/address_validator.dart +++ b/lib/core/address_validator.dart @@ -24,8 +24,7 @@ class AddressValidator extends TextValidator { return '^[0-9a-zA-Z]{59}\$|^[0-9a-zA-Z]{92}\$|^[0-9a-zA-Z]{104}\$' '|^[0-9a-zA-Z]{105}\$|^addr1[0-9a-zA-Z]{98}\$'; case CryptoCurrency.btc: - final silentpayments = '^tsp1[0-9a-zA-Z]{113}\$'; - return '${bitcoin.P2pkhAddress.REGEX.pattern}|${bitcoin.P2shAddress.REGEX.pattern}|${bitcoin.P2wpkhAddress.REGEX.pattern}|${bitcoin.P2trAddress.REGEX.pattern}|$silentpayments'; + return '${bitcoin.P2pkhAddress.REGEX.pattern}|${bitcoin.P2shAddress.REGEX.pattern}|${bitcoin.P2wpkhAddress.REGEX.pattern}|${bitcoin.P2trAddress.REGEX.pattern}|${bitcoin.SilentPaymentAddress.REGEX.pattern}'; case CryptoCurrency.nano: case CryptoCurrency.nano: return '[0-9a-zA-Z_]'; @@ -286,4 +285,3 @@ class AddressValidator extends TextValidator { } } } -