Skip to content

Commit

Permalink
Add global_xpubs to decodepsbt
Browse files Browse the repository at this point in the history
Github-Pull: bitcoin#16463
Rebased-From: 5d23641
  • Loading branch information
achow101 authored and luke-jr committed Apr 3, 2020
1 parent 51d9a2c commit 717793f
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/rpc/rawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <base58.h>
#include <chain.h>
#include <coins.h>
#include <consensus/validation.h>
Expand Down Expand Up @@ -983,6 +984,15 @@ UniValue decodepsbt(const JSONRPCRequest& request)
{
{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::OBJ_DYN, "unknown", "The unknown global fields",
{
{RPCResult::Type::STR_HEX, "key", "(key-value pair) An unknown key-value pair"},
Expand Down Expand Up @@ -1122,6 +1132,23 @@ UniValue decodepsbt(const JSONRPCRequest& request)
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<KeyOriginInfo, std::set<CExtPubKey>> xpub_pair : psbtx.xpubs) {
for (auto& xpub : xpub_pair.second) {
std::vector<unsigned char> 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(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);

// Proprietary
UniValue proprietary(UniValue::VARR);
for (const auto& entry : psbtx.proprietary) {
Expand Down

0 comments on commit 717793f

Please sign in to comment.