@@ -957,6 +957,46 @@ static RPCHelpMan createwalletdescriptor()
957957 };
958958}
959959
960+ static RPCHelpMan exportwatchonlywallet ()
961+ {
962+ return RPCHelpMan{" exportwatchonlywallet" ,
963+ " Creates a wallet file at the specified path and name containing a watchonly version "
964+ " of the wallet. This watchonly wallet contains the wallet's public descriptors, "
965+ " its transactions, and address book data. The watchonly wallet can be imported to "
966+ " another node using 'restorewallet'." ,
967+ {
968+ {" destination" , RPCArg::Type::STR, RPCArg::Optional::NO, " The path to the filename the exported watchonly wallet will be saved to" },
969+ },
970+ RPCResult{
971+ RPCResult::Type::OBJ, " " , " " ,
972+ {
973+ {RPCResult::Type::STR, " exported_file" , " The full path that the file has been exported to" },
974+ },
975+ },
976+ RPCExamples{
977+ HelpExampleCli (" exportwatchonlywallet" , " \" home\\ user\\\" " )
978+ + HelpExampleRpc (" exportwatchonlywallet" , " \" home\\ user\\\" " )
979+ },
980+ [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
981+ {
982+ std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest (request);
983+ if (!pwallet) return UniValue::VNULL;
984+ WalletContext& context = EnsureWalletContext (request.context );
985+
986+ std::string dest = request.params [0 ].get_str ();
987+
988+ LOCK (pwallet->cs_wallet );
989+ util::Result<std::string> exported = pwallet->ExportWatchOnlyWallet (fs::PathFromString (dest), context);
990+ if (!exported) {
991+ throw JSONRPCError (RPC_WALLET_ERROR, util::ErrorString (exported).original );
992+ }
993+ UniValue out{UniValue::VOBJ};
994+ out.pushKV (" exported_file" , *exported);
995+ return out;
996+ }
997+ };
998+ }
999+
9601000// addresses
9611001RPCHelpMan getaddressinfo ();
9621002RPCHelpMan getnewaddress ();
@@ -1033,6 +1073,7 @@ std::span<const CRPCCommand> GetWalletRPCCommands()
10331073 {" wallet" , &createwalletdescriptor},
10341074 {" wallet" , &restorewallet},
10351075 {" wallet" , &encryptwallet},
1076+ {" wallet" , &exportwatchonlywallet},
10361077 {" wallet" , &getaddressesbylabel},
10371078 {" wallet" , &getaddressinfo},
10381079 {" wallet" , &getbalance},
0 commit comments