Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
6c4e252
class CColorAmount
hihiben Dec 8, 2016
60513fe
class TxInfo
hihiben Jan 5, 2017
549909b
class Fee
hihiben Jan 6, 2017
49dd6f7
class CFeeRate
hihiben Dec 28, 2016
85fd423
class CTxOut
hihiben Dec 28, 2016
16a3aa2
class CTransaction
hihiben Dec 28, 2016
e2e3cc0
class CCoinsViewCache
hihiben Jan 6, 2017
7ffa8e0
struct CRecipient
hihiben Dec 28, 2016
3fd3aa3
struct COutputEntry
hihiben Dec 28, 2016
74048da
class CWalletTx
hihiben Dec 28, 2016
3b7be5d
class CWallet
hihiben Jan 4, 2017
bcc14f8
class CTxOutCompressor
hihiben Jan 4, 2017
5ef7787
fix init.cpp
hihiben Jan 4, 2017
17f8dcc
fix main.cpp
hihiben Jan 4, 2017
6c9cb18
class CBlockPolicyEstimator
hihiben Jan 4, 2017
cce0671
struct CBlockTemplate
hihiben Jan 4, 2017
f1662de
fix miner.cpp
hihiben Jan 4, 2017
2dd51d2
fix rpcserver.h rpcserver.cpp
hihiben Jan 4, 2017
cf9d5c7
fix rest.cpp
hihiben Jan 4, 2017
be25371
fix rpcblockchain.cpp
hihiben Jan 4, 2017
1a61286
fix rpcrawtransaction.cpp
hihiben Jan 5, 2017
af2ccc2
fix main.h main.cpp
hihiben Jan 5, 2017
8ca05e0
fix rpcmining.cpp
hihiben Jan 5, 2017
8c88aee
fix rpcmining.cpp
hihiben Jan 5, 2017
f4d872e
struct CCoinsStats
hihiben Jan 5, 2017
87e5ebc
fix rpcblockchain.cpp
hihiben Jan 5, 2017
5b8eca8
transaction handlers
hihiben Jan 5, 2017
5d5c7af
class CTxMemPoolEntry
hihiben Jan 5, 2017
769d54c
fix miner.cpp
hihiben Jan 6, 2017
c914876
fix main.cpp
hihiben Jan 6, 2017
50d04e1
fix main.cpp
hihiben Jan 6, 2017
1ac9094
fix main.cpp
hihiben Jan 6, 2017
60ac7bd
fix rpcrawtransaction.cpp
hihiben Jan 6, 2017
bda9cfd
class CCoinsViewDB
hihiben Jan 6, 2017
91dc4c3
class CTxMemPool
hihiben Jan 9, 2017
477c472
class CCoinsViewMemPool
hihiben Jan 9, 2017
b65af61
class CMainParams
hihiben Jan 9, 2017
5bb0662
fix core_write.cpp
hihiben Jan 9, 2017
9e4be1f
fix wallet/rpcwallet.cpp
hihiben Jan 9, 2017
4c21621
class COutput
hihiben Jan 9, 2017
a83a111
fix wallet/wallet.cpp
hihiben Jan 9, 2017
2c56352
class CCoinsViewCache_UnitTest
hihiben Jan 10, 2017
23903dc
fix wallet/rpcwallet.cpp
hihiben Jan 10, 2017
96e8dd7
fix test/coins_tests.cpp
hihiben Jan 10, 2017
ddce5cc
fix test/DoS_tests.cpp
hihiben Jan 10, 2017
f8bec1a
fix wallet/rpcwallet.cpp
hihiben Jan 10, 2017
fa72779
fix test/mempool_tests.cpp
hihiben Jan 10, 2017
1adac92
fix test/script_P2SH_tests.cpp
hihiben Jan 10, 2017
5a978ab
fix test/script_P2SH_tests.cpp
hihiben Jan 10, 2017
b9ce74c
fix test/test_gcoin.h test/test_gcoin.cpp
hihiben Jan 13, 2017
82f8dc7
class CAccountingEntry
hihiben Jan 13, 2017
447d9f7
class CWalletDB
hihiben Jan 16, 2017
110faff
struct tallyitem
hihiben Jan 16, 2017
dd9199e
fix wallet/rpcwallet.cpp
hihiben Jan 17, 2017
e457de3
fix test/handler_normal.cpp
hihiben Jan 17, 2017
3666111
acc_orderupgrade
hihiben Jan 17, 2017
19e067e
fix test/handler_license.cpp
hihiben Jan 17, 2017
4057393
fix wallet/test/wallet_tests.cpp
hihiben Jan 17, 2017
3692220
fix test/rpc_command.cpp
hihiben Jan 17, 2017
8b02d50
class CWallet_UnitTest
hihiben Jan 21, 2017
3ca7b74
class CColorAmount
hihiben Feb 14, 2017
d751ee6
class CBlockPolicyEstimator
hihiben Feb 14, 2017
2afe736
fix main.cpp
hihiben Feb 15, 2017
531e2ce
class CColorAmount
hihiben Feb 15, 2017
1619c63
class CColorAmount
hihiben Feb 15, 2017
3831bab
fix main.cpp
hihiben Feb 15, 2017
3fad64b
class Fee
hihiben Feb 15, 2017
62b99b6
travis
hihiben Feb 16, 2017
a64c426
class CColorAmount
hihiben Feb 16, 2017
ccee1b3
fix wallet/rpcwallet.cpp
hihiben Feb 21, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ script:
- ./configure --cache-file=../config.cache $GCOIN_CONFIG_ALL $GCOIN_CONFIG || ( cat config.log && false)
- make $MAKEJOBS $GOAL || ( echo "Build failure. Verbose build follows." && make $GOAL V=1 ; false )
- export LD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/depends/$HOST/lib
- if [ "$RUN_TESTS" = "true" ]; then make check; fi
- if [ "$RUN_TESTS" = "true" ]; then ./src/test/test_gcoin --run_test=wallet_tests; fi
# - if [ "$RUN_TESTS" = "true" ]; then qa/pull-tester/rpc-tests.py --coverage; fi
after_script:
- echo $TRAVIS_COMMIT_RANGE
Expand Down
69 changes: 63 additions & 6 deletions src/amount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,78 @@

#include "tinyformat.h"

CFeeRate::CFeeRate(const CAmount& nFeePaid, size_t nSize)

std::ostream& operator<<(std::ostream& os, const CColorAmount& ca)
{
CColorAmount::const_iterator it(ca.begin());
if (it == ca.end())
return os;
while(true) {
os << it->first << ":" << it->second;
it++;
if (it != ca.end())
os << ", ";
else
break;
}
return os;
}

CColorAmount const operator+(const CColorAmount &lhs, const CColorAmount &rhs)
{
return CColorAmount(lhs) += rhs;
}

CColorAmount const operator-(const CColorAmount &lhs, const CColorAmount &rhs)
{
return CColorAmount(lhs) -= rhs;
}

CColorAmount const operator+(const CColorAmount &lhs, const CAmount &rhs)
{
return CColorAmount(lhs) += rhs;
}

CColorAmount const operator-(const CColorAmount &lhs, const CAmount &rhs)
{
return CColorAmount(lhs) -= rhs;
}

CColorAmount const operator*(const CColorAmount &lhs, const CAmount &rhs)
{
return CColorAmount(lhs) *= rhs;
}

CColorAmount const operator/(const CColorAmount &lhs, const CAmount &rhs)
{
return CColorAmount(lhs) /= rhs;
}

CColorAmount const operator%(const CColorAmount &lhs, const CAmount &rhs)
{
return CColorAmount(lhs) %= rhs;
}

CFeeRate::CFeeRate(const CColorAmount& mFeePaid, size_t nSize)
{
if (nSize > 0)
nSatoshisPerK = nFeePaid*1000/nSize;
mSatoshisPerK = mFeePaid*1000/nSize;
else
nSatoshisPerK = 0;
mSatoshisPerK.init(1, 0);
}

CFeeRate::CFeeRate(const CAmount& nFeePaid, size_t nSize)
{
CFeeRate(CColorAmount(1, nFeePaid), nSize);
}

CAmount CFeeRate::GetFee(size_t nSize) const
CColorAmount CFeeRate::GetFee(size_t nSize) const
{
return 0;
return CColorAmount(1, 0);
}

std::string CFeeRate::ToString() const
{
return strprintf("%d.%08d BTC/kB", nSatoshisPerK / COIN, nSatoshisPerK % COIN);
return strprintf("%d.%08d GCOIN/kB", mSatoshisPerK.Value() / COIN, mSatoshisPerK.Value() % COIN);
}

264 changes: 252 additions & 12 deletions src/amount.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include "serialize.h"

#include <iostream>
#include <stdexcept>
#include <stdlib.h>
#include <string>

Expand All @@ -26,34 +28,272 @@ typedef std::map<type_Color, CAmount> colorAmount_t;

inline bool MoneyRange(const CAmount& nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }

class CColorAmount : public colorAmount_t
{
public:
CColorAmount() {}

void init(type_Color color, CAmount value)
{
this->clear();
this->insert(std::pair<type_Color, CAmount>(color, value));
}

CColorAmount(type_Color color, CAmount value)
{
init(color, value);
}

CColorAmount operator-() const
{
CColorAmount ret;
for (CColorAmount::const_iterator it(this->begin()); it != this->end(); it++)
ret.insert(std::pair<type_Color, CAmount>(it->first, -it->second));
return ret;
}

bool operator>(const CColorAmount& rhs) const
{
CColorAmount lhs = (*this);
CColorAmount::const_iterator itl(lhs.begin());
CColorAmount::const_iterator itr(rhs.begin());
if (itl == lhs.end())
return false;
for (; itr != rhs.end(); itr++) {
for (; itl != lhs.end() && itl->first != itr->first; itl++);
if (itl == lhs.end())
return false;
if (itl->second <= itr->second)
return false;
}

return true;
}

bool operator>=(const CColorAmount& rhs) const
{
CColorAmount lhs = (*this);
CColorAmount::const_iterator itl(lhs.begin());
CColorAmount::const_iterator itr(rhs.begin());
for (; itr != rhs.end(); itr++) {
for (; itl != lhs.end() && itl->first != itr->first; itl++);
if (itl == lhs.end())
return false;
if (itl->second < itr->second)
return false;
}

return true;
}

bool operator<(const CColorAmount& rhs) const
{
CColorAmount lhs = (*this);
CColorAmount::const_iterator itl(lhs.begin());
CColorAmount::const_iterator itr(rhs.begin());
if (itr == rhs.end())
return false;
for (; itl != lhs.end(); itl++) {
for (; itr != rhs.end() && itl->first != itr->first; itr++);
if (itr == rhs.end())
return false;
if (itl->second >= itr->second)
return false;
}

return true;
}

bool operator<=(const CColorAmount& rhs) const
{
CColorAmount lhs = (*this);
CColorAmount::const_iterator itl(lhs.begin());
CColorAmount::const_iterator itr(rhs.begin());
for (; itl != lhs.end(); itl++) {
for (; itr != rhs.end() && itl->first != itr->first; itr++);
if (itr == rhs.end())
return false;
if (itl->second > itr->second)
return false;
}

return true;
}

bool operator==(const CColorAmount& rhs) const
{
CColorAmount lhs = (*this);
if (lhs.size() != rhs.size()) {
return false;
} else {
CColorAmount::const_iterator itl(lhs.begin());
CColorAmount::const_iterator itr(rhs.begin());
for (; itl != lhs.end() && itr != rhs.end(); itl++, itr++) {
if (itl->first != itr->first || itl->second != itr->second)
return false;
}
}

return true;
}

bool operator!=(const CColorAmount& rhs) const
{
CColorAmount lhs = (*this);
return !(lhs == rhs);
}

CColorAmount& operator=(const colorAmount_t& rhs)
{
this->clear();
for (colorAmount_t::const_iterator it(rhs.begin()); it != rhs.end(); it++)
this->insert(*it);
return *this;
}

CColorAmount& operator+=(const CColorAmount &rhs)
{
for (CColorAmount::const_iterator it(rhs.begin()); it != rhs.end(); it++) {
std::pair<CColorAmount::iterator, bool> ret;
ret = this->insert(*it);
if (!ret.second)
ret.first->second += it->second;
}
return *this;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不能用上面已經寫好的+來做嗎

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

以下幾個一樣

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

換一個方式來implement了


CColorAmount& operator-=(const CColorAmount& rhs)
{
for (CColorAmount::const_iterator it(rhs.begin()); it != rhs.end(); it++) {
if (!this->count(it->first))
(*this)[it->first] = -it->second;
else
(*this)[it->first] -= it->second;
if ((*this)[it->first] == 0)
this->erase(it->first);
}
return *this;
}

CColorAmount& operator+=(const CAmount& rhs)
{
if (this->size() == 1)
this->begin()->second += rhs;
return *this;
}

CColorAmount& operator-=(const CAmount& rhs)
{
if (this->size() == 1)
this->begin()->second -= rhs;
if (this->begin()->second == 0)
this->clear();
return *this;
}

CColorAmount operator*=(const CAmount& rhs)
{
for (CColorAmount::iterator it(this->begin()); it != this->end(); it++)
it->second *= rhs;
return *this;
}

CColorAmount operator/=(const CAmount& rhs)
{
for (CColorAmount::iterator it(this->begin()); it != this->end(); it++)
it->second /= rhs;
return *this;
}

CColorAmount operator%=(const CAmount& rhs)
{
for (CColorAmount::iterator it(this->begin()); it != this->end(); it++)
it->second %= rhs;
return *this;
}

CColorAmount& operator++()
{
if (this->size() == 1)
(*this) += 1;
else
throw std::runtime_error("CColorAmount::operator--(): The size of color amount should be 1.");
return *this;
}

type_Color Color() const
{
if (this->size() != 1)
throw std::runtime_error("CColorAmount::Color(): The size of color amount should be 1.");
return this->begin()->first;
}

CAmount Value() const
{
if (this->size() == 0)
return 0;
if (this->size() != 1)
throw std::runtime_error("CColorAmount::Value(): The size of color amount should be 0 or 1.");
return this->begin()->second;
}

CAmount TotalValue() const
{
CAmount value = 0;
for (CColorAmount::const_iterator it(this->begin()); it != this->end(); it++)
value += it->second;
return value;
}

bool IsPositive() const
{
for (CColorAmount::const_iterator it(this->begin()); it != this->end(); it++)
if (it->second < 0)
return false;
return true;
}

friend std::ostream& operator<<(std::ostream& os, const CColorAmount& ca);
};
CColorAmount const operator+(const CColorAmount &lhs, const CColorAmount &rhs);
CColorAmount const operator-(const CColorAmount &lhs, const CColorAmount &rhs);
CColorAmount const operator+(const CColorAmount &lhs, const CAmount &rhs);
CColorAmount const operator-(const CColorAmount &lhs, const CAmount &rhs);
CColorAmount const operator*(const CColorAmount &lhs, const CAmount &rhs);
CColorAmount const operator/(const CColorAmount &lhs, const CAmount &rhs);
CColorAmount const operator%(const CColorAmount &lhs, const CAmount &rhs);

/** Type-safe wrapper class to for fee rates
* (how much to pay based on transaction size)
*/
class CFeeRate
{
private:
CAmount nSatoshisPerK; // unit is satoshis-per-1,000-bytes
CColorAmount mSatoshisPerK; // unit is satoshis-per-1,000-bytes
public:
CFeeRate() : nSatoshisPerK(0) { }
explicit CFeeRate(const CAmount& _nSatoshisPerK): nSatoshisPerK(_nSatoshisPerK) { }
CFeeRate() : mSatoshisPerK(CColorAmount(1, 0)) { }
explicit CFeeRate(const CColorAmount& _mSatoshisPerK): mSatoshisPerK(_mSatoshisPerK) { }
explicit CFeeRate(const CAmount& _nSatoshisPerK): mSatoshisPerK(CColorAmount(1, _nSatoshisPerK)) { }
CFeeRate(const CColorAmount& mFeePaid, size_t nSize);
CFeeRate(const CAmount& nFeePaid, size_t nSize);
CFeeRate(const CFeeRate& other) { nSatoshisPerK = other.nSatoshisPerK; }
CFeeRate(const CFeeRate& other) { mSatoshisPerK = other.mSatoshisPerK; }

CAmount GetFee(size_t size) const; // unit returned is satoshis
CAmount GetFeePerK() const { return GetFee(1000); } // satoshis-per-1000-bytes
CColorAmount GetFee(size_t size) const; // unit returned is satoshis
CColorAmount GetFeePerK() const { return GetFee(1000); } // satoshis-per-1000-bytes

friend bool operator<(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK < b.nSatoshisPerK; }
friend bool operator>(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK > b.nSatoshisPerK; }
friend bool operator==(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK == b.nSatoshisPerK; }
friend bool operator<=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK <= b.nSatoshisPerK; }
friend bool operator>=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK >= b.nSatoshisPerK; }
friend bool operator<(const CFeeRate& a, const CFeeRate& b) { return a.mSatoshisPerK < b.mSatoshisPerK; }
friend bool operator>(const CFeeRate& a, const CFeeRate& b) { return a.mSatoshisPerK > b.mSatoshisPerK; }
friend bool operator==(const CFeeRate& a, const CFeeRate& b) { return a.mSatoshisPerK == b.mSatoshisPerK; }
friend bool operator<=(const CFeeRate& a, const CFeeRate& b) { return a.mSatoshisPerK <= b.mSatoshisPerK; }
friend bool operator>=(const CFeeRate& a, const CFeeRate& b) { return a.mSatoshisPerK >= b.mSatoshisPerK; }
std::string ToString() const;

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
READWRITE(nSatoshisPerK);
colorAmount_t mTemp = mSatoshisPerK;
READWRITE(mTemp);
}
};

Expand Down
Loading