Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
// Copyright (c) 2010 Satoshi Nakamoto | // Copyright (c) 2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include "amount.h" | #include "amount.h" | ||||
#include "chain.h" | #include "chain.h" | ||||
#include "chainparams.h" // for GetConsensus. | #include "chainparams.h" // for GetConsensus. | ||||
#include "config.h" | #include "config.h" | ||||
#include "consensus/validation.h" | #include "consensus/validation.h" | ||||
#include "core_io.h" | #include "core_io.h" | ||||
#include "dstencode.h" | #include "dstencode.h" | ||||
#include "httpserver.h" | |||||
#include "init.h" | #include "init.h" | ||||
#include "net.h" | #include "net.h" | ||||
#include "rpc/misc.h" | #include "rpc/misc.h" | ||||
#include "rpc/server.h" | #include "rpc/server.h" | ||||
#include "timedata.h" | #include "timedata.h" | ||||
#include "util.h" | #include "util.h" | ||||
#include "utilmoneystr.h" | #include "utilmoneystr.h" | ||||
#include "validation.h" | #include "validation.h" | ||||
#include "wallet.h" | #include "wallet.h" | ||||
#include "walletdb.h" | #include "walletdb.h" | ||||
#include <univalue.h> | #include <univalue.h> | ||||
#include <cstdint> | static const std::string WALLET_ENDPOINT_BASE = "/wallet/"; | ||||
CWallet *GetWalletForJSONRPCRequest(const JSONRPCRequest &request) { | CWallet *GetWalletForJSONRPCRequest(const JSONRPCRequest &request) { | ||||
// TODO: Some way to access secondary wallets | if (request.URI.substr(0, WALLET_ENDPOINT_BASE.size()) == | ||||
return vpwallets.empty() ? nullptr : vpwallets[0]; | WALLET_ENDPOINT_BASE) { | ||||
// wallet endpoint was used | |||||
std::string requestedWallet = | |||||
urlDecode(request.URI.substr(WALLET_ENDPOINT_BASE.size())); | |||||
for (CWalletRef pwallet : ::vpwallets) { | |||||
if (pwallet->GetName() == requestedWallet) { | |||||
return pwallet; | |||||
} | |||||
} | |||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | |||||
"Requested wallet does not exist or is not loaded"); | |||||
} | |||||
return ::vpwallets.size() == 1 || (request.fHelp && ::vpwallets.size() > 0) | |||||
? ::vpwallets[0] | |||||
: nullptr; | |||||
} | } | ||||
std::string HelpRequiringPassphrase(CWallet *const pwallet) { | std::string HelpRequiringPassphrase(CWallet *const pwallet) { | ||||
return pwallet && pwallet->IsCrypted() ? "\nRequires wallet passphrase to " | return pwallet && pwallet->IsCrypted() ? "\nRequires wallet passphrase to " | ||||
"be set with walletpassphrase " | "be set with walletpassphrase " | ||||
"call." | "call." | ||||
: ""; | : ""; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 3,378 Lines • Show Last 20 Lines |