Skip to content

Commit 27fc6a3

Browse files
committed
DecodeHexTx: Break out transaction decoding logic into own function
1 parent 6020ce3 commit 27fc6a3

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/core_read.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,10 @@ static bool CheckTxScriptsSanity(const CMutableTransaction& tx)
109109
return true;
110110
}
111111

112-
bool DecodeHexTx(CMutableTransaction& tx, const std::string& hex_tx, bool try_no_witness, bool try_witness)
112+
static bool DecodeTx(CMutableTransaction& tx, const std::vector<unsigned char>& tx_data, bool try_no_witness, bool try_witness)
113113
{
114-
if (!IsHex(hex_tx)) {
115-
return false;
116-
}
117-
118-
std::vector<unsigned char> txData(ParseHex(hex_tx));
119-
120114
if (try_witness) {
121-
CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION);
115+
CDataStream ssData(tx_data, SER_NETWORK, PROTOCOL_VERSION);
122116
try {
123117
ssData >> tx;
124118
// If transaction looks sane, we don't try other mode even if requested
@@ -131,7 +125,7 @@ bool DecodeHexTx(CMutableTransaction& tx, const std::string& hex_tx, bool try_no
131125
}
132126

133127
if (try_no_witness) {
134-
CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS);
128+
CDataStream ssData(tx_data, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS);
135129
try {
136130
ssData >> tx;
137131
if (ssData.empty()) {
@@ -145,6 +139,16 @@ bool DecodeHexTx(CMutableTransaction& tx, const std::string& hex_tx, bool try_no
145139
return false;
146140
}
147141

142+
bool DecodeHexTx(CMutableTransaction& tx, const std::string& hex_tx, bool try_no_witness, bool try_witness)
143+
{
144+
if (!IsHex(hex_tx)) {
145+
return false;
146+
}
147+
148+
std::vector<unsigned char> txData(ParseHex(hex_tx));
149+
return DecodeTx(tx, txData, try_no_witness, try_witness);
150+
}
151+
148152
bool DecodeHexBlockHeader(CBlockHeader& header, const std::string& hex_header)
149153
{
150154
if (!IsHex(hex_header)) return false;

0 commit comments

Comments
 (0)