6#ifndef BITCOIN_TEST_SCRIPTNUM10_H
7#define BITCOIN_TEST_SCRIPTNUM10_H
36 explicit CScriptNum10(
const std::vector<unsigned char>& vch,
bool fRequireMinimal,
39 if (vch.size() > nMaxNumSize) {
42 if (fRequireMinimal && vch.size() > 0) {
49 if ((vch.back() & 0x7f) == 0) {
55 if (vch.size() <= 1 || (vch[vch.size() - 2] & 0x80) == 0) {
99 assert(rhs == 0 || (rhs > 0 &&
m_value <= std::numeric_limits<int64_t>::max() - rhs) ||
100 (rhs < 0 && m_value >= std::numeric_limits<int64_t>::min() - rhs));
107 assert(rhs == 0 || (rhs > 0 &&
m_value >= std::numeric_limits<int64_t>::min() + rhs) ||
108 (rhs < 0 &&
m_value <= std::numeric_limits<int64_t>::max() + rhs));
115 if (
m_value > std::numeric_limits<int>::max())
116 return std::numeric_limits<int>::max();
117 else if (
m_value < std::numeric_limits<int>::min())
118 return std::numeric_limits<int>::min();
122 std::vector<unsigned char>
getvch()
const
127 static std::vector<unsigned char>
serialize(
const int64_t& value)
130 return std::vector<unsigned char>();
132 std::vector<unsigned char> result;
133 const bool neg = value < 0;
134 uint64_t absvalue = neg ? -value : value;
138 result.push_back(absvalue & 0xff);
152 if (result.back() & 0x80)
153 result.push_back(neg ? 0x80 : 0);
155 result.back() |= 0x80;
161 static int64_t
set_vch(
const std::vector<unsigned char>& vch)
167 for (
size_t i = 0; i != vch.size(); ++i)
168 result |=
static_cast<int64_t
>(vch[i]) << 8*i;
172 if (vch.back() & 0x80)
173 return -((int64_t)(result & ~(0x80ULL << (8 * (vch.size() - 1)))));
bool operator<=(const int64_t &rhs) const
CScriptNum10 & operator=(const int64_t &rhs)
static const size_t nDefaultMaxNumSize
std::vector< unsigned char > getvch() const
bool operator==(const int64_t &rhs) const
static int64_t set_vch(const std::vector< unsigned char > &vch)
CScriptNum10 operator-(const int64_t &rhs) const
bool operator!=(const CScriptNum10 &rhs) const
CScriptNum10 & operator-=(const int64_t &rhs)
bool operator<=(const CScriptNum10 &rhs) const
CScriptNum10 & operator+=(const CScriptNum10 &rhs)
CScriptNum10 operator-(const CScriptNum10 &rhs) const
CScriptNum10 & operator-=(const CScriptNum10 &rhs)
bool operator<(const int64_t &rhs) const
CScriptNum10(const std::vector< unsigned char > &vch, bool fRequireMinimal, const size_t nMaxNumSize=nDefaultMaxNumSize)
CScriptNum10 operator-() const
CScriptNum10(const int64_t &n)
The ScriptNum implementation from Bitcoin Core 0.10.0, for cross-comparison.
bool operator!=(const int64_t &rhs) const
bool operator>(const int64_t &rhs) const
bool operator>=(const int64_t &rhs) const
CScriptNum10 operator+(const int64_t &rhs) const
CScriptNum10 & operator+=(const int64_t &rhs)
CScriptNum10 operator+(const CScriptNum10 &rhs) const
bool operator>=(const CScriptNum10 &rhs) const
static std::vector< unsigned char > serialize(const int64_t &value)
bool operator==(const CScriptNum10 &rhs) const
scriptnum10_error(const std::string &str)