| 20 | }; |
| 21 | |
| 22 | class CScriptNum10 |
| 23 | { |
| 24 | /** |
| 25 | * The ScriptNum implementation from Bitcoin Core 0.10.0, for cross-comparison. |
| 26 | */ |
| 27 | public: |
| 28 | |
| 29 | explicit CScriptNum10(const int64_t& n) |
| 30 | { |
| 31 | m_value = n; |
| 32 | } |
| 33 | |
| 34 | static const size_t nDefaultMaxNumSize = 4; |
| 35 | |
| 36 | explicit CScriptNum10(const std::vector<unsigned char>& vch, bool fRequireMinimal, |
| 37 | const size_t nMaxNumSize = nDefaultMaxNumSize) |
| 38 | { |
| 39 | if (vch.size() > nMaxNumSize) { |
| 40 | throw scriptnum10_error("script number overflow"); |
| 41 | } |
| 42 | if (fRequireMinimal && vch.size() > 0) { |
| 43 | // Check that the number is encoded with the minimum possible |
| 44 | // number of bytes. |
| 45 | // |
| 46 | // If the most-significant-byte - excluding the sign bit - is zero |
| 47 | // then we're not minimal. Note how this test also rejects the |
| 48 | // negative-zero encoding, 0x80. |
| 49 | if ((vch.back() & 0x7f) == 0) { |
| 50 | // One exception: if there's more than one byte and the most |
| 51 | // significant bit of the second-most-significant-byte is set |
| 52 | // it would conflict with the sign bit. An example of this case |
| 53 | // is +-255, which encode to 0xff00 and 0xff80 respectively. |
| 54 | // (big-endian). |
| 55 | if (vch.size() <= 1 || (vch[vch.size() - 2] & 0x80) == 0) { |
| 56 | throw scriptnum10_error("non-minimally encoded script number"); |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | m_value = set_vch(vch); |
| 61 | } |
| 62 | |
| 63 | inline bool operator==(const int64_t& rhs) const { return m_value == rhs; } |
| 64 | inline bool operator!=(const int64_t& rhs) const { return m_value != rhs; } |
| 65 | inline bool operator<=(const int64_t& rhs) const { return m_value <= rhs; } |
| 66 | inline bool operator< (const int64_t& rhs) const { return m_value < rhs; } |
| 67 | inline bool operator>=(const int64_t& rhs) const { return m_value >= rhs; } |
| 68 | inline bool operator> (const int64_t& rhs) const { return m_value > rhs; } |
| 69 | |
| 70 | inline bool operator==(const CScriptNum10& rhs) const { return operator==(rhs.m_value); } |
| 71 | inline bool operator!=(const CScriptNum10& rhs) const { return operator!=(rhs.m_value); } |
| 72 | inline bool operator<=(const CScriptNum10& rhs) const { return operator<=(rhs.m_value); } |
| 73 | inline bool operator< (const CScriptNum10& rhs) const { return operator< (rhs.m_value); } |
| 74 | inline bool operator>=(const CScriptNum10& rhs) const { return operator>=(rhs.m_value); } |
| 75 | inline bool operator> (const CScriptNum10& rhs) const { return operator> (rhs.m_value); } |
| 76 | |
| 77 | inline CScriptNum10 operator+( const int64_t& rhs) const { return CScriptNum10(m_value + rhs);} |
| 78 | inline CScriptNum10 operator-( const int64_t& rhs) const { return CScriptNum10(m_value - rhs);} |
| 79 | inline CScriptNum10 operator+( const CScriptNum10& rhs) const { return operator+(rhs.m_value); } |
no outgoing calls