From 3de2ecfc67d296a427b68a668a01db0ed4656c4f Mon Sep 17 00:00:00 2001 From: Vincent Gariepy Date: Fri, 28 Mar 2014 02:22:32 -0400 Subject: [PATCH 1/6] cleaner ncurses console output --- eth/main.cpp | 165 +++++++++++++++++++++++++++------------------------ 1 file changed, 87 insertions(+), 78 deletions(-) diff --git a/eth/main.cpp b/eth/main.cpp index cebcfb9ec..2b6894518 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -93,6 +93,14 @@ void interactiveHelp() << " exit Exits the application." << endl; } +void credits() +{ + cout + << "Ethereum (++) " << ETH_QUOTED(ETH_VERSION) << endl + << " Code by Gav Wood, (c) 2013, 2014." << endl + << " Based on a design by Vitalik Buterin." << endl << endl; +} + void version() { cout << "eth version " << ETH_QUOTED(ETH_VERSION) << endl; @@ -186,13 +194,18 @@ int nc_window_streambuf::overflow( int c ) int ret = c; if (c != EOF) { - int x = 0; - int y = 0; + int x = 0, y = 0, mx = 0, my = 0; getyx(m_pnl, y, x); + getmaxyx(m_pnl, my, mx); if (y < 1) y = 1; if (x < 2) x = 2; + if (x > mx - 4) + { + y++; + x = 2; + } if (m_flags) { wattron(m_pnl, m_flags); @@ -332,18 +345,17 @@ int main(int argc, char** argv) if (!clientName.empty()) clientName += "/"; Client c("Ethereum(++)/" + clientName + "v" ETH_QUOTED(ETH_VERSION) "/" ETH_QUOTED(ETH_BUILD_TYPE) "/" ETH_QUOTED(ETH_BUILD_PLATFORM), coinbase, dbPath); + credits(); if (interactive) { - g_logPost = std::function(); -/* cout << "Ethereum (++)" << endl; - cout << " Code by Gav Wood, (c) 2013, 2014." << endl; - cout << " Based on a design by Vitalik Buterin." << endl << endl; -*/ + std::ostringstream ccout; + /* Initialize ncurses */ const char* chr; char* str = new char[255]; - int termwidth, termheight; + int width, height; + int y = 0, x = 2; std::string cmd; WINDOW * mainwin, * consolewin, * logwin, * blockswin, * pendingwin, * contractswin, * peerswin; @@ -353,8 +365,8 @@ int main(int argc, char** argv) return -1; } - getmaxyx(mainwin, termheight, termwidth); - int width = termwidth, height = termheight; + getmaxyx(mainwin, height, width); + int qwidth = width / 4 - 4; nonl(); nocbreak(); @@ -368,27 +380,25 @@ int main(int argc, char** argv) g_logVerbosity = 1; // Force verbosity level for now consolewin = newwin(height * 3 / 5, width / 4, 0, 0); + nc::nc_window_streambuf coutbuf( consolewin, ccout ); blockswin = newwin(height * 3 / 5, width / 4, 0, width / 4); pendingwin = newwin(height * 1 / 5, width / 4, 0, width * 2 / 4); peerswin = newwin(height * 2 / 5, width / 4, height * 1 / 5, width * 2 / 4); contractswin = newwin(height * 3 / 5, width / 4, 0, width * 3 / 4); - wsetscrreg(consolewin, 1, height * 3 / 5 - 2); - wsetscrreg(blockswin, 1, height * 3 / 5 - 2); - wsetscrreg(pendingwin, 1, height * 1 / 5 - 2); - wsetscrreg(peerswin, 1, height * 2 / 5 - 2); - wsetscrreg(contractswin, 1, height * 3 / 5 - 2); - - mvwaddnstr(consolewin, 4, 2, "Ethereum (++) " ETH_QUOTED(ETH_VERSION) "\n", width / 4 - 4); - mvwaddnstr(consolewin, 5, 2, " Code by Gav Wood, (c) 2013, 2014.\n", width / 4 - 4); - mvwaddnstr(consolewin, 6, 2, " Based on a design by Vitalik Buterin.\n", width / 4 - 4); + int vl = height * 3 / 5 - 4; + wsetscrreg(consolewin, 1, vl); + wsetscrreg(blockswin, 1, vl); + wsetscrreg(pendingwin, 1, vl); + wsetscrreg(peerswin, 1, vl); + wsetscrreg(contractswin, 1, vl); - mvwaddnstr(consolewin, 7, 2, "Type 'netstart 30303' to start networking", width / 4 - 4); - mvwaddnstr(consolewin, 8, 2, "Type 'connect 54.201.28.117 30303' to connect", width / 4 - 4); - mvwaddnstr(consolewin, 9, 2, "Type 'exit' to quit", width / 4 - 4); - - mvwprintw(mainwin, 1, 2, "> "); + credits(); + ccout << "Type 'netstart 30303' to start networking" << endl; + ccout << "Type 'connect 54.201.28.117 30303' to connect" << endl; + ccout << "Type 'exit' to quit" << endl; + mvwprintw(mainwin, 1, x, "> "); wresize(mainwin, 3, width); mvwin(mainwin, height - 3, 0); @@ -399,45 +409,14 @@ int main(int argc, char** argv) while (true) { - int y = 0; + getmaxyx(mainwin, height, width); + qwidth = width / 4 - 4; + wclrtobot(consolewin); wclrtobot(pendingwin); wclrtobot(peerswin); wclrtobot(contractswin); - box(mainwin, 0, 0); - box(blockswin, 0, 0); - box(pendingwin, 0, 0); - box(peerswin, 0, 0); - box(consolewin, 0, 0); - box(contractswin, 0, 0); - - mvwprintw(blockswin, 0, 2, "Blocks"); - mvwprintw(pendingwin, 0, 2, "Pending"); - mvwprintw(contractswin, 0, 2, "Contracts"); - - // Block - mvwprintw(consolewin, 0, 2, "Block # "); - eth::uint n = c.blockChain().details().number; - chr = toString(n).c_str(); - mvwprintw(consolewin, 0, 10, chr); - - // Address - mvwprintw(consolewin, 1, 2, "Address: "); - chr = toHex(us.address().asArray()).c_str(); - mvwprintw(consolewin, 2, 2, chr); - - // Balance - mvwprintw(consolewin, height * 3 / 5 - 1, 2, "Balance: "); - u256 balance = c.state().balance(us.address()); - chr = toString(balance).c_str(); - mvwprintw(consolewin, height * 3 / 5 - 1, 11, chr); - - // Peers - mvwprintw(peerswin, 0, 2, "Peers: "); - chr = toString(c.peers().size()).c_str(); - mvwprintw(peerswin, 0, 9, chr); - // Prompt wmove(mainwin, 1, 4); getstr(str); @@ -446,15 +425,13 @@ int main(int argc, char** argv) istringstream iss(s); iss >> cmd; - mvwprintw(mainwin, 1, 2, "> "); + mvwprintw(mainwin, 1, x, "> "); clrtoeol(); if (s.length() > 1) { - mvwaddstr(consolewin, height * 3 / 5 - 3, 2, "> "); - wclrtoeol(consolewin); - mvwaddnstr(consolewin, height * 3 / 5 - 3, 4, str, width - 6); - mvwaddch(consolewin, height * 3 / 5 - 3, width / 4 - 1, ACS_VLINE); + ccout << "> "; + ccout << str << endl; } if (cmd == "netstart") @@ -478,31 +455,29 @@ int main(int argc, char** argv) c.stopMining(); else if (cmd == "address") { - mvwaddstr(consolewin, height * 3 / 5 - 3, 2, "Current address:\n"); - mvwaddch(consolewin, height * 3 / 5 - 3, width / 4 - 1, ACS_VLINE); + ccout << "Current address:" << endl; const char* addchr = toHex(us.address().asArray()).c_str(); - mvwaddstr(consolewin, height * 3 / 5 - 2, 2, addchr); + ccout << addchr << endl; } else if (cmd == "secret") { - mvwaddstr(consolewin, height * 3 / 5 - 4, 2, "Current secret:\n"); - mvwaddch(consolewin, height * 3 / 5 - 3, width / 4 - 1, ACS_VLINE); + ccout << "Current secret:" << endl; const char* addchr = toHex(us.secret().asArray()).c_str(); - mvwaddstr(consolewin, height * 3 / 5 - 3, 2, addchr); + ccout << addchr << endl; } else if (cmd == "block") { eth::uint n = c.blockChain().details().number; - mvwaddstr(consolewin, height * 3 / 5 - 1, 2, "Current block # "); + ccout << "Current block #:" << endl; const char* addchr = toString(n).c_str(); - waddstr(consolewin, addchr); + ccout << addchr << endl; } else if (cmd == "balance") { u256 balance = c.state().balance(us.address()); - mvwaddstr(consolewin, height * 3 / 5 - 1, 2, "Current balance: "); + ccout << "Current balance:" << endl; const char* addchr = toString(balance).c_str(); - waddstr(consolewin, addchr); + ccout << addchr << endl; } else if (cmd == "transact") { @@ -604,7 +579,7 @@ int main(int argc, char** argv) auto d = bc.details(h); std::string s = "# " + std::to_string(d.number) + ' ' + toString(h); // .abridged(); y += 1; - mvwaddnstr(blockswin, y, 2, s.c_str(), width / 4 - 4); + mvwaddnstr(blockswin, y, x, s.c_str(), qwidth); for (auto const& i: RLP(bc.block(h))[1]) { @@ -614,7 +589,7 @@ int main(int argc, char** argv) " " + toString(toHex(t.safeSender().asArray())) + " " + (st.isContractAddress(t.receiveAddress) ? '*' : '-') + "> " + toString(t.receiveAddress) + ": " + toString(formatBalance(t.value)) + " [" + toString((unsigned)t.nonce) + "]": " " + toString(toHex(t.safeSender().asArray())) + " +> " + toString(right160(t.sha3())) + ": " + toString(formatBalance(t.value)) + " [" + toString((unsigned)t.nonce) + "]"; y += 1; - mvwaddnstr(blockswin, y, 2, ss.c_str(), width / 4 - 6); + mvwaddnstr(blockswin, y, x, ss.c_str(), width / 4 - 6); if (y > height * 3 / 5 - 4) break; } @@ -633,7 +608,7 @@ int main(int argc, char** argv) else ss = toString(toHex(t.safeSender().asArray())) + " +> " + toString(right160(t.sha3())) + ": " + toString(formatBalance(t.value)) + "[" + toString((unsigned)t.nonce) + "]"; y += 1; - mvwaddnstr(pendingwin, y, 2, ss.c_str(), width / 4 - 6); + mvwaddnstr(pendingwin, y, x, ss.c_str(), width / 4 - 6); if (y > height * 3 / 5 - 4) break; } @@ -652,7 +627,7 @@ int main(int argc, char** argv) std::string ss; ss = toString(r) + " : " + toString(formatBalance(i.second)) + " [" + toString((unsigned)st.transactionsFrom(i.first)) + "]"; y += 1; - mvwaddnstr(contractswin, y, 2, ss.c_str(), width / 4 - 5); + mvwaddnstr(contractswin, y, x, ss.c_str(), width / 4 - 5); if (y > height * 3 / 5 - 4) break; } @@ -668,11 +643,45 @@ int main(int argc, char** argv) { pss = toString(chrono::duration_cast(i.lastPing).count()) + " ms - " + i.host + ":" + toString(i.port) + " - " + i.clientVersion; y += 1; - mvwaddnstr(peerswin, y, 2, pss.c_str(), width / 4 - 5); + mvwaddnstr(peerswin, y, x, pss.c_str(), width / 4 - 5); if (y > height * 2 / 5 - 4) break; } + // Address + ccout << "Address:" << endl; + chr = toHex(us.address().asArray()).c_str(); + ccout << chr << endl << endl; + // wmove(consolewin, 3, x); + + box(mainwin, 0, 0); + box(blockswin, 0, 0); + box(pendingwin, 0, 0); + box(peerswin, 0, 0); + box(consolewin, 0, 0); + box(contractswin, 0, 0); + + mvwprintw(pendingwin, 0, x, "Pending"); + mvwprintw(contractswin, 0, x, "Contracts"); + + // Block + mvwprintw(blockswin, 0, x, "Block # "); + eth::uint n = c.blockChain().details().number; + chr = toString(n).c_str(); + mvwprintw(blockswin, 0, 10, chr); + + // Balance + mvwprintw(consolewin, height * 3 / 5 - 1, x, "Balance: "); + u256 balance = c.state().balance(us.address()); + chr = toString(balance).c_str(); + mvwprintw(consolewin, height * 3 / 5 - 1, 11, chr); + wmove(consolewin, y, x); + + // Peers + mvwprintw(peerswin, 0, x, "Peers: "); + chr = toString(c.peers().size()).c_str(); + mvwprintw(peerswin, 0, 9, chr); + wrefresh(consolewin); wrefresh(blockswin); wrefresh(pendingwin); From a536f1e91048a200f2dfb78403d6dd948ea81ab3 Mon Sep 17 00:00:00 2001 From: Vincent Gariepy Date: Fri, 28 Mar 2014 08:24:44 -0400 Subject: [PATCH 2/6] return credits and switch server IPs --- eth/main.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/eth/main.cpp b/eth/main.cpp index 2b6894518..d10386d09 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -93,12 +93,14 @@ void interactiveHelp() << " exit Exits the application." << endl; } -void credits() +std::string credits() { - cout + std::ostringstream ccout; + ccout << "Ethereum (++) " << ETH_QUOTED(ETH_VERSION) << endl << " Code by Gav Wood, (c) 2013, 2014." << endl << " Based on a design by Vitalik Buterin." << endl << endl; + return ccout.str(); } void version() @@ -345,7 +347,7 @@ int main(int argc, char** argv) if (!clientName.empty()) clientName += "/"; Client c("Ethereum(++)/" + clientName + "v" ETH_QUOTED(ETH_VERSION) "/" ETH_QUOTED(ETH_BUILD_TYPE) "/" ETH_QUOTED(ETH_BUILD_PLATFORM), coinbase, dbPath); - credits(); + cout << credits(); if (interactive) { @@ -393,9 +395,19 @@ int main(int argc, char** argv) wsetscrreg(peerswin, 1, vl); wsetscrreg(contractswin, 1, vl); - credits(); + ccout << credits(); + + std::string vs = toString(ETH_QUOTED(ETH_VERSION)); + vs = vs.substr(vs.find_first_of('.') + 1)[0]; + int pocnumber = stoi(vs); + std::string m_servers; + if (pocnumber == 3) + m_servers = "54.201.28.117"; + if (pocnumber == 4) + m_servers = "54.72.31.55"; + ccout << "Type 'netstart 30303' to start networking" << endl; - ccout << "Type 'connect 54.201.28.117 30303' to connect" << endl; + ccout << "Type 'connect " << m_servers << " 30303' to connect" << endl; ccout << "Type 'exit' to quit" << endl; mvwprintw(mainwin, 1, x, "> "); From 596999e1204bd16667cdd61b9eb1149973bdc9bf Mon Sep 17 00:00:00 2001 From: Vincent Gariepy Date: Fri, 28 Mar 2014 09:32:44 -0400 Subject: [PATCH 3/6] a few ncurses windows touchups --- eth/main.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/eth/main.cpp b/eth/main.cpp index d10386d09..0e7d10f8c 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -421,9 +421,6 @@ int main(int argc, char** argv) while (true) { - getmaxyx(mainwin, height, width); - qwidth = width / 4 - 4; - wclrtobot(consolewin); wclrtobot(pendingwin); wclrtobot(peerswin); @@ -605,7 +602,7 @@ int main(int argc, char** argv) if (y > height * 3 / 5 - 4) break; } - if (y > height * 3 / 5 - 3) + if (y > height * 3 / 5 - 4) break; } @@ -620,8 +617,8 @@ int main(int argc, char** argv) else ss = toString(toHex(t.safeSender().asArray())) + " +> " + toString(right160(t.sha3())) + ": " + toString(formatBalance(t.value)) + "[" + toString((unsigned)t.nonce) + "]"; y += 1; - mvwaddnstr(pendingwin, y, x, ss.c_str(), width / 4 - 6); - if (y > height * 3 / 5 - 4) + mvwaddnstr(pendingwin, y, x, ss.c_str(), qwidth); + if (y > height * 3 / 5 - 6) break; } @@ -639,7 +636,7 @@ int main(int argc, char** argv) std::string ss; ss = toString(r) + " : " + toString(formatBalance(i.second)) + " [" + toString((unsigned)st.transactionsFrom(i.first)) + "]"; y += 1; - mvwaddnstr(contractswin, y, x, ss.c_str(), width / 4 - 5); + mvwaddnstr(contractswin, y, x, ss.c_str(), qwidth); if (y > height * 3 / 5 - 4) break; } @@ -655,8 +652,8 @@ int main(int argc, char** argv) { pss = toString(chrono::duration_cast(i.lastPing).count()) + " ms - " + i.host + ":" + toString(i.port) + " - " + i.clientVersion; y += 1; - mvwaddnstr(peerswin, y, x, pss.c_str(), width / 4 - 5); - if (y > height * 2 / 5 - 4) + mvwaddnstr(peerswin, y, x, pss.c_str(), qwidth); + if (y > height * 2 / 5 - 6) break; } @@ -683,11 +680,11 @@ int main(int argc, char** argv) mvwprintw(blockswin, 0, 10, chr); // Balance - mvwprintw(consolewin, height * 3 / 5 - 1, x, "Balance: "); + mvwprintw(consolewin, 0, x, "Balance: "); u256 balance = c.state().balance(us.address()); chr = toString(balance).c_str(); - mvwprintw(consolewin, height * 3 / 5 - 1, 11, chr); - wmove(consolewin, y, x); + mvwprintw(consolewin, 0, 11, chr); + wmove(consolewin, 1, x); // Peers mvwprintw(peerswin, 0, x, "Peers: "); From 47f6b441f6d0120741feb4dc6a060a807ce68edf Mon Sep 17 00:00:00 2001 From: Vincent Gariepy Date: Sun, 30 Mar 2014 16:45:56 -0400 Subject: [PATCH 4/6] coding standards and adjust heights --- eth/main.cpp | 50 +++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/eth/main.cpp b/eth/main.cpp index 0e7d10f8c..b2a41f2cb 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -93,7 +93,7 @@ void interactiveHelp() << " exit Exits the application." << endl; } -std::string credits() +string credits() { std::ostringstream ccout; ccout @@ -191,12 +191,15 @@ nc_window_streambuf::~nc_window_streambuf() m_os->rdbuf(m_old); } -int nc_window_streambuf::overflow( int c ) +int nc_window_streambuf::overflow(int c) { int ret = c; if (c != EOF) { - int x = 0, y = 0, mx = 0, my = 0; + int x = 0; + int y = 0; + int mx = 0; + int my = 0; getyx(m_pnl, y, x); getmaxyx(m_pnl, my, mx); if (y < 1) @@ -356,9 +359,11 @@ int main(int argc, char** argv) /* Initialize ncurses */ const char* chr; char* str = new char[255]; - int width, height; - int y = 0, x = 2; - std::string cmd; + int width; + int height; + int y = 0; + int x = 2; + string cmd; WINDOW * mainwin, * consolewin, * logwin, * blockswin, * pendingwin, * contractswin, * peerswin; if (!(mainwin = initscr())) @@ -377,12 +382,12 @@ int main(int argc, char** argv) keypad(mainwin, true); logwin = newwin(height * 2 / 5 - 2, width, height * 3 / 5, 0); - nc::nc_window_streambuf outbuf( logwin, std::cout ); + nc::nc_window_streambuf outbuf(logwin, std::cout); // nc::nc_window_streambuf errbuf( logwin, std::cerr ); g_logVerbosity = 1; // Force verbosity level for now consolewin = newwin(height * 3 / 5, width / 4, 0, 0); - nc::nc_window_streambuf coutbuf( consolewin, ccout ); + nc::nc_window_streambuf coutbuf(consolewin, ccout); blockswin = newwin(height * 3 / 5, width / 4, 0, width / 4); pendingwin = newwin(height * 1 / 5, width / 4, 0, width * 2 / 4); peerswin = newwin(height * 2 / 5, width / 4, height * 1 / 5, width * 2 / 4); @@ -397,10 +402,10 @@ int main(int argc, char** argv) ccout << credits(); - std::string vs = toString(ETH_QUOTED(ETH_VERSION)); + string vs = toString(ETH_QUOTED(ETH_VERSION)); vs = vs.substr(vs.find_first_of('.') + 1)[0]; int pocnumber = stoi(vs); - std::string m_servers; + string m_servers; if (pocnumber == 3) m_servers = "54.201.28.117"; if (pocnumber == 4) @@ -586,23 +591,23 @@ int main(int argc, char** argv) for (auto h = bc.currentHash(); h != bc.genesisHash(); h = bc.details(h).parent) { auto d = bc.details(h); - std::string s = "# " + std::to_string(d.number) + ' ' + toString(h); // .abridged(); + string s = "# " + std::to_string(d.number) + ' ' + toString(h); // .abridged(); y += 1; mvwaddnstr(blockswin, y, x, s.c_str(), qwidth); for (auto const& i: RLP(bc.block(h))[1]) { Transaction t(i.data()); - std::string ss; + string ss; ss = t.receiveAddress ? " " + toString(toHex(t.safeSender().asArray())) + " " + (st.isContractAddress(t.receiveAddress) ? '*' : '-') + "> " + toString(t.receiveAddress) + ": " + toString(formatBalance(t.value)) + " [" + toString((unsigned)t.nonce) + "]": " " + toString(toHex(t.safeSender().asArray())) + " +> " + toString(right160(t.sha3())) + ": " + toString(formatBalance(t.value)) + " [" + toString((unsigned)t.nonce) + "]"; y += 1; - mvwaddnstr(blockswin, y, x, ss.c_str(), width / 4 - 6); - if (y > height * 3 / 5 - 4) + mvwaddnstr(blockswin, y, x, ss.c_str(), qwidth - 2); + if (y > height * 3 / 5 - 2) break; } - if (y > height * 3 / 5 - 4) + if (y > height * 3 / 5 - 2) break; } @@ -611,14 +616,14 @@ int main(int argc, char** argv) y = 0; for (Transaction const& t: c.pending()) { - std::string ss; + string ss; if (t.receiveAddress) ss = toString(toHex(t.safeSender().asArray())) + " " + (st.isContractAddress(t.receiveAddress) ? '*' : '-') + "> " + toString(t.receiveAddress) + ": " + toString(formatBalance(t.value)) + " " + " [" + toString((unsigned)t.nonce) + "]"; else ss = toString(toHex(t.safeSender().asArray())) + " +> " + toString(right160(t.sha3())) + ": " + toString(formatBalance(t.value)) + "[" + toString((unsigned)t.nonce) + "]"; y += 1; mvwaddnstr(pendingwin, y, x, ss.c_str(), qwidth); - if (y > height * 3 / 5 - 6) + if (y > height * 3 / 5 - 4) break; } @@ -633,19 +638,19 @@ int main(int argc, char** argv) if (st.isContractAddress(r)) { - std::string ss; + string ss; ss = toString(r) + " : " + toString(formatBalance(i.second)) + " [" + toString((unsigned)st.transactionsFrom(i.first)) + "]"; y += 1; mvwaddnstr(contractswin, y, x, ss.c_str(), qwidth); - if (y > height * 3 / 5 - 4) + if (y > height * 3 / 5 - 2) break; } } // Peers y = 0; - std::string psc; - std::string pss; + string psc; + string pss; auto cp = c.peers(); psc = toString(cp.size()) + " peer(s)"; for (PeerInfo const& i: cp) @@ -653,7 +658,7 @@ int main(int argc, char** argv) pss = toString(chrono::duration_cast(i.lastPing).count()) + " ms - " + i.host + ":" + toString(i.port) + " - " + i.clientVersion; y += 1; mvwaddnstr(peerswin, y, x, pss.c_str(), qwidth); - if (y > height * 2 / 5 - 6) + if (y > height * 2 / 5 - 4) break; } @@ -661,7 +666,6 @@ int main(int argc, char** argv) ccout << "Address:" << endl; chr = toHex(us.address().asArray()).c_str(); ccout << chr << endl << endl; - // wmove(consolewin, 3, x); box(mainwin, 0, 0); box(blockswin, 0, 0); From 0627f0fe4f9910d36e1f03decbbaa2a8105b37ff Mon Sep 17 00:00:00 2001 From: Vincent Gariepy Date: Sun, 30 Mar 2014 19:07:59 -0400 Subject: [PATCH 5/6] server info in credits and a few more ncurses changes --- eth/main.cpp | 67 +++++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/eth/main.cpp b/eth/main.cpp index b2a41f2cb..9db48ef9d 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -93,13 +93,29 @@ void interactiveHelp() << " exit Exits the application." << endl; } -string credits() +string credits(bool interactive = false) { std::ostringstream ccout; ccout << "Ethereum (++) " << ETH_QUOTED(ETH_VERSION) << endl << " Code by Gav Wood, (c) 2013, 2014." << endl << " Based on a design by Vitalik Buterin." << endl << endl; + + if (interactive) + { + string vs = toString(ETH_QUOTED(ETH_VERSION)); + vs = vs.substr(vs.find_first_of('.') + 1)[0]; + int pocnumber = stoi(vs); + string m_servers; + if (pocnumber == 3) + m_servers = "54.201.28.117"; + if (pocnumber == 4) + m_servers = "54.72.31.55"; + + ccout << "Type 'netstart 30303' to start networking" << endl; + ccout << "Type 'connect " << m_servers << " 30303' to connect" << endl; + ccout << "Type 'exit' to quit" << endl << endl; + } return ccout.str(); } @@ -400,21 +416,6 @@ int main(int argc, char** argv) wsetscrreg(peerswin, 1, vl); wsetscrreg(contractswin, 1, vl); - ccout << credits(); - - string vs = toString(ETH_QUOTED(ETH_VERSION)); - vs = vs.substr(vs.find_first_of('.') + 1)[0]; - int pocnumber = stoi(vs); - string m_servers; - if (pocnumber == 3) - m_servers = "54.201.28.117"; - if (pocnumber == 4) - m_servers = "54.72.31.55"; - - ccout << "Type 'netstart 30303' to start networking" << endl; - ccout << "Type 'connect " << m_servers << " 30303' to connect" << endl; - ccout << "Type 'exit' to quit" << endl; - mvwprintw(mainwin, 1, x, "> "); wresize(mainwin, 3, width); mvwin(mainwin, height - 3, 0); @@ -431,6 +432,8 @@ int main(int argc, char** argv) wclrtobot(peerswin); wclrtobot(contractswin); + ccout << credits(true); + // Prompt wmove(mainwin, 1, 4); getstr(str); @@ -439,6 +442,11 @@ int main(int argc, char** argv) istringstream iss(s); iss >> cmd; + // Address + ccout << "Address:" << endl; + chr = toHex(us.address().asArray()).c_str(); + ccout << chr << endl << endl; + mvwprintw(mainwin, 1, x, "> "); clrtoeol(); @@ -482,7 +490,7 @@ int main(int argc, char** argv) else if (cmd == "block") { eth::uint n = c.blockChain().details().number; - ccout << "Current block #:" << endl; + ccout << "Current block # "; const char* addchr = toString(n).c_str(); ccout << addchr << endl; } @@ -662,20 +670,19 @@ int main(int argc, char** argv) break; } - // Address - ccout << "Address:" << endl; - chr = toHex(us.address().asArray()).c_str(); - ccout << chr << endl << endl; - - box(mainwin, 0, 0); + box(consolewin, 0, 0); box(blockswin, 0, 0); box(pendingwin, 0, 0); box(peerswin, 0, 0); - box(consolewin, 0, 0); box(contractswin, 0, 0); + box(mainwin, 0, 0); - mvwprintw(pendingwin, 0, x, "Pending"); - mvwprintw(contractswin, 0, x, "Contracts"); + // Balance + mvwprintw(consolewin, 0, x, "Balance: "); + u256 balance = c.state().balance(us.address()); + chr = toString(balance).c_str(); + mvwprintw(consolewin, 0, 11, chr); + wmove(consolewin, 1, x); // Block mvwprintw(blockswin, 0, x, "Block # "); @@ -683,12 +690,8 @@ int main(int argc, char** argv) chr = toString(n).c_str(); mvwprintw(blockswin, 0, 10, chr); - // Balance - mvwprintw(consolewin, 0, x, "Balance: "); - u256 balance = c.state().balance(us.address()); - chr = toString(balance).c_str(); - mvwprintw(consolewin, 0, 11, chr); - wmove(consolewin, 1, x); + mvwprintw(pendingwin, 0, x, "Pending"); + mvwprintw(contractswin, 0, x, "Contracts"); // Peers mvwprintw(peerswin, 0, x, "Peers: "); From e12a3d6de374596635b7013d6b919b5511fa9437 Mon Sep 17 00:00:00 2001 From: Vincent Gariepy Date: Sun, 30 Mar 2014 19:27:45 -0400 Subject: [PATCH 6/6] prefix arguments with underscores --- eth/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eth/main.cpp b/eth/main.cpp index 9db48ef9d..d756f0353 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -93,7 +93,7 @@ void interactiveHelp() << " exit Exits the application." << endl; } -string credits(bool interactive = false) +string credits(bool _interactive = false) { std::ostringstream ccout; ccout @@ -101,7 +101,7 @@ string credits(bool interactive = false) << " Code by Gav Wood, (c) 2013, 2014." << endl << " Based on a design by Vitalik Buterin." << endl << endl; - if (interactive) + if (_interactive) { string vs = toString(ETH_QUOTED(ETH_VERSION)); vs = vs.substr(vs.find_first_of('.') + 1)[0];