mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-01-19 03:20:37 +00:00
Get rid of db dependencies on main
This commit is contained in:
parent
c94bd68547
commit
336fe971e6
11
src/db.cpp
11
src/db.cpp
@ -5,10 +5,12 @@
|
|||||||
|
|
||||||
#include "db.h"
|
#include "db.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "main.h"
|
#include "hash.h"
|
||||||
|
#include "addrman.h"
|
||||||
#include <boost/version.hpp>
|
#include <boost/version.hpp>
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
#include <boost/filesystem/fstream.hpp>
|
#include <boost/filesystem/fstream.hpp>
|
||||||
|
#include <openssl/rand.h>
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
#include "sys/stat.h"
|
#include "sys/stat.h"
|
||||||
@ -486,6 +488,7 @@ void CDBEnv::Flush(bool fShutdown)
|
|||||||
// CAddrDB
|
// CAddrDB
|
||||||
//
|
//
|
||||||
|
|
||||||
|
unsigned char CAddrDB::pchMessageStart[4] = { 0x00, 0x00, 0x00, 0x00 };
|
||||||
|
|
||||||
CAddrDB::CAddrDB()
|
CAddrDB::CAddrDB()
|
||||||
{
|
{
|
||||||
@ -501,7 +504,7 @@ bool CAddrDB::Write(const CAddrMan& addr)
|
|||||||
|
|
||||||
// serialize addresses, checksum data up to that point, then append csum
|
// serialize addresses, checksum data up to that point, then append csum
|
||||||
CDataStream ssPeers(SER_DISK, CLIENT_VERSION);
|
CDataStream ssPeers(SER_DISK, CLIENT_VERSION);
|
||||||
ssPeers << FLATDATA(pchMessageStart);
|
ssPeers << FLATDATA(CAddrDB::pchMessageStart);
|
||||||
ssPeers << addr;
|
ssPeers << addr;
|
||||||
uint256 hash = Hash(ssPeers.begin(), ssPeers.end());
|
uint256 hash = Hash(ssPeers.begin(), ssPeers.end());
|
||||||
ssPeers << hash;
|
ssPeers << hash;
|
||||||
@ -566,11 +569,11 @@ bool CAddrDB::Read(CAddrMan& addr)
|
|||||||
|
|
||||||
unsigned char pchMsgTmp[4];
|
unsigned char pchMsgTmp[4];
|
||||||
try {
|
try {
|
||||||
// de-serialize file header (pchMessageStart magic number) and
|
// de-serialize file header (CAddrDB::pchMessageStart magic number) and
|
||||||
ssPeers >> FLATDATA(pchMsgTmp);
|
ssPeers >> FLATDATA(pchMsgTmp);
|
||||||
|
|
||||||
// verify the network matches ours
|
// verify the network matches ours
|
||||||
if (memcmp(pchMsgTmp, pchMessageStart, sizeof(pchMsgTmp)))
|
if (memcmp(pchMsgTmp, CAddrDB::pchMessageStart, sizeof(pchMsgTmp)))
|
||||||
return error("CAddrman::Read() : invalid network magic number");
|
return error("CAddrman::Read() : invalid network magic number");
|
||||||
|
|
||||||
// de-serialize address data into one CAddrMan object
|
// de-serialize address data into one CAddrMan object
|
||||||
|
10
src/db.h
10
src/db.h
@ -5,22 +5,22 @@
|
|||||||
#ifndef BITCOIN_DB_H
|
#ifndef BITCOIN_DB_H
|
||||||
#define BITCOIN_DB_H
|
#define BITCOIN_DB_H
|
||||||
|
|
||||||
#include "main.h"
|
#include "sync.h"
|
||||||
|
#include "serialize.h"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <boost/filesystem.hpp>
|
||||||
#include <db_cxx.h>
|
#include <db_cxx.h>
|
||||||
|
|
||||||
class CAddress;
|
|
||||||
class CAddrMan;
|
class CAddrMan;
|
||||||
class CBlockLocator;
|
class CBlockLocator;
|
||||||
class CDiskBlockIndex;
|
class CDiskBlockIndex;
|
||||||
class CMasterKey;
|
class CMasterKey;
|
||||||
class COutPoint;
|
class COutPoint;
|
||||||
class CWallet;
|
class CWallet;
|
||||||
class CWalletTx;
|
|
||||||
|
|
||||||
extern unsigned int nWalletDBUpdated;
|
extern unsigned int nWalletDBUpdated;
|
||||||
|
|
||||||
@ -318,10 +318,14 @@ class CAddrDB
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
boost::filesystem::path pathAddr;
|
boost::filesystem::path pathAddr;
|
||||||
|
static unsigned char pchMessageStart[4];
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CAddrDB();
|
CAddrDB();
|
||||||
bool Write(const CAddrMan& addr);
|
bool Write(const CAddrMan& addr);
|
||||||
bool Read(CAddrMan& addr);
|
bool Read(CAddrMan& addr);
|
||||||
|
|
||||||
|
static void SetMessageStart(unsigned char _pchMessageStart[]) { memcpy(CAddrDB::pchMessageStart, _pchMessageStart, sizeof(CAddrDB::pchMessageStart)); }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BITCOIN_DB_H
|
#endif // BITCOIN_DB_H
|
||||||
|
@ -928,6 +928,7 @@ bool AppInit2(boost::thread_group& threadGroup)
|
|||||||
nStart = GetTimeMillis();
|
nStart = GetTimeMillis();
|
||||||
|
|
||||||
{
|
{
|
||||||
|
CAddrDB::SetMessageStart(pchMessageStart);
|
||||||
CAddrDB adb;
|
CAddrDB adb;
|
||||||
if (!adb.Read(addrman))
|
if (!adb.Read(addrman))
|
||||||
printf("Invalid or missing peers.dat; recreating\n");
|
printf("Invalid or missing peers.dat; recreating\n");
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
#ifndef BITCOIN_WALLET_H
|
#ifndef BITCOIN_WALLET_H
|
||||||
#define BITCOIN_WALLET_H
|
#define BITCOIN_WALLET_H
|
||||||
|
|
||||||
|
#include "walletdb.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -16,12 +18,12 @@
|
|||||||
#include "script.h"
|
#include "script.h"
|
||||||
#include "ui_interface.h"
|
#include "ui_interface.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "walletdb.h"
|
|
||||||
|
|
||||||
class CAccountingEntry;
|
class CAccountingEntry;
|
||||||
class CWalletTx;
|
class CWalletTx;
|
||||||
class CReserveKey;
|
class CReserveKey;
|
||||||
class COutput;
|
class COutput;
|
||||||
|
class CWalletDB;
|
||||||
|
|
||||||
/** (client) version numbers for particular wallet features */
|
/** (client) version numbers for particular wallet features */
|
||||||
enum WalletFeature
|
enum WalletFeature
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
class CKeyPool;
|
class CKeyPool;
|
||||||
class CAccount;
|
class CAccount;
|
||||||
class CAccountingEntry;
|
class CAccountingEntry;
|
||||||
|
class CWallet;
|
||||||
|
class CWalletTx;
|
||||||
|
|
||||||
/** Error statuses for the wallet database */
|
/** Error statuses for the wallet database */
|
||||||
enum DBErrors
|
enum DBErrors
|
||||||
@ -160,4 +162,6 @@ public:
|
|||||||
static bool Recover(CDBEnv& dbenv, std::string filename);
|
static bool Recover(CDBEnv& dbenv, std::string filename);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool BackupWallet(const CWallet& wallet, const std::string& strDest);
|
||||||
|
|
||||||
#endif // BITCOIN_WALLETDB_H
|
#endif // BITCOIN_WALLETDB_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user