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