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 <chain.h> | #include <chain.h> | ||||
#include <config.h> | #include <config.h> | ||||
#include <core_io.h> | #include <core_io.h> | ||||
#include <interfaces/chain.h> | #include <interfaces/chain.h> | ||||
#include <key_io.h> | #include <key_io.h> | ||||
#include <merkleblock.h> | #include <merkleblock.h> | ||||
#include <rpc/server.h> | #include <rpc/server.h> | ||||
#include <rpc/util.h> | #include <rpc/util.h> | ||||
#include <script/descriptor.h> | #include <script/descriptor.h> | ||||
#include <script/script.h> | #include <script/script.h> | ||||
#include <script/standard.h> | #include <script/standard.h> | ||||
#include <sync.h> | #include <sync.h> | ||||
#include <util/bip32.h> | |||||
#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 <validation.h> | #include <validation.h> | ||||
#include <wallet/rpcwallet.h> | #include <wallet/rpcwallet.h> | ||||
#include <wallet/wallet.h> | #include <wallet/wallet.h> | ||||
#include <boost/algorithm/string.hpp> | #include <boost/algorithm/string.hpp> | ||||
▲ Show 20 Lines • Show All 1,003 Lines • ▼ Show 20 Lines | for (std::vector<std::pair<int64_t, CKeyID>>::const_iterator it = | ||||
file << "reserve=1"; | file << "reserve=1"; | ||||
} else if (pwallet->mapKeyMetadata[keyid].hdKeypath == "s") { | } else if (pwallet->mapKeyMetadata[keyid].hdKeypath == "s") { | ||||
file << "inactivehdseed=1"; | file << "inactivehdseed=1"; | ||||
} else { | } else { | ||||
file << "change=1"; | file << "change=1"; | ||||
} | } | ||||
file << strprintf( | file << strprintf( | ||||
" # addr=%s%s\n", strAddr, | " # addr=%s%s\n", strAddr, | ||||
(pwallet->mapKeyMetadata[keyid].hdKeypath.size() > 0 | (pwallet->mapKeyMetadata[keyid].has_key_origin | ||||
? " hdkeypath=" + pwallet->mapKeyMetadata[keyid].hdKeypath | ? " hdkeypath=" + | ||||
WriteHDKeypath( | |||||
pwallet->mapKeyMetadata[keyid].key_origin.path) | |||||
: "")); | : "")); | ||||
} | } | ||||
} | } | ||||
file << "\n"; | file << "\n"; | ||||
for (const CScriptID &scriptid : scripts) { | for (const CScriptID &scriptid : scripts) { | ||||
CScript script; | CScript script; | ||||
std::string create_time = "0"; | std::string create_time = "0"; | ||||
std::string address = EncodeDestination(scriptid, config); | std::string address = EncodeDestination(scriptid, config); | ||||
Show All 24 Lines | struct ImportData { | ||||
//! Provided redeemScript; will be moved to `import_scripts` if relevant. | //! Provided redeemScript; will be moved to `import_scripts` if relevant. | ||||
std::unique_ptr<CScript> redeemscript; | std::unique_ptr<CScript> redeemscript; | ||||
// Output data | // Output data | ||||
std::set<CScript> import_scripts; | std::set<CScript> import_scripts; | ||||
//! Import these private keys if available (the value indicates whether if | //! Import these private keys if available (the value indicates whether if | ||||
//! the key is required for solvability) | //! the key is required for solvability) | ||||
std::map<CKeyID, bool> used_keys; | std::map<CKeyID, bool> used_keys; | ||||
std::map<CKeyID, KeyOriginInfo> key_origins; | |||||
}; | }; | ||||
enum class ScriptContext { | enum class ScriptContext { | ||||
//! Top-level scriptPubKey | //! Top-level scriptPubKey | ||||
TOP, | TOP, | ||||
//! P2SH redeemScript | //! P2SH redeemScript | ||||
P2SH, | P2SH, | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 299 Lines • ▼ Show 20 Lines | static UniValue ProcessImportDescriptor(ImportData &import_data, | ||||
} | } | ||||
for (const auto &x : out_keys.scripts) { | for (const auto &x : out_keys.scripts) { | ||||
import_data.import_scripts.emplace(x.second); | import_data.import_scripts.emplace(x.second); | ||||
} | } | ||||
std::copy(out_keys.pubkeys.begin(), out_keys.pubkeys.end(), | std::copy(out_keys.pubkeys.begin(), out_keys.pubkeys.end(), | ||||
std::inserter(pubkey_map, pubkey_map.end())); | std::inserter(pubkey_map, pubkey_map.end())); | ||||
import_data.key_origins.insert(out_keys.origins.begin(), | |||||
out_keys.origins.end()); | |||||
for (size_t i = 0; i < priv_keys.size(); ++i) { | for (size_t i = 0; i < priv_keys.size(); ++i) { | ||||
const auto &str = priv_keys[i].get_str(); | const auto &str = priv_keys[i].get_str(); | ||||
CKey key = DecodeSecret(str); | CKey key = DecodeSecret(str); | ||||
if (!key.IsValid()) { | if (!key.IsValid()) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Invalid private key encoding"); | "Invalid private key encoding"); | ||||
} | } | ||||
CPubKey pubkey = key.GetPubKey(); | CPubKey pubkey = key.GetPubKey(); | ||||
▲ Show 20 Lines • Show All 122 Lines • ▼ Show 20 Lines | try { | ||||
const CKeyID &id = entry.first; | const CKeyID &id = entry.first; | ||||
CPubKey temp; | CPubKey temp; | ||||
if (!pwallet->GetPubKey(id, temp) && | if (!pwallet->GetPubKey(id, temp) && | ||||
!pwallet->AddWatchOnly(GetScriptForRawPubKey(pubkey), | !pwallet->AddWatchOnly(GetScriptForRawPubKey(pubkey), | ||||
timestamp)) { | timestamp)) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, | throw JSONRPCError(RPC_WALLET_ERROR, | ||||
"Error adding address to wallet"); | "Error adding address to wallet"); | ||||
} | } | ||||
const auto &key_orig_it = import_data.key_origins.find(id); | |||||
if (key_orig_it != import_data.key_origins.end()) { | |||||
pwallet->AddKeyOrigin(pubkey, key_orig_it->second); | |||||
} | |||||
pwallet->mapKeyMetadata[id].nCreateTime = timestamp; | |||||
} | } | ||||
for (const CScript &script : script_pub_keys) { | for (const CScript &script : script_pub_keys) { | ||||
if (!have_solving_data || !::IsMine(*pwallet, script)) { | if (!have_solving_data || !::IsMine(*pwallet, script)) { | ||||
// Always call AddWatchOnly for non-solvable watch-only, so that | // Always call AddWatchOnly for non-solvable watch-only, so that | ||||
// watch timestamp gets updated | // watch timestamp gets updated | ||||
if (!pwallet->AddWatchOnly(script, timestamp)) { | if (!pwallet->AddWatchOnly(script, timestamp)) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, | throw JSONRPCError(RPC_WALLET_ERROR, | ||||
▲ Show 20 Lines • Show All 357 Lines • Show Last 20 Lines |