28 #pragma warning(disable:4244) 31 #if _MSC_VER && _MSC_VER < 1900 32 #define _ALLOW_KEYWORD_MACROS 33 #define noexcept throw() 36 #ifdef __INTEL_COMPILER 37 #pragma warning(disable:3682) //call through incomplete class 41 #include <unordered_map> 44 #include <unordered_set> 49 #pragma GCC diagnostic push 50 #pragma GCC diagnostic ignored "-Wunused-parameter" 51 #include <boost/multiprecision/cpp_int.hpp> 53 #pragma GCC diagnostic pop 60 #define DEV_QUOTED_HELPER(s) #s 61 #define DEV_QUOTED(s) DEV_QUOTED_HELPER(s) 63 #define DEV_IGNORE_EXCEPTIONS(X) try { X; } catch (...) {} 65 #define DEV_IF_THROWS(X) try{X;}catch(...) 72 static const std::string EmptyString;
75 using bytes = std::vector<byte>;
121 using bigint = boost::multiprecision::number<boost::multiprecision::cpp_int_backend<>>;
122 using u8 = boost::multiprecision::number<boost::multiprecision::cpp_int_backend<8, 8, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>>;
123 using u64 = boost::multiprecision::number<boost::multiprecision::cpp_int_backend<64, 64, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>>;
124 using u128 = boost::multiprecision::number<boost::multiprecision::cpp_int_backend<128, 128, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>>;
125 using u256 = boost::multiprecision::number<boost::multiprecision::cpp_int_backend<256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>>;
126 using s256 = boost::multiprecision::number<boost::multiprecision::cpp_int_backend<256, 256, boost::multiprecision::signed_magnitude, boost::multiprecision::unchecked, void>>;
127 using u160 = boost::multiprecision::number<boost::multiprecision::cpp_int_backend<160, 160, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>>;
128 using s160 = boost::multiprecision::number<boost::multiprecision::cpp_int_backend<160, 160, boost::multiprecision::signed_magnitude, boost::multiprecision::unchecked, void>>;
129 using u512 = boost::multiprecision::number<boost::multiprecision::cpp_int_backend<512, 512, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>>;
130 using s512 = boost::multiprecision::number<boost::multiprecision::cpp_int_backend<512, 512, boost::multiprecision::signed_magnitude, boost::multiprecision::unchecked, void>>;
151 static const string32 ZeroString32 = {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }};
154 static const bytes NullBytes;
155 static const std::map<u256, u256> EmptyMapU256U256;
162 if (boost::multiprecision::bit_test(_u, 255))
163 return s256(-(c_end - _u));
175 return u256(c_end + _u);
185 for (ret = 0; _x >>= 1; ++ret) {}
202 return static_cast<uint64_t
>(
u64(_u));
207 return static_cast<uint8_t
>(
u8(_u));
212 inline N
diff(N
const& _a, N
const& _b)
225 std::function<void(void)>
m_f;
233 virtual bool invariants()
const = 0;
240 InvariantChecker(
HasInvariants* _this,
char const* _fn,
char const* _file,
int _line): m_this(_this), m_function(_fn), m_file(_file), m_line(_line) { checkInvariants(_this, _fn , _file, _line,
true); }
243 static void checkInvariants(
HasInvariants const* _this,
char const* _fn,
char const* _file,
int line,
bool _pre);
254 #define DEV_INVARIANT_CHECK ::dev::InvariantChecker __dev_invariantCheck(this, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__) 255 #define DEV_INVARIANT_CHECK_HERE ::dev::InvariantChecker::checkInvariants(this, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__, true) 257 #define DEV_INVARIANT_CHECK (void)0; 258 #define DEV_INVARIANT_CHECK_HERE (void)0; 265 TimerHelper(std::string
const& _id,
unsigned _msReportWhenGreater = 0): m_t(
std::
chrono::high_resolution_clock::now()), m_id(_id), m_ms(_msReportWhenGreater) {}
280 double elapsed()
const {
return std::chrono::duration_cast<std::chrono::microseconds>(
duration()).
count() / 1000000.0; }
281 void restart() { m_t = std::chrono::high_resolution_clock::now(); }
287 #define DEV_TIMED(S) for (::std::pair<::dev::TimerHelper, bool> __eth_t(S, true); __eth_t.second; __eth_t.second = false) 288 #define DEV_TIMED_SCOPE(S) ::dev::TimerHelper __eth_t(S) 289 #if defined(_MSC_VER) 290 #define DEV_TIMED_FUNCTION DEV_TIMED_SCOPE(__FUNCSIG__) 292 #define DEV_TIMED_FUNCTION DEV_TIMED_SCOPE(__PRETTY_FUNCTION__) 295 #define DEV_TIMED_ABOVE(S, MS) for (::std::pair<::dev::TimerHelper, bool> __eth_t(::dev::TimerHelper(S, MS), true); __eth_t.second; __eth_t.second = false) 296 #define DEV_TIMED_SCOPE_ABOVE(S, MS) ::dev::TimerHelper __eth_t(S, MS) 297 #if defined(_MSC_VER) 298 #define DEV_TIMED_FUNCTION_ABOVE(MS) DEV_TIMED_SCOPE_ABOVE(__FUNCSIG__, MS) 300 #define DEV_TIMED_FUNCTION_ABOVE(MS) DEV_TIMED_SCOPE_ABOVE(__PRETTY_FUNCTION__, MS) 307 #define DEV_UNUSED __attribute__((unused)) 335 unsigned size = _a.backend().size();
336 auto limbs = _a.backend().limbs();
337 return boost::hash_range(limbs, limbs + size);
uint64_t toUint64(T _u)
Converts given multiprecision number to standard number type.
Inheritable for classes that have invariants.
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
#define function(a, b, c, d, k, s)
A modifiable reference to an existing object or vector in memory.
std::map< bytes, bytes > BytesMap
secure_vector< T > & operator=(secure_vector< T > const &_c)
std::chrono::high_resolution_clock::time_point m_t
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::signed_magnitude, boost::multiprecision::unchecked, void >> s256
RAII utility class whose destructor calls a given function.
uint64_t utcTime()
Get the current time in seconds since the epoch in UTC.
boost::multiprecision::number< boost::multiprecision::cpp_int_backend<>> bigint
RAII checker for invariant assertions.
unsigned int toLog2(u256 _x)
std::function< void(void)> m_f
std::vector< std::string > strings
std::hash for asio::adress
std::vector< T > const & makeInsecure() const
string inUnits(bigint const &_b, strings const &_units)
Converts given int to a string and appends one of a series of units according to its size...
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 160, 160, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u160
std::chrono::high_resolution_clock::duration duration() const
std::map< u256, u256 > u256Map
size_t operator()(dev::u256 const &_a) const
std::vector< u256 > u256s
HasInvariants const * m_this
std::vector< u160 > u160s
std::vector< byte > bytes
secure_vector(vector_ref< T > _c)
ScopeGuard(std::function< void(void)> _f)
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 512, 512, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u512
secure_vector(size_t _size)
Simple scope-based timer helper.
secure_vector(std::vector< T > const &_c)
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u256
std::unordered_map< std::string, std::string > StringHashMap
std::vector< T > & writable()
void swap(secure_vector< T > &io_other)
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 64, 64, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u64
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 128, 128, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u128
std::array< char, 32 > string32
InvariantChecker(HasInvariants *_this, char const *_fn, char const *_file, int _line)
vector_ref< T const > ref() const
s256 u2s(u256 _u)
Interprets _u as a two's complement signed number and returns the resulting s256. ...
std::map< bytes, bytes > HexMap
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 8, 8, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u8
N diff(N const &_a, N const &_b)
clock::time_point time_point
TimerHelper(std::string const &_id, unsigned _msReportWhenGreater=0)
secure_vector(vector_ref< const T > _c)
dev::WithExisting max(dev::WithExisting _a, dev::WithExisting _b)
std::map< std::string, std::string > StringMap
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 160, 160, boost::multiprecision::signed_magnitude, boost::multiprecision::unchecked, void >> s160
std::unordered_map< u256, u256 > u256HashMap
std::chrono::high_resolution_clock::time_point m_t
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 512, 512, boost::multiprecision::signed_magnitude, boost::multiprecision::unchecked, void >> s512
secure_vector(size_t _size, T _item)