aboutsummaryrefslogtreecommitdiff
path: root/src/core_write.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_write.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_write.cpp')
-rw-r--r--src/core_write.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/core_write.cpp b/src/core_write.cpp
index ee6737201b..1272266235 100644
--- a/src/core_write.cpp
+++ b/src/core_write.cpp
@@ -70,6 +70,13 @@ const std::map<unsigned char, std::string> mapSigHashTypes = {
{static_cast<unsigned char>(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY), std::string("SINGLE|ANYONECANPAY")},
};
+std::string SighashToStr(unsigned char sighash_type)
+{
+ const auto& it = mapSigHashTypes.find(sighash_type);
+ if (it == mapSigHashTypes.end()) return "";
+ return it->second;
+}
+
/**
* Create the assembly string representation of a CScript object.
* @param[in] script CScript object to convert into the asm string representation.
@@ -128,6 +135,22 @@ std::string EncodeHexTx(const CTransaction& tx, const int serializeFlags)
return HexStr(ssTx.begin(), ssTx.end());
}
+void ScriptToUniv(const CScript& script, UniValue& out, bool include_address)
+{
+ out.pushKV("asm", ScriptToAsmStr(script));
+ out.pushKV("hex", HexStr(script.begin(), script.end()));
+
+ std::vector<std::vector<unsigned char>> solns;
+ txnouttype type;
+ Solver(script, type, solns);
+ out.pushKV("type", GetTxnOutputType(type));
+
+ CTxDestination address;
+ if (include_address && ExtractDestination(script, address)) {
+ out.pushKV("address", EncodeDestination(address));
+ }
+}
+
void ScriptPubKeyToUniv(const CScript& scriptPubKey,
UniValue& out, bool fIncludeHex)
{