Merge branch 'passwords'

This commit is contained in:
Arthur Britto
2012-05-02 17:38:44 -07:00
5 changed files with 67 additions and 122 deletions

View File

@@ -46,27 +46,20 @@ std::string EncodeBase64(const std::string& s)
return result; return result;
} }
int commandLineRPC(int argc, char *argv[]) int commandLineRPC(const std::vector<std::string>& vCmd)
{ {
std::string strPrint; std::string strPrint;
int nRet = 0; int nRet = 0;
try try
{ {
// Skip switches if (vCmd.size() < 2) return 1;
while ((argc > 1) && isSwitchChar(argv[1][0]))
{
argc--;
argv++;
}
if (argc < 2) return 0; std::string strMethod = vCmd[0];
std::string strMethod = argv[1];
// Parameters default to strings // Parameters default to strings
Json::Value params(Json::arrayValue); Json::Value params(Json::arrayValue);
for (int i = 2; i < argc; i++) for (int i = 1; i != vCmd.size(); i++)
params.append(argv[i]); params.append(vCmd[i]);
// Execute // Execute
Json::Value reply = callRPC(strMethod, params); Json::Value reply = callRPC(strMethod, params);

View File

@@ -3,5 +3,5 @@
#include "../json/value.h" #include "../json/value.h"
extern int commandLineRPC(int argc, char *argv[]); extern int commandLineRPC(const std::vector<std::string>& vCmd);
extern Json::Value callRPC(const std::string& strMethod, const Json::Value& params); extern Json::Value callRPC(const std::string& strMethod, const Json::Value& params);

View File

@@ -28,67 +28,6 @@ void NewcoinAddress::clear()
vchData.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 // NodePublic
// //
@@ -99,9 +38,6 @@ const std::vector<unsigned char>& NewcoinAddress::getNodePublic() const
case VER_NONE: case VER_NONE:
throw std::runtime_error("unset source"); throw std::runtime_error("unset source");
case VER_HANKO:
throw std::runtime_error("public not available from hanko");
case VER_NODE_PUBLIC: case VER_NODE_PUBLIC:
return vchData; return vchData;
@@ -116,9 +52,6 @@ std::string NewcoinAddress::humanNodePublic() const
case VER_NONE: case VER_NONE:
throw std::runtime_error("unset source"); throw std::runtime_error("unset source");
case VER_HANKO:
throw std::runtime_error("public not available from hanko");
case VER_NODE_PUBLIC: case VER_NODE_PUBLIC:
return ToString(); return ToString();

View File

@@ -12,7 +12,6 @@ class NewcoinAddress : public CBase58Data
private: private:
typedef enum { typedef enum {
VER_NONE = 1, VER_NONE = 1,
VER_HANKO = 8,
VER_NODE_PUBLIC = 28, VER_NODE_PUBLIC = 28,
VER_NODE_PRIVATE = 32, VER_NODE_PRIVATE = 32,
VER_ACCOUNT_ID = 0, VER_ACCOUNT_ID = 0,
@@ -29,18 +28,7 @@ public:
bool isValid() const; bool isValid() const;
void clear(); 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 // Node Public
// //

View File

@@ -1,34 +1,31 @@
#include "Application.h" #include "Application.h"
#include "CallRPC.h"
#include "Config.h"
#include "utils.h"
#include <iostream> #include <iostream>
#include "CallRPC.h" #include <boost/program_options.hpp>
#include "Config.h" namespace po = boost::program_options;
extern void runTests();
extern bool AddSystemEntropy(); extern bool AddSystemEntropy();
using namespace std; using namespace std;
using namespace boost; using namespace boost;
/* void startServer()
Detect if another is running
If so message it with the users command
*/
void startApp()
{ {
theApp = new Application(); 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] <command> <params>" << endl; cout << "newcoin [options] <command> <params>" << endl;
cout << "options: " << endl;
cout << " -" << endl; cout << desc << endl;
cout << "commands: " << endl;
cout << "Commands: " << endl;
cout << " accountinfo <family>:<key>" << endl; cout << " accountinfo <family>:<key>" << endl;
cout << " connect <ip> [<port>]" << endl; cout << " connect <ip> [<port>]" << endl;
cout << " createfamily [<key>]" << endl; cout << " createfamily [<key>]" << endl;
@@ -48,35 +45,69 @@ void printHelp()
cout << " validation_create [<seed>|<pass_phrase>|<key>]" << endl; cout << " validation_create [<seed>|<pass_phrase>|<key>]" << 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<string> >(), "Specify a comma seperated RPC command.")
;
po::positional_options_description p;
p.add("command", -1);
//
// Prepare to run
//
theConfig.load(); theConfig.load();
if (!AddSystemEntropy()) if (!AddSystemEntropy())
{ {
#ifdef DEBUG
std::cerr << "Unable to add system entropy" << std::endl; 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); po::store(po::command_line_parser(argc, argv)
if(ret) .options(desc) // Parse options.
printHelp(); .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<std::string> vCmd = vm["command"].as<std::vector<std::string> >();
iResult = commandLineRPC(vCmd);
}
int main(int argc, char* argv[]) if (1 == iResult)
{ printHelp(desc);
// runTests();
return(parseCommandline(argc, argv)); return iResult;
} }
// vim:ts=4 // vim:ts=4