@@ -929,6 +929,46 @@ static RPCHelpMan createwalletdescriptor()
929
929
};
930
930
}
931
931
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
+
932
972
// addresses
933
973
RPCHelpMan getaddressinfo ();
934
974
RPCHelpMan getnewaddress ();
@@ -1005,6 +1045,7 @@ std::span<const CRPCCommand> GetWalletRPCCommands()
1005
1045
{" wallet" , &createwalletdescriptor},
1006
1046
{" wallet" , &restorewallet},
1007
1047
{" wallet" , &encryptwallet},
1048
+ {" wallet" , &exportwatchonlywallet},
1008
1049
{" wallet" , &getaddressesbylabel},
1009
1050
{" wallet" , &getaddressinfo},
1010
1051
{" wallet" , &getbalance},
0 commit comments