26 error =
_(
"Error: Legacy wallets only support the \"legacy\", \"p2sh-segwit\", and \"bech32\" address types").
translated;
37 error =
_(
"Error: Keypool ran out, please call keypoolrefill first").
translated;
45 typedef std::vector<unsigned char>
valtype;
77 return sigversion == IsMineSigVersion::TOP || sigversion == IsMineSigVersion::P2SH;
82 for (
const valtype& pubkey : pubkeys) {
84 if (!keystore.
HaveKey(keyID))
return false;
101 std::vector<valtype> vSolutions;
113 if (!PermitsUncompressed(sigversion) && vSolutions[0].size() != 33) {
114 return IsMineResult::INVALID;
117 ret = std::max(ret, IsMineResult::SPENDABLE);
122 if (sigversion == IsMineSigVersion::WITNESS_V0) {
124 return IsMineResult::INVALID;
137 if (!PermitsUncompressed(sigversion)) {
140 return IsMineResult::INVALID;
144 ret = std::max(ret, IsMineResult::SPENDABLE);
149 if (sigversion != IsMineSigVersion::TOP) {
151 return IsMineResult::INVALID;
155 if (keystore.
GetCScript(scriptID, subscript)) {
156 ret = std::max(ret, recurse_scripthash ? IsMineInner(keystore, subscript, IsMineSigVersion::P2SH) : IsMineResult::SPENDABLE);
162 if (sigversion == IsMineSigVersion::WITNESS_V0) {
164 return IsMineResult::INVALID;
173 if (keystore.
GetCScript(scriptID, subscript)) {
174 ret = std::max(ret, recurse_scripthash ? IsMineInner(keystore, subscript, IsMineSigVersion::WITNESS_V0) : IsMineResult::SPENDABLE);
182 if (sigversion == IsMineSigVersion::TOP) {
191 std::vector<valtype> keys(vSolutions.begin()+1, vSolutions.begin()+vSolutions.size()-1);
192 if (!PermitsUncompressed(sigversion)) {
193 for (
size_t i = 0; i < keys.size(); i++) {
194 if (keys[i].size() != 33) {
195 return IsMineResult::INVALID;
199 if (HaveKeys(keys, keystore)) {
200 ret = std::max(ret, IsMineResult::SPENDABLE);
206 if (ret == IsMineResult::NO && keystore.
HaveWatchOnly(scriptPubKey)) {
207 ret = std::max(ret, IsMineResult::WATCH_ONLY);
216 switch (IsMineInner(*
this, script, IsMineSigVersion::TOP)) {
217 case IsMineResult::INVALID:
218 case IsMineResult::NO:
220 case IsMineResult::WATCH_ONLY:
222 case IsMineResult::SPENDABLE:
234 bool keyPass = mapCryptedKeys.empty();
235 bool keyFail =
false;
236 CryptedKeyMap::const_iterator mi = mapCryptedKeys.begin();
238 for (; mi != mapCryptedKeys.end(); ++mi)
240 const CPubKey &vchPubKey = (*mi).second.first;
241 const std::vector<unsigned char> &vchCryptedSecret = (*mi).second.second;
243 if (!
DecryptKey(master_key, vchCryptedSecret, vchPubKey, key))
253 batch.WriteCryptedKey(vchPubKey, vchCryptedSecret, mapKeyMetadata[vchPubKey.
GetID()]);
256 if (keyPass && keyFail)
258 LogPrintf(
"The wallet is probably corrupted: Some keys decrypt but not all.\n");
259 throw std::runtime_error(
"Error unlocking wallet: some keys decrypt but not all. Your wallet file may be corrupt.");
261 if (keyFail || (!keyPass && !accept_no_keys))
271 encrypted_batch = batch;
272 if (!mapCryptedKeys.empty()) {
273 encrypted_batch =
nullptr;
278 keys_to_encrypt.swap(mapKeys);
279 for (
const KeyMap::value_type& mKey : keys_to_encrypt)
281 const CKey &key = mKey.second;
284 std::vector<unsigned char> vchCryptedSecret;
286 encrypted_batch =
nullptr;
290 encrypted_batch =
nullptr;
294 encrypted_batch =
nullptr;
301 error =
_(
"Error: Legacy wallets only support the \"legacy\", \"p2sh-segwit\", and \"bech32\" address types").
translated;
308 error =
_(
"Error: Keypool ran out, please call keypoolrefill first").
translated;
313 error =
_(
"Error: Keypool ran out, please call keypoolrefill first").
translated;
341 int64_t missing = std::max(target_size - kp_size, (int64_t) 0);
345 for (int64_t i = missing; i > 0; --i) {
364 WalletLogPrintf(
"%s: Detected a used keypool key, mark all keypool keys up to this key as used\n", __func__);
368 WalletLogPrintf(
"%s: Topping up keypool failed (locked wallet)\n", __func__);
374 auto it = mapKeyMetadata.find(keyid);
375 if (it != mapKeyMetadata.end()){
397 for (
auto& meta_pair : mapKeyMetadata) {
408 throw std::runtime_error(
"Invalid stored hdKeypath");
417 if (
GetPubKey(meta_pair.first, pubkey)) {
418 batch->WriteKeyMetadata(meta, pubkey,
true);
446 bool keypool_has_keys;
448 keypool_has_keys = setInternalKeyPool.size() > 0;
453 if (!keypool_has_keys) {
456 return keypool_has_keys;
462 bool hd_upgrade =
false;
463 bool split_upgrade =
false;
482 throw std::runtime_error(std::string(__func__) +
": writing chain failed");
493 error =
_(
"Unable to generate keys");
503 return !mapKeys.empty() || !mapCryptedKeys.empty();
509 setInternalKeyPool.clear();
510 setExternalKeyPool.clear();
518 if (setKeyPool.empty()) {
523 int64_t nIndex = *(setKeyPool.begin());
524 if (!batch.
ReadPool(nIndex, keypool)) {
525 throw std::runtime_error(std::string(__func__) +
": read oldest key in keypool failed");
528 return keypool.
nTime;
541 if (!set_pre_split_keypool.empty()) {
552 return setExternalKeyPool.size() + set_pre_split_keypool.size();
558 return setInternalKeyPool.size() + setExternalKeyPool.size() + set_pre_split_keypool.size();
564 return nTimeFirstKey;
569 return std::make_unique<LegacySigningProvider>(*this);
574 IsMineResult ismine = IsMineInner(*
this, script, IsMineSigVersion::TOP,
false);
575 if (ismine == IsMineResult::SPENDABLE || ismine == IsMineResult::WATCH_ONLY) {
585 bool has_privkeys =
false;
586 for (
const auto& key_sig_pair : sigdata.
signatures) {
587 has_privkeys |=
HaveKey(key_sig_pair.first);
618 for (
unsigned int i = 0; i < psbtx.
tx->vin.size(); ++i) {
619 const CTxIn& txin = psbtx.
tx->vin[i];
645 if (n_signed && (signed_one || !sign)) {
654 for (
unsigned int i = 0; i < psbtx.
tx->vout.size(); ++i) {
667 auto it = mapKeyMetadata.find(key_id);
668 if (it != mapKeyMetadata.end()) {
669 return std::make_unique<CKeyMetadata>(it->second);
674 auto it = m_script_metadata.find(
CScriptID(scriptPubKey));
675 if (it != m_script_metadata.end()) {
676 return std::make_unique<CKeyMetadata>(it->second);
694 if (nCreateTime <= 1) {
698 }
else if (!nTimeFirstKey || nCreateTime < nTimeFirstKey) {
699 nTimeFirstKey = nCreateTime;
725 bool needsDB = !encrypted_batch;
727 encrypted_batch = &batch;
730 if (needsDB) encrypted_batch =
nullptr;
733 if (needsDB) encrypted_batch =
nullptr;
749 mapKeyMetadata[pubkey.
GetID()]);
763 WalletLogPrintf(
"%s: Warning: This wallet contains a redeemScript of size %i which exceeds maximum size %i thus can never be redeemed. Do not use address %s.\n", __func__, redeemScript.
size(),
MAX_SCRIPT_ELEMENT_SIZE, strAddr);
774 mapKeyMetadata[keyID] = meta;
781 m_script_metadata[script_id] = meta;
795 std::vector<unsigned char> vchCryptedSecret;
810 if (!checksum_valid) {
822 mapCryptedKeys[vchPubKey.
GetID()] = make_pair(vchPubKey, vchCryptedSecret);
828 const std::vector<unsigned char> &vchCryptedSecret)
835 return encrypted_batch->WriteCryptedKey(vchPubKey,
837 mapKeyMetadata[vchPubKey.
GetID()]);
841 mapKeyMetadata[vchPubKey.
GetID()]);
848 return setWatchOnly.count(dest) > 0;
854 return (!setWatchOnly.empty());
859 std::vector<std::vector<unsigned char>> solutions;
861 (pubKeyOut =
CPubKey(solutions[0])).IsFullyValid();
868 setWatchOnly.erase(dest);
871 mapWatchKeys.erase(pubKey.
GetID());
893 setWatchOnly.insert(dest);
896 mapWatchKeys[pubKey.
GetID()] = pubKey;
918 m_script_metadata[
CScriptID(dest)].nCreateTime = create_time;
930 m_script_metadata[
CScriptID(dest)].nCreateTime = nCreateTime;
945 throw std::runtime_error(std::string(__func__) +
": writing chain failed");
968 return mapCryptedKeys.count(address) > 0;
978 CryptedKeyMap::const_iterator mi = mapCryptedKeys.find(address);
979 if (mi != mapCryptedKeys.end())
981 const CPubKey &vchPubKey = (*mi).second.first;
982 const std::vector<unsigned char> &vchCryptedSecret = (*mi).second.second;
993 auto it = mapKeyMetadata.find(keyID);
994 if (it != mapKeyMetadata.end()) {
1010 WatchKeyMap::const_iterator it = mapWatchKeys.find(address);
1011 if (it != mapWatchKeys.end()) {
1012 pubkey_out = it->second;
1028 CryptedKeyMap::const_iterator mi = mapCryptedKeys.find(address);
1029 if (mi != mapCryptedKeys.end())
1031 vchPubKeyOut = (*mi).second.first;
1048 int64_t nCreationTime =
GetTime();
1066 mapKeyMetadata[pubkey.
GetID()] = metadata;
1070 throw std::runtime_error(std::string(__func__) +
": AddKey failed");
1086 throw std::runtime_error(std::string(__func__) +
": seed not found");
1120 secret = childKey.
key;
1127 throw std::runtime_error(std::string(__func__) +
": writing HD chain model failed");
1134 set_pre_split_keypool.insert(nIndex);
1136 setInternalKeyPool.insert(nIndex);
1138 setExternalKeyPool.insert(nIndex);
1140 m_max_keypool_index = std::max(m_max_keypool_index, nIndex);
1147 if (mapKeyMetadata.count(keyid) == 0)
1168 int64_t nCreationTime =
GetTime();
1184 mapKeyMetadata[seed.
GetID()] = metadata;
1188 throw std::runtime_error(std::string(__func__) +
": AddKeyPubKey failed");
1222 for (
const int64_t nIndex : setInternalKeyPool) {
1225 setInternalKeyPool.clear();
1227 for (
const int64_t nIndex : setExternalKeyPool) {
1228 batch.ErasePool(nIndex);
1230 setExternalKeyPool.clear();
1232 for (
const int64_t nIndex : set_pre_split_keypool) {
1233 batch.ErasePool(nIndex);
1235 set_pre_split_keypool.clear();
1242 WalletLogPrintf(
"LegacyScriptPubKeyMan::NewKeyPool rewrote keypool\n");
1258 unsigned int nTargetSize;
1260 nTargetSize = kpSize;
1266 int64_t missingExternal = std::max(std::max((int64_t) nTargetSize, (int64_t) 1) - (int64_t)setExternalKeyPool.size(), (int64_t) 0);
1267 int64_t missingInternal = std::max(std::max((int64_t) nTargetSize, (int64_t) 1) - (int64_t)setInternalKeyPool.size(), (int64_t) 0);
1272 missingInternal = 0;
1274 bool internal =
false;
1276 for (int64_t i = missingInternal + missingExternal; i--;)
1278 if (i < missingInternal) {
1285 if (missingInternal + missingExternal > 0) {
1286 WalletLogPrintf(
"keypool added %d keys (%d internal), size=%u (%u internal)\n", missingInternal + missingExternal, missingInternal, setInternalKeyPool.size() + setExternalKeyPool.size() + set_pre_split_keypool.size(), setInternalKeyPool.size());
1296 assert(m_max_keypool_index < std::numeric_limits<int64_t>::max());
1297 int64_t index = ++m_max_keypool_index;
1299 throw std::runtime_error(std::string(__func__) +
": writing imported pubkey failed");
1302 setInternalKeyPool.insert(index);
1304 setExternalKeyPool.insert(index);
1329 setInternalKeyPool.insert(nIndex);
1330 }
else if (!set_pre_split_keypool.empty()) {
1331 set_pre_split_keypool.insert(nIndex);
1333 setExternalKeyPool.insert(nIndex);
1373 bool fReturningInternal = fRequestedInternal;
1375 bool use_split_keypool = set_pre_split_keypool.empty();
1376 std::set<int64_t>& setKeyPool = use_split_keypool ? (fReturningInternal ? setInternalKeyPool : setExternalKeyPool) : set_pre_split_keypool;
1379 if (setKeyPool.empty()) {
1385 auto it = setKeyPool.begin();
1387 setKeyPool.erase(it);
1388 if (!batch.ReadPool(nIndex, keypool)) {
1389 throw std::runtime_error(std::string(__func__) +
": read failed");
1393 throw std::runtime_error(std::string(__func__) +
": unknown key in key pool");
1396 if (use_split_keypool && keypool.
fInternal != fReturningInternal) {
1397 throw std::runtime_error(std::string(__func__) +
": keypool entry misclassified");
1400 throw std::runtime_error(std::string(__func__) +
": keypool entry invalid");
1433 bool internal = setInternalKeyPool.count(keypool_id);
1434 if (!
internal)
assert(setExternalKeyPool.count(keypool_id) || set_pre_split_keypool.count(keypool_id));
1435 std::set<int64_t> *setKeyPool =
internal ? &setInternalKeyPool : (set_pre_split_keypool.empty() ? &setExternalKeyPool : &set_pre_split_keypool);
1436 auto it = setKeyPool->begin();
1439 while (it != std::end(*setKeyPool)) {
1440 const int64_t& index = *(it);
1441 if (index > keypool_id)
break;
1444 if (batch.ReadPool(index, keypool)) {
1448 batch.ErasePool(index);
1450 it = setKeyPool->erase(it);
1456 std::vector<CScript> dummy;
1459 std::vector<CKeyID> ret;
1460 for (
const auto& entry : out.
pubkeys) {
1461 ret.push_back(entry.first);
1469 for (
auto it = setExternalKeyPool.begin(); it != setExternalKeyPool.end();) {
1470 int64_t index = *it;
1472 if (!batch.ReadPool(index, keypool)) {
1473 throw std::runtime_error(std::string(__func__) +
": read keypool entry failed");
1476 if (!batch.WritePool(index, keypool)) {
1477 throw std::runtime_error(std::string(__func__) +
": writing modified keypool entry failed");
1479 set_pre_split_keypool.insert(index);
1480 it = setExternalKeyPool.erase(it);
1505 mapKeyMetadata[pubkey.
GetID()].key_origin.path = info.
path;
1506 mapKeyMetadata[pubkey.
GetID()].has_key_origin =
true;
1514 for (
const auto& entry : scripts) {
1524 if (timestamp > 0) {
1525 m_script_metadata[
CScriptID(entry)].nCreateTime = timestamp;
1528 if (timestamp > 0) {
1538 for (
const auto& entry : privkey_map) {
1539 const CKey& key = entry.second;
1541 const CKeyID&
id = entry.first;
1548 mapKeyMetadata[id].nCreateTime = timestamp;
1558 bool LegacyScriptPubKeyMan::ImportPubKeys(
const std::vector<CKeyID>& ordered_pubkeys,
const std::map<CKeyID, CPubKey>& pubkey_map,
const std::map<
CKeyID, std::pair<CPubKey, KeyOriginInfo>>& key_origins,
const bool add_keypool,
const bool internal,
const int64_t timestamp)
1561 for (
const auto& entry : key_origins) {
1564 for (
const CKeyID&
id : ordered_pubkeys) {
1565 auto entry = pubkey_map.find(
id);
1566 if (entry == pubkey_map.end()) {
1569 const CPubKey& pubkey = entry->second;
1579 mapKeyMetadata[id].nCreateTime = timestamp;
1593 for (
const CScript& script : script_pub_keys) {
1594 if (!have_solving_data || !
IsMine(script)) {
1609 std::set<CKeyID> set_address;
1610 for (
const auto& mi : mapCryptedKeys) {
1611 set_address.insert(mi.first);
1620 error =
"No addresses available";
1625 assert(m_wallet_descriptor.descriptor->IsSingleType());
1626 std::optional<OutputType> desc_addr_type = m_wallet_descriptor.descriptor->GetOutputType();
1628 if (type != *desc_addr_type) {
1629 throw std::runtime_error(std::string(__func__) +
": Types are inconsistent");
1636 std::vector<CScript> scripts_temp;
1639 error =
"Error: Keypool ran out, please call keypoolrefill first";
1642 if (!m_wallet_descriptor.descriptor->ExpandFromCache(m_wallet_descriptor.next_index, m_wallet_descriptor.cache, scripts_temp, out_keys)) {
1644 error =
"Error: Keypool ran out, please call keypoolrefill first";
1648 std::optional<OutputType> out_script_type = m_wallet_descriptor.descriptor->GetOutputType();
1649 if (out_script_type && out_script_type == type) {
1652 throw std::runtime_error(std::string(__func__) +
": Types are inconsistent. Stored type does not match type of newly generated address");
1654 m_wallet_descriptor.next_index++;
1663 if (m_map_script_pub_keys.count(script) > 0) {
1672 if (!m_map_keys.empty()) {
1676 bool keyPass = m_map_crypted_keys.empty();
1677 bool keyFail =
false;
1678 for (
const auto& mi : m_map_crypted_keys) {
1679 const CPubKey &pubkey = mi.second.first;
1680 const std::vector<unsigned char> &crypted_secret = mi.second.second;
1682 if (!
DecryptKey(master_key, crypted_secret, pubkey, key)) {
1690 if (keyPass && keyFail) {
1691 LogPrintf(
"The wallet is probably corrupted: Some keys decrypt but not all.\n");
1692 throw std::runtime_error(
"Error unlocking wallet: some keys decrypt but not all. Your wallet file may be corrupt.");
1694 if (keyFail || (!keyPass && !accept_no_keys)) {
1704 if (!m_map_crypted_keys.empty()) {
1708 for (
const KeyMap::value_type& key_in : m_map_keys)
1710 const CKey &key = key_in.second;
1713 std::vector<unsigned char> crypted_secret;
1717 m_map_crypted_keys[pubkey.
GetID()] = make_pair(pubkey, crypted_secret);
1728 index = m_wallet_descriptor.next_index - 1;
1736 if (m_wallet_descriptor.next_index - 1 == index) {
1737 m_wallet_descriptor.next_index--;
1748 for (
auto key_pair : m_map_crypted_keys) {
1749 const CPubKey& pubkey = key_pair.second.first;
1750 const std::vector<unsigned char>& crypted_secret = key_pair.second.second;
1753 keys[pubkey.GetID()] = key;
1763 unsigned int target_size;
1771 int32_t new_range_end = std::max(m_wallet_descriptor.next_index + (int32_t)target_size, m_wallet_descriptor.range_end);
1774 if (!m_wallet_descriptor.descriptor->IsRange()) {
1776 m_wallet_descriptor.range_end = 1;
1777 m_wallet_descriptor.range_start = 0;
1787 std::vector<CScript> scripts_temp;
1790 if (!m_wallet_descriptor.descriptor->ExpandFromCache(i, m_wallet_descriptor.cache, scripts_temp, out_keys)) {
1791 if (!m_wallet_descriptor.descriptor->Expand(i, provider, scripts_temp, out_keys, &temp_cache))
return false;
1794 for (
const CScript& script : scripts_temp) {
1795 m_map_script_pub_keys[script] = i;
1797 for (
const auto& pk_pair : out_keys.
pubkeys) {
1798 const CPubKey& pubkey = pk_pair.second;
1799 if (m_map_pubkeys.count(pubkey) != 0) {
1804 m_map_pubkeys[pubkey] = i;
1808 if (!batch.WriteDescriptorCacheItems(
id, new_items)) {
1809 throw std::runtime_error(std::string(__func__) +
": writing cache items failed");
1813 m_wallet_descriptor.range_end = new_range_end;
1814 batch.WriteDescriptor(
GetID(), m_wallet_descriptor);
1827 int32_t index = m_map_script_pub_keys[script];
1828 if (index >= m_wallet_descriptor.next_index) {
1829 WalletLogPrintf(
"%s: Detected a used keypool item at index %d, mark all keypool items up to this item as used\n", __func__, index);
1830 m_wallet_descriptor.next_index = index + 1;
1833 WalletLogPrintf(
"%s: Topping up keypool failed (locked wallet)\n", __func__);
1843 throw std::runtime_error(std::string(__func__) +
": writing descriptor private key failed");
1853 if (m_map_keys.find(pubkey.
GetID()) != m_map_keys.end() ||
1854 m_map_crypted_keys.find(pubkey.
GetID()) != m_map_crypted_keys.end()) {
1863 std::vector<unsigned char> crypted_secret;
1869 m_map_crypted_keys[pubkey.
GetID()] = make_pair(pubkey, crypted_secret);
1872 m_map_keys[pubkey.
GetID()] = key;
1889 if (m_wallet_descriptor.descriptor) {
1893 int64_t creation_time =
GetTime();
1898 std::string desc_prefix;
1899 std::string desc_suffix =
"/*)";
1900 switch (addr_type) {
1902 desc_prefix =
"pkh(" + xpub +
"/44'";
1906 desc_prefix =
"sh(wpkh(" + xpub +
"/49'";
1911 desc_prefix =
"wpkh(" + xpub +
"/84'";
1916 assert(!desc_prefix.empty());
1920 desc_prefix +=
"/1'";
1922 desc_prefix +=
"/0'";
1925 std::string internal_path =
internal ?
"/1" :
"/0";
1926 std::string desc_str = desc_prefix +
"/0'" + internal_path + desc_suffix;
1931 std::unique_ptr<Descriptor> desc =
Parse(desc_str, keys,
error,
false);
1933 m_wallet_descriptor = w_desc;
1938 throw std::runtime_error(std::string(__func__) +
": writing descriptor master private key failed");
1940 if (!batch.WriteDescriptor(
GetID(), m_wallet_descriptor)) {
1941 throw std::runtime_error(std::string(__func__) +
": writing descriptor failed");
1954 return m_wallet_descriptor.descriptor->IsRange();
1962 return m_wallet_descriptor.descriptor->IsSingleType() &&
1963 m_wallet_descriptor.descriptor->IsRange() &&
1964 (
HavePrivateKeys() || m_wallet_descriptor.next_index < m_wallet_descriptor.range_end);
1970 return m_map_keys.size() > 0 || m_map_crypted_keys.size() > 0;
1984 return m_wallet_descriptor.range_end - m_wallet_descriptor.next_index;
1990 return m_wallet_descriptor.creation_time;
1998 auto it = m_map_script_pub_keys.find(script);
1999 if (it == m_map_script_pub_keys.end()) {
2002 int32_t index = it->second;
2012 auto it = m_map_pubkeys.find(pubkey);
2013 if (it == m_map_pubkeys.end()) {
2016 int32_t index = it->second;
2026 std::unique_ptr<FlatSigningProvider> out_keys = std::make_unique<FlatSigningProvider>();
2027 std::vector<CScript> scripts_temp;
2028 if (!m_wallet_descriptor.descriptor->ExpandFromCache(index, m_wallet_descriptor.cache, scripts_temp, *out_keys))
return nullptr;
2033 m_wallet_descriptor.descriptor->ExpandPrivate(index, master_provider, *out_keys);
2051 std::unique_ptr<FlatSigningProvider> keys = std::make_unique<FlatSigningProvider>();
2052 for (
const auto& coin_pair : coins) {
2053 std::unique_ptr<FlatSigningProvider> coin_keys =
GetSigningProvider(coin_pair.second.out.scriptPubKey,
true);
2057 *keys =
Merge(*keys, *coin_keys);
2071 if (!keys->GetKey(
ToKeyID(pkhash), key)) {
2086 for (
unsigned int i = 0; i < psbtx.
tx->vin.size(); ++i) {
2087 const CTxIn& txin = psbtx.
tx->vin[i];
2115 std::unique_ptr<FlatSigningProvider> keys = std::make_unique<FlatSigningProvider>();
2118 *keys =
Merge(*keys, *script_keys);
2121 script_keys = std::make_unique<FlatSigningProvider>();
2123 const CPubKey& pubkey = pk_pair.first;
2126 *keys =
Merge(*keys, *pk_keys);
2134 if (n_signed && (signed_one || !sign)) {
2143 for (
unsigned int i = 0; i < psbtx.
tx->vout.size(); ++i) {
2160 if (provider->GetKeyOrigin(key_id, orig)) {
2162 std::unique_ptr<CKeyMetadata> meta = std::make_unique<CKeyMetadata>();
2163 meta->key_origin = orig;
2164 meta->has_key_origin =
true;
2165 meta->nCreateTime = m_wallet_descriptor.creation_time;
2175 std::string desc_str = m_wallet_descriptor.descriptor->ToString();
2177 CSHA256().
Write((
unsigned char*)desc_str.data(), desc_str.size()).Finalize(
id.begin());
2184 m_wallet_descriptor.cache = cache;
2185 for (int32_t i = m_wallet_descriptor.range_start; i < m_wallet_descriptor.range_end; ++i) {
2187 std::vector<CScript> scripts_temp;
2188 if (!m_wallet_descriptor.descriptor->ExpandFromCache(i, m_wallet_descriptor.cache, scripts_temp, out_keys)) {
2189 throw std::runtime_error(
"Error: Unable to expand wallet descriptor from cache");
2192 for (
const CScript& script : scripts_temp) {
2193 if (m_map_script_pub_keys.count(script) != 0) {
2194 throw std::runtime_error(
strprintf(
"Error: Already loaded script at index %d as being at index %d", i, m_map_script_pub_keys[script]));
2196 m_map_script_pub_keys[script] = i;
2198 for (
const auto& pk_pair : out_keys.
pubkeys) {
2199 const CPubKey& pubkey = pk_pair.second;
2200 if (m_map_pubkeys.count(pubkey) != 0) {
2205 m_map_pubkeys[pubkey] = i;
2214 m_map_keys[key_id] = key;
2221 if (!m_map_keys.empty()) {
2225 m_map_crypted_keys[key_id] = make_pair(pubkey, crypted_key);
2232 return m_wallet_descriptor.descriptor !=
nullptr && desc.
descriptor !=
nullptr && m_wallet_descriptor.descriptor->ToString() == desc.
descriptor->ToString();
2239 if (!batch.WriteDescriptor(
GetID(), m_wallet_descriptor)) {
2240 throw std::runtime_error(std::string(__func__) +
": writing descriptor failed");
2246 return m_wallet_descriptor;
2252 std::vector<CScript> script_pub_keys;
2253 script_pub_keys.reserve(m_map_script_pub_keys.size());
2255 for (
auto const& script_pub_key: m_map_script_pub_keys) {
2256 script_pub_keys.push_back(script_pub_key.first);
2258 return script_pub_keys;
2268 return m_wallet_descriptor.descriptor->ToNormalizedString(provider, out, &m_wallet_descriptor.cache);
2279 if (m_wallet_descriptor.cache.GetCachedLastHardenedExtPubKeys().size() > 0) {
2287 std::vector<CScript> scripts_temp;
2289 if (!m_wallet_descriptor.descriptor->Expand(0, provider, scripts_temp, out_keys, &temp_cache)){
2290 throw std::runtime_error(
"Unable to expand descriptor");
2296 throw std::runtime_error(std::string(__func__) +
": writing cache items failed");
2305 throw std::runtime_error(std::string(__func__) +
": " +
error);
2308 m_map_pubkeys.clear();
2309 m_map_script_pub_keys.clear();
2311 m_wallet_descriptor = descriptor;
2318 error =
"can only update matching descriptor";
2322 if (descriptor.
range_start > m_wallet_descriptor.range_start ||
2323 descriptor.
range_end < m_wallet_descriptor.range_end) {
2325 error =
strprintf(
"new range must include current range = [%d,%d]",
2326 m_wallet_descriptor.range_start,
2327 m_wallet_descriptor.range_end - 1);
void ReturnDestination(int64_t index, bool internal, const CTxDestination &) override
virtual bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const override
Witness v0 (P2WPKH and P2WSH); see BIP 141.
CSHA256 & Write(const unsigned char *data, size_t len)
bool LoadCryptedKey(const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret, bool checksum_valid)
Adds an encrypted key to the store, without saving it to disk (used by LoadWallet) ...
bool NewKeyPool()
Mark old keypool keys as used, and generate all new keys.
void UpgradeDescriptorCache()
unsigned char fingerprint[4]
First 32 bits of the Hash160 of the public key at the root of the path.
bool AddKeyPubKeyInner(const CKey &key, const CPubKey &pubkey)
void LoadScriptMetadata(const CScriptID &script_id, const CKeyMetadata &metadata)
CPrivKey GetPrivKey() const
Convert the private key to a CPrivKey (serialized OpenSSL private key data).
bool AddKeyPubKeyWithDB(WalletBatch &batch, const CKey &key, const CPubKey &pubkey) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
Adds a key to the store, and saves it to disk.
void KeepDestination(int64_t index, const OutputType &type) override
void SignTransaction(CMutableTransaction &mtx, const SigningProvider *keystore, const std::map< COutPoint, Coin > &coins, const UniValue &hashType, UniValue &result)
Sign a transaction with the given keystore and previous transactions.
bool AddCryptedKey(const CKeyID &key_id, const CPubKey &pubkey, const std::vector< unsigned char > &crypted_key)
bool IsFeatureSupported(int wallet_version, int feature_version)
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
void RewriteDB() override
The action to do when the DB needs rewrite.
bool GetNewDestination(const OutputType type, CTxDestination &dest, std::string &error) override
virtual const CKeyingMaterial & GetEncryptionKey() const =0
virtual void UnsetBlankWalletFlag(WalletBatch &)=0
bool SignPSBTInput(const SigningProvider &provider, PartiallySignedTransaction &psbt, int index, const PrecomputedTransactionData *txdata, int sighash, SignatureData *out_sigdata)
Signs a PSBTInput, verifying that all provided data matches what is being signed. ...
virtual bool GetCScript(const CScriptID &hash, CScript &redeemScriptOut) const override
void LearnAllRelatedScripts(const CPubKey &key)
Same as LearnRelatedScripts, but when the OutputType is not known (and could be anything).
bool Upgrade(int prev_version, int new_version, bilingual_str &error) override
Upgrades the wallet to the specified version.
void MarkReserveKeysAsUsed(int64_t keypool_id) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
Marks all keys in the keypool up to and including reserve_key as used.
std::shared_ptr< Descriptor > descriptor
bool ImportScriptPubKeys(const std::set< CScript > &script_pub_keys, const bool have_solving_data, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
bool LoadCScript(const CScript &redeemScript)
Adds a CScript to the store.
std::unordered_map< CKeyID, CHDChain, SaltedSipHasher > m_inactive_hd_chains
bool AddKeyOriginWithDB(WalletBatch &batch, const CPubKey &pubkey, const KeyOriginInfo &info)
Add a KeyOriginInfo to the wallet.
bool SignTransaction(CMutableTransaction &tx, const std::map< COutPoint, Coin > &coins, int sighash, std::map< int, std::string > &input_errors) const override
Creates new signatures and adds them to the transaction.
bool DecryptKey(const CKeyingMaterial &vMasterKey, const std::vector< unsigned char > &vchCryptedSecret, const CPubKey &vchPubKey, CKey &key)
bool GetKeyOrigin(const CKeyID &keyid, KeyOriginInfo &info) const override
bool Derive(CExtKey &out, unsigned int nChild) const
isminetype IsMine(const CScript &script) const override
RecursiveMutex cs_KeyStore
uint256 GetID() const override
bool VerifyPubKey(const CPubKey &vchPubKey) const
Verify thoroughly whether a private key and a public key match.
CPubKey GetPubKey() const
Compute the public key from a private key.
std::map< CKeyID, CKey > keys
bool CheckDecryptionKey(const CKeyingMaterial &master_key, bool accept_no_keys=false) override
Check that the given decryption key is valid for this ScriptPubKeyMan, i.e. it decrypts all of the ke...
RecursiveMutex cs_desc_man
size_t KeypoolCountExternalKeys() const
int64_t GetOldestKeyPoolTime() const override
FlatSigningProvider Merge(const FlatSigningProvider &a, const FlatSigningProvider &b)
bool WriteHDChain(const CHDChain &chain)
write the hdchain model (external chain child index counter)
void AddKeypoolPubkeyWithDB(const CPubKey &pubkey, const bool internal, WalletBatch &batch)
virtual bool AddCScript(const CScript &redeemScript)
virtual void SetMinVersion(enum WalletFeature, WalletBatch *=nullptr)=0
bool WriteWatchOnly(const CScript &script, const CKeyMetadata &keymeta)
const BaseSignatureCreator & DUMMY_SIGNATURE_CREATOR
A signature creator that just produces 71-byte empty signatures.
CScript GetScriptForRawPubKey(const CPubKey &pubKey)
Generate a P2PK script for the given pubkey.
uint256 GetHash() const
Get the 256-bit hash of this public key.
bool CanProvide(const CScript &script, SignatureData &sigdata) override
Whether this ScriptPubKeyMan can provide a SigningProvider (via GetSolvingProvider) that...
std::vector< unsigned char, secure_allocator< unsigned char > > CKeyingMaterial
boost::signals2::signal< void()> NotifyCanGetAddressesChanged
Keypool has new keys.
unsigned int GetKeyPoolSize() const override
bool CanGetAddresses(bool internal=false) const override
virtual std::set< CKeyID > GetKeys() const
static const std::unordered_set< OutputType > LEGACY_OUTPUT_TYPES
OutputTypes supported by the LegacyScriptPubKeyMan.
uint256 GetID() const override
CKeyID GetKeyForDestination(const SigningProvider &store, const CTxDestination &dest)
Return the CKeyID of the key involved in a script (if there is a unique one).
uint32_t nExternalChainCounter
bool GetReservedDestination(const OutputType type, bool internal, CTxDestination &address, int64_t &index, CKeyPool &keypool, std::string &error) override
void LearnRelatedScripts(const CPubKey &key, OutputType)
Explicitly make the wallet learn the related scripts for outputs to the given key.
A version of CTransaction with the PSBT format.
void LoadKeyMetadata(const CKeyID &keyID, const CKeyMetadata &metadata)
Load metadata (used by LoadWallet)
std::unique_ptr< SigningProvider > GetSolvingProvider(const CScript &script) const override
bool ImportPubKeys(const std::vector< CKeyID > &ordered_pubkeys, const std::map< CKeyID, CPubKey > &pubkey_map, const std::map< CKeyID, std::pair< CPubKey, KeyOriginInfo >> &key_origins, const bool add_keypool, const bool internal, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
bool CanGenerateKeys() const
CPubKey GenerateNewKey(WalletBatch &batch, CHDChain &hd_chain, bool internal=false) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
Generate a new key.
static const unsigned int MAX_SCRIPT_ELEMENT_SIZE
boost::signals2::signal< void(bool fHaveWatchOnly)> NotifyWatchonlyChanged
Watch-only address added.
const unsigned char * begin() const
const WalletDescriptor GetWalletDescriptor() const EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man)
virtual WalletDatabase & GetDatabase() const =0
virtual bool IsWalletFlagSet(uint64_t) const =0
bool RemoveWatchOnly(const CScript &dest)
Remove a watch only script from the keystore.
std::unique_ptr< CKeyMetadata > GetMetadata(const CTxDestination &dest) const override
KeyMap GetKeys() const EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man)
unspendable OP_RETURN script that carries data
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
bool IsHDEnabled() const override
bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey) override
Adds a key to the store, and saves it to disk.
void AddInactiveHDChain(const CHDChain &chain)
Access to the wallet database.
static bool ExtractPubKey(const CScript &dest, CPubKey &pubKeyOut)
void WalletLogPrintf(std::string fmt, Params... parameters) const
Prepends the wallet name in logging output to ease debugging in multi-wallet use cases.
void MarkPreSplitKeys() EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
bool WriteCryptedDescriptorKey(const uint256 &desc_id, const CPubKey &pubkey, const std::vector< unsigned char > &secret)
bool Encrypt(const CKeyingMaterial &master_key, WalletBatch *batch) override
const std::vector< CScript > GetScriptPubKeys() const
int64_t GetOldestKeyPoolTime() const override
bool AddWatchOnlyWithDB(WalletBatch &batch, const CScript &dest) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
std::unique_ptr< Descriptor > Parse(const std::string &descriptor, FlatSigningProvider &out, std::string &error, bool require_checksum)
Parse a descriptor string.
CPubKey GenerateNewSeed()
std::string ToString(const T &t)
Locale-independent version of std::to_string.
unsigned int GetKeyPoolSize() const override
bool TopUpInactiveHDChain(const CKeyID seed_id, int64_t index, bool internal)
Like TopUp() but adds keys for inactive HD chains.
bool MessageSign(const CKey &privkey, const std::string &message, std::string &signature)
Sign a message.
bool IsHDEnabled() const override
IsMineSigVersion
This is an enum that tracks the execution context of a script, similar to SigVersion in script/interp...
int64_t nTime
The time at which the key was generated. Set in AddKeypoolPubKeyWithDB.
void UpdateTimeFirstKey(int64_t nCreateTime) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
Update wallet first key creation time.
bool WriteCScript(const uint160 &hash, const CScript &redeemScript)
bool CanProvide(const CScript &script, SignatureData &sigdata) override
Whether this ScriptPubKeyMan can provide a SigningProvider (via GetSolvingProvider) that...
bool GetWatchPubKey(const CKeyID &address, CPubKey &pubkey_out) const
Fetches a pubkey from mapWatchKeys if it exists there.
bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret)
Adds an encrypted key to the store, and saves it to disk.
An input of a transaction.
bool AddWatchOnlyInMem(const CScript &dest)
void MarkUnusedAddresses(const CScript &script) override
Mark unused addresses as being used.
static const unsigned int DEFAULT_KEYPOOL_SIZE
Default for -keypool.
bilingual_str _(const char *psz)
Translation function.
const SigningProvider & DUMMY_SIGNING_PROVIDER
bool AddCryptedKeyInner(const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret)
bool TopUp(unsigned int size=0) override
Fills internal address pool.
An encapsulated public key.
std::map< CKeyID, CPubKey > pubkeys
bool CanUpdateToWalletDescriptor(const WalletDescriptor &descriptor, std::string &error)
void SetHDSeed(const CPubKey &key)
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
Flag set when a wallet contains no HD seed and no private keys, scripts, addresses, and other watch only things, and is therefore "blank.".
void ReturnDestination(int64_t index, bool internal, const CTxDestination &addr) override
void ImplicitlyLearnRelatedKeyScripts(const CPubKey &pubkey) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
bool m_pre_split
Whether this key was generated for a keypool before the wallet was upgraded to HD-split.
bool GetKey(const CKeyID &address, CKey &keyOut) const override
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
isminetype
IsMine() return codes, which depend on ScriptPubKeyMan implementation.
unsigned int size() const
Simple read-only vector-like interface.
void MarkUnusedAddresses(const CScript &script) override
Mark unused addresses as being used.
void UpdatePSBTOutput(const SigningProvider &provider, PartiallySignedTransaction &psbt, int index)
Updates a PSBTOutput with information from provider.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
Descriptor with some wallet metadata.
bool AddKey(const CKeyID &key_id, const CKey &key)
bool LoadWatchOnly(const CScript &dest)
Adds a watch-only address to the store, without saving it to disk (used by LoadWallet) ...
bool ReserveKeyFromKeyPool(int64_t &nIndex, CKeyPool &keypool, bool fRequestedInternal)
Reserves a key from the keypool and sets nIndex to its index.
std::vector< PSBTInput > inputs
void SetSeed(const unsigned char *seed, unsigned int nSeedLen)
bool GetKeyFromPool(CPubKey &key, const OutputType type, bool internal=false)
Fetches a key from the keypool.
virtual bool IsLocked() const =0
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
bool HasWalletDescriptor(const WalletDescriptor &desc) const
bool HavePrivateKeys() const override
bool WriteKeyMetadata(const CKeyMetadata &meta, const CPubKey &pubkey, const bool overwrite)
virtual bool GetKey(const CKeyID &address, CKey &keyOut) const override
std::map< int64_t, CKeyID > m_index_to_reserved_key
bool IsSolvable(const SigningProvider &provider, const CScript &script)
CRIPEMD160 & Write(const unsigned char *data, size_t len)
bool AddCScript(const CScript &redeemScript) override
std::vector< CKeyID > GetAffectedKeys(const CScript &spk, const SigningProvider &provider)
int64_t GetTimeFirstKey() const override
uint160 Hash160(const T1 &in1)
Compute the 160-bit hash an object.
static int64_t GetOldestKeyTimeInPool(const std::set< int64_t > &setKeyPool, WalletBatch &batch)
bool ErasePool(int64_t nPool)
bool WritePool(int64_t nPool, const CKeyPool &keypool)
CPubKey vchPubKey
The public key.
bool LoadKey(const CKey &key, const CPubKey &pubkey)
Adds a key to the store, without saving it to disk (used by LoadWallet)
virtual bool CanSupportFeature(enum WalletFeature) const =0
void SetCache(const DescriptorCache &cache)
bool HaveWatchOnly() const
Returns whether there are any watch-only things in the wallet.
std::string EncodeExtPubKey(const CExtPubKey &key)
bool IsTestChain() const
If this chain is exclusively used for testing.
std::unique_ptr< Descriptor > InferDescriptor(const CScript &script, const SigningProvider &provider)
Find a descriptor for the specified script, using information from provider where possible...
An interface to be implemented by keystores that support signing.
CExtPubKey Neuter() const
bool ParseHDKeypath(const std::string &keypath_str, std::vector< uint32_t > &keypath)
Parse an HD keypaths like "m/7/0'/2000".
const CChainParams & Params()
Return the currently selected parameters.
Cache for single descriptor's derived extended pubkeys.
bool GetNewDestination(const OutputType type, CTxDestination &dest, std::string &error) override
bool HaveKey(const CKeyID &address) const override
std::map< CKeyID, CKey > KeyMap
Serialized script, used inside transaction inputs and outputs.
void UpdateWalletDescriptor(WalletDescriptor &descriptor)
void AddHDChain(const CHDChain &chain)
bool GetDescriptorString(std::string &out) const
std::string WriteHDKeypath(const std::vector< uint32_t > &keypath)
Write HD keypaths as strings.
std::unique_ptr< FlatSigningProvider > GetSigningProvider(const CScript &script, bool include_private=false) const
const unsigned char * end() const
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
void LoadKeyPool(int64_t nIndex, const CKeyPool &keypool)
Load a keypool entry.
A reference to a CKey: the Hash160 of its serialized public key.
bool CheckDecryptionKey(const CKeyingMaterial &master_key, bool accept_no_keys=false) override
Check that the given decryption key is valid for this ScriptPubKeyMan, i.e. it decrypts all of the ke...
TxoutType Solver(const CScript &scriptPubKey, std::vector< std::vector< unsigned char >> &vSolutionsRet)
Parse a scriptPubKey and identify script type for standard scripts.
DescriptorCache MergeAndDiff(const DescriptorCache &other)
Combine another DescriptorCache into this one.
Only for Witness versions not already defined above.
bool CanGetAddresses(bool internal=false) const override
std::unique_ptr< SigningProvider > GetSolvingProvider(const CScript &script) const override
virtual bool HaveCScript(const CScriptID &hash) const override
std::vector< unsigned char > valtype
bool AddWatchOnly(const CScript &dest) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
Private version of AddWatchOnly method which does not accept a timestamp, and which will reset the wa...
IsMineResult
This is an internal representation of isminetype + invalidity.
bool ProduceSignature(const SigningProvider &provider, const BaseSignatureCreator &creator, const CScript &fromPubKey, SignatureData &sigdata)
Produce a script signature using a generic signature creator.
void UpgradeKeyMetadata()
Upgrade stored CKeyMetadata objects to store key origin info as KeyOriginInfo.
CPubKey DeriveNewSeed(const CKey &key)
CTxDestination GetDestinationForKey(const CPubKey &key, OutputType type)
Get a destination of the requested type (if possible) to the specified key.
TransactionError FillPSBT(PartiallySignedTransaction &psbt, const PrecomputedTransactionData &txdata, int sighash_type=1, bool sign=true, bool bip32derivs=false, int *n_signed=nullptr) const override
Adds script and derivation path information to a PSBT, and optionally signs it.
bool EncryptSecret(const CKeyingMaterial &vMasterKey, const CKeyingMaterial &vchPlaintext, const uint256 &nIV, std::vector< unsigned char > &vchCiphertext)
bool ReadPool(int64_t nPool, CKeyPool &keypool)
int64_t GetTimeFirstKey() const override
static const int VERSION_HD_CHAIN_SPLIT
A reference to a CScript: the Hash160 of its serialization (see script.h)
std::string EncodeDestination(const CTxDestination &dest)
virtual bool HasEncryptionKeys() const =0
A mutable version of CTransaction.
virtual bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey)
bool PSBTInputSigned(const PSBTInput &input)
Checks whether a PSBTInput is already signed.
bool SignTransaction(CMutableTransaction &tx, const std::map< COutPoint, Coin > &coins, int sighash, std::map< int, std::string > &input_errors) const override
Creates new signatures and adds them to the transaction.
void DeriveNewChildKey(WalletBatch &batch, CKeyMetadata &metadata, CKey &secret, CHDChain &hd_chain, bool internal=false) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
std::vector< unsigned char > valtype
TransactionError FillPSBT(PartiallySignedTransaction &psbt, const PrecomputedTransactionData &txdata, int sighash_type=1, bool sign=true, bool bip32derivs=false, int *n_signed=nullptr) const override
Adds script and derivation path information to a PSBT, and optionally signs it.
bool SetupGeneration(bool force=false) override
Sets up the key generation stuff, i.e.
bool WriteKey(const CPubKey &vchPubKey, const CPrivKey &vchPrivKey, const CKeyMetadata &keyMeta)
bool Encrypt(const CKeyingMaterial &master_key, WalletBatch *batch) override
bool HavePrivateKeys() const override
std::map< CKeyID, CKey > KeyMap
void AddDescriptorKey(const CKey &key, const CPubKey &pubkey)
SigningResult SignMessage(const std::string &message, const PKHash &pkhash, std::string &str_sig) const override
Sign a message with the given script.
An encapsulated private key.
std::unique_ptr< CKeyMetadata > GetMetadata(const CTxDestination &dest) const override
bool GetReservedDestination(const OutputType type, bool internal, CTxDestination &address, int64_t &index, CKeyPool &keypool, std::string &error) override
bool AddDescriptorKeyWithDB(WalletBatch &batch, const CKey &key, const CPubKey &pubkey) EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man)
std::optional< CMutableTransaction > tx
bool TopUp(unsigned int size=0) override
Fills internal address pool.
WalletStorage & m_storage
bool m_decryption_thoroughly_checked
keeps track of whether Unlock has run a thorough check before
void Finalize(unsigned char hash[OUTPUT_SIZE])
Indicate that this wallet supports DescriptorScriptPubKeyMan.
CKeyID seed_id
seed hash160
A hasher class for SHA-256.
bool ImportPrivKeys(const std::map< CKeyID, CKey > &privkey_map, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
int64_t GetTime()
Return system time (or mocked time, if set)
void LoadHDChain(const CHDChain &chain)
Load a HD chain model (used by LoadWallet)
std::vector< uint32_t > path
int32_t m_max_cached_index
bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const override
bool error(const char *fmt, const Args &... args)
bool AddCScriptWithDB(WalletBatch &batch, const CScript &script)
Adds a script to the store and saves it to disk.
bool fDecryptionThoroughlyChecked
keeps track of whether Unlock has run a thorough check before
bool fInternal
Whether this keypool entry is in the internal keypool (for change outputs)
bool SetupDescriptorGeneration(const CExtKey &master_key, OutputType addr_type, bool internal)
Setup descriptors based on the given CExtkey.
std::set< CKeyID > GetKeys() const override
static const int VERSION_HD_BASE
isminetype IsMine(const CScript &script) const override
bool ImportScripts(const std::set< CScript > scripts, int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
std::map< CKeyID, SigPair > signatures
BIP 174 style partial signatures for the input. May contain all signatures necessary for producing a ...
A hasher class for RIPEMD-160.
CKeyID ToKeyID(const PKHash &key_hash)
uint32_t nInternalChainCounter
bool WriteDescriptorKey(const uint256 &desc_id, const CPubKey &pubkey, const CPrivKey &privkey)
std::map< CKeyID, int64_t > m_pool_key_to_index
A key from a CWallet's keypool.
SigningResult SignMessage(const std::string &message, const PKHash &pkhash, std::string &str_sig) const override
Sign a message with the given script.
bool HaveWatchOnly(const CScript &dest) const
Returns whether the watch-only script is in the wallet.
const uint32_t BIP32_HARDENED_KEY_LIMIT
Value for the first BIP 32 hardened derivation. Can be used as a bit mask and as a value...
bool IsCompressed() const
Check whether this is a compressed public key.
virtual bool HaveKey(const CKeyID &address) const override