MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / CScriptNum10

Class CScriptNum10

src/test/scriptnum10.h:23–180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 3

operator+Method · 0.85
operator-Method · 0.85
CheckCreateIntFunction · 0.85

Calls 1

maxFunction · 0.85

Tested by 3

operator+Method · 0.68
operator-Method · 0.68
CheckCreateIntFunction · 0.68