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>

+ Collaboration diagram for CTransactionBuilder:

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...
 
CTransactionBuilderOutputAddOutput (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

CWalletpwallet {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::~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()

void CTransactionBuilder::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()

◆ 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()

int CTransactionBuilder::CountOutputs ( ) const
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()

CAmount CTransactionBuilder::GetAmountInitial ( ) const
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]

CAmount CTransactionBuilder::GetAmountLeft ( ) const
inline

◆ GetAmountLeft() [2/2]

CAmount CTransactionBuilder::GetAmountLeft ( CAmount  nAmountInitial,
CAmount  nAmountUsed,
CAmount  nFee 
)
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()

CAmount CTransactionBuilder::GetAmountUsed ( ) const
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()

unsigned int CTransactionBuilder::GetBytesTotal ( ) const
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()

CAmount CTransactionBuilder::GetFee ( unsigned int  nBytes) const
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()

int CTransactionBuilder::GetSizeOfCompactSizeDiff ( size_t  nAdd) const
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()

Friends And Related Function Documentation

◆ CTransactionBuilderOutput

friend class CTransactionBuilderOutput
friend

Needed by CTransactionBuilderOutput::UpdateAmount to lock cs_outputs.

Definition at line 99 of file privatesend-util.h.

Member Data Documentation

◆ coinControl

CCoinControl CTransactionBuilder::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

CCriticalSection CTransactionBuilder::cs_outputs
mutableprivate

Protect vecOutputs.

Definition at line 95 of file privatesend-util.h.

Referenced by AddOutput(), Clear(), Commit(), and CTransactionBuilderOutput::UpdateAmount().

◆ dummyReserveKey

CReserveKey CTransactionBuilder::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.

Referenced by Clear(), and Commit().

◆ fKeepKeys

bool CTransactionBuilder::fKeepKeys {false}
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.

Referenced by Clear(), and Commit().

◆ nBytesBase

int CTransactionBuilder::nBytesBase {0}
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

int CTransactionBuilder::nBytesOutput {0}
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

CWallet* CTransactionBuilder::pwallet {nullptr}
private

Wallet the transaction will be build for.

Definition at line 79 of file privatesend-util.h.

Referenced by AddOutput(), Commit(), and CTransactionBuilder().

◆ tallyItem

CompactTallyItem 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

std::vector<std::unique_ptr<CTransactionBuilderOutput> > CTransactionBuilder::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:
Released under the MIT license