Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcdump.cpp
Show First 20 Lines • Show All 1,070 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; | std::map<CKeyID, std::pair<CPubKey, 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 333 Lines • ▼ Show 20 Lines | static UniValue ProcessImportDescriptor(ImportData &import_data, | ||||
// multisigs which could be spendable without all keys. Thus, threshold | // multisigs which could be spendable without all keys. Thus, threshold | ||||
// multisigs without all keys will be considered not spendable here, even if | // multisigs without all keys will be considered not spendable here, even if | ||||
// they are, perhaps triggering a false warning message. This is consistent | // they are, perhaps triggering a false warning message. This is consistent | ||||
// with the current wallet IsMine check. | // with the current wallet IsMine check. | ||||
bool spendable = | bool spendable = | ||||
std::all_of(pubkey_map.begin(), pubkey_map.end(), | std::all_of(pubkey_map.begin(), pubkey_map.end(), | ||||
[&](const std::pair<CKeyID, CPubKey> &used_key) { | [&](const std::pair<CKeyID, CPubKey> &used_key) { | ||||
return privkey_map.count(used_key.first) > 0; | return privkey_map.count(used_key.first) > 0; | ||||
}); | }) && | ||||
std::all_of( | |||||
import_data.key_origins.begin(), import_data.key_origins.end(), | |||||
[&](const std::pair<CKeyID, std::pair<CPubKey, KeyOriginInfo>> | |||||
&entry) { return privkey_map.count(entry.first) > 0; }); | |||||
if (!watch_only && !spendable) { | if (!watch_only && !spendable) { | ||||
warnings.push_back( | warnings.push_back( | ||||
"Some private keys are missing, outputs will be considered " | "Some private keys are missing, outputs will be considered " | ||||
"watchonly. If this is intentional, specify the watchonly flag."); | "watchonly. If this is intentional, specify the watchonly flag."); | ||||
} | } | ||||
if (watch_only && spendable) { | if (watch_only && spendable) { | ||||
warnings.push_back("All private keys are provided, outputs will be " | warnings.push_back("All private keys are provided, outputs will be " | ||||
"considered spendable. If this is intentional, do " | "considered spendable. If this is intentional, do " | ||||
▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | try { | ||||
pwallet->mapKeyMetadata[id].nCreateTime = timestamp; | pwallet->mapKeyMetadata[id].nCreateTime = timestamp; | ||||
// If the private key is not present in the wallet, insert it. | // If the private key is not present in the wallet, insert it. | ||||
if (!pwallet->HaveKey(id) && !pwallet->AddKeyPubKey(key, pubkey)) { | if (!pwallet->HaveKey(id) && !pwallet->AddKeyPubKey(key, pubkey)) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, | throw JSONRPCError(RPC_WALLET_ERROR, | ||||
"Error adding key to wallet"); | "Error adding key to wallet"); | ||||
} | } | ||||
pwallet->UpdateTimeFirstKey(timestamp); | pwallet->UpdateTimeFirstKey(timestamp); | ||||
} | } | ||||
for (const auto &entry : import_data.key_origins) { | |||||
pwallet->AddKeyOrigin(entry.second.first, entry.second.second); | |||||
} | |||||
for (const CKeyID &id : ordered_pubkeys) { | for (const CKeyID &id : ordered_pubkeys) { | ||||
auto entry = pubkey_map.find(id); | auto entry = pubkey_map.find(id); | ||||
if (entry == pubkey_map.end()) { | if (entry == pubkey_map.end()) { | ||||
continue; | continue; | ||||
} | } | ||||
const CPubKey &pubkey = entry->second; | const CPubKey &pubkey = entry->second; | ||||
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; | pwallet->mapKeyMetadata[id].nCreateTime = timestamp; | ||||
// Add to keypool only works with pubkeys | // Add to keypool only works with pubkeys | ||||
if (add_keypool) { | if (add_keypool) { | ||||
pwallet->AddKeypoolPubkey(pubkey, internal); | pwallet->AddKeypoolPubkey(pubkey, internal); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 357 Lines • Show Last 20 Lines |