6 #ifndef BITCOIN_WALLET_WALLETDB_H 7 #define BITCOIN_WALLET_WALLETDB_H 55 extern const std::string
ACENTRY;
61 extern const std::string
CSCRIPT;
64 extern const std::string
FLAGS;
65 extern const std::string
HDCHAIN;
66 extern const std::string
KEY;
67 extern const std::string
KEYMETA;
70 extern const std::string
NAME;
71 extern const std::string
OLD_KEY;
73 extern const std::string
POOL;
74 extern const std::string
PURPOSE;
76 extern const std::string
TX;
77 extern const std::string
VERSION;
82 extern const std::string
WATCHS;
93 static const int VERSION_HD_BASE = 1;
94 static const int VERSION_HD_CHAIN_SPLIT = 2;
95 static const int CURRENT_VERSION = VERSION_HD_CHAIN_SPLIT;
102 READWRITE(obj.nVersion, obj.nExternalChainCounter, obj.seed_id);
103 if (obj.nVersion >= VERSION_HD_CHAIN_SPLIT) {
111 nExternalChainCounter = 0;
112 nInternalChainCounter = 0;
118 return seed_id == chain.
seed_id;
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;
134 bool has_key_origin =
false;
143 nCreateTime = nCreateTime_;
148 READWRITE(obj.nVersion, obj.nCreateTime);
149 if (obj.nVersion >= VERSION_WITH_HDDATA) {
150 READWRITE(obj.hdKeypath, obj.hd_seed_id);
152 if (obj.nVersion >= VERSION_WITH_KEY_ORIGIN)
166 has_key_origin =
false;
180 template <
typename K,
typename T>
181 bool WriteIC(
const K& key,
const T& value,
bool fOverwrite =
true)
183 if (!m_batch->Write(key, value, fOverwrite)) {
186 m_database.IncrementUpdateCounter();
187 if (m_database.nUpdateCounter % 1000 == 0) {
193 template <
typename K>
196 if (!m_batch->Erase(key)) {
199 m_database.IncrementUpdateCounter();
200 if (m_database.nUpdateCounter % 1000 == 0) {
208 m_batch(database.MakeBatch(_fFlushOnClose)),
215 bool WriteName(
const std::string& strAddress,
const std::string& strName);
216 bool EraseName(
const std::string& strAddress);
218 bool WritePurpose(
const std::string& strAddress,
const std::string& purpose);
219 bool ErasePurpose(
const std::string& strAddress);
224 bool WriteKeyMetadata(
const CKeyMetadata& meta,
const CPubKey& pubkey,
const bool overwrite);
226 bool WriteCryptedKey(
const CPubKey& vchPubKey,
const std::vector<unsigned char>& vchCryptedSecret,
const CKeyMetadata &keyMeta);
227 bool WriteMasterKey(
unsigned int nID,
const CMasterKey& kMasterKey);
229 bool WriteCScript(
const uint160& hash,
const CScript& redeemScript);
232 bool EraseWatchOnly(
const CScript &script);
237 bool WriteOrderPosNext(int64_t nOrderPosNext);
239 bool ReadPool(int64_t nPool,
CKeyPool& keypool);
240 bool WritePool(int64_t nPool,
const CKeyPool& keypool);
241 bool ErasePool(int64_t nPool);
243 bool WriteMinVersion(
int nVersion);
246 bool WriteCryptedDescriptorKey(
const uint256& desc_id,
const CPubKey& pubkey,
const std::vector<unsigned char>& secret);
248 bool WriteDescriptorDerivedCache(
const CExtPubKey& xpub,
const uint256& desc_id, uint32_t key_exp_index, uint32_t der_index);
249 bool WriteDescriptorParentCache(
const CExtPubKey& xpub,
const uint256& desc_id, uint32_t key_exp_index);
252 bool WriteDestData(
const std::string &address,
const std::string &key,
const std::string &value);
254 bool EraseDestData(
const std::string &address,
const std::string &key);
256 bool WriteActiveScriptPubKeyMan(uint8_t type,
const uint256&
id,
bool internal);
259 DBErrors FindWalletTx(std::vector<uint256>& vTxHash, std::list<CWalletTx>& vWtx);
260 DBErrors ZapSelectTx(std::vector<uint256>& vHashIn, std::vector<uint256>& vHashOut);
262 static bool IsKeyType(
const std::string& strType);
265 bool WriteHDChain(
const CHDChain& chain);
267 bool WriteWalletFlags(
const uint64_t
flags);
294 #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...
const std::string SETTINGS
bool operator==(const CHDChain &chain) const
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.
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.
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)
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.