aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@protonmail.com>2020-10-15 10:53:51 +0200
committerWladimir J. van der Laan <laanwj@protonmail.com>2020-10-15 10:55:44 +0200
commit3956165903cf2fce3acd61ed6f2625f769ac7e2f (patch)
tree8ce9045b9a2baf396598ff7be199782392c40cc7
parent3caee16946575e71e90ead9ac531f5a3a1259307 (diff)
parent27fc6a38f813b65e5110c77925a335214aec756a (diff)
Merge #17775: DecodeHexTx: Try case where txn has inputs first
27fc6a38f813b65e5110c77925a335214aec756a DecodeHexTx: Break out transaction decoding logic into own function (Gregory Sanders) 6020ce3c01fe5ee15a236c47da23342005b63055 DecodeHexTx: Try case where txn has inputs first (Gregory Sanders) Pull request description: Alternative/complementary to https://github.com/bitcoin/bitcoin/pull/17773 to avoid random `decoderawtransaction` failures. Most cases this is used now is on complete transactions, especially with the uptake of PSBT. ACKs for top commit: ajtowns: ACK 27fc6a38f813b65e5110c77925a335214aec756a achow101: ACK 27fc6a38f813b65e5110c77925a335214aec756a Tree-SHA512: 0a836d7c9951bf7d2764507788dbcc871d520f1ea9b77d6b22f051f4d6224ed779aba0e4f28c5c165040095ee0c70b67080c39164d82de61b19158f7ae6fddb2
-rw-r--r--src/core_read.cpp29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/core_read.cpp b/src/core_read.cpp
index 1c0a8a096d..121e62457c 100644
--- a/src/core_read.cpp
+++ b/src/core_read.cpp
@@ -117,19 +117,14 @@ static bool CheckTxScriptsSanity(const CMutableTransaction& tx)
return true;
}
-bool DecodeHexTx(CMutableTransaction& tx, const std::string& hex_tx, bool try_no_witness, bool try_witness)
+static bool DecodeTx(CMutableTransaction& tx, const std::vector<unsigned char>& tx_data, bool try_no_witness, bool try_witness)
{
- if (!IsHex(hex_tx)) {
- return false;
- }
-
- std::vector<unsigned char> txData(ParseHex(hex_tx));
-
- if (try_no_witness) {
- CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS);
+ if (try_witness) {
+ CDataStream ssData(tx_data, SER_NETWORK, PROTOCOL_VERSION);
try {
ssData >> tx;
- if (ssData.eof() && (!try_witness || CheckTxScriptsSanity(tx))) {
+ // If transaction looks sane, we don't try other mode even if requested
+ if (ssData.empty() && (!try_no_witness || CheckTxScriptsSanity(tx))) {
return true;
}
} catch (const std::exception&) {
@@ -137,8 +132,8 @@ bool DecodeHexTx(CMutableTransaction& tx, const std::string& hex_tx, bool try_no
}
}
- if (try_witness) {
- CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION);
+ if (try_no_witness) {
+ CDataStream ssData(tx_data, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS);
try {
ssData >> tx;
if (ssData.empty()) {
@@ -152,6 +147,16 @@ bool DecodeHexTx(CMutableTransaction& tx, const std::string& hex_tx, bool try_no
return false;
}
+bool DecodeHexTx(CMutableTransaction& tx, const std::string& hex_tx, bool try_no_witness, bool try_witness)
+{
+ if (!IsHex(hex_tx)) {
+ return false;
+ }
+
+ std::vector<unsigned char> txData(ParseHex(hex_tx));
+ return DecodeTx(tx, txData, try_no_witness, try_witness);
+}
+
bool DecodeHexBlockHeader(CBlockHeader& header, const std::string& hex_header)
{
if (!IsHex(hex_header)) return false;