From 4e84596892c19421759086434a6c9240278903b2 Mon Sep 17 00:00:00 2001 From: Steven Roose Date: Wed, 12 Jun 2019 22:23:28 +0100 Subject: [PATCH] Always return blind address for "blech32" type Even when -blindedaddresses=0. --- src/wallet/rpcwallet.cpp | 14 ++++++++++++-- test/functional/wallet_address_types.py | 10 ++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index beada87e18..64095a0129 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -206,10 +206,15 @@ static UniValue getnewaddress(const JSONRPCRequest& request) label = LabelFromValue(request.params[0]); OutputType output_type = pwallet->m_default_address_type; + bool force_blind = false; if (!request.params[1].isNull()) { if (!ParseOutputType(request.params[1].get_str(), output_type)) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Unknown address type '%s'", request.params[1].get_str())); } + // Special case for "blech32" when `-blindedaddresses=0` in the config. + if (request.params[1].get_str() == "blech32") { + force_blind = true; + } } if (!pwallet->IsLocked()) { @@ -223,7 +228,7 @@ static UniValue getnewaddress(const JSONRPCRequest& request) } pwallet->LearnRelatedScripts(newKey, output_type); CTxDestination dest = GetDestinationForKey(newKey, output_type); - if (gArgs.GetBoolArg("-blindedaddresses", g_con_elementsmode)) { + if (gArgs.GetBoolArg("-blindedaddresses", g_con_elementsmode) || force_blind) { CPubKey blinding_pubkey = pwallet->GetBlindingPubKey(GetScriptForDestination(dest)); dest = GetDestinationForKey(newKey, output_type, blinding_pubkey); } @@ -270,10 +275,15 @@ static UniValue getrawchangeaddress(const JSONRPCRequest& request) } OutputType output_type = pwallet->m_default_change_type != OutputType::CHANGE_AUTO ? pwallet->m_default_change_type : pwallet->m_default_address_type; + bool force_blind = false; if (!request.params[0].isNull()) { if (!ParseOutputType(request.params[0].get_str(), output_type)) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Unknown address type '%s'", request.params[0].get_str())); } + // Special case for "blech32" when `-blindedaddresses=0` in the config. + if (request.params[0].get_str() == "blech32") { + force_blind = true; + } } CReserveKey reservekey(pwallet); @@ -285,7 +295,7 @@ static UniValue getrawchangeaddress(const JSONRPCRequest& request) pwallet->LearnRelatedScripts(vchPubKey, output_type); CTxDestination dest = GetDestinationForKey(vchPubKey, output_type); - if (gArgs.GetBoolArg("-blindedaddresses", g_con_elementsmode)) { + if (gArgs.GetBoolArg("-blindedaddresses", g_con_elementsmode) || force_blind) { CPubKey blinding_pubkey = pwallet->GetBlindingPubKey(GetScriptForDestination(dest)); dest = GetDestinationForKey(vchPubKey, output_type, blinding_pubkey); } diff --git a/test/functional/wallet_address_types.py b/test/functional/wallet_address_types.py index 1839fecc69..5075dd81cb 100755 --- a/test/functional/wallet_address_types.py +++ b/test/functional/wallet_address_types.py @@ -369,5 +369,15 @@ class AddressTypeTest(BitcoinTestFramework): self.test_address(4, self.nodes[4].getrawchangeaddress(), multisig=False, typ='p2sh-segwit') self.test_address(4, self.nodes[4].getrawchangeaddress('bech32'), multisig=False, typ='bech32') + # test blech32 addresses + info_unblinded = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress("", "bech32")) + assert(len(info_unblinded["confidential_key"]) == 0) + # getnewaddress + info1 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress("", "blech32")) + assert(len(info1["confidential_key"]) > 0) + # getrawchangeaddress + info2 = self.nodes[0].getaddressinfo(self.nodes[0].getrawchangeaddress("blech32")) + assert(len(info2["confidential_key"]) > 0) + if __name__ == '__main__': AddressTypeTest().main()