Browse Source

Initial commits for skeletons of IEthXi and libethereumx.

cl-refactor
Gav Wood 10 years ago
parent
commit
bd4770944e
  1. 2
      CMakeLists.txt
  2. 260
      exp/main.cpp
  3. 117
      iethxi/CMakeLists.txt
  4. 168
      iethxi/Main.ui
  5. 59
      iethxi/MainWin.cpp
  6. 18
      iethxi/MainWin.h
  7. 5
      iethxi/Resources.qrc
  8. 9
      iethxi/main.cpp
  9. 2
      libethcore/Exceptions.h
  10. 10
      libethereum/BlockChain.cpp
  11. 3
      libethereum/State.cpp
  12. 66
      libethereumx/CMakeLists.txt
  13. 125
      libethereumx/Ethereum.cpp
  14. 144
      libethereumx/Ethereum.h

2
CMakeLists.txt

@ -340,6 +340,7 @@ if (NOT LANGUAGES)
add_subdirectory(libethcore) add_subdirectory(libethcore)
add_subdirectory(libevm) add_subdirectory(libevm)
add_subdirectory(libethereum) add_subdirectory(libethereum)
add_subdirectory(libethereumx)
add_subdirectory(test) add_subdirectory(test)
add_subdirectory(eth) add_subdirectory(eth)
if("x${CMAKE_BUILD_TYPE}" STREQUAL "xDebug") if("x${CMAKE_BUILD_TYPE}" STREQUAL "xDebug")
@ -361,6 +362,7 @@ if (NOT LANGUAGES)
add_subdirectory(alethzero) add_subdirectory(alethzero)
add_subdirectory(third) add_subdirectory(third)
if(QTQML) if(QTQML)
add_subdirectory(iethxi)
add_subdirectory(walleth) add_subdirectory(walleth)
endif() endif()
endif() endif()

260
exp/main.cpp

@ -19,6 +19,12 @@
* @date 2014 * @date 2014
* Ethereum client. * Ethereum client.
*/ */
#if 0
#define BOOST_RESULT_OF_USE_DECLTYPE
#define BOOST_SPIRIT_USE_PHOENIX_V3
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix.hpp>
#include <boost/spirit/include/support_utree.hpp>
#include <libethential/Log.h> #include <libethential/Log.h>
#include <libethential/Common.h> #include <libethential/Common.h>
@ -27,9 +33,263 @@
#include "BuildInfo.h" #include "BuildInfo.h"
using namespace std; using namespace std;
using namespace eth; using namespace eth;
namespace qi = boost::spirit::qi;
namespace px = boost::phoenix;
namespace sp = boost::spirit;
#if 0
class ASTSymbol: public string
{
public:
ASTSymbol() {}
};
enum class ASTType
{
Symbol,
IntegerLiteral,
StringLiteral,
Call,
Return,
Operator,
Compound
};
class ASTNode: public vector<ASTNode>
{
public:
ASTNode() {}
ASTNode(ASTSymbol const& _s): m_type(ASTType::Symbol), m_s(_s) {}
ASTNode(string const& _s): m_type(ASTType::StringLiteral), m_s(_s) {}
ASTNode(bigint const& _i): m_type(ASTType::IntegerLiteral), m_i(_i) {}
ASTNode(ASTType _t): m_type(_t) {}
ASTNode& operator=(ASTSymbol const& _s) { m_type = ASTType::Symbol; m_s = _s; return *this; }
ASTNode& operator=(string const& _s) { m_type = ASTType::StringLiteral; m_s = _s; return *this; }
ASTNode& operator=(bigint const& _i) { m_type = ASTType::IntegerLiteral; m_i = _i; return *this; }
ASTNode& operator=(ASTType const& _s) { m_type = _s; return *this; }
void debugOut(ostream& _out) const;
private:
ASTType m_type;
string m_s;
bigint m_i;
};
void parseTree(string const& _s, ASTNode& o_out)
{
using qi::standard::space;
using qi::standard::space_type;
typedef string::const_iterator it;
/* static const u256 ether = u256(1000000000) * 1000000000;
static const u256 finney = u256(1000000000) * 1000000;
static const u256 szabo = u256(1000000000) * 1000;*/
qi::rule<it, space_type, ASTNode()> element;
qi::rule<it, space_type, ASTNode()> call;
qi::rule<it, string()> str = '"' > qi::lexeme[+(~qi::char_(std::string("\"") + '\0'))] > '"';
qi::rule<it, ASTSymbol()> symbol = qi::lexeme[+(~qi::char_(std::string(" $@[]{}:();\"\x01-\x1f\x7f") + '\0'))];
/* qi::rule<it, string()> strsh = '\'' > qi::lexeme[+(~qi::char_(std::string(" ;$@()[]{}:\n\t") + '\0'))];
qi::rule<it, string()> intstr = qi::lexeme[ qi::no_case["0x"][qi::_val = "0x"] >> *qi::char_("0-9a-fA-F")[qi::_val += qi::_1]] | qi::lexeme[+qi::char_("0-9")[qi::_val += qi::_1]];
qi::rule<it, bigint()> integer = intstr;
qi::rule<it, bigint()> multiplier = qi::lit("wei")[qi::_val = 1] | qi::lit("szabo")[qi::_val = szabo] | qi::lit("finney")[qi::_val = finney] | qi::lit("ether")[qi::_val = ether];
qi::rule<it, space_type, bigint()> quantity = integer[qi::_val = qi::_1] >> -multiplier[qi::_val *= qi::_1];
qi::rule<it, space_type, sp::utree()> atom = quantity[qi::_val = px::construct<sp::any_ptr>(px::new_<bigint>(qi::_1))] | (str | strsh)[qi::_val = qi::_1] | symbol[qi::_val = qi::_1];
qi::rule<it, space_type, sp::utree::list_type()> seq = '{' > *element > '}';
qi::rule<it, space_type, sp::utree::list_type()> mload = '@' > element;
qi::rule<it, space_type, sp::utree::list_type()> sload = qi::lit("@@") > element;
qi::rule<it, space_type, sp::utree::list_type()> mstore = '[' > element > ']' > -qi::lit(":") > element;
qi::rule<it, space_type, sp::utree::list_type()> sstore = qi::lit("[[") > element > qi::lit("]]") > -qi::lit(":") > element;
qi::rule<it, space_type, sp::utree::list_type()> calldataload = qi::lit("$") > element;
qi::rule<it, space_type, sp::utree::list_type()> list = '(' > *element > ')';
qi::rule<it, space_type, sp::utree()> extra = sload[tagNode<2>()] | mload[tagNode<1>()] | sstore[tagNode<4>()] | mstore[tagNode<3>()] | seq[tagNode<5>()] | calldataload[tagNode<6>()];*/
qi::rule<it, space_type, ASTNode()> value = call[qi::_val = ASTType::Call] | str[qi::_val = qi::_1] | symbol[qi::_val = qi::_1];
qi::rule<it, space_type, ASTNode()> compound = '{' > *element > '}';
call = '(' > *value > ')'; //symbol > '(' > !(value > *(',' > value)) > ')';
element = compound[qi::_val = ASTType::Compound] | value[qi::_val = qi::_1];
auto ret = _s.cbegin();
qi::phrase_parse(ret, _s.cend(), element, space, qi::skip_flag::dont_postskip, o_out);
for (auto i = ret; i != _s.cend(); ++i)
if (!isspace(*i))
throw std::exception();
}
void ASTNode::debugOut(ostream& _out) const
{
switch (m_type)
{
case ASTType::StringLiteral:
_out << "\"" << m_s << "\"";
break;
case ASTType::Symbol:
_out << m_s;
break;
case ASTType::Compound:
{
unsigned n = 0;
_out << "{";
for (auto const& i: *this)
{
i.debugOut(_out);
_out << ";";
++n;
}
_out << "}";
break;
}
case ASTType::Call:
{
unsigned n = 0;
for (auto const& i: *this)
{
i.debugOut(_out);
if (n == 0)
_out << "(";
else if (n < size() - 1)
_out << ",";
if (n == size() - 1)
_out << ")";
++n;
}
break;
}
default:
_out << "nil";
}
}
int main(int, char**) int main(int, char**)
{ {
ASTNode out;
parseTree("{x}", out);
out.debugOut(cout);
cout << endl;
return 0;
}
#endif
void killBigints(sp::utree const& _this)
{
switch (_this.which())
{
case sp::utree_type::list_type: for (auto const& i: _this) killBigints(i); break;
case sp::utree_type::any_type: delete _this.get<bigint*>(); break;
default:;
}
}
void debugOutAST(ostream& _out, sp::utree const& _this)
{
switch (_this.which())
{
case sp::utree_type::list_type:
switch (_this.tag())
{
case 0: { int n = 0; for (auto const& i: _this) { debugOutAST(_out, i); if (n++) _out << ", "; } break; }
case 1: _out << "@ "; debugOutAST(_out, _this.front()); break;
case 2: _out << "@@ "; debugOutAST(_out, _this.front()); break;
case 3: _out << "[ "; debugOutAST(_out, _this.front()); _out << " ] "; debugOutAST(_out, _this.back()); break;
case 4: _out << "[[ "; debugOutAST(_out, _this.front()); _out << " ]] "; debugOutAST(_out, _this.back()); break;
case 5: _out << "{ "; for (auto const& i: _this) { debugOutAST(_out, i); _out << " "; } _out << "}"; break;
case 6: _out << "$ "; debugOutAST(_out, _this.front()); break;
default:
{ _out << _this.tag() << ": "; int n = 0; for (auto const& i: _this) { debugOutAST(_out, i); if (n++) _out << ", "; } break; }
}
break;
case sp::utree_type::int_type: _out << _this.get<int>(); break;
case sp::utree_type::string_type: _out << "\"" << _this.get<sp::basic_string<boost::iterator_range<char const*>, sp::utree_type::string_type>>() << "\""; break;
case sp::utree_type::symbol_type: _out << _this.get<sp::basic_string<boost::iterator_range<char const*>, sp::utree_type::symbol_type>>(); break;
case sp::utree_type::any_type: _out << *_this.get<bigint*>(); break;
default: _out << "nil";
}
}
namespace eth {
namespace parseTreeLLL_ {
template<unsigned N>
struct tagNode
{
void operator()(sp::utree& n, qi::rule<string::const_iterator, qi::ascii::space_type, sp::utree()>::context_type& c) const
{
(boost::fusion::at_c<0>(c.attributes) = n).tag(N);
}
};
}}
void parseTree(string const& _s, sp::utree& o_out)
{
using qi::standard::space;
using qi::standard::space_type;
using eth::parseTreeLLL_::tagNode;
typedef sp::basic_string<std::string, sp::utree_type::symbol_type> symbol_type;
typedef string::const_iterator it;
static const u256 ether = u256(1000000000) * 1000000000;
static const u256 finney = u256(1000000000) * 1000000;
static const u256 szabo = u256(1000000000) * 1000;
#if 0
qi::rule<it, space_type, sp::utree()> element;
qi::rule<it, space_type, sp::utree()> statement;
qi::rule<it, string()> str = '"' > qi::lexeme[+(~qi::char_(std::string("\"") + '\0'))] > '"';
qi::rule<it, string()> strsh = '\'' > qi::lexeme[+(~qi::char_(std::string(" ;$@()[]{}:\n\t") + '\0'))];
qi::rule<it, symbol_type()> symbol = qi::lexeme[+(~qi::char_(std::string(" $@[]{}:();\"\x01-\x1f\x7f") + '\0'))];
qi::rule<it, string()> intstr = qi::lexeme[ qi::no_case["0x"][qi::_val = "0x"] >> *qi::char_("0-9a-fA-F")[qi::_val += qi::_1]] | qi::lexeme[+qi::char_("0-9")[qi::_val += qi::_1]];
qi::rule<it, bigint()> integer = intstr;
qi::rule<it, bigint()> multiplier = qi::lit("wei")[qi::_val = 1] | qi::lit("szabo")[qi::_val = szabo] | qi::lit("finney")[qi::_val = finney] | qi::lit("ether")[qi::_val = ether];
qi::rule<it, space_type, bigint()> quantity = integer[qi::_val = qi::_1] >> -multiplier[qi::_val *= qi::_1];
qi::rule<it, space_type, sp::utree()> atom = quantity[qi::_val = px::construct<sp::any_ptr>(px::new_<bigint>(qi::_1))] | (str | strsh)[qi::_val = qi::_1] | symbol[qi::_val = qi::_1];
qi::rule<it, space_type, sp::utree::list_type()> compound = '{' > *statement > '}';
/* qi::rule<it, space_type, sp::utree::list_type()> mload = '@' > element;
qi::rule<it, space_type, sp::utree::list_type()> sload = qi::lit("@@") > element;
qi::rule<it, space_type, sp::utree::list_type()> mstore = '[' > element > ']' > -qi::lit(":") > element;
qi::rule<it, space_type, sp::utree::list_type()> sstore = qi::lit("[[") > element > qi::lit("]]") > -qi::lit(":") > element;
qi::rule<it, space_type, sp::utree::list_type()> calldataload = qi::lit("$") > element;*/
// qi::rule<it, space_type, sp::utree::list_type()> args = '(' > (element % ',') > ')';
qi::rule<it, space_type, sp::utree::list_type()> expression;
qi::rule<it, space_type, sp::utree()> group = '(' >> expression[qi::_val = qi::_1] >> ')';
qi::rule<it, space_type, sp::utree()> factor = atom | group;
qi::rule<it, space_type, sp::utree()> mul = '*' >> factor;
qi::rule<it, space_type, sp::utree()> div = '/' >> factor;
qi::rule<it, space_type, sp::utree()> op = mul[tagNode<10>()] | div[tagNode<11>()];
qi::rule<it, space_type, sp::utree::list_type()> term = factor >> !op;
expression = term >> !(('+' >> term) | ('-' >> term));
// qi::rule<it, space_type, sp::utree()> extra = sload[tagNode<2>()] | mload[tagNode<1>()] | sstore[tagNode<4>()] | mstore[tagNode<3>()] | calldataload[tagNode<6>()];
statement = compound[tagNode<5>()] | (element > ';')[qi::_val = qi::_1];
element %= expression;// | extra;
#endif
qi::rule<it, symbol_type()> symbol = qi::lexeme[+(~qi::char_(std::string(" $@[]{}:();\"\x01-\x1f\x7f") + '\0'))];
qi::rule<it, string()> intstr = qi::lexeme[ qi::no_case["0x"][qi::_val = "0x"] >> *qi::char_("0-9a-fA-F")[qi::_val += qi::_1]] | qi::lexeme[+qi::char_("0-9")[qi::_val += qi::_1]];
qi::rule<it, bigint()> integer = intstr;
qi::rule<it, sp::utree()> intnode = integer[qi::_val = px::construct<sp::any_ptr>(px::new_<bigint>(qi::_1))];
qi::rule<it, space_type, sp::utree()> funcname = symbol;
qi::rule<it, space_type, sp::utree()> statement;
qi::rule<it, space_type, sp::utree::list_type()> call = funcname > '(' > funcname > ')';
statement = call | intnode | symbol;
auto ret = _s.cbegin();
qi::phrase_parse(ret, _s.cend(), statement, space, qi::skip_flag::dont_postskip, o_out);
for (auto i = ret; i != _s.cend(); ++i)
if (!isspace(*i))
throw std::exception();
}
#endif
int main(int, char**)
{
#if 0
sp::utree out;
parseTree("x(2)", out);
debugOutAST(cout, out);
killBigints(out);
cout << endl;
#endif
return 0; return 0;
} }

117
iethxi/CMakeLists.txt

@ -0,0 +1,117 @@
cmake_policy(SET CMP0015 NEW)
if ("${TARGET_PLATFORM}" STREQUAL "w64")
cmake_policy(SET CMP0020 NEW)
endif ()
set(CMAKE_INCLUDE_CURRENT_DIR ON)
aux_source_directory(. SRC_LIST)
include_directories(..)
link_directories(../libethcore)
link_directories(../libethereum)
link_directories(../libqethereum)
# Find Qt5 for Apple and update src_list for windows
if (APPLE)
# homebrew defaults to qt4 and installs qt5 as 'keg-only'
# which places it into /usr/local/opt insteadof /usr/local.
set(CMAKE_PREFIX_PATH /usr/local/opt/qt5)
include_directories(/usr/local/opt/qt5/include /usr/local/include)
elseif ("${TARGET_PLATFORM}" STREQUAL "w64")
set(SRC_LIST ${SRC_LIST} ../windows/qt_plugin_import.cpp)
elseif (UNIX)
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ";$ENV{QTDIR}/lib/cmake")
endif ()
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5Quick REQUIRED)
find_package(Qt5Qml REQUIRED)
find_package(Qt5Network REQUIRED)
qt5_wrap_ui(ui_Main.h Main.ui)
qt5_add_resources(RESOURCE_ADDED Resources.qrc)
# Set name of binary and add_executable()
if (APPLE)
set(EXECUTEABLE IEthXi)
set(CMAKE_INSTALL_PREFIX ./)
set(BIN_INSTALL_DIR ".")
set(DOC_INSTALL_DIR ".")
set(PROJECT_VERSION "${ETH_VERSION}")
set(MACOSX_BUNDLE_INFO_STRING "${PROJECT_NAME} ${PROJECT_VERSION}")
set(MACOSX_BUNDLE_BUNDLE_VERSION "${PROJECT_NAME} ${PROJECT_VERSION}")
set(MACOSX_BUNDLE_LONG_VERSION_STRING "${PROJECT_NAME} ${PROJECT_VERSION}")
set(MACOSX_BUNDLE_SHORT_VERSION_STRING "${PROJECT_VERSION}")
set(MACOSX_BUNDLE_COPYRIGHT "${PROJECT_COPYRIGHT_YEAR} ${PROJECT_VENDOR}")
set(MACOSX_BUNDLE_GUI_IDENTIFIER "${PROJECT_DOMAIN_SECOND}.${PROJECT_DOMAIN_FIRST}")
set(MACOSX_BUNDLE_BUNDLE_NAME ${EXECUTEABLE})
include(BundleUtilities)
add_executable(${EXECUTEABLE} MACOSX_BUNDLE Main.ui ${RESOURCE_ADDED} ${SRC_LIST})
else ()
set(EXECUTEABLE iethxi)
add_executable(${EXECUTEABLE} Main.ui ${RESOURCE_ADDED} ${SRC_LIST})
endif ()
qt5_use_modules(${EXECUTEABLE} Core Gui Widgets Network Quick Qml)
target_link_libraries(${EXECUTEABLE} qethereum ethereum secp256k1 ${CRYPTOPP_LS})
if (APPLE)
if (${ADDFRAMEWORKS})
set_target_properties(${EXECUTEABLE} PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/EthereumMacOSXBundleInfo.plist.in")
endif ()
SET_SOURCE_FILES_PROPERTIES(${EXECUTEABLE} PROPERTIES MACOSX_PACKAGE_LOCATION MacOS)
# This is a workaround for when the build-type defaults to Debug, and when a multi-config generator like xcode is used, where the type
# will not be set but defaults to release.
set(generator_lowercase "${CMAKE_GENERATOR}")
string(TOLOWER "${CMAKE_GENERATOR}" generator_lowercase)
if ("${generator_lowercase}" STREQUAL "xcode")
# TODO: Not sure how to resolve this. Possibly \${TARGET_BUILD_DIR}
set(binary_build_dir "${CMAKE_CURRENT_BINARY_DIR}/Debug")
else ()
set(binary_build_dir "${CMAKE_CURRENT_BINARY_DIR}")
endif ()
set(APPS ${binary_build_dir}/${EXECUTEABLE}.app)
# This tool and the next will automatically looked at the linked libraries in order to determine what dependencies are required. Thus, target_link_libaries only needs to add ethereum and secp256k1 (above)
install(CODE "
include(BundleUtilities)
set(BU_CHMOD_BUNDLE_ITEMS 1)
fixup_bundle(\"${APPS}\" \"${BUNDLELIBS}\" \"../libqethereum ../libethereum ../secp256k1\")
" COMPONENT RUNTIME )
if (${ADDFRAMEWORKS})
add_custom_target(addframeworks ALL
COMMAND /usr/local/opt/qt5/bin/macdeployqt ${binary_build_dir}/${EXECUTEABLE}.app
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
DEPENDS ${PROJECT_NAME}
)
endif ()
elseif ("${TARGET_PLATFORM}" STREQUAL "w64")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-keep-inline-dllexport -static-libgcc -static-libstdc++ -static")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-s -Wl,-subsystem,windows -mthreads -L/usr/x86_64-w64-mingw32/plugins/platforms")
target_link_libraries(${EXECUTEABLE} gcc)
target_link_libraries(${EXECUTEABLE} mingw32 qtmain mswsock iphlpapi qwindows shlwapi Qt5PlatformSupport gdi32 comdlg32 oleaut32 imm32 winmm ole32 uuid ws2_32)
target_link_libraries(${EXECUTEABLE} boost_system-mt-s)
target_link_libraries(${EXECUTEABLE} boost_filesystem-mt-s)
target_link_libraries(${EXECUTEABLE} boost_thread_win32-mt-s)
target_link_libraries(${EXECUTEABLE} Qt5PlatformSupport)
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS)
elseif (UNIX)
else ()
target_link_libraries(${EXECUTEABLE} boost_system)
target_link_libraries(${EXECUTEABLE} boost_filesystem)
find_package(Threads REQUIRED)
target_link_libraries(${EXECUTEABLE} ${CMAKE_THREAD_LIBS_INIT})
install( TARGETS ${EXECUTEABLE} RUNTIME DESTINATION bin )
endif ()

168
iethxi/Main.ui

@ -0,0 +1,168 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Main</class>
<widget class="QMainWindow" name="Main">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>562</width>
<height>488</height>
</rect>
</property>
<property name="windowTitle">
<string>Walleth</string>
</property>
<property name="dockNestingEnabled">
<bool>true</bool>
</property>
<property name="dockOptions">
<set>QMainWindow::AllowNestedDocks|QMainWindow::AllowTabbedDocks|QMainWindow::VerticalTabs</set>
</property>
<property name="sizeGripEnabled" stdset="0">
<bool>true</bool>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="fullDisplay">
<item>
<widget class="QLabel" name="balance">
<property name="text">
<string>0 wei</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="peerCount">
<property name="text">
<string>0 peers</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="blockCount">
<property name="text">
<string>1 block</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>562</width>
<height>25</height>
</rect>
</property>
<widget class="QMenu" name="menu_File">
<property name="title">
<string>&amp;File</string>
</property>
<addaction name="quit"/>
</widget>
<widget class="QMenu" name="menu_Network">
<property name="title">
<string>&amp;Network</string>
</property>
<addaction name="upnp"/>
<addaction name="net"/>
<addaction name="connect"/>
</widget>
<widget class="QMenu" name="menu_Tools">
<property name="title">
<string>T&amp;ools</string>
</property>
<addaction name="mine"/>
<addaction name="create"/>
<addaction name="preview"/>
</widget>
<widget class="QMenu" name="menu_Help">
<property name="title">
<string>&amp;Help</string>
</property>
<addaction name="about"/>
</widget>
<addaction name="menu_File"/>
<addaction name="menu_Network"/>
<addaction name="menu_Tools"/>
<addaction name="menu_Help"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<action name="quit">
<property name="text">
<string>&amp;Quit</string>
</property>
</action>
<action name="upnp">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="text">
<string>Use &amp;UPnP</string>
</property>
</action>
<action name="connect">
<property name="text">
<string>&amp;Connect to Peer...</string>
</property>
</action>
<action name="net">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Enable &amp;Network</string>
</property>
</action>
<action name="mine">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>&amp;Mine</string>
</property>
</action>
<action name="create">
<property name="text">
<string>&amp;New Address</string>
</property>
</action>
<action name="about">
<property name="text">
<string>&amp;About...</string>
</property>
</action>
<action name="preview">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>&amp;Preview</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

59
iethxi/MainWin.cpp

@ -0,0 +1,59 @@
#include <QtNetwork/QNetworkReply>
#include <QtQuick/QQuickView>
#include <QtQml/QQmlContext>
#include <QtQml/QQmlEngine>
#include <QtQml/QtQml>
#include <QtWidgets/QMessageBox>
#include <QtWidgets/QInputDialog>
#include <QtGui/QClipboard>
#include <QtCore/QtCore>
#include <libethcore/FileSystem.h>
#include <libethcore/Dagger.h>
#include <libevmface/Instruction.h>
#include <libethereum/Client.h>
#include <libethereum/PeerServer.h>
#include "BuildInfo.h"
#include "MainWin.h"
#include "ui_Main.h"
using namespace std;
using namespace eth;
Main::Main(QWidget *parent) :
QObject(parent)
{
/* qRegisterMetaType<eth::u256>("eth::u256");
qRegisterMetaType<eth::KeyPair>("eth::KeyPair");
qRegisterMetaType<eth::Secret>("eth::Secret");
qRegisterMetaType<eth::Address>("eth::Address");
qRegisterMetaType<QmlAccount*>("QmlAccount*");
qRegisterMetaType<QmlEthereum*>("QmlEthereum*");
qmlRegisterType<QmlEthereum>("org.ethereum", 1, 0, "Ethereum");
qmlRegisterType<QmlAccount>("org.ethereum", 1, 0, "Account");
qmlRegisterSingletonType<QmlU256Helper>("org.ethereum", 1, 0, "Balance", QmlEthereum::constructU256Helper);
qmlRegisterSingletonType<QmlKeyHelper>("org.ethereum", 1, 0, "Key", QmlEthereum::constructKeyHelper);
*/
/*
ui->librariesView->setModel(m_libraryMan);
ui->graphsView->setModel(m_graphMan);
*/
// QQmlContext* context = m_view->rootContext();
// context->setContextProperty("u256", new U256Helper(this));
}
Main::~Main()
{
}
// extra bits needed to link on VS
#ifdef _MSC_VER
// include moc file, ofuscated to hide from automoc
#include\
"moc_MainWin.cpp"
#endif

18
iethxi/MainWin.h

@ -0,0 +1,18 @@
#ifndef MAIN_H
#define MAIN_H
#include <QtQml/QQmlApplicationEngine>
class Main: public QObject
{
Q_OBJECT
public:
explicit Main(QWidget *parent = 0);
~Main();
private:
QQmlApplicationEngine* m_view;
};
#endif // MAIN_H

5
iethxi/Resources.qrc

@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/">
<file>Simple.qml</file>
</qresource>
</RCC>

9
iethxi/main.cpp

@ -0,0 +1,9 @@
#include <QtQml/QQmlApplicationEngine>
#include <QtWidgets/QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QQmlApplicationEngine app(QUrl("qrc:/Simple.qml"));
return a.exec();
}

2
libethcore/Exceptions.h

@ -5,6 +5,8 @@
namespace eth namespace eth
{ {
class DatabaseAlreadyOpen: public Exception {};
class NotEnoughCash: public Exception {}; class NotEnoughCash: public Exception {};
class GasPriceTooLow: public Exception {}; class GasPriceTooLow: public Exception {};

10
libethereum/BlockChain.cpp

@ -119,10 +119,12 @@ BlockChain::BlockChain(std::string _path, bool _killExisting)
ldb::Options o; ldb::Options o;
o.create_if_missing = true; o.create_if_missing = true;
auto s = ldb::DB::Open(o, _path + "/blocks", &m_db); ldb::DB::Open(o, _path + "/blocks", &m_db);
assert(m_db); ldb::DB::Open(o, _path + "/details", &m_extrasDB);
s = ldb::DB::Open(o, _path + "/details", &m_extrasDB); if (!m_db)
assert(m_extrasDB); throw DatabaseAlreadyOpen();
if (!m_extrasDB)
throw DatabaseAlreadyOpen();
// Initialise with the genesis as the last block on the longest chain. // Initialise with the genesis as the last block on the longest chain.
m_genesisHash = BlockChain::genesis().hash; m_genesisHash = BlockChain::genesis().hash;

3
libethereum/State.cpp

@ -52,6 +52,9 @@ OverlayDB State::openDB(std::string _path, bool _killExisting)
o.create_if_missing = true; o.create_if_missing = true;
ldb::DB* db = nullptr; ldb::DB* db = nullptr;
ldb::DB::Open(o, _path + "/state", &db); ldb::DB::Open(o, _path + "/state", &db);
if (!db)
throw DatabaseAlreadyOpen();
cnote << "Opened state DB."; cnote << "Opened state DB.";
return OverlayDB(db); return OverlayDB(db);
} }

66
libethereumx/CMakeLists.txt

@ -0,0 +1,66 @@
cmake_policy(SET CMP0015 NEW)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSTATICLIB")
aux_source_directory(. SRC_LIST)
set(EXECUTABLE ethereumx)
# set(CMAKE_INSTALL_PREFIX ../lib)
if(ETH_STATIC)
add_library(${EXECUTABLE} STATIC ${SRC_LIST})
else()
add_library(${EXECUTABLE} SHARED ${SRC_LIST})
endif()
file(GLOB HEADERS "*.h")
include_directories(..)
target_link_libraries(${EXECUTABLE} evm)
target_link_libraries(${EXECUTABLE} lll)
target_link_libraries(${EXECUTABLE} ethcore)
target_link_libraries(${EXECUTABLE} secp256k1)
if(MINIUPNPC_LS)
target_link_libraries(${EXECUTABLE} ${MINIUPNPC_LS})
endif()
target_link_libraries(${EXECUTABLE} ${LEVELDB_LS})
target_link_libraries(${EXECUTABLE} ${CRYPTOPP_LS})
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)
target_link_libraries(${EXECUTABLE} ws2_32)
target_link_libraries(${EXECUTABLE} mswsock)
target_link_libraries(${EXECUTABLE} shlwapi)
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)
target_link_libraries(${EXECUTABLE} ${CMAKE_THREAD_LIBS_INIT})
endif ()
install( TARGETS ${EXECUTABLE} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib )
install( FILES ${HEADERS} DESTINATION include/${EXECUTABLE} )

125
libethereumx/Ethereum.cpp

@ -0,0 +1,125 @@
/*
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 Ethereum.cpp
* @author Gav Wood <i@gavwood.com>
* @date 2014
*/
#include "Ethereum.h"
#include <libethential/Log.h>
#include <libethereum/Client.h>
using namespace std;
using namespace eth;
Ethereum::Ethereum()
{
ensureReady();
}
void Ethereum::ensureReady()
{
while (!m_client && connectionOpen())
try
{
m_client = unique_ptr<Client>(new Client("+ethereum+"));
if (m_client)
startServer();
}
catch (DatabaseAlreadyOpen)
{
startClient();
}
}
Ethereum::~Ethereum()
{
}
bool Ethereum::connectionOpen() const
{
return false;
}
void Ethereum::startClient()
{
}
void Ethereum::startServer()
{
}
void Client::flushTransactions()
{
}
std::vector<PeerInfo> Client::peers()
{
return std::vector<PeerInfo>();
}
size_t Client::peerCount() const
{
return 0;
}
void Client::connect(std::string const& _seedHost, unsigned short _port)
{
}
void Client::transact(Secret _secret, u256 _value, Address _dest, bytes const& _data, u256 _gas, u256 _gasPrice)
{
}
bytes Client::call(Secret _secret, u256 _value, Address _dest, bytes const& _data, u256 _gas, u256 _gasPrice)
{
return bytes();
}
Address Client::transact(Secret _secret, u256 _endowment, bytes const& _init, u256 _gas, u256 _gasPrice)
{
return Address();
}
void Client::inject(bytesConstRef _rlp)
{
}
u256 Client::balanceAt(Address _a, int _block) const
{
return u256();
}
std::map<u256, u256> Client::storageAt(Address _a, int _block) const
{
return std::map<u256, u256>();
}
u256 Client::countAt(Address _a, int _block) const
{
return u256();
}
u256 Client::stateAt(Address _a, u256 _l, int _block) const
{
return u256();
}
bytes Client::codeAt(Address _a, int _block) const
{
return bytes();
}

144
libethereumx/Ethereum.h

@ -0,0 +1,144 @@
/*
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 Ethereum.h
* @author Gav Wood <i@gavwood.com>
* @date 2014
*/
#pragma once
#include <thread>
#include <mutex>
#include <list>
#include <atomic>
#include <boost/utility.hpp>
#include <libethential/Common.h>
#include <libethential/CommonIO.h>
#include <libevm/FeeStructure.h>
#include <libethcore/Dagger.h>
#include <libethereum/Guards.h>
#include <libethereum/PastMessage.h>
#include <libethereum/MessageFilter.h>
#include <libethereum/PeerNetwork.h>
namespace eth
{
class Client;
/**
* @brief Main API hub for interfacing with Ethereum.
* This class is automatically able to share a single machine-wide Client instance with other
* instances, cross-process.
*
* Other than that, it provides much the same subset of functionality as Client.
*/
class Ethereum
{
friend class Miner;
public:
/// Constructor. After this, everything should be set up to go.
Ethereum();
/// Destructor.
~Ethereum();
/// Submits the given message-call transaction.
void transact(Secret _secret, u256 _value, Address _dest, bytes const& _data = bytes(), u256 _gas = 10000, u256 _gasPrice = 10 * szabo);
/// Submits a new contract-creation transaction.
/// @returns the new contract's address (assuming it all goes through).
Address transact(Secret _secret, u256 _endowment, bytes const& _init, u256 _gas = 10000, u256 _gasPrice = 10 * szabo);
/// Injects the RLP-encoded transaction given by the _rlp into the transaction queue directly.
void inject(bytesConstRef _rlp);
/// Blocks until all pending transactions have been processed.
void flushTransactions();
/// Makes the given call. Nothing is recorded into the state.
bytes call(Secret _secret, u256 _value, Address _dest, bytes const& _data = bytes(), u256 _gas = 10000, u256 _gasPrice = 10 * szabo);
// Informational stuff
// [NEW API]
int getDefault() const { return m_default; }
void setDefault(int _block) { m_default = _block; }
u256 balanceAt(Address _a) const { return balanceAt(_a, m_default); }
u256 countAt(Address _a) const { return countAt(_a, m_default); }
u256 stateAt(Address _a, u256 _l) const { return stateAt(_a, _l, m_default); }
bytes codeAt(Address _a) const { return codeAt(_a, m_default); }
std::map<u256, u256> storageAt(Address _a) const { return storageAt(_a, m_default); }
u256 balanceAt(Address _a, int _block) const;
u256 countAt(Address _a, int _block) const;
u256 stateAt(Address _a, u256 _l, int _block) const;
bytes codeAt(Address _a, int _block) const;
std::map<u256, u256> storageAt(Address _a, int _block) const;
PastMessages messages(MessageFilter const& _filter) const;
// [EXTRA API]:
#if 0
/// Get a map containing each of the pending transactions.
/// @TODO: Remove in favour of transactions().
Transactions pending() const { return m_postMine.pending(); }
/// Differences between transactions.
StateDiff diff(unsigned _txi) const { return diff(_txi, m_default); }
StateDiff diff(unsigned _txi, h256 _block) const;
StateDiff diff(unsigned _txi, int _block) const;
/// Get a list of all active addresses.
std::vector<Address> addresses() const { return addresses(m_default); }
std::vector<Address> addresses(int _block) const;
/// Get the fee associated for a transaction with the given data.
static u256 txGas(uint _dataCount, u256 _gas = 0) { return c_txDataGas * _dataCount + c_txGas + _gas; }
/// Get the remaining gas limit in this block.
u256 gasLimitRemaining() const { return m_postMine.gasLimitRemaining(); }
#endif
// Network stuff:
/// Get information on the current peer set.
std::vector<PeerInfo> peers();
/// Same as peers().size(), but more efficient.
size_t peerCount() const;
/// Connect to a particular peer.
void connect(std::string const& _seedHost, unsigned short _port = 30303);
private:
/// Ensure that through either the client or the
void ensureReady();
/// Check to see if the client/server connection is open.
bool connectionOpen() const;
/// Start the API client.
void startClient();
/// Start the API server.
void startServer();
std::unique_ptr<Client> m_client;
int m_default = -1;
};
}
Loading…
Cancel
Save