From 210104395fbd0cd1bd00ed2700395f1c4b8b713a Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 5 Mar 2015 11:09:34 +0100 Subject: [PATCH] Bunch of repotting/curating. [10:59:28] Vitalik Buterin: block.parent.gas_limit * 1023 / 1024 <= block.gas_limit <= block.parent.gas_limit * 1025/1024 --- alethzero/Context.cpp | 2 +- alethzero/Context.h | 2 +- alethzero/Debugger.h | 2 +- alethzero/MainWin.h | 2 +- alethzero/Transact.h | 2 +- rlp/base64.cpp => libdevcore/Base64.cpp | 12 +-- rlp/base64.h => libdevcore/Base64.h | 9 +- libdevcore/Common.h | 6 ++ libdevcore/CommonIO.h | 1 + libdevcore/CommonJS.cpp | 101 ++++++++++++++++++++ libdevcore/CommonJS.h | 116 +++++++++++++++++++++++ libethcore/BlockInfo.cpp | 12 +-- libethcore/BlockInfo.h | 2 +- libethcore/{CommonEth.cpp => Common.cpp} | 4 +- libethcore/{CommonEth.h => Common.h} | 2 +- libethcore/CommonJS.cpp | 79 +-------------- libethcore/CommonJS.h | 114 +++------------------- libethcore/Exceptions.cpp | 2 +- libethcore/Exceptions.h | 4 +- libethcore/ProofOfWork.h | 2 +- libethereum/Account.cpp | 2 +- libethereum/AccountDiff.h | 2 +- libethereum/BlockChain.h | 2 +- libethereum/BlockQueue.h | 2 +- libethereum/CanonBlockChain.h | 2 +- libethereum/EthereumHost.h | 2 +- libethereum/EthereumPeer.h | 2 +- libethereum/Executive.h | 2 +- libethereum/ExtVM.h | 2 +- libethereum/LogFilter.h | 2 +- libethereum/Miner.h | 2 +- libethereum/Precompiled.cpp | 2 +- libethereum/Transaction.h | 2 +- libethereum/TransactionQueue.h | 2 +- libethereum/Utility.cpp | 2 +- libevm/ExtVMFace.h | 2 +- libevm/VM.h | 2 +- mix/QEther.h | 2 +- rlp/main.cpp | 94 +++++++++--------- test/MemTrie.cpp | 2 +- test/TrieHash.cpp | 2 +- test/commonjs.cpp | 2 +- third/MainWin.h | 2 +- 43 files changed, 339 insertions(+), 275 deletions(-) rename rlp/base64.cpp => libdevcore/Base64.cpp (91%) rename rlp/base64.h => libdevcore/Base64.h (80%) create mode 100644 libdevcore/CommonJS.cpp create mode 100644 libdevcore/CommonJS.h rename libethcore/{CommonEth.cpp => Common.cpp} (97%) rename libethcore/{CommonEth.h => Common.h} (98%) diff --git a/alethzero/Context.cpp b/alethzero/Context.cpp index d187e6d47..7a5a986d1 100644 --- a/alethzero/Context.cpp +++ b/alethzero/Context.cpp @@ -21,7 +21,7 @@ #include "Context.h" #include -#include +#include using namespace std; using namespace dev; using namespace dev::eth; diff --git a/alethzero/Context.h b/alethzero/Context.h index 098690455..beb368c26 100644 --- a/alethzero/Context.h +++ b/alethzero/Context.h @@ -25,7 +25,7 @@ #include #include #include -#include +#include class QComboBox; diff --git a/alethzero/Debugger.h b/alethzero/Debugger.h index 370ad6e30..76ef6a0d3 100644 --- a/alethzero/Debugger.h +++ b/alethzero/Debugger.h @@ -22,7 +22,7 @@ #pragma once #include -#include +#include #include #include #include diff --git a/alethzero/MainWin.h b/alethzero/MainWin.h index 638469fbe..072911ff7 100644 --- a/alethzero/MainWin.h +++ b/alethzero/MainWin.h @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/alethzero/Transact.h b/alethzero/Transact.h index f14005eff..8ef4f41e0 100644 --- a/alethzero/Transact.h +++ b/alethzero/Transact.h @@ -22,7 +22,7 @@ #pragma once #include -#include +#include #include #include #include diff --git a/rlp/base64.cpp b/libdevcore/Base64.cpp similarity index 91% rename from rlp/base64.cpp rename to libdevcore/Base64.cpp index 5e2b32000..684556cd5 100644 --- a/rlp/base64.cpp +++ b/libdevcore/Base64.cpp @@ -23,13 +23,11 @@ René Nyffenegger rene.nyffenegger@adp-gmbh.ch */ -/// code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c -/// originally by René Nyffenegger, modified by some other guy and then again by Gav Wood. - -#include "base64.h" +/// Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c +/// Originally by René Nyffenegger, modified by some other guy and then devified by Gav Wood. +#include "Base64.h" #include - using namespace std; using namespace dev; @@ -42,7 +40,7 @@ static inline bool is_base64(byte c) { return (isalnum(c) || (c == '+') || (c == '/')); } -std::string dev::base64_encode(bytesConstRef _in) { +std::string dev::toBase64(bytesConstRef _in) { std::string ret; int i = 0; int j = 0; @@ -86,7 +84,7 @@ std::string dev::base64_encode(bytesConstRef _in) { return ret; } -bytes dev::base64_decode(std::string const& encoded_string) { +bytes dev::fromBase64(std::string const& encoded_string) { int in_len = encoded_string.size(); int i = 0; int j = 0; diff --git a/rlp/base64.h b/libdevcore/Base64.h similarity index 80% rename from rlp/base64.h rename to libdevcore/Base64.h index 53ba282c8..1e9c88429 100644 --- a/rlp/base64.h +++ b/libdevcore/Base64.h @@ -23,8 +23,9 @@ René Nyffenegger rene.nyffenegger@adp-gmbh.ch */ -/// code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c -/// originally by René Nyffenegger, modified by some other guy and then again by Gav Wood. +/// Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c +/// Originally by René Nyffenegger. +/// DEVified by Gav Wood. #pragma once #include @@ -34,7 +35,7 @@ namespace dev { -std::string base64_encode(bytesConstRef _in); -bytes base64_decode(std::string const& _in); +std::string toBase64(bytesConstRef _in); +bytes fromBase64(std::string const& _in); } diff --git a/libdevcore/Common.h b/libdevcore/Common.h index 764b3454e..b82cb827e 100644 --- a/libdevcore/Common.h +++ b/libdevcore/Common.h @@ -119,6 +119,12 @@ inline unsigned int toLog2(u256 _x) return ret; } +template +inline N diff(N const& _a, N const& _b) +{ + return std::max(_a, _b) - std::min(_a, _b); +} + /// RAII utility class whose destructor calls a given function. class ScopeGuard { public: diff --git a/libdevcore/CommonIO.h b/libdevcore/CommonIO.h index 1fc8a65e4..03fc9cffc 100644 --- a/libdevcore/CommonIO.h +++ b/libdevcore/CommonIO.h @@ -36,6 +36,7 @@ #include #include #include "Common.h" +#include "Base64.h" namespace dev { diff --git a/libdevcore/CommonJS.cpp b/libdevcore/CommonJS.cpp new file mode 100644 index 000000000..f173e779e --- /dev/null +++ b/libdevcore/CommonJS.cpp @@ -0,0 +1,101 @@ +/* + 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 CommonJS.cpp + * @authors: + * Gav Wood + * Marek Kotewicz + * @date 2014 + */ + +#include "CommonJS.h" + +namespace dev +{ + +bytes jsToBytes(std::string const& _s) +{ + if (_s.substr(0, 2) == "0x") + // Hex + return fromHex(_s.substr(2)); + else if (_s.find_first_not_of("0123456789") == std::string::npos) + // Decimal + return toCompactBigEndian(bigint(_s)); + else + return bytes(); +} + +bytes padded(bytes _b, unsigned _l) +{ + while (_b.size() < _l) + _b.insert(_b.begin(), 0); + return asBytes(asString(_b).substr(_b.size() - std::max(_l, _l))); +} + +bytes paddedRight(bytes _b, unsigned _l) +{ + _b.resize(_l); + return _b; +} + +bytes unpadded(bytes _b) +{ + auto p = asString(_b).find_last_not_of((char)0); + _b.resize(p == std::string::npos ? 0 : (p + 1)); + return _b; +} + +bytes unpadLeft(bytes _b) +{ + unsigned int i = 0; + if (_b.size() == 0) + return _b; + + while (i < _b.size() && _b[i] == byte(0)) + i++; + + if (i != 0) + _b.erase(_b.begin(), _b.begin() + i); + return _b; +} + +std::string fromRaw(h256 _n, unsigned* _inc) +{ + if (_n) + { + std::string s((char const*)_n.data(), 32); + auto l = s.find_first_of('\0'); + if (!l) + return ""; + if (l != std::string::npos) + { + auto p = s.find_first_not_of('\0', l); + if (!(p == std::string::npos || (_inc && p == 31))) + return ""; + if (_inc) + *_inc = (byte)s[31]; + s.resize(l); + } + for (auto i: s) + if (i < 32) + return ""; + return s; + } + return ""; +} + +} + diff --git a/libdevcore/CommonJS.h b/libdevcore/CommonJS.h new file mode 100644 index 000000000..d3e8e6daa --- /dev/null +++ b/libdevcore/CommonJS.h @@ -0,0 +1,116 @@ +/* + 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 CommonJS.h + * @authors: + * Gav Wood + * Marek Kotewicz + * @date 2014 + */ + +#pragma once + +#include +#include "FixedHash.h" +#include "CommonData.h" +#include "CommonIO.h" + +namespace dev +{ + +template std::string toJS(FixedHash const& _h) +{ + return "0x" + toHex(_h.ref()); +} + +template std::string toJS(boost::multiprecision::number> const& _n) +{ + return "0x" + toHex(toCompactBigEndian(_n)); +} + +inline std::string toJS(dev::bytes const& _n) +{ + return "0x" + dev::toHex(_n); +} + +/// Convert string to byte array. Input parameters can be hex or dec. Returns empty array if invalid input e.g neither dec or hex. +bytes jsToBytes(std::string const& _s); +/// Add '0' on the head of @a _b until @a _l. +bytes padded(bytes _b, unsigned _l); +/// Add '0' on the queue of @a _b until @a _l. +bytes paddedRight(bytes _b, unsigned _l); +/// Removing all trailing '0'. Returns empty array if input contains only '0' char. +bytes unpadded(bytes _s); +/// Remove all 0 byte on the head of @a _s. +bytes unpadLeft(bytes _s); +/// Convert h256 into user-readable string (by directly using std::string constructor). +std::string fromRaw(h256 _n, unsigned* _inc = nullptr); + +template FixedHash jsToFixed(std::string const& _s) +{ + if (_s.substr(0, 2) == "0x") + // Hex + return FixedHash(_s.substr(2 + std::max(N * 2, _s.size() - 2) - N * 2)); + else if (_s.find_first_not_of("0123456789") == std::string::npos) + // Decimal + return (typename FixedHash::Arith)(_s); + else + // Binary + return FixedHash(); // FAIL +} + +inline std::string jsToFixed(double _s) +{ + return toJS(dev::u256(_s * (double)(dev::u256(1) << 128))); +} + +template boost::multiprecision::number> jsToInt(std::string const& _s) +{ + if (_s.substr(0, 2) == "0x") + // Hex + return fromBigEndian>>(fromHex(_s.substr(2))); + else if (_s.find_first_not_of("0123456789") == std::string::npos) + // Decimal + return boost::multiprecision::number>(_s); + else + // Binary + return 0; // FAIL +} + +inline u256 jsToU256(std::string const& _s) { return jsToInt<32>(_s); } + +inline std::string jsToDecimal(std::string const& _s) +{ + return dev::toString(jsToU256(_s)); +} + +inline std::string jsFromBinary(dev::bytes _s, unsigned _padding = 32) +{ + _s.resize(std::max(_s.size(), _padding)); + return "0x" + dev::toHex(_s); +} + +inline std::string jsFromBinary(std::string const& _s, unsigned _padding = 32) +{ + return jsFromBinary(asBytes(_s), _padding); +} + +inline double jsFromFixed(std::string const& _s) +{ + return (double)jsToU256(_s) / (double)(dev::u256(1) << 128); +} + +} diff --git a/libethcore/BlockInfo.cpp b/libethcore/BlockInfo.cpp index d8a2357a1..270f96b07 100644 --- a/libethcore/BlockInfo.cpp +++ b/libethcore/BlockInfo.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include "ProofOfWork.h" #include "Exceptions.h" #include "Params.h" @@ -203,15 +203,15 @@ u256 BlockInfo::calculateDifficulty(BlockInfo const& _parent) const return max(c_minimumDifficulty, timestamp >= _parent.timestamp + c_durationLimit ? _parent.difficulty - (_parent.difficulty / c_difficultyBoundDivisor) : (_parent.difficulty + (_parent.difficulty / c_difficultyBoundDivisor))); } -template inline N diff(N const& _a, N const& _b) { return max(_a, _b) - min(_a, _b); } - void BlockInfo::verifyParent(BlockInfo const& _parent) const -{ // Check difficulty is correct given the two timestamps. +{ + // Check difficulty is correct given the two timestamps. if (difficulty != calculateDifficulty(_parent)) BOOST_THROW_EXCEPTION(InvalidDifficulty()); - if (diff(gasLimit, _parent.gasLimit) <= _parent.gasLimit / c_gasLimitBoundDivisor) - BOOST_THROW_EXCEPTION(InvalidGasLimit(gasLimit, calculateGasLimit(_parent), diff(gasLimit, _parent.gasLimit), _parent.gasLimit / c_gasLimitBoundDivisor)); + if (gasLimit < _parent.gasLimit * (c_gasLimitBoundDivisor - 1) / c_gasLimitBoundDivisor || + gasLimit > _parent.gasLimit * (c_gasLimitBoundDivisor + 1) / c_gasLimitBoundDivisor) + BOOST_THROW_EXCEPTION(InvalidGasLimit(gasLimit, _parent.gasLimit * (c_gasLimitBoundDivisor - 1) / c_gasLimitBoundDivisor, _parent.gasLimit * (c_gasLimitBoundDivisor + 1) / c_gasLimitBoundDivisor)); if (seedHash != calculateSeedHash(_parent)) BOOST_THROW_EXCEPTION(InvalidSeedHash()); diff --git a/libethcore/BlockInfo.h b/libethcore/BlockInfo.h index bf986e3a1..a119d92eb 100644 --- a/libethcore/BlockInfo.h +++ b/libethcore/BlockInfo.h @@ -23,7 +23,7 @@ #include #include -#include "CommonEth.h" +#include "Common.h" namespace dev { diff --git a/libethcore/CommonEth.cpp b/libethcore/Common.cpp similarity index 97% rename from libethcore/CommonEth.cpp rename to libethcore/Common.cpp index 822ede5aa..65c0b8b92 100644 --- a/libethcore/CommonEth.cpp +++ b/libethcore/Common.cpp @@ -14,12 +14,12 @@ You should have received a copy of the GNU General Public License along with cpp-ethereum. If not, see . */ -/** @file CommonEth.cpp +/** @file Common.cpp * @author Gav Wood * @date 2014 */ -#include "CommonEth.h" +#include "Common.h" #include #include #include "Exceptions.h" diff --git a/libethcore/CommonEth.h b/libethcore/Common.h similarity index 98% rename from libethcore/CommonEth.h rename to libethcore/Common.h index edefda380..80a253bdd 100644 --- a/libethcore/CommonEth.h +++ b/libethcore/Common.h @@ -14,7 +14,7 @@ You should have received a copy of the GNU General Public License along with cpp-ethereum. If not, see . */ -/** @file CommonEth.h +/** @file Common.h * @author Gav Wood * @date 2014 * diff --git a/libethcore/CommonJS.cpp b/libethcore/CommonJS.cpp index 388738528..ef9ac9f65 100644 --- a/libethcore/CommonJS.cpp +++ b/libethcore/CommonJS.cpp @@ -26,75 +26,12 @@ namespace dev { -bytes jsToBytes(std::string const& _s) +Address toAddress(std::string const& _sn) { - if (_s.substr(0, 2) == "0x") - // Hex - return fromHex(_s.substr(2)); - else if (_s.find_first_not_of("0123456789") == std::string::npos) - // Decimal - return toCompactBigEndian(bigint(_s)); + if (_sn.size() == 40) + return Address(fromHex(_sn)); else - return bytes(); -} - -bytes padded(bytes _b, unsigned _l) -{ - while (_b.size() < _l) - _b.insert(_b.begin(), 0); - return asBytes(asString(_b).substr(_b.size() - std::max(_l, _l))); -} - -bytes paddedRight(bytes _b, unsigned _l) -{ - _b.resize(_l); - return _b; -} - -bytes unpadded(bytes _b) -{ - auto p = asString(_b).find_last_not_of((char)0); - _b.resize(p == std::string::npos ? 0 : (p + 1)); - return _b; -} - -bytes unpadLeft(bytes _b) -{ - unsigned int i = 0; - if (_b.size() == 0) - return _b; - - while (i < _b.size() && _b[i] == byte(0)) - i++; - - if (i != 0) - _b.erase(_b.begin(), _b.begin() + i); - return _b; -} - -std::string fromRaw(h256 _n, unsigned* _inc) -{ - if (_n) - { - std::string s((char const*)_n.data(), 32); - auto l = s.find_first_of('\0'); - if (!l) - return ""; - if (l != std::string::npos) - { - auto p = s.find_first_not_of('\0', l); - if (!(p == std::string::npos || (_inc && p == 31))) - return ""; - if (_inc) - *_inc = (byte)s[31]; - s.resize(l); - } - for (auto i: s) - if (i < 32) - return ""; - return s; - } - return ""; + return Address(); } std::string prettyU256(u256 _n, bool _abridged) @@ -128,13 +65,5 @@ std::string prettyU256(u256 _n, bool _abridged) return s.str(); } -Address fromString(std::string const& _sn) -{ - if (_sn.size() == 40) - return Address(fromHex(_sn)); - else - return Address(); -} - } diff --git a/libethcore/CommonJS.h b/libethcore/CommonJS.h index abe74f0af..7d3071c68 100644 --- a/libethcore/CommonJS.h +++ b/libethcore/CommonJS.h @@ -24,124 +24,38 @@ #pragma once #include -#include -#include -#include -#include -#include "CommonEth.h" +#include +#include +#include "Common.h" + +// devcrypto namespace dev { -template std::string toJS(FixedHash const& _h) -{ - return "0x" + toHex(_h.ref()); -} +/// Strictly convert unprefixed hex string string to Address (h160). @returns empty address if (_a.size != 40). +Address toAddress(std::string const& _a); -template std::string toJS(boost::multiprecision::number> const& _n) -{ - return "0x" + toHex(toCompactBigEndian(_n)); -} +/// Leniently convert string to Public (h512). Accepts integers, "0x" prefixing, non-exact length. +inline Public jsToPublic(std::string const& _s) { return jsToFixed(_s); } -inline std::string toJS(dev::bytes const& _n) -{ - return "0x" + dev::toHex(_n); -} +/// Leniently convert string to Secret (h256). Accepts integers, "0x" prefixing, non-exact length. +inline Secret jsToSecret(std::string const& _s) { return jsToFixed(_s); } + +/// Leniently convert string to Address (h160). Accepts integers, "0x" prefixing, non-exact length. +inline Address jsToAddress(std::string const& _s) { return jsToFixed(_s); } -/// Convert string to byte array. Input parameters can be hex or dec. Returns empty array if invalid input e.g neither dec or hex. -bytes jsToBytes(std::string const& _s); -/// Add '0' on the head of @a _b until @a _l. -bytes padded(bytes _b, unsigned _l); -/// Add '0' on the queue of @a _b until @a _l. -bytes paddedRight(bytes _b, unsigned _l); -/// Removing all trailing '0'. Returns empty array if input contains only '0' char. -bytes unpadded(bytes _s); -/// Remove all 0 byte on the head of @a _s. -bytes unpadLeft(bytes _s); /// Convert u256 into user-readable string. Returns int/hex value of 64 bits int, hex of 160 bits FixedHash. As a fallback try to handle input as h256. std::string prettyU256(u256 _n, bool _abridged = true); -/// Convert h256 into user-readable string (by directly using std::string constructor). -std::string fromRaw(h256 _n, unsigned* _inc = nullptr); -/// Convert string to Address (h160), returns empty address if (_a.size != 40). -Address fromString(std::string const& _a); - -template FixedHash jsToFixed(std::string const& _s) -{ - if (_s.substr(0, 2) == "0x") - // Hex - return FixedHash(_s.substr(2 + std::max(N * 2, _s.size() - 2) - N * 2)); - else if (_s.find_first_not_of("0123456789") == std::string::npos) - // Decimal - return (typename FixedHash::Arith)(_s); - else - // Binary - return FixedHash(); // FAIL -} - -inline std::string jsToFixed(double _s) -{ - return toJS(dev::u256(_s * (double)(dev::u256(1) << 128))); -} - -template boost::multiprecision::number> jsToInt(std::string const& _s) -{ - if (_s.substr(0, 2) == "0x") - // Hex - return fromBigEndian>>(fromHex(_s.substr(2))); - else if (_s.find_first_not_of("0123456789") == std::string::npos) - // Decimal - return boost::multiprecision::number>(_s); - else - // Binary - return 0; // FAIL -} - -inline u256 jsToU256(std::string const& _s) { return jsToInt<32>(_s); } - -inline std::string jsToDecimal(std::string const& _s) -{ - return dev::toString(jsToU256(_s)); -} -inline std::string jsFromBinary(dev::bytes _s, unsigned _padding = 32) -{ - _s.resize(std::max(_s.size(), _padding)); - return "0x" + dev::toHex(_s); } -inline std::string jsFromBinary(std::string const& _s, unsigned _padding = 32) -{ - return jsFromBinary(asBytes(_s), _padding); -} - -inline double jsFromFixed(std::string const& _s) -{ - return (double)jsToU256(_s) / (double)(dev::u256(1) << 128); -} - -} - -// devcrypto - -#include - -namespace dev -{ - -inline Public jsToPublic(std::string const& _s) { return jsToFixed(_s); } -inline Secret jsToSecret(std::string const& _s) { return jsToFixed(_s); } - -} - - // ethcore namespace dev { namespace eth { -inline Address jsToAddress(std::string const& _s) { return jsToFixed(_s); } - struct TransactionSkeleton { bool creation = false; diff --git a/libethcore/Exceptions.cpp b/libethcore/Exceptions.cpp index c4628f4aa..c489c8f4a 100644 --- a/libethcore/Exceptions.cpp +++ b/libethcore/Exceptions.cpp @@ -39,7 +39,7 @@ static boost::thread_specific_ptr g_exceptionMessage; const char* InvalidBlockFormat::what() const noexcept { ETH_RETURN_STRING("Invalid block format: Bad field " + toString(m_f) + " (" + toHex(m_d) + ")"); } const char* UncleInChain::what() const noexcept { ETH_RETURN_STRING("Uncle in block already mentioned: Uncles " + toString(m_uncles) + " (" + m_block.abridged() + ")"); } const char* InvalidTransactionsHash::what() const noexcept { ETH_RETURN_STRING("Invalid transactions hash: header says: " + toHex(m_head.ref()) + " block is:" + toHex(m_real.ref())); } -const char* InvalidGasLimit::what() const noexcept { ETH_RETURN_STRING("Invalid gas limit (provided: " + toString(provided) + " default:" + toString(valid) + " givenDiff:" + toString(givenDiff) + " maxDiff:" + toString(maxDiff) + ")"); } +const char* InvalidGasLimit::what() const noexcept { ETH_RETURN_STRING("Invalid gas limit (provided: " + toString(provided) + " minimum:" + toString(minimum) + " max:" + toString(maximum) + ")"); } const char* InvalidMinGasPrice::what() const noexcept { ETH_RETURN_STRING("Invalid minimum gas price (provided: " + toString(provided) + " limit:" + toString(limit) + ")"); } const char* InvalidNonce::what() const noexcept { ETH_RETURN_STRING("Invalid nonce (r: " + toString(required) + " c:" + toString(candidate) + ")"); } const char* InvalidBlockNonce::what() const noexcept { ETH_RETURN_STRING("Invalid nonce (h: " + toString(h) + " n:" + toString(n) + " d:" + toString(d) + ")"); } diff --git a/libethcore/Exceptions.h b/libethcore/Exceptions.h index 833bc2b04..2d732325b 100644 --- a/libethcore/Exceptions.h +++ b/libethcore/Exceptions.h @@ -22,7 +22,7 @@ #pragma once #include -#include "CommonEth.h" +#include "Common.h" namespace dev { @@ -58,7 +58,7 @@ class InvalidTransactionsHash: virtual public dev::Exception { public: InvalidTr struct InvalidTransaction: virtual dev::Exception {}; struct InvalidDifficulty: virtual dev::Exception {}; struct InvalidSeedHash: virtual dev::Exception {}; -class InvalidGasLimit: virtual public dev::Exception { public: InvalidGasLimit(u256 _provided = 0, u256 _valid = 0, u256 _gD = 0, u256 _mD = 0): provided(_provided), valid(_valid), givenDiff(_gD), maxDiff(_mD) {} u256 provided; u256 valid; u256 givenDiff; u256 maxDiff; virtual const char* what() const noexcept; }; +class InvalidGasLimit: virtual public dev::Exception { public: InvalidGasLimit(u256 _provided = 0, u256 _n = 0, u256 _x = 0): provided(_provided), minimum(_n), maximum(_x) {} u256 provided; u256 minimum; u256 maximum; virtual const char* what() const noexcept; }; class InvalidMinGasPrice: virtual public dev::Exception { public: InvalidMinGasPrice(u256 _provided = 0, u256 _limit = 0): provided(_provided), limit(_limit) {} u256 provided; u256 limit; virtual const char* what() const noexcept; }; struct InvalidTransactionGasUsed: virtual dev::Exception {}; struct InvalidTransactionsStateRoot: virtual dev::Exception {}; diff --git a/libethcore/ProofOfWork.h b/libethcore/ProofOfWork.h index fdf51f0d4..7006f6f61 100644 --- a/libethcore/ProofOfWork.h +++ b/libethcore/ProofOfWork.h @@ -27,7 +27,7 @@ #include #include #include -#include "CommonEth.h" +#include "Common.h" #include "BlockInfo.h" #define FAKE_DAGGER 1 diff --git a/libethereum/Account.cpp b/libethereum/Account.cpp index 74b6ebe7b..13eb0a8cd 100644 --- a/libethereum/Account.cpp +++ b/libethereum/Account.cpp @@ -20,7 +20,7 @@ */ #include "Account.h" -#include +#include using namespace std; using namespace dev; using namespace dev::eth; diff --git a/libethereum/AccountDiff.h b/libethereum/AccountDiff.h index 0c0ede4ae..dd494c0a5 100644 --- a/libethereum/AccountDiff.h +++ b/libethereum/AccountDiff.h @@ -23,7 +23,7 @@ #include #include -#include +#include namespace dev { diff --git a/libethereum/BlockChain.h b/libethereum/BlockChain.h index 0c5587d2a..dbcab2580 100644 --- a/libethereum/BlockChain.h +++ b/libethereum/BlockChain.h @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include #include "BlockDetails.h" diff --git a/libethereum/BlockQueue.h b/libethereum/BlockQueue.h index 210b9eeb0..5eefa9d8e 100644 --- a/libethereum/BlockQueue.h +++ b/libethereum/BlockQueue.h @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include namespace dev diff --git a/libethereum/CanonBlockChain.h b/libethereum/CanonBlockChain.h index d9739097a..7110dbc90 100644 --- a/libethereum/CanonBlockChain.h +++ b/libethereum/CanonBlockChain.h @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include #include "BlockDetails.h" diff --git a/libethereum/EthereumHost.h b/libethereum/EthereumHost.h index dfa928675..16c7056ca 100644 --- a/libethereum/EthereumHost.h +++ b/libethereum/EthereumHost.h @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include "CommonNet.h" #include "EthereumPeer.h" diff --git a/libethereum/EthereumPeer.h b/libethereum/EthereumPeer.h index 71bfc544f..94142ef86 100644 --- a/libethereum/EthereumPeer.h +++ b/libethereum/EthereumPeer.h @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include "CommonNet.h" #include "DownloadMan.h" diff --git a/libethereum/Executive.h b/libethereum/Executive.h index bb5563604..2e89f0623 100644 --- a/libethereum/Executive.h +++ b/libethereum/Executive.h @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include "Transaction.h" diff --git a/libethereum/ExtVM.h b/libethereum/ExtVM.h index 2ff270de5..d63cd943a 100644 --- a/libethereum/ExtVM.h +++ b/libethereum/ExtVM.h @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include "State.h" diff --git a/libethereum/LogFilter.h b/libethereum/LogFilter.h index 5f68cd5d0..7b8922a03 100644 --- a/libethereum/LogFilter.h +++ b/libethereum/LogFilter.h @@ -23,7 +23,7 @@ #include #include -#include +#include #include "TransactionReceipt.h" namespace dev diff --git a/libethereum/Miner.h b/libethereum/Miner.h index fd449e995..bdd49abb9 100644 --- a/libethereum/Miner.h +++ b/libethereum/Miner.h @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include "State.h" namespace dev diff --git a/libethereum/Precompiled.cpp b/libethereum/Precompiled.cpp index 6e0d4756c..62d159418 100644 --- a/libethereum/Precompiled.cpp +++ b/libethereum/Precompiled.cpp @@ -23,7 +23,7 @@ #include #include -#include +#include #include using namespace std; using namespace dev; diff --git a/libethereum/Transaction.h b/libethereum/Transaction.h index a9044970f..7dd28f7c6 100644 --- a/libethereum/Transaction.h +++ b/libethereum/Transaction.h @@ -23,7 +23,7 @@ #include #include -#include +#include namespace dev { diff --git a/libethereum/TransactionQueue.h b/libethereum/TransactionQueue.h index 22a420602..b58944e4f 100644 --- a/libethereum/TransactionQueue.h +++ b/libethereum/TransactionQueue.h @@ -23,7 +23,7 @@ #include #include -#include "libethcore/CommonEth.h" +#include "libethcore/Common.h" #include namespace dev diff --git a/libethereum/Utility.cpp b/libethereum/Utility.cpp index 31c5e278a..7b0a961b2 100644 --- a/libethereum/Utility.cpp +++ b/libethereum/Utility.cpp @@ -22,7 +22,7 @@ #include "Utility.h" #include -#include +#include #include using namespace std; using namespace dev; diff --git a/libevm/ExtVMFace.h b/libevm/ExtVMFace.h index 1bca3e2b2..9a49db113 100644 --- a/libevm/ExtVMFace.h +++ b/libevm/ExtVMFace.h @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include namespace dev diff --git a/libevm/VM.h b/libevm/VM.h index f100badc4..f2c773e4b 100644 --- a/libevm/VM.h +++ b/libevm/VM.h @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include #include diff --git a/mix/QEther.h b/mix/QEther.h index 794ba2ba1..f50c39e7c 100644 --- a/mix/QEther.h +++ b/mix/QEther.h @@ -23,7 +23,7 @@ #pragma once #include -#include +#include #include "QBigInt.h" namespace dev diff --git a/rlp/main.cpp b/rlp/main.cpp index c3c04535b..85c08e0e6 100644 --- a/rlp/main.cpp +++ b/rlp/main.cpp @@ -22,11 +22,9 @@ #include #include #include -#include #include #include #include -#include "base64.h" using namespace std; using namespace dev; @@ -218,7 +216,7 @@ int main(int argc, char** argv) boost::algorithm::replace_all(s, " ", ""); boost::algorithm::replace_all(s, "\n", ""); boost::algorithm::replace_all(s, "\t", ""); - b = base64_decode(s); + b = fromBase64(s); break; } default: @@ -228,60 +226,60 @@ int main(int argc, char** argv) try { - RLP rlp(b); - switch (mode) - { - case Mode::ListArchive: - { - if (!rlp.isList()) + RLP rlp(b); + switch (mode) { - cout << "Error: Invalid format; RLP data is not a list." << endl; - exit(1); - } - cout << rlp.itemCount() << " items:" << endl; - for (auto i: rlp) + case Mode::ListArchive: { - if (!i.isData()) + if (!rlp.isList()) { - cout << "Error: Invalid format; RLP list item is not data." << endl; - if (!lenience) - exit(1); + cout << "Error: Invalid format; RLP data is not a list." << endl; + exit(1); } - cout << " " << i.size() << " bytes: " << sha3(i.data()) << endl; - } - break; - } - case Mode::ExtractArchive: - { - if (!rlp.isList()) - { - cout << "Error: Invalid format; RLP data is not a list." << endl; - exit(1); + cout << rlp.itemCount() << " items:" << endl; + for (auto i: rlp) + { + if (!i.isData()) + { + cout << "Error: Invalid format; RLP list item is not data." << endl; + if (!lenience) + exit(1); + } + cout << " " << i.size() << " bytes: " << sha3(i.data()) << endl; + } + break; } - cout << rlp.itemCount() << " items:" << endl; - for (auto i: rlp) + case Mode::ExtractArchive: { - if (!i.isData()) + if (!rlp.isList()) { - cout << "Error: Invalid format; RLP list item is not data." << endl; - if (!lenience) - exit(1); + cout << "Error: Invalid format; RLP data is not a list." << endl; + exit(1); } - ofstream fout; - fout.open(toString(sha3(i.data()))); - fout.write(reinterpret_cast(i.data().data()), i.data().size()); + cout << rlp.itemCount() << " items:" << endl; + for (auto i: rlp) + { + if (!i.isData()) + { + cout << "Error: Invalid format; RLP list item is not data." << endl; + if (!lenience) + exit(1); + } + ofstream fout; + fout.open(toString(sha3(i.data()))); + fout.write(reinterpret_cast(i.data().data()), i.data().size()); + } + break; + } + case Mode::Render: + { + RLPStreamer s(cout, prefs); + s.output(rlp); + cout << endl; + break; + } + default:; } - break; - } - case Mode::Render: - { - RLPStreamer s(cout, prefs); - s.output(rlp); - cout << endl; - break; - } - default:; - } } catch (...) { diff --git a/test/MemTrie.cpp b/test/MemTrie.cpp index c3a44e1e5..ab5a13b60 100644 --- a/test/MemTrie.cpp +++ b/test/MemTrie.cpp @@ -23,7 +23,7 @@ #include #include -#include +#include using namespace std; using namespace dev; using namespace dev::eth; diff --git a/test/TrieHash.cpp b/test/TrieHash.cpp index ee4f2e87d..ccf12c162 100644 --- a/test/TrieHash.cpp +++ b/test/TrieHash.cpp @@ -23,7 +23,7 @@ #include #include -#include +#include using namespace std; using namespace dev; using namespace dev::eth; diff --git a/test/commonjs.cpp b/test/commonjs.cpp index 041a14f68..72582c540 100644 --- a/test/commonjs.cpp +++ b/test/commonjs.cpp @@ -42,7 +42,7 @@ BOOST_AUTO_TEST_CASE(jsToAddress) cnote << "Testing jsToPublic..."; KeyPair kp = KeyPair::create(); string string = toJS(kp.address()); - Address address = dev::eth::jsToAddress(string); + Address address = dev::jsToAddress(string); BOOST_CHECK_EQUAL(kp.address(), address); } diff --git a/third/MainWin.h b/third/MainWin.h index 513cfe96e..2f8f95f0e 100644 --- a/third/MainWin.h +++ b/third/MainWin.h @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include namespace Ui {