Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/walletdb.h
// Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Copyright (c) 2017-2020 The Bitcoin developers | // Copyright (c) 2017-2020 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_WALLET_WALLETDB_H | #ifndef BITCOIN_WALLET_WALLETDB_H | ||||
#define BITCOIN_WALLET_WALLETDB_H | #define BITCOIN_WALLET_WALLETDB_H | ||||
#include <amount.h> | #include <amount.h> | ||||
#include <key.h> | #include <key.h> | ||||
#include <primitives/transaction.h> | #include <primitives/transaction.h> | ||||
#include <script/sign.h> | |||||
#include <script/standard.h> // for CTxDestination | #include <script/standard.h> // for CTxDestination | ||||
#include <wallet/db.h> | #include <wallet/db.h> | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <list> | #include <list> | ||||
#include <string> | #include <string> | ||||
#include <utility> | #include <utility> | ||||
#include <vector> | #include <vector> | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | void SetNull() { | ||||
seed_id.SetNull(); | seed_id.SetNull(); | ||||
} | } | ||||
}; | }; | ||||
class CKeyMetadata { | class CKeyMetadata { | ||||
public: | public: | ||||
static const int VERSION_BASIC = 1; | static const int VERSION_BASIC = 1; | ||||
static const int VERSION_WITH_HDDATA = 10; | static const int VERSION_WITH_HDDATA = 10; | ||||
static const int CURRENT_VERSION = VERSION_WITH_HDDATA; | static const int VERSION_WITH_KEY_ORIGIN = 12; | ||||
static const int CURRENT_VERSION = VERSION_WITH_KEY_ORIGIN; | |||||
int nVersion; | int nVersion; | ||||
// 0 means unknown. | // 0 means unknown. | ||||
int64_t nCreateTime; | int64_t nCreateTime; | ||||
// optional HD/bip32 keypath. | // optional HD/bip32 keypath. Still used to determine whether a key is a | ||||
// seed. Also kept for backwards compatibility | |||||
std::string hdKeypath; | std::string hdKeypath; | ||||
// Id of the HD seed used to derive this key. | // Id of the HD seed used to derive this key. | ||||
CKeyID hd_seed_id; | CKeyID hd_seed_id; | ||||
// Key origin info with path and fingerprint | |||||
KeyOriginInfo key_origin; | |||||
//< Whether the key_origin is useful | |||||
bool has_key_origin = false; | |||||
CKeyMetadata() { SetNull(); } | CKeyMetadata() { SetNull(); } | ||||
explicit CKeyMetadata(int64_t nCreateTime_) { | explicit CKeyMetadata(int64_t nCreateTime_) { | ||||
SetNull(); | SetNull(); | ||||
nCreateTime = nCreateTime_; | nCreateTime = nCreateTime_; | ||||
} | } | ||||
ADD_SERIALIZE_METHODS; | ADD_SERIALIZE_METHODS; | ||||
template <typename Stream, typename Operation> | template <typename Stream, typename Operation> | ||||
inline void SerializationOp(Stream &s, Operation ser_action) { | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
READWRITE(this->nVersion); | READWRITE(this->nVersion); | ||||
READWRITE(nCreateTime); | READWRITE(nCreateTime); | ||||
if (this->nVersion >= VERSION_WITH_HDDATA) { | if (this->nVersion >= VERSION_WITH_HDDATA) { | ||||
READWRITE(hdKeypath); | READWRITE(hdKeypath); | ||||
READWRITE(hd_seed_id); | READWRITE(hd_seed_id); | ||||
} | } | ||||
if (this->nVersion >= VERSION_WITH_KEY_ORIGIN) { | |||||
READWRITE(key_origin); | |||||
READWRITE(has_key_origin); | |||||
} | |||||
} | } | ||||
void SetNull() { | void SetNull() { | ||||
nVersion = CKeyMetadata::CURRENT_VERSION; | nVersion = CKeyMetadata::CURRENT_VERSION; | ||||
nCreateTime = 0; | nCreateTime = 0; | ||||
hdKeypath.clear(); | hdKeypath.clear(); | ||||
hd_seed_id.SetNull(); | hd_seed_id.SetNull(); | ||||
key_origin.clear(); | |||||
has_key_origin = false; | |||||
} | } | ||||
}; | }; | ||||
/** | /** | ||||
* Access to the wallet database. | * Access to the wallet database. | ||||
* This represents a single transaction at the database. It will be committed | * This represents a single transaction at the database. It will be committed | ||||
* when the object goes out of scope. Optionally (on by default) it will flush | * when the object goes out of scope. Optionally (on by default) it will flush | ||||
* to disk as well. | * to disk as well. | ||||
▲ Show 20 Lines • Show All 125 Lines • Show Last 20 Lines |