PIVX Core  5.6.99
P2P Digital Currency
coincontrol.h
Go to the documentation of this file.
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 
18 public:
21  bool isP2CS;
22 
23  bool operator<(const OutPointWrapper& obj2) const {
24  return this->outPoint < obj2.outPoint;
25  }
26 
27  bool operator==(const OutPointWrapper& obj2) const {
28  return this->outPoint == obj2.outPoint;
29  }
30 };
31 
34 {
35 public:
36  // TODO: upgrade those two fields to a single CWDestination?
49 
51  {
52  SetNull();
53  }
54 
55  void SetNull()
56  {
58  setSelected.clear();
59  fAllowOtherInputs = false;
60  fAllowWatchOnly = false;
61  nMinimumTotalFee = 0;
62  nFeeRate = CFeeRate(0);
63  fOverrideFeeRate = false;
64  }
65 
66  bool HasSelected() const
67  {
68  return (!setSelected.empty());
69  }
70 
71  bool IsSelected(const BaseOutPoint& output) const
72  {
73  return (setSelected.count(OutPointWrapper{output, 0, false}) > 0);
74  }
75 
76  void Select(const BaseOutPoint& output, CAmount value = 0, bool isP2CS = false)
77  {
78  setSelected.insert(OutPointWrapper{output, value, isP2CS});
79  }
80 
81  void UnSelect(const BaseOutPoint& output)
82  {
83  setSelected.erase(OutPointWrapper{output, 0, false});
84  }
85 
86  void UnSelectAll()
87  {
88  setSelected.clear();
89  }
90 
91  void ListSelected(std::vector<OutPointWrapper>& vOutpoints) const
92  {
93  vOutpoints.assign(setSelected.begin(), setSelected.end());
94  }
95 
96  unsigned int QuantitySelected() const
97  {
98  return setSelected.size();
99  }
100 
101 private:
102 
104  size_t operator() (const OutPointWrapper& obj) const {
105  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
int64_t CAmount
Amount in PIV (Can be negative)
Definition: amount.h:13
arith_uint256 UintToArith256(const uint256 &a)
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:33
uint256 hash
Definition: transaction.h:35
uint32_t n
Definition: transaction.h:36
Coin Control Features.
Definition: coincontrol.h:34
std::unordered_set< OutPointWrapper, SimpleOutpointHash > setSelected
Definition: coincontrol.h:109
bool IsSelected(const BaseOutPoint &output) const
Definition: coincontrol.h:71
bool HasSelected() const
Definition: coincontrol.h:66
CFeeRate nFeeRate
Feerate to use if overrideFeeRate is true.
Definition: coincontrol.h:48
unsigned int QuantitySelected() const
Definition: coincontrol.h:96
void Select(const BaseOutPoint &output, CAmount value=0, bool isP2CS=false)
Definition: coincontrol.h:76
void ListSelected(std::vector< OutPointWrapper > &vOutpoints) const
Definition: coincontrol.h:91
void UnSelectAll()
Definition: coincontrol.h:86
bool fAllowWatchOnly
Includes watch only addresses which are solvable.
Definition: coincontrol.h:42
bool fOverrideFeeRate
Override estimated feerate.
Definition: coincontrol.h:46
void UnSelect(const BaseOutPoint &output)
Definition: coincontrol.h:81
CTxDestination destChange
Definition: coincontrol.h:38
void SetNull()
Definition: coincontrol.h:55
bool fAllowOtherInputs
If false, allows unselected inputs, but requires all selected inputs be used.
Definition: coincontrol.h:40
Optional< libzcash::SaplingPaymentAddress > destShieldChange
Definition: coincontrol.h:37
CAmount nMinimumTotalFee
Minimum absolute fee (not per kilobyte)
Definition: coincontrol.h:44
Fee rate in PIV per kilobyte: CAmount / kB.
Definition: feerate.h:20
BaseOutPoint outPoint
Definition: coincontrol.h:19
bool operator<(const OutPointWrapper &obj2) const
Definition: coincontrol.h:23
bool operator==(const OutPointWrapper &obj2) const
Definition: coincontrol.h:27
boost::optional< T > Optional
Substitute for C++17 std::optional.
Definition: optional.h:12
boost::variant< CNoDestination, CKeyID, CScriptID, CExchangeKeyID > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:72
size_t operator()(const OutPointWrapper &obj) const
Definition: coincontrol.h:104