Blackcoin Lore
This commit is contained in:
37
src/coins.h
37
src/coins.h
@@ -1,5 +1,6 @@
|
||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2015 The Bitcoin Core developers
|
||||
// Copyright (c) 2016 The BlackCoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
@@ -27,6 +28,7 @@
|
||||
* - unspentness bitvector, for vout[2] and further; least significant byte first
|
||||
* - the non-spent CTxOuts (via CTxOutCompressor)
|
||||
* - VARINT(nHeight)
|
||||
* - nTime
|
||||
*
|
||||
* The nCode value consists of:
|
||||
* - bit 0: IsCoinBase()
|
||||
@@ -76,6 +78,9 @@ public:
|
||||
//! whether transaction is a coinbase
|
||||
bool fCoinBase;
|
||||
|
||||
//! whether transaction is a coinstake
|
||||
bool fCoinStake;
|
||||
|
||||
//! unspent transaction outputs; spent outputs are .IsNull(); spent outputs at the end of the array are dropped
|
||||
std::vector<CTxOut> vout;
|
||||
|
||||
@@ -86,11 +91,16 @@ public:
|
||||
//! as new tx version will probably only be introduced at certain heights
|
||||
int nVersion;
|
||||
|
||||
//! time of the CTransaction
|
||||
unsigned int nTime;
|
||||
|
||||
void FromTx(const CTransaction &tx, int nHeightIn) {
|
||||
fCoinBase = tx.IsCoinBase();
|
||||
fCoinStake = tx.IsCoinStake();
|
||||
vout = tx.vout;
|
||||
nHeight = nHeightIn;
|
||||
nVersion = tx.nVersion;
|
||||
nTime = tx.nTime;
|
||||
ClearUnspendable();
|
||||
}
|
||||
|
||||
@@ -101,13 +111,15 @@ public:
|
||||
|
||||
void Clear() {
|
||||
fCoinBase = false;
|
||||
fCoinStake = false;
|
||||
std::vector<CTxOut>().swap(vout);
|
||||
nHeight = 0;
|
||||
nVersion = 0;
|
||||
nTime = 0;
|
||||
}
|
||||
|
||||
//! empty constructor
|
||||
CCoins() : fCoinBase(false), vout(0), nHeight(0), nVersion(0) { }
|
||||
CCoins() : fCoinBase(false), fCoinStake(false), vout(0), nHeight(0), nVersion(0), nTime(0) { }
|
||||
|
||||
//!remove spent outputs at the end of vout
|
||||
void Cleanup() {
|
||||
@@ -119,7 +131,7 @@ public:
|
||||
|
||||
void ClearUnspendable() {
|
||||
BOOST_FOREACH(CTxOut &txout, vout) {
|
||||
if (txout.scriptPubKey.IsUnspendable())
|
||||
if (txout.IsUnspendable())
|
||||
txout.SetNull();
|
||||
}
|
||||
Cleanup();
|
||||
@@ -127,9 +139,11 @@ public:
|
||||
|
||||
void swap(CCoins &to) {
|
||||
std::swap(to.fCoinBase, fCoinBase);
|
||||
std::swap(to.fCoinStake, fCoinStake);
|
||||
to.vout.swap(vout);
|
||||
std::swap(to.nHeight, nHeight);
|
||||
std::swap(to.nVersion, nVersion);
|
||||
std::swap(to.nTime, nTime);
|
||||
}
|
||||
|
||||
//! equality test
|
||||
@@ -138,8 +152,10 @@ public:
|
||||
if (a.IsPruned() && b.IsPruned())
|
||||
return true;
|
||||
return a.fCoinBase == b.fCoinBase &&
|
||||
a.fCoinStake == b.fCoinStake &&
|
||||
a.nHeight == b.nHeight &&
|
||||
a.nVersion == b.nVersion &&
|
||||
a.nTime == b.nTime &&
|
||||
a.vout == b.vout;
|
||||
}
|
||||
friend bool operator!=(const CCoins &a, const CCoins &b) {
|
||||
@@ -152,6 +168,10 @@ public:
|
||||
return fCoinBase;
|
||||
}
|
||||
|
||||
bool IsCoinStake() const {
|
||||
return fCoinStake;
|
||||
}
|
||||
|
||||
unsigned int GetSerializeSize(int nType, int nVersion) const {
|
||||
unsigned int nSize = 0;
|
||||
unsigned int nMaskSize = 0, nMaskCode = 0;
|
||||
@@ -159,7 +179,7 @@ public:
|
||||
bool fFirst = vout.size() > 0 && !vout[0].IsNull();
|
||||
bool fSecond = vout.size() > 1 && !vout[1].IsNull();
|
||||
assert(fFirst || fSecond || nMaskCode);
|
||||
unsigned int nCode = 8*(nMaskCode - (fFirst || fSecond ? 0 : 1)) + (fCoinBase ? 1 : 0) + (fFirst ? 2 : 0) + (fSecond ? 4 : 0);
|
||||
unsigned int nCode = 16*(nMaskCode - (fFirst || fSecond ? 0 : 1)) + (fCoinBase ? 1 : 0) + (fFirst ? 2 : 0) + (fSecond ? 4 : 0) + (fCoinStake ? 8 : 0);
|
||||
// version
|
||||
nSize += ::GetSerializeSize(VARINT(this->nVersion), nType, nVersion);
|
||||
// size of header code
|
||||
@@ -172,6 +192,8 @@ public:
|
||||
nSize += ::GetSerializeSize(CTxOutCompressor(REF(vout[i])), nType, nVersion);
|
||||
// height
|
||||
nSize += ::GetSerializeSize(VARINT(nHeight), nType, nVersion);
|
||||
// time
|
||||
nSize += ::GetSerializeSize(nTime, nType, nVersion);
|
||||
return nSize;
|
||||
}
|
||||
|
||||
@@ -182,7 +204,7 @@ public:
|
||||
bool fFirst = vout.size() > 0 && !vout[0].IsNull();
|
||||
bool fSecond = vout.size() > 1 && !vout[1].IsNull();
|
||||
assert(fFirst || fSecond || nMaskCode);
|
||||
unsigned int nCode = 8*(nMaskCode - (fFirst || fSecond ? 0 : 1)) + (fCoinBase ? 1 : 0) + (fFirst ? 2 : 0) + (fSecond ? 4 : 0);
|
||||
unsigned int nCode = 16*(nMaskCode - (fFirst || fSecond ? 0 : 1)) + (fCoinBase ? 1 : 0) + (fFirst ? 2 : 0) + (fSecond ? 4 : 0) + (fCoinStake ? 8 : 0);
|
||||
// version
|
||||
::Serialize(s, VARINT(this->nVersion), nType, nVersion);
|
||||
// header code
|
||||
@@ -202,6 +224,8 @@ public:
|
||||
}
|
||||
// coinbase height
|
||||
::Serialize(s, VARINT(nHeight), nType, nVersion);
|
||||
// time
|
||||
::Serialize(s, nTime, nType, nVersion);
|
||||
}
|
||||
|
||||
template<typename Stream>
|
||||
@@ -212,10 +236,11 @@ public:
|
||||
// header code
|
||||
::Unserialize(s, VARINT(nCode), nType, nVersion);
|
||||
fCoinBase = nCode & 1;
|
||||
fCoinStake = nCode & 8;
|
||||
std::vector<bool> vAvail(2, false);
|
||||
vAvail[0] = (nCode & 2) != 0;
|
||||
vAvail[1] = (nCode & 4) != 0;
|
||||
unsigned int nMaskCode = (nCode / 8) + ((nCode & 6) != 0 ? 0 : 1);
|
||||
unsigned int nMaskCode = (nCode / 16) + ((nCode & 6) != 0 ? 0 : 1);
|
||||
// spentness bitmask
|
||||
while (nMaskCode > 0) {
|
||||
unsigned char chAvail = 0;
|
||||
@@ -235,6 +260,8 @@ public:
|
||||
}
|
||||
// coinbase height
|
||||
::Unserialize(s, VARINT(nHeight), nType, nVersion);
|
||||
// time
|
||||
::Unserialize(s, nTime, nType, nVersion);
|
||||
Cleanup();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user