Skip to content

Commit 42a8996

Browse files
committed
[Core] PIVX: Add fCoinStake boolean field to Coin class
change the serialization/unserialization code, mirroring CTxInUndo class (which will be removed in next commit, and replaced with a serialization adapter for Coin)
1 parent a01a9f2 commit 42a8996

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/coins.h

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* A UTXO entry.
2424
*
2525
* Serialized format:
26-
* - VARINT((coinbase ? 1 : 0) | (height << 1))
26+
* - VARINT((coinbase ? 2 : 0) | (coinstake ? 1 : 0) | (height << 2))
2727
* - the non-spent CTxOut (via CTxOutCompressor)
2828
*/
2929
class Coin
@@ -32,33 +32,41 @@ class Coin
3232
//! whether the containing transaction was a coinbase
3333
bool fCoinBase;
3434

35+
//! whether the containing transaction was a coinstake
36+
bool fCoinStake;
37+
3538
//! unspent transaction output
3639
CTxOut out;
3740

3841
//! at which height the containing transaction was included in the active block chain
3942
uint32_t nHeight;
4043

4144
//! construct a Coin from a CTxOut and height/coinbase properties.
42-
Coin(CTxOut&& outIn, int nHeightIn, bool fCoinBaseIn) : fCoinBase(fCoinBaseIn), out(std::move(outIn)), nHeight(nHeightIn) {}
43-
Coin(const CTxOut& outIn, int nHeightIn, bool fCoinBaseIn) : fCoinBase(fCoinBaseIn), out(outIn), nHeight(nHeightIn) {}
45+
Coin(CTxOut&& outIn, int nHeightIn, bool fCoinBaseIn, bool fCoinStakeIn) : fCoinBase(fCoinBaseIn), fCoinStake(fCoinStakeIn), out(std::move(outIn)), nHeight(nHeightIn) {}
46+
Coin(const CTxOut& outIn, int nHeightIn, bool fCoinBaseIn, bool fCoinStakeIn) : fCoinBase(fCoinBaseIn), fCoinStake(fCoinStakeIn), out(outIn), nHeight(nHeightIn) {}
4447

4548
void Clear() {
4649
out.SetNull();
4750
fCoinBase = false;
51+
fCoinStake = false;
4852
nHeight = 0;
4953
}
5054

5155
//! empty constructor
52-
Coin() : fCoinBase(false), nHeight(0) { }
56+
Coin() : fCoinBase(false), fCoinStake(false), nHeight(0) { }
5357

5458
bool IsCoinBase() const {
5559
return fCoinBase;
5660
}
5761

62+
bool IsCoinStake() const {
63+
return fCoinStake;
64+
}
65+
5866
template<typename Stream>
5967
void Serialize(Stream &s) const {
6068
assert(!IsPruned());
61-
uint32_t code = nHeight * 2 + fCoinBase;
69+
uint32_t code = nHeight * 4 + (fCoinBase ? 2 : 0) + (fCoinStake ? 1 : 0);
6270
::Serialize(s, VARINT(code));
6371
::Serialize(s, CTxOutCompressor(REF(out)));
6472
}
@@ -67,8 +75,9 @@ class Coin
6775
void Unserialize(Stream &s) {
6876
uint32_t code = 0;
6977
::Unserialize(s, VARINT(code));
70-
nHeight = code >> 1;
71-
fCoinBase = code & 1;
78+
nHeight = code >> 2;
79+
fCoinBase = code & 2;
80+
fCoinStake = code & 1;
7281
::Unserialize(s, REF(CTxOutCompressor(out)));
7382
}
7483

0 commit comments

Comments
 (0)