2011-08-09 13:27:58 +02:00
|
|
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
2015-12-13 17:58:29 +01:00
|
|
|
// Copyright (c) 2009-2015 The Bitcoin Core developers
|
2014-10-26 08:03:12 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2012-05-18 16:02:28 +02:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2014-08-28 22:21:03 +02:00
|
|
|
|
2015-03-21 18:15:31 +01:00
|
|
|
#ifndef BITCOIN_WALLET_WALLET_H
|
|
|
|
#define BITCOIN_WALLET_WALLET_H
|
2011-06-26 19:23:24 +02:00
|
|
|
|
2014-10-23 02:05:11 +02:00
|
|
|
#include "amount.h"
|
2015-07-05 14:17:46 +02:00
|
|
|
#include "streams.h"
|
2015-02-05 01:21:11 +01:00
|
|
|
#include "tinyformat.h"
|
2012-05-06 19:40:58 +02:00
|
|
|
#include "ui_interface.h"
|
2015-02-05 01:21:11 +01:00
|
|
|
#include "utilstrencodings.h"
|
2015-02-05 01:11:44 +01:00
|
|
|
#include "validationinterface.h"
|
2016-04-18 15:12:46 +02:00
|
|
|
#include "script/ismine.h"
|
2015-03-22 20:18:55 +01:00
|
|
|
#include "wallet/crypter.h"
|
2015-02-03 21:09:47 +01:00
|
|
|
#include "wallet/walletdb.h"
|
2016-01-07 08:33:49 +01:00
|
|
|
#include "wallet/rpcwallet.h"
|
2013-04-13 07:13:08 +02:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <map>
|
|
|
|
#include <set>
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
2011-06-26 19:23:24 +02:00
|
|
|
|
2015-07-01 08:32:30 +02:00
|
|
|
#include <boost/shared_ptr.hpp>
|
2016-10-20 09:22:13 +02:00
|
|
|
#include <boost/thread.hpp>
|
2015-07-01 08:32:30 +02:00
|
|
|
|
2016-03-15 10:30:37 +01:00
|
|
|
extern CWallet* pwalletMain;
|
|
|
|
|
2014-10-26 08:03:12 +01:00
|
|
|
/**
|
|
|
|
* Settings
|
|
|
|
*/
|
2014-04-10 20:14:18 +02:00
|
|
|
extern CFeeRate payTxFee;
|
2014-05-27 21:44:57 +02:00
|
|
|
extern unsigned int nTxConfirmTarget;
|
2014-02-11 12:49:33 +01:00
|
|
|
extern bool bSpendZeroConfChange;
|
2014-11-02 00:43:31 +01:00
|
|
|
extern bool fSendFreeTransactions;
|
2016-09-01 15:24:45 +02:00
|
|
|
extern bool fWalletRbf;
|
2013-12-13 16:14:48 +01:00
|
|
|
|
2015-06-27 21:21:41 +02:00
|
|
|
static const unsigned int DEFAULT_KEYPOOL_SIZE = 100;
|
2014-10-26 08:03:12 +01:00
|
|
|
//! -paytxfee default
|
2014-04-23 00:46:19 +02:00
|
|
|
static const CAmount DEFAULT_TRANSACTION_FEE = 0;
|
2016-01-05 19:11:34 +01:00
|
|
|
//! -fallbackfee default
|
|
|
|
static const CAmount DEFAULT_FALLBACK_FEE = 20000;
|
2015-09-13 23:23:59 +02:00
|
|
|
//! -mintxfee default
|
|
|
|
static const CAmount DEFAULT_TRANSACTION_MINFEE = 1000;
|
|
|
|
//! minimum change amount
|
|
|
|
static const CAmount MIN_CHANGE = CENT;
|
2015-11-09 19:16:38 +01:00
|
|
|
//! Default for -spendzeroconfchange
|
|
|
|
static const bool DEFAULT_SPEND_ZEROCONF_CHANGE = true;
|
|
|
|
//! Default for -sendfreetransactions
|
|
|
|
static const bool DEFAULT_SEND_FREE_TRANSACTIONS = false;
|
2016-12-02 21:29:20 +01:00
|
|
|
//! Default for -walletrejectlongchains
|
|
|
|
static const bool DEFAULT_WALLET_REJECT_LONG_CHAINS = false;
|
2015-05-18 08:51:16 +02:00
|
|
|
//! -txconfirmtarget default
|
2016-10-28 14:15:46 +02:00
|
|
|
static const unsigned int DEFAULT_TX_CONFIRM_TARGET = 6;
|
2016-09-01 15:24:45 +02:00
|
|
|
//! -walletrbf default
|
|
|
|
static const bool DEFAULT_WALLET_RBF = false;
|
2014-10-26 08:03:12 +01:00
|
|
|
//! Largest (in bytes) free transaction we're willing to create
|
2014-05-27 21:44:57 +02:00
|
|
|
static const unsigned int MAX_FREE_TRANSACTION_CREATE_SIZE = 1000;
|
2015-06-27 21:21:41 +02:00
|
|
|
static const bool DEFAULT_WALLETBROADCAST = true;
|
2016-09-21 12:15:18 +02:00
|
|
|
static const bool DEFAULT_DISABLE_WALLET = false;
|
2016-01-02 12:34:08 +01:00
|
|
|
//! if set, all keys will be derived by using BIP32
|
|
|
|
static const bool DEFAULT_USE_HD_WALLET = true;
|
|
|
|
|
2016-02-22 10:48:44 +01:00
|
|
|
extern const char * DEFAULT_WALLET_DAT;
|
|
|
|
|
2015-02-05 01:21:11 +01:00
|
|
|
class CBlockIndex;
|
2013-11-16 17:37:31 +01:00
|
|
|
class CCoinControl;
|
2012-02-27 13:19:32 +01:00
|
|
|
class COutput;
|
2013-04-13 07:13:08 +02:00
|
|
|
class CReserveKey;
|
|
|
|
class CScript;
|
2015-02-05 01:21:11 +01:00
|
|
|
class CTxMemPool;
|
2013-04-13 07:13:08 +02:00
|
|
|
class CWalletTx;
|
2011-06-26 19:23:24 +02:00
|
|
|
|
2012-03-26 16:48:23 +02:00
|
|
|
/** (client) version numbers for particular wallet features */
|
2012-03-22 03:56:31 +01:00
|
|
|
enum WalletFeature
|
|
|
|
{
|
|
|
|
FEATURE_BASE = 10500, // the earliest version new wallets supports (only useful for getinfo's clientversion output)
|
|
|
|
|
|
|
|
FEATURE_WALLETCRYPT = 40000, // wallet encryption
|
|
|
|
FEATURE_COMPRPUBKEY = 60000, // compressed public keys
|
|
|
|
|
2016-07-15 11:42:47 +02:00
|
|
|
FEATURE_HD = 130000, // Hierarchical key derivation after BIP32 (HD Wallet)
|
|
|
|
FEATURE_LATEST = FEATURE_COMPRPUBKEY // HD is optional, use FEATURE_COMPRPUBKEY as latest version
|
2012-03-22 03:56:31 +01:00
|
|
|
};
|
|
|
|
|
2012-04-15 22:10:54 +02:00
|
|
|
|
|
|
|
/** A key pool entry */
|
|
|
|
class CKeyPool
|
|
|
|
{
|
|
|
|
public:
|
2013-04-13 07:13:08 +02:00
|
|
|
int64_t nTime;
|
2012-05-14 19:07:52 +02:00
|
|
|
CPubKey vchPubKey;
|
2012-04-15 22:10:54 +02:00
|
|
|
|
2014-08-21 05:04:43 +02:00
|
|
|
CKeyPool();
|
|
|
|
CKeyPool(const CPubKey& vchPubKeyIn);
|
2012-04-15 22:10:54 +02:00
|
|
|
|
2014-09-02 09:58:09 +02:00
|
|
|
ADD_SERIALIZE_METHODS;
|
overhaul serialization code
The implementation of each class' serialization/deserialization is no longer
passed within a macro. The implementation now lies within a template of form:
template <typename T, typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0;
/* CODE */
return nSerSize;
}
In cases when codepath should depend on whether or not we are just deserializing
(old fGetSize, fWrite, fRead flags) an additional clause can be used:
bool fRead = boost::is_same<Operation, CSerActionUnserialize>();
The IMPLEMENT_SERIALIZE macro will now be a freestanding clause added within
class' body (similiar to Qt's Q_OBJECT) to implement GetSerializeSize,
Serialize and Unserialize. These are now wrappers around
the "SerializationOp" template.
2014-08-20 08:42:31 +02:00
|
|
|
|
2014-08-20 22:44:38 +02:00
|
|
|
template <typename Stream, typename Operation>
|
2016-10-29 01:29:17 +02:00
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action) {
|
|
|
|
int nVersion = s.GetVersion();
|
|
|
|
if (!(s.GetType() & SER_GETHASH))
|
2012-04-15 22:10:54 +02:00
|
|
|
READWRITE(nVersion);
|
|
|
|
READWRITE(nTime);
|
|
|
|
READWRITE(vchPubKey);
|
overhaul serialization code
The implementation of each class' serialization/deserialization is no longer
passed within a macro. The implementation now lies within a template of form:
template <typename T, typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0;
/* CODE */
return nSerSize;
}
In cases when codepath should depend on whether or not we are just deserializing
(old fGetSize, fWrite, fRead flags) an additional clause can be used:
bool fRead = boost::is_same<Operation, CSerActionUnserialize>();
The IMPLEMENT_SERIALIZE macro will now be a freestanding clause added within
class' body (similiar to Qt's Q_OBJECT) to implement GetSerializeSize,
Serialize and Unserialize. These are now wrappers around
the "SerializationOp" template.
2014-08-20 08:42:31 +02:00
|
|
|
}
|
2012-04-15 22:10:54 +02:00
|
|
|
};
|
|
|
|
|
2013-07-15 07:20:50 +02:00
|
|
|
/** Address book data */
|
|
|
|
class CAddressBookData
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::string name;
|
2013-07-22 08:50:39 +02:00
|
|
|
std::string purpose;
|
2013-07-15 07:20:50 +02:00
|
|
|
|
|
|
|
CAddressBookData()
|
|
|
|
{
|
2013-07-22 08:50:39 +02:00
|
|
|
purpose = "unknown";
|
2013-07-15 07:20:50 +02:00
|
|
|
}
|
2013-11-18 16:55:54 +01:00
|
|
|
|
|
|
|
typedef std::map<std::string, std::string> StringMap;
|
|
|
|
StringMap destdata;
|
2013-07-15 07:20:50 +02:00
|
|
|
};
|
|
|
|
|
2014-07-23 14:34:36 +02:00
|
|
|
struct CRecipient
|
|
|
|
{
|
|
|
|
CScript scriptPubKey;
|
|
|
|
CAmount nAmount;
|
|
|
|
bool fSubtractFeeFromAmount;
|
|
|
|
};
|
2014-12-19 02:03:51 +01:00
|
|
|
|
|
|
|
typedef std::map<std::string, std::string> mapValue_t;
|
|
|
|
|
|
|
|
|
2016-11-03 01:29:16 +01:00
|
|
|
static inline void ReadOrderPos(int64_t& nOrderPos, mapValue_t& mapValue)
|
2014-12-19 02:03:51 +01:00
|
|
|
{
|
|
|
|
if (!mapValue.count("n"))
|
|
|
|
{
|
|
|
|
nOrderPos = -1; // TODO: calculate elsewhere
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nOrderPos = atoi64(mapValue["n"].c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-03 01:29:16 +01:00
|
|
|
static inline void WriteOrderPos(const int64_t& nOrderPos, mapValue_t& mapValue)
|
2014-12-19 02:03:51 +01:00
|
|
|
{
|
|
|
|
if (nOrderPos == -1)
|
|
|
|
return;
|
|
|
|
mapValue["n"] = i64tostr(nOrderPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct COutputEntry
|
|
|
|
{
|
|
|
|
CTxDestination destination;
|
|
|
|
CAmount amount;
|
|
|
|
int vout;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** A transaction with a merkle branch linking it to the block chain. */
|
2016-11-12 01:54:51 +01:00
|
|
|
class CMerkleTx
|
2011-06-26 19:23:24 +02:00
|
|
|
{
|
2016-01-07 22:31:27 +01:00
|
|
|
private:
|
|
|
|
/** Constant used in hashBlock to indicate tx has been abandoned */
|
|
|
|
static const uint256 ABANDON_HASH;
|
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
public:
|
2016-11-12 01:54:51 +01:00
|
|
|
CTransactionRef tx;
|
2014-12-19 02:03:51 +01:00
|
|
|
uint256 hashBlock;
|
2015-11-26 18:42:07 +01:00
|
|
|
|
|
|
|
/* An nIndex == -1 means that hashBlock (in nonzero) refers to the earliest
|
|
|
|
* block in the chain we know this or any in-wallet dependency conflicts
|
|
|
|
* with. Older clients interpret nIndex == -1 as unconfirmed for backward
|
|
|
|
* compatibility.
|
|
|
|
*/
|
2014-12-19 02:03:51 +01:00
|
|
|
int nIndex;
|
2011-06-26 19:23:24 +02:00
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
CMerkleTx()
|
|
|
|
{
|
2016-11-12 01:54:51 +01:00
|
|
|
SetTx(MakeTransactionRef());
|
2014-12-19 02:03:51 +01:00
|
|
|
Init();
|
|
|
|
}
|
2013-04-19 23:28:25 +02:00
|
|
|
|
2016-11-12 01:54:51 +01:00
|
|
|
CMerkleTx(CTransactionRef arg)
|
2014-12-19 02:03:51 +01:00
|
|
|
{
|
2016-11-12 01:54:51 +01:00
|
|
|
SetTx(std::move(arg));
|
2014-12-19 02:03:51 +01:00
|
|
|
Init();
|
|
|
|
}
|
2014-02-15 22:38:28 +01:00
|
|
|
|
2016-11-12 01:54:51 +01:00
|
|
|
/** Helper conversion operator to allow passing CMerkleTx where CTransaction is expected.
|
|
|
|
* TODO: adapt callers and remove this operator. */
|
|
|
|
operator const CTransaction&() const { return *tx; }
|
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
void Init()
|
|
|
|
{
|
|
|
|
hashBlock = uint256();
|
|
|
|
nIndex = -1;
|
|
|
|
}
|
2014-02-14 02:12:51 +01:00
|
|
|
|
2016-11-12 01:54:51 +01:00
|
|
|
void SetTx(CTransactionRef arg)
|
|
|
|
{
|
|
|
|
tx = std::move(arg);
|
|
|
|
}
|
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
2016-10-29 01:29:17 +02:00
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action) {
|
2015-08-11 21:03:31 +02:00
|
|
|
std::vector<uint256> vMerkleBranch; // For compatibility with older versions.
|
2016-11-12 01:54:51 +01:00
|
|
|
READWRITE(tx);
|
2014-12-19 02:03:51 +01:00
|
|
|
READWRITE(hashBlock);
|
|
|
|
READWRITE(vMerkleBranch);
|
|
|
|
READWRITE(nIndex);
|
|
|
|
}
|
|
|
|
|
2016-04-26 13:55:13 +02:00
|
|
|
int SetMerkleBranch(const CBlockIndex* pIndex, int posInBlock);
|
2014-12-19 02:03:51 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return depth of transaction in blockchain:
|
2015-11-26 18:42:07 +01:00
|
|
|
* <0 : conflicts with a transaction this deep in the blockchain
|
2014-12-19 02:03:51 +01:00
|
|
|
* 0 : in memory pool, waiting to be included in a block
|
|
|
|
* >=1 : this many blocks deep in the main chain
|
2014-10-26 08:03:12 +01:00
|
|
|
*/
|
2014-12-19 02:03:51 +01:00
|
|
|
int GetDepthInMainChain(const CBlockIndex* &pindexRet) const;
|
|
|
|
int GetDepthInMainChain() const { const CBlockIndex *pindexRet; return GetDepthInMainChain(pindexRet); }
|
2015-11-26 18:42:07 +01:00
|
|
|
bool IsInMainChain() const { const CBlockIndex *pindexRet; return GetDepthInMainChain(pindexRet) > 0; }
|
2014-12-19 02:03:51 +01:00
|
|
|
int GetBlocksToMaturity() const;
|
2015-11-20 16:48:06 +01:00
|
|
|
/** Pass this transaction to the mempool. Fails if absolute fee exceeds absurd fee. */
|
2016-10-25 20:27:04 +02:00
|
|
|
bool AcceptToMemoryPool(const CAmount& nAbsurdFee, CValidationState& state);
|
2016-01-07 22:31:27 +01:00
|
|
|
bool hashUnset() const { return (hashBlock.IsNull() || hashBlock == ABANDON_HASH); }
|
|
|
|
bool isAbandoned() const { return (hashBlock == ABANDON_HASH); }
|
|
|
|
void setAbandoned() { hashBlock = ABANDON_HASH; }
|
2016-11-12 01:54:51 +01:00
|
|
|
|
|
|
|
const uint256& GetHash() const { return tx->GetHash(); }
|
|
|
|
bool IsCoinBase() const { return tx->IsCoinBase(); }
|
2014-12-19 02:03:51 +01:00
|
|
|
};
|
2011-08-26 20:37:23 +02:00
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
/**
|
|
|
|
* A transaction with a bunch of additional info that only the owner cares about.
|
|
|
|
* It includes any unrecorded transactions needed to link it back to the block chain.
|
|
|
|
*/
|
|
|
|
class CWalletTx : public CMerkleTx
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
const CWallet* pwallet;
|
2011-06-26 19:23:24 +02:00
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
public:
|
|
|
|
mapValue_t mapValue;
|
|
|
|
std::vector<std::pair<std::string, std::string> > vOrderForm;
|
|
|
|
unsigned int fTimeReceivedIsTxTime;
|
2016-04-03 11:49:36 +02:00
|
|
|
unsigned int nTimeReceived; //!< time received by this node
|
2014-12-19 02:03:51 +01:00
|
|
|
unsigned int nTimeSmart;
|
|
|
|
char fFromMe;
|
|
|
|
std::string strFromAccount;
|
2016-04-03 11:49:36 +02:00
|
|
|
int64_t nOrderPos; //!< position in ordered transaction list
|
2012-02-18 14:55:02 +01:00
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
// memory only
|
|
|
|
mutable bool fDebitCached;
|
|
|
|
mutable bool fCreditCached;
|
|
|
|
mutable bool fImmatureCreditCached;
|
|
|
|
mutable bool fAvailableCreditCached;
|
|
|
|
mutable bool fWatchDebitCached;
|
|
|
|
mutable bool fWatchCreditCached;
|
|
|
|
mutable bool fImmatureWatchCreditCached;
|
|
|
|
mutable bool fAvailableWatchCreditCached;
|
|
|
|
mutable bool fChangeCached;
|
|
|
|
mutable CAmount nDebitCached;
|
|
|
|
mutable CAmount nCreditCached;
|
|
|
|
mutable CAmount nImmatureCreditCached;
|
|
|
|
mutable CAmount nAvailableCreditCached;
|
|
|
|
mutable CAmount nWatchDebitCached;
|
|
|
|
mutable CAmount nWatchCreditCached;
|
|
|
|
mutable CAmount nImmatureWatchCreditCached;
|
|
|
|
mutable CAmount nAvailableWatchCreditCached;
|
|
|
|
mutable CAmount nChangeCached;
|
Add wallet privkey encryption.
This commit adds support for ckeys, or enCrypted private keys, to the wallet.
All keys are stored in memory in their encrypted form and thus the passphrase
is required from the user to spend coins, or to create new addresses.
Keys are encrypted with AES-256-CBC using OpenSSL's EVP library. The key is
calculated via EVP_BytesToKey using SHA512 with (by default) 25000 rounds and
a random salt.
By default, the user's wallet remains unencrypted until they call the RPC
command encryptwallet <passphrase> or, from the GUI menu, Options->
Encrypt Wallet.
When the user is attempting to call RPC functions which require the password
to unlock the wallet, an error will be returned unless they call
walletpassphrase <passphrase> <time to keep key in memory> first.
A keypoolrefill command has been added which tops up the users keypool
(requiring the passphrase via walletpassphrase first).
keypoolsize has been added to the output of getinfo to show the user the
number of keys left before they need to specify their passphrase (and call
keypoolrefill).
Note that walletpassphrase will automatically fill keypool in a separate
thread which it spawns when the passphrase is set. This could cause some
delays in other threads waiting for locks on the wallet passphrase, including
one which could cause the passphrase to be stored longer than expected,
however it will not allow the passphrase to be used longer than expected as
ThreadCleanWalletPassphrase will attempt to get a lock on the key as soon
as the specified lock time has arrived.
When the keypool runs out (and wallet is locked) GetOrReuseKeyFromPool
returns vchDefaultKey, meaning miners may start to generate many blocks to
vchDefaultKey instead of a new key each time.
A walletpassphrasechange <oldpassphrase> <newpassphrase> has been added to
allow the user to change their password via RPC.
Whenever keying material (unencrypted private keys, the user's passphrase,
the wallet's AES key) is stored unencrypted in memory, any reasonable attempt
is made to mlock/VirtualLock that memory before storing the keying material.
This is not true in several (commented) cases where mlock/VirtualLocking the
memory is not possible.
Although encryption of private keys in memory can be very useful on desktop
systems (as some small amount of protection against stupid viruses), on an
RPC server, the password is entered fairly insecurely. Thus, the only main
advantage encryption has for RPC servers is for RPC servers that do not spend
coins, except in rare cases, eg. a webserver of a merchant which only receives
payment except for cases of manual intervention.
Thanks to jgarzik for the original patch and sipa, gmaxwell and many others
for all their input.
Conflicts:
src/wallet.cpp
2011-07-08 15:47:35 +02:00
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
CWalletTx()
|
2011-06-26 19:23:24 +02:00
|
|
|
{
|
2014-12-19 02:03:51 +01:00
|
|
|
Init(NULL);
|
2011-06-26 19:23:24 +02:00
|
|
|
}
|
2014-09-28 16:11:17 +02:00
|
|
|
|
2016-11-12 01:54:51 +01:00
|
|
|
CWalletTx(const CWallet* pwalletIn, CTransactionRef arg) : CMerkleTx(std::move(arg))
|
2014-09-28 16:11:17 +02:00
|
|
|
{
|
2014-12-19 02:03:51 +01:00
|
|
|
Init(pwalletIn);
|
2014-09-28 16:11:17 +02:00
|
|
|
}
|
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
void Init(const CWallet* pwalletIn)
|
2014-06-03 18:55:33 +02:00
|
|
|
{
|
2014-12-19 02:03:51 +01:00
|
|
|
pwallet = pwalletIn;
|
|
|
|
mapValue.clear();
|
|
|
|
vOrderForm.clear();
|
|
|
|
fTimeReceivedIsTxTime = false;
|
|
|
|
nTimeReceived = 0;
|
|
|
|
nTimeSmart = 0;
|
|
|
|
fFromMe = false;
|
|
|
|
strFromAccount.clear();
|
|
|
|
fDebitCached = false;
|
|
|
|
fCreditCached = false;
|
|
|
|
fImmatureCreditCached = false;
|
|
|
|
fAvailableCreditCached = false;
|
|
|
|
fWatchDebitCached = false;
|
|
|
|
fWatchCreditCached = false;
|
|
|
|
fImmatureWatchCreditCached = false;
|
|
|
|
fAvailableWatchCreditCached = false;
|
|
|
|
fChangeCached = false;
|
|
|
|
nDebitCached = 0;
|
|
|
|
nCreditCached = 0;
|
|
|
|
nImmatureCreditCached = 0;
|
|
|
|
nAvailableCreditCached = 0;
|
|
|
|
nWatchDebitCached = 0;
|
|
|
|
nWatchCreditCached = 0;
|
|
|
|
nAvailableWatchCreditCached = 0;
|
|
|
|
nImmatureWatchCreditCached = 0;
|
|
|
|
nChangeCached = 0;
|
|
|
|
nOrderPos = -1;
|
2011-06-26 19:23:24 +02:00
|
|
|
}
|
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
ADD_SERIALIZE_METHODS;
|
2014-02-14 02:12:51 +01:00
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
template <typename Stream, typename Operation>
|
2016-10-29 01:29:17 +02:00
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action) {
|
2014-12-19 02:03:51 +01:00
|
|
|
if (ser_action.ForRead())
|
|
|
|
Init(NULL);
|
|
|
|
char fSpent = false;
|
2011-06-26 19:23:24 +02:00
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
if (!ser_action.ForRead())
|
|
|
|
{
|
|
|
|
mapValue["fromaccount"] = strFromAccount;
|
2011-06-26 19:23:24 +02:00
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
WriteOrderPos(nOrderPos, mapValue);
|
2011-06-26 19:23:24 +02:00
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
if (nTimeSmart)
|
|
|
|
mapValue["timesmart"] = strprintf("%u", nTimeSmart);
|
|
|
|
}
|
2012-09-27 19:52:09 +02:00
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
READWRITE(*(CMerkleTx*)this);
|
2016-04-03 11:49:36 +02:00
|
|
|
std::vector<CMerkleTx> vUnused; //!< Used to be vtxPrev
|
2014-12-19 02:03:51 +01:00
|
|
|
READWRITE(vUnused);
|
|
|
|
READWRITE(mapValue);
|
|
|
|
READWRITE(vOrderForm);
|
|
|
|
READWRITE(fTimeReceivedIsTxTime);
|
|
|
|
READWRITE(nTimeReceived);
|
|
|
|
READWRITE(fFromMe);
|
|
|
|
READWRITE(fSpent);
|
2013-06-10 15:36:29 +02:00
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
if (ser_action.ForRead())
|
|
|
|
{
|
|
|
|
strFromAccount = mapValue["fromaccount"];
|
2014-02-15 22:38:28 +01:00
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
ReadOrderPos(nOrderPos, mapValue);
|
2012-03-22 03:56:31 +01:00
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
nTimeSmart = mapValue.count("timesmart") ? (unsigned int)atoi64(mapValue["timesmart"]) : 0;
|
|
|
|
}
|
2013-12-12 08:07:59 +01:00
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
mapValue.erase("fromaccount");
|
|
|
|
mapValue.erase("version");
|
|
|
|
mapValue.erase("spent");
|
|
|
|
mapValue.erase("n");
|
|
|
|
mapValue.erase("timesmart");
|
|
|
|
}
|
2014-02-15 22:38:28 +01:00
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
//! make sure balances are recalculated
|
|
|
|
void MarkDirty()
|
|
|
|
{
|
|
|
|
fCreditCached = false;
|
|
|
|
fAvailableCreditCached = false;
|
2016-09-14 00:30:32 +02:00
|
|
|
fImmatureCreditCached = false;
|
2014-12-19 02:03:51 +01:00
|
|
|
fWatchDebitCached = false;
|
|
|
|
fWatchCreditCached = false;
|
|
|
|
fAvailableWatchCreditCached = false;
|
|
|
|
fImmatureWatchCreditCached = false;
|
|
|
|
fDebitCached = false;
|
|
|
|
fChangeCached = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BindWallet(CWallet *pwalletIn)
|
|
|
|
{
|
|
|
|
pwallet = pwalletIn;
|
|
|
|
MarkDirty();
|
|
|
|
}
|
|
|
|
|
|
|
|
//! filter decides which addresses will count towards the debit
|
|
|
|
CAmount GetDebit(const isminefilter& filter) const;
|
|
|
|
CAmount GetCredit(const isminefilter& filter) const;
|
|
|
|
CAmount GetImmatureCredit(bool fUseCache=true) const;
|
|
|
|
CAmount GetAvailableCredit(bool fUseCache=true) const;
|
|
|
|
CAmount GetImmatureWatchOnlyCredit(const bool& fUseCache=true) const;
|
|
|
|
CAmount GetAvailableWatchOnlyCredit(const bool& fUseCache=true) const;
|
|
|
|
CAmount GetChange() const;
|
|
|
|
|
|
|
|
void GetAmounts(std::list<COutputEntry>& listReceived,
|
|
|
|
std::list<COutputEntry>& listSent, CAmount& nFee, std::string& strSentAccount, const isminefilter& filter) const;
|
|
|
|
|
|
|
|
void GetAccountAmounts(const std::string& strAccount, CAmount& nReceived,
|
|
|
|
CAmount& nSent, CAmount& nFee, const isminefilter& filter) const;
|
|
|
|
|
|
|
|
bool IsFromMe(const isminefilter& filter) const
|
|
|
|
{
|
|
|
|
return (GetDebit(filter) > 0);
|
|
|
|
}
|
|
|
|
|
2015-07-02 20:57:39 +02:00
|
|
|
// True if only scriptSigs are different
|
|
|
|
bool IsEquivalentTo(const CWalletTx& tx) const;
|
|
|
|
|
2015-11-30 16:15:15 +01:00
|
|
|
bool InMempool() const;
|
2014-12-19 02:03:51 +01:00
|
|
|
bool IsTrusted() const;
|
|
|
|
|
|
|
|
int64_t GetTxTime() const;
|
|
|
|
int GetRequestCount() const;
|
|
|
|
|
2016-05-25 02:56:17 +02:00
|
|
|
bool RelayWalletTransaction(CConnman* connman);
|
2014-12-19 02:03:51 +01:00
|
|
|
|
|
|
|
std::set<uint256> GetConflicts() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class COutput
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
const CWalletTx *tx;
|
|
|
|
int i;
|
|
|
|
int nDepth;
|
|
|
|
bool fSpendable;
|
2016-03-14 19:22:11 +01:00
|
|
|
bool fSolvable;
|
2014-12-19 02:03:51 +01:00
|
|
|
|
2016-03-14 19:22:11 +01:00
|
|
|
COutput(const CWalletTx *txIn, int iIn, int nDepthIn, bool fSpendableIn, bool fSolvableIn)
|
2014-12-19 02:03:51 +01:00
|
|
|
{
|
2016-03-14 19:22:11 +01:00
|
|
|
tx = txIn; i = iIn; nDepth = nDepthIn; fSpendable = fSpendableIn; fSolvable = fSolvableIn;
|
2014-12-19 02:03:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string ToString() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Private key that includes an expiration date in case it never gets used. */
|
|
|
|
class CWalletKey
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CPrivKey vchPrivKey;
|
|
|
|
int64_t nTimeCreated;
|
|
|
|
int64_t nTimeExpires;
|
|
|
|
std::string strComment;
|
|
|
|
//! todo: add something to note what created it (user, getnewaddress, change)
|
|
|
|
//! maybe should have a map<string, string> property map
|
|
|
|
|
|
|
|
CWalletKey(int64_t nExpires=0);
|
|
|
|
|
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
2016-10-29 01:29:17 +02:00
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action) {
|
|
|
|
int nVersion = s.GetVersion();
|
|
|
|
if (!(s.GetType() & SER_GETHASH))
|
2014-12-19 02:03:51 +01:00
|
|
|
READWRITE(nVersion);
|
|
|
|
READWRITE(vchPrivKey);
|
|
|
|
READWRITE(nTimeCreated);
|
|
|
|
READWRITE(nTimeExpires);
|
|
|
|
READWRITE(LIMITED_STRING(strComment, 65536));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-01-05 22:25:42 +01:00
|
|
|
/**
|
|
|
|
* Internal transfers.
|
|
|
|
* Database key is acentry<account><counter>.
|
|
|
|
*/
|
|
|
|
class CAccountingEntry
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::string strAccount;
|
|
|
|
CAmount nCreditDebit;
|
|
|
|
int64_t nTime;
|
|
|
|
std::string strOtherAccount;
|
|
|
|
std::string strComment;
|
|
|
|
mapValue_t mapValue;
|
2016-04-03 11:49:36 +02:00
|
|
|
int64_t nOrderPos; //!< position in ordered transaction list
|
2016-01-05 22:25:42 +01:00
|
|
|
uint64_t nEntryNo;
|
|
|
|
|
|
|
|
CAccountingEntry()
|
|
|
|
{
|
|
|
|
SetNull();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetNull()
|
|
|
|
{
|
|
|
|
nCreditDebit = 0;
|
|
|
|
nTime = 0;
|
|
|
|
strAccount.clear();
|
|
|
|
strOtherAccount.clear();
|
|
|
|
strComment.clear();
|
|
|
|
nOrderPos = -1;
|
|
|
|
nEntryNo = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
2016-10-29 01:29:17 +02:00
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action) {
|
|
|
|
int nVersion = s.GetVersion();
|
|
|
|
if (!(s.GetType() & SER_GETHASH))
|
2016-01-05 22:25:42 +01:00
|
|
|
READWRITE(nVersion);
|
|
|
|
//! Note: strAccount is serialized as part of the key, not here.
|
|
|
|
READWRITE(nCreditDebit);
|
|
|
|
READWRITE(nTime);
|
|
|
|
READWRITE(LIMITED_STRING(strOtherAccount, 65536));
|
|
|
|
|
|
|
|
if (!ser_action.ForRead())
|
|
|
|
{
|
|
|
|
WriteOrderPos(nOrderPos, mapValue);
|
|
|
|
|
|
|
|
if (!(mapValue.empty() && _ssExtra.empty()))
|
|
|
|
{
|
2016-10-29 01:29:17 +02:00
|
|
|
CDataStream ss(s.GetType(), s.GetVersion());
|
2016-01-05 22:25:42 +01:00
|
|
|
ss.insert(ss.begin(), '\0');
|
|
|
|
ss << mapValue;
|
|
|
|
ss.insert(ss.end(), _ssExtra.begin(), _ssExtra.end());
|
|
|
|
strComment.append(ss.str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
READWRITE(LIMITED_STRING(strComment, 65536));
|
|
|
|
|
|
|
|
size_t nSepPos = strComment.find("\0", 0, 1);
|
|
|
|
if (ser_action.ForRead())
|
|
|
|
{
|
|
|
|
mapValue.clear();
|
|
|
|
if (std::string::npos != nSepPos)
|
|
|
|
{
|
2016-10-29 01:29:17 +02:00
|
|
|
CDataStream ss(std::vector<char>(strComment.begin() + nSepPos + 1, strComment.end()), s.GetType(), s.GetVersion());
|
2016-01-05 22:25:42 +01:00
|
|
|
ss >> mapValue;
|
|
|
|
_ssExtra = std::vector<char>(ss.begin(), ss.end());
|
|
|
|
}
|
|
|
|
ReadOrderPos(nOrderPos, mapValue);
|
|
|
|
}
|
|
|
|
if (std::string::npos != nSepPos)
|
|
|
|
strComment.erase(nSepPos);
|
|
|
|
|
|
|
|
mapValue.erase("n");
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<char> _ssExtra;
|
|
|
|
};
|
2014-12-19 02:03:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,
|
|
|
|
* and provides the ability to create new transactions.
|
|
|
|
*/
|
|
|
|
class CWallet : public CCryptoKeyStore, public CValidationInterface
|
|
|
|
{
|
|
|
|
private:
|
2015-09-14 14:49:59 +02:00
|
|
|
/**
|
|
|
|
* Select a set of coins such that nValueRet >= nTargetValue and at least
|
|
|
|
* all coins from coinControl are selected; Never select unconfirmed coins
|
|
|
|
* if they are not ours
|
|
|
|
*/
|
2016-03-08 01:15:17 +01:00
|
|
|
bool SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAmount& nTargetValue, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, CAmount& nValueRet, const CCoinControl *coinControl = NULL) const;
|
2014-12-19 02:03:51 +01:00
|
|
|
|
|
|
|
CWalletDB *pwalletdbEncryption;
|
|
|
|
|
|
|
|
//! the current wallet version: clients below this version are not able to load the wallet
|
|
|
|
int nWalletVersion;
|
|
|
|
|
|
|
|
//! the maximum wallet format version: memory-only variable that specifies to what version this wallet may be upgraded
|
|
|
|
int nWalletMaxVersion;
|
|
|
|
|
|
|
|
int64_t nNextResend;
|
|
|
|
int64_t nLastResend;
|
2015-03-27 10:34:48 +01:00
|
|
|
bool fBroadcastTransactions;
|
2014-12-19 02:03:51 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to keep track of spent outpoints, and
|
|
|
|
* detect and report conflicts (double-spends or
|
|
|
|
* mutated transactions where the mutant gets mined).
|
|
|
|
*/
|
|
|
|
typedef std::multimap<COutPoint, uint256> TxSpends;
|
|
|
|
TxSpends mapTxSpends;
|
|
|
|
void AddToSpends(const COutPoint& outpoint, const uint256& wtxid);
|
|
|
|
void AddToSpends(const uint256& wtxid);
|
|
|
|
|
2015-11-26 18:42:07 +01:00
|
|
|
/* Mark a transaction (and its in-wallet descendants) as conflicting with a particular block. */
|
|
|
|
void MarkConflicted(const uint256& hashBlock, const uint256& hashTx);
|
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
void SyncMetaData(std::pair<TxSpends::iterator, TxSpends::iterator>);
|
|
|
|
|
2016-07-15 10:34:08 +02:00
|
|
|
/* the HD chain data model (external chain counters) */
|
2016-01-02 12:34:08 +01:00
|
|
|
CHDChain hdChain;
|
|
|
|
|
2016-07-30 20:27:48 +02:00
|
|
|
bool fFileBacked;
|
2016-08-02 02:14:40 +02:00
|
|
|
|
|
|
|
std::set<int64_t> setKeyPool;
|
2014-12-19 02:03:51 +01:00
|
|
|
public:
|
|
|
|
/*
|
|
|
|
* Main wallet lock.
|
|
|
|
* This lock protects all the fields added by CWallet
|
|
|
|
* except for:
|
|
|
|
* fFileBacked (immutable after instantiation)
|
|
|
|
* strWalletFile (immutable after instantiation)
|
|
|
|
*/
|
|
|
|
mutable CCriticalSection cs_wallet;
|
|
|
|
|
2016-11-11 14:32:38 +01:00
|
|
|
const std::string strWalletFile;
|
2014-12-19 02:03:51 +01:00
|
|
|
|
2016-08-02 02:14:40 +02:00
|
|
|
void LoadKeyPool(int nIndex, const CKeyPool &keypool)
|
|
|
|
{
|
|
|
|
setKeyPool.insert(nIndex);
|
|
|
|
|
|
|
|
// If no metadata exists yet, create a default with the pool key's
|
|
|
|
// creation time. Note that this may be overwritten by actually
|
|
|
|
// stored metadata for that key later, which is fine.
|
|
|
|
CKeyID keyid = keypool.vchPubKey.GetID();
|
|
|
|
if (mapKeyMetadata.count(keyid) == 0)
|
|
|
|
mapKeyMetadata[keyid] = CKeyMetadata(keypool.nTime);
|
|
|
|
}
|
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
std::map<CKeyID, CKeyMetadata> mapKeyMetadata;
|
|
|
|
|
|
|
|
typedef std::map<unsigned int, CMasterKey> MasterKeyMap;
|
|
|
|
MasterKeyMap mapMasterKeys;
|
|
|
|
unsigned int nMasterKeyMaxID;
|
|
|
|
|
|
|
|
CWallet()
|
|
|
|
{
|
|
|
|
SetNull();
|
|
|
|
}
|
|
|
|
|
2016-11-11 14:32:38 +01:00
|
|
|
CWallet(const std::string& strWalletFileIn) : strWalletFile(strWalletFileIn)
|
2014-12-19 02:03:51 +01:00
|
|
|
{
|
|
|
|
SetNull();
|
|
|
|
fFileBacked = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
~CWallet()
|
|
|
|
{
|
|
|
|
delete pwalletdbEncryption;
|
|
|
|
pwalletdbEncryption = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetNull()
|
|
|
|
{
|
|
|
|
nWalletVersion = FEATURE_BASE;
|
|
|
|
nWalletMaxVersion = FEATURE_BASE;
|
|
|
|
fFileBacked = false;
|
|
|
|
nMasterKeyMaxID = 0;
|
|
|
|
pwalletdbEncryption = NULL;
|
|
|
|
nOrderPosNext = 0;
|
|
|
|
nNextResend = 0;
|
|
|
|
nLastResend = 0;
|
|
|
|
nTimeFirstKey = 0;
|
2015-03-27 10:34:48 +01:00
|
|
|
fBroadcastTransactions = false;
|
2014-12-19 02:03:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
std::map<uint256, CWalletTx> mapWallet;
|
2015-10-19 11:19:38 +02:00
|
|
|
std::list<CAccountingEntry> laccentries;
|
|
|
|
|
|
|
|
typedef std::pair<CWalletTx*, CAccountingEntry*> TxPair;
|
|
|
|
typedef std::multimap<int64_t, TxPair > TxItems;
|
|
|
|
TxItems wtxOrdered;
|
2014-12-19 02:03:51 +01:00
|
|
|
|
|
|
|
int64_t nOrderPosNext;
|
|
|
|
std::map<uint256, int> mapRequestCount;
|
|
|
|
|
|
|
|
std::map<CTxDestination, CAddressBookData> mapAddressBook;
|
|
|
|
|
|
|
|
CPubKey vchDefaultKey;
|
|
|
|
|
|
|
|
std::set<COutPoint> setLockedCoins;
|
|
|
|
|
|
|
|
int64_t nTimeFirstKey;
|
|
|
|
|
|
|
|
const CWalletTx* GetWalletTx(const uint256& hash) const;
|
|
|
|
|
|
|
|
//! check whether we are allowed to upgrade (or already support) to the named feature
|
|
|
|
bool CanSupportFeature(enum WalletFeature wf) { AssertLockHeld(cs_wallet); return nWalletMaxVersion >= wf; }
|
|
|
|
|
2015-09-13 23:23:59 +02:00
|
|
|
/**
|
|
|
|
* populate vCoins with vector of available COutputs.
|
|
|
|
*/
|
2015-04-20 19:13:18 +02:00
|
|
|
void AvailableCoins(std::vector<COutput>& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl = NULL, bool fIncludeZeroValue=false) const;
|
2015-09-14 14:49:59 +02:00
|
|
|
|
2015-09-13 23:23:59 +02:00
|
|
|
/**
|
2015-09-14 14:49:59 +02:00
|
|
|
* Shuffle and select coins until nTargetValue is reached while avoiding
|
|
|
|
* small change; This method is stochastic for some inputs and upon
|
|
|
|
* completion the coin set and corresponding actual target value is
|
|
|
|
* assembled
|
2015-09-13 23:23:59 +02:00
|
|
|
*/
|
2016-12-02 21:29:20 +01:00
|
|
|
bool SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int nConfTheirs, uint64_t nMaxAncestors, std::vector<COutput> vCoins, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, CAmount& nValueRet) const;
|
2014-12-19 02:03:51 +01:00
|
|
|
|
|
|
|
bool IsSpent(const uint256& hash, unsigned int n) const;
|
|
|
|
|
|
|
|
bool IsLockedCoin(uint256 hash, unsigned int n) const;
|
2016-04-06 16:56:14 +02:00
|
|
|
void LockCoin(const COutPoint& output);
|
|
|
|
void UnlockCoin(const COutPoint& output);
|
2012-09-27 19:52:09 +02:00
|
|
|
void UnlockAllCoins();
|
|
|
|
void ListLockedCoins(std::vector<COutPoint>& vOutpts);
|
2012-02-27 13:19:32 +01:00
|
|
|
|
2014-10-26 08:03:12 +01:00
|
|
|
/**
|
|
|
|
* keystore implementation
|
|
|
|
* Generate a new key
|
|
|
|
*/
|
2012-05-14 19:07:52 +02:00
|
|
|
CPubKey GenerateNewKey();
|
2016-07-20 01:43:11 +02:00
|
|
|
void DeriveNewChildKey(CKeyMetadata& metadata, CKey& secret);
|
2014-10-26 08:03:12 +01:00
|
|
|
//! Adds a key to the store, and saves it to disk.
|
2013-06-20 01:13:55 +02:00
|
|
|
bool AddKeyPubKey(const CKey& key, const CPubKey &pubkey);
|
2014-10-26 08:03:12 +01:00
|
|
|
//! Adds a key to the store, without saving it to disk (used by LoadWallet)
|
2013-05-01 06:52:05 +02:00
|
|
|
bool LoadKey(const CKey& key, const CPubKey &pubkey) { return CCryptoKeyStore::AddKeyPubKey(key, pubkey); }
|
2014-10-26 08:03:12 +01:00
|
|
|
//! Load metadata (used by LoadWallet)
|
2013-06-20 01:13:55 +02:00
|
|
|
bool LoadKeyMetadata(const CPubKey &pubkey, const CKeyMetadata &metadata);
|
2011-11-07 00:05:42 +01:00
|
|
|
|
2013-12-12 08:07:59 +01:00
|
|
|
bool LoadMinVersion(int nVersion) { AssertLockHeld(cs_wallet); nWalletVersion = nVersion; nWalletMaxVersion = std::max(nWalletMaxVersion, nVersion); return true; }
|
2012-02-18 14:55:02 +01:00
|
|
|
|
2014-10-26 08:03:12 +01:00
|
|
|
//! Adds an encrypted key to the store, and saves it to disk.
|
2013-06-20 01:13:55 +02:00
|
|
|
bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret);
|
2014-10-26 08:03:12 +01:00
|
|
|
//! Adds an encrypted key to the store, without saving it to disk (used by LoadWallet)
|
2013-05-02 18:43:07 +02:00
|
|
|
bool LoadCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret);
|
2012-01-05 03:40:52 +01:00
|
|
|
bool AddCScript(const CScript& redeemScript);
|
2014-06-10 09:42:42 +02:00
|
|
|
bool LoadCScript(const CScript& redeemScript);
|
Add wallet privkey encryption.
This commit adds support for ckeys, or enCrypted private keys, to the wallet.
All keys are stored in memory in their encrypted form and thus the passphrase
is required from the user to spend coins, or to create new addresses.
Keys are encrypted with AES-256-CBC using OpenSSL's EVP library. The key is
calculated via EVP_BytesToKey using SHA512 with (by default) 25000 rounds and
a random salt.
By default, the user's wallet remains unencrypted until they call the RPC
command encryptwallet <passphrase> or, from the GUI menu, Options->
Encrypt Wallet.
When the user is attempting to call RPC functions which require the password
to unlock the wallet, an error will be returned unless they call
walletpassphrase <passphrase> <time to keep key in memory> first.
A keypoolrefill command has been added which tops up the users keypool
(requiring the passphrase via walletpassphrase first).
keypoolsize has been added to the output of getinfo to show the user the
number of keys left before they need to specify their passphrase (and call
keypoolrefill).
Note that walletpassphrase will automatically fill keypool in a separate
thread which it spawns when the passphrase is set. This could cause some
delays in other threads waiting for locks on the wallet passphrase, including
one which could cause the passphrase to be stored longer than expected,
however it will not allow the passphrase to be used longer than expected as
ThreadCleanWalletPassphrase will attempt to get a lock on the key as soon
as the specified lock time has arrived.
When the keypool runs out (and wallet is locked) GetOrReuseKeyFromPool
returns vchDefaultKey, meaning miners may start to generate many blocks to
vchDefaultKey instead of a new key each time.
A walletpassphrasechange <oldpassphrase> <newpassphrase> has been added to
allow the user to change their password via RPC.
Whenever keying material (unencrypted private keys, the user's passphrase,
the wallet's AES key) is stored unencrypted in memory, any reasonable attempt
is made to mlock/VirtualLock that memory before storing the keying material.
This is not true in several (commented) cases where mlock/VirtualLocking the
memory is not possible.
Although encryption of private keys in memory can be very useful on desktop
systems (as some small amount of protection against stupid viruses), on an
RPC server, the password is entered fairly insecurely. Thus, the only main
advantage encryption has for RPC servers is for RPC servers that do not spend
coins, except in rare cases, eg. a webserver of a merchant which only receives
payment except for cases of manual intervention.
Thanks to jgarzik for the original patch and sipa, gmaxwell and many others
for all their input.
Conflicts:
src/wallet.cpp
2011-07-08 15:47:35 +02:00
|
|
|
|
2014-10-26 08:03:12 +01:00
|
|
|
//! Adds a destination data tuple to the store, and saves it to disk
|
2013-11-18 16:55:54 +01:00
|
|
|
bool AddDestData(const CTxDestination &dest, const std::string &key, const std::string &value);
|
2014-10-26 08:03:12 +01:00
|
|
|
//! Erases a destination data tuple in the store and on disk
|
2013-11-18 16:55:54 +01:00
|
|
|
bool EraseDestData(const CTxDestination &dest, const std::string &key);
|
2014-10-26 08:03:12 +01:00
|
|
|
//! Adds a destination data tuple to the store, without saving it to disk
|
2013-11-18 16:55:54 +01:00
|
|
|
bool LoadDestData(const CTxDestination &dest, const std::string &key, const std::string &value);
|
2014-10-26 08:03:12 +01:00
|
|
|
//! Look up a destination data tuple in the store, return true if found false otherwise
|
2013-11-18 16:55:54 +01:00
|
|
|
bool GetDestData(const CTxDestination &dest, const std::string &key, std::string *value) const;
|
|
|
|
|
2014-10-26 08:03:12 +01:00
|
|
|
//! Adds a watch-only address to the store, and saves it to disk.
|
2014-06-09 21:11:59 +02:00
|
|
|
bool AddWatchOnly(const CScript &dest);
|
2014-07-26 21:05:11 +02:00
|
|
|
bool RemoveWatchOnly(const CScript &dest);
|
2014-10-26 08:03:12 +01:00
|
|
|
//! Adds a watch-only address to the store, without saving it to disk (used by LoadWallet)
|
2014-06-09 21:11:59 +02:00
|
|
|
bool LoadWatchOnly(const CScript &dest);
|
2013-07-26 01:06:01 +02:00
|
|
|
|
2011-11-26 07:02:04 +01:00
|
|
|
bool Unlock(const SecureString& strWalletPassphrase);
|
|
|
|
bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase);
|
|
|
|
bool EncryptWallet(const SecureString& strWalletPassphrase);
|
2011-06-25 14:57:32 +02:00
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
void GetKeyBirthTimes(std::map<CKeyID, int64_t> &mapKeyBirth) const;
|
2013-04-29 19:50:40 +02:00
|
|
|
|
2014-10-26 08:03:12 +01:00
|
|
|
/**
|
|
|
|
* Increment the next transaction order id
|
|
|
|
* @return next transaction order id
|
2012-09-08 06:55:36 +02:00
|
|
|
*/
|
2013-04-13 07:13:08 +02:00
|
|
|
int64_t IncOrderPosNext(CWalletDB *pwalletdb = NULL);
|
2016-09-10 04:21:44 +02:00
|
|
|
DBErrors ReorderTransactions();
|
2016-06-02 15:00:59 +02:00
|
|
|
bool AccountMove(std::string strFrom, std::string strTo, CAmount nAmount, std::string strComment = "");
|
2016-06-03 08:16:42 +02:00
|
|
|
bool GetAccountPubkey(CPubKey &pubKey, std::string strAccount, bool bForceNew = false);
|
2012-09-08 06:55:36 +02:00
|
|
|
|
2011-07-13 11:56:38 +02:00
|
|
|
void MarkDirty();
|
2016-06-08 06:41:03 +02:00
|
|
|
bool AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose=true);
|
2016-06-08 06:25:31 +02:00
|
|
|
bool LoadToWallet(const CWalletTx& wtxIn);
|
2016-04-26 13:55:13 +02:00
|
|
|
void SyncTransaction(const CTransaction& tx, const CBlockIndex *pindex, int posInBlock);
|
|
|
|
bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlockIndex* pIndex, int posInBlock, bool fUpdate);
|
2011-06-26 19:23:24 +02:00
|
|
|
int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false);
|
|
|
|
void ReacceptWalletTransactions();
|
2016-05-25 02:56:17 +02:00
|
|
|
void ResendWalletTransactions(int64_t nBestBlockTime, CConnman* connman);
|
|
|
|
std::vector<uint256> ResendWalletTransactionsBefore(int64_t nTime, CConnman* connman);
|
2014-04-23 00:46:19 +02:00
|
|
|
CAmount GetBalance() const;
|
|
|
|
CAmount GetUnconfirmedBalance() const;
|
|
|
|
CAmount GetImmatureBalance() const;
|
|
|
|
CAmount GetWatchOnlyBalance() const;
|
|
|
|
CAmount GetUnconfirmedWatchOnlyBalance() const;
|
|
|
|
CAmount GetImmatureWatchOnlyBalance() const;
|
2015-09-14 14:49:59 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Insert additional inputs into the transaction by
|
|
|
|
* calling CreateTransaction();
|
|
|
|
*/
|
2016-05-06 11:01:50 +02:00
|
|
|
bool FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, bool overrideEstimatedFeeRate, const CFeeRate& specificFeeRate, int& nChangePosInOut, std::string& strFailReason, bool includeWatching, bool lockUnspents, const CTxDestination& destChange = CNoDestination());
|
2015-09-14 14:49:59 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new transaction paying the recipients with a set of coins
|
|
|
|
* selected by SelectCoins(); Also create the change output, when needed
|
2016-03-30 03:04:22 +02:00
|
|
|
* @note passing nChangePosInOut as -1 will result in setting a random position
|
2015-09-14 14:49:59 +02:00
|
|
|
*/
|
2016-03-30 03:04:22 +02:00
|
|
|
bool CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, int& nChangePosInOut,
|
2015-04-25 03:29:00 +02:00
|
|
|
std::string& strFailReason, const CCoinControl *coinControl = NULL, bool sign = true);
|
2016-10-25 20:27:04 +02:00
|
|
|
bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey, CConnman* connman, CValidationState& state);
|
2011-06-26 19:23:24 +02:00
|
|
|
|
2016-09-10 03:53:23 +02:00
|
|
|
void ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& entries);
|
2016-09-10 04:22:59 +02:00
|
|
|
bool AddAccountingEntry(const CAccountingEntry&);
|
|
|
|
bool AddAccountingEntry(const CAccountingEntry&, CWalletDB *pwalletdb);
|
2015-10-19 11:19:38 +02:00
|
|
|
|
2014-07-03 20:25:32 +02:00
|
|
|
static CFeeRate minTxFee;
|
2016-01-05 19:11:34 +01:00
|
|
|
static CFeeRate fallbackFee;
|
2015-10-25 02:47:04 +02:00
|
|
|
/**
|
|
|
|
* Estimate the minimum fee considering user set parameters
|
|
|
|
* and the required fee
|
|
|
|
*/
|
2014-04-23 00:46:19 +02:00
|
|
|
static CAmount GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool& pool);
|
2015-10-25 02:47:04 +02:00
|
|
|
/**
|
|
|
|
* Return the minimum required fee taking into account the
|
|
|
|
* floating relay fee and user set minimum transaction fee
|
|
|
|
*/
|
|
|
|
static CAmount GetRequiredFee(unsigned int nTxBytes);
|
2014-05-27 21:44:57 +02:00
|
|
|
|
2011-11-17 20:01:25 +01:00
|
|
|
bool NewKeyPool();
|
2013-06-25 22:07:29 +02:00
|
|
|
bool TopUpKeyPool(unsigned int kpSize = 0);
|
2013-04-13 07:13:08 +02:00
|
|
|
void ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool);
|
|
|
|
void KeepKey(int64_t nIndex);
|
|
|
|
void ReturnKey(int64_t nIndex);
|
2013-08-23 21:54:50 +02:00
|
|
|
bool GetKeyFromPool(CPubKey &key);
|
2013-04-13 07:13:08 +02:00
|
|
|
int64_t GetOldestKeyPoolTime();
|
2013-04-29 19:50:40 +02:00
|
|
|
void GetAllReserveKeys(std::set<CKeyID>& setAddress) const;
|
2011-06-26 19:23:24 +02:00
|
|
|
|
2012-08-20 19:43:33 +02:00
|
|
|
std::set< std::set<CTxDestination> > GetAddressGroupings();
|
2014-04-23 00:46:19 +02:00
|
|
|
std::map<CTxDestination, CAmount> GetAddressBalances();
|
2012-08-01 18:48:42 +02:00
|
|
|
|
2016-05-17 02:11:24 +02:00
|
|
|
CAmount GetAccountBalance(const std::string& strAccount, int nMinDepth, const isminefilter& filter);
|
|
|
|
CAmount GetAccountBalance(CWalletDB& walletdb, const std::string& strAccount, int nMinDepth, const isminefilter& filter);
|
2015-05-31 15:36:44 +02:00
|
|
|
std::set<CTxDestination> GetAccountAddresses(const std::string& strAccount) const;
|
2013-07-16 01:01:09 +02:00
|
|
|
|
2013-07-26 01:06:01 +02:00
|
|
|
isminetype IsMine(const CTxIn& txin) const;
|
2014-04-23 00:46:19 +02:00
|
|
|
CAmount GetDebit(const CTxIn& txin, const isminefilter& filter) const;
|
2015-02-04 23:19:29 +01:00
|
|
|
isminetype IsMine(const CTxOut& txout) const;
|
|
|
|
CAmount GetCredit(const CTxOut& txout, const isminefilter& filter) const;
|
2014-12-19 02:03:51 +01:00
|
|
|
bool IsChange(const CTxOut& txout) const;
|
2015-02-04 23:19:29 +01:00
|
|
|
CAmount GetChange(const CTxOut& txout) const;
|
|
|
|
bool IsMine(const CTransaction& tx) const;
|
2014-12-19 02:03:51 +01:00
|
|
|
/** should probably be renamed to IsRelevantToMe */
|
2015-02-04 23:19:29 +01:00
|
|
|
bool IsFromMe(const CTransaction& tx) const;
|
|
|
|
CAmount GetDebit(const CTransaction& tx, const isminefilter& filter) const;
|
|
|
|
CAmount GetCredit(const CTransaction& tx, const isminefilter& filter) const;
|
|
|
|
CAmount GetChange(const CTransaction& tx) const;
|
2014-12-19 02:03:51 +01:00
|
|
|
void SetBestChain(const CBlockLocator& loc);
|
2011-06-26 19:23:24 +02:00
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
DBErrors LoadWallet(bool& fFirstRunRet);
|
|
|
|
DBErrors ZapWalletTx(std::vector<CWalletTx>& vWtx);
|
2016-03-07 14:51:06 +01:00
|
|
|
DBErrors ZapSelectTx(std::vector<uint256>& vHashIn, std::vector<uint256>& vHashOut);
|
2011-06-26 19:23:24 +02:00
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
bool SetAddressBook(const CTxDestination& address, const std::string& strName, const std::string& purpose);
|
2012-05-28 01:06:09 +02:00
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
bool DelAddressBook(const CTxDestination& address);
|
2012-05-28 20:45:12 +02:00
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
void UpdatedTransaction(const uint256 &hashTx);
|
2011-06-26 19:23:24 +02:00
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
void Inventory(const uint256 &hash)
|
2011-06-26 19:23:24 +02:00
|
|
|
{
|
2014-12-19 02:03:51 +01:00
|
|
|
{
|
|
|
|
LOCK(cs_wallet);
|
|
|
|
std::map<uint256, int>::iterator mi = mapRequestCount.find(hash);
|
|
|
|
if (mi != mapRequestCount.end())
|
|
|
|
(*mi).second++;
|
|
|
|
}
|
2011-06-26 19:23:24 +02:00
|
|
|
}
|
|
|
|
|
2015-07-01 08:32:30 +02:00
|
|
|
void GetScriptForMining(boost::shared_ptr<CReserveScript> &script);
|
2015-07-01 16:06:49 +02:00
|
|
|
void ResetRequestCount(const uint256 &hash)
|
2015-04-10 12:49:01 +02:00
|
|
|
{
|
|
|
|
LOCK(cs_wallet);
|
2015-07-01 16:06:49 +02:00
|
|
|
mapRequestCount[hash] = 0;
|
2015-04-10 12:49:01 +02:00
|
|
|
};
|
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
unsigned int GetKeyPoolSize()
|
2011-06-28 23:45:22 +02:00
|
|
|
{
|
2014-12-19 02:03:51 +01:00
|
|
|
AssertLockHeld(cs_wallet); // setKeyPool
|
|
|
|
return setKeyPool.size();
|
2011-06-28 23:45:22 +02:00
|
|
|
}
|
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
bool SetDefaultKey(const CPubKey &vchPubKey);
|
2011-06-26 19:23:24 +02:00
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
//! signify that a particular wallet feature is now used. this may change nWalletVersion and nWalletMaxVersion if those are lower
|
|
|
|
bool SetMinVersion(enum WalletFeature, CWalletDB* pwalletdbIn = NULL, bool fExplicit = false);
|
2011-06-26 19:23:24 +02:00
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
//! change which version we're allowed to upgrade to (note that this does not immediately imply upgrading to that format)
|
|
|
|
bool SetMaxVersion(int nVersion);
|
2011-06-26 19:23:24 +02:00
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
//! get the current wallet format (the oldest client version guaranteed to understand this wallet)
|
|
|
|
int GetVersion() { LOCK(cs_wallet); return nWalletVersion; }
|
2011-06-26 19:23:24 +02:00
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
//! Get wallet transactions that conflict with given transaction (spend same outputs)
|
|
|
|
std::set<uint256> GetConflicts(const uint256& txid) const;
|
2011-06-26 19:23:24 +02:00
|
|
|
|
2015-02-04 21:19:27 +01:00
|
|
|
//! Flush wallet (bitdb flush)
|
|
|
|
void Flush(bool shutdown=false);
|
|
|
|
|
|
|
|
//! Verify the wallet database and perform salvage if required
|
2016-03-15 10:30:37 +01:00
|
|
|
static bool Verify();
|
2015-02-04 21:19:27 +01:00
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
/**
|
|
|
|
* Address book entry changed.
|
|
|
|
* @note called with lock cs_wallet held.
|
|
|
|
*/
|
|
|
|
boost::signals2::signal<void (CWallet *wallet, const CTxDestination
|
|
|
|
&address, const std::string &label, bool isMine,
|
|
|
|
const std::string &purpose,
|
|
|
|
ChangeType status)> NotifyAddressBookChanged;
|
2011-06-26 19:23:24 +02:00
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
/**
|
|
|
|
* Wallet transaction added, removed or updated.
|
|
|
|
* @note called with lock cs_wallet held.
|
|
|
|
*/
|
|
|
|
boost::signals2::signal<void (CWallet *wallet, const uint256 &hashTx,
|
|
|
|
ChangeType status)> NotifyTransactionChanged;
|
2011-06-26 19:23:24 +02:00
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
/** Show progress e.g. for rescan */
|
|
|
|
boost::signals2::signal<void (const std::string &title, int nProgress)> ShowProgress;
|
2014-02-14 02:12:51 +01:00
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
/** Watch-only address added */
|
|
|
|
boost::signals2::signal<void (bool fHaveWatchOnly)> NotifyWatchonlyChanged;
|
2015-03-27 10:34:48 +01:00
|
|
|
|
|
|
|
/** Inquire whether this wallet broadcasts transactions. */
|
|
|
|
bool GetBroadcastTransactions() const { return fBroadcastTransactions; }
|
|
|
|
/** Set whether this wallet broadcasts transactions. */
|
|
|
|
void SetBroadcastTransactions(bool broadcast) { fBroadcastTransactions = broadcast; }
|
2016-01-07 22:31:27 +01:00
|
|
|
|
|
|
|
/* Mark a transaction (and it in-wallet descendants) as abandoned so its inputs may be respent. */
|
|
|
|
bool AbandonTransaction(const uint256& hashTx);
|
2016-02-22 10:48:44 +01:00
|
|
|
|
|
|
|
/* Returns the wallets help message */
|
|
|
|
static std::string GetWalletHelpString(bool showDebug);
|
2016-02-22 12:07:55 +01:00
|
|
|
|
2016-03-15 10:30:37 +01:00
|
|
|
/* Initializes the wallet, returns a new CWallet instance or a null pointer in case of an error */
|
|
|
|
static bool InitLoadWallet();
|
|
|
|
|
2016-10-20 09:22:13 +02:00
|
|
|
/**
|
|
|
|
* Wallet post-init setup
|
|
|
|
* Gives the wallet a chance to register repetitive tasks and complete post-init tasks
|
|
|
|
*/
|
|
|
|
void postInitProcess(boost::thread_group& threadGroup);
|
|
|
|
|
2016-03-15 10:30:37 +01:00
|
|
|
/* Wallets parameter interaction */
|
|
|
|
static bool ParameterInteraction();
|
2016-05-17 02:31:16 +02:00
|
|
|
|
|
|
|
bool BackupWallet(const std::string& strDest);
|
2016-01-02 12:34:08 +01:00
|
|
|
|
2016-07-15 10:34:08 +02:00
|
|
|
/* Set the HD chain model (chain child index counters) */
|
2016-01-02 12:34:08 +01:00
|
|
|
bool SetHDChain(const CHDChain& chain, bool memonly);
|
2016-06-15 10:49:29 +02:00
|
|
|
const CHDChain& GetHDChain() { return hdChain; }
|
2016-01-02 12:34:08 +01:00
|
|
|
|
2016-08-17 14:09:47 +02:00
|
|
|
/* Returns true if HD is enabled */
|
|
|
|
bool IsHDEnabled();
|
|
|
|
|
2016-07-21 21:19:02 +02:00
|
|
|
/* Generates a new HD master key (will not be activated) */
|
|
|
|
CPubKey GenerateNewHDMasterKey();
|
|
|
|
|
2016-07-15 10:34:08 +02:00
|
|
|
/* Set the current HD master key (will reset the chain child index counters) */
|
2016-07-21 21:19:02 +02:00
|
|
|
bool SetHDMasterKey(const CPubKey& key);
|
2011-06-26 19:23:24 +02:00
|
|
|
};
|
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
/** A key allocated from the key pool. */
|
2015-07-01 08:32:30 +02:00
|
|
|
class CReserveKey : public CReserveScript
|
2012-02-27 13:19:32 +01:00
|
|
|
{
|
2014-12-19 02:03:51 +01:00
|
|
|
protected:
|
|
|
|
CWallet* pwallet;
|
|
|
|
int64_t nIndex;
|
|
|
|
CPubKey vchPubKey;
|
2012-02-27 13:19:32 +01:00
|
|
|
public:
|
2014-12-19 02:03:51 +01:00
|
|
|
CReserveKey(CWallet* pwalletIn)
|
2012-02-27 13:19:32 +01:00
|
|
|
{
|
2014-12-19 02:03:51 +01:00
|
|
|
nIndex = -1;
|
|
|
|
pwallet = pwalletIn;
|
2012-02-27 13:19:32 +01:00
|
|
|
}
|
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
~CReserveKey()
|
|
|
|
{
|
|
|
|
ReturnKey();
|
overhaul serialization code
The implementation of each class' serialization/deserialization is no longer
passed within a macro. The implementation now lies within a template of form:
template <typename T, typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0;
/* CODE */
return nSerSize;
}
In cases when codepath should depend on whether or not we are just deserializing
(old fGetSize, fWrite, fRead flags) an additional clause can be used:
bool fRead = boost::is_same<Operation, CSerActionUnserialize>();
The IMPLEMENT_SERIALIZE macro will now be a freestanding clause added within
class' body (similiar to Qt's Q_OBJECT) to implement GetSerializeSize,
Serialize and Unserialize. These are now wrappers around
the "SerializationOp" template.
2014-08-20 08:42:31 +02:00
|
|
|
}
|
2011-06-26 19:23:24 +02:00
|
|
|
|
2014-12-19 02:03:51 +01:00
|
|
|
void ReturnKey();
|
|
|
|
bool GetReservedKey(CPubKey &pubkey);
|
|
|
|
void KeepKey();
|
2015-07-01 08:32:30 +02:00
|
|
|
void KeepScript() { KeepKey(); }
|
2014-12-19 02:03:51 +01:00
|
|
|
};
|
2011-06-26 19:23:24 +02:00
|
|
|
|
|
|
|
|
2014-10-26 08:03:12 +01:00
|
|
|
/**
|
|
|
|
* Account information.
|
2012-03-26 16:48:23 +02:00
|
|
|
* Stored in wallet with key "acc"+string account name.
|
|
|
|
*/
|
2011-06-26 19:23:24 +02:00
|
|
|
class CAccount
|
|
|
|
{
|
|
|
|
public:
|
2012-05-14 19:07:52 +02:00
|
|
|
CPubKey vchPubKey;
|
2011-06-26 19:23:24 +02:00
|
|
|
|
|
|
|
CAccount()
|
|
|
|
{
|
|
|
|
SetNull();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetNull()
|
|
|
|
{
|
2012-05-14 19:07:52 +02:00
|
|
|
vchPubKey = CPubKey();
|
2011-06-26 19:23:24 +02:00
|
|
|
}
|
|
|
|
|
2014-09-02 09:58:09 +02:00
|
|
|
ADD_SERIALIZE_METHODS;
|
overhaul serialization code
The implementation of each class' serialization/deserialization is no longer
passed within a macro. The implementation now lies within a template of form:
template <typename T, typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0;
/* CODE */
return nSerSize;
}
In cases when codepath should depend on whether or not we are just deserializing
(old fGetSize, fWrite, fRead flags) an additional clause can be used:
bool fRead = boost::is_same<Operation, CSerActionUnserialize>();
The IMPLEMENT_SERIALIZE macro will now be a freestanding clause added within
class' body (similiar to Qt's Q_OBJECT) to implement GetSerializeSize,
Serialize and Unserialize. These are now wrappers around
the "SerializationOp" template.
2014-08-20 08:42:31 +02:00
|
|
|
|
2014-08-20 22:44:38 +02:00
|
|
|
template <typename Stream, typename Operation>
|
2016-10-29 01:29:17 +02:00
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action) {
|
|
|
|
int nVersion = s.GetVersion();
|
|
|
|
if (!(s.GetType() & SER_GETHASH))
|
2011-06-26 19:23:24 +02:00
|
|
|
READWRITE(nVersion);
|
|
|
|
READWRITE(vchPubKey);
|
overhaul serialization code
The implementation of each class' serialization/deserialization is no longer
passed within a macro. The implementation now lies within a template of form:
template <typename T, typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0;
/* CODE */
return nSerSize;
}
In cases when codepath should depend on whether or not we are just deserializing
(old fGetSize, fWrite, fRead flags) an additional clause can be used:
bool fRead = boost::is_same<Operation, CSerActionUnserialize>();
The IMPLEMENT_SERIALIZE macro will now be a freestanding clause added within
class' body (similiar to Qt's Q_OBJECT) to implement GetSerializeSize,
Serialize and Unserialize. These are now wrappers around
the "SerializationOp" template.
2014-08-20 08:42:31 +02:00
|
|
|
}
|
2011-06-26 19:23:24 +02:00
|
|
|
};
|
|
|
|
|
2015-03-21 18:15:31 +01:00
|
|
|
#endif // BITCOIN_WALLET_WALLET_H
|