@@ -957,6 +957,46 @@ static RPCHelpMan createwalletdescriptor()
957
957
};
958
958
}
959
959
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
+
960
1000
// addresses
961
1001
RPCHelpMan getaddressinfo ();
962
1002
RPCHelpMan getnewaddress ();
@@ -1033,6 +1073,7 @@ std::span<const CRPCCommand> GetWalletRPCCommands()
1033
1073
{" wallet" , &createwalletdescriptor},
1034
1074
{" wallet" , &restorewallet},
1035
1075
{" wallet" , &encryptwallet},
1076
+ {" wallet" , &exportwatchonlywallet},
1036
1077
{" wallet" , &getaddressesbylabel},
1037
1078
{" wallet" , &getaddressinfo},
1038
1079
{" wallet" , &getbalance},
0 commit comments