26 error =
_(
"Error: Keypool ran out, please call keypoolrefill first").
translated;
34 typedef std::vector<unsigned char>
valtype;
44 enum class IsMineSigVersion
56 enum class IsMineResult
64 bool PermitsUncompressed(IsMineSigVersion sigversion)
66 return sigversion == IsMineSigVersion::TOP || sigversion == IsMineSigVersion::P2SH;
71 for (
const valtype& pubkey : pubkeys) {
73 if (!keystore.
HaveKey(keyID))
return false;
86 IsMineResult IsMineInner(
const LegacyScriptPubKeyMan& keystore,
const CScript& scriptPubKey, IsMineSigVersion sigversion,
bool recurse_scripthash=
true)
88 IsMineResult ret = IsMineResult::NO;
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))
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) {
1212 setExternalKeyPool.clear();
1214 for (
const int64_t nIndex : set_pre_split_keypool) {
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)) {
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");
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;
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)) {
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)) {
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;
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");
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");
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);
1819 m_wallet_descriptor.range_end = new_range_end;
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__);
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());
1912 if (
Params().IsTestChain()) {
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;
1931 throw std::runtime_error(std::string(__func__) +
": writing descriptor master private key failed");
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;
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 = 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);
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>();
2118 *keys =
Merge(*keys, *script_keys);
2121 script_keys = MakeUnique<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 = 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();
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;
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();
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;
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.
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string 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 * end() const
unsigned int size() const
Simple read-only vector-like interface.
CPrivKey GetPrivKey() const
Convert the private key to a CPrivKey (serialized OpenSSL private key data).
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
CPubKey GetPubKey() const
Compute the public key from a private key.
const unsigned char * begin() const
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.
const ExtPubKeyMap GetCachedParentExtPubKeys() const
Retrieve all cached parent xpubs.
const std::unordered_map< uint32_t, ExtPubKeyMap > GetCachedDerivedExtPubKeys() const
Retrieve all cached derived xpubs.
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
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.
SigningResult SignMessage(const std::string &message, const PKHash &pkhash, std::string &str_sig) const override
Sign a message with the given script.
bool TopUp(unsigned int size=0) override
Fills internal address pool.
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 AddCryptedKey(const CKeyID &key_id, const CPubKey &pubkey, const std::vector< unsigned char > &crypted_key)
void SetInternal(bool internal) override
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 GetReservedDestination(const OutputType type, bool internal, CTxDestination &address, int64_t &index, CKeyPool &keypool) override
bool GetNewDestination(const OutputType type, CTxDestination &dest, std::string &error) override
RecursiveMutex cs_desc_man
unsigned int GetKeyPoolSize() const override
bool SetupDescriptorGeneration(const CExtKey &master_key, OutputType addr_type)
Setup descriptors based on the given CExtkey.
void AddDescriptorKey(const CKey &key, const CPubKey &pubkey)
std::unique_ptr< CKeyMetadata > GetMetadata(const CTxDestination &dest) const override
size_t KeypoolCountExternalKeys() 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 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 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
bool GetReservedDestination(const OutputType type, bool internal, CTxDestination &address, int64_t &index, CKeyPool &keypool) 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 GetNewDestination(const OutputType type, CTxDestination &dest, std::string &error) override
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)
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 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.
size_t KeypoolCountExternalKeys() const override
void ReturnDestination(int64_t index, bool internal, const CTxDestination &) override
void SetHDSeed(const CPubKey &key)
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 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.
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.
void LoadKeyMetadata(const CKeyID &keyID, const CKeyMetadata &metadata)
Load metadata (used by LoadWallet)
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 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.
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.
void SetInternal(bool internal) override
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 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 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)
std::unordered_map< CKeyID, CHDChain, KeyIDHasher > m_inactive_hd_chains
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 WriteDescriptorDerivedCache(const CExtPubKey &xpub, const uint256 &desc_id, uint32_t key_exp_index, uint32_t der_index)
bool ErasePool(int64_t nPool)
bool WriteDescriptorParentCache(const CExtPubKey &xpub, const uint256 &desc_id, uint32_t key_exp_index)
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 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 WalletDatabase & GetDatabase() const =0
virtual bool HasEncryptionKeys() const =0
virtual bool IsLocked() const =0
virtual void SetMinVersion(enum WalletFeature, WalletBatch *=nullptr)=0
virtual const CKeyingMaterial & GetEncryptionKey() const =0
virtual void UnsetBlankWalletFlag(WalletBatch &)=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 > Parse(const std::string &descriptor, FlatSigningProvider &out, std::string &error, bool require_checksum)
Parse a descriptor string.
std::unique_ptr< Descriptor > InferDescriptor(const CScript &script, const SigningProvider &provider)
Find a descriptor for the specified script, using information from provider where possible.
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.
std::string EncodeDestination(const CTxDestination &dest)
std::string EncodeExtPubKey(const CExtPubKey &key)
static void LogPrintf(const char *fmt, const Args &... args)
bool MessageSign(const CKey &privkey, const std::string &message, std::string &signature)
Sign a message.
@ PRIVATE_KEY_NOT_AVAILABLE
std::deque< CInv >::iterator it
boost::optional< T > Optional
Substitute for C++17 std::optional.
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, int sighash, SignatureData *out_sigdata, bool use_dummy)
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< 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)
std::vector< CKeyID > GetAffectedKeys(const CScript &spk, const SigningProvider &provider)
static const unsigned int DEFAULT_KEYPOOL_SIZE
Default for -keypool.
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
boost::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, 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(const unsigned char *seed, unsigned int nSeedLen)
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.
Optional< CMutableTransaction > tx
std::vector< PSBTInput > inputs
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 GetSystemTimeInSeconds (not mockable) or GetTime<T> (mockable)
bilingual_str _(const char *psz)
Translation function.
AssertLockHeld(mempool.cs)
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_BLANK_WALLET
Flag set when a wallet contains no HD seed and no private keys, scripts, addresses,...
@ FEATURE_PRE_SPLIT_KEYPOOL