@@ -938,6 +938,46 @@ static RPCHelpMan createwalletdescriptor()
938938 };
939939}
940940
941+ static RPCHelpMan exportwatchonlywallet ()
942+ {
943+ return RPCHelpMan{" exportwatchonlywallet" ,
944+ " Creates a wallet file at the specified path and name containing a watchonly version "
945+ " of the wallet. This watchonly wallet contains the wallet's public descriptors, "
946+ " its transactions, and address book data. The watchonly wallet can be imported to "
947+ " another node using 'restorewallet'." ,
948+ {
949+ {" destination" , RPCArg::Type::STR, RPCArg::Optional::NO, " The path to the filename the exported watchonly wallet will be saved to" },
950+ },
951+ RPCResult{
952+ RPCResult::Type::OBJ, " " , " " ,
953+ {
954+ {RPCResult::Type::STR, " exported_file" , " The full path that the file has been exported to" },
955+ },
956+ },
957+ RPCExamples{
958+ HelpExampleCli (" exportwatchonlywallet" , " \" home\\ user\\\" " )
959+ + HelpExampleRpc (" exportwatchonlywallet" , " \" home\\ user\\\" " )
960+ },
961+ [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
962+ {
963+ std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest (request);
964+ if (!pwallet) return UniValue::VNULL;
965+ WalletContext& context = EnsureWalletContext (request.context );
966+
967+ std::string dest = request.params [0 ].get_str ();
968+
969+ LOCK (pwallet->cs_wallet );
970+ util::Result<std::string> exported = pwallet->ExportWatchOnlyWallet (fs::PathFromString (dest), context);
971+ if (!exported) {
972+ throw JSONRPCError (RPC_WALLET_ERROR, util::ErrorString (exported).original );
973+ }
974+ UniValue out{UniValue::VOBJ};
975+ out.pushKV (" exported_file" , *exported);
976+ return out;
977+ }
978+ };
979+ }
980+
941981// addresses
942982RPCHelpMan getaddressinfo ();
943983RPCHelpMan getnewaddress ();
@@ -1014,6 +1054,7 @@ std::span<const CRPCCommand> GetWalletRPCCommands()
10141054 {" wallet" , &createwalletdescriptor},
10151055 {" wallet" , &restorewallet},
10161056 {" wallet" , &encryptwallet},
1057+ {" wallet" , &exportwatchonlywallet},
10171058 {" wallet" , &getaddressesbylabel},
10181059 {" wallet" , &getaddressinfo},
10191060 {" wallet" , &getbalance},
0 commit comments