MOVEONLY: Move LoadWalletHelper to wallet/rpc/util
This commit is contained in:
1 parent
8b73640152
commit
5b2167fd30
5 files changed
+36
-40
No files matched your search
@@ -17,7 +17,6 @@
|
|||||||
#include <util/system.h>
|
#include <util/system.h>
|
||||||
#include <util/time.h>
|
#include <util/time.h>
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
#include <wallet/rpcwallet.h>
|
|
||||||
#include <wallet/rpc/util.h>
|
#include <wallet/rpc/util.h>
|
||||||
#include <wallet/wallet.h>
|
#include <wallet/wallet.h>
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <wallet/rpc/util.h>
|
#include <wallet/rpc/util.h>
|
||||||
|
|
||||||
#include <rpc/util.h>
|
#include <rpc/util.h>
|
||||||
|
#include <util/translation.h>
|
||||||
#include <util/url.h>
|
#include <util/url.h>
|
||||||
#include <wallet/context.h>
|
#include <wallet/context.h>
|
||||||
#include <wallet/wallet.h>
|
#include <wallet/wallet.h>
|
||||||
@@ -120,3 +121,34 @@ std::string LabelFromValue(const UniValue& value)
|
|||||||
throw JSONRPCError(RPC_WALLET_INVALID_LABEL_NAME, "Invalid label name");
|
throw JSONRPCError(RPC_WALLET_INVALID_LABEL_NAME, "Invalid label name");
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::tuple<std::shared_ptr<CWallet>, std::vector<bilingual_str>> LoadWalletHelper(WalletContext& context, UniValue load_on_start_param, const std::string wallet_name)
|
||||||
|
{
|
||||||
|
DatabaseOptions options;
|
||||||
|
DatabaseStatus status;
|
||||||
|
options.require_existing = true;
|
||||||
|
bilingual_str error;
|
||||||
|
std::vector<bilingual_str> warnings;
|
||||||
|
std::optional<bool> load_on_start = load_on_start_param.isNull() ? std::nullopt : std::optional<bool>(load_on_start_param.get_bool());
|
||||||
|
std::shared_ptr<CWallet> const wallet = LoadWallet(context, wallet_name, load_on_start, options, status, error, warnings);
|
||||||
|
|
||||||
|
if (!wallet) {
|
||||||
|
// Map bad format to not found, since bad format is returned when the
|
||||||
|
// wallet directory exists, but doesn't contain a data file.
|
||||||
|
RPCErrorCode code = RPC_WALLET_ERROR;
|
||||||
|
switch (status) {
|
||||||
|
case DatabaseStatus::FAILED_NOT_FOUND:
|
||||||
|
case DatabaseStatus::FAILED_BAD_FORMAT:
|
||||||
|
code = RPC_WALLET_NOT_FOUND;
|
||||||
|
break;
|
||||||
|
case DatabaseStatus::FAILED_ALREADY_LOADED:
|
||||||
|
code = RPC_WALLET_ALREADY_LOADED;
|
||||||
|
break;
|
||||||
|
default: // RPC_WALLET_ERROR is returned for all other cases.
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
throw JSONRPCError(code, error.original);
|
||||||
|
}
|
||||||
|
|
||||||
|
return { wallet, warnings };
|
||||||
|
}
|
||||||
@@ -8,7 +8,9 @@
|
|||||||
#include <any>
|
#include <any>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
struct bilingual_str;
|
||||||
class CWallet;
|
class CWallet;
|
||||||
class JSONRPCRequest;
|
class JSONRPCRequest;
|
||||||
class LegacyScriptPubKeyMan;
|
class LegacyScriptPubKeyMan;
|
||||||
@@ -35,4 +37,6 @@ bool GetAvoidReuseFlag(const CWallet& wallet, const UniValue& param);
|
|||||||
bool ParseIncludeWatchonly(const UniValue& include_watchonly, const CWallet& wallet);
|
bool ParseIncludeWatchonly(const UniValue& include_watchonly, const CWallet& wallet);
|
||||||
std::string LabelFromValue(const UniValue& value);
|
std::string LabelFromValue(const UniValue& value);
|
||||||
|
|
||||||
|
std::tuple<std::shared_ptr<CWallet>, std::vector<bilingual_str>> LoadWalletHelper(WalletContext& context, UniValue load_on_start_param, const std::string wallet_name);
|
||||||
|
|
||||||
#endif // BITCOIN_WALLET_RPC_UTIL_H
|
#endif // BITCOIN_WALLET_RPC_UTIL_H
|
||||||
@@ -2191,37 +2191,6 @@ static RPCHelpMan listwallets()
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::tuple<std::shared_ptr<CWallet>, std::vector<bilingual_str>> LoadWalletHelper(WalletContext& context, UniValue load_on_start_param, const std::string wallet_name)
|
|
||||||
{
|
|
||||||
DatabaseOptions options;
|
|
||||||
DatabaseStatus status;
|
|
||||||
options.require_existing = true;
|
|
||||||
bilingual_str error;
|
|
||||||
std::vector<bilingual_str> warnings;
|
|
||||||
std::optional<bool> load_on_start = load_on_start_param.isNull() ? std::nullopt : std::optional<bool>(load_on_start_param.get_bool());
|
|
||||||
std::shared_ptr<CWallet> const wallet = LoadWallet(context, wallet_name, load_on_start, options, status, error, warnings);
|
|
||||||
|
|
||||||
if (!wallet) {
|
|
||||||
// Map bad format to not found, since bad format is returned when the
|
|
||||||
// wallet directory exists, but doesn't contain a data file.
|
|
||||||
RPCErrorCode code = RPC_WALLET_ERROR;
|
|
||||||
switch (status) {
|
|
||||||
case DatabaseStatus::FAILED_NOT_FOUND:
|
|
||||||
case DatabaseStatus::FAILED_BAD_FORMAT:
|
|
||||||
code = RPC_WALLET_NOT_FOUND;
|
|
||||||
break;
|
|
||||||
case DatabaseStatus::FAILED_ALREADY_LOADED:
|
|
||||||
code = RPC_WALLET_ALREADY_LOADED;
|
|
||||||
break;
|
|
||||||
default: // RPC_WALLET_ERROR is returned for all other cases.
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
throw JSONRPCError(code, error.original);
|
|
||||||
}
|
|
||||||
|
|
||||||
return { wallet, warnings };
|
|
||||||
}
|
|
||||||
|
|
||||||
static RPCHelpMan loadwallet()
|
static RPCHelpMan loadwallet()
|
||||||
{
|
{
|
||||||
return RPCHelpMan{"loadwallet",
|
return RPCHelpMan{"loadwallet",
|
||||||
|
|||||||
@@ -7,18 +7,10 @@
|
|||||||
|
|
||||||
#include <span.h>
|
#include <span.h>
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
class CRPCCommand;
|
class CRPCCommand;
|
||||||
class CWallet;
|
|
||||||
struct WalletContext;
|
|
||||||
|
|
||||||
Span<const CRPCCommand> GetWalletRPCCommands();
|
Span<const CRPCCommand> GetWalletRPCCommands();
|
||||||
|
|
||||||
std::tuple<std::shared_ptr<CWallet>, std::vector<bilingual_str>> LoadWalletHelper(WalletContext& context, UniValue load_on_start_param, const std::string wallet_name);
|
|
||||||
|
|
||||||
RPCHelpMan getaddressinfo();
|
RPCHelpMan getaddressinfo();
|
||||||
RPCHelpMan signrawtransactionwithwallet();
|
RPCHelpMan signrawtransactionwithwallet();
|
||||||
#endif // BITCOIN_WALLET_RPCWALLET_H
|
#endif // BITCOIN_WALLET_RPCWALLET_H
|
||||||
Reference in new issue
Block a user