26 error =
_(
"Error: Legacy wallets only support the \"legacy\", \"p2sh-segwit\", and \"bech32\" address types");
37 error =
_(
"Error: Keypool ran out, please call keypoolrefill first");
45typedef std::vector<unsigned char>
valtype;
55enum class IsMineSigVersion
67enum class IsMineResult
75bool PermitsUncompressed(IsMineSigVersion sigversion)
77 return sigversion == IsMineSigVersion::TOP || sigversion == IsMineSigVersion::P2SH;
82 for (
const valtype& pubkey : pubkeys) {
84 if (!keystore.
HaveKey(keyID))
return false;
97IsMineResult IsMineInner(
const LegacyScriptPubKeyMan& keystore,
const CScript& scriptPubKey, IsMineSigVersion sigversion,
bool recurse_scripthash=
true)
99 IsMineResult ret = IsMineResult::NO;
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))
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");
308 error =
_(
"Error: Keypool ran out, please call keypoolrefill first");
313 error =
_(
"Error: Keypool ran out, please call keypoolrefill first");
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()){
378 bool internal = (meta.
key_origin.
path[1] & ~BIP32_HARDENED_KEY_LIMIT) != 0;
379 int64_t index = meta.
key_origin.
path[2] & ~BIP32_HARDENED_KEY_LIMIT;
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) {
1230 setExternalKeyPool.clear();
1232 for (
const int64_t nIndex : set_pre_split_keypool) {
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)) {
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");
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;
1558bool 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;
1809 throw std::runtime_error(std::string(__func__) +
": writing cache items failed");
1813 m_wallet_descriptor.range_end = new_range_end;
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());
1919 if (
Params().IsTestChain()) {
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");
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();
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();
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;
2272 return m_wallet_descriptor.descriptor->ToPrivateString(provider, out);
2275 return m_wallet_descriptor.descriptor->ToNormalizedString(provider, out, &m_wallet_descriptor.cache);
2286 if (m_wallet_descriptor.cache.GetCachedLastHardenedExtPubKeys().size() > 0) {
2294 std::vector<CScript> scripts_temp;
2296 if (!m_wallet_descriptor.descriptor->Expand(0, provider, scripts_temp, out_keys, &temp_cache)){
2297 throw std::runtime_error(
"Unable to expand descriptor");
2303 throw std::runtime_error(std::string(__func__) +
": writing cache items failed");
2312 throw std::runtime_error(std::string(__func__) +
": " +
error);
2315 m_map_pubkeys.clear();
2316 m_map_script_pub_keys.clear();
2318 m_wallet_descriptor = descriptor;
2325 error =
"can only update matching descriptor";
2329 if (descriptor.
range_start > m_wallet_descriptor.range_start ||
2330 descriptor.
range_end < m_wallet_descriptor.range_end) {
2332 error =
strprintf(
"new range must include current range = [%d,%d]",
2333 m_wallet_descriptor.range_start,
2334 m_wallet_descriptor.range_end - 1);
bool ParseHDKeypath(const std::string &keypath_str, std::vector< uint32_t > &keypath)
Parse an HD keypaths like "m/7/0'/2000".
std::string WriteHDKeypath(const std::vector< uint32_t > &keypath)
Write HD keypaths as strings.
const CChainParams & Params()
Return the currently selected parameters.
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
static const int VERSION_HD_BASE
uint32_t nInternalChainCounter
CKeyID seed_id
seed hash160
static const int VERSION_HD_CHAIN_SPLIT
uint32_t nExternalChainCounter
An encapsulated private key.
const unsigned char * begin() const
CPrivKey GetPrivKey() const
Convert the private key to a CPrivKey (serialized OpenSSL private key data).
const unsigned char * end() const
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
CPubKey GetPubKey() const
Compute the public key from a private key.
bool VerifyPubKey(const CPubKey &vchPubKey) const
Verify thoroughly whether a private key and a public key match.
A reference to a CKey: the Hash160 of its serialized public key.
A key from a CWallet's keypool.
bool fInternal
Whether this keypool entry is in the internal keypool (for change outputs)
CPubKey vchPubKey
The public key.
int64_t nTime
The time at which the key was generated. Set in AddKeypoolPubKeyWithDB.
bool m_pre_split
Whether this key was generated for a keypool before the wallet was upgraded to HD-split.
An encapsulated public key.
bool IsCompressed() const
Check whether this is a compressed public key.
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
uint256 GetHash() const
Get the 256-bit hash of this public key.
A hasher class for RIPEMD-160.
CRIPEMD160 & Write(const unsigned char *data, size_t len)
void Finalize(unsigned char hash[OUTPUT_SIZE])
A hasher class for SHA-256.
void Finalize(unsigned char hash[OUTPUT_SIZE])
CSHA256 & Write(const unsigned char *data, size_t len)
Serialized script, used inside transaction inputs and outputs.
A reference to a CScript: the Hash160 of its serialization (see script.h)
An input of a transaction.
Cache for single descriptor's derived extended pubkeys.
DescriptorCache MergeAndDiff(const DescriptorCache &other)
Combine another DescriptorCache into this one.
int64_t GetOldestKeyPoolTime() const override
void ReturnDestination(int64_t index, bool internal, const CTxDestination &addr) override
bool AddKey(const CKeyID &key_id, const CKey &key)
void MarkUnusedAddresses(const CScript &script) override
Mark unused addresses as being used.
bool HavePrivateKeys() const override
SigningResult SignMessage(const std::string &message, const PKHash &pkhash, std::string &str_sig) const override
Sign a message with the given script.
bool CanUpdateToWalletDescriptor(const WalletDescriptor &descriptor, std::string &error)
bool GetNewDestination(const OutputType type, CTxDestination &dest, bilingual_str &error) override
bool TopUp(unsigned int size=0) override
Fills internal address pool.
bool AddCryptedKey(const CKeyID &key_id, const CPubKey &pubkey, const std::vector< unsigned char > &crypted_key)
std::unique_ptr< SigningProvider > GetSolvingProvider(const CScript &script) const override
bool HasWalletDescriptor(const WalletDescriptor &desc) const
int64_t GetTimeFirstKey() const override
bool CanProvide(const CScript &script, SignatureData &sigdata) override
Whether this ScriptPubKeyMan can provide a SigningProvider (via GetSolvingProvider) that,...
bool SetupDescriptorGeneration(const CExtKey &master_key, OutputType addr_type, bool internal)
Setup descriptors based on the given CExtkey.
RecursiveMutex cs_desc_man
unsigned int GetKeyPoolSize() const override
bool SignTransaction(CMutableTransaction &tx, const std::map< COutPoint, Coin > &coins, int sighash, std::map< int, bilingual_str > &input_errors) const override
Creates new signatures and adds them to the transaction.
void AddDescriptorKey(const CKey &key, const CPubKey &pubkey)
std::unique_ptr< CKeyMetadata > GetMetadata(const CTxDestination &dest) const override
int32_t m_max_cached_index
bool m_decryption_thoroughly_checked
keeps track of whether Unlock has run a thorough check before
KeyMap GetKeys() const EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man)
std::unique_ptr< FlatSigningProvider > GetSigningProvider(const CScript &script, bool include_private=false) const
const std::vector< CScript > GetScriptPubKeys() const
std::map< CKeyID, CKey > KeyMap
bool Encrypt(const CKeyingMaterial &master_key, WalletBatch *batch) override
bool AddDescriptorKeyWithDB(WalletBatch &batch, const CKey &key, const CPubKey &pubkey) EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man)
void UpdateWalletDescriptor(WalletDescriptor &descriptor)
bool GetReservedDestination(const OutputType type, bool internal, CTxDestination &address, int64_t &index, CKeyPool &keypool, bilingual_str &error) override
void UpgradeDescriptorCache()
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.
void SetCache(const DescriptorCache &cache)
uint256 GetID() const override
const WalletDescriptor GetWalletDescriptor() const EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man)
isminetype IsMine(const CScript &script) const override
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...
bool GetDescriptorString(std::string &out, const bool priv) const
bool IsHDEnabled() const override
bool CanGetAddresses(bool internal=false) const override
virtual bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey)
virtual bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const override
virtual bool GetCScript(const CScriptID &hash, CScript &redeemScriptOut) const override
virtual bool GetKey(const CKeyID &address, CKey &keyOut) const override
virtual bool AddCScript(const CScript &redeemScript)
void ImplicitlyLearnRelatedKeyScripts(const CPubKey &pubkey) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
virtual std::set< CKeyID > GetKeys() const
std::map< CKeyID, CKey > KeyMap
virtual bool HaveCScript(const CScriptID &hash) const override
RecursiveMutex cs_KeyStore
virtual bool HaveKey(const CKeyID &address) const override
bool GetKeyOrigin(const CKeyID &keyid, KeyOriginInfo &info) const override
std::map< int64_t, CKeyID > m_index_to_reserved_key
void UpgradeKeyMetadata()
Upgrade stored CKeyMetadata objects to store key origin info as KeyOriginInfo.
bool fDecryptionThoroughlyChecked
keeps track of whether Unlock has run a thorough check before
int64_t GetOldestKeyPoolTime() const override
uint256 GetID() const override
bool LoadWatchOnly(const CScript &dest)
Adds a watch-only address to the store, without saving it to disk (used by LoadWallet)
std::unique_ptr< SigningProvider > GetSolvingProvider(const CScript &script) const override
void MarkUnusedAddresses(const CScript &script) override
Mark unused addresses as being used.
bool HaveWatchOnly() const
Returns whether there are any watch-only things in the wallet.
bool RemoveWatchOnly(const CScript &dest)
Remove a watch only script from the keystore.
bool AddWatchOnlyInMem(const CScript &dest)
void UpdateTimeFirstKey(int64_t nCreateTime) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
Update wallet first key creation time.
void AddKeypoolPubkeyWithDB(const CPubKey &pubkey, const bool internal, WalletBatch &batch)
void ReturnDestination(int64_t index, bool internal, const CTxDestination &) override
void SetHDSeed(const CPubKey &key)
std::unordered_map< CKeyID, CHDChain, SaltedSipHasher > m_inactive_hd_chains
bool GetKey(const CKeyID &address, CKey &keyOut) const override
void LearnAllRelatedScripts(const CPubKey &key)
Same as LearnRelatedScripts, but when the OutputType is not known (and could be anything).
bool Encrypt(const CKeyingMaterial &master_key, WalletBatch *batch) override
isminetype IsMine(const CScript &script) const override
bool ImportScripts(const std::set< CScript > scripts, int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
std::unique_ptr< CKeyMetadata > GetMetadata(const CTxDestination &dest) const override
bool HaveKey(const CKeyID &address) const override
bool ImportPrivKeys(const std::map< CKeyID, CKey > &privkey_map, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
bool TopUpInactiveHDChain(const CKeyID seed_id, int64_t index, bool internal)
Like TopUp() but adds keys for inactive HD chains.
bool CanGetAddresses(bool internal=false) const override
bool AddKeyPubKeyInner(const CKey &key, const CPubKey &pubkey)
void AddHDChain(const CHDChain &chain)
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...
bool CanGenerateKeys() const
void LoadKeyPool(int64_t nIndex, const CKeyPool &keypool)
Load a keypool entry.
bool AddCryptedKeyInner(const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret)
bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret)
Adds an encrypted key to the store, and saves it to disk.
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 IsHDEnabled() const override
bool AddWatchOnlyWithDB(WalletBatch &batch, const CScript &dest) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
bool LoadKey(const CKey &key, const CPubKey &pubkey)
Adds a key to the store, without saving it to disk (used by LoadWallet)
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 AddKeyOriginWithDB(WalletBatch &batch, const CPubKey &pubkey, const KeyOriginInfo &info)
Add a KeyOriginInfo to the wallet.
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...
bool TopUp(unsigned int size=0) override
Fills internal address pool.
void LoadKeyMetadata(const CKeyID &keyID, const CKeyMetadata &metadata)
Load metadata (used by LoadWallet)
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.
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.
void LoadHDChain(const CHDChain &chain)
Load a HD chain model (used by LoadWallet)
bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const override
void AddInactiveHDChain(const CHDChain &chain)
bool Upgrade(int prev_version, int new_version, bilingual_str &error) override
Upgrades the wallet to the specified version.
bool GetWatchPubKey(const CKeyID &address, CPubKey &pubkey_out) const
Fetches a pubkey from mapWatchKeys if it exists there.
void LearnRelatedScripts(const CPubKey &key, OutputType)
Explicitly make the wallet learn the related scripts for outputs to the given key.
bool SignTransaction(CMutableTransaction &tx, const std::map< COutPoint, Coin > &coins, int sighash, std::map< int, bilingual_str > &input_errors) const override
Creates new signatures and adds them to the transaction.
bool NewKeyPool()
Mark old keypool keys as used, and generate all new keys.
bool ReserveKeyFromKeyPool(int64_t &nIndex, CKeyPool &keypool, bool fRequestedInternal)
Reserves a key from the keypool and sets nIndex to its index.
std::set< CKeyID > GetKeys() const override
void KeepDestination(int64_t index, const OutputType &type) override
bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey) override
Adds a key to the store, and saves it to disk.
CPubKey GenerateNewKey(WalletBatch &batch, CHDChain &hd_chain, bool internal=false) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
Generate a new key.
bool GetNewDestination(const OutputType type, CTxDestination &dest, bilingual_str &error) override
void MarkPreSplitKeys() EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
unsigned int GetKeyPoolSize() const override
bool HavePrivateKeys() const override
bool HaveWatchOnly(const CScript &dest) const
Returns whether the watch-only script is in the wallet.
bool SetupGeneration(bool force=false) override
Sets up the key generation stuff, i.e.
CPubKey GenerateNewSeed()
bool ImportScriptPubKeys(const std::set< CScript > &script_pub_keys, const bool have_solving_data, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
bool GetReservedDestination(const OutputType type, bool internal, CTxDestination &address, int64_t &index, CKeyPool &keypool, bilingual_str &error) override
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.
size_t KeypoolCountExternalKeys() const
void RewriteDB() override
The action to do when the DB needs rewrite.
CPubKey DeriveNewSeed(const CKey &key)
bool CanProvide(const CScript &script, SignatureData &sigdata) override
Whether this ScriptPubKeyMan can provide a SigningProvider (via GetSolvingProvider) that,...
int64_t GetTimeFirstKey() const override
void LoadScriptMetadata(const CScriptID &script_id, const CKeyMetadata &metadata)
SigningResult SignMessage(const std::string &message, const PKHash &pkhash, std::string &str_sig) const override
Sign a message with the given script.
bool LoadCScript(const CScript &redeemScript)
Adds a CScript to the store.
bool AddCScript(const CScript &redeemScript) override
bool AddCScriptWithDB(WalletBatch &batch, const CScript &script)
Adds a script to the store and saves it to disk.
std::map< CKeyID, int64_t > m_pool_key_to_index
bool GetKeyFromPool(CPubKey &key, const OutputType type, bool internal=false)
Fetches a key from the keypool.
void DeriveNewChildKey(WalletBatch &batch, CKeyMetadata &metadata, CKey &secret, CHDChain &hd_chain, bool internal=false) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
WalletStorage & m_storage
boost::signals2::signal< void()> NotifyCanGetAddressesChanged
Keypool has new keys.
boost::signals2::signal< void(bool fHaveWatchOnly)> NotifyWatchonlyChanged
Watch-only address added.
void WalletLogPrintf(std::string fmt, Params... parameters) const
Prepends the wallet name in logging output to ease debugging in multi-wallet use cases.
An interface to be implemented by keystores that support signing.
Access to the wallet database.
bool WriteDescriptor(const uint256 &desc_id, const WalletDescriptor &descriptor)
bool ErasePool(int64_t nPool)
bool WriteCScript(const uint160 &hash, const CScript &redeemScript)
bool EraseWatchOnly(const CScript &script)
bool WriteCryptedKey(const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret, const CKeyMetadata &keyMeta)
bool WriteDescriptorKey(const uint256 &desc_id, const CPubKey &pubkey, const CPrivKey &privkey)
bool ReadPool(int64_t nPool, CKeyPool &keypool)
bool WriteKey(const CPubKey &vchPubKey, const CPrivKey &vchPrivKey, const CKeyMetadata &keyMeta)
bool WriteHDChain(const CHDChain &chain)
write the hdchain model (external chain child index counter)
bool WriteCryptedDescriptorKey(const uint256 &desc_id, const CPubKey &pubkey, const std::vector< unsigned char > &secret)
bool WriteDescriptorCacheItems(const uint256 &desc_id, const DescriptorCache &cache)
bool WriteKeyMetadata(const CKeyMetadata &meta, const CPubKey &pubkey, const bool overwrite)
bool WriteWatchOnly(const CScript &script, const CKeyMetadata &keymeta)
bool WritePool(int64_t nPool, const CKeyPool &keypool)
Descriptor with some wallet metadata.
std::shared_ptr< Descriptor > descriptor
virtual bool IsWalletFlagSet(uint64_t) const =0
virtual bool HasEncryptionKeys() const =0
virtual const CKeyingMaterial & GetEncryptionKey() const =0
virtual bool IsLocked() const =0
virtual void SetMinVersion(enum WalletFeature, WalletBatch *=nullptr)=0
virtual void UnsetBlankWalletFlag(WalletBatch &)=0
virtual WalletDatabase & GetDatabase() const =0
virtual bool CanSupportFeature(enum WalletFeature) const =0
bool DecryptKey(const CKeyingMaterial &vMasterKey, const std::vector< unsigned char > &vchCryptedSecret, const CPubKey &vchPubKey, CKey &key)
bool EncryptSecret(const CKeyingMaterial &vMasterKey, const CKeyingMaterial &vchPlaintext, const uint256 &nIV, std::vector< unsigned char > &vchCiphertext)
std::vector< unsigned char, secure_allocator< unsigned char > > CKeyingMaterial
std::unique_ptr< Descriptor > InferDescriptor(const CScript &script, const SigningProvider &provider)
Find a descriptor for the specified script, using information from provider where possible.
std::unique_ptr< Descriptor > Parse(const std::string &descriptor, FlatSigningProvider &out, std::string &error, bool require_checksum)
Parse a descriptor string.
uint160 Hash160(const T1 &in1)
Compute the 160-bit hash an object.
std::vector< unsigned char > valtype
@ WITNESS_V0
Witness v0 (P2WPKH and P2WSH); see BIP 141.
isminetype
IsMine() return codes, which depend on ScriptPubKeyMan implementation.
std::string EncodeDestination(const CTxDestination &dest)
std::string EncodeExtPubKey(const CExtPubKey &key)
@ PRIVATE_KEY_NOT_AVAILABLE
static unsigned const char sighash[]
CTxDestination GetDestinationForKey(const CPubKey &key, OutputType type)
Get a destination of the requested type (if possible) to the specified key.
void UpdatePSBTOutput(const SigningProvider &provider, PartiallySignedTransaction &psbt, int index)
Updates a PSBTOutput with information from provider.
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.
bool PSBTInputSigned(const PSBTInput &input)
Checks whether a PSBTInput is already signed.
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.
@ TOP
Top-level scriptPubKey.
static const unsigned int MAX_SCRIPT_ELEMENT_SIZE
static bool ExtractPubKey(const CScript &dest, CPubKey &pubKeyOut)
std::vector< CKeyID > GetAffectedKeys(const CScript &spk, const SigningProvider &provider)
std::vector< unsigned char > valtype
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....
static int64_t GetOldestKeyTimeInPool(const std::set< int64_t > &setKeyPool, WalletBatch &batch)
static const unsigned int DEFAULT_KEYPOOL_SIZE
Default for -keypool.
static const std::unordered_set< OutputType > LEGACY_OUTPUT_TYPES
OutputTypes supported by the LegacyScriptPubKeyMan.
bool ProduceSignature(const SigningProvider &provider, const BaseSignatureCreator &creator, const CScript &fromPubKey, SignatureData &sigdata)
Produce a script signature using a generic signature creator.
bool IsSolvable(const SigningProvider &provider, const CScript &script)
const BaseSignatureCreator & DUMMY_SIGNATURE_CREATOR
A signature creator that just produces 71-byte empty signatures.
const SigningProvider & DUMMY_SIGNING_PROVIDER
FlatSigningProvider Merge(const FlatSigningProvider &a, const FlatSigningProvider &b)
CKeyID GetKeyForDestination(const SigningProvider &store, const CTxDestination &dest)
Return the CKeyID of the key involved in a script (if there is a unique one).
TxoutType Solver(const CScript &scriptPubKey, std::vector< std::vector< unsigned char > > &vSolutionsRet)
Parse a scriptPubKey and identify script type for standard scripts.
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
CScript GetScriptForRawPubKey(const CPubKey &pubKey)
Generate a P2PK script for the given pubkey.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
CKeyID ToKeyID(const PKHash &key_hash)
@ WITNESS_UNKNOWN
Only for Witness versions not already defined above.
@ NULL_DATA
unspendable OP_RETURN script that carries data
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
std::string ToString(const T &t)
Locale-independent version of std::to_string.
CExtPubKey Neuter() const
bool Derive(CExtKey &out, unsigned int nChild) const
void SetSeed(Span< const uint8_t > seed)
A mutable version of CTransaction.
std::map< CKeyID, CPubKey > pubkeys
std::map< CKeyID, CKey > keys
unsigned char fingerprint[4]
First 32 bits of the Hash160 of the public key at the root of the path.
std::vector< uint32_t > path
A version of CTransaction with the PSBT format.
std::vector< PSBTInput > inputs
std::optional< CMutableTransaction > tx
std::map< CKeyID, SigPair > signatures
BIP 174 style partial signatures for the input. May contain all signatures necessary for producing a ...
bool error(const char *fmt, const Args &... args)
int64_t GetTime()
DEPRECATED Use either GetTimeSeconds (not mockable) or GetTime<T> (mockable)
bilingual_str _(const char *psz)
Translation function.
bool MessageSign(const CKey &privkey, const std::string &message, std::string &signature)
Sign a message.
bool IsFeatureSupported(int wallet_version, int feature_version)
@ WALLET_FLAG_DISABLE_PRIVATE_KEYS
@ WALLET_FLAG_KEY_ORIGIN_METADATA
@ WALLET_FLAG_DESCRIPTORS
Indicate that this wallet supports DescriptorScriptPubKeyMan.
@ WALLET_FLAG_LAST_HARDENED_XPUB_CACHED
@ WALLET_FLAG_BLANK_WALLET
Flag set when a wallet contains no HD seed and no private keys, scripts, addresses,...
@ FEATURE_PRE_SPLIT_KEYPOOL