30 error =
_(
"Error: Keypool ran out, please call keypoolrefill first")
49 enum class IsMineSigVersion {
59 enum class IsMineResult {
66 bool HaveKeys(
const std::vector<valtype> &pubkeys,
68 for (
const valtype &pubkey : pubkeys) {
88 IsMineSigVersion sigversion,
89 bool recurse_scripthash =
true) {
90 IsMineResult ret = IsMineResult::NO;
92 std::vector<valtype> vSolutions;
103 ret = std::max(ret, IsMineResult::SPENDABLE);
109 ret = std::max(ret, IsMineResult::SPENDABLE);
113 if (sigversion != IsMineSigVersion::TOP) {
115 return IsMineResult::INVALID;
119 if (keystore.
GetCScript(scriptID, subscript)) {
120 ret = std::max(ret, recurse_scripthash
121 ? IsMineInner(keystore, subscript,
122 IsMineSigVersion::P2SH)
123 : IsMineResult::SPENDABLE);
130 if (sigversion == IsMineSigVersion::TOP) {
139 std::vector<valtype> keys(vSolutions.begin() + 1,
140 vSolutions.begin() + vSolutions.size() -
142 if (HaveKeys(keys, keystore)) {
143 ret = std::max(ret, IsMineResult::SPENDABLE);
149 if (ret == IsMineResult::NO && keystore.
HaveWatchOnly(scriptPubKey)) {
150 ret = std::max(ret, IsMineResult::WATCH_ONLY);
158 switch (IsMineInner(*
this, script, IsMineSigVersion::TOP)) {
159 case IsMineResult::INVALID:
160 case IsMineResult::NO:
162 case IsMineResult::WATCH_ONLY:
164 case IsMineResult::SPENDABLE:
177 bool keyPass = mapCryptedKeys.empty();
178 bool keyFail =
false;
179 CryptedKeyMap::const_iterator mi = mapCryptedKeys.begin();
181 for (; mi != mapCryptedKeys.end(); ++mi) {
182 const CPubKey &vchPubKey = (*mi).second.first;
183 const std::vector<uint8_t> &vchCryptedSecret = (*mi).second.second;
185 if (!
DecryptKey(master_key, vchCryptedSecret, vchPubKey, key)) {
195 mapKeyMetadata[vchPubKey.
GetID()]);
198 if (keyPass && keyFail) {
199 LogPrintf(
"The wallet is probably corrupted: Some keys decrypt but "
201 throw std::runtime_error(
202 "Error unlocking wallet: some keys decrypt but not all. Your "
203 "wallet file may be corrupt.");
205 if (keyFail || (!keyPass && !accept_no_keys)) {
216 encrypted_batch = batch;
217 if (!mapCryptedKeys.empty()) {
218 encrypted_batch =
nullptr;
224 keys_to_encrypt.swap(mapKeys);
225 for (
const KeyMap::value_type &mKey : keys_to_encrypt) {
226 const CKey &key = mKey.second;
229 std::vector<uint8_t> vchCryptedSecret;
232 encrypted_batch =
nullptr;
236 encrypted_batch =
nullptr;
240 encrypted_batch =
nullptr;
262 int64_t index,
bool internal) {
277 int64_t target_size =
288 int64_t missing = std::max(target_size - kp_size, (int64_t)0);
292 for (int64_t i = missing; i > 0; --i) {
297 HexStr(seed_id), missing);
300 HexStr(seed_id), missing);
310 std::map<CKeyID, int64_t>::const_iterator mi =
314 "keys up to this key as used\n",
320 "%s: Topping up keypool failed (locked wallet)\n",
328 auto it = mapKeyMetadata.find(keyid);
329 if (it != mapKeyMetadata.end()) {
355 for (
auto &meta_pair : mapKeyMetadata) {
367 std::copy(master_id.
begin(), master_id.
begin() + 4,
370 throw std::runtime_error(
"Invalid stored hdKeypath");
379 if (
GetPubKey(meta_pair.first, pubkey)) {
380 batch->WriteKeyMetadata(meta, pubkey,
true);
405 bool keypool_has_keys;
407 keypool_has_keys = setInternalKeyPool.size() > 0;
412 if (!keypool_has_keys) {
415 return keypool_has_keys;
420 bool hd_upgrade =
false;
421 bool split_upgrade =
false;
444 error =
_(
"Unable to generate keys");
453 return !mapKeys.empty() || !mapCryptedKeys.empty();
458 setInternalKeyPool.clear();
459 setExternalKeyPool.clear();
468 if (setKeyPool.empty()) {
473 int64_t nIndex = *(setKeyPool.begin());
474 if (!batch.
ReadPool(nIndex, keypool)) {
475 throw std::runtime_error(std::string(__func__) +
476 ": read oldest key in keypool failed");
480 return keypool.
nTime;
493 if (!set_pre_split_keypool.empty()) {
505 return setExternalKeyPool.size() + set_pre_split_keypool.size();
510 return setInternalKeyPool.size() + setExternalKeyPool.size() +
511 set_pre_split_keypool.size();
516 return nTimeFirstKey;
519 std::unique_ptr<SigningProvider>
521 return std::make_unique<LegacySigningProvider>(*
this);
526 IsMineResult ismine = IsMineInner(*
this, script, IsMineSigVersion::TOP,
528 if (ismine == IsMineResult::SPENDABLE ||
529 ismine == IsMineResult::WATCH_ONLY) {
541 bool has_privkeys =
false;
542 for (
const auto &key_sig_pair : sigdata.
signatures) {
543 has_privkeys |=
HaveKey(key_sig_pair.first);
552 SigHashType sighash, std::map<int, std::string> &input_errors)
const {
558 std::string &str_sig)
const {
573 bool bip32derivs)
const {
574 for (
size_t i = 0; i < psbtx.
tx->vin.size(); ++i) {
599 for (
size_t i = 0; i < psbtx.
tx->vout.size(); ++i) {
607 std::unique_ptr<CKeyMetadata>
613 auto it = mapKeyMetadata.find(key_id);
614 if (it != mapKeyMetadata.end()) {
615 return std::make_unique<CKeyMetadata>(it->second);
620 auto it = m_script_metadata.find(
CScriptID(scriptPubKey));
621 if (it != m_script_metadata.end()) {
622 return std::make_unique<CKeyMetadata>(it->second);
638 if (nCreateTime <= 1) {
642 }
else if (!nTimeFirstKey || nCreateTime < nTimeFirstKey) {
643 nTimeFirstKey = nCreateTime;
669 bool needsDB = !encrypted_batch;
671 encrypted_batch = &batch;
675 encrypted_batch =
nullptr;
681 encrypted_batch =
nullptr;
698 mapKeyMetadata[pubkey.
GetID()]);
711 std::string strAddr =
714 "of size %i which exceeds maximum size %i thus can "
715 "never be redeemed. Do not use address %s.\n",
728 mapKeyMetadata[keyID] = meta;
735 m_script_metadata[script_id] = meta;
749 std::vector<uint8_t> vchCryptedSecret;
752 pubkey.
GetHash(), vchCryptedSecret)) {
763 const CPubKey &vchPubKey,
const std::vector<uint8_t> &vchCryptedSecret,
764 bool checksum_valid) {
766 if (!checksum_valid) {
774 const CPubKey &vchPubKey,
const std::vector<uint8_t> &vchCryptedSecret) {
778 mapCryptedKeys[vchPubKey.
GetID()] = make_pair(vchPubKey, vchCryptedSecret);
783 const CPubKey &vchPubKey,
const std::vector<uint8_t> &vchCryptedSecret) {
789 if (encrypted_batch) {
790 return encrypted_batch->WriteCryptedKey(
791 vchPubKey, vchCryptedSecret, mapKeyMetadata[vchPubKey.
GetID()]);
796 mapKeyMetadata[vchPubKey.
GetID()]);
801 return setWatchOnly.count(dest) > 0;
806 return (!setWatchOnly.empty());
810 std::vector<std::vector<uint8_t>> solutions;
812 (pubKeyOut =
CPubKey(solutions[0])).IsFullyValid();
818 setWatchOnly.erase(dest);
821 mapWatchKeys.erase(pubKey.
GetID());
838 setWatchOnly.insert(dest);
841 mapWatchKeys[pubKey.
GetID()] = pubKey;
864 int64_t create_time) {
865 m_script_metadata[
CScriptID(dest)].nCreateTime = create_time;
875 int64_t nCreateTime) {
876 m_script_metadata[
CScriptID(dest)].nCreateTime = nCreateTime;
889 throw std::runtime_error(std::string(__func__) +
890 ": writing chain failed");
912 return mapCryptedKeys.count(address) > 0;
921 CryptedKeyMap::const_iterator mi = mapCryptedKeys.find(address);
922 if (mi != mapCryptedKeys.end()) {
923 const CPubKey &vchPubKey = (*mi).second.first;
924 const std::vector<uint8_t> &vchCryptedSecret = (*mi).second.second;
936 auto it = mapKeyMetadata.find(keyID);
937 if (it != mapKeyMetadata.end()) {
955 WatchKeyMap::const_iterator it = mapWatchKeys.find(address);
956 if (it != mapWatchKeys.end()) {
957 pubkey_out = it->second;
973 CryptedKeyMap::const_iterator mi = mapCryptedKeys.find(address);
974 if (mi != mapCryptedKeys.end()) {
975 vchPubKeyOut = (*mi).second.first;
995 int64_t nCreationTime =
GetTime();
1002 batch, metadata, secret, hd_chain,
1016 mapKeyMetadata[pubkey.
GetID()] = metadata;
1020 throw std::runtime_error(std::string(__func__) +
": AddKey failed");
1044 throw std::runtime_error(std::string(__func__) +
": seed not found");
1056 accountKey.
Derive(chainChildKey,
1087 secret = childKey.
key;
1090 std::copy(master_id.
begin(), master_id.
begin() + 4,
1096 throw std::runtime_error(std::string(__func__) +
1097 ": writing HD chain model failed");
1105 set_pre_split_keypool.insert(nIndex);
1107 setInternalKeyPool.insert(nIndex);
1109 setExternalKeyPool.insert(nIndex);
1111 m_max_keypool_index = std::max(m_max_keypool_index, nIndex);
1118 if (mapKeyMetadata.count(keyid) == 0) {
1138 int64_t nCreationTime =
GetTime();
1153 mapKeyMetadata[seed.
GetID()] = metadata;
1157 throw std::runtime_error(std::string(__func__) +
1158 ": AddKeyPubKey failed");
1190 for (
const int64_t nIndex : setInternalKeyPool) {
1193 setInternalKeyPool.clear();
1195 for (
const int64_t nIndex : setExternalKeyPool) {
1198 setExternalKeyPool.clear();
1200 for (int64_t nIndex : set_pre_split_keypool) {
1203 set_pre_split_keypool.clear();
1211 WalletLogPrintf(
"LegacyScriptPubKeyMan::NewKeyPool rewrote keypool\n");
1227 unsigned int nTargetSize;
1229 nTargetSize = kpSize;
1231 nTargetSize = std::max<int64_t>(
1238 int64_t missingExternal = std::max<int64_t>(
1239 std::max<int64_t>(nTargetSize, 1) - setExternalKeyPool.size(), 0);
1240 int64_t missingInternal = std::max<int64_t>(
1241 std::max<int64_t>(nTargetSize, 1) - setInternalKeyPool.size(), 0);
1245 missingInternal = 0;
1247 bool internal =
false;
1249 for (int64_t i = missingInternal + missingExternal; i--;) {
1250 if (i < missingInternal) {
1257 if (missingInternal + missingExternal > 0) {
1259 "keypool added %d keys (%d internal), size=%u (%u internal)\n",
1260 missingInternal + missingExternal, missingInternal,
1261 setInternalKeyPool.size() + setExternalKeyPool.size() +
1262 set_pre_split_keypool.size(),
1263 setInternalKeyPool.size());
1271 const bool internal,
1275 assert(m_max_keypool_index < std::numeric_limits<int64_t>::max());
1276 int64_t index = ++m_max_keypool_index;
1278 throw std::runtime_error(std::string(__func__) +
1279 ": writing imported pubkey failed");
1282 setInternalKeyPool.insert(index);
1284 setExternalKeyPool.insert(index);
1308 setInternalKeyPool.insert(nIndex);
1309 }
else if (!set_pre_split_keypool.empty()) {
1310 set_pre_split_keypool.insert(nIndex);
1312 setExternalKeyPool.insert(nIndex);
1351 bool fRequestedInternal) {
1357 bool fReturningInternal = fRequestedInternal;
1358 fReturningInternal &=
1361 bool use_split_keypool = set_pre_split_keypool.empty();
1362 std::set<int64_t> &setKeyPool =
1364 ? (fReturningInternal ? setInternalKeyPool : setExternalKeyPool)
1365 : set_pre_split_keypool;
1368 if (setKeyPool.empty()) {
1374 auto it = setKeyPool.begin();
1376 setKeyPool.erase(it);
1377 if (!batch.
ReadPool(nIndex, keypool)) {
1378 throw std::runtime_error(std::string(__func__) +
": read failed");
1382 throw std::runtime_error(std::string(__func__) +
1383 ": unknown key in key pool");
1386 if (use_split_keypool && keypool.
fInternal != fReturningInternal) {
1387 throw std::runtime_error(std::string(__func__) +
1388 ": keypool entry misclassified");
1391 throw std::runtime_error(std::string(__func__) +
1392 ": keypool entry invalid");
1415 bool internal = setInternalKeyPool.count(keypool_id);
1417 assert(setExternalKeyPool.count(keypool_id) ||
1418 set_pre_split_keypool.count(keypool_id));
1421 std::set<int64_t> *setKeyPool =
1422 internal ? &setInternalKeyPool
1423 : (set_pre_split_keypool.empty() ? &setExternalKeyPool
1424 : &set_pre_split_keypool);
1425 auto it = setKeyPool->begin();
1428 while (it != std::end(*setKeyPool)) {
1429 const int64_t &index = *(it);
1430 if (index > keypool_id) {
1436 if (batch.
ReadPool(index, keypool)) {
1443 it = setKeyPool->erase(it);
1449 std::vector<CScript> dummy;
1453 std::vector<CKeyID> ret;
1454 for (
const auto &entry : out.
pubkeys) {
1455 ret.push_back(entry.first);
1462 for (
auto it = setExternalKeyPool.begin();
1463 it != setExternalKeyPool.end();) {
1464 int64_t index = *it;
1466 if (!batch.
ReadPool(index, keypool)) {
1467 throw std::runtime_error(std::string(__func__) +
1468 ": read keypool entry failed");
1472 throw std::runtime_error(std::string(__func__) +
1473 ": writing modified keypool entry failed");
1475 set_pre_split_keypool.insert(index);
1476 it = setExternalKeyPool.erase(it);
1486 const CScript &redeemScript) {
1502 mapKeyMetadata[pubkey.
GetID()].key_origin.fingerprint);
1503 mapKeyMetadata[pubkey.
GetID()].key_origin.path = info.
path;
1504 mapKeyMetadata[pubkey.
GetID()].has_key_origin =
true;
1510 int64_t timestamp) {
1512 for (
const auto &entry : scripts) {
1523 if (timestamp > 0) {
1524 m_script_metadata[
CScriptID(entry)].nCreateTime = timestamp;
1527 if (timestamp > 0) {
1535 const std::map<CKeyID, CKey> &privkey_map,
const int64_t timestamp) {
1537 for (
const auto &entry : privkey_map) {
1538 const CKey &key = entry.second;
1540 const CKeyID &
id = entry.first;
1548 mapKeyMetadata[id].nCreateTime = timestamp;
1559 const std::vector<CKeyID> &ordered_pubkeys,
1560 const std::map<CKeyID, CPubKey> &pubkey_map,
1561 const std::map<
CKeyID, std::pair<CPubKey, KeyOriginInfo>> &key_origins,
1562 const bool add_keypool,
const bool internal,
const int64_t timestamp) {
1564 for (
const auto &entry : key_origins) {
1567 for (
const CKeyID &
id : ordered_pubkeys) {
1568 auto entry = pubkey_map.find(
id);
1569 if (entry == pubkey_map.end()) {
1572 const CPubKey &pubkey = entry->second;
1583 mapKeyMetadata[id].nCreateTime = timestamp;
1595 const std::set<CScript> &script_pub_keys,
const bool have_solving_data,
1596 const int64_t timestamp) {
1598 for (
const CScript &script : script_pub_keys) {
1599 if (!have_solving_data || !
IsMine(script)) {
1615 std::set<CKeyID> set_address;
1616 for (
const auto &mi : mapCryptedKeys) {
1617 set_address.insert(mi.first);
1626 std::string &
error) {
1631 error =
"No addresses available";
1637 assert(m_wallet_descriptor.descriptor->IsSingleType());
1638 std::optional<OutputType> desc_addr_type =
1639 m_wallet_descriptor.descriptor->GetOutputType();
1641 if (type != *desc_addr_type) {
1642 throw std::runtime_error(std::string(__func__) +
1643 ": Types are inconsistent");
1650 std::vector<CScript> scripts_temp;
1653 error =
"Error: Keypool ran out, please call keypoolrefill first";
1656 if (!m_wallet_descriptor.descriptor->ExpandFromCache(
1657 m_wallet_descriptor.next_index, m_wallet_descriptor.cache,
1658 scripts_temp, out_keys)) {
1660 error =
"Error: Keypool ran out, please call keypoolrefill first";
1664 std::optional<OutputType> out_script_type =
1665 m_wallet_descriptor.descriptor->GetOutputType();
1666 if (out_script_type && out_script_type == type) {
1669 throw std::runtime_error(
1670 std::string(__func__) +
1671 ": Types are inconsistent. Stored type does not match type of "
1672 "newly generated address");
1674 m_wallet_descriptor.next_index++;
1683 if (m_map_script_pub_keys.count(script) > 0) {
1692 if (!m_map_keys.empty()) {
1697 bool keyPass = m_map_crypted_keys.empty();
1698 bool keyFail =
false;
1699 for (
const auto &mi : m_map_crypted_keys) {
1700 const CPubKey &pubkey = mi.second.first;
1701 const std::vector<uint8_t> &crypted_secret = mi.second.second;
1703 if (!
DecryptKey(master_key, crypted_secret, pubkey, key)) {
1712 if (keyPass && keyFail) {
1713 LogPrintf(
"The wallet is probably corrupted: Some keys decrypt but not "
1715 throw std::runtime_error(
1716 "Error unlocking wallet: some keys decrypt but not all. Your "
1717 "wallet file may be corrupt.");
1719 if (keyFail || (!keyPass && !accept_no_keys)) {
1729 if (!m_map_crypted_keys.empty()) {
1733 for (
const KeyMap::value_type &key_in : m_map_keys) {
1734 const CKey &key = key_in.second;
1737 std::vector<uint8_t> crypted_secret;
1742 m_map_crypted_keys[pubkey.
GetID()] = make_pair(pubkey, crypted_secret);
1757 index = m_wallet_descriptor.next_index - 1;
1765 if (m_wallet_descriptor.next_index - 1 == index) {
1766 m_wallet_descriptor.next_index--;
1777 for (
auto key_pair : m_map_crypted_keys) {
1778 const CPubKey &pubkey = key_pair.second.first;
1779 const std::vector<uint8_t> &crypted_secret = key_pair.second.second;
1783 keys[pubkey.
GetID()] = key;
1792 unsigned int target_size;
1796 target_size = std::max(
1801 int32_t new_range_end =
1802 std::max(m_wallet_descriptor.next_index + int32_t(target_size),
1803 m_wallet_descriptor.range_end);
1807 if (!m_wallet_descriptor.descriptor->IsRange()) {
1809 m_wallet_descriptor.range_end = 1;
1810 m_wallet_descriptor.range_start = 0;
1820 std::vector<CScript> scripts_temp;
1823 if (!m_wallet_descriptor.descriptor->ExpandFromCache(
1824 i, m_wallet_descriptor.cache, scripts_temp, out_keys)) {
1825 if (!m_wallet_descriptor.descriptor->Expand(
1826 i, provider, scripts_temp, out_keys, &temp_cache)) {
1831 for (
const CScript &script : scripts_temp) {
1832 m_map_script_pub_keys[script] = i;
1834 for (
const auto &pk_pair : out_keys.
pubkeys) {
1835 const CPubKey &pubkey = pk_pair.second;
1836 if (m_map_pubkeys.count(pubkey) != 0) {
1843 m_map_pubkeys[pubkey] = i;
1846 for (
const auto &parent_xpub_pair :
1849 if (m_wallet_descriptor.cache.GetCachedParentExtPubKey(
1850 parent_xpub_pair.first, xpub)) {
1851 if (xpub != parent_xpub_pair.second) {
1852 throw std::runtime_error(
1853 std::string(__func__) +
1854 ": New cached parent xpub does not match already "
1855 "cached parent xpub");
1860 parent_xpub_pair.first)) {
1861 throw std::runtime_error(std::string(__func__) +
1862 ": writing cache item failed");
1864 m_wallet_descriptor.cache.CacheParentExtPubKey(
1865 parent_xpub_pair.first, parent_xpub_pair.second);
1867 for (
const auto &derived_xpub_map_pair :
1869 for (
const auto &derived_xpub_pair : derived_xpub_map_pair.second) {
1871 if (m_wallet_descriptor.cache.GetCachedDerivedExtPubKey(
1872 derived_xpub_map_pair.first, derived_xpub_pair.first,
1874 if (xpub != derived_xpub_pair.second) {
1875 throw std::runtime_error(
1876 std::string(__func__) +
1877 ": New cached derived xpub does not match already "
1878 "cached derived xpub");
1883 derived_xpub_pair.second,
id,
1884 derived_xpub_map_pair.first, derived_xpub_pair.first)) {
1885 throw std::runtime_error(std::string(__func__) +
1886 ": writing cache item failed");
1888 m_wallet_descriptor.cache.CacheDerivedExtPubKey(
1889 derived_xpub_map_pair.first, derived_xpub_pair.first,
1890 derived_xpub_pair.second);
1895 m_wallet_descriptor.range_end = new_range_end;
1908 int32_t index = m_map_script_pub_keys[script];
1909 if (index >= m_wallet_descriptor.next_index) {
1911 "mark all keypool items up to this item as used\n",
1913 m_wallet_descriptor.next_index = index + 1;
1927 throw std::runtime_error(std::string(__func__) +
1928 ": writing descriptor private key failed");
1939 if (m_map_keys.find(pubkey.
GetID()) != m_map_keys.end() ||
1940 m_map_crypted_keys.find(pubkey.
GetID()) != m_map_crypted_keys.end()) {
1949 std::vector<uint8_t> crypted_secret;
1952 pubkey.
GetHash(), crypted_secret)) {
1956 m_map_crypted_keys[pubkey.
GetID()] = make_pair(pubkey, crypted_secret);
1959 m_map_keys[pubkey.
GetID()] = key;
1970 if (m_wallet_descriptor.descriptor) {
1974 int64_t creation_time =
GetTime();
1979 std::string desc_prefix;
1980 std::string desc_suffix =
"/*)";
1981 switch (addr_type) {
1983 desc_prefix =
"pkh(" + xpub +
"/44'";
1987 assert(!desc_prefix.empty());
1991 desc_prefix +=
"/1'";
1993 desc_prefix +=
"/0'";
1996 std::string internal_path =
m_internal ?
"/1" :
"/0";
1997 std::string desc_str = desc_prefix +
"/0'" + internal_path + desc_suffix;
2002 std::unique_ptr<Descriptor> desc =
Parse(desc_str, keys,
error,
false);
2004 m_wallet_descriptor = w_desc;
2010 throw std::runtime_error(
2011 std::string(__func__) +
2012 ": writing descriptor master private key failed");
2015 throw std::runtime_error(std::string(__func__) +
2016 ": writing descriptor failed");
2028 return m_wallet_descriptor.descriptor->IsRange();
2036 return m_wallet_descriptor.descriptor->IsSingleType() &&
2037 m_wallet_descriptor.descriptor->IsRange() &&
2039 m_wallet_descriptor.next_index < m_wallet_descriptor.range_end);
2044 return m_map_keys.size() > 0 || m_map_crypted_keys.size() > 0;
2063 return m_wallet_descriptor.range_end - m_wallet_descriptor.next_index;
2068 return m_wallet_descriptor.creation_time;
2071 std::unique_ptr<FlatSigningProvider>
2073 bool include_private)
const {
2077 auto it = m_map_script_pub_keys.find(script);
2078 if (it == m_map_script_pub_keys.end()) {
2081 int32_t index = it->second;
2086 std::unique_ptr<FlatSigningProvider>
2091 auto it = m_map_pubkeys.find(pubkey);
2092 if (it == m_map_pubkeys.end()) {
2095 int32_t index = it->second;
2102 std::unique_ptr<FlatSigningProvider>
2104 bool include_private)
const {
2107 std::unique_ptr<FlatSigningProvider> out_keys =
2108 std::make_unique<FlatSigningProvider>();
2109 std::vector<CScript> scripts_temp;
2110 if (!m_wallet_descriptor.descriptor->ExpandFromCache(
2111 index, m_wallet_descriptor.cache, scripts_temp, *out_keys)) {
2118 m_wallet_descriptor.descriptor->ExpandPrivate(index, master_provider,
2125 std::unique_ptr<SigningProvider>
2137 SigHashType sighash, std::map<int, std::string> &input_errors)
const {
2138 std::unique_ptr<FlatSigningProvider> keys =
2139 std::make_unique<FlatSigningProvider>();
2140 for (
const auto &coin_pair : coins) {
2141 std::unique_ptr<FlatSigningProvider> coin_keys =
2146 *keys =
Merge(*keys, *coin_keys);
2155 std::string &str_sig)
const {
2156 std::unique_ptr<FlatSigningProvider> keys =
2163 if (!keys->GetKey(
ToKeyID(pkhash), key)) {
2176 bool bip32derivs)
const {
2177 for (
size_t i = 0; i < psbtx.
tx->vin.size(); ++i) {
2201 std::unique_ptr<FlatSigningProvider> keys =
2202 std::make_unique<FlatSigningProvider>();
2203 std::unique_ptr<FlatSigningProvider> script_keys =
2206 *keys =
Merge(*keys, *script_keys);
2209 script_keys = std::make_unique<FlatSigningProvider>();
2211 const CPubKey &pubkey = pk_pair.first;
2212 std::unique_ptr<FlatSigningProvider> pk_keys =
2215 *keys =
Merge(*keys, *pk_keys);
2221 psbtx, i, sighash_type);
2226 for (
size_t i = 0; i < psbtx.
tx->vout.size(); ++i) {
2227 std::unique_ptr<SigningProvider> keys =
2239 std::unique_ptr<CKeyMetadata>
2241 std::unique_ptr<SigningProvider> provider =
2246 if (provider->GetKeyOrigin(key_id, orig)) {
2248 std::unique_ptr<CKeyMetadata> meta =
2249 std::make_unique<CKeyMetadata>();
2250 meta->key_origin = orig;
2251 meta->has_key_origin =
true;
2252 meta->nCreateTime = m_wallet_descriptor.creation_time;
2261 std::string desc_str = m_wallet_descriptor.descriptor->ToString();
2264 .
Write((uint8_t *)desc_str.data(), desc_str.size())
2275 m_wallet_descriptor.cache = cache;
2276 for (int32_t i = m_wallet_descriptor.range_start;
2277 i < m_wallet_descriptor.range_end; ++i) {
2279 std::vector<CScript> scripts_temp;
2280 if (!m_wallet_descriptor.descriptor->ExpandFromCache(
2281 i, m_wallet_descriptor.cache, scripts_temp, out_keys)) {
2282 throw std::runtime_error(
2283 "Error: Unable to expand wallet descriptor from cache");
2286 for (
const CScript &script : scripts_temp) {
2287 if (m_map_script_pub_keys.count(script) != 0) {
2288 throw std::runtime_error(
2289 strprintf(
"Error: Already loaded script at index %d as "
2290 "being at index %d",
2291 i, m_map_script_pub_keys[script]));
2293 m_map_script_pub_keys[script] = i;
2295 for (
const auto &pk_pair : out_keys.
pubkeys) {
2296 const CPubKey &pubkey = pk_pair.second;
2297 if (m_map_pubkeys.count(pubkey) != 0) {
2304 m_map_pubkeys[pubkey] = i;
2312 m_map_keys[key_id] = key;
2318 const std::vector<uint8_t> &crypted_key) {
2320 if (!m_map_keys.empty()) {
2324 m_map_crypted_keys[key_id] = make_pair(pubkey, crypted_key);
2331 return m_wallet_descriptor.descriptor !=
nullptr &&
2333 m_wallet_descriptor.descriptor->ToString() ==
2341 throw std::runtime_error(std::string(__func__) +
2342 ": writing descriptor failed");
2347 return m_wallet_descriptor;
2352 std::vector<CScript> script_pub_keys;
2353 script_pub_keys.reserve(m_map_script_pub_keys.size());
2355 for (
auto const &script_pub_key : m_map_script_pub_keys) {
2356 script_pub_keys.push_back(script_pub_key.first);
2358 return script_pub_keys;
2366 throw std::runtime_error(std::string(__func__) +
": " +
error);
2369 m_map_pubkeys.clear();
2370 m_map_script_pub_keys.clear();
2372 m_wallet_descriptor = descriptor;
2379 error =
"can only update matching descriptor";
2383 if (descriptor.
range_start > m_wallet_descriptor.range_start ||
2384 descriptor.
range_end < m_wallet_descriptor.range_end) {
2386 error =
strprintf(
"new range must include current range = [%d,%d]",
2387 m_wallet_descriptor.range_start,
2388 m_wallet_descriptor.range_end - 1);
@ TOP
Top-level scriptPubKey.
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.
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
bool IsTestChain() const
If this chain is exclusively used for testing.
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 secp256k1 private key.
const uint8_t * begin() 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 uint8_t * end() 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.
A mutable version of CTransaction.
An encapsulated 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 SHA-256.
CSHA256 & Write(const uint8_t *data, size_t len)
void Finalize(uint8_t hash[OUTPUT_SIZE])
Serialized script, used inside transaction inputs and outputs.
A reference to a CScript: the Hash160 of its serialization (see script.h)
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
bool AddCryptedKey(const CKeyID &key_id, const CPubKey &pubkey, const std::vector< uint8_t > &crypted_key)
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)
TransactionError FillPSBT(PartiallySignedTransaction &psbt, SigHashType sighash_type=SigHashType().withForkId(), bool sign=true, bool bip32derivs=false) const override
Adds script and derivation path information to a PSBT, and optionally signs it.
bool TopUp(unsigned int size=0) override
Fills internal address pool.
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 SignTransaction(CMutableTransaction &tx, const std::map< COutPoint, Coin > &coins, SigHashType sighash, std::map< int, std::string > &input_errors) const override
Creates new signatures and adds them to the transaction.
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)
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.
bool IsHDEnabled() const override
bool CanGetAddresses(bool internal=false) const override
Returns true if the wallet can give out new addresses.
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)
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 AddCryptedKeyInner(const CPubKey &vchPubKey, const std::vector< uint8_t > &vchCryptedSecret)
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)
size_t KeypoolCountExternalKeys() const override
void ReturnDestination(int64_t index, bool internal, const CTxDestination &) override
void SetHDSeed(const CPubKey &key)
bool LoadCryptedKey(const CPubKey &vchPubKey, const std::vector< uint8_t > &vchCryptedSecret, bool checksum_valid)
Adds an encrypted key to the store, without saving it to disk (used by LoadWallet)
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
Returns true if the wallet can give out new addresses.
bool AddKeyPubKeyInner(const CKey &key, const CPubKey &pubkey)
void AddHDChain(const CHDChain &chain)
Set the HD chain model (chain child index counters) and writes it to the database.
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.
bool CanGenerateKeys() const
void LoadKeyPool(int64_t nIndex, const CKeyPool &keypool)
Load a keypool entry.
bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector< uint8_t > &vchCryptedSecret)
Adds an encrypted key to the store, and saves it to disk.
bool Upgrade(int prev_version, bilingual_str &error) override
Upgrades the wallet to the specified version.
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.
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 GetWatchPubKey(const CKeyID &address, CPubKey &pubkey_out) const
Fetches a pubkey from mapWatchKeys if it exists there.
TransactionError FillPSBT(PartiallySignedTransaction &psbt, SigHashType sighash_type=SigHashType().withForkId(), bool sign=true, bool bip32derivs=false) const override
Adds script and derivation path information to a PSBT, and optionally signs it.
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
bool SignTransaction(CMutableTransaction &tx, const std::map< COutPoint, Coin > &coins, SigHashType 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)
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.
Signature hash type wrapper class.
uint32_t getRawSigHashType() const
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 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 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)
bool WriteCryptedKey(const CPubKey &vchPubKey, const std::vector< uint8_t > &vchCryptedSecret, const CKeyMetadata &keyMeta)
bool WriteCryptedDescriptorKey(const uint256 &desc_id, const CPubKey &pubkey, const std::vector< uint8_t > &secret)
Descriptor with some wallet metadata.
std::shared_ptr< Descriptor > descriptor
virtual bool IsWalletFlagSet(uint64_t) const =0
virtual bool HasEncryptionKeys() const =0
virtual WalletDatabase & GetDatabase()=0
virtual bool IsLocked() const =0
virtual const CKeyingMaterial & GetEncryptionKey() const =0
virtual void UnsetBlankWalletFlag(WalletBatch &)=0
virtual void SetMinVersion(enum WalletFeature, WalletBatch *=nullptr, bool=false)=0
virtual bool CanSupportFeature(enum WalletFeature) const =0
virtual const CChainParams & GetChainParams() const =0
const Config & GetConfig()
bool DecryptKey(const CKeyingMaterial &vMasterKey, const std::vector< uint8_t > &vchCryptedSecret, const CPubKey &vchPubKey, CKey &key)
bool EncryptSecret(const CKeyingMaterial &vMasterKey, const CKeyingMaterial &vchPlaintext, const uint256 &nIV, std::vector< uint8_t > &vchCiphertext)
std::vector< uint8_t, secure_allocator< uint8_t > > 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.
isminetype
IsMine() return codes.
std::string EncodeDestination(const CTxDestination &dest, const Config &config)
std::string EncodeExtPubKey(const CExtPubKey &key)
bool MessageSign(const CKey &privkey, const std::string &message, std::string &signature)
Sign a message.
@ PRIVATE_KEY_NOT_AVAILABLE
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 PSBTInputSigned(const PSBTInput &input)
Checks whether a PSBTInput is already signed.
bool SignPSBTInput(const SigningProvider &provider, PartiallySignedTransaction &psbt, int index, SigHashType sighash, SignatureData *out_sigdata, bool use_dummy)
Signs a PSBTInput, verifying that all provided data matches what is being 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.
static const unsigned int MAX_SCRIPT_ELEMENT_SIZE
std::vector< uint8_t > valtype
static bool ExtractPubKey(const CScript &dest, CPubKey &pubKeyOut)
const uint32_t BIP32_HARDENED_KEY_LIMIT
Value for the first BIP 32 hardened derivation.
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.
std::vector< uint8_t > valtype
bool ProduceSignature(const SigningProvider &provider, const BaseSignatureCreator &creator, const CScript &fromPubKey, SignatureData &sigdata)
Produce a script signature using a generic signature creator.
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).
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.
TxoutType Solver(const CScript &scriptPubKey, std::vector< std::vector< uint8_t >> &vSolutionsRet)
Parse a scriptPubKey and identify script type for standard scripts.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
CKeyID ToKeyID(const PKHash &key_hash)
std::variant< CNoDestination, PKHash, ScriptHash > 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 uint8_t *seed, unsigned int nSeedLen)
std::map< CKeyID, CPubKey > pubkeys
std::map< CKeyID, CKey > keys
std::vector< uint32_t > path
uint8_t fingerprint[4]
First 32 bits of the Hash160 of the public key at the root of the 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.
bool error(const char *fmt, const Args &...args)
bilingual_str _(const char *psz)
Translation function.
@ 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