LCOV - code coverage report
Current view: top level - src - coincontrol.h (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 29 29 100.0 %
Date: 2025-02-23 09:33:43 Functions: 5 5 100.0 %

          Line data    Source code
       1             : // Copyright (c) 2011-2013 The Bitcoin developers
       2             : // Copyright (c) 2014-2016 The Dash developers
       3             : // Copyright (c) 2015-2021 The PIVX Core developers
       4             : // Distributed under the MIT/X11 software license, see the accompanying
       5             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       6             : 
       7             : #ifndef PIVX_COINCONTROL_H
       8             : #define PIVX_COINCONTROL_H
       9             : 
      10             : #include "optional.h"
      11             : #include "policy/feerate.h"
      12             : #include "primitives/transaction.h"
      13             : #include "sapling/address.h"
      14             : #include "script/standard.h"
      15             : #include <unordered_set>
      16             : 
      17             : class OutPointWrapper {
      18             : public:
      19             :     BaseOutPoint outPoint;
      20             :     CAmount value;
      21             :     bool isP2CS;
      22             : 
      23             :     bool operator<(const OutPointWrapper& obj2) const {
      24             :         return this->outPoint < obj2.outPoint;
      25             :     }
      26             : 
      27           9 :     bool operator==(const OutPointWrapper& obj2) const {
      28          25 :         return this->outPoint == obj2.outPoint;
      29             :     }
      30             : };
      31             : 
      32             : /** Coin Control Features. */
      33         283 : class CCoinControl
      34             : {
      35             : public:
      36             :     // TODO: upgrade those two fields to a single CWDestination?
      37             :     Optional<libzcash::SaplingPaymentAddress> destShieldChange = boost::none;
      38             :     CTxDestination destChange = CNoDestination();
      39             :     //! If false, allows unselected inputs, but requires all selected inputs be used
      40             :     bool fAllowOtherInputs;
      41             :     //! Includes watch only addresses which are solvable
      42             :     bool fAllowWatchOnly;
      43             :     //! Minimum absolute fee (not per kilobyte)
      44             :     CAmount nMinimumTotalFee;
      45             :     //! Override estimated feerate
      46             :     bool fOverrideFeeRate;
      47             :     //! Feerate to use if overrideFeeRate is true
      48             :     CFeeRate nFeeRate;
      49             : 
      50         283 :     CCoinControl()
      51         283 :     {
      52         283 :         SetNull();
      53             :     }
      54             : 
      55         283 :     void SetNull()
      56             :     {
      57         283 :         destChange = CNoDestination();
      58         283 :         setSelected.clear();
      59         283 :         fAllowOtherInputs = false;
      60         283 :         fAllowWatchOnly = false;
      61         283 :         nMinimumTotalFee = 0;
      62         283 :         nFeeRate = CFeeRate(0);
      63         283 :         fOverrideFeeRate = false;
      64         283 :     }
      65             : 
      66        1109 :     bool HasSelected() const
      67             :     {
      68        1109 :         return (!setSelected.empty());
      69             :     }
      70             : 
      71         185 :     bool IsSelected(const BaseOutPoint& output) const
      72             :     {
      73         185 :         return (setSelected.count(OutPointWrapper{output, 0, false}) > 0);
      74             :     }
      75             : 
      76          20 :     void Select(const BaseOutPoint& output, CAmount value = 0, bool isP2CS = false)
      77             :     {
      78          20 :         setSelected.insert(OutPointWrapper{output, value, isP2CS});
      79          20 :     }
      80             : 
      81             :     void UnSelect(const BaseOutPoint& output)
      82             :     {
      83             :         setSelected.erase(OutPointWrapper{output, 0, false});
      84             :     }
      85             : 
      86           5 :     void UnSelectAll()
      87             :     {
      88           5 :         setSelected.clear();
      89             :     }
      90             : 
      91         328 :     void ListSelected(std::vector<OutPointWrapper>& vOutpoints) const
      92             :     {
      93         328 :         vOutpoints.assign(setSelected.begin(), setSelected.end());
      94         328 :     }
      95             : 
      96             :     unsigned int QuantitySelected() const
      97             :     {
      98             :         return setSelected.size();
      99             :     }
     100             : 
     101             : private:
     102             : 
     103             :     struct SimpleOutpointHash {
     104         205 :         size_t operator() (const OutPointWrapper& obj) const {
     105         410 :             return (UintToArith256(obj.outPoint.hash) + obj.outPoint.n).GetLow64();
     106             :         }
     107             :     };
     108             : 
     109             :     std::unordered_set<OutPointWrapper, SimpleOutpointHash> setSelected;
     110             : };
     111             : 
     112             : #endif // PIVX_COINCONTROL_H

Generated by: LCOV version 1.14