6 #ifndef BITCOIN_WALLET_WALLETDB_H
7 #define BITCOIN_WALLET_WALLETDB_H
60 extern const std::string
ACENTRY;
66 extern const std::string
CSCRIPT;
69 extern const std::string
FLAGS;
70 extern const std::string
HDCHAIN;
71 extern const std::string
KEY;
72 extern const std::string
KEYMETA;
76 extern const std::string
NAME;
77 extern const std::string
OLD_KEY;
79 extern const std::string
POOL;
80 extern const std::string
PURPOSE;
82 extern const std::string
TX;
83 extern const std::string
VERSION;
88 extern const std::string
WATCHS;
91 extern const std::unordered_set<std::string>
LEGACY_TYPES;
113 READWRITE(obj.nVersion, obj.nExternalChainCounter, obj.seed_id);
159 READWRITE(obj.nVersion, obj.nCreateTime);
161 READWRITE(obj.hdKeypath, obj.hd_seed_id);
191 template <
typename K,
typename T>
192 bool WriteIC(
const K& key,
const T& value,
bool fOverwrite =
true)
194 if (!
m_batch->Write(key, value, fOverwrite)) {
204 template <
typename K>
219 m_batch(database.MakeBatch(_fFlushOnClose)),
226 bool WriteName(
const std::string& strAddress,
const std::string& strName);
227 bool EraseName(
const std::string& strAddress);
229 bool WritePurpose(
const std::string& strAddress,
const std::string& purpose);
268 bool WriteDestData(
const std::string &address,
const std::string &key,
const std::string &value);
270 bool EraseDestData(
const std::string &address,
const std::string &key);
279 static bool IsKeyType(
const std::string& strType);
285 bool EraseRecords(
const std::unordered_set<std::string>& types);
A reference to a CKey: the Hash160 of its serialized public key.
An outpoint - a combination of a transaction hash and an index n into its vout.
An encapsulated public key.
Serialized script, used inside transaction inputs and outputs.
Double ended buffer combining vector and stream-like interfaces.
Cache for single descriptor's derived extended pubkeys.
SERIALIZE_METHODS(CHDChain, obj)
uint32_t nInternalChainCounter
static const int VERSION_HD_BASE
uint32_t nExternalChainCounter
int64_t m_next_external_index
static const int VERSION_HD_CHAIN_SPLIT
CKeyID seed_id
seed hash160
bool operator==(const CHDChain &chain) const
int64_t m_next_internal_index
static const int CURRENT_VERSION
A key from a CWallet's keypool.
Private key encryption is done based on a CMasterKey, which holds a salt and random encryption key.
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
A transaction with a bunch of additional info that only the owner cares about.
Access to the wallet database.
bool WriteDescriptor(const uint256 &desc_id, const WalletDescriptor &descriptor)
bool TxnAbort()
Abort current transaction.
bool WriteDescriptorParentCache(const CExtPubKey &xpub, const uint256 &desc_id, uint32_t key_exp_index)
bool EraseName(const std::string &strAddress)
DBErrors LoadWallet(CWallet *pwallet)
bool WriteBestBlock(const CBlockLocator &locator)
bool ReadBestBlock(CBlockLocator &locator)
bool WriteDescriptorCacheItems(const uint256 &desc_id, const DescriptorCache &cache)
bool EraseTx(uint256 hash)
bool WriteHDChain(const CHDChain &chain)
write the hdchain model (external chain child index counter)
bool WriteMasterKey(unsigned int nID, const CMasterKey &kMasterKey)
bool WriteMinVersion(int nVersion)
bool WriteWatchOnly(const CScript &script, const CKeyMetadata &keymeta)
bool TxnBegin()
Begin a new transaction.
static bool IsKeyType(const std::string &strType)
bool TxnCommit()
Commit current transaction.
bool WriteName(const std::string &strAddress, const std::string &strName)
bool WritePurpose(const std::string &strAddress, const std::string &purpose)
std::unique_ptr< DatabaseBatch > m_batch
bool EraseRecords(const std::unordered_set< std::string > &types)
Delete records of the given types.
WalletBatch(const WalletBatch &)=delete
bool WriteWalletFlags(const uint64_t flags)
bool WriteKeyMetadata(const CKeyMetadata &meta, const CPubKey &pubkey, const bool overwrite)
bool WriteDescriptorLastHardenedCache(const CExtPubKey &xpub, const uint256 &desc_id, uint32_t key_exp_index)
bool WriteIC(const K &key, const T &value, bool fOverwrite=true)
bool WriteOrderPosNext(int64_t nOrderPosNext)
WalletDatabase & m_database
bool WriteTx(const CWalletTx &wtx)
bool WriteKey(const CPubKey &vchPubKey, const CPrivKey &vchPrivKey, const CKeyMetadata &keyMeta)
bool ReadPool(int64_t nPool, CKeyPool &keypool)
bool EraseIC(const K &key)
bool WriteCryptedKey(const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret, const CKeyMetadata &keyMeta)
bool ErasePurpose(const std::string &strAddress)
bool EraseLockedUTXO(const COutPoint &output)
WalletBatch(WalletDatabase &database, bool _fFlushOnClose=true)
bool WriteDestData(const std::string &address, const std::string &key, const std::string &value)
Write destination data key,value tuple to database.
bool WriteDescriptorDerivedCache(const CExtPubKey &xpub, const uint256 &desc_id, uint32_t key_exp_index, uint32_t der_index)
WalletBatch & operator=(const WalletBatch &)=delete
bool WriteCryptedDescriptorKey(const uint256 &desc_id, const CPubKey &pubkey, const std::vector< unsigned char > &secret)
bool WriteLockedUTXO(const COutPoint &output)
bool EraseDestData(const std::string &address, const std::string &key)
Erase destination data tuple from wallet database.
bool WriteActiveScriptPubKeyMan(uint8_t type, const uint256 &id, bool internal)
bool EraseActiveScriptPubKeyMan(uint8_t type, bool internal)
bool WritePool(int64_t nPool, const CKeyPool &keypool)
DBErrors FindWalletTxHashes(std::vector< uint256 > &tx_hashes)
bool WriteDescriptorKey(const uint256 &desc_id, const CPubKey &pubkey, const CPrivKey &privkey)
bool WriteCScript(const uint160 &hash, const CScript &redeemScript)
bool ErasePool(int64_t nPool)
DBErrors ZapSelectTx(std::vector< uint256 > &vHashIn, std::vector< uint256 > &vHashOut)
bool EraseWatchOnly(const CScript &script)
An instance of this class represents one database.
virtual void IncrementUpdateCounter()=0
std::atomic< unsigned int > nUpdateCounter
Descriptor with some wallet metadata.
std::vector< unsigned char, secure_allocator< unsigned char > > CPrivKey
CPrivKey is a serialized private key, with all parameters included (SIZE bytes)
const std::string BESTBLOCK
const std::string WALLETDESCRIPTORCKEY
const std::string MINVERSION
const std::string WATCHMETA
const std::string DEFAULTKEY
const std::string OLD_KEY
const std::string WALLETDESCRIPTORKEY
const std::string ACENTRY
const std::string ACTIVEEXTERNALSPK
const std::string CRYPTED_KEY
const std::string DESTDATA
const std::string CSCRIPT
const std::unordered_set< std::string > LEGACY_TYPES
const std::string SETTINGS
const std::string BESTBLOCK_NOMERKLE
const std::string LOCKED_UTXO
const std::string ACTIVEINTERNALSPK
const std::string HDCHAIN
const std::string ORDERPOSNEXT
const std::string VERSION
const std::string MASTER_KEY
const std::string KEYMETA
const std::string PURPOSE
const std::string WALLETDESCRIPTOR
DBErrors
Error statuses for the wallet database.
@ UNEXPECTED_LEGACY_ENTRY
@ EXTERNAL_SIGNER_SUPPORT_REQUIRED
std::unique_ptr< WalletDatabase > CreateMockWalletDatabase(DatabaseOptions &options)
Return object for accessing temporary in-memory database.
void MaybeCompactWalletDB(WalletContext &context)
Compacts BDB state so that wallet.dat is self-contained (if there are changes)
std::function< bool(const std::string &)> KeyFilterFn
Callback for filtering key types to deserialize in ReadKeyValue.
static bool ReadKeyValue(CWallet *pwallet, DataStream &ssKey, CDataStream &ssValue, CWalletScanState &wss, std::string &strType, std::string &strErr, const KeyFilterFn &filter_fn=nullptr) EXCLUSIVE_LOCKS_REQUIRED(pwallet -> cs_wallet)
std::unique_ptr< WalletDatabase > CreateDummyWalletDatabase()
Return object for accessing dummy database with no read/write capabilities.
static const bool DEFAULT_FLUSHWALLET
Overview of wallet database classes:
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
WalletContext struct containing references to state shared between CWallet instances,...