mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-16 13:01:19 +02:00
Move rest of CAmountMap stuff
This commit is contained in:
parent
fa0a86fb74
commit
9e669c8837
4 changed files with 133 additions and 132 deletions
104
src/amount.cpp
104
src/amount.cpp
|
|
@ -75,3 +75,107 @@ CAmountMap operator-(const CAmountMap& a, const CAmountMap& b)
|
|||
c[it->first] -= it->second;
|
||||
return c;
|
||||
}
|
||||
|
||||
bool operator<(const CAmountMap& a, const CAmountMap& b)
|
||||
{
|
||||
bool smallerElement = false;
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it) {
|
||||
CAmount aValue = a.count(it->first) ? a.find(it->first)->second : 0;
|
||||
if (aValue > it->second)
|
||||
return false;
|
||||
if (aValue < it->second)
|
||||
smallerElement = true;
|
||||
}
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = a.begin(); it != a.end(); ++it) {
|
||||
CAmount bValue = b.count(it->first) ? b.find(it->first)->second : 0;
|
||||
if (it->second > bValue)
|
||||
return false;
|
||||
if (it->second < bValue)
|
||||
smallerElement = true;
|
||||
}
|
||||
return smallerElement;
|
||||
}
|
||||
|
||||
bool operator<=(const CAmountMap& a, const CAmountMap& b)
|
||||
{
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it) {
|
||||
CAmount aValue = a.count(it->first) ? a.find(it->first)->second : 0;
|
||||
if (aValue > it->second)
|
||||
return false;
|
||||
}
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = a.begin(); it != a.end(); ++it) {
|
||||
CAmount bValue = b.count(it->first) ? b.find(it->first)->second : 0;
|
||||
if (it->second > bValue)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator>(const CAmountMap& a, const CAmountMap& b)
|
||||
{
|
||||
bool largerElement = false;
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it) {
|
||||
CAmount aValue = a.count(it->first) ? a.find(it->first)->second : 0;
|
||||
if (aValue < it->second)
|
||||
return false;
|
||||
if (aValue > it->second)
|
||||
largerElement = true;
|
||||
}
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = a.begin(); it != a.end(); ++it) {
|
||||
CAmount bValue = b.count(it->first) ? b.find(it->first)->second : 0;
|
||||
if (it->second < bValue)
|
||||
return false;
|
||||
if (it->second > bValue)
|
||||
largerElement = true;
|
||||
}
|
||||
return largerElement;
|
||||
}
|
||||
|
||||
bool operator>=(const CAmountMap& a, const CAmountMap& b)
|
||||
{
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it) {
|
||||
if ((a.count(it->first) ? a.find(it->first)->second : 0) < it->second)
|
||||
return false;
|
||||
}
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = a.begin(); it != a.end(); ++it) {
|
||||
if (it->second < (b.count(it->first) ? b.find(it->first)->second : 0))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator==(const CAmountMap& a, const CAmountMap& b)
|
||||
{
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = a.begin(); it != a.end(); ++it) {
|
||||
if ((b.count(it->first) ? b.find(it->first)->second : 0) != it->second)
|
||||
return false;
|
||||
}
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it) {
|
||||
if ((a.count(it->first) ? a.find(it->first)->second : 0) != it->second)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator!=(const CAmountMap& a, const CAmountMap& b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
bool hasNegativeValue(const CAmountMap& amount)
|
||||
{
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = amount.begin(); it != amount.end(); ++it) {
|
||||
if (it->second < 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool hasNonPostiveValue(const CAmountMap& amount)
|
||||
{
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = amount.begin(); it != amount.end(); ++it) {
|
||||
if (it->second <= 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
29
src/amount.h
29
src/amount.h
|
|
@ -41,6 +41,35 @@ CAmountMap& operator-=(CAmountMap& a, const CAmountMap& b);
|
|||
CAmountMap operator+(const CAmountMap& a, const CAmountMap& b);
|
||||
CAmountMap operator-(const CAmountMap& a, const CAmountMap& b);
|
||||
|
||||
// WARNING: Comparisons are only looking for *complete* ordering.
|
||||
// For strict inequality checks, if any entry would fail the non-strict
|
||||
// inequality, the comparison will fail. Therefore it is possible
|
||||
// that all inequality comparison checks may fail.
|
||||
// Therefore if >/< fails against a CAmountMap(), this means there
|
||||
// are all zeroes or one or more negative values.
|
||||
//
|
||||
// Examples: 1A + 2B <= 1A + 2B + 1C
|
||||
// and 1A + 2B < 1A + 2B + 1C
|
||||
// but
|
||||
// !(1A + 2B == 1A + 2B + 1C)
|
||||
//-------------------------------------
|
||||
// 1A + 2B == 1A + 2B
|
||||
// and 1A + 2B <= 1A + 2B
|
||||
// but
|
||||
// !(1A + 2B < 1A + 2B)
|
||||
//-------------------------------------
|
||||
// !(1A + 2B == 2B - 1C)
|
||||
// !(1A + 2B >= 2B - 1C)
|
||||
// ...
|
||||
// !(1A + 2B < 2B - 1C)
|
||||
// and 1A + 2B != 2B - 1C
|
||||
bool operator<(const CAmountMap& a, const CAmountMap& b);
|
||||
bool operator<=(const CAmountMap& a, const CAmountMap& b);
|
||||
bool operator>(const CAmountMap& a, const CAmountMap& b);
|
||||
bool operator>=(const CAmountMap& a, const CAmountMap& b);
|
||||
bool operator==(const CAmountMap& a, const CAmountMap& b);
|
||||
bool operator!=(const CAmountMap& a, const CAmountMap& b);
|
||||
|
||||
/** No amount larger than this (in satoshi) is valid.
|
||||
*
|
||||
* Note that this constant is *not* the total money supply, which in Bitcoin
|
||||
|
|
|
|||
|
|
@ -4428,107 +4428,3 @@ void CWalletTx::WipeUnknownBlindingData() const
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool operator<(const CAmountMap& a, const CAmountMap& b)
|
||||
{
|
||||
bool smallerElement = false;
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it) {
|
||||
CAmount aValue = a.count(it->first) ? a.find(it->first)->second : 0;
|
||||
if (aValue > it->second)
|
||||
return false;
|
||||
if (aValue < it->second)
|
||||
smallerElement = true;
|
||||
}
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = a.begin(); it != a.end(); ++it) {
|
||||
CAmount bValue = b.count(it->first) ? b.find(it->first)->second : 0;
|
||||
if (it->second > bValue)
|
||||
return false;
|
||||
if (it->second < bValue)
|
||||
smallerElement = true;
|
||||
}
|
||||
return smallerElement;
|
||||
}
|
||||
|
||||
bool operator<=(const CAmountMap& a, const CAmountMap& b)
|
||||
{
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it) {
|
||||
CAmount aValue = a.count(it->first) ? a.find(it->first)->second : 0;
|
||||
if (aValue > it->second)
|
||||
return false;
|
||||
}
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = a.begin(); it != a.end(); ++it) {
|
||||
CAmount bValue = b.count(it->first) ? b.find(it->first)->second : 0;
|
||||
if (it->second > bValue)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator>(const CAmountMap& a, const CAmountMap& b)
|
||||
{
|
||||
bool largerElement = false;
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it) {
|
||||
CAmount aValue = a.count(it->first) ? a.find(it->first)->second : 0;
|
||||
if (aValue < it->second)
|
||||
return false;
|
||||
if (aValue > it->second)
|
||||
largerElement = true;
|
||||
}
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = a.begin(); it != a.end(); ++it) {
|
||||
CAmount bValue = b.count(it->first) ? b.find(it->first)->second : 0;
|
||||
if (it->second < bValue)
|
||||
return false;
|
||||
if (it->second > bValue)
|
||||
largerElement = true;
|
||||
}
|
||||
return largerElement;
|
||||
}
|
||||
|
||||
bool operator>=(const CAmountMap& a, const CAmountMap& b)
|
||||
{
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it) {
|
||||
if ((a.count(it->first) ? a.find(it->first)->second : 0) < it->second)
|
||||
return false;
|
||||
}
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = a.begin(); it != a.end(); ++it) {
|
||||
if (it->second < (b.count(it->first) ? b.find(it->first)->second : 0))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator==(const CAmountMap& a, const CAmountMap& b)
|
||||
{
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = a.begin(); it != a.end(); ++it) {
|
||||
if ((b.count(it->first) ? b.find(it->first)->second : 0) != it->second)
|
||||
return false;
|
||||
}
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it) {
|
||||
if ((a.count(it->first) ? a.find(it->first)->second : 0) != it->second)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator!=(const CAmountMap& a, const CAmountMap& b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
bool hasNegativeValue(const CAmountMap& amount)
|
||||
{
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = amount.begin(); it != amount.end(); ++it) {
|
||||
if (it->second < 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool hasNonPostiveValue(const CAmountMap& amount)
|
||||
{
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = amount.begin(); it != amount.end(); ++it) {
|
||||
if (it->second <= 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,34 +75,6 @@ static const bool DEFAULT_USE_HD_WALLET = true;
|
|||
|
||||
extern const char * DEFAULT_WALLET_DAT;
|
||||
|
||||
// WARNING: Comparisons are only looking for *complete* ordering.
|
||||
// For strict inequality checks, if any entry would fail the non-strict
|
||||
// inequality, the comparison will fail. Therefore it is possible
|
||||
// that all inequality comparison checks may fail.
|
||||
// Therefore if >/< fails against a CAmountMap(), this means there
|
||||
// are all zeroes or one or more negative values.
|
||||
//
|
||||
// Examples: 1A + 2B <= 1A + 2B + 1C
|
||||
// and 1A + 2B < 1A + 2B + 1C
|
||||
// but
|
||||
// !(1A + 2B == 1A + 2B + 1C)
|
||||
//-------------------------------------
|
||||
// 1A + 2B == 1A + 2B
|
||||
// and 1A + 2B <= 1A + 2B
|
||||
// but
|
||||
// !(1A + 2B < 1A + 2B)
|
||||
//-------------------------------------
|
||||
// !(1A + 2B == 2B - 1C)
|
||||
// !(1A + 2B >= 2B - 1C)
|
||||
// ...
|
||||
// !(1A + 2B < 2B - 1C)
|
||||
// and 1A + 2B != 2B - 1C
|
||||
bool operator<(const CAmountMap& a, const CAmountMap& b);
|
||||
bool operator<=(const CAmountMap& a, const CAmountMap& b);
|
||||
bool operator>(const CAmountMap& a, const CAmountMap& b);
|
||||
bool operator>=(const CAmountMap& a, const CAmountMap& b);
|
||||
bool operator==(const CAmountMap& a, const CAmountMap& b);
|
||||
bool operator!=(const CAmountMap& a, const CAmountMap& b);
|
||||
bool hasNegativeValue(const CAmountMap& amount);
|
||||
bool hasNonPositiveValue(const CAmountMap& amount);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue