mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-17 13:07:54 +02:00
Move CAmountMap to amount.h
This commit is contained in:
parent
2f7a9a5846
commit
fa0a86fb74
4 changed files with 48 additions and 49 deletions
|
|
@ -41,3 +41,37 @@ std::string CFeeRate::ToString() const
|
|||
{
|
||||
return strprintf("%d.%08d %s/kB", nSatoshisPerK / COIN, nSatoshisPerK % COIN, CURRENCY_UNIT);
|
||||
}
|
||||
|
||||
CAmountMap& operator+=(CAmountMap& a, const CAmountMap& b)
|
||||
{
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it)
|
||||
a[it->first] += it->second;
|
||||
return a;
|
||||
}
|
||||
|
||||
CAmountMap& operator-=(CAmountMap& a, const CAmountMap& b)
|
||||
{
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it)
|
||||
a[it->first] -= it->second;
|
||||
return a;
|
||||
}
|
||||
|
||||
CAmountMap operator+(const CAmountMap& a, const CAmountMap& b)
|
||||
{
|
||||
CAmountMap c;
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = a.begin(); it != a.end(); ++it)
|
||||
c[it->first] += it->second;
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it)
|
||||
c[it->first] += it->second;
|
||||
return c;
|
||||
}
|
||||
|
||||
CAmountMap operator-(const CAmountMap& a, const CAmountMap& b)
|
||||
{
|
||||
CAmountMap c;
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = a.begin(); it != a.end(); ++it)
|
||||
c[it->first] += it->second;
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it)
|
||||
c[it->first] -= it->second;
|
||||
return c;
|
||||
}
|
||||
|
|
|
|||
14
src/amount.h
14
src/amount.h
|
|
@ -33,6 +33,14 @@ typedef uint256 CAssetID;
|
|||
/** The sha256 of Bitcoin genesis block, for easy reference **/
|
||||
static const CAssetID BITCOINID(uint256S("09f663de96be771f50cab5ded00256ffe63773e2eaa9a604092951cc3d7c6621"));
|
||||
|
||||
/** Used for consensus fee and general wallet accounting*/
|
||||
typedef std::map<CAssetID, CAmount> CAmountMap;
|
||||
|
||||
CAmountMap& operator+=(CAmountMap& a, const CAmountMap& b);
|
||||
CAmountMap& operator-=(CAmountMap& a, const CAmountMap& b);
|
||||
CAmountMap operator+(const CAmountMap& a, const CAmountMap& b);
|
||||
CAmountMap 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
|
||||
|
|
@ -45,6 +53,12 @@ static const CAssetID BITCOINID(uint256S("09f663de96be771f50cab5ded00256ffe63773
|
|||
static const CAmount MAX_MONEY = 21000000 * COIN;
|
||||
inline bool MoneyRange(const CAmount& nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }
|
||||
|
||||
inline bool MoneyRange(const CAmountMap& mapValue) {
|
||||
for(CAmountMap::const_iterator it = mapValue.begin(); it != mapValue.end(); it++)
|
||||
if (it->second < 0 || it->second > MAX_MONEY)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Fee rate in satoshis per kilobyte: CAmount / kB
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -4532,37 +4532,3 @@ bool hasNonPostiveValue(const CAmountMap& amount)
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
CAmountMap& operator+=(CAmountMap& a, const CAmountMap& b)
|
||||
{
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it)
|
||||
a[it->first] += it->second;
|
||||
return a;
|
||||
}
|
||||
|
||||
CAmountMap& operator-=(CAmountMap& a, const CAmountMap& b)
|
||||
{
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it)
|
||||
a[it->first] -= it->second;
|
||||
return a;
|
||||
}
|
||||
|
||||
CAmountMap operator+(const CAmountMap& a, const CAmountMap& b)
|
||||
{
|
||||
CAmountMap c;
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = a.begin(); it != a.end(); ++it)
|
||||
c[it->first] += it->second;
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it)
|
||||
c[it->first] += it->second;
|
||||
return c;
|
||||
}
|
||||
|
||||
CAmountMap operator-(const CAmountMap& a, const CAmountMap& b)
|
||||
{
|
||||
CAmountMap c;
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = a.begin(); it != a.end(); ++it)
|
||||
c[it->first] += it->second;
|
||||
for(std::map<CAssetID, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it)
|
||||
c[it->first] -= it->second;
|
||||
return c;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,9 +75,6 @@ static const bool DEFAULT_USE_HD_WALLET = true;
|
|||
|
||||
extern const char * DEFAULT_WALLET_DAT;
|
||||
|
||||
/** Structure used for internal wallet accounting, and not consensus**/
|
||||
typedef std::map<CAssetID, CAmount> CAmountMap;
|
||||
|
||||
// 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
|
||||
|
|
@ -109,18 +106,6 @@ bool operator!=(const CAmountMap& a, const CAmountMap& b);
|
|||
bool hasNegativeValue(const CAmountMap& amount);
|
||||
bool hasNonPositiveValue(const CAmountMap& amount);
|
||||
|
||||
CAmountMap& operator+=(CAmountMap& a, const CAmountMap& b);
|
||||
CAmountMap& operator-=(CAmountMap& a, const CAmountMap& b);
|
||||
CAmountMap operator+(const CAmountMap& a, const CAmountMap& b);
|
||||
CAmountMap operator-(const CAmountMap& a, const CAmountMap& b);
|
||||
|
||||
inline bool MoneyRange(const CAmountMap& mapValue) {
|
||||
for(CAmountMap::const_iterator it = mapValue.begin(); it != mapValue.end(); it++)
|
||||
if (it->second < 0 || it->second > MAX_MONEY)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
class CBlockIndex;
|
||||
class CCoinControl;
|
||||
class COutput;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue