aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorJonas Schnelli <dev@jonasschnelli.ch>2019-02-12 08:19:05 -1000
committerJonas Schnelli <dev@jonasschnelli.ch>2019-02-12 08:20:50 -1000
commit7d3f255316fc0d45272a38e3fea206105f67dc45 (patch)
tree9ea3977ad966597372981d790b40650e2f820783 /src/wallet
parentd8794a78a887a920276c7124f1c46d69592c6c4e (diff)
parent1951ea4342db4122032660139248b79a02c574f3 (diff)
downloadbitcoin-7d3f255316fc0d45272a38e3fea206105f67dc45.tar.xz
Merge #15153: gui: Add Open Wallet menu
1951ea434 gui: Show indeterminate progress dialog while opening walllet (João Barbosa) 8847cdaaa gui: Add OpenWalletActivity (João Barbosa) 4c8982a88 interfaces: Avoid interface instance if wallet is null (João Barbosa) be82dea23 gui: Add thread to run background activity in WalletController (João Barbosa) 6c49a55b4 gui: Add Open Wallet menu (João Barbosa) 32a8c6abf gui: Add openWallet and getWalletsAvailableToOpen to WalletController (João Barbosa) ab288b4e5 interfaces: Add loadWallet to Node (João Barbosa) 17abc0fd5 wallet: Factor out LoadWallet (João Barbosa) Pull request description: The *Open Wallet* menu has all the available wallets currently not loaded. The list of the available wallets comes from `listWalletDir`. In the future the menu can be replaced by a custom dialog. <img width="674" alt="screenshot 2019-01-12 at 12 17 02" src="https://user-images.githubusercontent.com/3534524/51073166-ac041480-1664-11e9-8302-be81702bc146.png"> Tree-SHA512: ebfd75eee0c8264863748899843afab67dadb7dff21313c11e3cb5b6108d954978dd1f1ae786bc07580c5a771ea4ab38d18c1643c9b9b3683ed53f0f6c582e38
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/rpcwallet.cpp16
-rw-r--r--src/wallet/wallet.cpp22
-rw-r--r--src/wallet/wallet.h1
3 files changed, 26 insertions, 13 deletions
diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp
index 9bbbdc6132..a9fbed5423 100644
--- a/src/wallet/rpcwallet.cpp
+++ b/src/wallet/rpcwallet.cpp
@@ -2555,7 +2555,6 @@ static UniValue loadwallet(const JSONRPCRequest& request)
}.ToString());
WalletLocation location(request.params[0].get_str());
- std::string error;
if (!location.Exists()) {
throw JSONRPCError(RPC_WALLET_NOT_FOUND, "Wallet " + location.GetName() + " not found.");
@@ -2567,18 +2566,9 @@ static UniValue loadwallet(const JSONRPCRequest& request)
}
}
- std::string warning;
- if (!CWallet::Verify(*g_rpc_interfaces->chain, location, false, error, warning)) {
- throw JSONRPCError(RPC_WALLET_ERROR, "Wallet file verification failed: " + error);
- }
-
- std::shared_ptr<CWallet> const wallet = CWallet::CreateWalletFromFile(*g_rpc_interfaces->chain, location);
- if (!wallet) {
- throw JSONRPCError(RPC_WALLET_ERROR, "Wallet loading failed.");
- }
- AddWallet(wallet);
-
- wallet->postInitProcess();
+ std::string error, warning;
+ std::shared_ptr<CWallet> const wallet = LoadWallet(*g_rpc_interfaces->chain, location, error, warning);
+ if (!wallet) throw JSONRPCError(RPC_WALLET_ERROR, error);
UniValue obj(UniValue::VOBJ);
obj.pushKV("name", wallet->GetName());
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index d38c15220f..063015d1d8 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -130,6 +130,28 @@ void UnloadWallet(std::shared_ptr<CWallet>&& wallet)
}
}
+std::shared_ptr<CWallet> LoadWallet(interfaces::Chain& chain, const WalletLocation& location, std::string& error, std::string& warning)
+{
+ if (!CWallet::Verify(chain, location, false, error, warning)) {
+ error = "Wallet file verification failed: " + error;
+ return nullptr;
+ }
+
+ std::shared_ptr<CWallet> wallet = CWallet::CreateWalletFromFile(chain, location);
+ if (!wallet) {
+ error = "Wallet loading failed.";
+ return nullptr;
+ }
+ AddWallet(wallet);
+ wallet->postInitProcess();
+ return wallet;
+}
+
+std::shared_ptr<CWallet> LoadWallet(interfaces::Chain& chain, const std::string& name, std::string& error, std::string& warning)
+{
+ return LoadWallet(chain, WalletLocation(name), error, warning);
+}
+
const uint32_t BIP32_HARDENED_KEY_LIMIT = 0x80000000;
const uint256 CMerkleTx::ABANDON_HASH(uint256S("0000000000000000000000000000000000000000000000000000000000000001"));
diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h
index c455b7cdad..5846ac0f3e 100644
--- a/src/wallet/wallet.h
+++ b/src/wallet/wallet.h
@@ -66,6 +66,7 @@ bool RemoveWallet(const std::shared_ptr<CWallet>& wallet);
bool HasWallets();
std::vector<std::shared_ptr<CWallet>> GetWallets();
std::shared_ptr<CWallet> GetWallet(const std::string& name);
+std::shared_ptr<CWallet> LoadWallet(interfaces::Chain& chain, const WalletLocation& location, std::string& error, std::string& warning);
//! Default for -keypool
static const unsigned int DEFAULT_KEYPOOL_SIZE = 1000;