Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcdump.cpp
Show First 20 Lines • Show All 1,061 Lines • ▼ Show 20 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 347 Lines • Show Last 20 Lines |