6 #ifndef BITCOIN_WALLET_WALLET_H 7 #define BITCOIN_WALLET_WALLET_H 36 bool AddWallet(
const std::shared_ptr<CWallet>& wallet);
37 bool RemoveWallet(
const std::shared_ptr<CWallet>& wallet);
39 std::vector<std::shared_ptr<CWallet>>
GetWallets();
46 static const unsigned int DEFAULT_KEYPOOL_SIZE = 1000;
50 static const CAmount DEFAULT_FALLBACK_FEE = 20000;
52 static const CAmount DEFAULT_DISCARD_FEE = 10000;
54 static const CAmount DEFAULT_TRANSACTION_MINFEE = 1000;
56 static const CAmount WALLET_INCREMENTAL_RELAY_FEE = 5000;
58 static const bool DEFAULT_SPEND_ZEROCONF_CHANGE =
true;
60 static const bool DEFAULT_WALLET_REJECT_LONG_CHAINS =
false;
62 static const bool DEFAULT_AVOIDPARTIALSPENDS =
false;
64 static const unsigned int DEFAULT_TX_CONFIRM_TARGET = 6;
66 static const bool DEFAULT_WALLET_RBF =
false;
67 static const bool DEFAULT_WALLETBROADCAST =
true;
68 static const bool DEFAULT_DISABLE_WALLET =
false;
130 template <
typename Stream,
typename Operation>
132 int nVersion = s.GetVersion();
137 if (ser_action.ForRead()) {
141 catch (std::ios_base::failure&) {
149 catch (std::ios_base::failure&) {
185 static inline void ReadOrderPos(int64_t& nOrderPos,
mapValue_t& mapValue)
187 if (!mapValue.count(
"n"))
192 nOrderPos =
atoi64(mapValue[
"n"].c_str());
196 static inline void WriteOrderPos(
const int64_t& nOrderPos,
mapValue_t& mapValue)
200 mapValue[
"n"] =
i64tostr(nOrderPos);
230 SetTx(MakeTransactionRef());
236 SetTx(std::move(arg));
253 template <
typename Stream,
typename Operation>
255 std::vector<uint256> vMerkleBranch;
327 std::vector<std::pair<std::string, std::string> >
vOrderForm;
380 fTimeReceivedIsTxTime =
false;
384 fDebitCached =
false;
385 fCreditCached =
false;
386 fImmatureCreditCached =
false;
387 fAvailableCreditCached =
false;
388 fWatchDebitCached =
false;
389 fWatchCreditCached =
false;
390 fImmatureWatchCreditCached =
false;
391 fAvailableWatchCreditCached =
false;
392 fChangeCached =
false;
396 nImmatureCreditCached = 0;
397 nAvailableCreditCached = 0;
398 nWatchDebitCached = 0;
399 nWatchCreditCached = 0;
400 nAvailableWatchCreditCached = 0;
401 nImmatureWatchCreditCached = 0;
406 template<
typename Stream>
412 mapValueCopy[
"fromaccount"] =
"";
413 WriteOrderPos(nOrderPos, mapValueCopy);
415 mapValueCopy[
"timesmart"] =
strprintf(
"%u", nTimeSmart);
418 s << static_cast<const CMerkleTx&>(*this);
419 std::vector<CMerkleTx> vUnused;
420 s << vUnused << mapValueCopy << vOrderForm << fTimeReceivedIsTxTime << nTimeReceived << fFromMe << fSpent;
423 template<
typename Stream>
430 std::vector<CMerkleTx> vUnused;
431 s >> vUnused >> mapValue >> vOrderForm >> fTimeReceivedIsTxTime >> nTimeReceived >> fFromMe >> fSpent;
433 ReadOrderPos(nOrderPos, mapValue);
434 nTimeSmart = mapValue.count(
"timesmart") ? (
unsigned int)
atoi64(mapValue[
"timesmart"]) : 0;
436 mapValue.erase(
"fromaccount");
437 mapValue.erase(
"spent");
439 mapValue.erase(
"timesmart");
445 fCreditCached =
false;
446 fAvailableCreditCached =
false;
447 fImmatureCreditCached =
false;
448 fWatchDebitCached =
false;
449 fWatchCreditCached =
false;
450 fAvailableWatchCreditCached =
false;
451 fImmatureWatchCreditCached =
false;
452 fDebitCached =
false;
453 fChangeCached =
false;
475 int GetSpendSize(
unsigned int out,
bool use_max_sig = false)
const 480 void GetAmounts(std::list<COutputEntry>& listReceived,
485 return (GetDebit(
filter) > 0);
491 bool InMempool()
const;
494 int64_t GetTxTime() const;
537 COutput(
const CWalletTx *txIn,
int iIn,
int nDepthIn,
bool fSpendableIn,
bool fSolvableIn,
bool fSafeIn,
bool use_max_sig_in =
false)
539 tx = txIn; i = iIn; nDepth = nDepthIn; fSpendable = fSpendableIn; fSolvable = fSolvableIn; fSafe = fSafeIn; nInputBytes = -1; use_max_sig = use_max_sig_in;
542 if (fSpendable &&
tx) {
543 nInputBytes =
tx->GetSpendSize(i, use_max_sig);
547 std::string ToString()
const;
570 template <
typename Stream,
typename Operation>
572 int nVersion = s.GetVersion();
585 size_t change_output_size = 0;
586 size_t change_spend_size = 0;
588 size_t tx_noinputs_size = 0;
590 CoinSelectionParams(
bool use_bnb,
size_t change_output_size,
size_t change_spend_size,
CFeeRate effective_fee,
size_t tx_noinputs_size) : use_bnb(use_bnb), change_output_size(change_output_size), change_spend_size(change_spend_size), effective_fee(effective_fee), tx_noinputs_size(tx_noinputs_size) {}
602 std::atomic<bool> fAbortRescan{
false};
603 std::atomic<bool> fScanningWallet{
false};
615 int64_t nNextResend = 0;
616 int64_t nLastResend = 0;
617 bool fBroadcastTransactions =
false;
624 typedef std::multimap<COutPoint, uint256>
TxSpends;
662 std::set<int64_t> setInternalKeyPool;
664 std::set<int64_t> set_pre_split_keypool;
667 std::atomic<uint64_t> m_wallet_flags{0};
724 bool SelectCoins(
const std::vector<COutput>& vAvailableCoins,
const CAmount& nTargetValue, std::set<CInputCoin>& setCoinsRet,
CAmount& nValueRet,
729 const std::string&
GetName()
const {
return m_name; }
742 unsigned int nMasterKeyMaxID = 0;
751 delete encrypted_batch;
752 encrypted_batch =
nullptr;
757 typedef std::multimap<int64_t, CWalletTx*>
TxItems;
761 uint64_t nAccountingEntryNumber = 0;
775 void AvailableCoins(std::vector<COutput>& vCoins,
bool fOnlySafe=
true,
const CCoinControl *coinControl =
nullptr,
const CAmount& nMinimumAmount = 1,
const CAmount& nMaximumAmount = MAX_MONEY,
const CAmount& nMinimumSumAmount = MAX_MONEY,
const uint64_t nMaximumCount = 0,
const int nMinDepth = 0,
const int nMaxDepth = 9999999) const
EXCLUSIVE_LOCKS_REQUIRED(
cs_main,
cs_wallet);
808 void AbortRescan() { fAbortRescan =
true; }
830 bool AddCryptedKey(
const CPubKey &vchPubKey,
const std::vector<unsigned char> &vchCryptedSecret)
override;
832 bool LoadCryptedKey(
const CPubKey &vchPubKey,
const std::vector<unsigned char> &vchCryptedSecret);
833 bool AddCScript(
const CScript& redeemScript)
override;
834 bool LoadCScript(
const CScript& redeemScript);
837 bool AddDestData(
const CTxDestination &dest,
const std::string &key,
const std::string &value);
839 bool EraseDestData(
const CTxDestination &dest,
const std::string &key);
841 void LoadDestData(
const CTxDestination &dest,
const std::string &key,
const std::string &value);
843 bool GetDestData(
const CTxDestination &dest,
const std::string &key, std::string *value)
const;
845 std::vector<std::string> GetDestValues(
const std::string&
prefix)
const;
851 bool LoadWatchOnly(
const CScript &dest);
854 int64_t nRelockTime = 0;
857 bool ChangeWalletPassphrase(
const SecureString& strOldWalletPassphrase,
const SecureString& strNewWalletPassphrase);
858 bool EncryptWallet(
const SecureString& strWalletPassphrase);
861 unsigned int ComputeTimeSmart(
const CWalletTx& wtx)
const;
871 bool AddToWallet(const
CWalletTx& wtxIn,
bool fFlushOnClose=true);
875 void BlockDisconnected(const
std::shared_ptr<const
CBlock>& pblock) override;
878 void TransactionRemovedFromMempool(const
CTransactionRef &ptx) override;
879 void ReacceptWalletTransactions();
884 CAmount GetUnconfirmedBalance() const;
885 CAmount GetImmatureBalance() const;
886 CAmount GetUnconfirmedWatchOnlyBalance() const;
887 CAmount GetImmatureWatchOnlyBalance() const;
906 std::
string& strFailReason, const
CCoinControl& coin_control,
bool sign = true);
911 std::vector<CTxOut> v_txouts(txouts.size());
912 std::copy(txouts.begin(), txouts.end(), v_txouts.begin());
913 return DummySignTx(txNew, v_txouts, use_max_sig);
915 bool DummySignTx(
CMutableTransaction &txNew,
const std::vector<CTxOut> &txouts,
bool use_max_sig =
false)
const;
916 bool DummySignInput(
CTxIn &tx_in,
const CTxOut &txout,
bool use_max_sig =
false)
const;
919 unsigned int m_confirm_target{DEFAULT_TX_CONFIRM_TARGET};
920 bool m_spend_zero_conf_change{DEFAULT_SPEND_ZEROCONF_CHANGE};
921 bool m_signal_rbf{DEFAULT_WALLET_RBF};
922 bool m_allow_fallback_fee{
true};
936 bool TopUpKeyPool(
unsigned int kpSize = 0);
952 bool ReserveKeyFromKeyPool(int64_t&
nIndex,
CKeyPool& keypool,
bool fRequestedInternal);
953 void KeepKey(int64_t
nIndex);
954 void ReturnKey(int64_t
nIndex,
bool fInternal, const
CPubKey& pubkey);
955 bool GetKeyFromPool(
CPubKey &key,
bool internal = false);
956 int64_t GetOldestKeyPoolTime();
961 const
std::map<
CKeyID, int64_t>& GetAllReserveKeys()
const {
return m_pool_key_to_index; }
976 bool IsChange(const
CTxOut& txout) const;
988 DBErrors LoadWallet(
bool& fFirstRunRet);
992 bool SetAddressBook(const
CTxDestination& address, const
std::
string& strName, const
std::
string& purpose);
996 const
std::
string& GetLabelName(const
CScript& scriptPubKey) const;
1003 return setInternalKeyPool.size() + setExternalKeyPool.size();
1010 bool SetMaxVersion(
int nVersion);
1022 void Flush(
bool shutdown=
false);
1032 &address,
const std::string &label,
bool isMine,
1033 const std::string &purpose,
1040 boost::signals2::signal<void (
CWallet *wallet,
const uint256 &hashTx,
1044 boost::signals2::signal<void (const std::string &title, int nProgress)>
ShowProgress;
1055 bool TransactionCanBeAbandoned(
const uint256& hashTx)
const;
1058 bool AbandonTransaction(
const uint256& hashTx);
1061 bool MarkReplaced(
const uint256& originalHash,
const uint256& newHash);
1064 static bool Verify(std::string wallet_file,
bool salvage_wallet, std::string& error_string, std::string& warning_string);
1067 static std::shared_ptr<CWallet> CreateWalletFromFile(
const std::string&
name,
const fs::path& path, uint64_t wallet_creation_flags = 0);
1073 void postInitProcess();
1075 bool BackupWallet(
const std::string& strDest);
1078 void SetHDChain(
const CHDChain& chain,
bool memonly);
1082 bool IsHDEnabled()
const;
1094 void SetHDSeed(
const CPubKey& key);
1116 void LearnAllRelatedScripts(const
CPubKey& key);
1119 void SetWalletFlag(uint64_t
flags);
1122 bool IsWalletFlagSet(uint64_t flag);
1126 bool SetWalletFlags(uint64_t overwriteFlags,
bool memOnly);
1129 const
std::
string GetDisplayName()
const {
1130 std::string wallet_name = GetName().length() == 0 ?
"default wallet" : GetName();
1135 template<
typename...
Params>
1137 LogPrintf((
"%s " + fmt).c_str(), GetDisplayName(), parameters...);
1156 pwallet = pwalletIn;
1170 bool GetReservedKey(
CPubKey &pubkey,
bool internal =
false);
1186 assert(!m_could_reserve);
1192 m_could_reserve =
true;
1204 if (m_could_reserve) {
1216 #endif // BITCOIN_WALLET_WALLET_H
std::atomic< bool > fScanningWallet
#define NO_THREAD_SAFETY_ANALYSIS
void SetTx(CTransactionRef arg)
static const uint256 ABANDON_HASH
Constant used in hashBlock to indicate tx has been abandoned.
Result CreateTransaction(const CWallet *wallet, const uint256 &txid, const CCoinControl &coin_control, CAmount total_fee, std::vector< std::string > &errors, CAmount &old_fee, CAmount &new_fee, CMutableTransaction &mtx)
Create bumpfee transaction.
std::unique_ptr< WalletDatabase > database
Internal database handle.
void SerializationOp(Stream &s, Operation ser_action)
void SetMerkleBranch(const CBlockIndex *pIndex, int posInBlock)
CAmount nImmatureWatchCreditCached
void BindWallet(CWallet *pwalletIn)
std::map< std::string, std::string > mapValue_t
bool CanSupportFeature(enum WalletFeature wf) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
check whether we are allowed to upgrade (or already support) to the named feature ...
bool fSolvable
Whether we know how to spend this output, ignoring the lack of keys.
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
char fFromMe
From me flag is set to 1 for transactions that were created by the wallet on this bitcoin node...
constexpr CAmount DEFAULT_PAY_TX_FEE
-paytxfee default
std::map< CTxDestination, CAddressBookData > mapAddressBook
const uint256 & GetHash() const
bool IsFromMe(const isminefilter &filter) const
constexpr OutputType DEFAULT_CHANGE_TYPE
Default for -changetype.
bool use_max_sig
Whether to use the maximum sized, 72 byte signature when calculating the size of the input spend...
bool fImmatureCreditCached
bool AddWallet(const std::shared_ptr< CWallet > &wallet)
Private key encryption is done based on a CMasterKey, which holds a salt and random encryption key...
std::multimap< COutPoint, uint256 > TxSpends
Used to keep track of spent outpoints, and detect and report conflicts (double-spends or mutated tran...
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
int64_t nOrderPos
position in ordered transaction list
std::multimap< int64_t, CWalletTx * >::const_iterator m_it_wtxOrdered
An instance of this class represents one database.
CMerkleTx(CTransactionRef arg)
uint8_t isminefilter
used for bitflags of isminetype
std::vector< std::shared_ptr< CWallet > > vpwallets GUARDED_BY(cs_wallets)
WalletFeature
(client) version numbers for particular wallet features
void MarkDirty()
make sure balances are recalculated
bool fSubtractFeeFromAmount
std::map< unsigned int, CMasterKey > MasterKeyMap
int nInputBytes
Pre-computed estimated size of this output as a fully-signed input in a transaction.
DBErrors
Error statuses for the wallet database.
CAmount nWatchDebitCached
Keystore which keeps the private keys encrypted.
CCriticalSection cs_wallets
bool fSpendable
Whether we have the private keys to spend this output.
std::shared_ptr< const CTransaction > CTransactionRef
bool fAvailableCreditCached
Implement this to subscribe to events generated in validation.
bool AcceptToMemoryPool(CTxMemPool &pool, CValidationState &state, const CTransactionRef &tx, bool *pfMissingInputs, std::list< CTransactionRef > *plTxnReplaced, bool bypass_limits, const CAmount nAbsurdFee, bool test_accept)
(try to) add transaction to memory pool plTxnReplaced will be appended to with all transactions repla...
Access to the wallet database.
mapValue_t mapValue
Key/value map with information about the transaction.
int64_t CAmount
Amount in satoshis (Can be negative)
boost::signals2::signal< void()> NotifyUnload
Wallet is about to be unloaded.
bool fAvailableWatchCreditCached
bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey) override
Add a key to the store.
std::vector< unsigned char, secure_allocator< unsigned char > > CPrivKey
secure_allocator is defined in allocators.h CPrivKey is a serialized private key, with all parameters...
boost::signals2::signal< void(CWallet *wallet, const uint256 &hashTx, ChangeType status)> NotifyTransactionChanged
Wallet transaction added, removed or updated.
#define AssertLockHeld(cs)
void SetBroadcastTransactions(bool broadcast)
Set whether this wallet broadcasts transactions.
COutput(const CWalletTx *txIn, int iIn, int nDepthIn, bool fSpendableIn, bool fSolvableIn, bool fSafeIn, bool use_max_sig_in=false)
void Unserialize(Stream &s)
int GetDepthInMainChain() const EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Return depth of transaction in blockchain: <0 : conflicts with a transaction this deep in the blockch...
ChangeType
General change type (added, updated, removed).
void WalletLogPrintf(std::string fmt, Params... parameters) const
Prepends the wallet name in logging output to ease debugging in multi-wallet use cases.
isminetype
IsMine() return codes.
An input of a transaction.
boost::variant< CNoDestination, CKeyID, CScriptID, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
int CalculateMaximumSignedInputSize(const CTxOut &txout, const CWallet *pwallet, bool use_max_sig=false)
The BlockPolicyEstimator is used for estimating the feerate needed for a transaction to be included i...
int GetVersion()
get the current wallet format (the oldest client version guaranteed to understand this wallet) ...
int GetBlocksToMaturity() const EXCLUSIVE_LOCKS_REQUIRED(cs_main)
void SerializationOp(Stream &s, Operation ser_action)
An encapsulated public key.
bool fSafe
Whether this output is considered safe to spend.
void KeepScript() override
std::map< std::string, std::string > StringMap
WalletDatabase & GetDBHandle()
Get database handle used by this wallet.
constexpr OutputType DEFAULT_ADDRESS_TYPE
Default for -addresstype.
An output of a transaction.
std::shared_ptr< CWallet > GetWallet(const std::string &name)
An outpoint - a combination of a transaction hash and an index n into its vout.
CCriticalSection cs_wallet
unsigned int fTimeReceivedIsTxTime
Special output type for change outputs only.
RAII object to check and reserve a wallet rescan.
A transaction with a bunch of additional info that only the owner cares about.
bool GetBroadcastTransactions() const
Inquire whether this wallet broadcasts transactions.
bool RemoveWallet(const std::shared_ptr< CWallet > &wallet)
void Serialize(Stream &s) const
bool IsInMainChain() const EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Capture information about block/transaction validation.
void Init(const CWallet *pwalletIn)
static feebumper::Result wallet cs_wallet
CAmount nWatchCreditCached
CWalletTx(const CWallet *pwalletIn, CTransactionRef arg)
#define EXCLUSIVE_LOCKS_REQUIRED(...)
CAmount nAvailableCreditCached
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
CoinSelectionParams coin_selection_params(false, 0, 0, CFeeRate(0), 0)
#define LOCKS_EXCLUDED(...)
boost::signals2::signal< void(CWallet *wallet, const CTxDestination &address, const std::string &label, bool isMine, const std::string &purpose, ChangeType status)> NotifyAddressBookChanged
Address book entry changed.
const std::string & GetName() const
Get a name for this wallet for logging/debugging purposes.
A key allocated from the key pool.
Result CommitTransaction(CWallet *wallet, const uint256 &txid, CMutableTransaction &&mtx, std::vector< std::string > &errors, uint256 &bumped_txid)
Commit the bumpfee transaction.
The block chain is a tree shaped structure starting with the genesis block at the root...
const CChainParams & Params()
Return the currently selected parameters.
Serialized script, used inside transaction inputs and outputs.
CTxDestination destination
unsigned int nTimeSmart
Stable timestamp that never changes, and reflects the order a transaction was added to the wallet...
CInputCoin GetInputCoin() const
isminetype IsMine(const CKeyStore &keystore, const CScript &scriptPubKey)
Private key that includes an expiration date in case it never gets used.
A reference to a CKey: the Hash360 of its serialized public key.
#define LIMITED_STRING(obj, n)
CoinSelectionParams(bool use_bnb, size_t change_output_size, size_t change_spend_size, CFeeRate effective_fee, size_t tx_noinputs_size)
int64_t atoi64(const char *psz)
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
UniValue SignTransaction(CMutableTransaction &mtx, const UniValue &prevTxsUnival, CBasicKeyStore *keystore, bool is_temp_keystore, const UniValue &hashType)
Sign a transaction with the given keystore and previous transactions.
Fee rate in satoshis per kilobyte: CAmount / kB.
std::string i64tostr(int64_t n)
CReserveKey(CWallet *pwalletIn)
void FundTransaction(CWallet *const pwallet, CMutableTransaction &tx, CAmount &fee_out, int &change_position, UniValue options)
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
A reference to a CScript: the Hash360 of its serialization (see script.h)
void SerializationOp(Stream &s, Operation ser_action)
A mutable version of CTransaction.
CAmount nAvailableWatchCreditCached
bool LoadMinVersion(int nVersion) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
unsigned int nTimeReceived
time received by this node
An encapsulated private key.
std::string m_name
Wallet filename from wallet=<path> command line or config option.
The basic transaction that is broadcasted on the network and contained in blocks. ...
bool fImmatureWatchCreditCached
const CHDChain & GetHDChain() const
WalletRescanReserver(CWallet *w)
boost::signals2::signal< void(bool fHaveWatchOnly)> NotifyWatchonlyChanged
Watch-only address added.
std::multimap< int64_t, CWalletTx * > TxItems
bool IsImmatureCoinBase() const EXCLUSIVE_LOCKS_REQUIRED(cs_main)
int64_t CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet, bool use_max_sig=false) EXCLUSIVE_LOCKS_REQUIRED(wallet -> cs_wallet)
std::vector< std::shared_ptr< CWallet > > GetWallets()
CAmount nImmatureCreditCached
A transaction with a merkle branch linking it to the block chain.
std::vector< std::pair< std::string, std::string > > vOrderForm