Browse Source

Bunch of repotting/curating.

[10:59:28] Vitalik Buterin: block.parent.gas_limit * 1023 / 1024 <=
block.gas_limit <= block.parent.gas_limit * 1025/1024
cl-refactor
Gav Wood 10 years ago
parent
commit
103b9ea0a7
  1. 2
      alethzero/Context.cpp
  2. 2
      alethzero/Context.h
  3. 2
      alethzero/Debugger.h
  4. 2
      alethzero/MainWin.h
  5. 2
      alethzero/Transact.h
  6. 12
      libdevcore/Base64.cpp
  7. 9
      libdevcore/Base64.h
  8. 6
      libdevcore/Common.h
  9. 1
      libdevcore/CommonIO.h
  10. 101
      libdevcore/CommonJS.cpp
  11. 116
      libdevcore/CommonJS.h
  12. 12
      libethcore/BlockInfo.cpp
  13. 2
      libethcore/BlockInfo.h
  14. 4
      libethcore/Common.cpp
  15. 2
      libethcore/Common.h
  16. 79
      libethcore/CommonJS.cpp
  17. 114
      libethcore/CommonJS.h
  18. 2
      libethcore/Exceptions.cpp
  19. 4
      libethcore/Exceptions.h
  20. 2
      libethcore/ProofOfWork.h
  21. 2
      libethereum/Account.cpp
  22. 2
      libethereum/AccountDiff.h
  23. 2
      libethereum/BlockChain.h
  24. 2
      libethereum/BlockQueue.h
  25. 2
      libethereum/CanonBlockChain.h
  26. 2
      libethereum/EthereumHost.h
  27. 2
      libethereum/EthereumPeer.h
  28. 2
      libethereum/Executive.h
  29. 2
      libethereum/ExtVM.h
  30. 2
      libethereum/LogFilter.h
  31. 2
      libethereum/Miner.h
  32. 2
      libethereum/Precompiled.cpp
  33. 2
      libethereum/Transaction.h
  34. 2
      libethereum/TransactionQueue.h
  35. 2
      libethereum/Utility.cpp
  36. 2
      libevm/ExtVMFace.h
  37. 2
      libevm/VM.h
  38. 2
      mix/QEther.h
  39. 4
      rlp/main.cpp
  40. 2
      test/MemTrie.cpp
  41. 2
      test/TrieHash.cpp
  42. 2
      test/commonjs.cpp
  43. 2
      third/MainWin.h

2
alethzero/Context.cpp

@ -21,7 +21,7 @@
#include "Context.h" #include "Context.h"
#include <QComboBox> #include <QComboBox>
#include <libethcore/CommonEth.h> #include <libethcore/Common.h>
using namespace std; using namespace std;
using namespace dev; using namespace dev;
using namespace dev::eth; using namespace dev::eth;

2
alethzero/Context.h

@ -25,7 +25,7 @@
#include <vector> #include <vector>
#include <QString> #include <QString>
#include <QList> #include <QList>
#include <libethcore/CommonEth.h> #include <libethcore/Common.h>
class QComboBox; class QComboBox;

2
alethzero/Debugger.h

@ -22,7 +22,7 @@
#pragma once #pragma once
#include <libdevcore/RLP.h> #include <libdevcore/RLP.h>
#include <libethcore/CommonEth.h> #include <libethcore/Common.h>
#include <libethereum/State.h> #include <libethereum/State.h>
#include <libethereum/Executive.h> #include <libethereum/Executive.h>
#include <QDialog> #include <QDialog>

2
alethzero/MainWin.h

@ -32,7 +32,7 @@
#include <QtCore/QMutex> #include <QtCore/QMutex>
#include <QtWidgets/QMainWindow> #include <QtWidgets/QMainWindow>
#include <libdevcore/RLP.h> #include <libdevcore/RLP.h>
#include <libethcore/CommonEth.h> #include <libethcore/Common.h>
#include <libethereum/State.h> #include <libethereum/State.h>
#include <libethereum/Executive.h> #include <libethereum/Executive.h>
#include <libwebthree/WebThree.h> #include <libwebthree/WebThree.h>

2
alethzero/Transact.h

@ -22,7 +22,7 @@
#pragma once #pragma once
#include <libdevcore/RLP.h> #include <libdevcore/RLP.h>
#include <libethcore/CommonEth.h> #include <libethcore/Common.h>
#include <libethereum/Transaction.h> #include <libethereum/Transaction.h>
#include <QDialog> #include <QDialog>
#include <QMap> #include <QMap>

12
rlp/base64.cpp → libdevcore/Base64.cpp

@ -23,13 +23,11 @@
René Nyffenegger rene.nyffenegger@adp-gmbh.ch René Nyffenegger rene.nyffenegger@adp-gmbh.ch
*/ */
/// code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c /// 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 again by Gav Wood. /// Originally by René Nyffenegger, modified by some other guy and then devified by Gav Wood.
#include "base64.h"
#include "Base64.h"
#include <iostream> #include <iostream>
using namespace std; using namespace std;
using namespace dev; using namespace dev;
@ -42,7 +40,7 @@ static inline bool is_base64(byte c) {
return (isalnum(c) || (c == '+') || (c == '/')); return (isalnum(c) || (c == '+') || (c == '/'));
} }
std::string dev::base64_encode(bytesConstRef _in) { std::string dev::toBase64(bytesConstRef _in) {
std::string ret; std::string ret;
int i = 0; int i = 0;
int j = 0; int j = 0;
@ -86,7 +84,7 @@ std::string dev::base64_encode(bytesConstRef _in) {
return ret; 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 in_len = encoded_string.size();
int i = 0; int i = 0;
int j = 0; int j = 0;

9
rlp/base64.h → libdevcore/Base64.h

@ -23,8 +23,9 @@
René Nyffenegger rene.nyffenegger@adp-gmbh.ch René Nyffenegger rene.nyffenegger@adp-gmbh.ch
*/ */
/// code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c /// 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 again by Gav Wood. /// Originally by René Nyffenegger.
/// DEVified by Gav Wood.
#pragma once #pragma once
#include <vector> #include <vector>
@ -34,7 +35,7 @@
namespace dev namespace dev
{ {
std::string base64_encode(bytesConstRef _in); std::string toBase64(bytesConstRef _in);
bytes base64_decode(std::string const& _in); bytes fromBase64(std::string const& _in);
} }

6
libdevcore/Common.h

@ -119,6 +119,12 @@ inline unsigned int toLog2(u256 _x)
return ret; return ret;
} }
template <class N>
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. /// RAII utility class whose destructor calls a given function.
class ScopeGuard { class ScopeGuard {
public: public:

1
libdevcore/CommonIO.h

@ -36,6 +36,7 @@
#include <string> #include <string>
#include <iostream> #include <iostream>
#include "Common.h" #include "Common.h"
#include "Base64.h"
namespace dev namespace dev
{ {

101
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 <http://www.gnu.org/licenses/>.
*/
/** @file CommonJS.cpp
* @authors:
* Gav Wood <i@gavwood.com>
* Marek Kotewicz <marek@ethdev.com>
* @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 "";
}
}

116
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 <http://www.gnu.org/licenses/>.
*/
/** @file CommonJS.h
* @authors:
* Gav Wood <i@gavwood.com>
* Marek Kotewicz <marek@ethdev.com>
* @date 2014
*/
#pragma once
#include <string>
#include "FixedHash.h"
#include "CommonData.h"
#include "CommonIO.h"
namespace dev
{
template <unsigned S> std::string toJS(FixedHash<S> const& _h)
{
return "0x" + toHex(_h.ref());
}
template <unsigned N> std::string toJS(boost::multiprecision::number<boost::multiprecision::cpp_int_backend<N, N, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>> 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 <unsigned N> FixedHash<N> jsToFixed(std::string const& _s)
{
if (_s.substr(0, 2) == "0x")
// Hex
return FixedHash<N>(_s.substr(2 + std::max<unsigned>(N * 2, _s.size() - 2) - N * 2));
else if (_s.find_first_not_of("0123456789") == std::string::npos)
// Decimal
return (typename FixedHash<N>::Arith)(_s);
else
// Binary
return FixedHash<N>(); // FAIL
}
inline std::string jsToFixed(double _s)
{
return toJS(dev::u256(_s * (double)(dev::u256(1) << 128)));
}
template <unsigned N> boost::multiprecision::number<boost::multiprecision::cpp_int_backend<N * 8, N * 8, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>> jsToInt(std::string const& _s)
{
if (_s.substr(0, 2) == "0x")
// Hex
return fromBigEndian<boost::multiprecision::number<boost::multiprecision::cpp_int_backend<N * 8, N * 8, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>>>(fromHex(_s.substr(2)));
else if (_s.find_first_not_of("0123456789") == std::string::npos)
// Decimal
return boost::multiprecision::number<boost::multiprecision::cpp_int_backend<N * 8, N * 8, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>>(_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<unsigned>(_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);
}
}

12
libethcore/BlockInfo.cpp

@ -22,7 +22,7 @@
#include <libdevcore/Common.h> #include <libdevcore/Common.h>
#include <libdevcore/RLP.h> #include <libdevcore/RLP.h>
#include <libdevcrypto/TrieDB.h> #include <libdevcrypto/TrieDB.h>
#include <libethcore/CommonEth.h> #include <libethcore/Common.h>
#include "ProofOfWork.h" #include "ProofOfWork.h"
#include "Exceptions.h" #include "Exceptions.h"
#include "Params.h" #include "Params.h"
@ -203,15 +203,15 @@ u256 BlockInfo::calculateDifficulty(BlockInfo const& _parent) const
return max<u256>(c_minimumDifficulty, timestamp >= _parent.timestamp + c_durationLimit ? _parent.difficulty - (_parent.difficulty / c_difficultyBoundDivisor) : (_parent.difficulty + (_parent.difficulty / c_difficultyBoundDivisor))); return max<u256>(c_minimumDifficulty, timestamp >= _parent.timestamp + c_durationLimit ? _parent.difficulty - (_parent.difficulty / c_difficultyBoundDivisor) : (_parent.difficulty + (_parent.difficulty / c_difficultyBoundDivisor)));
} }
template <class N> inline N diff(N const& _a, N const& _b) { return max(_a, _b) - min(_a, _b); }
void BlockInfo::verifyParent(BlockInfo const& _parent) const 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)) if (difficulty != calculateDifficulty(_parent))
BOOST_THROW_EXCEPTION(InvalidDifficulty()); BOOST_THROW_EXCEPTION(InvalidDifficulty());
if (diff(gasLimit, _parent.gasLimit) <= _parent.gasLimit / c_gasLimitBoundDivisor) if (gasLimit < _parent.gasLimit * (c_gasLimitBoundDivisor - 1) / c_gasLimitBoundDivisor ||
BOOST_THROW_EXCEPTION(InvalidGasLimit(gasLimit, calculateGasLimit(_parent), diff(gasLimit, _parent.gasLimit), _parent.gasLimit / 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)) if (seedHash != calculateSeedHash(_parent))
BOOST_THROW_EXCEPTION(InvalidSeedHash()); BOOST_THROW_EXCEPTION(InvalidSeedHash());

2
libethcore/BlockInfo.h

@ -23,7 +23,7 @@
#include <libdevcore/Common.h> #include <libdevcore/Common.h>
#include <libdevcore/RLP.h> #include <libdevcore/RLP.h>
#include "CommonEth.h" #include "Common.h"
namespace dev namespace dev
{ {

4
libethcore/CommonEth.cpp → libethcore/Common.cpp

@ -14,12 +14,12 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>. along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** @file CommonEth.cpp /** @file Common.cpp
* @author Gav Wood <i@gavwood.com> * @author Gav Wood <i@gavwood.com>
* @date 2014 * @date 2014
*/ */
#include "CommonEth.h" #include "Common.h"
#include <random> #include <random>
#include <libdevcrypto/SHA3.h> #include <libdevcrypto/SHA3.h>
#include "Exceptions.h" #include "Exceptions.h"

2
libethcore/CommonEth.h → libethcore/Common.h

@ -14,7 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>. along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** @file CommonEth.h /** @file Common.h
* @author Gav Wood <i@gavwood.com> * @author Gav Wood <i@gavwood.com>
* @date 2014 * @date 2014
* *

79
libethcore/CommonJS.cpp

@ -26,75 +26,12 @@
namespace dev namespace dev
{ {
bytes jsToBytes(std::string const& _s) Address toAddress(std::string const& _sn)
{ {
if (_s.substr(0, 2) == "0x") if (_sn.size() == 40)
// Hex return Address(fromHex(_sn));
return fromHex(_s.substr(2));
else if (_s.find_first_not_of("0123456789") == std::string::npos)
// Decimal
return toCompactBigEndian(bigint(_s));
else else
return bytes(); return Address();
}
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 "";
} }
std::string prettyU256(u256 _n, bool _abridged) std::string prettyU256(u256 _n, bool _abridged)
@ -128,13 +65,5 @@ std::string prettyU256(u256 _n, bool _abridged)
return s.str(); return s.str();
} }
Address fromString(std::string const& _sn)
{
if (_sn.size() == 40)
return Address(fromHex(_sn));
else
return Address();
}
} }

114
libethcore/CommonJS.h

@ -24,124 +24,38 @@
#pragma once #pragma once
#include <string> #include <string>
#include <libdevcore/Common.h> #include <libdevcore/CommonJS.h>
#include <libdevcore/FixedHash.h> #include <libdevcrypto/Common.h>
#include <libdevcore/CommonData.h> #include "Common.h"
#include <libdevcore/CommonIO.h>
#include "CommonEth.h" // devcrypto
namespace dev namespace dev
{ {
template <unsigned S> std::string toJS(FixedHash<S> const& _h) /// Strictly convert unprefixed hex string string to Address (h160). @returns empty address if (_a.size != 40).
{ Address toAddress(std::string const& _a);
return "0x" + toHex(_h.ref());
}
template <unsigned N> std::string toJS(boost::multiprecision::number<boost::multiprecision::cpp_int_backend<N, N, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>> const& _n) /// Leniently convert string to Public (h512). Accepts integers, "0x" prefixing, non-exact length.
{ inline Public jsToPublic(std::string const& _s) { return jsToFixed<sizeof(dev::Public)>(_s); }
return "0x" + toHex(toCompactBigEndian(_n));
}
inline std::string toJS(dev::bytes const& _n) /// Leniently convert string to Secret (h256). Accepts integers, "0x" prefixing, non-exact length.
{ inline Secret jsToSecret(std::string const& _s) { return jsToFixed<sizeof(dev::Secret)>(_s); }
return "0x" + dev::toHex(_n);
} /// Leniently convert string to Address (h160). Accepts integers, "0x" prefixing, non-exact length.
inline Address jsToAddress(std::string const& _s) { return jsToFixed<sizeof(dev::Address)>(_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. /// 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); 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 <unsigned N> FixedHash<N> jsToFixed(std::string const& _s)
{
if (_s.substr(0, 2) == "0x")
// Hex
return FixedHash<N>(_s.substr(2 + std::max<unsigned>(N * 2, _s.size() - 2) - N * 2));
else if (_s.find_first_not_of("0123456789") == std::string::npos)
// Decimal
return (typename FixedHash<N>::Arith)(_s);
else
// Binary
return FixedHash<N>(); // FAIL
}
inline std::string jsToFixed(double _s)
{
return toJS(dev::u256(_s * (double)(dev::u256(1) << 128)));
}
template <unsigned N> boost::multiprecision::number<boost::multiprecision::cpp_int_backend<N * 8, N * 8, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>> jsToInt(std::string const& _s)
{
if (_s.substr(0, 2) == "0x")
// Hex
return fromBigEndian<boost::multiprecision::number<boost::multiprecision::cpp_int_backend<N * 8, N * 8, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>>>(fromHex(_s.substr(2)));
else if (_s.find_first_not_of("0123456789") == std::string::npos)
// Decimal
return boost::multiprecision::number<boost::multiprecision::cpp_int_backend<N * 8, N * 8, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>>(_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<unsigned>(_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 <libdevcrypto/Common.h>
namespace dev
{
inline Public jsToPublic(std::string const& _s) { return jsToFixed<sizeof(dev::Public)>(_s); }
inline Secret jsToSecret(std::string const& _s) { return jsToFixed<sizeof(dev::Secret)>(_s); }
}
// ethcore // ethcore
namespace dev namespace dev
{ {
namespace eth namespace eth
{ {
inline Address jsToAddress(std::string const& _s) { return jsToFixed<sizeof(dev::Address)>(_s); }
struct TransactionSkeleton struct TransactionSkeleton
{ {
bool creation = false; bool creation = false;

2
libethcore/Exceptions.cpp

@ -39,7 +39,7 @@ static boost::thread_specific_ptr<string> g_exceptionMessage;
const char* InvalidBlockFormat::what() const noexcept { ETH_RETURN_STRING("Invalid block format: Bad field " + toString(m_f) + " (" + toHex(m_d) + ")"); } 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* 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* 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* 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* 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) + ")"); } const char* InvalidBlockNonce::what() const noexcept { ETH_RETURN_STRING("Invalid nonce (h: " + toString(h) + " n:" + toString(n) + " d:" + toString(d) + ")"); }

4
libethcore/Exceptions.h

@ -22,7 +22,7 @@
#pragma once #pragma once
#include <libdevcore/Exceptions.h> #include <libdevcore/Exceptions.h>
#include "CommonEth.h" #include "Common.h"
namespace dev namespace dev
{ {
@ -58,7 +58,7 @@ class InvalidTransactionsHash: virtual public dev::Exception { public: InvalidTr
struct InvalidTransaction: virtual dev::Exception {}; struct InvalidTransaction: virtual dev::Exception {};
struct InvalidDifficulty: virtual dev::Exception {}; struct InvalidDifficulty: virtual dev::Exception {};
struct InvalidSeedHash: 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; }; 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 InvalidTransactionGasUsed: virtual dev::Exception {};
struct InvalidTransactionsStateRoot: virtual dev::Exception {}; struct InvalidTransactionsStateRoot: virtual dev::Exception {};

2
libethcore/ProofOfWork.h

@ -27,7 +27,7 @@
#include <thread> #include <thread>
#include <cstdint> #include <cstdint>
#include <libdevcrypto/SHA3.h> #include <libdevcrypto/SHA3.h>
#include "CommonEth.h" #include "Common.h"
#include "BlockInfo.h" #include "BlockInfo.h"
#define FAKE_DAGGER 1 #define FAKE_DAGGER 1

2
libethereum/Account.cpp

@ -20,7 +20,7 @@
*/ */
#include "Account.h" #include "Account.h"
#include <libethcore/CommonEth.h> #include <libethcore/Common.h>
using namespace std; using namespace std;
using namespace dev; using namespace dev;
using namespace dev::eth; using namespace dev::eth;

2
libethereum/AccountDiff.h

@ -23,7 +23,7 @@
#include <libdevcore/Common.h> #include <libdevcore/Common.h>
#include <libdevcore/Diff.h> #include <libdevcore/Diff.h>
#include <libethcore/CommonEth.h> #include <libethcore/Common.h>
namespace dev namespace dev
{ {

2
libethereum/BlockChain.h

@ -29,7 +29,7 @@
#include <mutex> #include <mutex>
#include <libdevcore/Log.h> #include <libdevcore/Log.h>
#include <libdevcore/Exceptions.h> #include <libdevcore/Exceptions.h>
#include <libethcore/CommonEth.h> #include <libethcore/Common.h>
#include <libethcore/BlockInfo.h> #include <libethcore/BlockInfo.h>
#include <libdevcore/Guards.h> #include <libdevcore/Guards.h>
#include "BlockDetails.h" #include "BlockDetails.h"

2
libethereum/BlockQueue.h

@ -24,7 +24,7 @@
#include <boost/thread.hpp> #include <boost/thread.hpp>
#include <libdevcore/Common.h> #include <libdevcore/Common.h>
#include <libdevcore/Log.h> #include <libdevcore/Log.h>
#include <libethcore/CommonEth.h> #include <libethcore/Common.h>
#include <libdevcore/Guards.h> #include <libdevcore/Guards.h>
namespace dev namespace dev

2
libethereum/CanonBlockChain.h

@ -29,7 +29,7 @@
#include <mutex> #include <mutex>
#include <libdevcore/Log.h> #include <libdevcore/Log.h>
#include <libdevcore/Exceptions.h> #include <libdevcore/Exceptions.h>
#include <libethcore/CommonEth.h> #include <libethcore/Common.h>
#include <libethcore/BlockInfo.h> #include <libethcore/BlockInfo.h>
#include <libdevcore/Guards.h> #include <libdevcore/Guards.h>
#include "BlockDetails.h" #include "BlockDetails.h"

2
libethereum/EthereumHost.h

@ -32,7 +32,7 @@
#include <libdevcore/Guards.h> #include <libdevcore/Guards.h>
#include <libdevcore/Worker.h> #include <libdevcore/Worker.h>
#include <libdevcore/RangeMask.h> #include <libdevcore/RangeMask.h>
#include <libethcore/CommonEth.h> #include <libethcore/Common.h>
#include <libp2p/Common.h> #include <libp2p/Common.h>
#include "CommonNet.h" #include "CommonNet.h"
#include "EthereumPeer.h" #include "EthereumPeer.h"

2
libethereum/EthereumPeer.h

@ -33,7 +33,7 @@
#include <libdevcore/RLP.h> #include <libdevcore/RLP.h>
#include <libdevcore/Guards.h> #include <libdevcore/Guards.h>
#include <libdevcore/RangeMask.h> #include <libdevcore/RangeMask.h>
#include <libethcore/CommonEth.h> #include <libethcore/Common.h>
#include <libp2p/Capability.h> #include <libp2p/Capability.h>
#include "CommonNet.h" #include "CommonNet.h"
#include "DownloadMan.h" #include "DownloadMan.h"

2
libethereum/Executive.h

@ -21,7 +21,7 @@
#include <functional> #include <functional>
#include <libdevcore/Log.h> #include <libdevcore/Log.h>
#include <libevmcore/Instruction.h> #include <libevmcore/Instruction.h>
#include <libethcore/CommonEth.h> #include <libethcore/Common.h>
#include <libevm/VMFace.h> #include <libevm/VMFace.h>
#include "Transaction.h" #include "Transaction.h"

2
libethereum/ExtVM.h

@ -23,7 +23,7 @@
#include <map> #include <map>
#include <functional> #include <functional>
#include <libethcore/CommonEth.h> #include <libethcore/Common.h>
#include <libevm/ExtVMFace.h> #include <libevm/ExtVMFace.h>
#include "State.h" #include "State.h"

2
libethereum/LogFilter.h

@ -23,7 +23,7 @@
#include <libdevcore/Common.h> #include <libdevcore/Common.h>
#include <libdevcore/RLP.h> #include <libdevcore/RLP.h>
#include <libethcore/CommonEth.h> #include <libethcore/Common.h>
#include "TransactionReceipt.h" #include "TransactionReceipt.h"
namespace dev namespace dev

2
libethereum/Miner.h

@ -27,7 +27,7 @@
#include <atomic> #include <atomic>
#include <libdevcore/Common.h> #include <libdevcore/Common.h>
#include <libdevcore/Worker.h> #include <libdevcore/Worker.h>
#include <libethcore/CommonEth.h> #include <libethcore/Common.h>
#include "State.h" #include "State.h"
namespace dev namespace dev

2
libethereum/Precompiled.cpp

@ -23,7 +23,7 @@
#include <libdevcrypto/SHA3.h> #include <libdevcrypto/SHA3.h>
#include <libdevcrypto/Common.h> #include <libdevcrypto/Common.h>
#include <libethcore/CommonEth.h> #include <libethcore/Common.h>
#include <libethcore/Params.h> #include <libethcore/Params.h>
using namespace std; using namespace std;
using namespace dev; using namespace dev;

2
libethereum/Transaction.h

@ -23,7 +23,7 @@
#include <libdevcore/RLP.h> #include <libdevcore/RLP.h>
#include <libdevcrypto/SHA3.h> #include <libdevcrypto/SHA3.h>
#include <libethcore/CommonEth.h> #include <libethcore/Common.h>
namespace dev namespace dev
{ {

2
libethereum/TransactionQueue.h

@ -23,7 +23,7 @@
#include <boost/thread.hpp> #include <boost/thread.hpp>
#include <libdevcore/Common.h> #include <libdevcore/Common.h>
#include "libethcore/CommonEth.h" #include "libethcore/Common.h"
#include <libdevcore/Guards.h> #include <libdevcore/Guards.h>
namespace dev namespace dev

2
libethereum/Utility.cpp

@ -22,7 +22,7 @@
#include "Utility.h" #include "Utility.h"
#include <boost/regex.hpp> #include <boost/regex.hpp>
#include <libethcore/CommonEth.h> #include <libethcore/Common.h>
#include <libdevcrypto/SHA3.h> #include <libdevcrypto/SHA3.h>
using namespace std; using namespace std;
using namespace dev; using namespace dev;

2
libevm/ExtVMFace.h

@ -28,7 +28,7 @@
#include <libdevcore/RLP.h> #include <libdevcore/RLP.h>
#include <libdevcrypto/SHA3.h> #include <libdevcrypto/SHA3.h>
#include <libevmcore/Instruction.h> #include <libevmcore/Instruction.h>
#include <libethcore/CommonEth.h> #include <libethcore/Common.h>
#include <libethcore/BlockInfo.h> #include <libethcore/BlockInfo.h>
namespace dev namespace dev

2
libevm/VM.h

@ -23,7 +23,7 @@
#include <unordered_map> #include <unordered_map>
#include <libdevcore/Exceptions.h> #include <libdevcore/Exceptions.h>
#include <libethcore/CommonEth.h> #include <libethcore/Common.h>
#include <libevmcore/Instruction.h> #include <libevmcore/Instruction.h>
#include <libdevcrypto/SHA3.h> #include <libdevcrypto/SHA3.h>
#include <libethcore/BlockInfo.h> #include <libethcore/BlockInfo.h>

2
mix/QEther.h

@ -23,7 +23,7 @@
#pragma once #pragma once
#include <QObject> #include <QObject>
#include <libethcore/CommonEth.h> #include <libethcore/Common.h>
#include "QBigInt.h" #include "QBigInt.h"
namespace dev namespace dev

4
rlp/main.cpp

@ -22,11 +22,9 @@
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <libdevcore/Common.h>
#include <libdevcore/CommonIO.h> #include <libdevcore/CommonIO.h>
#include <libdevcore/RLP.h> #include <libdevcore/RLP.h>
#include <libdevcrypto/SHA3.h> #include <libdevcrypto/SHA3.h>
#include "base64.h"
using namespace std; using namespace std;
using namespace dev; using namespace dev;
@ -218,7 +216,7 @@ int main(int argc, char** argv)
boost::algorithm::replace_all(s, " ", ""); boost::algorithm::replace_all(s, " ", "");
boost::algorithm::replace_all(s, "\n", ""); boost::algorithm::replace_all(s, "\n", "");
boost::algorithm::replace_all(s, "\t", ""); boost::algorithm::replace_all(s, "\t", "");
b = base64_decode(s); b = fromBase64(s);
break; break;
} }
default: default:

2
test/MemTrie.cpp

@ -23,7 +23,7 @@
#include <libdevcrypto/TrieCommon.h> #include <libdevcrypto/TrieCommon.h>
#include <libdevcrypto/SHA3.h> #include <libdevcrypto/SHA3.h>
#include <libethcore/CommonEth.h> #include <libethcore/Common.h>
using namespace std; using namespace std;
using namespace dev; using namespace dev;
using namespace dev::eth; using namespace dev::eth;

2
test/TrieHash.cpp

@ -23,7 +23,7 @@
#include <libdevcrypto/TrieCommon.h> #include <libdevcrypto/TrieCommon.h>
#include <libdevcrypto/SHA3.h> #include <libdevcrypto/SHA3.h>
#include <libethcore/CommonEth.h> #include <libethcore/Common.h>
using namespace std; using namespace std;
using namespace dev; using namespace dev;
using namespace dev::eth; using namespace dev::eth;

2
test/commonjs.cpp

@ -42,7 +42,7 @@ BOOST_AUTO_TEST_CASE(jsToAddress)
cnote << "Testing jsToPublic..."; cnote << "Testing jsToPublic...";
KeyPair kp = KeyPair::create(); KeyPair kp = KeyPair::create();
string string = toJS(kp.address()); string string = toJS(kp.address());
Address address = dev::eth::jsToAddress(string); Address address = dev::jsToAddress(string);
BOOST_CHECK_EQUAL(kp.address(), address); BOOST_CHECK_EQUAL(kp.address(), address);
} }

2
third/MainWin.h

@ -28,7 +28,7 @@
#include <QtCore/QMutex> #include <QtCore/QMutex>
#include <QtWidgets/QMainWindow> #include <QtWidgets/QMainWindow>
#include <libdevcore/RLP.h> #include <libdevcore/RLP.h>
#include <libethcore/CommonEth.h> #include <libethcore/Common.h>
#include <libethereum/State.h> #include <libethereum/State.h>
namespace Ui { namespace Ui {

Loading…
Cancel
Save