aboutsummaryrefslogtreecommitdiff
path: root/src/core.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/core.h')
-rw-r--r--src/core.h144
1 files changed, 91 insertions, 53 deletions
diff --git a/src/core.h b/src/core.h
index e3ceac97aa..9a2ac47487 100644
--- a/src/core.h
+++ b/src/core.h
@@ -6,7 +6,8 @@
#ifndef BITCOIN_CORE_H
#define BITCOIN_CORE_H
-#include "script.h"
+#include "script/compressor.h"
+#include "script/script.h"
#include "serialize.h"
#include "uint256.h"
@@ -26,13 +27,20 @@ class COutPoint
{
public:
uint256 hash;
- unsigned int n;
+ uint32_t n;
COutPoint() { SetNull(); }
- COutPoint(uint256 hashIn, unsigned int nIn) { hash = hashIn; n = nIn; }
- IMPLEMENT_SERIALIZE( READWRITE(FLATDATA(*this)); )
- void SetNull() { hash = 0; n = (unsigned int) -1; }
- bool IsNull() const { return (hash == 0 && n == (unsigned int) -1); }
+ COutPoint(uint256 hashIn, uint32_t nIn) { hash = hashIn; n = nIn; }
+
+ ADD_SERIALIZE_METHODS;
+
+ template <typename Stream, typename Operation>
+ inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
+ READWRITE(FLATDATA(*this));
+ }
+
+ void SetNull() { hash = 0; n = (uint32_t) -1; }
+ bool IsNull() const { return (hash == 0 && n == (uint32_t) -1); }
friend bool operator<(const COutPoint& a, const COutPoint& b)
{
@@ -57,12 +65,12 @@ class CInPoint
{
public:
const CTransaction* ptx;
- unsigned int n;
+ uint32_t n;
CInPoint() { SetNull(); }
- CInPoint(const CTransaction* ptxIn, unsigned int nIn) { ptx = ptxIn; n = nIn; }
- void SetNull() { ptx = NULL; n = (unsigned int) -1; }
- bool IsNull() const { return (ptx == NULL && n == (unsigned int) -1); }
+ CInPoint(const CTransaction* ptxIn, uint32_t nIn) { ptx = ptxIn; n = nIn; }
+ void SetNull() { ptx = NULL; n = (uint32_t) -1; }
+ bool IsNull() const { return (ptx == NULL && n == (uint32_t) -1); }
};
/** An input of a transaction. It contains the location of the previous
@@ -74,26 +82,28 @@ class CTxIn
public:
COutPoint prevout;
CScript scriptSig;
- unsigned int nSequence;
+ uint32_t nSequence;
CTxIn()
{
nSequence = std::numeric_limits<unsigned int>::max();
}
- explicit CTxIn(COutPoint prevoutIn, CScript scriptSigIn=CScript(), unsigned int nSequenceIn=std::numeric_limits<unsigned int>::max());
- CTxIn(uint256 hashPrevTx, unsigned int nOut, CScript scriptSigIn=CScript(), unsigned int nSequenceIn=std::numeric_limits<unsigned int>::max());
+ explicit CTxIn(COutPoint prevoutIn, CScript scriptSigIn=CScript(), uint32_t nSequenceIn=std::numeric_limits<unsigned int>::max());
+ CTxIn(uint256 hashPrevTx, uint32_t nOut, CScript scriptSigIn=CScript(), uint32_t nSequenceIn=std::numeric_limits<uint32_t>::max());
- IMPLEMENT_SERIALIZE
- (
+ ADD_SERIALIZE_METHODS;
+
+ template <typename Stream, typename Operation>
+ inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
READWRITE(prevout);
READWRITE(scriptSig);
READWRITE(nSequence);
- )
+ }
bool IsFinal() const
{
- return (nSequence == std::numeric_limits<unsigned int>::max());
+ return (nSequence == std::numeric_limits<uint32_t>::max());
}
friend bool operator==(const CTxIn& a, const CTxIn& b)
@@ -136,7 +146,12 @@ public:
friend bool operator>=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK >= b.nSatoshisPerK; }
std::string ToString() const;
- IMPLEMENT_SERIALIZE( READWRITE(nSatoshisPerK); )
+ ADD_SERIALIZE_METHODS;
+
+ template <typename Stream, typename Operation>
+ inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
+ READWRITE(nSatoshisPerK);
+ }
};
@@ -156,11 +171,13 @@ public:
CTxOut(int64_t nValueIn, CScript scriptPubKeyIn);
- IMPLEMENT_SERIALIZE
- (
+ ADD_SERIALIZE_METHODS;
+
+ template <typename Stream, typename Operation>
+ inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
READWRITE(nValue);
READWRITE(scriptPubKey);
- )
+ }
void SetNull()
{
@@ -217,17 +234,17 @@ private:
void UpdateHash() const;
public:
- static const int CURRENT_VERSION=1;
+ static const int32_t CURRENT_VERSION=1;
// The local variables are made const to prevent unintended modification
// without updating the cached hash value. However, CTransaction is not
// actually immutable; deserialization and assignment are implemented,
// and bypass the constness. This is safe, as they update the entire
// structure, including the hash.
- const int nVersion;
+ const int32_t nVersion;
const std::vector<CTxIn> vin;
const std::vector<CTxOut> vout;
- const unsigned int nLockTime;
+ const uint32_t nLockTime;
/** Construct a CTransaction that qualifies as IsNull() */
CTransaction();
@@ -237,15 +254,18 @@ public:
CTransaction& operator=(const CTransaction& tx);
- IMPLEMENT_SERIALIZE(
- READWRITE(*const_cast<int*>(&this->nVersion));
+ ADD_SERIALIZE_METHODS;
+
+ template <typename Stream, typename Operation>
+ inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
+ READWRITE(*const_cast<int32_t*>(&this->nVersion));
nVersion = this->nVersion;
READWRITE(*const_cast<std::vector<CTxIn>*>(&vin));
READWRITE(*const_cast<std::vector<CTxOut>*>(&vout));
- READWRITE(*const_cast<unsigned int*>(&nLockTime));
- if (fRead)
+ READWRITE(*const_cast<uint32_t*>(&nLockTime));
+ if (ser_action.ForRead())
UpdateHash();
- )
+ }
bool IsNull() const {
return vin.empty() && vout.empty();
@@ -263,6 +283,9 @@ public:
// Compute priority, given priority of inputs and (optionally) tx size
double ComputePriority(double dPriorityInputs, unsigned int nTxSize=0) const;
+ // Compute modified tx size for priority calculation (optionally given tx size)
+ unsigned int CalculateModifiedSize(unsigned int nTxSize=0) const;
+
bool IsCoinBase() const
{
return (vin.size() == 1 && vin[0].prevout.IsNull());
@@ -284,21 +307,24 @@ public:
/** A mutable version of CTransaction. */
struct CMutableTransaction
{
- int nVersion;
+ int32_t nVersion;
std::vector<CTxIn> vin;
std::vector<CTxOut> vout;
- unsigned int nLockTime;
+ uint32_t nLockTime;
CMutableTransaction();
CMutableTransaction(const CTransaction& tx);
- IMPLEMENT_SERIALIZE(
+ ADD_SERIALIZE_METHODS;
+
+ template <typename Stream, typename Operation>
+ inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
READWRITE(this->nVersion);
nVersion = this->nVersion;
READWRITE(vin);
READWRITE(vout);
READWRITE(nLockTime);
- )
+ }
/** Compute the hash of this CMutableTransaction. This is computed on the
* fly, as opposed to GetHash() in CTransaction, which uses a cached result.
@@ -318,8 +344,11 @@ public:
CTxOutCompressor(CTxOut &txoutIn) : txout(txoutIn) { }
- IMPLEMENT_SERIALIZE(({
- if (!fRead) {
+ ADD_SERIALIZE_METHODS;
+
+ template <typename Stream, typename Operation>
+ inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
+ if (!ser_action.ForRead()) {
uint64_t nVal = CompressAmount(txout.nValue);
READWRITE(VARINT(nVal));
} else {
@@ -329,7 +358,7 @@ public:
}
CScriptCompressor cscript(REF(txout.scriptPubKey));
READWRITE(cscript);
- });)
+ }
};
/** Undo information for a CTxIn
@@ -382,9 +411,12 @@ public:
// undo information for all txins
std::vector<CTxInUndo> vprevout;
- IMPLEMENT_SERIALIZE(
+ ADD_SERIALIZE_METHODS;
+
+ template <typename Stream, typename Operation>
+ inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
READWRITE(vprevout);
- )
+ }
};
@@ -399,21 +431,23 @@ class CBlockHeader
{
public:
// header
- static const int CURRENT_VERSION=2;
- int nVersion;
+ static const int32_t CURRENT_VERSION=2;
+ int32_t nVersion;
uint256 hashPrevBlock;
uint256 hashMerkleRoot;
- unsigned int nTime;
- unsigned int nBits;
- unsigned int nNonce;
+ uint32_t nTime;
+ uint32_t nBits;
+ uint32_t nNonce;
CBlockHeader()
{
SetNull();
}
- IMPLEMENT_SERIALIZE
- (
+ ADD_SERIALIZE_METHODS;
+
+ template <typename Stream, typename Operation>
+ inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
READWRITE(this->nVersion);
nVersion = this->nVersion;
READWRITE(hashPrevBlock);
@@ -421,7 +455,7 @@ public:
READWRITE(nTime);
READWRITE(nBits);
READWRITE(nNonce);
- )
+ }
void SetNull()
{
@@ -467,11 +501,13 @@ public:
*((CBlockHeader*)this) = header;
}
- IMPLEMENT_SERIALIZE
- (
+ ADD_SERIALIZE_METHODS;
+
+ template <typename Stream, typename Operation>
+ inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
READWRITE(*(CBlockHeader*)this);
READWRITE(vtx);
- )
+ }
void SetNull()
{
@@ -515,12 +551,14 @@ struct CBlockLocator
vHave = vHaveIn;
}
- IMPLEMENT_SERIALIZE
- (
+ ADD_SERIALIZE_METHODS;
+
+ template <typename Stream, typename Operation>
+ inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
if (!(nType & SER_GETHASH))
READWRITE(nVersion);
READWRITE(vHave);
- )
+ }
void SetNull()
{
@@ -533,4 +571,4 @@ struct CBlockLocator
}
};
-#endif
+#endif // BITCOIN_CORE_H