@ -24,6 +24,7 @@
# include <chrono>
# include <chrono>
# include <fstream>
# include <fstream>
# include <iostream>
# include <iostream>
# include <signal.h>
# include <boost/algorithm/string.hpp>
# include <boost/algorithm/string.hpp>
# include <boost/algorithm/string/trim_all.hpp>
# include <boost/algorithm/string/trim_all.hpp>
# include <libdevcrypto/FileSystem.h>
# include <libdevcrypto/FileSystem.h>
@ -121,17 +122,8 @@ string credits()
< < " Code by Gav Wood & , (c) 2013, 2014. " < < endl
< < " Code by Gav Wood & , (c) 2013, 2014. " < < endl
< < " Based on a design by Vitalik Buterin. " < < endl < < endl ;
< < " Based on a design by Vitalik Buterin. " < < endl < < endl ;
string vs = toString ( dev : : Version ) ;
vs = vs . substr ( vs . find_first_of ( ' . ' ) + 1 ) [ 0 ] ;
int pocnumber = stoi ( vs ) ;
string m_servers ;
if ( pocnumber = = 5 )
m_servers = " 54.72.69.180 " ;
else
m_servers = " 54.76.56.74 " ;
ccout < < " Type 'netstart 30303' to start networking " < < endl ;
ccout < < " Type 'netstart 30303' to start networking " < < endl ;
ccout < < " Type 'connect " < < m_servers < < " 30303' to connect " < < endl ;
ccout < < " Type 'connect " < < Host : : pocHost ( ) < < " 30303' to connect " < < endl ;
ccout < < " Type 'exit' to quit " < < endl < < endl ;
ccout < < " Type 'exit' to quit " < < endl < < endl ;
return ccout . str ( ) ;
return ccout . str ( ) ;
}
}
@ -139,12 +131,13 @@ string credits()
void version ( )
void version ( )
{
{
cout < < " neth version " < < dev : : Version < < endl ;
cout < < " neth version " < < dev : : Version < < endl ;
cout < < " Network protocol version: " < < dev : : eth : : c_protocolVersion < < endl ;
cout < < " Client database version: " < < dev : : eth : : c_databaseVersion < < endl ;
cout < < " Build: " < < DEV_QUOTED ( ETH_BUILD_PLATFORM ) < < " / " < < DEV_QUOTED ( ETH_BUILD_TYPE ) < < endl ;
cout < < " Build: " < < DEV_QUOTED ( ETH_BUILD_PLATFORM ) < < " / " < < DEV_QUOTED ( ETH_BUILD_TYPE ) < < endl ;
exit ( 0 ) ;
exit ( 0 ) ;
}
}
Address c_config = Address ( " 661005d2720d855f1d9976f88bb10c1a3398c77f " ) ;
Address c_config = Address ( " 661005d2720d855f1d9976f88bb10c1a3398c77f " ) ;
string pretty ( h160 _a , dev : : eth : : State _st )
string pretty ( h160 _a , dev : : eth : : State _st )
{
{
string ns ;
string ns ;
@ -161,6 +154,13 @@ string pretty(h160 _a, dev::eth::State _st)
return ns ;
return ns ;
}
}
bool g_exit = false ;
void sighandler ( int )
{
g_exit = true ;
}
namespace nc
namespace nc
{
{
@ -298,13 +298,18 @@ int main(int argc, char** argv)
string remoteHost ;
string remoteHost ;
unsigned short remotePort = 30303 ;
unsigned short remotePort = 30303 ;
string dbPath ;
string dbPath ;
bool mining = false ;
unsigned mining = ~ ( unsigned ) 0 ;
( void ) mining ;
NodeMode mode = NodeMode : : Full ;
unsigned peers = 5 ;
unsigned peers = 5 ;
# if ETH_JSONRPC
# if ETH_JSONRPC
int jsonrpc = 8080 ;
int jsonrpc = 8080 ;
# endif
# endif
string publicIP ;
string publicIP ;
bool bootstrap = false ;
bool upnp = true ;
bool upnp = true ;
bool useLocal = false ;
bool forceMining = false ;
string clientName ;
string clientName ;
// Init defaults
// Init defaults
@ -365,14 +370,21 @@ int main(int argc, char** argv)
{
{
string m = argv [ + + i ] ;
string m = argv [ + + i ] ;
if ( isTrue ( m ) )
if ( isTrue ( m ) )
mining = true ;
mining = ~ ( unsigned ) 0 ;
else if ( isFalse ( m ) )
else if ( isFalse ( m ) )
mining = false ;
mining = 0 ;
else if ( int i = stoi ( m ) )
mining = i ;
else
else
{
{
cerr < < " Unknown mining option: " < < m < < endl ;
cerr < < " Unknown -m/--mining option: " < < m < < endl ;
return - 1 ;
}
}
}
}
else if ( arg = = " -b " | | arg = = " --bootstrap " )
bootstrap = true ;
else if ( arg = = " -f " | | arg = = " --force-mining " )
forceMining = true ;
# if ETH_JSONRPC
# if ETH_JSONRPC
else if ( ( arg = = " -j " | | arg = = " --json-rpc " ) )
else if ( ( arg = = " -j " | | arg = = " --json-rpc " ) )
jsonrpc = jsonrpc ? jsonrpc : 8080 ;
jsonrpc = jsonrpc ? jsonrpc : 8080 ;
@ -394,12 +406,50 @@ int main(int argc, char** argv)
if ( ! clientName . empty ( ) )
if ( ! clientName . empty ( ) )
clientName + = " / " ;
clientName + = " / " ;
WebThreeDirect web3 ( " NEthereum(++) / " + clientName + " v " + dev::Version + " / " DEV_QUOTED(ETH_BUILD_TYPE) " / " DEV_QUOTED(ETH_BUILD_PLATFORM), dbPath) ;
cout < < credits ( ) ;
Client & c = * web3 . ethereum ( ) ;
c . setForceMining ( true ) ;
NetworkPreferences netPrefs ( listenPort , publicIP , upnp , useLocal ) ;
dev : : WebThreeDirect web3 (
" NEthereum(++)/ " + clientName + " v " + dev : : Version + " / " DEV_QUOTED ( ETH_BUILD_TYPE ) " / " DEV_QUOTED ( ETH_BUILD_PLATFORM ) ,
dbPath ,
false ,
mode = = NodeMode : : Full ? set < string > { " eth " , " shh " } : set < string > ( ) ,
netPrefs
) ;
web3 . setIdealPeerCount ( peers ) ;
eth : : Client * c = mode = = NodeMode : : Full ? web3 . ethereum ( ) : nullptr ;
cout < < credits ( ) ;
if ( c )
{
c - > setForceMining ( forceMining ) ;
c - > setAddress ( coinbase ) ;
}
auto nodesState = contents ( ( dbPath . size ( ) ? dbPath : getDataDir ( ) ) + " /nodeState.rlp " ) ;
web3 . restoreNodes ( & nodesState ) ;
web3 . startNetwork ( ) ;
if ( bootstrap )
web3 . connect ( Host : : pocHost ( ) ) ;
if ( remoteHost . size ( ) )
web3 . connect ( remoteHost , remotePort ) ;
# if ETH_JSONRPC
shared_ptr < WebThreeStubServer > jsonrpcServer ;
unique_ptr < jsonrpc : : AbstractServerConnector > jsonrpcConnector ;
if ( jsonrpc > - 1 )
{
jsonrpcConnector = unique_ptr < jsonrpc : : AbstractServerConnector > ( new jsonrpc : : HttpServer ( jsonrpc ) ) ;
jsonrpcServer = shared_ptr < WebThreeStubServer > ( new WebThreeStubServer ( * jsonrpcConnector . get ( ) , web3 , vector < KeyPair > ( { us } ) ) ) ;
jsonrpcServer - > setIdentities ( { us } ) ;
jsonrpcServer - > StartListening ( ) ;
}
# endif
signal ( SIGABRT , & sighandler ) ;
signal ( SIGTERM , & sighandler ) ;
signal ( SIGINT , & sighandler ) ;
std : : ostringstream ccout ;
std : : ostringstream ccout ;
@ -461,28 +511,6 @@ int main(int argc, char** argv)
wmove ( mainwin , 1 , 4 ) ;
wmove ( mainwin , 1 , 4 ) ;
if ( ! remoteHost . empty ( ) )
{
web3 . setIdealPeerCount ( peers ) ;
web3 . setNetworkPreferences ( NetworkPreferences ( listenPort , publicIP , upnp ) ) ;
web3 . startNetwork ( ) ;
web3 . connect ( remoteHost , remotePort ) ;
}
if ( mining )
c . startMining ( ) ;
# if ETH_JSONRPC
shared_ptr < WebThreeStubServer > jsonrpcServer ;
unique_ptr < jsonrpc : : AbstractServerConnector > jsonrpcConnector ;
if ( jsonrpc > - 1 )
{
jsonrpcConnector = unique_ptr < jsonrpc : : AbstractServerConnector > ( new jsonrpc : : HttpServer ( jsonrpc ) ) ;
jsonrpcServer = shared_ptr < WebThreeStubServer > ( new WebThreeStubServer ( * jsonrpcConnector . get ( ) , web3 , vector < KeyPair > ( { us } ) ) ) ;
jsonrpcServer - > setIdentities ( { us } ) ;
jsonrpcServer - > StartListening ( ) ;
}
# endif
while ( true )
while ( true )
{
{
wclrtobot ( consolewin ) ;
wclrtobot ( consolewin ) ;
@ -532,13 +560,25 @@ int main(int argc, char** argv)
{
{
web3 . stopNetwork ( ) ;
web3 . stopNetwork ( ) ;
}
}
else if ( cmd = = " minestart " )
else if ( c & & cmd = = " minestart " )
{
c - > startMining ( ) ;
}
else if ( c & & cmd = = " minestop " )
{
{
c . startMining ( ) ;
c - > stop Mining( ) ;
}
}
else if ( cmd = = " minestop " )
else if ( c & & c md = = " mineforce " )
{
{
c . stopMining ( ) ;
string enable ;
iss > > enable ;
c - > setForceMining ( isTrue ( enable ) ) ;
}
else if ( cmd = = " verbosity " )
{
if ( iss . peek ( ) ! = - 1 )
iss > > g_logVerbosity ;
cout < < " Verbosity: " < < g_logVerbosity < < endl ;
}
}
# if ETH_JSONRPC
# if ETH_JSONRPC
else if ( cmd = = " jsonport " )
else if ( cmd = = " jsonport " )
@ -575,7 +615,7 @@ int main(int argc, char** argv)
}
}
else if ( cmd = = " block " )
else if ( cmd = = " block " )
{
{
unsigned n = c . blockChain ( ) . details ( ) . number ;
unsigned n = c - > blockChain ( ) . details ( ) . number ;
ccout < < " Current block # " ;
ccout < < " Current block # " ;
ccout < < toString ( n ) < < endl ;
ccout < < toString ( n ) < < endl ;
}
}
@ -588,13 +628,13 @@ int main(int argc, char** argv)
}
}
else if ( cmd = = " balance " )
else if ( cmd = = " balance " )
{
{
u256 balance = c . balanceAt ( us . address ( ) ) ;
u256 balance = c - > balanceAt ( us . address ( ) ) ;
ccout < < " Current balance: " < < endl ;
ccout < < " Current balance: " < < endl ;
ccout < < toString ( balance ) < < endl ;
ccout < < toString ( balance ) < < endl ;
}
}
else if ( cmd = = " transact " )
else if ( cmd = = " transact " )
{
{
auto const & bc = c . blockChain ( ) ;
auto const & bc = c - > blockChain ( ) ;
auto h = bc . currentHash ( ) ;
auto h = bc . currentHash ( ) ;
auto blockData = bc . block ( h ) ;
auto blockData = bc . block ( h ) ;
BlockInfo info ( blockData ) ;
BlockInfo info ( blockData ) ;
@ -663,7 +703,7 @@ int main(int argc, char** argv)
{
{
Secret secret = h256 ( fromHex ( sechex ) ) ;
Secret secret = h256 ( fromHex ( sechex ) ) ;
Address dest = h160 ( fromHex ( fields [ 0 ] ) ) ;
Address dest = h160 ( fromHex ( fields [ 0 ] ) ) ;
c . transact ( secret , amount , dest , data , gas , gasPrice ) ;
c - > transact ( secret , amount , dest , data , gas , gasPrice ) ;
}
}
}
}
}
}
@ -696,19 +736,19 @@ int main(int argc, char** argv)
}
}
else
else
{
{
auto const & bc = c . blockChain ( ) ;
auto const & bc = c - > blockChain ( ) ;
auto h = bc . currentHash ( ) ;
auto h = bc . currentHash ( ) ;
auto blockData = bc . block ( h ) ;
auto blockData = bc . block ( h ) ;
BlockInfo info ( blockData ) ;
BlockInfo info ( blockData ) ;
u256 minGas = ( u256 ) Client : : txGas ( bytes ( ) , 0 ) ;
u256 minGas = ( u256 ) Client : : txGas ( bytes ( ) , 0 ) ;
Address dest = h160 ( fromHex ( fields [ 0 ] ) ) ;
Address dest = h160 ( fromHex ( fields [ 0 ] ) ) ;
c . transact ( us . secret ( ) , amount , dest , bytes ( ) , minGas ) ;
c - > transact ( us . secret ( ) , amount , dest , bytes ( ) , minGas ) ;
}
}
}
}
}
}
else if ( cmd = = " contract " )
else if ( cmd = = " contract " )
{
{
auto const & bc = c . blockChain ( ) ;
auto const & bc = c - > blockChain ( ) ;
auto h = bc . currentHash ( ) ;
auto h = bc . currentHash ( ) ;
auto blockData = bc . block ( h ) ;
auto blockData = bc . block ( h ) ;
BlockInfo info ( blockData ) ;
BlockInfo info ( blockData ) ;
@ -768,7 +808,7 @@ int main(int argc, char** argv)
cwarn < < " Minimum gas amount is " < < minGas ;
cwarn < < " Minimum gas amount is " < < minGas ;
else
else
{
{
c . transact ( us . secret ( ) , endowment , init , gas ) ;
c - > transact ( us . secret ( ) , endowment , init , gas ) ;
}
}
}
}
}
}
@ -786,10 +826,10 @@ int main(int argc, char** argv)
try
try
{
{
auto storage = c . storageAt ( address ) ;
auto storage = c - > storageAt ( address ) ;
for ( auto const & i : storage )
for ( auto const & i : storage )
s < < " @ " < < showbase < < hex < < i . first < < " " < < showbase < < hex < < i . second < < endl ;
s < < " @ " < < showbase < < hex < < i . first < < " " < < showbase < < hex < < i . second < < endl ;
s < < endl < < disassemble ( c . codeAt ( address ) ) < < endl ;
s < < endl < < disassemble ( c - > codeAt ( address ) ) < < endl ;
string outFile = getDataDir ( ) + " / " + rechex + " .evm " ;
string outFile = getDataDir ( ) + " / " + rechex + " .evm " ;
ofstream ofs ;
ofstream ofs ;
@ -824,7 +864,7 @@ int main(int argc, char** argv)
// Lock to prevent corrupt block-chain errors
// Lock to prevent corrupt block-chain errors
auto const & bc = c . blockChain ( ) ;
auto const & bc = c - > blockChain ( ) ;
ccout < < " Genesis hash: " < < bc . genesisHash ( ) < < endl ;
ccout < < " Genesis hash: " < < bc . genesisHash ( ) < < endl ;
// Blocks
// Blocks
@ -838,11 +878,11 @@ int main(int argc, char** argv)
auto b = bc . block ( h ) ;
auto b = bc . block ( h ) ;
for ( auto const & i : RLP ( b ) [ 1 ] )
for ( auto const & i : RLP ( b ) [ 1 ] )
{
{
Transaction t ( i [ 0 ] . data ( ) ) ;
Transaction t ( i . data ( ) ) ;
auto s = t . receiveAddress ( ) ?
auto s = t . receiveAddress ( ) ?
boost : : format ( " %1% %2%> %3%: %4% [%5%] " ) %
boost : : format ( " %1% %2%> %3%: %4% [%5%] " ) %
toString ( t . safeSender ( ) ) %
toString ( t . safeSender ( ) ) %
( c . codeAt ( t . receiveAddress ( ) , 0 ) . size ( ) ? ' * ' : ' - ' ) %
( c - > codeAt ( t . receiveAddress ( ) , 0 ) . size ( ) ? ' * ' : ' - ' ) %
toString ( t . receiveAddress ( ) ) %
toString ( t . receiveAddress ( ) ) %
toString ( formatBalance ( t . value ( ) ) ) %
toString ( formatBalance ( t . value ( ) ) ) %
toString ( ( unsigned ) t . nonce ( ) ) :
toString ( ( unsigned ) t . nonce ( ) ) :
@ -862,12 +902,12 @@ int main(int argc, char** argv)
// Pending
// Pending
y = 1 ;
y = 1 ;
for ( Transaction const & t : c . pending ( ) )
for ( Transaction const & t : c - > pending ( ) )
{
{
auto s = t . receiveAddress ( ) ?
auto s = t . receiveAddress ( ) ?
boost : : format ( " %1% %2%> %3%: %4% [%5%] " ) %
boost : : format ( " %1% %2%> %3%: %4% [%5%] " ) %
toString ( t . safeSender ( ) ) %
toString ( t . safeSender ( ) ) %
( c . codeAt ( t . receiveAddress ( ) , 0 ) . size ( ) ? ' * ' : ' - ' ) %
( c - > codeAt ( t . receiveAddress ( ) , 0 ) . size ( ) ? ' * ' : ' - ' ) %
toString ( t . receiveAddress ( ) ) %
toString ( t . receiveAddress ( ) ) %
toString ( formatBalance ( t . value ( ) ) ) %
toString ( formatBalance ( t . value ( ) ) ) %
toString ( ( unsigned ) t . nonce ( ) ) :
toString ( ( unsigned ) t . nonce ( ) ) :
@ -877,7 +917,7 @@ int main(int argc, char** argv)
toString ( formatBalance ( t . value ( ) ) ) %
toString ( formatBalance ( t . value ( ) ) ) %
toString ( ( unsigned ) t . nonce ( ) ) ;
toString ( ( unsigned ) t . nonce ( ) ) ;
mvwaddnstr ( pendingwin , y + + , x , s . str ( ) . c_str ( ) , qwidth ) ;
mvwaddnstr ( pendingwin , y + + , x , s . str ( ) . c_str ( ) , qwidth ) ;
if ( y > height * 1 / 5 - 4 )
if ( y > height * 1 / 5 - 2 )
break ;
break ;
}
}
@ -885,27 +925,27 @@ int main(int argc, char** argv)
// Contracts and addresses
// Contracts and addresses
y = 1 ;
y = 1 ;
int cc = 1 ;
int cc = 1 ;
auto acs = c . addresses ( ) ;
auto acs = c - > addresses ( ) ;
for ( auto const & i : acs )
for ( auto const & i : acs )
if ( c . codeAt ( i , 0 ) . size ( ) )
if ( c - > codeAt ( i , 0 ) . size ( ) )
{
{
auto s = boost : : format ( " %1%%2% : %3% [%4%] " ) %
auto s = boost : : format ( " %1%%2% : %3% [%4%] " ) %
toString ( i ) %
toString ( i ) %
pretty ( i , c . postState ( ) ) %
pretty ( i , c - > postState ( ) ) %
toString ( formatBalance ( c . balanceAt ( i ) ) ) %
toString ( formatBalance ( c - > balanceAt ( i ) ) ) %
toString ( ( unsigned ) c . countAt ( i , 0 ) ) ;
toString ( ( unsigned ) c - > countAt ( i , 0 ) ) ;
mvwaddnstr ( contractswin , cc + + , x , s . str ( ) . c_str ( ) , qwidth ) ;
mvwaddnstr ( contractswin , cc + + , x , s . str ( ) . c_str ( ) , qwidth ) ;
if ( cc > qheight - 2 )
if ( cc > qheight - 2 )
break ;
break ;
}
}
for ( auto const & i : acs )
for ( auto const & i : acs )
if ( c . codeAt ( i , 0 ) . empty ( ) )
if ( c - > codeAt ( i , 0 ) . empty ( ) )
{
{
auto s = boost : : format ( " %1%%2% : %3% [%4%] " ) %
auto s = boost : : format ( " %1%%2% : %3% [%4%] " ) %
toString ( i ) %
toString ( i ) %
pretty ( i , c . postState ( ) ) %
pretty ( i , c - > postState ( ) ) %
toString ( formatBalance ( c . balanceAt ( i ) ) ) %
toString ( formatBalance ( c - > balanceAt ( i ) ) ) %
toString ( ( unsigned ) c . countAt ( i , 0 ) ) ;
toString ( ( unsigned ) c - > countAt ( i , 0 ) ) ;
mvwaddnstr ( addswin , y + + , x , s . str ( ) . c_str ( ) , width / 2 - 4 ) ;
mvwaddnstr ( addswin , y + + , x , s . str ( ) . c_str ( ) , width / 2 - 4 ) ;
if ( y > height * 3 / 5 - 4 )
if ( y > height * 3 / 5 - 4 )
break ;
break ;
@ -935,21 +975,18 @@ int main(int argc, char** argv)
// Balance
// Balance
stringstream ssb ;
stringstream ssb ;
u256 balance = c . balanceAt ( us . address ( ) ) ;
u256 balance = c - > balanceAt ( us . address ( ) ) ;
Address coinsAddr = right160 ( c . stateAt ( c_config , 1 ) ) ;
ssb < < " Balance: " < < formatBalance ( balance ) ;
Address gavCoin = right160 ( c . stateAt ( coinsAddr , c . stateAt ( coinsAddr , 1 ) ) ) ;
u256 totalGavCoinBalance = c . stateAt ( gavCoin , ( u160 ) us . address ( ) ) ;
ssb < < " Balance: " < < formatBalance ( balance ) < < " | " < < totalGavCoinBalance < < " GAV " ;
mvwprintw ( consolewin , 0 , x , ssb . str ( ) . c_str ( ) ) ;
mvwprintw ( consolewin , 0 , x , ssb . str ( ) . c_str ( ) ) ;
// Block
// Block
mvwprintw ( blockswin , 0 , x , " Block # " ) ;
mvwprintw ( blockswin , 0 , x , " Block # " ) ;
unsigned n = c . blockChain ( ) . details ( ) . number ;
unsigned n = c - > blockChain ( ) . details ( ) . number ;
mvwprintw ( blockswin , 0 , 10 , toString ( n ) . c_str ( ) ) ;
mvwprintw ( blockswin , 0 , 10 , toString ( n ) . c_str ( ) ) ;
// Pending
// Pending
string pc ;
string pc ;
pc = " Pending: " + toString ( c . pending ( ) . size ( ) ) ;
pc = " Pending: " + toString ( c - > pending ( ) . size ( ) ) ;
mvwprintw ( pendingwin , 0 , x , pc . c_str ( ) ) ;
mvwprintw ( pendingwin , 0 , x , pc . c_str ( ) ) ;
// Contracts
// Contracts
@ -962,10 +999,10 @@ int main(int argc, char** argv)
mvwprintw ( peerswin , 0 , 9 , toString ( web3 . peers ( ) . size ( ) ) . c_str ( ) ) ;
mvwprintw ( peerswin , 0 , 9 , toString ( web3 . peers ( ) . size ( ) ) . c_str ( ) ) ;
// Mining flag
// Mining flag
if ( c . isMining ( ) )
if ( c - > isMining ( ) )
{
{
mvwprintw ( consolewin , qheight - 1 , width / 4 - 11 , " Mining ON " ) ;
mvwprintw ( consolewin , qheight - 1 , width / 4 - 11 , " Mining ON " ) ;
dev : : eth : : MineProgress p = c . miningProgress ( ) ;
dev : : eth : : MineProgress p = c - > miningProgress ( ) ;
auto speed = boost : : format ( " %2% kH/s @ %1%s " ) % ( p . ms / 1000 ) % ( p . ms ? p . hashes / p . ms : 0 ) ;
auto speed = boost : : format ( " %2% kH/s @ %1%s " ) % ( p . ms / 1000 ) % ( p . ms ? p . hashes / p . ms : 0 ) ;
mvwprintw ( consolewin , qheight - 2 , width / 4 - speed . str ( ) . length ( ) - 2 , speed . str ( ) . c_str ( ) ) ;
mvwprintw ( consolewin , qheight - 2 , width / 4 - speed . str ( ) . length ( ) - 2 , speed . str ( ) . c_str ( ) ) ;
}
}