network.py: reorder bitcoin core error msg whitelist
test policy.cpp strings last as some of them are short and too generic fixes https://github.com/spesmilo/electrum/issues/7483
This commit is contained in:
@@ -907,27 +907,7 @@ class Network(Logger, NetworkRetryManager[ServerAddr]):
|
|||||||
# server_msg is untrusted input so it should not be shown to the user. see #4968
|
# server_msg is untrusted input so it should not be shown to the user. see #4968
|
||||||
server_msg = str(server_msg)
|
server_msg = str(server_msg)
|
||||||
server_msg = server_msg.replace("\n", r"\n")
|
server_msg = server_msg.replace("\n", r"\n")
|
||||||
# https://github.com/bitcoin/bitcoin/blob/5bb64acd9d3ced6e6f95df282a1a0f8b98522cb0/src/policy/policy.cpp
|
|
||||||
# grep "reason ="
|
|
||||||
policy_error_messages = {
|
|
||||||
r"version": _("Transaction uses non-standard version."),
|
|
||||||
r"tx-size": _("The transaction was rejected because it is too large (in bytes)."),
|
|
||||||
r"scriptsig-size": None,
|
|
||||||
r"scriptsig-not-pushonly": None,
|
|
||||||
r"scriptpubkey":
|
|
||||||
("scriptpubkey\n" +
|
|
||||||
_("Some of the outputs pay to a non-standard script.")),
|
|
||||||
r"bare-multisig": None,
|
|
||||||
r"dust":
|
|
||||||
(_("Transaction could not be broadcast due to dust outputs.\n"
|
|
||||||
"Some of the outputs are too small in value, probably lower than 1000 satoshis.\n"
|
|
||||||
"Check the units, make sure you haven't confused e.g. mBTC and BTC.")),
|
|
||||||
r"multi-op-return": _("The transaction was rejected because it contains multiple OP_RETURN outputs."),
|
|
||||||
}
|
|
||||||
for substring in policy_error_messages:
|
|
||||||
if substring in server_msg:
|
|
||||||
msg = policy_error_messages[substring]
|
|
||||||
return msg if msg else substring
|
|
||||||
# https://github.com/bitcoin/bitcoin/blob/5bb64acd9d3ced6e6f95df282a1a0f8b98522cb0/src/script/script_error.cpp
|
# https://github.com/bitcoin/bitcoin/blob/5bb64acd9d3ced6e6f95df282a1a0f8b98522cb0/src/script/script_error.cpp
|
||||||
script_error_messages = {
|
script_error_messages = {
|
||||||
r"Script evaluated without error but finished with a false/empty top stack element",
|
r"Script evaluated without error but finished with a false/empty top stack element",
|
||||||
@@ -989,7 +969,7 @@ class Network(Logger, NetworkRetryManager[ServerAddr]):
|
|||||||
# https://github.com/bitcoin/bitcoin/blob/5bb64acd9d3ced6e6f95df282a1a0f8b98522cb0/src/validation.cpp
|
# https://github.com/bitcoin/bitcoin/blob/5bb64acd9d3ced6e6f95df282a1a0f8b98522cb0/src/validation.cpp
|
||||||
# grep "REJECT_"
|
# grep "REJECT_"
|
||||||
# grep "TxValidationResult"
|
# grep "TxValidationResult"
|
||||||
# should come after script_error.cpp (due to e.g. non-mandatory-script-verify-flag)
|
# should come after script_error.cpp (due to e.g. "non-mandatory-script-verify-flag")
|
||||||
validation_error_messages = {
|
validation_error_messages = {
|
||||||
r"coinbase": None,
|
r"coinbase": None,
|
||||||
r"tx-size-small": None,
|
r"tx-size-small": None,
|
||||||
@@ -1071,6 +1051,29 @@ class Network(Logger, NetworkRetryManager[ServerAddr]):
|
|||||||
if substring in server_msg:
|
if substring in server_msg:
|
||||||
msg = tx_verify_error_messages[substring]
|
msg = tx_verify_error_messages[substring]
|
||||||
return msg if msg else substring
|
return msg if msg else substring
|
||||||
|
# https://github.com/bitcoin/bitcoin/blob/5bb64acd9d3ced6e6f95df282a1a0f8b98522cb0/src/policy/policy.cpp
|
||||||
|
# grep "reason ="
|
||||||
|
# should come after validation.cpp (due to "tx-size" vs "tx-size-small")
|
||||||
|
# should come after script_error.cpp (due to e.g. "version")
|
||||||
|
policy_error_messages = {
|
||||||
|
r"version": _("Transaction uses non-standard version."),
|
||||||
|
r"tx-size": _("The transaction was rejected because it is too large (in bytes)."),
|
||||||
|
r"scriptsig-size": None,
|
||||||
|
r"scriptsig-not-pushonly": None,
|
||||||
|
r"scriptpubkey":
|
||||||
|
("scriptpubkey\n" +
|
||||||
|
_("Some of the outputs pay to a non-standard script.")),
|
||||||
|
r"bare-multisig": None,
|
||||||
|
r"dust":
|
||||||
|
(_("Transaction could not be broadcast due to dust outputs.\n"
|
||||||
|
"Some of the outputs are too small in value, probably lower than 1000 satoshis.\n"
|
||||||
|
"Check the units, make sure you haven't confused e.g. mBTC and BTC.")),
|
||||||
|
r"multi-op-return": _("The transaction was rejected because it contains multiple OP_RETURN outputs."),
|
||||||
|
}
|
||||||
|
for substring in policy_error_messages:
|
||||||
|
if substring in server_msg:
|
||||||
|
msg = policy_error_messages[substring]
|
||||||
|
return msg if msg else substring
|
||||||
# otherwise:
|
# otherwise:
|
||||||
return _("Unknown error")
|
return _("Unknown error")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user