Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

privatesend-util.h
Go to the documentation of this file.
1 // Copyright (c) 2014-2019 The Dash Core developers
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef PRIVATESENDUTIL_H
6 #define PRIVATESENDUTIL_H
7 
8 #include <wallet/wallet.h>
9 
11 
13 {
14 private:
17 
18 public:
19  CKeyHolder(CWallet* pwalletIn);
20  CKeyHolder(CKeyHolder&&) = delete;
21  CKeyHolder& operator=(CKeyHolder&&) = delete;
22  void KeepKey();
23  void ReturnKey();
24 
26 };
27 
29 {
30 private:
31  std::vector<std::unique_ptr<CKeyHolder> > storage;
33 
34 public:
35  CScript AddKey(CWallet* pwalletIn);
36  void KeepAll();
37  void ReturnAll();
38 };
39 
45 {
54 
55 public:
56  CTransactionBuilderOutput(CTransactionBuilder* pTxBuilderIn, CWallet* pwalletIn, CAmount nAmountIn);
60  CScript GetScript() const { return script; }
62  CAmount GetAmount() const { return nAmount; }
66  void KeepKey() { key.KeepKey(); }
68  void ReturnKey() { key.ReturnKey(); }
69 };
70 
77 {
79  CWallet* pwallet{nullptr};
89  int nBytesBase{0};
91  int nBytesOutput{0};
93  bool fKeepKeys{false};
97  std::vector<std::unique_ptr<CTransactionBuilderOutput>> vecOutputs;
100 
101 public:
102  CTransactionBuilder(CWallet* pwalletIn, const CompactTallyItem& tallyItemIn);
105  bool CouldAddOutput(CAmount nAmountOutput) const;
107  bool CouldAddOutputs(const std::vector<CAmount>& vecOutputAmounts) const;
109  CTransactionBuilderOutput* AddOutput(CAmount nAmountOutput = 0);
115  bool IsDust(CAmount nAmount) const;
117  int CountOutputs() const { return vecOutputs.size(); }
119  bool Commit(std::string& strResult);
121  std::string ToString() const;
122 
123 private:
125  void Clear();
127  unsigned int GetBytesTotal() const;
129  static CAmount GetAmountLeft(CAmount nAmountInitial, CAmount nAmountUsed, CAmount nFee);
131  CAmount GetAmountUsed() const;
135  CAmount GetFee(unsigned int nBytes) const;
137  int GetSizeOfCompactSizeDiff(size_t nAdd) const;
138 };
139 
140 #endif //PRIVATESENDUTIL_H
std::vector< std::unique_ptr< CTransactionBuilderOutput > > vecOutputs
Contains all outputs already added to the transaction.
CTransactionBuilderOutput(CTransactionBuilder *pTxBuilderIn, CWallet *pwalletIn, CAmount nAmountIn)
bool fKeepKeys
Call KeepKey for all keys in destructor if fKeepKeys is true, call ReturnKey for all key if its false...
bool Commit(std::string &strResult)
Create and Commit the transaction to the wallet.
CTransactionBuilder(CWallet *pwalletIn, const CompactTallyItem &tallyItemIn)
CCoinControl coinControl
See CTransactionBuilder() for initialization.
void ReturnKey()
Tell the wallet to return the key used by this output to the keypool.
int nBytesOutput
Contains the number of bytes required to add one output.
bool CouldAddOutputs(const std::vector< CAmount > &vecOutputAmounts) const
Check if its possible to add multiple outputs as vector of amounts. Returns true if its possible to a...
Coin Control Features.
Definition: coincontrol.h:28
CReserveKey key
Reserve key where the amount of this output will end up.
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
CAmount GetAmountLeft() const
Get the amount currently left to add more outputs. Does respect fees.
Enables simple transaction generation for a given CWallet object.
CAmount GetAmountUsed() const
Get the amount currently used by added outputs. Does not include fees.
CAmount GetAmountInitial() const
Get amount we had available when we started.
CompactTallyItem tallyItem
Contains all utxos available to generate this transactions. They are all from the same address...
CScript AddKey(CWallet *pwalletIn)
CKeyHolder(CWallet *pwalletIn)
CAmount nAmount
Amount this output will receive.
An encapsulated public key.
Definition: pubkey.h:30
CKeyHolder & operator=(CKeyHolder &&)=delete
int nBytesBase
Contains the number of bytes required for a transaction with only the inputs of tallyItems, no outputs.
CScript GetScriptForDestination() const
unsigned int GetBytesTotal() const
Get the total number of bytes used already by this transaction.
CReserveKey dummyReserveKey
Dummy since we anyway use tallyItem&#39;s destination as change destination in coincontrol.
CAmount GetAmount() const
Get the amount of this output.
std::vector< std::unique_ptr< CKeyHolder > > storage
std::string ToString() const
Convert to a string.
CPubKey pubKey
void KeepKey()
Definition: wallet.cpp:4740
bool IsDust(CAmount nAmount) const
Check if an amounts should be considered as dust.
CTransactionBuilderOutput & operator=(CTransactionBuilderOutput &&)=delete
Used by CTransactionBuilder to represent its transaction outputs.
CWallet * pwallet
Wallet the transaction will be build for.
CAmount nAmount
Definition: wallet.h:110
CAmount GetFee(unsigned int nBytes) const
Get fees based on the number of bytes and the feerate set in CoinControl.
A key allocated from the key pool.
Definition: wallet.h:1273
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:389
bool CouldAddOutput(CAmount nAmountOutput) const
Check it would be possible to add a single output with the amount nAmount. Returns true if its possib...
CReserveKey reserveKey
int CountOutputs() const
Get the total number of added outputs.
CTransactionBuilder * pTxBuilder
Used for amount updates.
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
Definition: wallet.h:715
CCriticalSection cs_outputs
Protect vecOutputs.
CScript GetScript() const
Get the scriptPubKey of this output.
void ReturnKey()
Definition: wallet.cpp:4749
CScript script
ScriptPubKey of this output.
void KeepKey()
Tell the wallet to remove the key used by this output from the keypool.
CCriticalSection cs_storage
void Clear()
Clear the output vector and keep/return the included keys depending on the value of fKeepKeys...
CTransactionBuilderOutput * AddOutput(CAmount nAmountOutput=0)
Add an output with the amount nAmount. Returns a pointer to the output if it could be added and nullp...
Wrapped mutex: supports recursive locking, but no waiting TODO: We should move away from using the re...
Definition: sync.h:94
int GetSizeOfCompactSizeDiff(size_t nAdd) const
Helper to get GetSizeOfCompactSizeDiff(vecOutputs.size(), vecOutputs.size() + nAdd) ...
bool UpdateAmount(CAmount nAmount)
Try update the amount of this output. Returns true if it was successful and false if not (e...
Released under the MIT license