Skip to content

Commit 6802564

Browse files
authored
Merge pull request #1246 from delta1/issue-1245
fix: getnewaddress - don't blind bech32 addresses
2 parents cfc10a5 + 49c3ea3 commit 6802564

4 files changed

+18
-15
lines changed

src/wallet/rpcwallet.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -294,23 +294,27 @@ static RPCHelpMan getnewaddress()
294294
label = LabelFromValue(request.params[0]);
295295

296296
OutputType output_type = pwallet->m_default_address_type;
297-
bool force_blind = false;
297+
// default blinding to the blindedaddresses setting
298+
bool add_blinding_key = gArgs.GetBoolArg("-blindedaddresses", g_con_elementsmode);
299+
298300
if (!request.params[1].isNull()) {
299301
if (!ParseOutputType(request.params[1].get_str(), output_type)) {
300302
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Unknown address type '%s'", request.params[1].get_str()));
301303
}
302304
if (output_type == OutputType::BECH32M && pwallet->GetLegacyScriptPubKeyMan()) {
303305
throw JSONRPCError(RPC_INVALID_PARAMETER, "Legacy wallets cannot provide bech32m addresses");
304306
}
305-
// Special case for "blech32" when `-blindedaddresses=0` in the config.
306307
if (request.params[1].get_str() == "blech32") {
307-
force_blind = true;
308+
// always blind for "blech32" even if `-blindedaddresses=0` in the config.
309+
add_blinding_key = true;
310+
} else if (request.params[1].get_str() == "bech32") {
311+
// never blind for "bech32"
312+
add_blinding_key = false;
308313
}
309314
}
310315

311316
CTxDestination dest;
312317
std::string error;
313-
bool add_blinding_key = force_blind || gArgs.GetBoolArg("-blindedaddresses", g_con_elementsmode);
314318
if (!pwallet->GetNewDestination(output_type, label, dest, error, add_blinding_key)) {
315319
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, error);
316320
}

test/functional/feature_confidential_transactions.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ def run_test(self):
164164
self.test_wallet_recovery()
165165

166166
print("Test blech32 python roundtrip")
167-
# blech/bech are aliased, both are blech32
168-
for addrtype in ["bech32", "blech32"]:
169-
addr_to_rt = self.nodes[0].getnewaddress("", addrtype)
170-
hrp = addr_to_rt[:2]
171-
assert_equal(hrp, "el")
172-
(witver, witprog) = decode(hrp, addr_to_rt)
173-
assert_equal(encode(hrp, witver, witprog), addr_to_rt)
167+
# test only blech32, since getnewaddress for bech32 was changed to return an unblinded address
168+
addr_to_rt = self.nodes[0].getnewaddress("", "blech32")
169+
hrp = addr_to_rt[:2]
170+
assert_equal(hrp, "el")
171+
172+
(witver, witprog) = decode(hrp, addr_to_rt)
173+
assert_equal(encode(hrp, witver, witprog), addr_to_rt)
174174

175175
# Test that "blech32" gives a blinded segwit address.
176176
blech32_addr = self.nodes[0].getnewaddress("", "blech32")

test/functional/feature_sighash_rangeproof.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def prepare_tx_signed_with_sighash(self, address_type, sighash_rangeproof_aware,
130130
struct.pack("<B", len(signature)) + signature
131131
+ struct.pack("<B", len(pubkey.get_bytes())) + pubkey.get_bytes()
132132
)
133-
elif address_type == "bech32" or address_type == "p2sh-segwit":
133+
elif address_type == "blech32" or address_type == "p2sh-segwit":
134134
assert signed_tx.wit.vtxinwit[0].scriptWitness.stack[1] == pubkey.get_bytes()
135135
pubkeyhash = hash160(pubkey.get_bytes())
136136
script = get_p2pkh_script(pubkeyhash)
@@ -217,7 +217,7 @@ def assert_tx_valid(self, tx, assert_valid=True):
217217

218218
def run_test(self):
219219
util.node_fastmerkle = self.nodes[0]
220-
ADDRESS_TYPES = ["legacy", "bech32", "p2sh-segwit"]
220+
ADDRESS_TYPES = ["legacy", "blech32", "p2sh-segwit"]
221221

222222
# Different test scenarios.
223223
# - before activation, using the flag is non-standard
@@ -280,4 +280,3 @@ def run_test(self):
280280

281281
if __name__ == '__main__':
282282
SighashRangeproofTest().main()
283-

test/functional/rpc_signrawtransaction.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ def witness_blind_pubkey_test(self):
357357
4) The signature of signrawtransactionwithwallet by inputs and
358358
the signature of signrawtransactionwithwallet by utxos are equal.
359359
5) The signed transaction can broadcast."""
360-
utxo_address = self.nodes[2].getnewaddress('', 'bech32')
360+
utxo_address = self.nodes[2].getnewaddress('', 'blech32')
361361
utxo_address_info = self.nodes[2].getaddressinfo(utxo_address)
362362
uc_addr = utxo_address_info['unconfidential']
363363
utxo_address_privkey = self.nodes[2].dumpprivkey(uc_addr)

0 commit comments

Comments
 (0)