Dash Core Source Documentation (0.16.0.1)
Find detailed information regarding the Dash Core source code.
privatesend-util.cpp
Go to the documentation of this file.
86 CTransactionBuilderOutput::CTransactionBuilderOutput(CTransactionBuilder* pTxBuilderIn, CWallet* pwalletIn, CAmount nAmountIn) :
107 CTransactionBuilder::CTransactionBuilder(CWallet* pwalletIn, const CompactTallyItem& tallyItemIn) :
112 // Generate a feerate which will be used to consider if the remainder is dust and will go into fees or not
114 // Generate a feerate which will be used by calculations of this class and also by CWallet::CreateTransaction
115 coinControl.m_feerate = std::max(::feeEstimator.estimateSmartFee((int)::nTxConfirmTarget, nullptr, true), payTxFee);
124 // Create dummy tx to calculate the exact required fees upfront for accurate amount and fee calculations
181 // Adding another output can change the serialized size of the vout size hence + GetSizeOfCompactSizeDiff()
197 // Adding other outputs can change the serialized size of the vout size hence + GetSizeOfCompactSizeDiff()
198 unsigned int nBytes = GetBytesTotal() + nBytesAdditional + GetSizeOfCompactSizeDiff(vecOutputAmounts.size());
199 return GetAmountLeft(GetAmountInitial(), GetAmountUsed() + nAmountAdditional, GetFee(nBytes)) >= 0;
206 vecOutputs.push_back(std::make_unique<CTransactionBuilderOutput>(this, pwallet, nAmountOutput));
214 // Adding other outputs can change the serialized size of the vout size hence + GetSizeOfCompactSizeDiff()
215 return nBytesBase + vecOutputs.size() * nBytesOutput + ::GetSizeOfCompactSizeDiff(0, vecOutputs.size());
218 CAmount CTransactionBuilder::GetAmountLeft(const CAmount nAmountInitial, const CAmount nAmountUsed, const CAmount nFee)
255 return ::IsDust(CTxOut(nAmount, ::GetScriptForDestination(tallyItem.txdest)), coinControl.m_discard_feerate.get());
274 if (!pwallet->CreateTransaction(vecSend, wtx, dummyReserveKey, nFeeRet, nChangePosRet, strResult, coinControl)) {
280 // If there is a either remainder which is considered to be dust (will be added to fee in this case) or no amount left there should be no change output, return if there is a change output.
282 strResult = strprintf("Unexpected change output %s at position %d", wtx.tx->vout[nChangePosRet].ToString(), nChangePosRet);
286 // If there is a remainder which is not considered to be dust it should end up in a change output, return if not.
298 // Add a change output and GetSizeOfCompactSizeDiff(1) as another output can changes the serialized size of the vout size in CTransaction
302 // If the calculated fee does not match the fee returned by CreateTransaction aka if this check fails something is wrong!
305 strResult = strprintf("Fee validation failed -> nFeeRet: %d, nFeeCalc: %d, nFeeAdditional: %d, nBytesAdditional: %d, %s", nFeeRet, nFeeCalc, nFeeAdditional, nBytesAdditional, ToString());
324 return strprintf("CTransactionBuilder(Amount initial: %d, Amount left: %d, Bytes base: %d, Bytes output: %d, Bytes total: %d, Amount used: %d, Outputs: %d, Fee rate: %d, Discard fee rate: %d, Fee: %d)",
std::vector< std::unique_ptr< CTransactionBuilderOutput > > vecOutputs
Contains all outputs already added to the transaction.
Definition: privatesend-util.h:97
CTransactionBuilderOutput(CTransactionBuilder *pTxBuilderIn, CWallet *pwalletIn, CAmount nAmountIn)
Definition: privatesend-util.cpp:86
CFeeRate GetDiscardRate(const CBlockPolicyEstimator &estimator)
Return the maximum feerate for discarding change.
Definition: fees.cpp:78
bool fKeepKeys
Call KeepKey for all keys in destructor if fKeepKeys is true, call ReturnKey for all key if its false...
Definition: privatesend-util.h:93
Definition: wallet.h:167
bool Commit(std::string &strResult)
Create and Commit the transaction to the wallet.
Definition: privatesend-util.cpp:258
CTransactionBuilder(CWallet *pwalletIn, const CompactTallyItem &tallyItemIn)
Definition: privatesend-util.cpp:107
CCoinControl coinControl
See CTransactionBuilder() for initialization.
Definition: privatesend-util.h:81
CAmount maxTxFee
Absolute maximum transaction fee (in duffs) used by wallet and mempool (rejects high fee in sendrawtr...
Definition: validation.cpp:247
Definition: sign.h:62
size_t GetSerializeSize(const T &t, int nType, int nVersion=0)
Definition: serialize.h:1295
int nBytesOutput
Contains the number of bytes required to add one output.
Definition: privatesend-util.h:91
unsigned int GetSizeOfCompactSize(uint64_t nSize)
Compact Size size < 253 – 1 byte size <= USHRT_MAX – 3 bytes (253 + 2 bytes) size <= UINT_MAX – 5 ...
Definition: serialize.h:225
Definition: privatesend-util.h:12
CAmount GetRequiredFee(unsigned int nTxBytes)
Return the minimum required fee taking into account the floating relay fee and user set minimum trans...
Definition: fees.cpp:16
bool ProduceSignature(const BaseSignatureCreator &creator, const CScript &fromPubKey, SignatureData &sigdata)
Produce a script signature using a generic signature creator.
Definition: sign.cpp:124
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Definition: pubkey.h:149
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...
Definition: privatesend-util.cpp:186
boost::optional< CFeeRate > m_feerate
Override the default payTxFee if set.
Definition: coincontrol.h:41
boost::optional< CFeeRate > m_discard_feerate
Override the discard feerate estimation with m_discard_feerate in CreateTransaction if set...
Definition: coincontrol.h:43
CReserveKey key
Reserve key where the amount of this output will end up.
Definition: privatesend-util.h:49
CAmount GetAmountLeft() const
Get the amount currently left to add more outputs. Does respect fees.
Definition: privatesend-util.h:113
Enables simple transaction generation for a given CWallet object.
Definition: privatesend-util.h:76
CAmount GetAmountUsed() const
Get the amount currently used by added outputs. Does not include fees.
Definition: privatesend-util.cpp:223
CAmount GetAmountInitial() const
Get amount we had available when we started.
Definition: privatesend-util.h:111
CompactTallyItem tallyItem
Contains all utxos available to generate this transactions. They are all from the same address...
Definition: privatesend-util.h:87
CFeeRate estimateSmartFee(int confTarget, FeeCalculation *feeCalc, bool conservative) const
Estimate feerate needed to get be included in a block within confTarget blocks.
Definition: fees.cpp:819
bool fAllowOtherInputs
If false, allows unselected inputs, but requires all selected inputs be used if fAllowOtherInputs is ...
Definition: coincontrol.h:33
int nBytesBase
Contains the number of bytes required for a transaction with only the inputs of tallyItems, no outputs.
Definition: privatesend-util.h:89
Definition: wallet.h:107
CScript GetScriptForDestination() const
Definition: privatesend-util.cpp:35
unsigned int GetBytesTotal() const
Get the total number of bytes used already by this transaction.
Definition: privatesend-util.cpp:212
CReserveKey dummyReserveKey
Dummy since we anyway use tallyItem's destination as change destination in coincontrol.
Definition: privatesend-util.h:85
std::vector< std::unique_ptr< CKeyHolder > > storage
Definition: privatesend-util.h:31
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
Definition: standard.cpp:256
unsigned int GetSizeOfCompactSizeDiff(uint64_t nSizePrev, uint64_t nSizeNew)
Definition: privatesend-util.cpp:13
A transaction with a bunch of additional info that only the owner cares about.
Definition: wallet.h:280
bool IsDust(CAmount nAmount) const
Check if an amounts should be considered as dust.
Definition: privatesend-util.cpp:253
Used by CTransactionBuilder to represent its transaction outputs.
Definition: privatesend-util.h:44
CAmount GetFee(unsigned int nBytes) const
Get fees based on the number of bytes and the feerate set in CoinControl.
Definition: privatesend-util.cpp:232
bool CouldAddOutput(CAmount nAmountOutput) const
Check it would be possible to add a single output with the amount nAmount. Returns true if its possib...
Definition: privatesend-util.cpp:176
bool CreateTransaction(const std::vector< CRecipient > &vecSend, CWalletTx &wtxNew, CReserveKey &reservekey, CAmount &nFeeRet, int &nChangePosInOut, std::string &strFailReason, const CCoinControl &coin_control, bool sign=true, int nExtraPayloadSize=0)
Create a new transaction paying the recipients with a set of coins selected by SelectCoins(); Also cr...
Definition: wallet.cpp:3658
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
Definition: wallet.h:715
CPubKey GenerateNewKey(WalletBatch &batch, uint32_t nAccountIndex, bool fInternal)
keystore implementation Generate a new key
Definition: wallet.cpp:187
bool GetReservedKey(CPubKey &pubkey, bool fInternalIn)
Definition: wallet.cpp:4721
Definition: serialize.h:160
void Clear()
Clear the output vector and keep/return the included keys depending on the value of fKeepKeys...
Definition: privatesend-util.cpp:155
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...
Definition: privatesend-util.cpp:202
A signature creator that just produces 72-byte empty signatures.
Definition: sign.h:55
int GetSizeOfCompactSizeDiff(size_t nAdd) const
Helper to get GetSizeOfCompactSizeDiff(vecOutputs.size(), vecOutputs.size() + nAdd) ...
Definition: privatesend-util.cpp:245
bool CommitTransaction(CWalletTx &wtxNew, CReserveKey &reservekey, CConnman *connman, CValidationState &state)
Call after CreateTransaction unless you want to abort.
Definition: wallet.cpp:4089
bool UpdateAmount(CAmount nAmount)
Try update the amount of this output. Returns true if it was successful and false if not (e...
Definition: privatesend-util.cpp:97