feat: use silent payment address regex

This commit is contained in:
Rafael Saes 2023-11-30 16:19:15 -03:00
parent 4b3b3f6d2c
commit d3d925c7ff
2 changed files with 4 additions and 5 deletions

View file

@ -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!);
}
});

View file

@ -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 {
}
}
}