From 35670df866e0bb4a58a7cc032f7bcae508fd0273 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Thu, 25 Jul 2019 13:20:38 -0400 Subject: [PATCH] Add global_xpubs to decodepsbt --- src/rpc/rawtransaction.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 4502776a043..7535ac02f72 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -3,6 +3,7 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include #include #include #include @@ -1075,6 +1076,15 @@ static RPCHelpMan decodepsbt() { {RPCResult::Type::ELISION, "", "The layout is the same as the output of decoderawtransaction."}, }}, + {RPCResult::Type::ARR, "global_xpubs", "", + { + {RPCResult::Type::OBJ, "", "", + { + {RPCResult::Type::STR, "xpub", "The extended public key this path corresponds to"}, + {RPCResult::Type::STR_HEX, "master_fingerprint", "The fingerprint of the master key"}, + {RPCResult::Type::STR, "path", "The path"}, + }}, + }}, {RPCResult::Type::NUM, "psbt_version", "The PSBT version number. Not to be confused with the unsigned transaction version"}, {RPCResult::Type::ARR, "proprietary", "The global proprietary map", { @@ -1225,6 +1235,23 @@ static RPCHelpMan decodepsbt() TxToUniv(CTransaction(*psbtx.tx), uint256(), tx_univ, false); result.pushKV("tx", tx_univ); + // Add the global xpubs + UniValue global_xpubs(UniValue::VARR); + for (std::pair> xpub_pair : psbtx.m_xpubs) { + for (auto& xpub : xpub_pair.second) { + std::vector ser_xpub; + ser_xpub.assign(BIP32_EXTKEY_WITH_VERSION_SIZE, 0); + xpub.EncodeWithVersion(ser_xpub.data()); + + UniValue keypath(UniValue::VOBJ); + keypath.pushKV("xpub", EncodeBase58Check(ser_xpub)); + keypath.pushKV("master_fingerprint", HexStr(Span(xpub_pair.first.fingerprint, xpub_pair.first.fingerprint + 4))); + keypath.pushKV("path", WriteHDKeypath(xpub_pair.first.path)); + global_xpubs.push_back(keypath); + } + } + result.pushKV("global_xpubs", global_xpubs); + // PSBT version result.pushKV("psbt_version", static_cast(psbtx.GetVersion()));