26 error =
_(
"Error: Keypool ran out, please call keypoolrefill first").
translated;
34 typedef std::vector<unsigned char>
valtype;
66 return sigversion == IsMineSigVersion::TOP || sigversion == IsMineSigVersion::P2SH;
71 for (
const valtype& pubkey : pubkeys) {
73 if (!keystore.
HaveKey(keyID))
return false;
90 std::vector<valtype> vSolutions;
103 if (!PermitsUncompressed(sigversion) && vSolutions[0].size() != 33) {
104 return IsMineResult::INVALID;
107 ret = std::max(ret, IsMineResult::SPENDABLE);
112 if (sigversion == IsMineSigVersion::WITNESS_V0) {
114 return IsMineResult::INVALID;
127 if (!PermitsUncompressed(sigversion)) {
130 return IsMineResult::INVALID;
134 ret = std::max(ret, IsMineResult::SPENDABLE);
139 if (sigversion != IsMineSigVersion::TOP) {
141 return IsMineResult::INVALID;
145 if (keystore.
GetCScript(scriptID, subscript)) {
146 ret = std::max(ret, recurse_scripthash ? IsMineInner(keystore, subscript, IsMineSigVersion::P2SH) : IsMineResult::SPENDABLE);
152 if (sigversion == IsMineSigVersion::WITNESS_V0) {
154 return IsMineResult::INVALID;
163 if (keystore.
GetCScript(scriptID, subscript)) {
164 ret = std::max(ret, recurse_scripthash ? IsMineInner(keystore, subscript, IsMineSigVersion::WITNESS_V0) : IsMineResult::SPENDABLE);
172 if (sigversion == IsMineSigVersion::TOP) {
181 std::vector<valtype> keys(vSolutions.begin()+1, vSolutions.begin()+vSolutions.size()-1);
182 if (!PermitsUncompressed(sigversion)) {
183 for (
size_t i = 0; i < keys.size(); i++) {
184 if (keys[i].size() != 33) {
185 return IsMineResult::INVALID;
189 if (HaveKeys(keys, keystore)) {
190 ret = std::max(ret, IsMineResult::SPENDABLE);
196 if (ret == IsMineResult::NO && keystore.
HaveWatchOnly(scriptPubKey)) {
197 ret = std::max(ret, IsMineResult::WATCH_ONLY);
206 switch (IsMineInner(*
this, script, IsMineSigVersion::TOP)) {
207 case IsMineResult::INVALID:
208 case IsMineResult::NO:
210 case IsMineResult::WATCH_ONLY:
212 case IsMineResult::SPENDABLE:
222 assert(mapKeys.empty());
224 bool keyPass = mapCryptedKeys.empty();
225 bool keyFail =
false;
226 CryptedKeyMap::const_iterator mi = mapCryptedKeys.begin();
228 for (; mi != mapCryptedKeys.end(); ++mi)
230 const CPubKey &vchPubKey = (*mi).second.first;
231 const std::vector<unsigned char> &vchCryptedSecret = (*mi).second.second;
233 if (!
DecryptKey(master_key, vchCryptedSecret, vchPubKey, key))
243 batch.WriteCryptedKey(vchPubKey, vchCryptedSecret, mapKeyMetadata[vchPubKey.
GetID()]);
246 if (keyPass && keyFail)
248 LogPrintf(
"The wallet is probably corrupted: Some keys decrypt but not all.\n");
249 throw std::runtime_error(
"Error unlocking wallet: some keys decrypt but not all. Your wallet file may be corrupt.");
251 if (keyFail || (!keyPass && !accept_no_keys))
261 encrypted_batch = batch;
262 if (!mapCryptedKeys.empty()) {
263 encrypted_batch =
nullptr;
268 keys_to_encrypt.swap(mapKeys);
269 for (
const KeyMap::value_type& mKey : keys_to_encrypt)
271 const CKey &key = mKey.second;
274 std::vector<unsigned char> vchCryptedSecret;
276 encrypted_batch =
nullptr;
280 encrypted_batch =
nullptr;
284 encrypted_batch =
nullptr;
323 int64_t missing = std::max(target_size - kp_size, (int64_t) 0);
327 for (int64_t i = missing; i > 0; --i) {
346 WalletLogPrintf(
"%s: Detected a used keypool key, mark all keypool keys up to this key as used\n", __func__);
350 WalletLogPrintf(
"%s: Topping up keypool failed (locked wallet)\n", __func__);
356 auto it = mapKeyMetadata.find(keyid);
357 if (
it != mapKeyMetadata.end()){
379 for (
auto& meta_pair : mapKeyMetadata) {
390 throw std::runtime_error(
"Invalid stored hdKeypath");
399 if (
GetPubKey(meta_pair.first, pubkey)) {
400 batch->WriteKeyMetadata(meta, pubkey,
true);
428 bool keypool_has_keys;
430 keypool_has_keys = setInternalKeyPool.size() > 0;
435 if (!keypool_has_keys) {
438 return keypool_has_keys;
444 bool hd_upgrade =
false;
445 bool split_upgrade =
false;
464 throw std::runtime_error(std::string(__func__) +
": writing chain failed");
475 error =
_(
"Unable to generate keys");
485 return !mapKeys.empty() || !mapCryptedKeys.empty();
491 setInternalKeyPool.clear();
492 setExternalKeyPool.clear();
500 if (setKeyPool.empty()) {
505 int64_t nIndex = *(setKeyPool.begin());
506 if (!batch.
ReadPool(nIndex, keypool)) {
507 throw std::runtime_error(std::string(__func__) +
": read oldest key in keypool failed");
510 return keypool.
nTime;
523 if (!set_pre_split_keypool.empty()) {
534 return setExternalKeyPool.size() + set_pre_split_keypool.size();
540 return setInternalKeyPool.size() + setExternalKeyPool.size() + set_pre_split_keypool.size();
546 return nTimeFirstKey;
551 return MakeUnique<LegacySigningProvider>(*this);
556 IsMineResult ismine = IsMineInner(*
this, script, IsMineSigVersion::TOP,
false);
557 if (ismine == IsMineResult::SPENDABLE || ismine == IsMineResult::WATCH_ONLY) {
567 bool has_privkeys =
false;
568 for (
const auto& key_sig_pair : sigdata.
signatures) {
569 has_privkeys |=
HaveKey(key_sig_pair.first);
600 for (
unsigned int i = 0; i < psbtx.
tx->vin.size(); ++i) {
601 const CTxIn& txin = psbtx.
tx->vin[i];
627 if (n_signed && (signed_one || !sign)) {
636 for (
unsigned int i = 0; i < psbtx.
tx->vout.size(); ++i) {
649 auto it = mapKeyMetadata.find(key_id);
650 if (
it != mapKeyMetadata.end()) {
651 return MakeUnique<CKeyMetadata>(
it->second);
656 auto it = m_script_metadata.find(
CScriptID(scriptPubKey));
657 if (
it != m_script_metadata.end()) {
658 return MakeUnique<CKeyMetadata>(
it->second);
676 if (nCreateTime <= 1) {
680 }
else if (!nTimeFirstKey || nCreateTime < nTimeFirstKey) {
681 nTimeFirstKey = nCreateTime;
707 bool needsDB = !encrypted_batch;
709 encrypted_batch = &batch;
712 if (needsDB) encrypted_batch =
nullptr;
715 if (needsDB) encrypted_batch =
nullptr;
731 mapKeyMetadata[pubkey.
GetID()]);
745 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);
756 mapKeyMetadata[keyID] = meta;
763 m_script_metadata[script_id] = meta;
777 std::vector<unsigned char> vchCryptedSecret;
792 if (!checksum_valid) {
802 assert(mapKeys.empty());
804 mapCryptedKeys[vchPubKey.
GetID()] = make_pair(vchPubKey, vchCryptedSecret);
810 const std::vector<unsigned char> &vchCryptedSecret)
817 return encrypted_batch->WriteCryptedKey(vchPubKey,
819 mapKeyMetadata[vchPubKey.
GetID()]);
823 mapKeyMetadata[vchPubKey.
GetID()]);
830 return setWatchOnly.count(dest) > 0;
836 return (!setWatchOnly.empty());
841 std::vector<std::vector<unsigned char>> solutions;
843 (pubKeyOut =
CPubKey(solutions[0])).IsFullyValid();
850 setWatchOnly.erase(dest);
853 mapWatchKeys.erase(pubKey.
GetID());
875 setWatchOnly.insert(dest);
878 mapWatchKeys[pubKey.
GetID()] = pubKey;
900 m_script_metadata[
CScriptID(dest)].nCreateTime = create_time;
912 m_script_metadata[
CScriptID(dest)].nCreateTime = nCreateTime;
927 throw std::runtime_error(std::string(__func__) +
": writing chain failed");
950 return mapCryptedKeys.count(address) > 0;
960 CryptedKeyMap::const_iterator mi = mapCryptedKeys.find(address);
961 if (mi != mapCryptedKeys.end())
963 const CPubKey &vchPubKey = (*mi).second.first;
964 const std::vector<unsigned char> &vchCryptedSecret = (*mi).second.second;
975 auto it = mapKeyMetadata.find(keyID);
976 if (
it != mapKeyMetadata.end()) {
992 WatchKeyMap::const_iterator
it = mapWatchKeys.find(address);
993 if (it != mapWatchKeys.end()) {
994 pubkey_out = it->second;
1010 CryptedKeyMap::const_iterator mi = mapCryptedKeys.find(address);
1011 if (mi != mapCryptedKeys.end())
1013 vchPubKeyOut = (*mi).second.first;
1030 int64_t nCreationTime =
GetTime();
1048 mapKeyMetadata[pubkey.
GetID()] = metadata;
1052 throw std::runtime_error(std::string(__func__) +
": AddKey failed");
1068 throw std::runtime_error(std::string(__func__) +
": seed not found");
1102 secret = childKey.
key;
1109 throw std::runtime_error(std::string(__func__) +
": writing HD chain model failed");
1116 set_pre_split_keypool.insert(nIndex);
1118 setInternalKeyPool.insert(nIndex);
1120 setExternalKeyPool.insert(nIndex);
1122 m_max_keypool_index = std::max(m_max_keypool_index, nIndex);
1129 if (mapKeyMetadata.count(keyid) == 0)
1150 int64_t nCreationTime =
GetTime();
1166 mapKeyMetadata[seed.
GetID()] = metadata;
1170 throw std::runtime_error(std::string(__func__) +
": AddKeyPubKey failed");
1204 for (
const int64_t nIndex : setInternalKeyPool) {
1207 setInternalKeyPool.clear();
1209 for (
const int64_t nIndex : setExternalKeyPool) {
1210 batch.ErasePool(nIndex);
1212 setExternalKeyPool.clear();
1214 for (
const int64_t nIndex : set_pre_split_keypool) {
1215 batch.ErasePool(nIndex);
1217 set_pre_split_keypool.clear();
1224 WalletLogPrintf(
"LegacyScriptPubKeyMan::NewKeyPool rewrote keypool\n");
1240 unsigned int nTargetSize;
1242 nTargetSize = kpSize;
1248 int64_t missingExternal = std::max(std::max((int64_t) nTargetSize, (int64_t) 1) - (int64_t)setExternalKeyPool.size(), (int64_t) 0);
1249 int64_t missingInternal = std::max(std::max((int64_t) nTargetSize, (int64_t) 1) - (int64_t)setInternalKeyPool.size(), (int64_t) 0);
1254 missingInternal = 0;
1256 bool internal =
false;
1258 for (int64_t i = missingInternal + missingExternal; i--;)
1260 if (i < missingInternal) {
1267 if (missingInternal + missingExternal > 0) {
1268 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());
1278 assert(m_max_keypool_index < std::numeric_limits<int64_t>::max());
1279 int64_t index = ++m_max_keypool_index;
1281 throw std::runtime_error(std::string(__func__) +
": writing imported pubkey failed");
1284 setInternalKeyPool.insert(index);
1286 setExternalKeyPool.insert(index);
1310 setInternalKeyPool.insert(nIndex);
1311 }
else if (!set_pre_split_keypool.empty()) {
1312 set_pre_split_keypool.insert(nIndex);
1314 setExternalKeyPool.insert(nIndex);
1353 bool fReturningInternal = fRequestedInternal;
1355 bool use_split_keypool = set_pre_split_keypool.empty();
1356 std::set<int64_t>& setKeyPool = use_split_keypool ? (fReturningInternal ? setInternalKeyPool : setExternalKeyPool) : set_pre_split_keypool;
1359 if (setKeyPool.empty()) {
1365 auto it = setKeyPool.begin();
1367 setKeyPool.erase(it);
1368 if (!batch.ReadPool(nIndex, keypool)) {
1369 throw std::runtime_error(std::string(__func__) +
": read failed");
1373 throw std::runtime_error(std::string(__func__) +
": unknown key in key pool");
1376 if (use_split_keypool && keypool.
fInternal != fReturningInternal) {
1377 throw std::runtime_error(std::string(__func__) +
": keypool entry misclassified");
1380 throw std::runtime_error(std::string(__func__) +
": keypool entry invalid");
1412 bool internal = setInternalKeyPool.count(keypool_id);
1413 if (!
internal) assert(setExternalKeyPool.count(keypool_id) || set_pre_split_keypool.count(keypool_id));
1414 std::set<int64_t> *setKeyPool =
internal ? &setInternalKeyPool : (set_pre_split_keypool.empty() ? &setExternalKeyPool : &set_pre_split_keypool);
1415 auto it = setKeyPool->begin();
1418 while (
it != std::end(*setKeyPool)) {
1419 const int64_t& index = *(
it);
1420 if (index > keypool_id)
break;
1423 if (batch.ReadPool(index, keypool)) {
1427 batch.ErasePool(index);
1429 it = setKeyPool->erase(
it);
1435 std::vector<CScript> dummy;
1438 std::vector<CKeyID> ret;
1439 for (
const auto& entry : out.
pubkeys) {
1440 ret.push_back(entry.first);
1448 for (
auto it = setExternalKeyPool.begin();
it != setExternalKeyPool.end();) {
1449 int64_t index = *
it;
1451 if (!batch.ReadPool(index, keypool)) {
1452 throw std::runtime_error(std::string(__func__) +
": read keypool entry failed");
1455 if (!batch.WritePool(index, keypool)) {
1456 throw std::runtime_error(std::string(__func__) +
": writing modified keypool entry failed");
1458 set_pre_split_keypool.insert(index);
1459 it = setExternalKeyPool.erase(
it);
1484 mapKeyMetadata[pubkey.
GetID()].key_origin.path = info.
path;
1485 mapKeyMetadata[pubkey.
GetID()].has_key_origin =
true;
1493 for (
const auto& entry : scripts) {
1503 if (timestamp > 0) {
1504 m_script_metadata[
CScriptID(entry)].nCreateTime = timestamp;
1507 if (timestamp > 0) {
1517 for (
const auto& entry : privkey_map) {
1518 const CKey& key = entry.second;
1520 const CKeyID&
id = entry.first;
1527 mapKeyMetadata[id].nCreateTime = timestamp;
1537 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)
1540 for (
const auto& entry : key_origins) {
1543 for (
const CKeyID&
id : ordered_pubkeys) {
1544 auto entry = pubkey_map.find(
id);
1545 if (entry == pubkey_map.end()) {
1548 const CPubKey& pubkey = entry->second;
1558 mapKeyMetadata[id].nCreateTime = timestamp;
1572 for (
const CScript& script : script_pub_keys) {
1573 if (!have_solving_data || !
IsMine(script)) {
1588 std::set<CKeyID> set_address;
1589 for (
const auto& mi : mapCryptedKeys) {
1590 set_address.insert(mi.first);
1601 error =
"No addresses available";
1606 assert(m_wallet_descriptor.descriptor->IsSingleType());
1608 assert(desc_addr_type);
1609 if (type != *desc_addr_type) {
1610 throw std::runtime_error(std::string(__func__) +
": Types are inconsistent");
1617 std::vector<CScript> scripts_temp;
1618 if (m_wallet_descriptor.range_end <= m_max_cached_index && !
TopUp(1)) {
1620 error =
"Error: Keypool ran out, please call keypoolrefill first";
1623 if (!m_wallet_descriptor.descriptor->ExpandFromCache(m_wallet_descriptor.next_index, m_wallet_descriptor.cache, scripts_temp, out_keys)) {
1625 error =
"Error: Keypool ran out, please call keypoolrefill first";
1630 if (out_script_type && out_script_type == type) {
1633 throw std::runtime_error(std::string(__func__) +
": Types are inconsistent. Stored type does not match type of newly generated address");
1635 m_wallet_descriptor.next_index++;
1644 if (m_map_script_pub_keys.count(script) > 0) {
1653 if (!m_map_keys.empty()) {
1657 bool keyPass = m_map_crypted_keys.empty();
1658 bool keyFail =
false;
1659 for (
const auto& mi : m_map_crypted_keys) {
1660 const CPubKey &pubkey = mi.second.first;
1661 const std::vector<unsigned char> &crypted_secret = mi.second.second;
1663 if (!
DecryptKey(master_key, crypted_secret, pubkey, key)) {
1668 if (m_decryption_thoroughly_checked)
1671 if (keyPass && keyFail) {
1672 LogPrintf(
"The wallet is probably corrupted: Some keys decrypt but not all.\n");
1673 throw std::runtime_error(
"Error unlocking wallet: some keys decrypt but not all. Your wallet file may be corrupt.");
1675 if (keyFail || (!keyPass && !accept_no_keys)) {
1678 m_decryption_thoroughly_checked =
true;
1685 if (!m_map_crypted_keys.empty()) {
1689 for (
const KeyMap::value_type& key_in : m_map_keys)
1691 const CKey &key = key_in.second;
1694 std::vector<unsigned char> crypted_secret;
1698 m_map_crypted_keys[pubkey.
GetID()] = make_pair(pubkey, crypted_secret);
1710 index = m_wallet_descriptor.next_index - 1;
1718 if (m_wallet_descriptor.next_index - 1 == index) {
1719 m_wallet_descriptor.next_index--;
1730 for (
auto key_pair : m_map_crypted_keys) {
1731 const CPubKey& pubkey = key_pair.second.first;
1732 const std::vector<unsigned char>& crypted_secret = key_pair.second.second;
1735 keys[pubkey.GetID()] = key;
1745 unsigned int target_size;
1753 int32_t new_range_end = std::max(m_wallet_descriptor.next_index + (int32_t)target_size, m_wallet_descriptor.range_end);
1756 if (!m_wallet_descriptor.descriptor->IsRange()) {
1758 m_wallet_descriptor.range_end = 1;
1759 m_wallet_descriptor.range_start = 0;
1767 for (int32_t i = m_max_cached_index + 1; i < new_range_end; ++i) {
1769 std::vector<CScript> scripts_temp;
1772 if (!m_wallet_descriptor.descriptor->ExpandFromCache(i, m_wallet_descriptor.cache, scripts_temp, out_keys)) {
1773 if (!m_wallet_descriptor.descriptor->Expand(i, provider, scripts_temp, out_keys, &temp_cache))
return false;
1776 for (
const CScript& script : scripts_temp) {
1777 m_map_script_pub_keys[script] = i;
1779 for (
const auto& pk_pair : out_keys.
pubkeys) {
1780 const CPubKey& pubkey = pk_pair.second;
1781 if (m_map_pubkeys.count(pubkey) != 0) {
1786 m_map_pubkeys[pubkey] = i;
1791 if (m_wallet_descriptor.cache.GetCachedParentExtPubKey(parent_xpub_pair.first, xpub)) {
1792 if (xpub != parent_xpub_pair.second) {
1793 throw std::runtime_error(std::string(__func__) +
": New cached parent xpub does not match already cached parent xpub");
1797 if (!batch.WriteDescriptorParentCache(parent_xpub_pair.second,
id, parent_xpub_pair.first)) {
1798 throw std::runtime_error(std::string(__func__) +
": writing cache item failed");
1800 m_wallet_descriptor.cache.CacheParentExtPubKey(parent_xpub_pair.first, parent_xpub_pair.second);
1803 for (
const auto& derived_xpub_pair : derived_xpub_map_pair.second) {
1805 if (m_wallet_descriptor.cache.GetCachedDerivedExtPubKey(derived_xpub_map_pair.first, derived_xpub_pair.first, xpub)) {
1806 if (xpub != derived_xpub_pair.second) {
1807 throw std::runtime_error(std::string(__func__) +
": New cached derived xpub does not match already cached derived xpub");
1811 if (!batch.WriteDescriptorDerivedCache(derived_xpub_pair.second,
id, derived_xpub_map_pair.first, derived_xpub_pair.first)) {
1812 throw std::runtime_error(std::string(__func__) +
": writing cache item failed");
1814 m_wallet_descriptor.cache.CacheDerivedExtPubKey(derived_xpub_map_pair.first, derived_xpub_pair.first, derived_xpub_pair.second);
1817 m_max_cached_index++;
1819 m_wallet_descriptor.range_end = new_range_end;
1820 batch.WriteDescriptor(
GetID(), m_wallet_descriptor);
1823 assert(m_wallet_descriptor.range_end - 1 == m_max_cached_index);
1833 int32_t index = m_map_script_pub_keys[script];
1834 if (index >= m_wallet_descriptor.next_index) {
1835 WalletLogPrintf(
"%s: Detected a used keypool item at index %d, mark all keypool items up to this item as used\n", __func__, index);
1836 m_wallet_descriptor.next_index = index + 1;
1839 WalletLogPrintf(
"%s: Topping up keypool failed (locked wallet)\n", __func__);
1848 if (!AddDescriptorKeyWithDB(batch, key, pubkey)) {
1849 throw std::runtime_error(std::string(__func__) +
": writing descriptor private key failed");
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;
1883 if (m_wallet_descriptor.descriptor) {
1887 int64_t creation_time =
GetTime();
1892 std::string desc_prefix;
1893 std::string desc_suffix =
"/*)";
1894 switch (addr_type) {
1896 desc_prefix =
"pkh(" + xpub +
"/44'";
1900 desc_prefix =
"sh(wpkh(" + xpub +
"/49'";
1905 desc_prefix =
"wpkh(" + xpub +
"/84'";
1909 assert(!desc_prefix.empty());
1913 desc_prefix +=
"/1'";
1915 desc_prefix +=
"/0'";
1918 std::string internal_path = m_internal ?
"/1" :
"/0";
1919 std::string desc_str = desc_prefix +
"/0'" + internal_path + desc_suffix;
1924 std::unique_ptr<Descriptor> desc =
Parse(desc_str, keys, error,
false);
1926 m_wallet_descriptor = w_desc;
1930 if (!AddDescriptorKeyWithDB(batch, master_key.
key, master_key.
key.
GetPubKey())) {
1931 throw std::runtime_error(std::string(__func__) +
": writing descriptor master private key failed");
1933 if (!batch.WriteDescriptor(
GetID(), m_wallet_descriptor)) {
1934 throw std::runtime_error(std::string(__func__) +
": writing descriptor failed");
1947 return m_wallet_descriptor.descriptor->IsRange();
1955 return m_wallet_descriptor.descriptor->IsSingleType() &&
1956 m_wallet_descriptor.descriptor->IsRange() &&
1957 (
HavePrivateKeys() || m_wallet_descriptor.next_index < m_wallet_descriptor.range_end);
1963 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;
2004 return GetSigningProvider(index, include_private);
2012 auto it = m_map_pubkeys.find(pubkey);
2013 if (
it == m_map_pubkeys.end()) {
2016 int32_t index =
it->second;
2019 return GetSigningProvider(index,
true);
2026 std::unique_ptr<FlatSigningProvider> out_keys = MakeUnique<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);
2041 return GetSigningProvider(script,
false);
2051 std::unique_ptr<FlatSigningProvider> keys = MakeUnique<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 = MakeUnique<FlatSigningProvider>();
2116 std::unique_ptr<FlatSigningProvider> script_keys = GetSigningProvider(script, sign);
2118 *keys =
Merge(*keys, *script_keys);
2121 script_keys = MakeUnique<FlatSigningProvider>();
2123 const CPubKey& pubkey = pk_pair.first;
2124 std::unique_ptr<FlatSigningProvider> pk_keys = GetSigningProvider(pubkey);
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 = MakeUnique<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());
2183 this->m_internal =
internal;
2189 m_wallet_descriptor.cache = cache;
2190 for (int32_t i = m_wallet_descriptor.range_start; i < m_wallet_descriptor.range_end; ++i) {
2192 std::vector<CScript> scripts_temp;
2193 if (!m_wallet_descriptor.descriptor->ExpandFromCache(i, m_wallet_descriptor.cache, scripts_temp, out_keys)) {
2194 throw std::runtime_error(
"Error: Unable to expand wallet descriptor from cache");
2197 for (
const CScript& script : scripts_temp) {
2198 if (m_map_script_pub_keys.count(script) != 0) {
2199 throw std::runtime_error(
strprintf(
"Error: Already loaded script at index %d as being at index %d", i, m_map_script_pub_keys[script]));
2201 m_map_script_pub_keys[script] = i;
2203 for (
const auto& pk_pair : out_keys.
pubkeys) {
2204 const CPubKey& pubkey = pk_pair.second;
2205 if (m_map_pubkeys.count(pubkey) != 0) {
2210 m_map_pubkeys[pubkey] = i;
2212 m_max_cached_index++;
2219 m_map_keys[key_id] = key;
2226 if (!m_map_keys.empty()) {
2230 m_map_crypted_keys[key_id] = make_pair(pubkey, crypted_key);
2237 return m_wallet_descriptor.descriptor !=
nullptr && desc.
descriptor !=
nullptr && m_wallet_descriptor.descriptor->ToString() == desc.
descriptor->ToString();
2244 if (!batch.WriteDescriptor(
GetID(), m_wallet_descriptor)) {
2245 throw std::runtime_error(std::string(__func__) +
": writing descriptor failed");
2251 return m_wallet_descriptor;
2257 std::vector<CScript> script_pub_keys;
2258 script_pub_keys.reserve(m_map_script_pub_keys.size());
2260 for (
auto const& script_pub_key: m_map_script_pub_keys) {
2261 script_pub_keys.push_back(script_pub_key.first);
2263 return script_pub_keys;
void ReturnDestination(int64_t index, bool internal, const CTxDestination &) override
size_t KeypoolCountExternalKeys() const override
Witness v0 (P2WPKH and P2WSH); see BIP 141.
std::unordered_map< CKeyID, CHDChain, KeyIDHasher > m_inactive_hd_chains
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) ...
virtual bool HaveKey(const CKeyID &address) const override
bool NewKeyPool()
Mark old keypool keys as used, and generate all new keys.
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)
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 LoadScriptMetadata(const CScriptID &script_id, const CKeyMetadata &metadata)
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.
uint256 GetID() const override
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)
std::deque< CInv >::iterator it
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 void UnsetBlankWalletFlag(WalletBatch &)=0
const unsigned char * begin() const
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)
CExtPubKey Neuter() const
bool LoadCScript(const CScript &redeemScript)
Adds a CScript to the store.
bool AddKeyOriginWithDB(WalletBatch &batch, const CPubKey &pubkey, const KeyOriginInfo &info)
Add a KeyOriginInfo to the wallet.
bool DecryptKey(const CKeyingMaterial &vMasterKey, const std::vector< unsigned char > &vchCryptedSecret, const CPubKey &vchPubKey, CKey &key)
void SetInternal(bool internal) override
bool VerifyPubKey(const CPubKey &vchPubKey) const
Verify thoroughly whether a private key and a public key match.
bool CanGenerateKeys() const
isminetype IsMine(const CScript &script) const override
RecursiveMutex cs_KeyStore
Optional< CMutableTransaction > tx
static void LogPrintf(const char *fmt, const Args &...args)
const unsigned char * end() const
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...
int64_t GetTimeFirstKey() const override
std::set< CKeyID > GetKeys() const override
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)
std::unique_ptr< FlatSigningProvider > GetSigningProvider(const CScript &script, bool include_private=false) const
virtual const CKeyingMaterial & GetEncryptionKey() const =0
unsigned int GetKeyPoolSize() const override
virtual bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const override
const std::vector< CScript > GetScriptPubKeys() const
virtual void SetMinVersion(enum WalletFeature, WalletBatch *=nullptr)=0
virtual bool HaveCScript(const CScriptID &hash) const override
bool SignPSBTInput(const SigningProvider &provider, PartiallySignedTransaction &psbt, int index, int sighash, SignatureData *out_sigdata, bool use_dummy)
Signs a PSBTInput, verifying that all provided data matches what is being signed. ...
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.
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.
bool SetupDescriptorGeneration(const CExtKey &master_key, OutputType addr_type)
Setup descriptors based on the given CExtkey.
bool HasWalletDescriptor(const WalletDescriptor &desc) const
CKeyID GetKeyForDestination(const SigningProvider &store, const CTxDestination &dest)
Return the CKeyID of the key involved in a script (if there is a unique one).
bool IsHDEnabled() const override
uint32_t nExternalChainCounter
bool GetKey(const CKeyID &address, CKey &keyOut) const 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)
virtual bool IsLocked() const =0
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)
CPubKey GenerateNewKey(WalletBatch &batch, CHDChain &hd_chain, bool internal=false) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
Generate a new key.
bool GetReservedDestination(const OutputType type, bool internal, CTxDestination &address, int64_t &index, CKeyPool &keypool) override
static const unsigned int MAX_SCRIPT_ELEMENT_SIZE
boost::signals2::signal< void(bool fHaveWatchOnly)> NotifyWatchonlyChanged
Watch-only address added.
const WalletDescriptor GetWalletDescriptor() const EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man)
bool CanGetAddresses(bool internal=false) const override
bool RemoveWatchOnly(const CScript &dest)
Remove a watch only script from the keystore.
bool IsHDEnabled() const override
virtual std::set< CKeyID > GetKeys() const
KeyMap GetKeys() const EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man)
unspendable OP_RETURN script that carries data
bool Derive(CExtKey &out, unsigned int nChild) const
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.
SigningResult SignMessage(const std::string &message, const PKHash &pkhash, std::string &str_sig) const override
Sign a message with the given script.
static bool ExtractPubKey(const CScript &dest, CPubKey &pubKeyOut)
bool HaveWatchOnly(const CScript &dest) const
Returns whether the watch-only script is in the wallet.
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
TransactionError FillPSBT(PartiallySignedTransaction &psbt, 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 HavePrivateKeys() 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.
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.
IsMineSigVersion
This is an enum that tracks the execution context of a script, similar to SigVersion in script/interp...
bool error(const char *fmt, const Args &...args)
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 CanGetAddresses(bool internal=false) const override
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)
CPubKey GetPubKey() const
Compute the public key from a private key.
CPrivKey GetPrivKey() const
Convert the private key to a CPrivKey (serialized OpenSSL private key data).
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.
virtual bool HasEncryptionKeys() const =0
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.
AssertLockHeld(mempool.cs)
An encapsulated public key.
std::map< CKeyID, CPubKey > pubkeys
std::unique_ptr< CKeyMetadata > GetMetadata(const CTxDestination &dest) const override
void SetHDSeed(const CPubKey &key)
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
bool GetKeyOrigin(const CKeyID &keyid, KeyOriginInfo &info) const override
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)
std::unique_ptr< SigningProvider > GetSolvingProvider(const CScript &script) const override
bool m_pre_split
Whether this key was generated for a keypool before the wallet was upgraded to HD-split.
uint256 GetHash() const
Get the 256-bit hash of this public key.
isminetype
IsMine() return codes.
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)
virtual bool CanSupportFeature(enum WalletFeature) const =0
bool LoadWatchOnly(const CScript &dest)
Adds a watch-only address to the store, without saving it to disk (used by LoadWallet) ...
bool HaveKey(const CKeyID &address) const override
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.
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
bool WriteKeyMetadata(const CKeyMetadata &meta, const CPubKey &pubkey, const bool overwrite)
std::map< int64_t, CKeyID > m_index_to_reserved_key
const std::unordered_map< uint32_t, ExtPubKeyMap > GetCachedDerivedExtPubKeys() const
Retrieve all cached derived xpubs.
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)
isminetype IsMine(const CScript &script) const override
virtual bool IsWalletFlagSet(uint64_t) const =0
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 IsCompressed() const
Check whether this is a compressed public key.
bool ErasePool(int64_t nPool)
std::unique_ptr< SigningProvider > GetSolvingProvider(const CScript &script) const override
bool IsTestChain() const
If this chain is exclusively used for testing.
bool WritePool(int64_t nPool, const CKeyPool &keypool)
bool GetReservedDestination(const OutputType type, bool internal, CTxDestination &address, int64_t &index, CKeyPool &keypool) override
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)
std::unique_ptr< CKeyMetadata > GetMetadata(const CTxDestination &dest) const override
void SetCache(const DescriptorCache &cache)
std::string EncodeExtPubKey(const CExtPubKey &key)
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.
virtual bool GetCScript(const CScriptID &hash, CScript &redeemScriptOut) const override
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.
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
uint256 GetID() const override
std::map< CKeyID, CKey > KeyMap
Serialized script, used inside transaction inputs and outputs.
void AddHDChain(const CHDChain &chain)
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
std::string WriteHDKeypath(const std::vector< uint32_t > &keypath)
Write HD keypaths as strings.
bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const override
void LoadKeyPool(int64_t nIndex, const CKeyPool &keypool)
Load a keypool entry.
A reference to a CKey: the Hash160 of its serialized public key.
SigningResult SignMessage(const std::string &message, const PKHash &pkhash, std::string &str_sig) const override
Sign a message with the given script.
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.
Only for Witness versions not already defined above.
void WalletLogPrintf(std::string fmt, Params...parameters) const
Prepends the wallet name in logging output to ease debugging in multi-wallet use cases.
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.
int64_t GetOldestKeyPoolTime() const override
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.
bool EncryptSecret(const CKeyingMaterial &vMasterKey, const CKeyingMaterial &vchPlaintext, const uint256 &nIV, std::vector< unsigned char > &vchCiphertext)
bool ReadPool(int64_t nPool, CKeyPool &keypool)
static const int VERSION_HD_CHAIN_SPLIT
A reference to a CScript: the Hash160 of its serialization (see script.h)
bool GetWatchPubKey(const CKeyID &address, CPubKey &pubkey_out) const
Fetches a pubkey from mapWatchKeys if it exists there.
std::string EncodeDestination(const CTxDestination &dest)
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.
void DeriveNewChildKey(WalletBatch &batch, CKeyMetadata &metadata, CKey &secret, CHDChain &hd_chain, bool internal=false) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
std::vector< unsigned char > valtype
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
void SetInternal(bool internal) override
std::map< CKeyID, CKey > KeyMap
void AddDescriptorKey(const CKey &key, const CPubKey &pubkey)
An encapsulated private key.
boost::optional< T > Optional
Substitute for C++17 std::optional.
bool AddDescriptorKeyWithDB(WalletBatch &batch, const CKey &key, const CPubKey &pubkey) EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man)
const ExtPubKeyMap GetCachedParentExtPubKeys() const
Retrieve all cached parent xpubs.
virtual WalletDatabase & GetDatabase() const =0
bool TopUp(unsigned int size=0) override
Fills internal address pool.
unsigned int GetKeyPoolSize() const override
WalletStorage & m_storage
void Finalize(unsigned char hash[OUTPUT_SIZE])
boost::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
bool HaveWatchOnly() const
Returns whether there are any watch-only things in the wallet.
Indicate that this wallet supports DescriptorScriptPubKeyMan.
unsigned int size() const
Simple read-only vector-like interface.
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)
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
int64_t GetTime()
Return system time (or mocked time, if set)
void LoadHDChain(const CHDChain &chain)
Load a HD chain model (used by LoadWallet)
int64_t GetTimeFirstKey() const override
std::vector< uint32_t > path
size_t KeypoolCountExternalKeys() const override
bool AddCScriptWithDB(WalletBatch &batch, const CScript &script)
Adds a script to the store and saves it to disk.
virtual bool GetKey(const CKeyID &address, CKey &keyOut) const override
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)
TransactionError FillPSBT(PartiallySignedTransaction &psbt, 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.
static const int VERSION_HD_BASE
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.
bool HavePrivateKeys() const override
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...