From f775bfd856390f7161ad98371f503d91d326d15b Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Tue, 1 May 2012 15:18:23 -0700 Subject: [PATCH 1/2] Remove obsolete hanko support from NewcoinAddress. --- src/NewcoinAddress.cpp | 67 ------------------------------------------ src/NewcoinAddress.h | 12 -------- 2 files changed, 79 deletions(-) diff --git a/src/NewcoinAddress.cpp b/src/NewcoinAddress.cpp index 47b064baf..e07a7d334 100644 --- a/src/NewcoinAddress.cpp +++ b/src/NewcoinAddress.cpp @@ -28,67 +28,6 @@ void NewcoinAddress::clear() vchData.clear(); } -#if 0 -// -// Hanko - OBSOLETE -// - -uint160 NewcoinAddress::getHanko() const -{ - switch (nVersion) { - case VER_NONE: - throw std::runtime_error("unset source"); - - case VER_HANKO: - return uint160(vchData); - - case VER_NODE_PUBLIC: - // Note, we are encoding the left or right. - return Hash160(vchData); - - default: - throw std::runtime_error(str(boost::format("bad source: %d") % int(nVersion))); - } -} - -std::string NewcoinAddress::humanHanko() const -{ - switch (nVersion) { - case VER_NONE: - throw std::runtime_error("unset source"); - - case VER_HANKO: - return ToString(); - - case VER_NODE_PUBLIC: - { - NewcoinAddress hanko; - - (void) hanko.setHanko(getHanko()); - - return hanko.ToString(); - } - - default: - throw std::runtime_error(str(boost::format("bad source: %d") % int(nVersion))); - } -} - -bool NewcoinAddress::setHanko(const std::string& strHanko) -{ - return SetString(strHanko.c_str(), VER_HANKO); -} - -void NewcoinAddress::setHanko(const uint160& hash160) -{ - SetData(VER_HANKO, hash160.begin(), 20); -} - -void NewcoinAddress::setHanko(const NewcoinAddress& nodePublic) { - setHanko(nodePublic.getHanko()); -} -#endif - // // NodePublic // @@ -99,9 +38,6 @@ const std::vector& NewcoinAddress::getNodePublic() const case VER_NONE: throw std::runtime_error("unset source"); - case VER_HANKO: - throw std::runtime_error("public not available from hanko"); - case VER_NODE_PUBLIC: return vchData; @@ -116,9 +52,6 @@ std::string NewcoinAddress::humanNodePublic() const case VER_NONE: throw std::runtime_error("unset source"); - case VER_HANKO: - throw std::runtime_error("public not available from hanko"); - case VER_NODE_PUBLIC: return ToString(); diff --git a/src/NewcoinAddress.h b/src/NewcoinAddress.h index e07d510f6..3621c19ef 100644 --- a/src/NewcoinAddress.h +++ b/src/NewcoinAddress.h @@ -12,7 +12,6 @@ class NewcoinAddress : public CBase58Data private: typedef enum { VER_NONE = 1, - VER_HANKO = 8, VER_NODE_PUBLIC = 28, VER_NODE_PRIVATE = 32, VER_ACCOUNT_ID = 0, @@ -29,18 +28,7 @@ public: bool isValid() const; void clear(); -#if 0 - // - // hanko - OBSOLETE - // - uint160 getHanko() const; - std::string humanHanko() const; - - bool setHanko(const std::string& strHanko); - void setHanko(const uint160& hash160); - void setHanko(const NewcoinAddress& nodePublic); -#endif // // Node Public // From c6f6914dab7ef08cf0e4e9404115a13a1b4ec45e Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Wed, 2 May 2012 17:35:28 -0700 Subject: [PATCH 2/2] Add support for boost command line options in prep for unit tests. --- src/CallRPC.cpp | 17 +++------ src/CallRPC.h | 2 +- src/main.cpp | 91 +++++++++++++++++++++++++++++++++---------------- 3 files changed, 67 insertions(+), 43 deletions(-) diff --git a/src/CallRPC.cpp b/src/CallRPC.cpp index 99dabf2fa..678772730 100644 --- a/src/CallRPC.cpp +++ b/src/CallRPC.cpp @@ -46,27 +46,20 @@ std::string EncodeBase64(const std::string& s) return result; } -int commandLineRPC(int argc, char *argv[]) +int commandLineRPC(const std::vector& vCmd) { std::string strPrint; int nRet = 0; try { - // Skip switches - while ((argc > 1) && isSwitchChar(argv[1][0])) - { - argc--; - argv++; - } + if (vCmd.size() < 2) return 1; - if (argc < 2) return 0; - - std::string strMethod = argv[1]; + std::string strMethod = vCmd[0]; // Parameters default to strings Json::Value params(Json::arrayValue); - for (int i = 2; i < argc; i++) - params.append(argv[i]); + for (int i = 1; i != vCmd.size(); i++) + params.append(vCmd[i]); // Execute Json::Value reply = callRPC(strMethod, params); diff --git a/src/CallRPC.h b/src/CallRPC.h index 03b90511b..ac6fc3dae 100644 --- a/src/CallRPC.h +++ b/src/CallRPC.h @@ -3,5 +3,5 @@ #include "../json/value.h" -extern int commandLineRPC(int argc, char *argv[]); +extern int commandLineRPC(const std::vector& vCmd); extern Json::Value callRPC(const std::string& strMethod, const Json::Value& params); diff --git a/src/main.cpp b/src/main.cpp index 9f5b84fdf..c8dceb02d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,34 +1,31 @@ #include "Application.h" +#include "CallRPC.h" +#include "Config.h" +#include "utils.h" #include -#include "CallRPC.h" -#include "Config.h" +#include +namespace po = boost::program_options; -extern void runTests(); extern bool AddSystemEntropy(); using namespace std; using namespace boost; -/* - Detect if another is running - If so message it with the users command -*/ - - -void startApp() +void startServer() { theApp = new Application(); - theApp->run(); // blocks till we get a stop RPC + theApp->run(); // Blocks till we get a stop RPC. } -void printHelp() +void printHelp(const po::options_description& desc) { cout << "newcoin [options] " << endl; - cout << "options: " << endl; - cout << " -" << endl; - cout << "commands: " << endl; + + cout << desc << endl; + + cout << "Commands: " << endl; cout << " accountinfo :" << endl; cout << " connect []" << endl; cout << " createfamily []" << endl; @@ -48,35 +45,69 @@ void printHelp() cout << " validation_create [||]" << endl; } -int parseCommandline(int argc, char* argv[]) +int main(int argc, char* argv[]) { - int ret=0; + int iResult = 0; + po::variables_map vm; // Map of options. + // + // Set up option parsing. + // + po::options_description desc("Options"); + desc.add_options() + ("help,h", "Display this message.") + ("command", po::value< vector >(), "Specify a comma seperated RPC command.") + ; + + po::positional_options_description p; + p.add("command", -1); + + // + // Prepare to run + // theConfig.load(); if (!AddSystemEntropy()) { -#ifdef DEBUG std::cerr << "Unable to add system entropy" << std::endl; -#endif + iResult = 2; } - if(argc>1) + // Parse options, if no error. + if (!iResult) { - ret = commandLineRPC(argc, argv); - if(ret) - printHelp(); + po::store(po::command_line_parser(argc, argv) + .options(desc) // Parse options. + .positional(p) // Remainder as --command. + .run(), + vm); + po::notify(vm); // Invoke option notify functions. } - else startApp(); - return ret; -} + if (iResult) + { + nothing(); + } + else if (vm.count("help")) + { + iResult = 1; + } + else if (!vm.count("command")) + { + // No arguments. Run server. + startServer(); + } + else + { + // Have a RPC command. + std::vector vCmd = vm["command"].as >(); + iResult = commandLineRPC(vCmd); + } -int main(int argc, char* argv[]) -{ -// runTests(); + if (1 == iResult) + printHelp(desc); - return(parseCommandline(argc, argv)); + return iResult; } // vim:ts=4