LCOV - code coverage report
Current view: top level - src - amount.h (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 8 10 80.0 %
Date: 2015-10-12 22:39:14 Functions: 0 4 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Copyright (c) 2009-2010 Satoshi Nakamoto
       2             : // Copyright (c) 2009-2014 The Bitcoin Core developers
       3             : // Distributed under the MIT software license, see the accompanying
       4             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       5             : 
       6             : #ifndef BITCOIN_AMOUNT_H
       7             : #define BITCOIN_AMOUNT_H
       8             : 
       9             : #include "serialize.h"
      10             : 
      11             : #include <stdlib.h>
      12             : #include <string>
      13             : 
      14             : typedef int64_t CAmount;
      15             : 
      16             : static const CAmount COIN = 100000000;
      17             : static const CAmount CENT = 1000000;
      18             : 
      19             : extern const std::string CURRENCY_UNIT;
      20             : 
      21             : /** No amount larger than this (in satoshi) is valid.
      22             :  *
      23             :  * Note that this constant is *not* the total money supply, which in Bitcoin
      24             :  * currently happens to be less than 21,000,000 BTC for various reasons, but
      25             :  * rather a sanity check. As this sanity check is used by consensus-critical
      26             :  * validation code, the exact value of the MAX_MONEY constant is consensus
      27             :  * critical; in unusual circumstances like a(nother) overflow bug that allowed
      28             :  * for the creation of coins out of thin air modification could lead to a fork.
      29             :  * */
      30             : static const CAmount MAX_MONEY = 21000000 * COIN;
      31      223212 : inline bool MoneyRange(const CAmount& nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }
      32             : 
      33             : /** Type-safe wrapper class to for fee rates
      34             :  * (how much to pay based on transaction size)
      35             :  */
      36             : class CFeeRate
      37             : {
      38             : private:
      39             :     CAmount nSatoshisPerK; // unit is satoshis-per-1,000-bytes
      40             : public:
      41         297 :     CFeeRate() : nSatoshisPerK(0) { }
      42        1813 :     explicit CFeeRate(const CAmount& _nSatoshisPerK): nSatoshisPerK(_nSatoshisPerK) { }
      43             :     CFeeRate(const CAmount& nFeePaid, size_t nSize);
      44        7444 :     CFeeRate(const CFeeRate& other) { nSatoshisPerK = other.nSatoshisPerK; }
      45             : 
      46             :     CAmount GetFee(size_t size) const; // unit returned is satoshis
      47       25075 :     CAmount GetFeePerK() const { return GetFee(1000); } // satoshis-per-1000-bytes
      48             : 
      49       52119 :     friend bool operator<(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK < b.nSatoshisPerK; }
      50           0 :     friend bool operator>(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK > b.nSatoshisPerK; }
      51           8 :     friend bool operator==(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK == b.nSatoshisPerK; }
      52           0 :     friend bool operator<=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK <= b.nSatoshisPerK; }
      53       24864 :     friend bool operator>=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK >= b.nSatoshisPerK; }
      54             :     std::string ToString() const;
      55             : 
      56             :     ADD_SERIALIZE_METHODS;
      57             : 
      58             :     template <typename Stream, typename Operation>
      59             :     inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
      60             :         READWRITE(nSatoshisPerK);
      61             :     }
      62             : };
      63             : 
      64             : #endif //  BITCOIN_AMOUNT_H

Generated by: LCOV version 1.11