wallet: disable sending to silent payment address

Have `IsValidDestination` return false for silent payment destinations
and set an error string when decoding a silent payment address.

This prevents anyone from sending to a silent payment address before
sending is implemented in the wallet, but also allows the functions to
be used in the unit testing famework.
This commit is contained in:
josibake 2023-09-12 10:26:27 +02:00
parent a72cac6ee1
commit 1a16a7832b
No known key found for this signature in database
GPG key ID: 8ADCB558C4F33D65
2 changed files with 8 additions and 1 deletions

View file

@ -160,7 +160,9 @@ public:
bool operator()(const PubKeyDestination& dest) const { return false; } bool operator()(const PubKeyDestination& dest) const { return false; }
bool operator()(const PKHash& dest) const { return true; } bool operator()(const PKHash& dest) const { return true; }
bool operator()(const ScriptHash& dest) const { return true; } bool operator()(const ScriptHash& dest) const { return true; }
bool operator()(const V0SilentPaymentDestination& dest) const { return true; } // silent payment addresses are not valid until sending support has been implemented
// TODO: set this to true once sending is implemented
bool operator()(const V0SilentPaymentDestination& dest) const { return false; }
bool operator()(const WitnessV0KeyHash& dest) const { return true; } bool operator()(const WitnessV0KeyHash& dest) const { return true; }
bool operator()(const WitnessV0ScriptHash& dest) const { return true; } bool operator()(const WitnessV0ScriptHash& dest) const { return true; }
bool operator()(const WitnessV1Taproot& dest) const { return true; } bool operator()(const WitnessV1Taproot& dest) const { return true; }

View file

@ -174,6 +174,11 @@ CTxDestination DecodeDestination(const std::string& str, const CChainParams& par
} }
CPubKey scan_pubkey{data.begin(), data.begin() + CPubKey::COMPRESSED_SIZE}; CPubKey scan_pubkey{data.begin(), data.begin() + CPubKey::COMPRESSED_SIZE};
CPubKey spend_pubkey{data.begin() + CPubKey::COMPRESSED_SIZE, data.begin() + 2*CPubKey::COMPRESSED_SIZE}; CPubKey spend_pubkey{data.begin() + CPubKey::COMPRESSED_SIZE, data.begin() + 2*CPubKey::COMPRESSED_SIZE};
// This is a bit of a hack to disable silent payments until sending is implemented. The reason we return a V0SilentPaymentDestination
// while also setting an error message is so that we can use DecodeDestination in the unit tests, but also have `validateaddress` fail
// when passed a silent payment address
// TODO: remove this error_str once sending support is implemented
error_str = strprintf("This is a valid Silent Payments v0 address, but sending support is not yet implemented.");
return V0SilentPaymentDestination{scan_pubkey, spend_pubkey}; return V0SilentPaymentDestination{scan_pubkey, spend_pubkey};
} }
// Bech32 decoding // Bech32 decoding