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