@@ -938,6 +938,46 @@ static RPCHelpMan createwalletdescriptor()
938
938
};
939
939
}
940
940
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
+
941
981
// addresses
942
982
RPCHelpMan getaddressinfo ();
943
983
RPCHelpMan getnewaddress ();
@@ -1014,6 +1054,7 @@ std::span<const CRPCCommand> GetWalletRPCCommands()
1014
1054
{" wallet" , &createwalletdescriptor},
1015
1055
{" wallet" , &restorewallet},
1016
1056
{" wallet" , &encryptwallet},
1057
+ {" wallet" , &exportwatchonlywallet},
1017
1058
{" wallet" , &getaddressesbylabel},
1018
1059
{" wallet" , &getaddressinfo},
1019
1060
{" wallet" , &getbalance},
0 commit comments