aboutsummaryrefslogtreecommitdiff
path: root/src/core_read.cpp
diff options
context:
space:
mode:
authorAndrew Chow <achow101-github@achow101.com>2018-06-28 19:04:40 -0700
committerAndrew Chow <achow101-github@achow101.com>2018-07-16 16:08:24 -0700
commitc27fe419efb3b6588c400d764122ffb33375e028 (patch)
tree710267c171e804f20286191f1495c66ca59683cf /src/core_read.cpp
parent8b5ef2793748065727a9a2498805ae5b269dcb4f (diff)
Create utility RPCs for PSBT
decodepsbt takes a PSBT and decodes it to JSON combinepsbt takes multiple PSBTs for the same tx and combines them. finalizepsbt takes a PSBT and finalizes the inputs. If all inputs are final, it extracts the network serialized transaction and returns that instead of a PSBT unless instructed otherwise. createpsbt is like createrawtransaction but for PSBTs instead of raw transactions. convertpsbt takes a network serialized transaction and converts it into a psbt. The resulting psbt will lose all signature data and an explicit flag must be set to allow transactions with signature data to be converted.
Diffstat (limited to 'src/core_read.cpp')
-rw-r--r--src/core_read.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/core_read.cpp b/src/core_read.cpp
index 4d851610ef..7ee3edc1f3 100644
--- a/src/core_read.cpp
+++ b/src/core_read.cpp
@@ -7,6 +7,7 @@
#include <primitives/block.h>
#include <primitives/transaction.h>
#include <script/script.h>
+#include <script/sign.h>
#include <serialize.h>
#include <streams.h>
#include <univalue.h>
@@ -160,6 +161,23 @@ bool DecodeHexBlk(CBlock& block, const std::string& strHexBlk)
return true;
}
+bool DecodePSBT(PartiallySignedTransaction& psbt, const std::string& base64_tx, std::string& error)
+{
+ std::vector<unsigned char> tx_data = DecodeBase64(base64_tx.c_str());
+ CDataStream ss_data(tx_data, SER_NETWORK, PROTOCOL_VERSION);
+ try {
+ ss_data >> psbt;
+ if (!ss_data.empty()) {
+ error = "extra data after PSBT";
+ return false;
+ }
+ } catch (const std::exception& e) {
+ error = e.what();
+ return false;
+ }
+ return true;
+}
+
uint256 ParseHashStr(const std::string& strHex, const std::string& strName)
{
if (!IsHex(strHex)) // Note: IsHex("") is false