Line data Source code
1 : /** 2 : * @file Coin.h 3 : * 4 : * @brief PublicCoin class for the Zerocoin library. 5 : * 6 : * @author Ian Miers, Christina Garman and Matthew Green 7 : * @date June 2013 8 : * 9 : * @copyright Copyright 2013 Ian Miers, Christina Garman and Matthew Green 10 : * @license This project is released under the MIT license. 11 : **/ 12 : // Copyright (c) 2017-2021 The PIVX Core developers 13 : 14 : #ifndef PIVX_LIBZEROCOIN_COIN_H 15 : #define PIVX_LIBZEROCOIN_COIN_H 16 : 17 : #include "Denominations.h" 18 : #include "Params.h" 19 : #include "amount.h" 20 : #include "bignum.h" 21 : #include "util/system.h" 22 : #include "key.h" 23 : 24 : namespace libzerocoin 25 : { 26 : static int constexpr PUBKEY_VERSION = 2; 27 : static int constexpr CURRENT_VERSION = 2; 28 : static int constexpr V2_BITSHIFT = 4; 29 : 30 : class InvalidSerialException : public std::exception { 31 : public: 32 : std::string message; 33 0 : explicit InvalidSerialException(const std::string &message) : message(message) {} 34 : }; 35 : 36 : int ExtractVersionFromSerial(const CBigNum& bnSerial); 37 : bool IsValidSerial(const ZerocoinParams* params, const CBigNum& bnSerial); 38 : bool IsValidCommitmentToCoinRange(const ZerocoinParams* params, const CBigNum& bnCommitment); 39 : CBigNum GetAdjustedSerial(const CBigNum& bnSerial); 40 : CBigNum ExtractSerialFromPubKey(const CPubKey pubkey); 41 : 42 : /** A Public coin is the part of a coin that 43 : * is published to the network and what is handled 44 : * by other clients. It contains only the value 45 : * of commitment to a serial number and the 46 : * denomination of the coin. 47 : */ 48 0 : class PublicCoin 49 : { 50 : public: 51 : template <typename Stream> 52 : PublicCoin(const ZerocoinParams* p, Stream& strm) : params(p) 53 : { 54 : strm >> *this; 55 : } 56 : 57 : explicit PublicCoin(const ZerocoinParams* p); 58 : 59 : /**Generates a public coin 60 : * 61 : * @param p cryptographic parameters 62 : * @param coin the value of the commitment. 63 : * @param denomination The denomination of the coin. 64 : */ 65 : PublicCoin(const ZerocoinParams* p, const CBigNum& coin, const CoinDenomination d); 66 0 : const CBigNum& getValue() const { return this->value; } 67 : 68 0 : CoinDenomination getDenomination() const { return this->denomination; } 69 : bool operator==(const PublicCoin& rhs) const 70 : { 71 : return ((this->value == rhs.value) && (this->params == rhs.params) && (this->denomination == rhs.denomination)); 72 : } 73 : bool operator!=(const PublicCoin& rhs) const { return !(*this == rhs); } 74 : /** Checks that coin is prime and in the appropriate range given the parameters 75 : * @return true if valid 76 : */ 77 : bool validate() const; 78 : 79 : SERIALIZE_METHODS(PublicCoin, obj) { READWRITE(obj.value, obj.denomination); } 80 : 81 : private: 82 : const ZerocoinParams* params; 83 : CBigNum value; 84 : CoinDenomination denomination; 85 : }; 86 : 87 : } /* namespace libzerocoin */ 88 : #endif // PIVX_LIBZEROCOIN_COIN_H