Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.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) 2018 The Bitcoin developers | // Copyright (c) 2018 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_WALLET_H | #ifndef BITCOIN_WALLET_WALLET_H | ||||
#define BITCOIN_WALLET_WALLET_H | #define BITCOIN_WALLET_WALLET_H | ||||
#include <amount.h> | #include <amount.h> | ||||
#include <outputtype.h> | |||||
#include <script/ismine.h> | #include <script/ismine.h> | ||||
#include <script/sign.h> | #include <script/sign.h> | ||||
#include <streams.h> | #include <streams.h> | ||||
#include <tinyformat.h> | #include <tinyformat.h> | ||||
#include <ui_interface.h> | #include <ui_interface.h> | ||||
#include <util/strencodings.h> | #include <util/strencodings.h> | ||||
#include <util/system.h> | #include <util/system.h> | ||||
#include <validationinterface.h> | #include <validationinterface.h> | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | enum WalletFeature { | ||||
FEATURE_NO_DEFAULT_KEY = 190700, | FEATURE_NO_DEFAULT_KEY = 190700, | ||||
// Upgraded to HD SPLIT and can have a pre-split keypool | // Upgraded to HD SPLIT and can have a pre-split keypool | ||||
FEATURE_PRE_SPLIT_KEYPOOL = 200300, | FEATURE_PRE_SPLIT_KEYPOOL = 200300, | ||||
FEATURE_LATEST = FEATURE_PRE_SPLIT_KEYPOOL, | FEATURE_LATEST = FEATURE_PRE_SPLIT_KEYPOOL, | ||||
}; | }; | ||||
enum class OutputType { | |||||
LEGACY, | |||||
/** | |||||
* Special output type for change outputs only. Automatically choose type | |||||
* based on address type setting and the types other of non-change outputs | |||||
* (see -changetype option documentation and implementation in | |||||
* CWallet::TransactionChangeType for details). | |||||
*/ | |||||
CHANGE_AUTO, | |||||
}; | |||||
//! Default for -addresstype | //! Default for -addresstype | ||||
constexpr OutputType DEFAULT_ADDRESS_TYPE{OutputType::LEGACY}; | constexpr OutputType DEFAULT_ADDRESS_TYPE{OutputType::LEGACY}; | ||||
//! Default for -changetype | //! Default for -changetype | ||||
constexpr OutputType DEFAULT_CHANGE_TYPE{OutputType::CHANGE_AUTO}; | constexpr OutputType DEFAULT_CHANGE_TYPE{OutputType::CHANGE_AUTO}; | ||||
/** A key pool entry */ | /** A key pool entry */ | ||||
class CKeyPool { | class CKeyPool { | ||||
▲ Show 20 Lines • Show All 1,224 Lines • ▼ Show 20 Lines | public: | ||||
*/ | */ | ||||
void LearnRelatedScripts(const CPubKey &key, OutputType); | void LearnRelatedScripts(const CPubKey &key, OutputType); | ||||
/** | /** | ||||
* Same as LearnRelatedScripts, but when the OutputType is not known (and | * Same as LearnRelatedScripts, but when the OutputType is not known (and | ||||
* could be anything). | * could be anything). | ||||
*/ | */ | ||||
void LearnAllRelatedScripts(const CPubKey &key); | void LearnAllRelatedScripts(const CPubKey &key); | ||||
/** | |||||
* Get a destination of the requested type (if possible) to the specified | |||||
* script. This function will automatically add the necessary scripts to the | |||||
* wallet. | |||||
*/ | |||||
CTxDestination AddAndGetDestinationForScript(const CScript &script, | |||||
OutputType); | |||||
}; | }; | ||||
/** A key allocated from the key pool. */ | /** A key allocated from the key pool. */ | ||||
class CReserveKey final : public CReserveScript { | class CReserveKey final : public CReserveScript { | ||||
protected: | protected: | ||||
CWallet *pwallet; | CWallet *pwallet; | ||||
int64_t nIndex{-1}; | int64_t nIndex{-1}; | ||||
CPubKey vchPubKey; | CPubKey vchPubKey; | ||||
Show All 33 Lines | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
if (!(s.GetType() & SER_GETHASH)) { | if (!(s.GetType() & SER_GETHASH)) { | ||||
READWRITE(nVersion); | READWRITE(nVersion); | ||||
} | } | ||||
READWRITE(vchPubKey); | READWRITE(vchPubKey); | ||||
} | } | ||||
}; | }; | ||||
bool ParseOutputType(const std::string &str, OutputType &output_type); | |||||
const std::string &FormatOutputType(OutputType type); | |||||
/** | |||||
* Get a destination of the requested type (if possible) to the specified key. | |||||
* The caller must make sure LearnRelatedScripts has been called beforehand. | |||||
*/ | |||||
CTxDestination GetDestinationForKey(const CPubKey &key, OutputType); | |||||
/** | |||||
* Get all destinations (potentially) supported by the wallet for the given key. | |||||
*/ | |||||
std::vector<CTxDestination> GetAllDestinationsForKey(const CPubKey &key); | |||||
/** RAII object to check and reserve a wallet rescan */ | /** RAII object to check and reserve a wallet rescan */ | ||||
class WalletRescanReserver { | class WalletRescanReserver { | ||||
private: | private: | ||||
CWallet *m_wallet; | CWallet *m_wallet; | ||||
bool m_could_reserve; | bool m_could_reserve; | ||||
public: | public: | ||||
explicit WalletRescanReserver(CWallet *w) | explicit WalletRescanReserver(CWallet *w) | ||||
Show All 36 Lines |