@@ -1680,6 +1680,15 @@ bool DescriptorScriptPubKeyMan::TopUp(unsigned int size)
1680
1680
for (const CScript& script : scripts_temp) {
1681
1681
m_map_script_pub_keys[script] = i;
1682
1682
}
1683
+ for (const auto & pk_pair : out_keys.pubkeys ) {
1684
+ const CPubKey& pubkey = pk_pair.second ;
1685
+ if (m_map_pubkeys.count (pubkey) != 0 ) {
1686
+ // We don't need to give an error here.
1687
+ // It doesn't matter which of many valid indexes the pubkey has, we just need an index where we can derive it and it's private key
1688
+ continue ;
1689
+ }
1690
+ m_map_pubkeys[pubkey] = i;
1691
+ }
1683
1692
// Write the cache
1684
1693
for (const auto & parent_xpub_pair : temp_cache.GetCachedParentExtPubKeys ()) {
1685
1694
CExtPubKey xpub;
@@ -1876,9 +1885,55 @@ int64_t DescriptorScriptPubKeyMan::GetTimeFirstKey() const
1876
1885
return m_wallet_descriptor.creation_time ;
1877
1886
}
1878
1887
1888
+ std::unique_ptr<FlatSigningProvider> DescriptorScriptPubKeyMan::GetSigningProvider (const CScript& script, bool include_private) const
1889
+ {
1890
+ LOCK (cs_desc_man);
1891
+
1892
+ // Find the index of the script
1893
+ auto it = m_map_script_pub_keys.find (script);
1894
+ if (it == m_map_script_pub_keys.end ()) {
1895
+ return nullptr ;
1896
+ }
1897
+ int32_t index = it->second ;
1898
+
1899
+ return GetSigningProvider (index, include_private);
1900
+ }
1901
+
1902
+ std::unique_ptr<FlatSigningProvider> DescriptorScriptPubKeyMan::GetSigningProvider (const CPubKey& pubkey) const
1903
+ {
1904
+ LOCK (cs_desc_man);
1905
+
1906
+ // Find index of the pubkey
1907
+ auto it = m_map_pubkeys.find (pubkey);
1908
+ if (it == m_map_pubkeys.end ()) {
1909
+ return nullptr ;
1910
+ }
1911
+ int32_t index = it->second ;
1912
+
1913
+ // Always try to get the signing provider with private keys. This function should only be called during signing anyways
1914
+ return GetSigningProvider (index, true );
1915
+ }
1916
+
1917
+ std::unique_ptr<FlatSigningProvider> DescriptorScriptPubKeyMan::GetSigningProvider (int32_t index, bool include_private) const
1918
+ {
1919
+ AssertLockHeld (cs_desc_man);
1920
+ // Get the scripts, keys, and key origins for this script
1921
+ std::unique_ptr<FlatSigningProvider> out_keys = MakeUnique<FlatSigningProvider>();
1922
+ std::vector<CScript> scripts_temp;
1923
+ if (!m_wallet_descriptor.descriptor ->ExpandFromCache (index, m_wallet_descriptor.cache , scripts_temp, *out_keys)) return nullptr ;
1924
+
1925
+ if (HavePrivateKeys () && include_private) {
1926
+ FlatSigningProvider master_provider;
1927
+ master_provider.keys = GetKeys ();
1928
+ m_wallet_descriptor.descriptor ->ExpandPrivate (index, master_provider, *out_keys);
1929
+ }
1930
+
1931
+ return out_keys;
1932
+ }
1933
+
1879
1934
std::unique_ptr<SigningProvider> DescriptorScriptPubKeyMan::GetSolvingProvider (const CScript& script) const
1880
1935
{
1881
- return nullptr ;
1936
+ return GetSigningProvider (script, false ) ;
1882
1937
}
1883
1938
1884
1939
bool DescriptorScriptPubKeyMan::CanProvide (const CScript& script, SignatureData& sigdata)
@@ -1938,6 +1993,15 @@ void DescriptorScriptPubKeyMan::SetCache(const DescriptorCache& cache)
1938
1993
}
1939
1994
m_map_script_pub_keys[script] = i;
1940
1995
}
1996
+ for (const auto & pk_pair : out_keys.pubkeys ) {
1997
+ const CPubKey& pubkey = pk_pair.second ;
1998
+ if (m_map_pubkeys.count (pubkey) != 0 ) {
1999
+ // We don't need to give an error here.
2000
+ // It doesn't matter which of many valid indexes the pubkey has, we just need an index where we can derive it and it's private key
2001
+ continue ;
2002
+ }
2003
+ m_map_pubkeys[pubkey] = i;
2004
+ }
1941
2005
m_max_cached_index++;
1942
2006
}
1943
2007
}
0 commit comments