Improve address decoding errors

This commit is contained in:
Aurèle Oulès
2022-11-08 16:24:03 +01:00
parent 89fb354f28
commit 962a0930e6
3 changed files with 15 additions and 15 deletions

View File

@@ -107,17 +107,17 @@ CTxDestination DecodeDestination(const std::string& str, const CChainParams& par
std::equal(script_prefix.begin(), script_prefix.end(), data.begin())) ||
(data.size() >= pubkey_prefix.size() &&
std::equal(pubkey_prefix.begin(), pubkey_prefix.end(), data.begin()))) {
error_str = "Invalid length for Base58 address";
error_str = "Invalid length for Base58 address (P2PKH or P2SH)";
} else {
error_str = "Invalid prefix for Base58-encoded address";
error_str = "Invalid or unsupported Base58-encoded address.";
}
return CNoDestination();
} else if (!is_bech32) {
// Try Base58 decoding without the checksum, using a much larger max length
if (!DecodeBase58(str, data, 100)) {
error_str = "Not a valid Bech32 or Base58 encoding";
error_str = "Invalid or unsupported Segwit (Bech32) or Base58 encoding.";
} else {
error_str = "Invalid checksum or length of Base58 address";
error_str = "Invalid checksum or length of Base58 address (P2PKH or P2SH)";
}
return CNoDestination();
}
@@ -127,7 +127,7 @@ CTxDestination DecodeDestination(const std::string& str, const CChainParams& par
if ((dec.encoding == bech32::Encoding::BECH32 || dec.encoding == bech32::Encoding::BECH32M) && dec.data.size() > 0) {
// Bech32 decoding
if (dec.hrp != params.Bech32HRP()) {
error_str = "Invalid prefix for Bech32 address";
error_str = strprintf("Invalid or unsupported prefix for Segwit (Bech32) address (expected %s, got %s).", params.Bech32HRP(), dec.hrp);
return CNoDestination();
}
int version = dec.data[0]; // The first 5 bit symbol is the witness version (0-16)