@@ -929,6 +929,46 @@ static RPCHelpMan createwalletdescriptor()
929929 };
930930}
931931
932+ static RPCHelpMan exportwatchonlywallet ()
933+ {
934+ return RPCHelpMan{" exportwatchonlywallet" ,
935+ " Creates a wallet file at the specified path and name containing a watchonly version "
936+ " of the wallet. This watchonly wallet contains the wallet's public descriptors, "
937+ " its transactions, and address book data. The watchonly wallet can be imported to "
938+ " another node using 'restorewallet'." ,
939+ {
940+ {" destination" , RPCArg::Type::STR, RPCArg::Optional::NO, " The path to the filename the exported watchonly wallet will be saved to" },
941+ },
942+ RPCResult{
943+ RPCResult::Type::OBJ, " " , " " ,
944+ {
945+ {RPCResult::Type::STR, " exported_file" , " The full path that the file has been exported to" },
946+ },
947+ },
948+ RPCExamples{
949+ HelpExampleCli (" exportwatchonlywallet" , " \" home\\ user\\\" " )
950+ + HelpExampleRpc (" exportwatchonlywallet" , " \" home\\ user\\\" " )
951+ },
952+ [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
953+ {
954+ std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest (request);
955+ if (!pwallet) return UniValue::VNULL;
956+ WalletContext& context = EnsureWalletContext (request.context );
957+
958+ std::string dest = request.params [0 ].get_str ();
959+
960+ LOCK (pwallet->cs_wallet );
961+ util::Result<std::string> exported = pwallet->ExportWatchOnlyWallet (fs::PathFromString (dest), context);
962+ if (!exported) {
963+ throw JSONRPCError (RPC_WALLET_ERROR, util::ErrorString (exported).original );
964+ }
965+ UniValue out{UniValue::VOBJ};
966+ out.pushKV (" exported_file" , *exported);
967+ return out;
968+ }
969+ };
970+ }
971+
932972// addresses
933973RPCHelpMan getaddressinfo ();
934974RPCHelpMan getnewaddress ();
@@ -1005,6 +1045,7 @@ std::span<const CRPCCommand> GetWalletRPCCommands()
10051045 {" wallet" , &createwalletdescriptor},
10061046 {" wallet" , &restorewallet},
10071047 {" wallet" , &encryptwallet},
1048+ {" wallet" , &exportwatchonlywallet},
10081049 {" wallet" , &getaddressesbylabel},
10091050 {" wallet" , &getaddressinfo},
10101051 {" wallet" , &getbalance},
0 commit comments