From d053c3af90324df4fddc57c8301fcf414019d726 Mon Sep 17 00:00:00 2001 From: josibake Date: Tue, 12 Sep 2023 10:26:27 +0200 Subject: [PATCH] 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. --- src/addresstype.cpp | 4 +++- src/key_io.cpp | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/addresstype.cpp b/src/addresstype.cpp index 16d5f0d81be704..49592519439193 100644 --- a/src/addresstype.cpp +++ b/src/addresstype.cpp @@ -156,7 +156,9 @@ class ValidDestinationVisitor bool operator()(const PubKeyDestination& dest) const { return false; } bool operator()(const PKHash& 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 WitnessV0ScriptHash& dest) const { return true; } bool operator()(const WitnessV1Taproot& dest) const { return true; } diff --git a/src/key_io.cpp b/src/key_io.cpp index 805a29878a1ac9..b12e84f9848fca 100644 --- a/src/key_io.cpp +++ b/src/key_io.cpp @@ -173,6 +173,11 @@ CTxDestination DecodeDestination(const std::string& str, const CChainParams& par } CPubKey scan_pubkey{data.begin(), data.begin() + 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}; } // Bech32 decoding