Browse Source

Merge branch 'poc-2'

Conflicts:
	alethzero/CMakeLists.txt
cl-refactor
subtly 11 years ago
parent
commit
ae1e33f039
  1. 130
      CMakeLists.txt
  2. 34
      TODO
  3. 29
      alethzero/CMakeLists.txt
  4. 42
      alethzero/Main.ui
  5. 39
      alethzero/MainWin.cpp
  6. 1
      alethzero/MainWin.h
  7. 25
      eth/CMakeLists.txt
  8. 121
      eth/main.cpp
  9. 86
      libethereum/BlockChain.cpp
  10. 3
      libethereum/BlockChain.h
  11. 2
      libethereum/BlockInfo.cpp
  12. 26
      libethereum/CMakeLists.txt
  13. 2
      libethereum/Common.cpp
  14. 2
      libethereum/Common.h
  15. 2
      libethereum/Exceptions.h
  16. 108
      libethereum/PeerNetwork.cpp
  17. 12
      libethereum/PeerNetwork.h
  18. 4
      libethereum/RLP.cpp
  19. 6
      libethereum/State.cpp
  20. 2
      libethereum/Transaction.cpp
  21. 25
      test/CMakeLists.txt
  22. 24
      test/crypto.cpp
  23. 8
      test/main.cpp
  24. 4
      windows/qt_plugin_import.cpp

130
CMakeLists.txt

@ -5,9 +5,41 @@ set(CMAKE_AUTOMOC ON)
cmake_policy(SET CMP0015 NEW)
set(ETH_VERSION 0.1.2)
set(ETH_VERSION 0.2.3)
set(ETH_BUILD_TYPE ${CMAKE_BUILD_TYPE})
set(ETH_BUILD_PLATFORM ${CMAKE_SYSTEM_NAME})
set(TARGET_PLATFORM CACHE STRING "linux")
if ("x${TARGET_PLATFORM}" STREQUAL "x")
set(TARGET_PLATFORM "linux")
endif ()
if ("${TARGET_PLATFORM}" STREQUAL "w64")
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_CXX_LIBRARY_ARCHITECTURE x86_64-w64-mingw32)
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
set(CMAKE_AR x86_64-w64-mingw32-ar)
set(CMAKE_RANLIB x86_64-w64-mingw32-ranlib)
set(CMAKE_EXECUTABLE_SUFFIX .exe)
set(CMAKE_FIND_ROOT_PATH
/usr/x86_64-w64-mingw32
)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_INSTALL_PREFIX /usr/x86_64-w64-mingw32)
set(ETH_BUILD_PLATFORM "windows")
else ()
set(ETH_BUILD_PLATFORM ${CMAKE_SYSTEM_NAME})
endif()
if (CMAKE_COMPILER_IS_MINGW)
set(ETH_BUILD_PLATFORM "${ETH_BUILD_PLATFORM}/mingw")
elseif (CMAKE_COMPILER_IS_MSYS)
@ -19,6 +51,7 @@ elseif (CMAKE_COMPILER_IS_MSVC)
else ()
set(ETH_BUILD_PLATFORM "${ETH_BUILD_PLATFORM}/unknown")
endif ()
# Initialize CXXFLAGS.
set(CMAKE_CXX_FLAGS "-Wall -std=c++11")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
@ -44,55 +77,58 @@ else ()
message(FATAL_ERROR "Your C++ compiler does not support C++11.")
endif ()
# Look for available Crypto++ version and if it is >= 5.6.2
find_path(ID cryptlib.h
/usr/include/cryptopp
/usr/include/crypto++
/usr/local/include/cryptopp
/usr/local/include/crypto++
/opt/local/include/cryptopp
/opt/local/include/crypto++
)
find_library(LS NAMES cryptoppeth cryptopp
PATHS
/usr/lib
/usr/local/lib
/opt/local/lib
)
if (${TARGET_PLATFORM} STREQUAL "w64")
else ()
# Look for available Crypto++ version and if it is >= 5.6.2
find_path(ID cryptlib.h
/usr/include/cryptopp
/usr/include/crypto++
/usr/local/include/cryptopp
/usr/local/include/crypto++
/opt/local/include/cryptopp
/opt/local/include/crypto++
)
find_library(LS NAMES cryptoppeth cryptopp
PATHS
/usr/lib
/usr/local/lib
/opt/local/lib
)
if(ID AND LS)
message(STATUS "Found Crypto++: ${ID}, ${LS}")
set(_CRYPTOPP_VERSION_HEADER ${ID}/config.h)
if(EXISTS ${_CRYPTOPP_VERSION_HEADER})
file(STRINGS ${_CRYPTOPP_VERSION_HEADER} _CRYPTOPP_VERSION REGEX "^#define CRYPTOPP_VERSION[ \t]+[0-9]+$")
string(REGEX REPLACE "^#define CRYPTOPP_VERSION[ \t]+([0-9]+)" "\\1" _CRYPTOPP_VERSION ${_CRYPTOPP_VERSION})
if(${_CRYPTOPP_VERSION} LESS 562)
message(STATUS "System Crypto++ version found is smaller than 5.6.2.")
else()
set(CRYPTOPP_INCLUDE_DIR ${ID} CACHE FILEPATH "" FORCE)
set(CRYPTOPP_LIBRARIES ${LS} CACHE FILEPATH "" FORCE)
set(CRYPTOPP_FOUND TRUE)
message(STATUS "System Crypto++ found and version greater or equal to 5.6.2")
endif()
endif()
endif()
if(ID AND LS)
message(STATUS "Found Crypto++: ${ID}, ${LS}")
set(_CRYPTOPP_VERSION_HEADER ${ID}/config.h)
if(EXISTS ${_CRYPTOPP_VERSION_HEADER})
file(STRINGS ${_CRYPTOPP_VERSION_HEADER} _CRYPTOPP_VERSION REGEX "^#define CRYPTOPP_VERSION[ \t]+[0-9]+$")
string(REGEX REPLACE "^#define CRYPTOPP_VERSION[ \t]+([0-9]+)" "\\1" _CRYPTOPP_VERSION ${_CRYPTOPP_VERSION})
if(${_CRYPTOPP_VERSION} LESS 562)
message(STATUS "System Crypto++ version found is smaller than 5.6.2.")
else()
set(CRYPTOPP_INCLUDE_DIR ${ID} CACHE FILEPATH "" FORCE)
set(CRYPTOPP_LIBRARIES ${LS} CACHE FILEPATH "" FORCE)
set(CRYPTOPP_FOUND TRUE)
message(STATUS "System Crypto++ found and version greater or equal to 5.6.2")
endif()
endif()
endif()
if(NOT CRYPTOPP_FOUND)
set(CRYPTOPP_INCLUDE_DIR "../cryptopp562" CACHE FILEPATH "" FORCE)
find_library(LSLOC NAMES cryptoppeth cryptopp
PATHS ../cryptopp562
NO_DEFAULT_PATH
)
set(CRYPTOPP_LIBRARIES ${LSLOC} CACHE FILEPATH "" FORCE)
message(STATUS "System Crypto++ not found, broken or too old. We use ${LSLOC}")
endif()
if(NOT CRYPTOPP_FOUND)
set(CRYPTOPP_INCLUDE_DIR "../cryptopp562" CACHE FILEPATH "" FORCE)
find_library(LSLOC NAMES cryptoppeth cryptopp
PATHS ../cryptopp562
NO_DEFAULT_PATH
)
set(CRYPTOPP_LIBRARIES ${LSLOC} CACHE FILEPATH "" FORCE)
message(STATUS "System Crypto++ not found, broken or too old. We use ${LSLOC}")
endif()
# Not really worth caching. We want to reevaluate anyway.
mark_as_advanced(CRYPTOPP_INCLUDE_DIR CRYPTOPP_LIBRARIES)
# Not really worth caching. We want to reevaluate anyway.
mark_as_advanced(CRYPTOPP_INCLUDE_DIR CRYPTOPP_LIBRARIES)
# Always "found", given last block.
include_directories(${CRYPTOPP_INCLUDE_DIR})
link_directories(${CRYPTOPP_LIBRARIES})
# Always "found", given last block.
include_directories(${CRYPTOPP_INCLUDE_DIR})
link_directories(${CRYPTOPP_LIBRARIES})
endif ()
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
link_directories(/usr/local/lib)

34
TODO

@ -12,47 +12,39 @@ Better handling of corrupt blocks.
Network:
- Crypto on network. TLS?
- Make work with IPv6
- Consider node addresses
CLI client
- Implement CLI option "--help".
- UPnP should be disablable.
- Should also attempt random port usage.
General:
- Better logging.
- Colours.
- Time/thread/channel stamp.
- Move over to new system.
AlephZero:
- Allow units to be selected for transactions.
### GAV
### Gav
For PoC2:
Network:
- NotInChain will be very bad for new peers - it'll run through until the genesis.
- Check how many it has first.
BUG: need to discard transactions if nonce too old.
### Marko
Ubuntu builds
- Raring (branch, local, x64 only :-( )
- Quantal (branch) (Launchpad)
- Saucy (master) (Launchpad)
Server
- Get PoC-2 running on dev server ready for switchover on release.
- Or just run on release @30300?
Network:
- NotInChain will be very bad for new peers - it'll run through until the genesis.
- Check how many it has first.
UI:
- State panel shouldn't show pending (i.e. post-mined) transactions.
### Alex
Mac build
### ERIC
### Eric
Build:
- Windows build.
Windows build.
LATER:

29
alethzero/CMakeLists.txt

@ -1,5 +1,9 @@
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)
@ -17,6 +21,11 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
include_directories(/usr/local/opt/qt5/include /usr/local/include)
endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
if (${TARGET_PLATFORM} STREQUAL "w64")
set(SRC_LIST ${SRC_LIST} ../windows/qt_plugin_import.cpp)
else ()
endif ()
find_package(Qt5Widgets REQUIRED)
@ -80,3 +89,23 @@ else()
)
endif()
if (${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(alethzero gcc)
target_link_libraries(alethzero mingw32 qtmain mswsock iphlpapi qwindows shlwapi Qt5PlatformSupport gdi32 comdlg32 oleaut32 imm32 winmm ole32 uuid ws2_32)
target_link_libraries(alethzero boost_system-mt-s)
target_link_libraries(alethzero boost_filesystem-mt-s)
target_link_libraries(alethzero boost_thread_win32-mt-s)
target_link_libraries(alethzero Qt5PlatformSupport)
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS)
else ()
target_link_libraries(alethzero boost_system)
target_link_libraries(alethzero boost_filesystem)
find_package(Threads REQUIRED)
target_link_libraries(alethzero ${CMAKE_THREAD_LIBS_INIT})
endif ()
qt5_use_modules(alethzero Core Gui Widgets Network)
install( TARGETS alethzero RUNTIME DESTINATION bin )

42
alethzero/Main.ui

@ -81,7 +81,6 @@
<string>&amp;Network</string>
</property>
<addaction name="upnp"/>
<addaction name="net"/>
<addaction name="connect"/>
</widget>
<widget class="QMenu" name="menu_Tools">
@ -153,12 +152,18 @@
<enum>QFrame::NoFrame</enum>
</property>
</widget>
<widget class="QWidget" name="">
<widget class="QWidget" name="layoutWidget">
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Listen on</string>
<item row="1" column="1">
<widget class="QSpinBox" name="port">
<property name="minimum">
<number>1024</number>
</property>
<property name="maximum">
<number>32767</number>
</property>
<property name="value">
<number>30303</number>
</property>
</widget>
</item>
@ -179,19 +184,6 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="port">
<property name="minimum">
<number>1024</number>
</property>
<property name="maximum">
<number>32767</number>
</property>
<property name="value">
<number>30303</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
@ -199,6 +191,13 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Listen on</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="clientName">
<property name="placeholderText">
@ -298,6 +297,7 @@
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="net"/>
<addaction name="connect"/>
<addaction name="mine"/>
</widget>
@ -469,7 +469,7 @@
</action>
<action name="connect">
<property name="text">
<string>&amp;Connect</string>
<string>&amp;Connect to Peer...</string>
</property>
</action>
<action name="net">
@ -477,7 +477,7 @@
<bool>true</bool>
</property>
<property name="text">
<string>&amp;Listen</string>
<string>Enable &amp;Network</string>
</property>
</action>
<action name="mine">

39
alethzero/MainWin.cpp

@ -64,7 +64,7 @@ Main::~Main()
void Main::on_about_triggered()
{
QMessageBox::about(this, "About AlethZero PoC-2", "AlethZero/v" ADD_QUOTES(ETH_VERSION) "/" ADD_QUOTES(ETH_BUILD_TYPE) "/" ADD_QUOTES(ETH_BUILD_PLATFORM) "\nBy Gav Wood, 2014.\nBased on a design by Vitalik Buterin.\n\nTeam Ethereum++ includes: Eric Lombrozo, Marko Simovic, Subtly and several others.");
QMessageBox::about(this, "About AlethZero PoC-2", "AlethZero/v" ADD_QUOTES(ETH_VERSION) "/" ADD_QUOTES(ETH_BUILD_TYPE) "/" ADD_QUOTES(ETH_BUILD_PLATFORM) "\nBy Gav Wood, 2014.\nBased on a design by Vitalik Buterin.\n\nTeam Ethereum++ includes: Eric Lombrozo, Marko Simovic, Alex Leverington and several others.");
}
void Main::writeSettings()
@ -80,16 +80,28 @@ void Main::writeSettings()
}
s.setValue("address", b);
// TODO: save peers - implement it in PeerNetwork though returning RLP bytes
/*for (uint i = 0; !s.value(QString("peer%1").arg(i)).isNull(); ++i)
s.setValue("upnp", ui->upnp->isChecked());
s.setValue("clientName", ui->clientName->text());
s.setValue("idealPeers", ui->idealPeers->value());
s.setValue("port", ui->port->value());
if (m_client->peerServer())
{
s.value(QString("peer%1").arg(i)).toString();
}*/
bytes d = m_client->peerServer()->savePeers();
m_peers = QByteArray((char*)d.data(), d.size());
}
s.setValue("peers", m_peers);
s.setValue("geometry", saveGeometry());
}
void Main::readSettings()
{
QSettings s("ethereum", "alethzero");
restoreGeometry(s.value("geometry").toByteArray());
QByteArray b = s.value("address").toByteArray();
if (b.isEmpty())
m_myKeys.append(KeyPair::create());
@ -103,14 +115,11 @@ void Main::readSettings()
}
}
m_client->setAddress(m_myKeys.back().address());
writeSettings();
// TODO: restore peers - implement it in PeerNetwork though giving RLP bytes
/*for (uint i = 0; !s.value(QString("peer%1").arg(i)).isNull(); ++i)
{
s.value(QString("peer%1").arg(i)).toString();
}*/
m_peers = s.value("peers").toByteArray();
ui->upnp->setChecked(s.value("upnp", true).toBool());
ui->clientName->setText(s.value("clientName", "").toString());
ui->idealPeers->setValue(s.value("idealPeers", ui->idealPeers->value()).toInt());
ui->port->setValue(s.value("port", ui->port->value()).toInt());
}
void Main::refresh()
@ -247,7 +256,11 @@ void Main::on_net_triggered()
n += "/" ADD_QUOTES(ETH_BUILD_TYPE) "/" ADD_QUOTES(ETH_BUILD_PLATFORM);
m_client->setClientVersion(n);
if (ui->net->isChecked())
{
m_client->startNetwork(ui->port->value(), string(), 0, NodeMode::Full, ui->idealPeers->value(), std::string(), ui->upnp->isChecked());
if (m_peers.size())
m_client->peerServer()->restorePeers(bytesConstRef((byte*)m_peers.data(), m_peers.size()));
}
else
m_client->stopNetwork();
}

1
alethzero/MainWin.h

@ -56,6 +56,7 @@ private:
eth::Client* m_client;
QByteArray m_peers;
QMutex m_guiLock;
QTimer* m_refresh;
QStringList m_servers;

25
eth/CMakeLists.txt

@ -7,7 +7,26 @@ link_directories(../libethereum)
add_executable(eth ${SRC_LIST})
find_package(Threads REQUIRED)
if (${TARGET_PLATFORM} STREQUAL "w64")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++")
target_link_libraries(eth gcc)
target_link_libraries(eth gdi32)
target_link_libraries(eth ws2_32)
target_link_libraries(eth mswsock)
target_link_libraries(eth shlwapi)
target_link_libraries(eth iphlpapi)
target_link_libraries(eth cryptopp)
target_link_libraries(eth boost_system-mt-s)
target_link_libraries(eth boost_filesystem-mt-s)
target_link_libraries(eth boost_thread_win32-mt-s)
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS)
else ()
target_link_libraries(eth ${CRYPTOPP_LIBRARIES})
target_link_libraries(eth boost_system)
target_link_libraries(eth boost_filesystem)
find_package(Threads REQUIRED)
target_link_libraries(eth ${CMAKE_THREAD_LIBS_INIT})
endif ()
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
include_directories(/usr/local/include)
@ -16,11 +35,7 @@ endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
target_link_libraries(eth ethereum)
target_link_libraries(eth miniupnpc)
target_link_libraries(eth leveldb)
target_link_libraries(eth ${CRYPTOPP_LIBRARIES})
target_link_libraries(eth gmp)
target_link_libraries(eth boost_system)
target_link_libraries(eth boost_filesystem)
target_link_libraries(eth ${CMAKE_THREAD_LIBS_INIT})
install( TARGETS eth DESTINATION bin )

121
eth/main.cpp

@ -65,6 +65,94 @@ bool isFalse(std::string const& _m)
return _m == "off" || _m == "no" || _m == "false" || _m == "0";
}
void help()
{
cout
<< "Usage eth [OPTIONS] <remote-host>" << endl
<< "Options:" << endl
<< " -l,--listen <port> Listen on the given port for incoming connected (default: 30303)." << endl
<< " -l,--listen <port> Listen on the given port for incoming connected (default: 30303)." << endl
<< " -l,--listen <port> Listen on the given port for incoming connected (default: 30303)." << endl
;
/*
if ((arg == "-l" || arg == "--listen" || arg == "--listen-port") && i + 1 < argc)
listenPort = atoi(argv[++i]);
else if ((arg == "-u" || arg == "--public-ip" || arg == "--public") && i + 1 < argc)
publicIP = argv[++i];
else if ((arg == "-r" || arg == "--remote") && i + 1 < argc)
remoteHost = argv[++i];
else if ((arg == "-p" || arg == "--port") && i + 1 < argc)
remotePort = atoi(argv[++i]);
else if ((arg == "-n" || arg == "--upnp") && i + 1 < argc)
{
string m = argv[++i];
if (isTrue(m))
upnp = true;
else if (isFalse(m))
upnp = false;
else
{
cerr << "Invalid UPnP option: " << m << endl;
return -1;
}
}
else if ((arg == "-c" || arg == "--client-name") && i + 1 < argc)
clientName = argv[++i];
else if ((arg == "-a" || arg == "--address" || arg == "--coinbase-address") && i + 1 < argc)
coinbase = h160(fromUserHex(argv[++i]));
else if ((arg == "-s" || arg == "--secret") && i + 1 < argc)
us = KeyPair(h256(fromUserHex(argv[++i])));
else if (arg == "-i" || arg == "--interactive")
interactive = true;
else if ((arg == "-d" || arg == "--path" || arg == "--db-path") && i + 1 < argc)
dbPath = argv[++i];
else if ((arg == "-m" || arg == "--mining") && i + 1 < argc)
{
string m = argv[++i];
if (isTrue(m))
mining = ~(eth::uint)0;
else if (isFalse(m))
mining = 0;
else if (int i = stoi(m))
mining = i;
else
{
cerr << "Unknown mining option: " << m << endl;
return -1;
}
}
else if ((arg == "-v" || arg == "--verbosity") && i + 1 < argc)
g_logVerbosity = atoi(argv[++i]);
else if ((arg == "-x" || arg == "--peers") && i + 1 < argc)
peers = atoi(argv[++i]);
else if ((arg == "-o" || arg == "--mode") && i + 1 < argc)
{
string m = argv[++i];
if (m == "full")
mode = NodeMode::Full;
else if (m == "peer")
mode = NodeMode::PeerServer;
else
{
cerr << "Unknown mode: " << m << endl;
return -1;
}
}
else if (arg == "-h" || arg == "--help")
help();
else if (arg == "-V" || arg == "--version")
version();
*/
exit(0);
}
void version()
{
cout << "eth version " << ADD_QUOTES(ETH_VERSION) << endl;
cout << "Build: " << ADD_QUOTES(ETH_BUILD_PLATFORM) << "/" << ADD_QUOTES(ETH_BUILD_TYPE) << endl;
exit(0);
}
int main(int argc, char** argv)
{
short listenPort = 30303;
@ -77,6 +165,7 @@ int main(int argc, char** argv)
unsigned peers = 5;
string publicIP;
bool upnp = true;
string clientName;
// Init defaults
Defaults::get();
@ -124,6 +213,8 @@ int main(int argc, char** argv)
return -1;
}
}
else if ((arg == "-c" || arg == "--client-name") && i + 1 < argc)
clientName = argv[++i];
else if ((arg == "-a" || arg == "--address" || arg == "--coinbase-address") && i + 1 < argc)
coinbase = h160(fromUserHex(argv[++i]));
else if ((arg == "-s" || arg == "--secret") && i + 1 < argc)
@ -164,11 +255,18 @@ int main(int argc, char** argv)
return -1;
}
}
else if (arg == "-h" || arg == "--help")
help();
else if (arg == "-V" || arg == "--version")
version();
else
remoteHost = argv[i];
}
Client c("Ethereum(++)/v" ADD_QUOTES(ETH_VERSION) "/" ADD_QUOTES(ETH_BUILD_TYPE) "/" ADD_QUOTES(ETH_BUILD_PLATFORM), coinbase, dbPath);
if (!clientName.empty())
clientName += "/";
Client c("Ethereum(++)/" + clientName + "v" ADD_QUOTES(ETH_VERSION) "/" ADD_QUOTES(ETH_BUILD_TYPE) "/" ADD_QUOTES(ETH_BUILD_PLATFORM), coinbase, dbPath);
if (interactive)
{
cout << "Ethereum (++)" << endl;
@ -205,6 +303,26 @@ int main(int argc, char** argv)
{
c.stopMining();
}
else if (cmd == "address")
{
cout << endl;
cout << "Current address: " + asHex(us.address().asArray()) << endl;
cout << "===" << endl;
}
else if (cmd == "secret")
{
cout << endl;
cout << "Current secret: " + asHex(us.secret().asArray()) << endl;
cout << "===" << endl;
}
else if (cmd == "balance")
{
u256 balance = c.state().balance(us.address());
cout << endl;
cout << "Current balance: ";
cout << balance << endl;
cout << "===" << endl;
}
else if (cmd == "transact")
{
string sechex;
@ -231,6 +349,7 @@ int main(int argc, char** argv)
}
else
{
cout << "Address: " << endl << asHex(us.address().asArray()) << endl;
c.startNetwork(listenPort, remoteHost, remotePort, mode, peers, publicIP, upnp);
eth::uint n = c.blockChain().details().number;
while (true)

86
libethereum/BlockChain.cpp

@ -120,16 +120,22 @@ void BlockChain::import(bytes const& _block, Overlay const& _db)
{
// VERIFY: populates from the block and checks the block is internally coherent.
BlockInfo bi(&_block);
bi.verifyInternals(&_block);
try
{
bi.verifyInternals(&_block);
}
catch (Exception const& _e)
{
clog(BlockChainNote) << " Malformed block (" << _e.description() << ").";
throw;
}
auto newHash = eth::sha3(_block);
clog(BlockChainChat) << "Attempting import of " << newHash << "...";
// Check block doesn't already exist first!
if (details(newHash))
{
clog(BlockChainChat) << " Not new.";
clog(BlockChainChat) << newHash << ": Not new.";
throw AlreadyHaveBlock();
}
@ -137,47 +143,61 @@ void BlockChain::import(bytes const& _block, Overlay const& _db)
auto pd = details(bi.parentHash);
if (!pd)
{
clog(BlockChainNote) << " Unknown parent " << bi.parentHash;
clog(BlockChainChat) << newHash << ": Unknown parent " << bi.parentHash;
// We don't know the parent (yet) - discard for now. It'll get resent to us if we find out about its ancestry later on.
throw UnknownParent();
}
// Check family:
BlockInfo biParent(block(bi.parentHash));
bi.verifyParent(biParent);
// Check transactions are valid and that they result in a state equivalent to our state_root.
State s(bi.coinbaseAddress, _db);
s.sync(*this, bi.parentHash);
// Get total difficulty increase and update state, checking it.
BlockInfo biGrandParent;
if (pd.number)
biGrandParent.populate(block(pd.parent));
auto tdIncrease = s.playback(&_block, bi, biParent, biGrandParent, true);
u256 td = pd.totalDifficulty + tdIncrease;
checkConsistency();
clog(BlockChainNote) << "Attempting import of " << newHash << "...";
// All ok - insert into DB
m_details[newHash] = BlockDetails((uint)pd.number + 1, td, bi.parentHash, {});
m_detailsDB->Put(m_writeOptions, ldb::Slice((char const*)&newHash, 32), (ldb::Slice)eth::ref(m_details[newHash].rlp()));
m_details[bi.parentHash].children.push_back(newHash);
m_detailsDB->Put(m_writeOptions, ldb::Slice((char const*)&bi.parentHash, 32), (ldb::Slice)eth::ref(m_details[bi.parentHash].rlp()));
m_db->Put(m_writeOptions, ldb::Slice((char const*)&newHash, 32), (ldb::Slice)ref(_block));
checkConsistency();
u256 td;
try
{
// Check family:
BlockInfo biParent(block(bi.parentHash));
bi.verifyParent(biParent);
// Check transactions are valid and that they result in a state equivalent to our state_root.
State s(bi.coinbaseAddress, _db);
s.sync(*this, bi.parentHash);
// Get total difficulty increase and update state, checking it.
BlockInfo biGrandParent;
if (pd.number)
biGrandParent.populate(block(pd.parent));
auto tdIncrease = s.playback(&_block, bi, biParent, biGrandParent, true);
td = pd.totalDifficulty + tdIncrease;
#if !NDEBUG
checkConsistency();
#endif
// All ok - insert into DB
m_details[newHash] = BlockDetails((uint)pd.number + 1, td, bi.parentHash, {});
m_detailsDB->Put(m_writeOptions, ldb::Slice((char const*)&newHash, 32), (ldb::Slice)eth::ref(m_details[newHash].rlp()));
m_details[bi.parentHash].children.push_back(newHash);
m_detailsDB->Put(m_writeOptions, ldb::Slice((char const*)&bi.parentHash, 32), (ldb::Slice)eth::ref(m_details[bi.parentHash].rlp()));
m_db->Put(m_writeOptions, ldb::Slice((char const*)&newHash, 32), (ldb::Slice)ref(_block));
#if !NDEBUG
checkConsistency();
#endif
}
catch (...)
{
clog(BlockChainNote) << " Malformed block.";
throw;
}
// cnote << "Parent " << bi.parentHash << " has " << details(bi.parentHash).children.size() << " children." << endl;
// cnote << "Parent " << bi.parentHash << " has " << details(bi.parentHash).children.size() << " children.";
// This might be the new last block...
if (td > m_details[m_lastBlockHash].totalDifficulty)
{
m_lastBlockHash = newHash;
m_detailsDB->Put(m_writeOptions, ldb::Slice("best"), ldb::Slice((char const*)&newHash, 32));
clog(BlockChainNote) << " Imported and best.";
clog(BlockChainNote) << " Imported and best. Has" << details(bi.parentHash).children.size() << "siblings.";
}
else
{

3
libethereum/BlockChain.h

@ -56,8 +56,7 @@ class AlreadyHaveBlock: public std::exception {};
class UnknownParent: public std::exception {};
struct BlockChainChat: public LogChannel { static const char constexpr* name = "-B-"; static const int verbosity = 7; };
struct BlockChainNote: public LogChannel { static const char constexpr* name = "=B="; static const int verbosity = 1; };
struct BlockChainWarn: public LogChannel { static const char constexpr* name = "!B!"; static const int verbosity = 0; };
struct BlockChainNote: public LogChannel { static const char constexpr* name = "=B="; static const int verbosity = 4; };
/**
* @brief Implements the blockchain database. All data this gives is disk-backed.

2
libethereum/BlockInfo.cpp

@ -131,7 +131,7 @@ void BlockInfo::verifyInternals(bytesConstRef _block) const
RLP root(_block);
if (sha3Transactions != sha3(root[1].data()))
throw InvalidTransactionsHash();
throw InvalidTransactionsHash(sha3Transactions, sha3(root[1].data()));
if (sha3Uncles != sha3(root[2].data()))
throw InvalidUnclesHash();

26
libethereum/CMakeLists.txt

@ -1,5 +1,7 @@
cmake_policy(SET CMP0015 NEW)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSTATICLIB")
aux_source_directory(. SRC_LIST)
if(NOT APPLE)
@ -10,18 +12,30 @@ endif()
file(GLOB HEADERS "*.h")
find_package(Threads REQUIRED)
include_directories(../secp256k1)
target_link_libraries(ethereum secp256k1)
target_link_libraries(ethereum miniupnpc)
target_link_libraries(ethereum leveldb)
target_link_libraries(ethereum ${CRYPTOPP_LIBRARIES})
target_link_libraries(ethereum gmp)
target_link_libraries(ethereum boost_system)
target_link_libraries(ethereum boost_filesystem)
target_link_libraries(ethereum ${CMAKE_THREAD_LIBS_INIT})
if(${TARGET_PLATFORM} STREQUAL "w64")
include_directories(/usr/x86_64-w64-mingw32/include/cryptopp)
target_link_libraries(ethereum cryptopp)
target_link_libraries(ethereum boost_system-mt-s)
target_link_libraries(ethereum boost_filesystem-mt-s)
target_link_libraries(ethereum boost_thread_win32-mt-s)
target_link_libraries(ethereum iphlpapi)
target_link_libraries(ethereum ws2_32)
target_link_libraries(ethereum mswsock)
target_link_libraries(ethereum shlwapi)
else ()
target_link_libraries(ethereum ${CRYPTOPP_LIBRARIES})
target_link_libraries(ethereum boost_system)
target_link_libraries(ethereum boost_filesystem)
find_package(Threads REQUIRED)
target_link_libraries(ethereum ${CMAKE_THREAD_LIBS_INIT})
endif ()
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
include_directories(/usr/local/include)

2
libethereum/Common.cpp

@ -38,6 +38,8 @@
using namespace std;
using namespace eth;
#define ETH_ADDRESS_DEBUG 1
// Logging
int eth::g_logVerbosity = 8;
map<type_info const*, bool> eth::g_logOverride;

2
libethereum/Common.h

@ -366,7 +366,7 @@ uint commonPrefix(_T const& _t, _U const& _u)
inline h160 right160(h256 const& _t)
{
h160 ret;
memcpy(ret.data(), _t.data() + 10, 20);
memcpy(ret.data(), _t.data() + 12, 20);
return ret;
}

2
libethereum/Exceptions.h

@ -29,7 +29,7 @@ class InvalidBlockHeaderFormat: public Exception { public: InvalidBlockHeaderFor
class InvalidUnclesHash: public Exception {};
class InvalidUncle: public Exception {};
class InvalidStateRoot: public Exception {};
class InvalidTransactionsHash: public Exception {};
class InvalidTransactionsHash: public Exception { public: InvalidTransactionsHash(h256 _head, h256 _real): m_head(_head), m_real(_real) {} h256 m_head; h256 m_real; virtual std::string description() const { return "Invalid transactions hash: header says: " + asHex(m_head.ref()) + " block is:" + asHex(m_real.ref()); } };
class InvalidTransaction: public Exception {};
class InvalidDifficulty: public Exception {};
class InvalidTimestamp: public Exception {};

108
libethereum/PeerNetwork.cpp

@ -43,7 +43,7 @@ using namespace eth;
#define clogS(X) eth::LogOutputStream<X, true>(false) << "| " << std::setw(2) << m_socket.native_handle() << "] "
static const int c_protocolVersion = 3;
static const int c_protocolVersion = 4;
static const eth::uint c_maxHashes = 256; ///< Maximum number of hashes GetChain will ever send.
static const eth::uint c_maxBlocks = 128; ///< Maximum number of blocks Blocks will ever send. BUG: if this gets too big (e.g. 2048) stuff starts going wrong.
@ -60,14 +60,36 @@ static const vector<bi::address> c_rejectAddresses = {
{bi::address_v6::from_string("::")}
};
PeerSession::PeerSession(PeerServer* _s, bi::tcp::socket _socket, uint _rNId):
// Helper function to determine if an address falls within one of the reserved ranges
// For V4:
// Class A "10.*", Class B "172.[16->31].*", Class C "192.168.*"
// Not implemented yet for V6
bool eth::isPrivateAddress(bi::address _addressToCheck)
{
if (_addressToCheck.is_v4())
{
bi::address_v4 v4Address = _addressToCheck.to_v4();
bi::address_v4::bytes_type bytesToCheck = v4Address.to_bytes();
if (bytesToCheck[0] == 10)
return true;
if (bytesToCheck[0] == 172 && (bytesToCheck[1] >= 16 && bytesToCheck[1] <=31))
return true;
if (bytesToCheck[0] == 192 && bytesToCheck[1] == 168)
return true;
}
return false;
}
PeerSession::PeerSession(PeerServer* _s, bi::tcp::socket _socket, uint _rNId, bi::address _peerAddress, short _peerPort):
m_server(_s),
m_socket(std::move(_socket)),
m_reqNetworkId(_rNId),
m_listenPort(_peerPort),
m_rating(0)
{
m_disconnect = std::chrono::steady_clock::time_point::max();
m_connect = std::chrono::steady_clock::now();
m_info = PeerInfo({"?", _peerAddress.to_string(), m_listenPort, std::chrono::steady_clock::duration(0)});
}
PeerSession::~PeerSession()
@ -116,7 +138,7 @@ bool PeerSession::interpret(RLP const& _r)
return false;
}
try
{ m_info = PeerInfo({clientVersion, m_socket.remote_endpoint().address().to_string(), (short)m_socket.remote_endpoint().port(), std::chrono::steady_clock::duration()}); }
{ m_info = PeerInfo({clientVersion, m_socket.remote_endpoint().address().to_string(), m_listenPort, std::chrono::steady_clock::duration()}); }
catch (...)
{
disconnect(BadProtocol);
@ -144,13 +166,13 @@ bool PeerSession::interpret(RLP const& _r)
case DisconnectPacket:
{
string reason = "Unspecified";
if (_r.itemCount() > 1 && _r[1].isInt())
if (_r[1].isInt())
switch (_r[1].toInt<int>())
{
case DisconnectRequested: reason = "Disconnect was requested."; break;
case TCPError: reason = "Low-level TCP communication error."; break;
case BadProtocol: reason = "Data format error."; break;
case UselessPeer: reason = "We had no use to peer."; break;
case UselessPeer: reason = "Peer had no use for this node."; break;
case TooManyPeers: reason = "Peer had too many connections."; break;
case DuplicatePeer: reason = "Peer was already connected."; break;
case WrongGenesis: reason = "Disagreement over genesis block."; break;
@ -196,10 +218,11 @@ bool PeerSession::interpret(RLP const& _r)
clogS(NetMessageSummary) << "Peers (" << dec << (_r.itemCount() - 1) << " entries)";
for (unsigned i = 1; i < _r.itemCount(); ++i)
{
auto ep = bi::tcp::endpoint(bi::address_v4(_r[i][0].toArray<byte, 4>()), _r[i][1].toInt<short>());
Public id;
if (_r[i].itemCount() > 2)
id = _r[i][2].toHash<Public>();
bi::address_v4 peerAddress(_r[i][0].toArray<byte, 4>());
auto ep = bi::tcp::endpoint(peerAddress, _r[i][1].toInt<short>());
Public id = _r[i][2].toHash<Public>();
if (isPrivateAddress(peerAddress))
goto CONTINUE;
clogS(NetAllDetail) << "Checking: " << ep << "(" << asHex(id.ref().cropped(0, 4)) << ")";
@ -223,8 +246,8 @@ bool PeerSession::interpret(RLP const& _r)
for (auto i: m_server->m_incomingPeers)
if (i.second == ep)
goto CONTINUE;
m_server->m_incomingPeers.insert(make_pair(id, ep));
clogS(NetMessageDetail) << "New peer: " << ep;
m_server->m_incomingPeers[id] = ep;
clogS(NetMessageDetail) << "New peer: " << ep << "(" << id << ")";
CONTINUE:;
}
break;
@ -240,15 +263,22 @@ bool PeerSession::interpret(RLP const& _r)
}
break;
case BlocksPacket:
{
if (m_server->m_mode == NodeMode::PeerServer)
break;
clogS(NetMessageSummary) << "Blocks (" << dec << (_r.itemCount() - 1) << " entries)";
m_rating += _r.itemCount() - 1;
unsigned used = 0;
for (unsigned i = 1; i < _r.itemCount(); ++i)
{
m_server->m_incomingBlocks.push_back(_r[i].data().toBytes());
m_knownBlocks.insert(sha3(_r[i].data()));
auto h = sha3(_r[i].data());
if (!m_server->m_chain->details(h))
{
m_server->m_incomingBlocks.push_back(_r[i].data().toBytes());
m_knownBlocks.insert(h);
used++;
}
}
m_rating += used;
if (g_logVerbosity >= 3)
for (unsigned i = 1; i < _r.itemCount(); ++i)
{
@ -259,7 +289,7 @@ bool PeerSession::interpret(RLP const& _r)
else
clogS(NetMessageDetail) << "Known parent " << bi.parentHash << " of block " << h;
}
if (_r.itemCount() > 1) // we received some - check if there's any more
if (used) // we received some - check if there's any more
{
RLPStream s;
prep(s).appendList(3);
@ -269,17 +299,18 @@ bool PeerSession::interpret(RLP const& _r)
sealAndSend(s);
}
break;
}
case GetChainPacket:
{
if (m_server->m_mode == NodeMode::PeerServer)
break;
clogS(NetMessageSummary) << "GetChain (" << (_r.itemCount() - 2) << " hashes, " << (_r[_r.itemCount() - 1].toInt<bigint>()) << ")";
// ********************************************************************
// NEEDS FULL REWRITE!
h256s parents;
parents.reserve(_r.itemCount() - 2);
for (unsigned i = 1; i < _r.itemCount() - 1; ++i)
parents.push_back(_r[i].toHash<h256>());
clogS(NetMessageSummary) << "GetChain (" << (_r.itemCount() - 2) << " hashes, " << (_r[_r.itemCount() - 1].toInt<bigint>()) << ")";
if (_r.itemCount() == 2)
break;
// return 2048 block max.
@ -444,8 +475,8 @@ void PeerSession::dropped()
if (m_socket.is_open())
try {
clogS(NetNote) << "Closing " << m_socket.remote_endpoint();
m_socket.close();
}catch (...){}
m_socket.close();
for (auto i = m_server->m_peers.begin(); i != m_server->m_peers.end(); ++i)
if (i->second.lock().get() == this)
{
@ -701,7 +732,9 @@ std::map<Public, bi::tcp::endpoint> PeerServer::potentialPeers()
if (auto j = i.second.lock())
{
auto ep = j->endpoint();
if (ep.port() && j->m_id)
// Skip peers with a listen port of zero or are on a private network
bool peerOnNet = (j->m_listenPort != 0 && !isPrivateAddress(ep.address()));
if (peerOnNet && ep.port() && j->m_id)
ret.insert(make_pair(i.first, ep));
}
return ret;
@ -721,7 +754,9 @@ void PeerServer::ensureAccepting()
try {
clog(NetNote) << "Accepted connection from " << m_socket.remote_endpoint();
} catch (...){}
auto p = std::make_shared<PeerSession>(this, std::move(m_socket), m_requiredNetworkId);
bi::address remoteAddress = m_socket.remote_endpoint().address();
// Port defaults to 0 - we let the hello tell us which port the peer listens to
auto p = std::make_shared<PeerSession>(this, std::move(m_socket), m_requiredNetworkId, remoteAddress);
p->start();
}
catch (std::exception const& _e)
@ -748,7 +783,7 @@ void PeerServer::connect(bi::tcp::endpoint const& _ep)
}
else
{
auto p = make_shared<PeerSession>(this, std::move(*s), m_requiredNetworkId);
auto p = make_shared<PeerSession>(this, std::move(*s), m_requiredNetworkId, _ep.address(), _ep.port());
clog(NetNote) << "Connected to " << p->endpoint();
p->start();
}
@ -863,9 +898,10 @@ bool PeerServer::process(BlockChain& _bc, TransactionQueue& _tq, Overlay& _o)
}
m_latestBlockSent = h;
for (int accepted = 1; accepted;)
for (int accepted = 1, n = 0; accepted; ++n)
{
accepted = 0;
if (m_incomingBlocks.size())
for (auto it = prev(m_incomingBlocks.end());; --it)
{
@ -879,6 +915,8 @@ bool PeerServer::process(BlockChain& _bc, TransactionQueue& _tq, Overlay& _o)
catch (UnknownParent)
{
// Don't (yet) know its parent. Leave it for later.
m_unknownParentBlocks.push_back(*it);
it = m_incomingBlocks.erase(it);
}
catch (...)
{
@ -889,6 +927,12 @@ bool PeerServer::process(BlockChain& _bc, TransactionQueue& _tq, Overlay& _o)
if (it == m_incomingBlocks.begin())
break;
}
if (!n && accepted)
{
for (auto i: m_unknownParentBlocks)
m_incomingBlocks.push_back(i);
m_unknownParentBlocks.clear();
}
}
// Connect to additional peers
@ -970,3 +1014,25 @@ void PeerServer::pingAll()
if (auto j = i.second.lock())
j->ping();
}
bytes PeerServer::savePeers() const
{
RLPStream ret;
int n = 0;
for (auto& i: m_peers)
if (auto p = i.second.lock())
if (p->m_socket.is_open() && p->endpoint().port())
{
ret.appendList(3) << p->endpoint().address().to_v4().to_bytes() << p->endpoint().port() << p->m_id;
n++;
}
return RLPStream(n).appendRaw(ret.out(), n).out();
}
void PeerServer::restorePeers(bytesConstRef _b)
{
for (auto i: RLP(_b))
{
m_incomingPeers.insert(make_pair((Public)i[2], bi::tcp::endpoint(bi::address_v4(i[0].toArray<byte, 4>()), i[1].toInt<short>())));
}
}

12
libethereum/PeerNetwork.h

@ -35,6 +35,8 @@ namespace bi = boost::asio::ip;
namespace eth
{
bool isPrivateAddress(bi::address _addressToCheck);
class BlockChain;
class TransactionQueue;
@ -89,7 +91,7 @@ class PeerSession: public std::enable_shared_from_this<PeerSession>
friend class PeerServer;
public:
PeerSession(PeerServer* _server, bi::tcp::socket _socket, uint _rNId);
PeerSession(PeerServer* _server, bi::tcp::socket _socket, uint _rNId, bi::address _peerAddress, short _peerPort = 0);
~PeerSession();
void start();
@ -111,8 +113,8 @@ private:
void sealAndSend(RLPStream& _s);
void sendDestroy(bytes& _msg);
void send(bytesConstRef _msg);
PeerServer* m_server;
bi::tcp::socket m_socket;
std::array<byte, 65536> m_data;
PeerInfo m_info;
@ -182,6 +184,9 @@ public:
/// Get the port we're listening on currently.
short listenPort() const { return m_public.port(); }
bytes savePeers() const;
void restorePeers(bytesConstRef _b);
private:
void seal(bytes& _b);
void populateAddresses();
@ -208,7 +213,8 @@ private:
std::vector<bytes> m_incomingTransactions;
std::vector<bytes> m_incomingBlocks;
std::multimap<Public, bi::tcp::endpoint> m_incomingPeers;
std::vector<bytes> m_unknownParentBlocks;
std::map<Public, bi::tcp::endpoint> m_incomingPeers;
h256 m_latestBlockSent;
std::set<h256> m_transactionsSent;

4
libethereum/RLP.cpp

@ -94,6 +94,8 @@ eth::uint RLP::actualSize() const
bool RLP::isInt() const
{
if (isNull())
return false;
byte n = m_data[0];
if (n < c_rlpDataImmLenStart)
return !!n;
@ -110,6 +112,8 @@ bool RLP::isInt() const
eth::uint RLP::length() const
{
if (isNull())
return 0;
uint ret = 0;
byte n = m_data[0];
if (n < c_rlpDataImmLenStart)

6
libethereum/State.cpp

@ -62,7 +62,7 @@ std::map<Address, AddressState> const& eth::genesisState()
if (s_ret.empty())
{
// Initialise.
s_ret[Address(fromUserHex("07598a40bfaa73256b60764c1bf40675a99083ef"))] = AddressState(u256(1) << 200, 0);
s_ret[Address(fromUserHex("8a40bfaa73256b60764c1bf40675a99083efb075"))] = AddressState(u256(1) << 200, 0);
s_ret[Address(fromUserHex("93658b04240e4bd4046fd2d6d417d20f146f4b43"))] = AddressState(u256(1) << 200, 0);
s_ret[Address(fromUserHex("1e12515ce3e0f817a4ddef9ca55788a1d66bd2df"))] = AddressState(u256(1) << 200, 0);
s_ret[Address(fromUserHex("80c01a26338f0d905e295fccb71fa9ea849ffa12"))] = AddressState(u256(1) << 200, 0);
@ -98,10 +98,10 @@ State::State(Address _coinbaseAddress, Overlay const& _db):
// Initialise to the state entailed by the genesis block; this guarantees the trie is built correctly.
m_state.init();
eth::commit(genesisState(), m_db, m_state);
cnote << "State root: " << m_state.root();
// cnote << "State root: " << m_state.root();
m_previousBlock = BlockInfo::genesis();
cnote << "Genesis hash:" << m_previousBlock.hash;
// cnote << "Genesis hash:" << m_previousBlock.hash;
resetCurrent();
assert(m_state.root() == m_previousBlock.stateRoot);

2
libethereum/Transaction.cpp

@ -26,6 +26,8 @@
using namespace std;
using namespace eth;
#define ETH_ADDRESS_DEBUG 0
Transaction::Transaction(bytesConstRef _rlpData)
{
RLP rlp(_rlpData);

25
test/CMakeLists.txt

@ -8,7 +8,26 @@ link_directories(../libethereum)
add_executable(testeth ${SRC_LIST})
find_package(Threads REQUIRED)
if (${TARGET_PLATFORM} STREQUAL "w64")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++")
target_link_libraries(testeth gcc)
target_link_libraries(testeth gdi32)
target_link_libraries(testeth ws2_32)
target_link_libraries(testeth mswsock)
target_link_libraries(testeth shlwapi)
target_link_libraries(testeth iphlpapi)
target_link_libraries(testeth cryptopp)
target_link_libraries(testeth boost_system-mt-s)
target_link_libraries(testeth boost_filesystem-mt-s)
target_link_libraries(testeth boost_thread_win32-mt-s)
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS)
else ()
target_link_libraries(testeth ${CRYPTOPP_LIBRARIES})
target_link_libraries(testeth boost_system)
target_link_libraries(testeth boost_filesystem)
find_package(Threads REQUIRED)
target_link_libraries(testeth ${CMAKE_THREAD_LIBS_INIT})
endif ()
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
include_directories(/usr/local/include)
@ -17,8 +36,4 @@ endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
target_link_libraries(testeth ethereum)
target_link_libraries(testeth secp256k1)
target_link_libraries(testeth miniupnpc)
target_link_libraries(testeth ${CRYPTOPP_LIBRARIES})
target_link_libraries(testeth gmp)
target_link_libraries(testeth boost_system)
target_link_libraries(testeth boost_filesystem)
target_link_libraries(testeth ${CMAKE_THREAD_LIBS_INIT})

24
test/crypto.cpp

@ -30,6 +30,29 @@ using namespace eth;
int cryptoTest()
{
secp256k1_start();
KeyPair p(Secret(fromUserHex("3ecb44df2159c26e0f995712d4f39b6f6e499b40749b1cf1246c37f9516cb6a4")));
assert(p.pub() == Public(fromUserHex("97466f2b32bc3bb76d4741ae51cd1d8578b48d3f1e68da206d47321aec267ce78549b514e4453d74ef11b0cd5e4e4c364effddac8b51bcfc8de80682f952896f")));
assert(p.address() == Address(fromUserHex("8a40bfaa73256b60764c1bf40675a99083efb075")));
{
Transaction t;
t.nonce = 0;
t.receiveAddress = h160(fromUserHex("944400f4b88ac9589a0f17ed4671da26bddb668b"));
t.value = 1000;
t.data = u256s();
cnote << RLP(t.rlp(false));
cnote << asHex(t.rlp(false));
cnote << t.sha3(false);
t.sign(p.secret());
cnote << RLP(t.rlp(true));
cnote << asHex(t.rlp(true));
cnote << t.sha3(true);
assert(t.sender() == p.address());
}
#if 0
// Test transaction.
bytes tx = fromUserHex("88005401010101010101010101010101010101010101011f0de0b6b3a76400001ce8d4a5100080181c373130a009ba1f10285d4e659568bfcfec85067855c5a3c150100815dad4ef98fd37cf0593828c89db94bd6c64e210a32ef8956eaa81ea9307194996a3b879441f5d");
cout << "TX: " << RLP(tx) << endl;
@ -94,6 +117,7 @@ int cryptoTest()
cout << "RECPUB: " << dec << ret << " " << pubkeylen << " " << asHex(pubkey) << endl;
cout << "SENDER: " << hex << low160(eth::sha3(bytesConstRef(&pubkey).cropped(1))) << dec << endl;
}
#endif
return 0;
}

8
test/main.cpp

@ -41,11 +41,11 @@ int main(int argc, char** argv)
std::cout << asHex(s.out()) << std::endl;
std::cout << sha3(s.out()) << std::endl;*/
hexPrefixTest();
rlpTest();
trieTest();
// hexPrefixTest();
// rlpTest();
// trieTest();
// daggerTest();
// cryptoTest();
cryptoTest();
// stateTest();
// peerTest(argc, argv);
return 0;

4
windows/qt_plugin_import.cpp

@ -0,0 +1,4 @@
// This file is autogenerated by qmake. It imports static plugin classes for
// static plugins specified using QTPLUGIN and QT_PLUGIN_CLASS.<plugin> variables.
#include <QtPlugin>
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
Loading…
Cancel
Save