/* This file is part of cpp-ethereum. cpp-ethereum is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. cpp-ethereum is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with cpp-ethereum. If not, see . */ /** @file Common.h * @author Gav Wood * @date 2014 * * Very common stuff (i.e. that every other header needs except vector_ref.h). */ #pragma once // way to many unsigned to size_t warnings in 32 bit build #ifdef _M_IX86 #pragma warning(disable:4244) #endif #include #include #include #include #include #include #include #include #include #include #include "vector_ref.h" using byte = uint8_t; namespace dev { // Binary data types. using bytes = std::vector; using bytesRef = vector_ref; using bytesConstRef = vector_ref; template class secure_vector { public: secure_vector() {} secure_vector(secure_vector const& _c) = default; explicit secure_vector(unsigned _size): m_data(_size) {} explicit secure_vector(unsigned _size, T _item): m_data(_size, _item) {} explicit secure_vector(std::vector const& _c): m_data(_c) {} explicit secure_vector(vector_ref _c): m_data(_c.data(), _c.data() + _c.size()) {} explicit secure_vector(vector_ref _c): m_data(_c.data(), _c.data() + _c.size()) {} ~secure_vector() { ref().cleanse(); } secure_vector& operator=(secure_vector const& _c) { if (&_c == this) return *this; ref().cleanse(); m_data = _c.m_data; return *this; } std::vector& writable() { clear(); return m_data; } std::vector const& makeInsecure() const { return m_data; } void clear() { ref().cleanse(); } vector_ref ref() { return vector_ref(&m_data); } vector_ref ref() const { return vector_ref(&m_data); } size_t size() const { return m_data.size(); } bool empty() const { return m_data.empty(); } void swap(secure_vector& io_other) { m_data.swap(io_other.m_data); } private: std::vector m_data; }; using bytesSec = secure_vector; // Numeric types. using bigint = boost::multiprecision::number>; using u64 = boost::multiprecision::number>; using u128 = boost::multiprecision::number>; using u256 = boost::multiprecision::number>; using s256 = boost::multiprecision::number>; using u160 = boost::multiprecision::number>; using s160 = boost::multiprecision::number>; using u512 = boost::multiprecision::number>; using u256s = std::vector; using u160s = std::vector; using u256Set = std::set; using u160Set = std::set; // String types. using strings = std::vector; // Null/Invalid values for convenience. static const u256 Invalid256 = ~(u256)0; /// Converts arbitrary value to string representation using std::stringstream. template std::string toString(_T const& _t) { std::ostringstream o; o << _t; return o.str(); } }