Skip to content

Commit 960afcf

Browse files
committed
feat: upgradetohd return string with futher instructions instead bool
1 parent 4f42cfa commit 960afcf

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

src/wallet/rpc/wallet.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,7 @@ static RPCHelpMan upgradetohd()
354354
{"walletpassphrase", RPCArg::Type::STR, RPCArg::Default{""}, "If your wallet is encrypted you must have your wallet passphrase here. If your wallet is not encrypted, specifying wallet passphrase will trigger wallet encryption."},
355355
{"rescan", RPCArg::Type::BOOL, RPCArg::DefaultHint{"false if mnemonic is empty"}, "Whether to rescan the blockchain for missing transactions or not"},
356356
},
357-
RPCResult{
358-
RPCResult::Type::BOOL, "", "true if successful"
359-
},
357+
RPCResult{RPCResult::Type::STR, "", "A string with further instructions"},
360358
RPCExamples{
361359
HelpExampleCli("upgradetohd", "")
362360
+ HelpExampleCli("upgradetohd", "\"mnemonicword1 ... mnemonicwordN\"")
@@ -370,7 +368,7 @@ static RPCHelpMan upgradetohd()
370368
if (!pwallet) return NullUniValue;
371369

372370
bool generate_mnemonic = request.params[0].isNull() || request.params[0].get_str().empty();
373-
371+
bool mnemonic_passphrase_has_null{false};
374372
{
375373
LOCK(pwallet->cs_wallet);
376374

@@ -395,6 +393,7 @@ static RPCHelpMan upgradetohd()
395393
mnemonic_passphrase.reserve(256);
396394
if (!request.params[1].isNull()) {
397395
mnemonic_passphrase = std::string_view{request.params[1].get_str()};
396+
mnemonic_passphrase_has_null = (mnemonic_passphrase.find('\0') != std::string::npos);
398397
}
399398

400399
// TODO: breaking changes kept for v21!
@@ -490,7 +489,17 @@ static RPCHelpMan upgradetohd()
490489
}
491490
}
492491

493-
return true;
492+
// Check if the passphrase has a null character (see #27067 for details)
493+
if (!mnemonic_passphrase_has_null) {
494+
return "Make sure that you have backup of your mnemonic.";
495+
} else {
496+
return "Make sure that you have backup of your mnemonic. "
497+
"Your mnemonic passphrase contains a null character (ie - a zero byte). "
498+
"If the passphrase was created with a version of this software prior to 23.0, "
499+
"please try again with only the characters up to — but not including — "
500+
"the first null character. If this is successful, please set a new "
501+
"passphrase to avoid this issue in the future.";
502+
}
494503
},
495504
};
496505
}

test/functional/wallet_upgradetohd.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ def run_test(self):
243243

244244
node.createwallet("wallet-12", blank=True)
245245
w12 = node.get_wallet_rpc("wallet-12")
246-
w12.upgradetohd(custom_mnemonic, "custom-passphrase")
246+
ret = w12.upgradetohd(custom_mnemonic, "custom-passphrase")
247+
assert_equal(ret, "Make sure that you have backup of your mnemonic.")
247248
assert_equal(get_mnemonic(w12)[0], custom_mnemonic)
248249
assert_equal(get_mnemonic(w12)[1], "custom-passphrase")
249250
assert_equal(12, w12.getbalance())
@@ -252,7 +253,8 @@ def run_test(self):
252253
self.log.info("Check if null character at the end of mnemonic-passphrase matters")
253254
node.createwallet("wallet-null", blank=True)
254255
w_null = node.get_wallet_rpc("wallet-null")
255-
w_null.upgradetohd(custom_mnemonic, "custom-passphrase\0")
256+
ret = w_null.upgradetohd(custom_mnemonic, "custom-passphrase\0")
257+
assert_equal(ret, "Make sure that you have backup of your mnemonic. Your mnemonic passphrase contains a null character (ie - a zero byte). If the passphrase was created with a version of this software prior to 23.0, please try again with only the characters up to — but not including — the first null character. If this is successful, please set a new passphrase to avoid this issue in the future.")
256258
assert_equal(0, w_null.getbalance())
257259
assert_equal(get_mnemonic(w_null)[1], "custom-passphrase\0")
258260
w_null.unloadwallet()

test/functional/wallet_upgradewallet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def copy_non_hd():
169169
self.test_upgradewallet(wallet, previous_version=61000, expected_version=120200, requested_version=169900)
170170
# after conversion master key hash should not be present yet
171171
assert 'hdchainid' not in wallet.getwalletinfo()
172-
assert_equal(wallet.upgradetohd(), True)
172+
assert_equal(wallet.upgradetohd(), "Make sure that you have backup of your mnemonic.")
173173
new_version = wallet.getwalletinfo()["walletversion"]
174174
assert_equal(new_version, 120200)
175175
assert_is_hex_string(wallet.getwalletinfo()['hdchainid'])

0 commit comments

Comments
 (0)