From 0331fc28ec479dfdb4d6eae156e08d5b46c4258a Mon Sep 17 00:00:00 2001 From: Mark Friedenbach Date: Thu, 9 Feb 2017 14:19:39 -0800 Subject: [PATCH] [Move Only] Move CTxOutValue to the top of the file since it will be used by the asset generation and reissuance classes. --- src/primitives/transaction.h | 156 +++++++++++++++++------------------ 1 file changed, 78 insertions(+), 78 deletions(-) diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 056f24108b..d360757b37 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -18,6 +18,84 @@ static const int WITNESS_SCALE_FACTOR = 4; static const CFeeRate withdrawLockTxFee = CFeeRate(5460); +class CTxOutValue +{ +public: + static const size_t nExplicitSize = 9; + static const size_t nCommittedSize = 33; + + std::vector vchCommitment; + std::vector vchRangeproof; + std::vector vchNonceCommitment; + + CTxOutValue() { SetNull(); } + CTxOutValue(CAmount); + + ADD_SERIALIZE_METHODS; + + template + inline void SerializationOp(Stream& s, Operation ser_action) { + if ((s.GetVersion() & SERIALIZE_BITCOIN_BLOCK_OR_TX) || IsInBitcoinTransaction()) { + CAmount nAmount = 0; + if (!ser_action.ForRead()) + nAmount = GetAmount(); + READWRITE(nAmount); + if (ser_action.ForRead()) + SetToBitcoinAmount(nAmount); + } else { + // We only serialize the value commitment here. + // The ECDH key and range proof are serialized through CTxOutWitnessSerializer. + READWRITE(vchCommitment.front()); + if (ser_action.ForRead()) { + switch (vchCommitment.front()) { + case 0: + case 1: + vchCommitment.resize(nExplicitSize); + break; + // Alpha used 2 and 3 for value commitments + case 2: + case 3: + break; + case 8: + case 9: + vchCommitment.resize(nCommittedSize); + break; + default: + vchCommitment.resize(1); + return; + } + } + READWRITE(REF(CFlatData(&vchCommitment[1], &vchCommitment[vchCommitment.size()]))); + } + } + + void SetNull(); + bool IsNull() const { return vchCommitment[0] == 0xff; } + + bool IsValid() const; + + // True for both native Amounts and "Bitcoin amounts" + bool IsAmount() const { return vchCommitment[0] == 0 || vchCommitment[0] == 1; } + CAmount GetAmount() const; + + friend bool operator==(const CTxOutValue& a, const CTxOutValue& b) + { + return a.vchRangeproof == b.vchRangeproof && + a.vchCommitment == b.vchCommitment && + a.vchNonceCommitment == b.vchNonceCommitment; + } + + friend bool operator!=(const CTxOutValue& a, const CTxOutValue& b) + { + return !(a == b); + } + +private: // "Bitcoin amounts" can only be set by deserializing with SERIALIZE_BITCOIN_BLOCK_OR_TX + void SetToBitcoinAmount(const CAmount nAmount); + bool IsInBitcoinTransaction() const { return vchCommitment[0] == 0; } + void SetToAmount(const CAmount nAmount); +}; + /** An outpoint - a combination of a transaction hash and an index n into its vout */ class COutPoint { @@ -200,84 +278,6 @@ private: void SetToAssetID(const uint256& assetID); }; -class CTxOutValue -{ -public: - static const size_t nExplicitSize = 9; - static const size_t nCommittedSize = 33; - - std::vector vchCommitment; - std::vector vchRangeproof; - std::vector vchNonceCommitment; - - CTxOutValue() { SetNull(); } - CTxOutValue(CAmount); - - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream& s, Operation ser_action) { - if ((s.GetVersion() & SERIALIZE_BITCOIN_BLOCK_OR_TX) || IsInBitcoinTransaction()) { - CAmount nAmount = 0; - if (!ser_action.ForRead()) - nAmount = GetAmount(); - READWRITE(nAmount); - if (ser_action.ForRead()) - SetToBitcoinAmount(nAmount); - } else { - // We only serialize the value commitment here. - // The ECDH key and range proof are serialized through CTxOutWitnessSerializer. - READWRITE(vchCommitment.front()); - if (ser_action.ForRead()) { - switch (vchCommitment.front()) { - case 0: - case 1: - vchCommitment.resize(nExplicitSize); - break; - // Alpha used 2 and 3 for value commitments - case 2: - case 3: - break; - case 8: - case 9: - vchCommitment.resize(nCommittedSize); - break; - default: - vchCommitment.resize(1); - return; - } - } - READWRITE(REF(CFlatData(&vchCommitment[1], &vchCommitment[vchCommitment.size()]))); - } - } - - void SetNull(); - bool IsNull() const { return vchCommitment[0] == 0xff; } - - bool IsValid() const; - - // True for both native Amounts and "Bitcoin amounts" - bool IsAmount() const { return vchCommitment[0] == 0 || vchCommitment[0] == 1; } - CAmount GetAmount() const; - - friend bool operator==(const CTxOutValue& a, const CTxOutValue& b) - { - return a.vchRangeproof == b.vchRangeproof && - a.vchCommitment == b.vchCommitment && - a.vchNonceCommitment == b.vchNonceCommitment; - } - - friend bool operator!=(const CTxOutValue& a, const CTxOutValue& b) - { - return !(a == b); - } - -private: // "Bitcoin amounts" can only be set by deserializing with SERIALIZE_BITCOIN_BLOCK_OR_TX - void SetToBitcoinAmount(const CAmount nAmount); - bool IsInBitcoinTransaction() const { return vchCommitment[0] == 0; } - void SetToAmount(const CAmount nAmount); -}; - /** An output of a transaction. It contains the public key that the next input * must be able to sign with to claim it. */