Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcdump.cpp
// 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 "base58.h" | #include "base58.h" | ||||
#include "chain.h" | #include "chain.h" | ||||
#include "config.h" | |||||
#include "core_io.h" | #include "core_io.h" | ||||
#include "dstencode.h" | #include "dstencode.h" | ||||
#include "init.h" | #include "init.h" | ||||
#include "merkleblock.h" | #include "merkleblock.h" | ||||
#include "rpc/server.h" | #include "rpc/server.h" | ||||
#include "rpcwallet.h" | #include "rpcwallet.h" | ||||
#include "script/script.h" | #include "script/script.h" | ||||
#include "script/standard.h" | #include "script/standard.h" | ||||
▲ Show 20 Lines • Show All 250 Lines • ▼ Show 20 Lines | UniValue importaddress(const Config &config, const JSONRPCRequest &request) { | ||||
// Whether to import a p2sh version, too | // Whether to import a p2sh version, too | ||||
bool fP2SH = false; | bool fP2SH = false; | ||||
if (request.params.size() > 3) { | if (request.params.size() > 3) { | ||||
fP2SH = request.params[3].get_bool(); | fP2SH = request.params[3].get_bool(); | ||||
} | } | ||||
LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, pwallet->cs_wallet); | ||||
CTxDestination dest = DecodeDestination(request.params[0].get_str()); | CTxDestination dest = | ||||
DecodeDestination(request.params[0].get_str(), config.GetChainParams()); | |||||
if (IsValidDestination(dest)) { | if (IsValidDestination(dest)) { | ||||
if (fP2SH) { | if (fP2SH) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Cannot use the p2sh flag with an address - use " | "Cannot use the p2sh flag with an address - use " | ||||
"a script instead"); | "a script instead"); | ||||
} | } | ||||
ImportAddress(pwallet, dest, strLabel); | ImportAddress(pwallet, dest, strLabel); | ||||
} else if (IsHex(request.params[0].get_str())) { | } else if (IsHex(request.params[0].get_str())) { | ||||
▲ Show 20 Lines • Show All 359 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() != 1) { | ||||
HelpExampleRpc("dumpprivkey", "\"myaddress\"")); | HelpExampleRpc("dumpprivkey", "\"myaddress\"")); | ||||
} | } | ||||
LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, pwallet->cs_wallet); | ||||
EnsureWalletIsUnlocked(pwallet); | EnsureWalletIsUnlocked(pwallet); | ||||
std::string strAddress = request.params[0].get_str(); | std::string strAddress = request.params[0].get_str(); | ||||
CTxDestination dest = DecodeDestination(strAddress); | CTxDestination dest = | ||||
DecodeDestination(strAddress, config.GetChainParams()); | |||||
if (!IsValidDestination(dest)) { | if (!IsValidDestination(dest)) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Invalid Bitcoin address"); | "Invalid Bitcoin address"); | ||||
} | } | ||||
const CKeyID *keyID = boost::get<CKeyID>(&dest); | const CKeyID *keyID = boost::get<CKeyID>(&dest); | ||||
if (!keyID) { | if (!keyID) { | ||||
throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to a key"); | throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to a key"); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 673 Lines • Show Last 20 Lines |