6 #ifndef BITCOIN_WALLET_WALLETDB_H 7 #define BITCOIN_WALLET_WALLETDB_H 54 extern const std::string
ACENTRY;
60 extern const std::string
CSCRIPT;
63 extern const std::string
FLAGS;
64 extern const std::string
HDCHAIN;
65 extern const std::string
KEY;
66 extern const std::string
KEYMETA;
69 extern const std::string
NAME;
70 extern const std::string
OLD_KEY;
72 extern const std::string
POOL;
73 extern const std::string
PURPOSE;
75 extern const std::string
TX;
76 extern const std::string
VERSION;
81 extern const std::string
WATCHS;
92 static const int VERSION_HD_BASE = 1;
93 static const int VERSION_HD_CHAIN_SPLIT = 2;
94 static const int CURRENT_VERSION = VERSION_HD_CHAIN_SPLIT;
101 READWRITE(obj.nVersion, obj.nExternalChainCounter, obj.seed_id);
102 if (obj.nVersion >= VERSION_HD_CHAIN_SPLIT) {
110 nExternalChainCounter = 0;
111 nInternalChainCounter = 0;
117 return seed_id == chain.
seed_id;
124 static const int VERSION_BASIC=1;
125 static const int VERSION_WITH_HDDATA=10;
126 static const int VERSION_WITH_KEY_ORIGIN = 12;
127 static const int CURRENT_VERSION=VERSION_WITH_KEY_ORIGIN;
133 bool has_key_origin =
false;
142 nCreateTime = nCreateTime_;
147 READWRITE(obj.nVersion, obj.nCreateTime);
148 if (obj.nVersion >= VERSION_WITH_HDDATA) {
149 READWRITE(obj.hdKeypath, obj.hd_seed_id);
151 if (obj.nVersion >= VERSION_WITH_KEY_ORIGIN)
165 has_key_origin =
false;
179 template <
typename K,
typename T>
180 bool WriteIC(
const K& key,
const T& value,
bool fOverwrite =
true)
182 if (!m_batch->Write(key, value, fOverwrite)) {
185 m_database.IncrementUpdateCounter();
186 if (m_database.nUpdateCounter % 1000 == 0) {
192 template <
typename K>
195 if (!m_batch->Erase(key)) {
198 m_database.IncrementUpdateCounter();
199 if (m_database.nUpdateCounter % 1000 == 0) {
207 m_batch(database.MakeBatch(_fFlushOnClose)),
214 bool WriteName(
const std::string& strAddress,
const std::string& strName);
215 bool EraseName(
const std::string& strAddress);
217 bool WritePurpose(
const std::string& strAddress,
const std::string& purpose);
218 bool ErasePurpose(
const std::string& strAddress);
223 bool WriteKeyMetadata(
const CKeyMetadata& meta,
const CPubKey& pubkey,
const bool overwrite);
225 bool WriteCryptedKey(
const CPubKey& vchPubKey,
const std::vector<unsigned char>& vchCryptedSecret,
const CKeyMetadata &keyMeta);
226 bool WriteMasterKey(
unsigned int nID,
const CMasterKey& kMasterKey);
228 bool WriteCScript(
const uint160& hash,
const CScript& redeemScript);
231 bool EraseWatchOnly(
const CScript &script);
236 bool WriteOrderPosNext(int64_t nOrderPosNext);
238 bool ReadPool(int64_t nPool,
CKeyPool& keypool);
239 bool WritePool(int64_t nPool,
const CKeyPool& keypool);
240 bool ErasePool(int64_t nPool);
242 bool WriteMinVersion(
int nVersion);
245 bool WriteCryptedDescriptorKey(
const uint256& desc_id,
const CPubKey& pubkey,
const std::vector<unsigned char>& secret);
247 bool WriteDescriptorDerivedCache(
const CExtPubKey& xpub,
const uint256& desc_id, uint32_t key_exp_index, uint32_t der_index);
248 bool WriteDescriptorParentCache(
const CExtPubKey& xpub,
const uint256& desc_id, uint32_t key_exp_index);
251 bool WriteDestData(
const std::string &address,
const std::string &key,
const std::string &value);
253 bool EraseDestData(
const std::string &address,
const std::string &key);
255 bool WriteActiveScriptPubKeyMan(uint8_t type,
const uint256&
id,
bool internal);
258 DBErrors FindWalletTx(std::vector<uint256>& vTxHash, std::list<CWalletTx>& vWtx);
259 DBErrors ZapSelectTx(std::vector<uint256>& vHashIn, std::vector<uint256>& vHashOut);
261 static bool IsKeyType(
const std::string& strType);
264 bool WriteHDChain(
const CHDChain& chain);
266 bool WriteWalletFlags(
const uint64_t
flags);
293 #endif // BITCOIN_WALLET_WALLETDB_H static const int CURRENT_VERSION
bool EraseIC(const K &key)
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
bool operator==(const CHDChain &chain) const
const std::string SETTINGS
const std::string WALLETDESCRIPTORCKEY
WalletBatch(WalletDatabase &database, bool _fFlushOnClose=true)
const std::string CRYPTED_KEY
bool WriteIC(const K &key, const T &value, bool fOverwrite=true)
const std::string DEFAULTKEY
Private key encryption is done based on a CMasterKey, which holds a salt and random encryption key...
const std::string KEYMETA
uint32_t nExternalChainCounter
Double ended buffer combining vector and stream-like interfaces.
std::shared_ptr< CWallet > LoadWallet(interfaces::Chain &chain, const std::string &name, Optional< bool > load_on_start, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error, std::vector< bilingual_str > &warnings)
DBErrors
Error statuses for the wallet database.
const std::string ORDERPOSNEXT
const std::string MASTER_KEY
Access to the wallet database.
std::vector< unsigned char, secure_allocator< unsigned char > > CPrivKey
secure_allocator is defined in allocators.h CPrivKey is a serialized private key, with all parameters...
const std::string OLD_KEY
std::unique_ptr< WalletDatabase > CreateMockWalletDatabase()
Return object for accessing temporary in-memory database.
const std::string HDCHAIN
const std::string WALLETDESCRIPTOR
std::unique_ptr< DatabaseBatch > m_batch
const std::string ACTIVEINTERNALSPK
WalletDatabase & m_database
void MaybeCompactWalletDB()
Compacts BDB state so that wallet.dat is self-contained (if there are changes)
An encapsulated public key.
const std::string WATCHMETA
const std::string WALLETDESCRIPTORKEY
const std::string DESTDATA
Descriptor with some wallet metadata.
std::unique_ptr< WalletDatabase > CreateDummyWalletDatabase()
Return object for accessing dummy database with no read/write capabilities.
A transaction with a bunch of additional info that only the owner cares about.
SERIALIZE_METHODS(CHDChain, obj)
const std::string ACENTRY
Serialized script, used inside transaction inputs and outputs.
const std::string MINVERSION
static const bool DEFAULT_FLUSHWALLET
Overview of wallet database classes:
A reference to a CKey: the Hash160 of its serialized public key.
const std::string ACTIVEEXTERNALSPK
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
const char * TX
The tx message transmits a single transaction.
const std::string BESTBLOCK
const std::string CSCRIPT
bool ReadKeyValue(CWallet *pwallet, CDataStream &ssKey, CDataStream &ssValue, std::string &strType, std::string &strErr, const KeyFilterFn &filter_fn=nullptr)
Unserialize a given Key-Value pair and load it into the wallet.
CKeyID seed_id
seed hash160
std::function< bool(const std::string &)> KeyFilterFn
Callback for filtering key types to deserialize in ReadKeyValue.
const std::string BESTBLOCK_NOMERKLE
uint32_t nInternalChainCounter
A key from a CWallet's keypool.
const std::string PURPOSE
An instance of this class represents one database.