Browse Source

Minor fixes.

cl-refactor
Gav Wood 10 years ago
parent
commit
84962d3136
  1. 1
      CMakeLists.txt
  2. 6
      libethereum/Client.h
  3. 17
      libethereum/Utility.cpp
  4. 12
      libjsqrc/js.qrc
  5. 2
      libqethereum/QEthereum.h
  6. 4
      libweb3jsonrpc/WebThreeStubServer.cpp

1
CMakeLists.txt

@ -49,6 +49,7 @@ endfunction()
function(createBuildInfo)
# Set build platform; to be written to BuildInfo.h
set(ETH_BUILD_PLATFORM ${TARGET_PLATFORM})
if (CMAKE_COMPILER_IS_MINGW)
set(ETH_BUILD_PLATFORM "${ETH_BUILD_PLATFORM}/mingw")
elseif (CMAKE_COMPILER_IS_MSYS)

6
libethereum/Client.h

@ -108,7 +108,7 @@ struct WorkChannel: public LogChannel { static const char* name() { return "-W-"
#define cworkout dev::LogOutputStream<dev::eth::WorkOutChannel, true>()
template <class T> struct ABISerialiser {};
template <unsigned N> struct ABISerialiser<FixedHash<N>> { static bytes serialise(FixedHash<N> const& _t) { static_assert(N < 32, "Parameter sizes must be at most 32 bytes."); return bytes(32 - N, 0) + _t.asBytes(); } };
template <unsigned N> struct ABISerialiser<FixedHash<N>> { static bytes serialise(FixedHash<N> const& _t) { static_assert(N <= 32, "Cannot serialise hash > 32 bytes."); static_assert(N > 0, "Cannot serialise zero-length hash."); return bytes(32 - N, 0) + _t.asBytes(); } };
template <> struct ABISerialiser<u256> { static bytes serialise(u256 const& _t) { return h256(_t).asBytes(); } };
template <> struct ABISerialiser<u160> { static bytes serialise(u160 const& _t) { return bytes(12, 0) + h160(_t).asBytes(); } };
template <> struct ABISerialiser<string32> { static bytes serialise(string32 const& _t) { return bytesConstRef((byte const*)_t.data(), 32).toBytes(); } };
@ -125,9 +125,9 @@ template <class ... T> bytes abiIn(std::string _id, T const& ... _t)
}
template <class T> struct ABIDeserialiser {};
template <unsigned N> struct ABIDeserialiser<FixedHash<N>> { static FixedHash<N> deserialise(bytesConstRef& io_t) { static_assert(N < 32, "Parameter sizes must be at most 32 bytes."); FixedHash<N> ret; io_t.cropped(32 - N, N).populate(ret.ref()); io_t = io_t.cropped(32); return ret; } };
template <unsigned N> struct ABIDeserialiser<FixedHash<N>> { static FixedHash<N> deserialise(bytesConstRef& io_t) { static_assert(N <= 32, "Parameter sizes must be at most 32 bytes."); FixedHash<N> ret; io_t.cropped(32 - N, N).populate(ret.ref()); io_t = io_t.cropped(32); return ret; } };
template <> struct ABIDeserialiser<u256> { static u256 deserialise(bytesConstRef& io_t) { u256 ret = fromBigEndian<u256>(io_t.cropped(0, 32)); io_t = io_t.cropped(32); return ret; } };
template <> struct ABIDeserialiser<u160> { static u256 deserialise(bytesConstRef& io_t) { u160 ret = fromBigEndian<u160>(io_t.cropped(12, 20)); io_t = io_t.cropped(32); return ret; } };
template <> struct ABIDeserialiser<u160> { static u160 deserialise(bytesConstRef& io_t) { u160 ret = fromBigEndian<u160>(io_t.cropped(12, 20)); io_t = io_t.cropped(32); return ret; } };
template <> struct ABIDeserialiser<string32> { static string32 deserialise(bytesConstRef& io_t) { string32 ret; io_t.cropped(0, 32).populate(vector_ref<char>(ret.data(), 32)); io_t = io_t.cropped(32); return ret; } };
template <class T> T abiOut(bytes const& _data)

17
libethereum/Utility.cpp

@ -23,6 +23,7 @@
#include <boost/regex.hpp>
#include <libethcore/CommonEth.h>
#include <libdevcrypto/SHA3.h>
using namespace std;
using namespace dev;
using namespace dev::eth;
@ -32,7 +33,7 @@ bytes dev::eth::parseData(string const& _args)
bytes m_data;
boost::smatch what;
static const boost::regex r("(@|\\$)?\"([^\"]*)\"(\\s.*)?");
static const boost::regex r("(!|#|@|\\$)?\"([^\"]*)\"(\\s.*)?");
static const boost::regex d("(@|\\$)?([0-9]+)(\\s*(ether)|(finney)|(szabo))?(\\s.*)?");
static const boost::regex h("(@|\\$)?(0x)?(([a-fA-F0-9])+)(\\s.*)?");
@ -67,13 +68,15 @@ bytes dev::eth::parseData(string const& _args)
}
else if (boost::regex_match(s, what, r))
{
for (auto i: (string)what[2])
m_data.push_back((byte)i);
if (what[1] != "$")
for (int i = what[2].length(); i < 32; ++i)
m_data.push_back(0);
bytes d = asBytes(what[2]);
if (what[1] == "!")
m_data += FixedHash<4>(sha3(d)).asBytes();
else if (what[1] == "#")
m_data += sha3(d).asBytes();
else if (what[1] == "$")
m_data += d + bytes{0};
else
m_data.push_back(0);
m_data += d + bytes(32 - what[2].length() % 32, 0);
s = what[3];
}
else

12
libjsqrc/js.qrc

@ -1,7 +1,7 @@
<RCC version="1.0">
<qresource prefix="/js">
<file>es6-promise-2.0.0.js</file>
<file>setup.js</file>
<file alias="ethereum.js">ethereumjs/dist/ethereum.js</file>
</qresource>
<RCC>
<qresource prefix="/js">
<file>es6-promise-2.0.0.js</file>
<file>setup.js</file>
<file alias="webthree.js">ethereumjs/dist/ethereum.js</file>
</qresource>
</RCC>

2
libqethereum/QEthereum.h

@ -85,7 +85,7 @@ private:
_frame->addToJavaScriptWindowObject("_web3", qweb, QWebFrame::ScriptOwnership); \
_frame->addToJavaScriptWindowObject("env", _env, QWebFrame::QtOwnership); \
_frame->evaluateJavaScript(contentsOfQResource(":/js/es6-promise-2.0.0.js")); \
_frame->evaluateJavaScript(contentsOfQResource(":/js/ethereum.js")); \
_frame->evaluateJavaScript(contentsOfQResource(":/js/webthree.js")); \
_frame->evaluateJavaScript(contentsOfQResource(":/js/setup.js")); \
}

4
libweb3jsonrpc/WebThreeStubServer.cpp

@ -634,7 +634,7 @@ std::string WebThreeStubServer::eth_transact(Json::Value const& _json)
{
auto b = m_accounts.begin()->first;
for (auto a: m_accounts)
if (client()->balanceAt(a.first) > client()->balanceAt(b))
if (client()->balanceAt(a.first, 0) > client()->balanceAt(b, 0))
b = a.first;
t.from = b;
}
@ -643,7 +643,7 @@ std::string WebThreeStubServer::eth_transact(Json::Value const& _json)
if (!t.gasPrice)
t.gasPrice = 10 * dev::eth::szabo;
if (!t.gas)
t.gas = min<u256>(client()->gasLimitRemaining(), client()->balanceAt(t.from) / t.gasPrice);
t.gas = min<u256>(client()->gasLimitRemaining(), client()->balanceAt(t.from, 0) / t.gasPrice);
if (authenticate(t))
{
if (t.to)

Loading…
Cancel
Save