mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-10 10:52:31 -05:00
Implement writing descriptorkeys, descriptorckeys, and descriptors to wallet file
This commit is contained in:
parent
4cb9b69be0
commit
46dfb99768
4 changed files with 56 additions and 0 deletions
|
@ -1553,6 +1553,30 @@ void DescriptorScriptPubKeyMan::MarkUnusedAddresses(const CScript& script)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DescriptorScriptPubKeyMan::AddDescriptorKeyWithDB(WalletBatch& batch, const CKey& key, const CPubKey &pubkey)
|
||||||
|
{
|
||||||
|
AssertLockHeld(cs_desc_man);
|
||||||
|
assert(!m_storage.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS));
|
||||||
|
|
||||||
|
if (m_storage.HasEncryptionKeys()) {
|
||||||
|
if (m_storage.IsLocked()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<unsigned char> crypted_secret;
|
||||||
|
CKeyingMaterial secret(key.begin(), key.end());
|
||||||
|
if (!EncryptSecret(m_storage.GetEncryptionKey(), secret, pubkey.GetHash(), crypted_secret)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_map_crypted_keys[pubkey.GetID()] = make_pair(pubkey, crypted_secret);
|
||||||
|
return batch.WriteCryptedDescriptorKey(GetID(), pubkey, crypted_secret);
|
||||||
|
} else {
|
||||||
|
m_map_keys[pubkey.GetID()] = key;
|
||||||
|
return batch.WriteDescriptorKey(GetID(), pubkey, key.GetPrivKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool DescriptorScriptPubKeyMan::IsHDEnabled() const
|
bool DescriptorScriptPubKeyMan::IsHDEnabled() const
|
||||||
{
|
{
|
||||||
LOCK(cs_desc_man);
|
LOCK(cs_desc_man);
|
||||||
|
|
|
@ -503,6 +503,8 @@ private:
|
||||||
|
|
||||||
//! keeps track of whether Unlock has run a thorough check before
|
//! keeps track of whether Unlock has run a thorough check before
|
||||||
bool m_decryption_thoroughly_checked = false;
|
bool m_decryption_thoroughly_checked = false;
|
||||||
|
|
||||||
|
bool AddDescriptorKeyWithDB(WalletBatch& batch, const CKey& key, const CPubKey &pubkey);
|
||||||
public:
|
public:
|
||||||
DescriptorScriptPubKeyMan(WalletStorage& storage, WalletDescriptor& descriptor)
|
DescriptorScriptPubKeyMan(WalletStorage& storage, WalletDescriptor& descriptor)
|
||||||
: ScriptPubKeyMan(storage),
|
: ScriptPubKeyMan(storage),
|
||||||
|
|
|
@ -191,6 +191,31 @@ bool WalletBatch::WriteActiveScriptPubKeyMan(uint8_t type, const uint256& id, bo
|
||||||
return WriteIC(make_pair(key, type), id);
|
return WriteIC(make_pair(key, type), id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool WalletBatch::WriteDescriptorKey(const uint256& desc_id, const CPubKey& pubkey, const CPrivKey& privkey)
|
||||||
|
{
|
||||||
|
// hash pubkey/privkey to accelerate wallet load
|
||||||
|
std::vector<unsigned char> key;
|
||||||
|
key.reserve(pubkey.size() + privkey.size());
|
||||||
|
key.insert(key.end(), pubkey.begin(), pubkey.end());
|
||||||
|
key.insert(key.end(), privkey.begin(), privkey.end());
|
||||||
|
|
||||||
|
return WriteIC(std::make_pair(DBKeys::WALLETDESCRIPTORKEY, std::make_pair(desc_id, pubkey)), std::make_pair(privkey, Hash(key.begin(), key.end())), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WalletBatch::WriteCryptedDescriptorKey(const uint256& desc_id, const CPubKey& pubkey, const std::vector<unsigned char>& secret)
|
||||||
|
{
|
||||||
|
if (!WriteIC(std::make_pair(DBKeys::WALLETDESCRIPTORCKEY, std::make_pair(desc_id, pubkey)), secret, false)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
EraseIC(std::make_pair(DBKeys::WALLETDESCRIPTORKEY, std::make_pair(desc_id, pubkey)));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WalletBatch::WriteDescriptor(const uint256& desc_id, const WalletDescriptor& descriptor)
|
||||||
|
{
|
||||||
|
return WriteIC(make_pair(DBKeys::WALLETDESCRIPTOR, desc_id), descriptor);
|
||||||
|
}
|
||||||
|
|
||||||
class CWalletScanState {
|
class CWalletScanState {
|
||||||
public:
|
public:
|
||||||
unsigned int nKeys{0};
|
unsigned int nKeys{0};
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <amount.h>
|
#include <amount.h>
|
||||||
#include <script/sign.h>
|
#include <script/sign.h>
|
||||||
#include <wallet/db.h>
|
#include <wallet/db.h>
|
||||||
|
#include <wallet/walletutil.h>
|
||||||
#include <key.h>
|
#include <key.h>
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
@ -245,6 +246,10 @@ public:
|
||||||
|
|
||||||
bool WriteMinVersion(int nVersion);
|
bool WriteMinVersion(int nVersion);
|
||||||
|
|
||||||
|
bool WriteDescriptorKey(const uint256& desc_id, const CPubKey& pubkey, const CPrivKey& privkey);
|
||||||
|
bool WriteCryptedDescriptorKey(const uint256& desc_id, const CPubKey& pubkey, const std::vector<unsigned char>& secret);
|
||||||
|
bool WriteDescriptor(const uint256& desc_id, const WalletDescriptor& descriptor);
|
||||||
|
|
||||||
/// Write destination data key,value tuple to database
|
/// Write destination data key,value tuple to database
|
||||||
bool WriteDestData(const std::string &address, const std::string &key, const std::string &value);
|
bool WriteDestData(const std::string &address, const std::string &key, const std::string &value);
|
||||||
/// Erase destination data tuple from wallet database
|
/// Erase destination data tuple from wallet database
|
||||||
|
|
Loading…
Add table
Reference in a new issue