7 #ifndef BITCOIN_WALLET_WALLETDB_H 8 #define BITCOIN_WALLET_WALLETDB_H 59 extern const std::string
ACENTRY;
65 extern const std::string
CSCRIPT;
68 extern const std::string
FLAGS;
69 extern const std::string
HDCHAIN;
70 extern const std::string
KEY;
71 extern const std::string
KEYMETA;
74 extern const std::string
NAME;
75 extern const std::string
OLD_KEY;
77 extern const std::string
POOL;
78 extern const std::string
PURPOSE;
80 extern const std::string
TX;
81 extern const std::string
VERSION;
87 extern const std::string
WATCHS;
98 static const int VERSION_HD_BASE = 1;
99 static const int VERSION_HD_CHAIN_SPLIT = 2;
100 static const int CURRENT_VERSION = VERSION_HD_CHAIN_SPLIT;
105 template <
typename Stream,
typename Operation>
110 if (this->nVersion >= VERSION_HD_CHAIN_SPLIT) {
117 nExternalChainCounter = 0;
118 nInternalChainCounter = 0;
125 static const int VERSION_BASIC = 1;
126 static const int VERSION_WITH_HDDATA = 10;
127 static const int VERSION_WITH_KEY_ORIGIN = 12;
128 static const int CURRENT_VERSION = VERSION_WITH_KEY_ORIGIN;
140 bool has_key_origin =
false;
145 nCreateTime = nCreateTime_;
150 template <
typename Stream,
typename Operation>
154 if (this->nVersion >= VERSION_WITH_HDDATA) {
158 if (this->nVersion >= VERSION_WITH_KEY_ORIGIN) {
170 has_key_origin =
false;
185 template <
typename K,
typename T>
186 bool WriteIC(
const K &key,
const T &value,
bool fOverwrite =
true) {
187 if (!m_batch.Write(key, value, fOverwrite)) {
190 m_database.IncrementUpdateCounter();
191 if (m_database.nUpdateCounter % 1000 == 0) {
197 template <
typename K>
bool EraseIC(
const K &key) {
198 if (!m_batch.Erase(key)) {
201 m_database.IncrementUpdateCounter();
202 if (m_database.nUpdateCounter % 1000 == 0) {
210 bool _fFlushOnClose =
true)
211 : m_batch(database, pszMode, _fFlushOnClose), m_database(database) {}
215 bool WriteName(
const CTxDestination &address,
const std::string &strName);
219 const std::string &purpose);
226 const bool overwrite);
229 bool WriteCryptedKey(
const CPubKey &vchPubKey,
230 const std::vector<uint8_t> &vchCryptedSecret,
232 bool WriteMasterKey(
unsigned int nID,
const CMasterKey &kMasterKey);
234 bool WriteCScript(
const uint160 &hash,
const CScript &redeemScript);
237 bool EraseWatchOnly(
const CScript &script);
242 bool WriteOrderPosNext(int64_t nOrderPosNext);
244 bool ReadPool(int64_t nPool,
CKeyPool &keypool);
245 bool WritePool(int64_t nPool,
const CKeyPool &keypool);
246 bool ErasePool(int64_t nPool);
248 bool WriteMinVersion(
int nVersion);
250 bool WriteDescriptorKey(
const uint256 &desc_id,
const CPubKey &pubkey,
252 bool WriteCryptedDescriptorKey(
const uint256 &desc_id,
254 const std::vector<uint8_t> &secret);
255 bool WriteDescriptor(
const uint256 &desc_id,
257 bool WriteDescriptorDerivedCache(
const CExtPubKey &xpub,
259 uint32_t key_exp_index,
261 bool WriteDescriptorParentCache(
const CExtPubKey &xpub,
263 uint32_t key_exp_index);
266 bool WriteDestData(
const CTxDestination &address,
const std::string &key,
267 const std::string &value);
269 bool EraseDestData(
const CTxDestination &address,
const std::string &key);
271 bool WriteActiveScriptPubKeyMan(uint8_t type,
const uint256 &
id,
275 DBErrors FindWalletTx(std::vector<TxId> &txIds,
276 std::vector<CWalletTx> &vWtx);
277 DBErrors ZapWalletTx(std::vector<CWalletTx> &vWtx);
278 DBErrors ZapSelectTx(std::vector<TxId> &txIdsIn,
279 std::vector<TxId> &txIdsOut);
282 static bool IsKeyType(
const std::string &strType);
284 static bool VerifyEnvironment(
const fs::path &wallet_path,
287 static bool VerifyDatabaseFile(
const fs::path &wallet_path,
291 bool WriteHDChain(
const CHDChain &chain);
293 bool WriteWalletFlags(
const uint64_t
flags);
312 std::string &strType, std::string &strErr);
317 #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 IsWalletLoaded(const fs::path &wallet_path)
Return whether a wallet database is currently loaded.
const std::string SETTINGS
const std::string WALLETDESCRIPTORCKEY
const std::string CRYPTED_KEY
bool WriteIC(const K &key, const T &value, bool fOverwrite=true)
const std::string DEFAULTKEY
std::shared_ptr< CWallet > LoadWallet(const CChainParams &chainParams, interfaces::Chain &chain, const std::string &name, bilingual_str &error, std::vector< bilingual_str > &warnings)
Private key encryption is done based on a CMasterKey, which holds a salt and random encryption key...
const std::string KEYMETA
An instance of this class represents one database.
uint32_t nExternalChainCounter
Double ended buffer combining vector and stream-like interfaces.
WalletBatch(WalletDatabase &database, const char *pszMode="r+", bool _fFlushOnClose=true)
DBErrors
Error statuses for the wallet database.
const std::string ORDERPOSNEXT
const std::string MASTER_KEY
std::vector< uint8_t, secure_allocator< uint8_t > > CPrivKey
secure_allocator is defined in allocators.h CPrivKey is a serialized private key, with all parameters...
void SerializationOp(Stream &s, Operation ser_action)
Access to the wallet database.
const std::string OLD_KEY
const std::string HDCHAIN
const std::string WALLETDESCRIPTOR
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
RAII class that provides access to a Berkeley database.
const std::string WALLETDESCRIPTORKEY
const std::string DESTDATA
Descriptor with some wallet metadata.
A transaction with a bunch of additional info that only the owner cares about.
const std::string WALLETDESCRIPTORCACHE
const std::string ACENTRY
const char * VERSION
The version message provides information about the transmitting node to the receiving node at the beg...
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...
bool ReadKeyValue(CWallet *pwallet, CDataStream &ssKey, CDataStream &ssValue, std::string &strType, std::string &strErr)
Unserialize a given Key-Value pair and load it into the wallet.
const char * TX
The tx message transmits a single transaction.
const std::string BESTBLOCK
const std::string CSCRIPT
CKeyID seed_id
seed hash160
const std::string BESTBLOCK_NOMERKLE
boost::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
uint32_t nInternalChainCounter
A key from a CWallet's keypool.
const std::string PURPOSE