mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 15:09:59 +01:00
Merge #17775: DecodeHexTx: Try case where txn has inputs first
27fc6a38f8DecodeHexTx: Break out transaction decoding logic into own function (Gregory Sanders)6020ce3c01DecodeHexTx: 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: ACK27fc6a38f8achow101: ACK27fc6a38f8Tree-SHA512: 0a836d7c9951bf7d2764507788dbcc871d520f1ea9b77d6b22f051f4d6224ed779aba0e4f28c5c165040095ee0c70b67080c39164d82de61b19158f7ae6fddb2
This commit is contained in:
@@ -117,19 +117,14 @@ static bool CheckTxScriptsSanity(const CMutableTransaction& tx)
|
|||||||
return true;
|
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)) {
|
if (try_witness) {
|
||||||
return false;
|
CDataStream ssData(tx_data, SER_NETWORK, PROTOCOL_VERSION);
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<unsigned char> txData(ParseHex(hex_tx));
|
|
||||||
|
|
||||||
if (try_no_witness) {
|
|
||||||
CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS);
|
|
||||||
try {
|
try {
|
||||||
ssData >> tx;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (const std::exception&) {
|
} catch (const std::exception&) {
|
||||||
@@ -137,8 +132,8 @@ bool DecodeHexTx(CMutableTransaction& tx, const std::string& hex_tx, bool try_no
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (try_witness) {
|
if (try_no_witness) {
|
||||||
CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION);
|
CDataStream ssData(tx_data, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS);
|
||||||
try {
|
try {
|
||||||
ssData >> tx;
|
ssData >> tx;
|
||||||
if (ssData.empty()) {
|
if (ssData.empty()) {
|
||||||
@@ -152,6 +147,16 @@ bool DecodeHexTx(CMutableTransaction& tx, const std::string& hex_tx, bool try_no
|
|||||||
return false;
|
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)
|
bool DecodeHexBlockHeader(CBlockHeader& header, const std::string& hex_header)
|
||||||
{
|
{
|
||||||
if (!IsHex(hex_header)) return false;
|
if (!IsHex(hex_header)) return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user