Browse Source

Merge branch 'networkthread' into develop

cl-refactor
Gav Wood 11 years ago
parent
commit
dc7bb81735
  1. 2
      CMakeLists.txt
  2. 66
      eth/main.cpp
  3. 1
      libethereum/All.h
  4. 4
      libethereum/CMakeLists.txt
  5. 82
      libethereum/Utility.cpp
  6. 32
      libethereum/Utility.h
  7. 3
      neth/CMakeLists.txt
  8. 59
      neth/main.cpp
  9. 2
      stdserv.js

2
CMakeLists.txt

@ -289,7 +289,7 @@ else()
if (LANGUAGES)
find_package(Boost 1.53 REQUIRED COMPONENTS thread date_time)
else()
find_package(Boost 1.53 REQUIRED COMPONENTS thread date_time system)
find_package(Boost 1.53 REQUIRED COMPONENTS thread date_time system regex)
endif()
set(QTQML 1)

66
eth/main.cpp

@ -31,12 +31,7 @@
#endif
#include <libethcore/FileSystem.h>
#include <libevmface/Instruction.h>
#include <libethereum/Defaults.h>
#include <libethereum/Client.h>
#include <libethereum/PeerNetwork.h>
#include <libethereum/BlockChain.h>
#include <libethereum/State.h>
#include <libethcore/CommonEth.h>
#include <libethereum/All.h>
#if ETH_READLINE
#include <readline/readline.h>
#include <readline/history.h>
@ -169,7 +164,7 @@ string pretty(h160 _a, eth::State _st)
}
return ns;
}
bytes parseData(string _args);
int main(int argc, char** argv)
{
unsigned short listenPort = 30303;
@ -434,7 +429,7 @@ int main(int argc, char** argv)
cnote << "Data:";
cnote << sdata;
bytes data = parseData(sdata);
bytes data = eth::parseData(sdata);
cnote << "Bytes:";
string sbd = asString(data);
bytes bbd = asBytes(sbd);
@ -681,58 +676,3 @@ int main(int argc, char** argv)
return 0;
}
bytes parseData(string _args)
{
bytes m_data;
stringstream args(_args);
string arg;
int cc = 0;
while (args >> arg)
{
int al = arg.length();
if (boost::starts_with(arg, "0x"))
{
bytes bs = fromHex(arg);
m_data += bs;
}
else if (arg[0] == '@')
{
arg = arg.substr(1, arg.length());
if (boost::starts_with(arg, "0x"))
{
cnote << "hex: " << arg;
bytes bs = fromHex(arg);
int size = bs.size();
if (size < 32)
for (auto i = 0; i < 32 - size; ++i)
m_data.push_back(0);
m_data += bs;
}
else if (boost::starts_with(arg, "\"") && boost::ends_with(arg, "\""))
{
arg = arg.substr(1, arg.length() - 2);
cnote << "string: " << arg;
if (al < 32)
for (int i = 0; i < 32 - al; ++i)
m_data.push_back(0);
for (int i = 0; i < al; ++i)
m_data.push_back(arg[i]);
}
else
{
cnote << "value: " << arg;
bytes bs = toBigEndian(u256(arg));
int size = bs.size();
if (size < 32)
for (auto i = 0; i < 32 - size; ++i)
m_data.push_back(0);
m_data += bs;
}
}
else
for (int i = 0; i < al; ++i)
m_data.push_back(arg[i]);
cc++;
}
return m_data;
}

1
libethereum/All.h

@ -12,3 +12,4 @@
#include "State.h"
#include "Transaction.h"
#include "TransactionQueue.h"
#include "Utility.h"

4
libethereum/CMakeLists.txt

@ -30,6 +30,7 @@ target_link_libraries(${EXECUTABLE} gmp)
if("${TARGET_PLATFORM}" STREQUAL "w64")
target_link_libraries(${EXECUTABLE} boost_system-mt-s)
target_link_libraries(${EXECUTABLE} boost_regex-mt-s)
target_link_libraries(${EXECUTABLE} boost_filesystem-mt-s)
target_link_libraries(${EXECUTABLE} boost_thread_win32-mt-s)
target_link_libraries(${EXECUTABLE} iphlpapi)
@ -39,18 +40,21 @@ if("${TARGET_PLATFORM}" STREQUAL "w64")
elseif (APPLE)
# Latest mavericks boost libraries only come with -mt
target_link_libraries(${EXECUTABLE} boost_system-mt)
target_link_libraries(${EXECUTABLE} boost_regex-mt)
target_link_libraries(${EXECUTABLE} boost_filesystem-mt)
target_link_libraries(${EXECUTABLE} boost_thread-mt)
find_package(Threads REQUIRED)
target_link_libraries(${EXECUTABLE} ${CMAKE_THREAD_LIBS_INIT})
elseif (UNIX)
target_link_libraries(${EXECUTABLE} ${Boost_SYSTEM_LIBRARY})
target_link_libraries(${EXECUTABLE} ${Boost_REGEX_LIBRARY})
target_link_libraries(${EXECUTABLE} ${Boost_FILESYSTEM_LIBRARY})
target_link_libraries(${EXECUTABLE} ${Boost_THREAD_LIBRARY})
target_link_libraries(${EXECUTABLE} ${Boost_DATE_TIME_LIBRARY})
target_link_libraries(${EXECUTABLE} ${CMAKE_THREAD_LIBS_INIT})
else ()
target_link_libraries(${EXECUTABLE} boost_system)
target_link_libraries(${EXECUTABLE} boost_regex)
target_link_libraries(${EXECUTABLE} boost_filesystem)
target_link_libraries(${EXECUTABLE} boost_thread)
find_package(Threads REQUIRED)

82
libethereum/Utility.cpp

@ -0,0 +1,82 @@
/*
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 Utility.cpp
* @author Gav Wood <i@gavwood.com>
* @date 2014
*/
#include "Utility.h"
#include <boost/regex.hpp>
#include <libethcore/CommonEth.h>
using namespace std;
using namespace eth;
bytes eth::parseData(string const& _args)
{
bytes m_data;
boost::smatch what;
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.*)?");
string s = _args;
while (s.size())
if (boost::regex_match(s, what, d))
{
u256 v((string)what[2]);
if (what[6] == "szabo")
v *= eth::szabo;
else if (what[5] == "finney")
v *= eth::finney;
else if (what[4] == "ether")
v *= eth::ether;
bytes bs = eth::toCompactBigEndian(v);
if (what[1] != "$")
for (auto i = bs.size(); i < 32; ++i)
m_data.push_back(0);
for (auto b: bs)
m_data.push_back(b);
s = what[7];
}
else if (boost::regex_match(s, what, h))
{
bytes bs = fromHex(((what[3].length() & 1) ? "0" : "") + what[3]);
if (what[1] != "$")
for (auto i = bs.size(); i < 32; ++i)
m_data.push_back(0);
for (auto b: bs)
m_data.push_back(b);
s = what[5];
}
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);
else
m_data.push_back(0);
s = what[3];
}
else
s = s.substr(1);
return m_data;
}

32
libethereum/Utility.h

@ -0,0 +1,32 @@
/*
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 Utility.h
* @author Gav Wood <i@gavwood.com>
* @date 2014
*/
#pragma once
#include <string>
#include <libethential/Common.h>
namespace eth
{
bytes parseData(std::string const& _args);
}

3
neth/CMakeLists.txt

@ -34,17 +34,14 @@ if ("${TARGET_PLATFORM}" STREQUAL "w64")
target_link_libraries(${EXECUTABLE} cryptopp)
target_link_libraries(${EXECUTABLE} ncurses)
target_link_libraries(${EXECUTABLE} form)
target_link_libraries(${EXECUTABLE} boost_regex-mt-s)
target_link_libraries(${EXECUTABLE} boost_system-mt-s)
target_link_libraries(${EXECUTABLE} boost_filesystem-mt-s)
target_link_libraries(${EXECUTABLE} boost_thread_win32-mt-s)
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS)
elseif (UNIX)
target_link_libraries(${EXECUTABLE} boost_regex)
target_link_libraries(${EXECUTABLE} ncurses)
target_link_libraries(${EXECUTABLE} form)
else ()
target_link_libraries(${EXECUTABLE} boost_regex)
target_link_libraries(${EXECUTABLE} boost_system)
target_link_libraries(${EXECUTABLE} boost_filesystem)
target_link_libraries(${EXECUTABLE} ncurses)

59
neth/main.cpp

@ -24,7 +24,6 @@
#include <chrono>
#include <fstream>
#include <iostream>
#include <boost/regex.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/trim_all.hpp>
#if ETH_JSONRPC
@ -32,11 +31,7 @@
#endif
#include <libethcore/FileSystem.h>
#include <libevmface/Instruction.h>
#include <libethereum/Defaults.h>
#include <libethereum/Client.h>
#include <libethereum/PeerNetwork.h>
#include <libethereum/BlockChain.h>
#include <libethereum/State.h>
#include <libethereum/All.h>
#if ETH_JSONRPC
#include <eth/EthStubServer.h>
#include <eth/EthStubServer.cpp>
@ -300,8 +295,6 @@ int nc_window_streambuf::sync()
}
vector<string> form_dialog(vector<string> _sfields, vector<string> _lfields, vector<string> _bfields, int _cols, int _rows, string _post_form);
bytes parseData(string _args);
int main(int argc, char** argv)
{
@ -648,7 +641,7 @@ int main(int argc, char** argv)
string sdata = fields[5];
cnote << "Data:";
cnote << sdata;
bytes data = parseData(sdata);
bytes data = eth::parseData(sdata);
cnote << "Bytes:";
string sbd = asString(data);
bytes bbd = asBytes(sbd);
@ -1201,51 +1194,3 @@ vector<string> form_dialog(vector<string> _sv, vector<string> _lv, vector<string
return vs;
}
bytes parseData(string _args)
{
bytes m_data;
stringstream args(_args);
string arg;
static const boost::regex r("\"([^\"]*)\"(.*)");
static const boost::regex h("(0x)?(([a-fA-F0-9])+)(.*)");
while (args >> arg)
{
if (boost::regex_match(arg, h))
{
if (boost::starts_with(arg, "0x"))
{
cnote << "hex: " << arg;
bytes bs = fromHex(arg);
int size = bs.size();
if (size < 32)
for (auto i = 0; i < 32 - size; ++i)
m_data.push_back(0);
m_data += bs;
}
else
{
cnote << "value: " << arg;
bytes bs = toBigEndian(u256(arg));
int size = bs.size();
if (size < 32)
for (auto i = 0; i < 32 - size; ++i)
m_data.push_back(0);
m_data += bs;
}
}
else if (boost::regex_match(arg, r))
{
arg = arg.substr(1, arg.length() - 2);
int al = arg.length();
cnote << "string: " << arg;
for (int i = 0; i < al; ++i)
m_data.push_back(arg[i]);
if (al < 32)
for (int i = 0; i < 32 - al; ++i)
m_data.push_back(0);
}
}
return m_data;
}

2
stdserv.js

@ -195,7 +195,7 @@ var exchangeCode = eth.lll("
(set 'arg1 'send)
(set 'arg2 (address))
(set 'arg3 @xoffer)
(set 'arg4 'origin)
(set 'arg4 (caller))
(unless (msg allgas @offer 0 arg1 128) (stop))
})
(set 'list (sha3pair @offer @want))

Loading…
Cancel
Save