Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/walletdb.cpp
// 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 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. | ||||
#include "wallet/walletdb.h" | #include "wallet/walletdb.h" | ||||
#include "base58.h" | |||||
#include "consensus/validation.h" | #include "consensus/validation.h" | ||||
#include "dstencode.h" | #include "dstencode.h" | ||||
#include "protocol.h" | #include "protocol.h" | ||||
#include "serialize.h" | #include "serialize.h" | ||||
#include "sync.h" | #include "sync.h" | ||||
#include "util.h" | #include "util.h" | ||||
#include "utiltime.h" | #include "utiltime.h" | ||||
#include "validation.h" // For CheckRegularTransaction | #include "validation.h" // For CheckRegularTransaction | ||||
#include "wallet/wallet.h" | #include "wallet/wallet.h" | ||||
#include <atomic> | #include <atomic> | ||||
#include <boost/filesystem.hpp> | #include <boost/filesystem.hpp> | ||||
#include <boost/thread.hpp> | #include <boost/thread.hpp> | ||||
#include <boost/version.hpp> | #include <boost/version.hpp> | ||||
static uint64_t nAccountingEntryNumber = 0; | static uint64_t nAccountingEntryNumber = 0; | ||||
static std::atomic<unsigned int> nWalletDBUpdateCounter; | static std::atomic<unsigned int> nWalletDBUpdateCounter; | ||||
// | // | ||||
// CWalletDB | // CWalletDB | ||||
// | // | ||||
bool CWalletDB::WriteName(const std::string &strAddress, | bool CWalletDB::WriteName(const CTxDestination &address, | ||||
const std::string &strName) { | const std::string &strName) { | ||||
if (!IsValidDestination(address)) { | |||||
return false; | |||||
} | |||||
nWalletDBUpdateCounter++; | nWalletDBUpdateCounter++; | ||||
return Write(std::make_pair(std::string("name"), strAddress), strName); | return Write(std::make_pair(std::string("name"), | ||||
EncodeLegacyAddr(address, Params())), | |||||
strName); | |||||
} | } | ||||
bool CWalletDB::EraseName(const std::string &strAddress) { | bool CWalletDB::EraseName(const CTxDestination &address) { | ||||
// This should only be used for sending addresses, never for receiving | // This should only be used for sending addresses, never for receiving | ||||
// addresses, receiving addresses must always have an address book entry if | // addresses, receiving addresses must always have an address book entry if | ||||
// they're not change return. | // they're not change return. | ||||
if (!IsValidDestination(address)) { | |||||
return false; | |||||
} | |||||
nWalletDBUpdateCounter++; | nWalletDBUpdateCounter++; | ||||
return Erase(std::make_pair(std::string("name"), strAddress)); | return Erase(std::make_pair(std::string("name"), | ||||
EncodeLegacyAddr(address, Params()))); | |||||
} | } | ||||
bool CWalletDB::WritePurpose(const std::string &strAddress, | bool CWalletDB::WritePurpose(const CTxDestination &address, | ||||
const std::string &strPurpose) { | const std::string &strPurpose) { | ||||
if (!IsValidDestination(address)) { | |||||
return false; | |||||
} | |||||
nWalletDBUpdateCounter++; | nWalletDBUpdateCounter++; | ||||
return Write(std::make_pair(std::string("purpose"), strAddress), | return Write(std::make_pair(std::string("purpose"), | ||||
EncodeLegacyAddr(address, Params())), | |||||
strPurpose); | strPurpose); | ||||
} | } | ||||
bool CWalletDB::ErasePurpose(const std::string &strPurpose) { | bool CWalletDB::ErasePurpose(const CTxDestination &address) { | ||||
if (!IsValidDestination(address)) { | |||||
return false; | |||||
} | |||||
nWalletDBUpdateCounter++; | nWalletDBUpdateCounter++; | ||||
return Erase(std::make_pair(std::string("purpose"), strPurpose)); | return Erase(std::make_pair(std::string("purpose"), | ||||
EncodeLegacyAddr(address, Params()))); | |||||
} | } | ||||
bool CWalletDB::WriteTx(const CWalletTx &wtx) { | bool CWalletDB::WriteTx(const CWalletTx &wtx) { | ||||
nWalletDBUpdateCounter++; | nWalletDBUpdateCounter++; | ||||
return Write(std::make_pair(std::string("tx"), wtx.GetId()), wtx); | return Write(std::make_pair(std::string("tx"), wtx.GetId()), wtx); | ||||
} | } | ||||
bool CWalletDB::EraseTx(uint256 hash) { | bool CWalletDB::EraseTx(uint256 hash) { | ||||
▲ Show 20 Lines • Show All 784 Lines • ▼ Show 20 Lines | bool CWalletDB::Recover(CDBEnv &dbenv, const std::string &filename, | ||||
return fSuccess; | return fSuccess; | ||||
} | } | ||||
bool CWalletDB::Recover(CDBEnv &dbenv, const std::string &filename) { | bool CWalletDB::Recover(CDBEnv &dbenv, const std::string &filename) { | ||||
return CWalletDB::Recover(dbenv, filename, false); | return CWalletDB::Recover(dbenv, filename, false); | ||||
} | } | ||||
bool CWalletDB::WriteDestData(const std::string &address, | bool CWalletDB::WriteDestData(const CTxDestination &address, | ||||
const std::string &key, | const std::string &key, | ||||
const std::string &value) { | const std::string &value) { | ||||
if (!IsValidDestination(address)) { | |||||
return false; | |||||
} | |||||
nWalletDBUpdateCounter++; | nWalletDBUpdateCounter++; | ||||
return Write( | return Write(std::make_pair( | ||||
std::make_pair(std::string("destdata"), std::make_pair(address, key)), | std::string("destdata"), | ||||
std::make_pair(EncodeLegacyAddr(address, Params()), key)), | |||||
value); | value); | ||||
} | } | ||||
bool CWalletDB::EraseDestData(const std::string &address, | bool CWalletDB::EraseDestData(const CTxDestination &address, | ||||
const std::string &key) { | const std::string &key) { | ||||
if (!IsValidDestination(address)) { | |||||
return false; | |||||
} | |||||
nWalletDBUpdateCounter++; | nWalletDBUpdateCounter++; | ||||
return Erase( | return Erase(std::make_pair( | ||||
std::make_pair(std::string("destdata"), std::make_pair(address, key))); | std::string("destdata"), | ||||
std::make_pair(EncodeLegacyAddr(address, Params()), key))); | |||||
} | } | ||||
bool CWalletDB::WriteHDChain(const CHDChain &chain) { | bool CWalletDB::WriteHDChain(const CHDChain &chain) { | ||||
nWalletDBUpdateCounter++; | nWalletDBUpdateCounter++; | ||||
return Write(std::string("hdchain"), chain); | return Write(std::string("hdchain"), chain); | ||||
} | } | ||||
void CWalletDB::IncrementUpdateCounter() { | void CWalletDB::IncrementUpdateCounter() { | ||||
nWalletDBUpdateCounter++; | nWalletDBUpdateCounter++; | ||||
} | } | ||||
unsigned int CWalletDB::GetUpdateCounter() { | unsigned int CWalletDB::GetUpdateCounter() { | ||||
return nWalletDBUpdateCounter; | return nWalletDBUpdateCounter; | ||||
} | } |