Skip to content

Commit afd20a2

Browse files
committed
Move PSBT decoding functions from core_io to psbt.cpp
Move PSBT decoding functions from core_io.h/core_read.cpp to psbt.h/psbt.cpp, to deal with a linker issue.
1 parent 8e1704c commit afd20a2

File tree

5 files changed

+33
-35
lines changed

5 files changed

+33
-35
lines changed

src/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,8 @@ libbitcoin_common_a_SOURCES = \
430430
netaddress.cpp \
431431
netbase.cpp \
432432
policy/feerate.cpp \
433-
psbt.cpp \
434433
protocol.cpp \
434+
psbt.cpp \
435435
scheduler.cpp \
436436
script/descriptor.cpp \
437437
script/ismine.cpp \

src/core_io.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class CBlockHeader;
1616
class CScript;
1717
class CTransaction;
1818
struct CMutableTransaction;
19-
struct PartiallySignedTransaction;
2019
class uint256;
2120
class UniValue;
2221

@@ -37,11 +36,6 @@ bool DecodeHexBlockHeader(CBlockHeader&, const std::string& hex_header);
3736
*/
3837
bool ParseHashStr(const std::string& strHex, uint256& result);
3938
std::vector<unsigned char> ParseHexUV(const UniValue& v, const std::string& strName);
40-
41-
//! Decode a base64ed PSBT into a PartiallySignedTransaction
42-
NODISCARD bool DecodeBase64PSBT(PartiallySignedTransaction& decoded_psbt, const std::string& base64_psbt, std::string& error);
43-
//! Decode a raw (binary blob) PSBT into a PartiallySignedTransaction
44-
NODISCARD bool DecodeRawPSBT(PartiallySignedTransaction& decoded_psbt, const std::string& raw_psbt, std::string& error);
4539
int ParseSighashString(const UniValue& sighash);
4640

4741
// core_write.cpp

src/core_read.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#include <core_io.h>
66

7-
#include <psbt.h>
87
#include <primitives/block.h>
98
#include <primitives/transaction.h>
109
#include <script/script.h>
@@ -177,33 +176,6 @@ bool DecodeHexBlk(CBlock& block, const std::string& strHexBlk)
177176
return true;
178177
}
179178

180-
bool DecodeBase64PSBT(PartiallySignedTransaction& psbt, const std::string& base64_tx, std::string& error)
181-
{
182-
bool invalid;
183-
std::string tx_data = DecodeBase64(base64_tx, &invalid);
184-
if (invalid) {
185-
error = "invalid base64";
186-
return false;
187-
}
188-
return DecodeRawPSBT(psbt, tx_data, error);
189-
}
190-
191-
bool DecodeRawPSBT(PartiallySignedTransaction& psbt, const std::string& tx_data, std::string& error)
192-
{
193-
CDataStream ss_data(tx_data.data(), tx_data.data() + tx_data.size(), SER_NETWORK, PROTOCOL_VERSION);
194-
try {
195-
ss_data >> psbt;
196-
if (!ss_data.empty()) {
197-
error = "extra data after PSBT";
198-
return false;
199-
}
200-
} catch (const std::exception& e) {
201-
error = e.what();
202-
return false;
203-
}
204-
return true;
205-
}
206-
207179
bool ParseHashStr(const std::string& strHex, uint256& result)
208180
{
209181
if ((strHex.size() != 64) || !IsHex(strHex))

src/psbt.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,3 +325,30 @@ TransactionError CombinePSBTs(PartiallySignedTransaction& out, const std::vector
325325

326326
return TransactionError::OK;
327327
}
328+
329+
bool DecodeBase64PSBT(PartiallySignedTransaction& psbt, const std::string& base64_tx, std::string& error)
330+
{
331+
bool invalid;
332+
std::string tx_data = DecodeBase64(base64_tx, &invalid);
333+
if (invalid) {
334+
error = "invalid base64";
335+
return false;
336+
}
337+
return DecodeRawPSBT(psbt, tx_data, error);
338+
}
339+
340+
bool DecodeRawPSBT(PartiallySignedTransaction& psbt, const std::string& tx_data, std::string& error)
341+
{
342+
CDataStream ss_data(tx_data.data(), tx_data.data() + tx_data.size(), SER_NETWORK, PROTOCOL_VERSION);
343+
try {
344+
ss_data >> psbt;
345+
if (!ss_data.empty()) {
346+
error = "extra data after PSBT";
347+
return false;
348+
}
349+
} catch (const std::exception& e) {
350+
error = e.what();
351+
return false;
352+
}
353+
return true;
354+
}

src/psbt.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,4 +580,9 @@ bool FinalizeAndExtractPSBT(PartiallySignedTransaction& psbtx, CMutableTransacti
580580
*/
581581
NODISCARD TransactionError CombinePSBTs(PartiallySignedTransaction& out, const std::vector<PartiallySignedTransaction>& psbtxs);
582582

583+
//! Decode a base64ed PSBT into a PartiallySignedTransaction
584+
NODISCARD bool DecodeBase64PSBT(PartiallySignedTransaction& decoded_psbt, const std::string& base64_psbt, std::string& error);
585+
//! Decode a raw (binary blob) PSBT into a PartiallySignedTransaction
586+
NODISCARD bool DecodeRawPSBT(PartiallySignedTransaction& decoded_psbt, const std::string& raw_psbt, std::string& error);
587+
583588
#endif // BITCOIN_PSBT_H

0 commit comments

Comments
 (0)