Skip to content

Commit

Permalink
Add global_xpubs to decodepsbt
Browse files Browse the repository at this point in the history
  • Loading branch information
achow101 committed Dec 10, 2021
1 parent feb2cae commit 958a2f7
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/amount.h>
Expand Down Expand Up @@ -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",
{
Expand Down Expand Up @@ -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<KeyOriginInfo, std::set<CExtPubKey>> xpub_pair : psbtx.m_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(Span<unsigned char>(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<uint64_t>(psbtx.GetVersion()));

Expand Down

0 comments on commit 958a2f7

Please sign in to comment.