Skip to content

Commit 35670df

Browse files
committed
Add global_xpubs to decodepsbt
1 parent 9038485 commit 35670df

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/rpc/rawtransaction.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Distributed under the MIT software license, see the accompanying
44
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

6+
#include <base58.h>
67
#include <chain.h>
78
#include <coins.h>
89
#include <consensus/amount.h>
@@ -1075,6 +1076,15 @@ static RPCHelpMan decodepsbt()
10751076
{
10761077
{RPCResult::Type::ELISION, "", "The layout is the same as the output of decoderawtransaction."},
10771078
}},
1079+
{RPCResult::Type::ARR, "global_xpubs", "",
1080+
{
1081+
{RPCResult::Type::OBJ, "", "",
1082+
{
1083+
{RPCResult::Type::STR, "xpub", "The extended public key this path corresponds to"},
1084+
{RPCResult::Type::STR_HEX, "master_fingerprint", "The fingerprint of the master key"},
1085+
{RPCResult::Type::STR, "path", "The path"},
1086+
}},
1087+
}},
10781088
{RPCResult::Type::NUM, "psbt_version", "The PSBT version number. Not to be confused with the unsigned transaction version"},
10791089
{RPCResult::Type::ARR, "proprietary", "The global proprietary map",
10801090
{
@@ -1225,6 +1235,23 @@ static RPCHelpMan decodepsbt()
12251235
TxToUniv(CTransaction(*psbtx.tx), uint256(), tx_univ, false);
12261236
result.pushKV("tx", tx_univ);
12271237

1238+
// Add the global xpubs
1239+
UniValue global_xpubs(UniValue::VARR);
1240+
for (std::pair<KeyOriginInfo, std::set<CExtPubKey>> xpub_pair : psbtx.m_xpubs) {
1241+
for (auto& xpub : xpub_pair.second) {
1242+
std::vector<unsigned char> ser_xpub;
1243+
ser_xpub.assign(BIP32_EXTKEY_WITH_VERSION_SIZE, 0);
1244+
xpub.EncodeWithVersion(ser_xpub.data());
1245+
1246+
UniValue keypath(UniValue::VOBJ);
1247+
keypath.pushKV("xpub", EncodeBase58Check(ser_xpub));
1248+
keypath.pushKV("master_fingerprint", HexStr(Span<unsigned char>(xpub_pair.first.fingerprint, xpub_pair.first.fingerprint + 4)));
1249+
keypath.pushKV("path", WriteHDKeypath(xpub_pair.first.path));
1250+
global_xpubs.push_back(keypath);
1251+
}
1252+
}
1253+
result.pushKV("global_xpubs", global_xpubs);
1254+
12281255
// PSBT version
12291256
result.pushKV("psbt_version", static_cast<uint64_t>(psbtx.GetVersion()));
12301257

0 commit comments

Comments
 (0)