Changeset View
Changeset View
Standalone View
Standalone View
src/script/script.h
| // Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
| // Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
| // Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
| // file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
| #ifndef BITCOIN_SCRIPT_SCRIPT_H | #ifndef BITCOIN_SCRIPT_SCRIPT_H | ||||
| #define BITCOIN_SCRIPT_SCRIPT_H | #define BITCOIN_SCRIPT_SCRIPT_H | ||||
| #include <attributes.h> | #include <attributes.h> | ||||
| #include <crypto/common.h> | #include <crypto/common.h> | ||||
| #include <prevector.h> | #include <prevector.h> | ||||
| #include <script/intmath.h> | |||||
| #include <serialize.h> | #include <serialize.h> | ||||
| #include <cassert> | #include <cassert> | ||||
| #include <climits> | #include <climits> | ||||
| #include <cstdint> | #include <cstdint> | ||||
| #include <cstring> | #include <cstring> | ||||
| #include <limits> | #include <limits> | ||||
| #include <stdexcept> | #include <stdexcept> | ||||
| ▲ Show 20 Lines • Show All 247 Lines • ▼ Show 20 Lines | public: | ||||
| inline bool operator>=(const CScriptNum &rhs) const { | inline bool operator>=(const CScriptNum &rhs) const { | ||||
| return operator>=(rhs.m_value); | return operator>=(rhs.m_value); | ||||
| } | } | ||||
| inline bool operator>(const CScriptNum &rhs) const { | inline bool operator>(const CScriptNum &rhs) const { | ||||
| return operator>(rhs.m_value); | return operator>(rhs.m_value); | ||||
| } | } | ||||
| inline CScriptNum operator+(const int64_t &rhs) const { | inline CScriptNum operator+(const int64_t &rhs) const { | ||||
| return CScriptNum(m_value + rhs); | int64_t result; | ||||
| if (AddInt63Overflow(m_value, rhs, result)) { | |||||
| throw scriptnum_error("script number overflow"); | |||||
| } | |||||
| return CScriptNum(result); | |||||
| } | } | ||||
| inline CScriptNum operator-(const int64_t &rhs) const { | inline CScriptNum operator-(const int64_t &rhs) const { | ||||
| return CScriptNum(m_value - rhs); | int64_t result; | ||||
| if (SubInt63Overflow(m_value, rhs, result)) { | |||||
| throw scriptnum_error("script number overflow"); | |||||
| } | |||||
| return CScriptNum(result); | |||||
| } | } | ||||
| inline CScriptNum operator+(const CScriptNum &rhs) const { | inline CScriptNum operator+(const CScriptNum &rhs) const { | ||||
| return operator+(rhs.m_value); | return operator+(rhs.m_value); | ||||
| } | } | ||||
| inline CScriptNum operator-(const CScriptNum &rhs) const { | inline CScriptNum operator-(const CScriptNum &rhs) const { | ||||
| return operator-(rhs.m_value); | return operator-(rhs.m_value); | ||||
| } | } | ||||
| Show All 35 Lines | public: | ||||
| } | } | ||||
| inline CScriptNum &operator=(const int64_t &rhs) { | inline CScriptNum &operator=(const int64_t &rhs) { | ||||
| m_value = rhs; | m_value = rhs; | ||||
| return *this; | return *this; | ||||
| } | } | ||||
| inline CScriptNum &operator+=(const int64_t &rhs) { | inline CScriptNum &operator+=(const int64_t &rhs) { | ||||
| assert( | assert(m_value != std::numeric_limits<int64_t>::min()); | ||||
| rhs == 0 || | *this = *this + CScriptNum(rhs); | ||||
| (rhs > 0 && m_value <= std::numeric_limits<int64_t>::max() - rhs) || | |||||
| (rhs < 0 && m_value >= std::numeric_limits<int64_t>::min() - rhs)); | |||||
| m_value += rhs; | |||||
| return *this; | return *this; | ||||
| } | } | ||||
| inline CScriptNum &operator-=(const int64_t &rhs) { | inline CScriptNum &operator-=(const int64_t &rhs) { | ||||
| assert( | assert(m_value != std::numeric_limits<int64_t>::min()); | ||||
| rhs == 0 || | *this = *this - CScriptNum(rhs); | ||||
| (rhs > 0 && m_value >= std::numeric_limits<int64_t>::min() + rhs) || | |||||
| (rhs < 0 && m_value <= std::numeric_limits<int64_t>::max() + rhs)); | |||||
| m_value -= rhs; | |||||
| return *this; | return *this; | ||||
| } | } | ||||
| inline CScriptNum &operator&=(const int64_t &rhs) { | inline CScriptNum &operator&=(const int64_t &rhs) { | ||||
| m_value &= rhs; | m_value &= rhs; | ||||
| return *this; | return *this; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 202 Lines • Show Last 20 Lines | |||||