aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjtimon <jtimon@blockstream.io>2014-10-23 02:05:11 +0200
committerjtimon <jtimon@blockstream.io>2014-10-27 13:54:37 +0100
commiteda37330911b005f4be0c2d934346b26247d50f5 (patch)
tree47b9e17e2ec8bf2a351608a2cada601ec9d7e0bb /src
parentb6c99efe9ccb44a4324bacb879ab1f43960bf69b (diff)
MOVEONLY: Move CFeeRate and Amount constants to amount.o
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am1
-rw-r--r--src/amount.cpp31
-rw-r--r--src/amount.h43
-rw-r--r--src/core.cpp23
-rw-r--r--src/core.h41
-rw-r--r--src/init.cpp1
-rw-r--r--src/main.h1
-rw-r--r--src/miner.cpp1
-rw-r--r--src/qt/optionsmodel.cpp1
-rw-r--r--src/rpcmining.cpp1
-rw-r--r--src/rpcwallet.cpp1
-rw-r--r--src/txmempool.h1
-rw-r--r--src/wallet.h1
13 files changed, 82 insertions, 65 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index dbefa71fc6..d5abbc17d3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -208,6 +208,7 @@ univalue_libbitcoin_univalue_a_SOURCES = \
libbitcoin_common_a_CPPFLAGS = $(BITCOIN_INCLUDES)
libbitcoin_common_a_SOURCES = \
allocators.cpp \
+ amount.cpp \
base58.cpp \
chainparams.cpp \
coins.cpp \
diff --git a/src/amount.cpp b/src/amount.cpp
new file mode 100644
index 0000000000..e6f5b7d440
--- /dev/null
+++ b/src/amount.cpp
@@ -0,0 +1,31 @@
+// Copyright (c) 2009-2010 Satoshi Nakamoto
+// Copyright (c) 2009-2014 The Bitcoin developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#include "amount.h"
+
+#include "tinyformat.h"
+
+CFeeRate::CFeeRate(const CAmount& nFeePaid, size_t nSize)
+{
+ if (nSize > 0)
+ nSatoshisPerK = nFeePaid*1000/nSize;
+ else
+ nSatoshisPerK = 0;
+}
+
+CAmount CFeeRate::GetFee(size_t nSize) const
+{
+ CAmount nFee = nSatoshisPerK*nSize / 1000;
+
+ if (nFee == 0 && nSatoshisPerK > 0)
+ nFee = nSatoshisPerK;
+
+ return nFee;
+}
+
+std::string CFeeRate::ToString() const
+{
+ return strprintf("%d.%08d BTC/kB", nSatoshisPerK / COIN, nSatoshisPerK % COIN);
+}
diff --git a/src/amount.h b/src/amount.h
index 831fa1f6ca..c0d37954cb 100644
--- a/src/amount.h
+++ b/src/amount.h
@@ -6,8 +6,49 @@
#ifndef BITCOIN_AMOUNT_H
#define BITCOIN_AMOUNT_H
-#include <stdint.h>
+#include "serialize.h"
+
+#include <stdlib.h>
+#include <string>
typedef int64_t CAmount;
+static const CAmount COIN = 100000000;
+static const CAmount CENT = 1000000;
+
+/** No amount larger than this (in satoshi) is valid */
+static const CAmount MAX_MONEY = 21000000 * COIN;
+inline bool MoneyRange(const CAmount& nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }
+
+/** 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
+public:
+ CFeeRate() : nSatoshisPerK(0) { }
+ explicit CFeeRate(const CAmount& _nSatoshisPerK): nSatoshisPerK(_nSatoshisPerK) { }
+ CFeeRate(const CAmount& nFeePaid, size_t nSize);
+ CFeeRate(const CFeeRate& other) { nSatoshisPerK = other.nSatoshisPerK; }
+
+ CAmount GetFee(size_t size) const; // unit returned is satoshis
+ CAmount 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; }
+ 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);
+ }
+};
+
#endif // BITCOIN_AMOUNT_H
diff --git a/src/core.cpp b/src/core.cpp
index 73e6de88e1..ac180cc509 100644
--- a/src/core.cpp
+++ b/src/core.cpp
@@ -59,29 +59,6 @@ std::string CTxOut::ToString() const
return strprintf("CTxOut(nValue=%d.%08d, scriptPubKey=%s)", nValue / COIN, nValue % COIN, scriptPubKey.ToString().substr(0,30));
}
-CFeeRate::CFeeRate(const CAmount& nFeePaid, size_t nSize)
-{
- if (nSize > 0)
- nSatoshisPerK = nFeePaid*1000/nSize;
- else
- nSatoshisPerK = 0;
-}
-
-CAmount CFeeRate::GetFee(size_t nSize) const
-{
- CAmount nFee = nSatoshisPerK*nSize / 1000;
-
- if (nFee == 0 && nSatoshisPerK > 0)
- nFee = nSatoshisPerK;
-
- return nFee;
-}
-
-std::string CFeeRate::ToString() const
-{
- return strprintf("%d.%08d BTC/kB", nSatoshisPerK / COIN, nSatoshisPerK % COIN);
-}
-
CMutableTransaction::CMutableTransaction() : nVersion(CTransaction::CURRENT_VERSION), nLockTime(0) {}
CMutableTransaction::CMutableTransaction(const CTransaction& tx) : nVersion(tx.nVersion), vin(tx.vin), vout(tx.vout), nLockTime(tx.nLockTime) {}
diff --git a/src/core.h b/src/core.h
index a024dad740..f7a46da2c1 100644
--- a/src/core.h
+++ b/src/core.h
@@ -16,13 +16,6 @@
class CTransaction;
-static const int64_t COIN = 100000000;
-static const int64_t CENT = 1000000;
-
-/** No amount larger than this (in satoshi) is valid */
-static const CAmount MAX_MONEY = 21000000 * COIN;
-inline bool MoneyRange(const CAmount& nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }
-
/** An outpoint - a combination of a transaction hash and an index n into its vout */
class COutPoint
{
@@ -109,40 +102,6 @@ public:
std::string ToString() const;
};
-
-
-/** 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
-public:
- CFeeRate() : nSatoshisPerK(0) { }
- explicit CFeeRate(const CAmount& _nSatoshisPerK): nSatoshisPerK(_nSatoshisPerK) { }
- CFeeRate(const CAmount& nFeePaid, size_t nSize);
- CFeeRate(const CFeeRate& other) { nSatoshisPerK = other.nSatoshisPerK; }
-
- CAmount GetFee(size_t size) const; // unit returned is satoshis
- CAmount 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; }
- 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);
- }
-};
-
-
/** An output of a transaction. It contains the public key that the next input
* must be able to sign with to claim it.
*/
diff --git a/src/init.cpp b/src/init.cpp
index 70ac5190d3..d928094bba 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -10,6 +10,7 @@
#include "init.h"
#include "addrman.h"
+#include "amount.h"
#include "checkpoints.h"
#include "compat/sanity.h"
#include "key.h"
diff --git a/src/main.h b/src/main.h
index 1ef51918c5..2686ed948f 100644
--- a/src/main.h
+++ b/src/main.h
@@ -10,6 +10,7 @@
#include "config/bitcoin-config.h"
#endif
+#include "amount.h"
#include "chain.h"
#include "chainparams.h"
#include "coins.h"
diff --git a/src/miner.cpp b/src/miner.cpp
index eefccfd641..897f7c56d7 100644
--- a/src/miner.cpp
+++ b/src/miner.cpp
@@ -5,6 +5,7 @@
#include "miner.h"
+#include "amount.h"
#include "core.h"
#include "hash.h"
#include "main.h"
diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp
index 6db654dff7..c941ebd4ca 100644
--- a/src/qt/optionsmodel.cpp
+++ b/src/qt/optionsmodel.cpp
@@ -11,6 +11,7 @@
#include "bitcoinunits.h"
#include "guiutil.h"
+#include "amount.h"
#include "init.h"
#include "main.h"
#include "net.h"
diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp
index c767835a27..8af3c46348 100644
--- a/src/rpcmining.cpp
+++ b/src/rpcmining.cpp
@@ -3,6 +3,7 @@
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+#include "amount.h"
#include "chainparams.h"
#include "core_io.h"
#include "init.h"
diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp
index 68bb4068b8..2728fb4fb3 100644
--- a/src/rpcwallet.cpp
+++ b/src/rpcwallet.cpp
@@ -3,6 +3,7 @@
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+#include "amount.h"
#include "base58.h"
#include "core_io.h"
#include "rpcserver.h"
diff --git a/src/txmempool.h b/src/txmempool.h
index 85cf5310ff..df2fbc78c3 100644
--- a/src/txmempool.h
+++ b/src/txmempool.h
@@ -8,6 +8,7 @@
#include <list>
+#include "amount.h"
#include "coins.h"
#include "core.h"
#include "sync.h"
diff --git a/src/wallet.h b/src/wallet.h
index 06706655f8..6a4b4b7f8d 100644
--- a/src/wallet.h
+++ b/src/wallet.h
@@ -6,6 +6,7 @@
#ifndef BITCOIN_WALLET_H
#define BITCOIN_WALLET_H
+#include "amount.h"
#include "core.h"
#include "crypter.h"
#include "key.h"