Dash Core Source Documentation (0.16.0.1)
Find detailed information regarding the Dash Core source code.
Enables simple transaction generation for a given CWallet object. More...
#include <privatesend-util.h>
Public Member Functions | |
CTransactionBuilder (CWallet *pwalletIn, const CompactTallyItem &tallyItemIn) | |
~CTransactionBuilder () | |
bool | CouldAddOutput (CAmount nAmountOutput) const |
Check it would be possible to add a single output with the amount nAmount. Returns true if its possible and false if not. More... | |
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 add all of them and false if not. More... | |
CTransactionBuilderOutput * | AddOutput (CAmount nAmountOutput=0) |
Add an output with the amount nAmount. Returns a pointer to the output if it could be added and nullptr if not due to insufficient amount left. More... | |
CAmount | GetAmountInitial () const |
Get amount we had available when we started. More... | |
CAmount | GetAmountLeft () const |
Get the amount currently left to add more outputs. Does respect fees. More... | |
bool | IsDust (CAmount nAmount) const |
Check if an amounts should be considered as dust. More... | |
int | CountOutputs () const |
Get the total number of added outputs. More... | |
bool | Commit (std::string &strResult) |
Create and Commit the transaction to the wallet. More... | |
std::string | ToString () const |
Convert to a string. More... | |
Private Member Functions | |
void | Clear () |
Clear the output vector and keep/return the included keys depending on the value of fKeepKeys. More... | |
unsigned int | GetBytesTotal () const |
Get the total number of bytes used already by this transaction. More... | |
CAmount | GetAmountUsed () const |
Get the amount currently used by added outputs. Does not include fees. More... | |
CAmount | GetFee (unsigned int nBytes) const |
Get fees based on the number of bytes and the feerate set in CoinControl. More... | |
int | GetSizeOfCompactSizeDiff (size_t nAdd) const |
Helper to get GetSizeOfCompactSizeDiff(vecOutputs.size(), vecOutputs.size() + nAdd) More... | |
Static Private Member Functions | |
static CAmount | GetAmountLeft (CAmount nAmountInitial, CAmount nAmountUsed, CAmount nFee) |
Helper to calculate static amount left by simply subtracting an used amount and a fee from a provided initial amount. More... | |
Private Attributes | |
CWallet * | pwallet {nullptr} |
Wallet the transaction will be build for. More... | |
CCoinControl | coinControl |
See CTransactionBuilder() for initialization. More... | |
CReserveKey | dummyReserveKey |
Dummy since we anyway use tallyItem's destination as change destination in coincontrol. More... | |
CompactTallyItem | tallyItem |
Contains all utxos available to generate this transactions. They are all from the same address. More... | |
int | nBytesBase {0} |
Contains the number of bytes required for a transaction with only the inputs of tallyItems, no outputs. More... | |
int | nBytesOutput {0} |
Contains the number of bytes required to add one output. More... | |
bool | fKeepKeys {false} |
Call KeepKey for all keys in destructor if fKeepKeys is true, call ReturnKey for all key if its false. More... | |
CCriticalSection | cs_outputs |
Protect vecOutputs. More... | |
std::vector< std::unique_ptr< CTransactionBuilderOutput > > | vecOutputs |
Contains all outputs already added to the transaction. More... | |
Friends | |
class | CTransactionBuilderOutput |
Needed by CTransactionBuilderOutput::UpdateAmount to lock cs_outputs. More... | |
Detailed Description
Enables simple transaction generation for a given CWallet object.
The resulting transaction's inputs are defined by the given CompactTallyItem. The outputs are defined by CTransactionBuilderOutput.
Definition at line 76 of file privatesend-util.h.
Constructor & Destructor Documentation
◆ CTransactionBuilder()
CTransactionBuilder::CTransactionBuilder | ( | CWallet * | pwalletIn, |
const CompactTallyItem & | tallyItemIn | ||
) |
Definition at line 107 of file privatesend-util.cpp.
References Clear(), coinControl, CWallet::cs_wallet, CCoinControl::destChange, CBlockPolicyEstimator::estimateSmartFee(), CCoinControl::fAllowOtherInputs, feeEstimator, CWallet::GenerateNewKey(), CWallet::GetDBHandle(), GetDiscardRate(), CPubKey::GetID(), GetScriptForDestination(), GetSerializeSize(), LOCK, CCoinControl::m_discard_feerate, CCoinControl::m_feerate, nBytesBase, nBytesOutput, nTxConfirmTarget, payTxFee, ProduceSignature(), PROTOCOL_VERSION, pwallet, SignatureData::scriptSig, CCoinControl::Select(), SER_NETWORK, tallyItem, CompactTallyItem::txdest, WalletBatch::TxnBegin(), CompactTallyItem::vecOutPoints, and CMutableTransaction::vin.
◆ ~CTransactionBuilder()
CTransactionBuilder::~CTransactionBuilder | ( | ) |
Definition at line 150 of file privatesend-util.cpp.
References Clear().
Member Function Documentation
◆ AddOutput()
CTransactionBuilderOutput * CTransactionBuilder::AddOutput | ( | CAmount | nAmountOutput = 0 | ) |
Add an output with the amount nAmount. Returns a pointer to the output if it could be added and nullptr if not due to insufficient amount left.
Definition at line 202 of file privatesend-util.cpp.
References CouldAddOutput(), cs_outputs, LOCK, pwallet, and vecOutputs.
Referenced by CPrivateSendClientSession::CreateDenominated(), and CPrivateSendClientSession::MakeCollateralAmounts().
◆ Clear()
|
private |
Clear the output vector and keep/return the included keys depending on the value of fKeepKeys.
Definition at line 155 of file privatesend-util.cpp.
References cs_outputs, dummyReserveKey, fKeepKeys, LOCK, CReserveKey::ReturnKey(), and vecOutputs.
Referenced by CTransactionBuilder(), and ~CTransactionBuilder().
◆ Commit()
bool CTransactionBuilder::Commit | ( | std::string & | strResult | ) |
Create and Commit the transaction to the wallet.
Definition at line 258 of file privatesend-util.cpp.
References coinControl, CWallet::CommitTransaction(), CWallet::CreateTransaction(), cs_outputs, dummyReserveKey, fKeepKeys, g_connman, GetAmountLeft(), GetBytesTotal(), GetFee(), CMerkleTx::GetHash(), CValidationState::GetRejectReason(), GetSizeOfCompactSizeDiff(), IsDust(), LOCK, nBytesOutput, pwallet, strprintf, base_blob< BITS >::ToString(), ToString(), CMerkleTx::tx, and vecOutputs.
Referenced by CPrivateSendClientSession::CreateDenominated(), and CPrivateSendClientSession::MakeCollateralAmounts().
◆ CouldAddOutput()
bool CTransactionBuilder::CouldAddOutput | ( | CAmount | nAmountOutput | ) | const |
Check it would be possible to add a single output with the amount nAmount. Returns true if its possible and false if not.
Definition at line 176 of file privatesend-util.cpp.
References GetAmountInitial(), GetAmountLeft(), GetAmountUsed(), GetBytesTotal(), GetFee(), GetSizeOfCompactSizeDiff(), and nBytesOutput.
Referenced by AddOutput(), CPrivateSendClientSession::CreateDenominated(), and CPrivateSendClientSession::MakeCollateralAmounts().
◆ CouldAddOutputs()
bool CTransactionBuilder::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 add all of them and false if not.
Definition at line 186 of file privatesend-util.cpp.
References GetAmountInitial(), GetAmountLeft(), GetAmountUsed(), GetBytesTotal(), GetFee(), GetSizeOfCompactSizeDiff(), and nBytesOutput.
Referenced by CPrivateSendClientSession::CreateDenominated(), and CPrivateSendClientSession::MakeCollateralAmounts().
◆ CountOutputs()
|
inline |
Get the total number of added outputs.
Definition at line 117 of file privatesend-util.h.
References vecOutputs.
Referenced by CPrivateSendClientSession::CreateDenominated(), and ToString().
◆ GetAmountInitial()
|
inline |
Get amount we had available when we started.
Definition at line 111 of file privatesend-util.h.
References CompactTallyItem::nAmount, and tallyItem.
Referenced by CouldAddOutput(), CouldAddOutputs(), GetAmountLeft(), and ToString().
◆ GetAmountLeft() [1/2]
|
inline |
Get the amount currently left to add more outputs. Does respect fees.
Definition at line 113 of file privatesend-util.h.
References GetAmountInitial(), GetAmountUsed(), GetBytesTotal(), and GetFee().
Referenced by Commit(), CouldAddOutput(), CouldAddOutputs(), CPrivateSendClientSession::CreateDenominated(), CPrivateSendClientSession::MakeCollateralAmounts(), ToString(), and CTransactionBuilderOutput::UpdateAmount().
◆ GetAmountLeft() [2/2]
|
staticprivate |
Helper to calculate static amount left by simply subtracting an used amount and a fee from a provided initial amount.
Definition at line 218 of file privatesend-util.cpp.
◆ GetAmountUsed()
|
private |
Get the amount currently used by added outputs. Does not include fees.
Definition at line 223 of file privatesend-util.cpp.
References vecOutputs.
Referenced by CouldAddOutput(), CouldAddOutputs(), GetAmountLeft(), and ToString().
◆ GetBytesTotal()
|
private |
Get the total number of bytes used already by this transaction.
Definition at line 212 of file privatesend-util.cpp.
References GetSizeOfCompactSizeDiff(), nBytesBase, nBytesOutput, and vecOutputs.
Referenced by Commit(), CouldAddOutput(), CouldAddOutputs(), GetAmountLeft(), and ToString().
◆ GetFee()
|
private |
Get fees based on the number of bytes and the feerate set in CoinControl.
NOTE: To get the total transaction fee this should only be called once with the total number of bytes for the transaction to avoid calling CFeeRate::GetFee multiple times with subtotals as this may add rounding errors with each further call.
Definition at line 232 of file privatesend-util.cpp.
References coinControl, GetRequiredFee(), CCoinControl::m_feerate, and maxTxFee.
Referenced by Commit(), CouldAddOutput(), CouldAddOutputs(), GetAmountLeft(), and ToString().
◆ GetSizeOfCompactSizeDiff()
|
private |
Helper to get GetSizeOfCompactSizeDiff(vecOutputs.size(), vecOutputs.size() + nAdd)
Definition at line 245 of file privatesend-util.cpp.
References vecOutputs.
Referenced by Commit(), CouldAddOutput(), CouldAddOutputs(), and GetBytesTotal().
◆ IsDust()
bool CTransactionBuilder::IsDust | ( | CAmount | nAmount | ) | const |
Check if an amounts should be considered as dust.
Definition at line 253 of file privatesend-util.cpp.
References coinControl, GetScriptForDestination(), IsDust(), CCoinControl::m_discard_feerate, tallyItem, and CompactTallyItem::txdest.
Referenced by Commit(), and CPrivateSendClientSession::MakeCollateralAmounts().
◆ ToString()
std::string CTransactionBuilder::ToString | ( | ) | const |
Convert to a string.
Definition at line 322 of file privatesend-util.cpp.
References coinControl, CountOutputs(), GetAmountInitial(), GetAmountLeft(), GetAmountUsed(), GetBytesTotal(), GetFee(), CCoinControl::m_discard_feerate, CCoinControl::m_feerate, nBytesBase, nBytesOutput, and strprintf.
Referenced by Commit(), CPrivateSendClientSession::CreateDenominated(), and CPrivateSendClientSession::MakeCollateralAmounts().
Friends And Related Function Documentation
◆ CTransactionBuilderOutput
|
friend |
Needed by CTransactionBuilderOutput::UpdateAmount to lock cs_outputs.
Definition at line 99 of file privatesend-util.h.
Member Data Documentation
◆ coinControl
|
private |
See CTransactionBuilder() for initialization.
Definition at line 81 of file privatesend-util.h.
Referenced by Commit(), CTransactionBuilder(), GetFee(), IsDust(), and ToString().
◆ cs_outputs
|
mutableprivate |
Protect vecOutputs.
Definition at line 95 of file privatesend-util.h.
Referenced by AddOutput(), Clear(), Commit(), and CTransactionBuilderOutput::UpdateAmount().
◆ dummyReserveKey
|
private |
Dummy since we anyway use tallyItem's destination as change destination in coincontrol.
Its a member just to make sure ReturnKey can be called in destructor just in case it gets generated/kept somewhere in CWallet code.
Definition at line 85 of file privatesend-util.h.
◆ fKeepKeys
|
private |
Call KeepKey for all keys in destructor if fKeepKeys is true, call ReturnKey for all key if its false.
Definition at line 93 of file privatesend-util.h.
◆ nBytesBase
|
private |
Contains the number of bytes required for a transaction with only the inputs of tallyItems, no outputs.
Definition at line 89 of file privatesend-util.h.
Referenced by CTransactionBuilder(), GetBytesTotal(), and ToString().
◆ nBytesOutput
|
private |
Contains the number of bytes required to add one output.
Definition at line 91 of file privatesend-util.h.
Referenced by Commit(), CouldAddOutput(), CouldAddOutputs(), CTransactionBuilder(), GetBytesTotal(), and ToString().
◆ pwallet
|
private |
Wallet the transaction will be build for.
Definition at line 79 of file privatesend-util.h.
Referenced by AddOutput(), Commit(), and CTransactionBuilder().
◆ tallyItem
|
private |
Contains all utxos available to generate this transactions. They are all from the same address.
Definition at line 87 of file privatesend-util.h.
Referenced by CTransactionBuilder(), GetAmountInitial(), and IsDust().
◆ vecOutputs
|
private |
Contains all outputs already added to the transaction.
Definition at line 97 of file privatesend-util.h.
Referenced by AddOutput(), Clear(), Commit(), CountOutputs(), GetAmountUsed(), GetBytesTotal(), and GetSizeOfCompactSizeDiff().
The documentation for this class was generated from the following files:
- src/privatesend/privatesend-util.h
- src/privatesend/privatesend-util.cpp