| 1904 | |
| 1905 | |
| 1906 | RPCHelpMan restorewallet() |
| 1907 | { |
| 1908 | return RPCHelpMan{ |
| 1909 | "restorewallet", |
| 1910 | "\nRestore and loads a wallet from backup.\n", |
| 1911 | { |
| 1912 | {"wallet_name", RPCArg::Type::STR, RPCArg::Optional::NO, "The name that will be applied to the restored wallet"}, |
| 1913 | {"backup_file", RPCArg::Type::STR, RPCArg::Optional::NO, "The backup file that will be used to restore the wallet."}, |
| 1914 | {"load_on_startup", RPCArg::Type::BOOL, RPCArg::Optional::OMITTED_NAMED_ARG, "Save wallet name to persistent settings and load on startup. True to add wallet to startup list, false to remove, null to leave unchanged."}, |
| 1915 | }, |
| 1916 | RPCResult{ |
| 1917 | RPCResult::Type::OBJ, "", "", |
| 1918 | { |
| 1919 | {RPCResult::Type::STR, "name", "The wallet name if restored successfully."}, |
| 1920 | {RPCResult::Type::STR, "warning", "Warning message if wallet was not loaded cleanly."}, |
| 1921 | } |
| 1922 | }, |
| 1923 | RPCExamples{ |
| 1924 | HelpExampleCli("restorewallet", "\"testwallet\" \"home\\backups\\backup-file.bak\"") |
| 1925 | + HelpExampleRpc("restorewallet", "\"testwallet\" \"home\\backups\\backup-file.bak\"") |
| 1926 | + HelpExampleCliNamed("restorewallet", {{"wallet_name", "testwallet"}, {"backup_file", "home\\backups\\backup-file.bak\""}, {"load_on_startup", true}}) |
| 1927 | + HelpExampleRpcNamed("restorewallet", {{"wallet_name", "testwallet"}, {"backup_file", "home\\backups\\backup-file.bak\""}, {"load_on_startup", true}}) |
| 1928 | }, |
| 1929 | [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue |
| 1930 | { |
| 1931 | |
| 1932 | WalletContext& context = EnsureWalletContext(request.context); |
| 1933 | |
| 1934 | auto backup_file = fs::u8path(request.params[1].get_str()); |
| 1935 | |
| 1936 | std::string wallet_name = request.params[0].get_str(); |
| 1937 | |
| 1938 | std::optional<bool> load_on_start = request.params[2].isNull() ? std::nullopt : std::optional<bool>(request.params[2].get_bool()); |
| 1939 | |
| 1940 | DatabaseStatus status; |
| 1941 | bilingual_str error; |
| 1942 | std::vector<bilingual_str> warnings; |
| 1943 | |
| 1944 | const std::shared_ptr<CWallet> wallet = RestoreWallet(context, backup_file, wallet_name, load_on_start, status, error, warnings); |
| 1945 | |
| 1946 | HandleWalletError(wallet, status, error); |
| 1947 | |
| 1948 | UniValue obj(UniValue::VOBJ); |
| 1949 | obj.pushKV("name", wallet->GetName()); |
| 1950 | obj.pushKV("warning", Join(warnings, Untranslated("\n")).original); |
| 1951 | |
| 1952 | return obj; |
| 1953 | |
| 1954 | }, |
| 1955 | }; |
| 1956 | } |
| 1957 | |
| 1958 | // |
| 1959 | // ELEMENTS: |
nothing calls this directly
no test coverage detected