diff --git a/src/DBInit.cpp b/src/DBInit.cpp index 48be4d9c2d..3bc64d4f9e 100644 --- a/src/DBInit.cpp +++ b/src/DBInit.cpp @@ -60,7 +60,7 @@ const char *WalletDBInit[] = { "CREATE TABLE NodeIdentity ( \ PublicKey CHARACTER(53), \ PrivateKey CHARACTER(52) \ - );" + );", "CREATE TABLE TrustedNodes ( \ Hanko CHARACTER(35) PRIMARY KEY, \ PublicKey CHARACTER(53), \ diff --git a/src/RPCServer.cpp b/src/RPCServer.cpp index b82cdee14f..74c87584d1 100644 --- a/src/RPCServer.cpp +++ b/src/RPCServer.cpp @@ -67,7 +67,7 @@ void RPCServer::handle_read(const boost::system::error_code& e, } else if(e != boost::asio::error::operation_aborted) { - + } } @@ -75,7 +75,7 @@ std::string RPCServer::handleRequest(const std::string& requestStr) { std::cout << "handleRequest " << requestStr << std::endl; Json::Value id; - + // Parse request Json::Value valRequest; Json::Reader reader; @@ -497,21 +497,21 @@ Json::Value RPCServer::doLedger(Json::Value& params) return "not implemented"; } +// unl_add +// unl_add Json::Value RPCServer::doUnlAdd(Json::Value& params) { - // unl_add - // unl_add if(params.size()==1 || params.size()==2) { - std::string pubKey=params[0u].asString(); - std::string comment=params.size() == 2 + std::string strNodePublic=params[0u].asString(); + std::string strComment=params.size() == 2 ? "" : params[1u].asString(); NewcoinAddress nodePublic; - if(nodePublic.setNodePublic(pubKey)) + if(nodePublic.setNodePublic(strNodePublic)) { - theApp->getUNL().addNode(nodePublic, comment); + theApp->getUNL().addNode(nodePublic, strComment); return "adding node"; } @@ -527,8 +527,26 @@ Json::Value RPCServer::doUnlDefault(Json::Value& params) { return "not implemented"; } +// unl_delete Json::Value RPCServer::doUnlDelete(Json::Value& params) { - return "not implemented"; + if(params.size()==1) + { + std::string strHanko=params[0u].asString(); + + NewcoinAddress hanko; + + if(hanko.setHanko(strHanko)) + { + theApp->getUNL().removeNode(hanko); + + return "removing node"; + } + else + { + return "invalid hanko"; + } + } + else return "invalid params"; } Json::Value RPCServer::doUnlFetch(Json::Value& params) { @@ -539,8 +557,14 @@ Json::Value RPCServer::doUnlList(Json::Value& params) { return theApp->getUNL().getUnlJson(); } +// unl_reset Json::Value RPCServer::doUnlReset(Json::Value& params) { - return "not implemented"; + if(!params.size()) + { + theApp->getUNL().reset(); + return "removing nodes"; + } + else return "invalid params"; } Json::Value RPCServer::doCommand(const std::string& command, Json::Value& params) diff --git a/src/UniqueNodeList.cpp b/src/UniqueNodeList.cpp index 7779fe522f..2c4457322c 100644 --- a/src/UniqueNodeList.cpp +++ b/src/UniqueNodeList.cpp @@ -40,6 +40,15 @@ void UniqueNodeList::removeNode(NewcoinAddress hanko) db->executeSQL(strSql.c_str()); } +void UniqueNodeList::reset() +{ + Database* db=theApp->getWalletDB()->getDB(); + + std::string strSql = "DELETE FROM TrustedNodes"; + ScopedLock sl(theApp->getWalletDB()->getDBLock()); + db->executeSQL(strSql.c_str()); +} + // 0- we don't care, 1- we care and is valid, 2-invalid signature #if 0 int UniqueNodeList::checkValid(newcoin::Validation& valid) diff --git a/src/UniqueNodeList.h b/src/UniqueNodeList.h index d43f58133f..88b0f0afa8 100644 --- a/src/UniqueNodeList.h +++ b/src/UniqueNodeList.h @@ -11,11 +11,9 @@ class UniqueNodeList // hanko to public key //std::map mUNL; public: - //void load(); - //void save(); - void addNode(NewcoinAddress nodePublic, std::string strComment); void removeNode(NewcoinAddress hanko); + void reset(); // 0- we don't care, 1- we care and is valid, 2-invalid signature // int checkValid(newcoin::Validation& valid); diff --git a/src/main.cpp b/src/main.cpp index cb859f911d..d3e019afd7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,19 +25,22 @@ void printHelp() cout << "options: " << endl; cout << " -" << endl; cout << "commands: " << endl; - cout << " createfamily []" << endl; cout << " accountinfo :" << endl; - cout << " newaccount []" << endl; - cout << " lock " << endl; - cout << " unlock " << endl; - cout << " familyinfo" << endl; cout << " connect []" << endl; + cout << " createfamily []" << endl; + cout << " familyinfo" << endl; + cout << " ledger" << endl; + cout << " lock " << endl; + cout << " newaccount []" << endl; cout << " peers" << endl; cout << " sendto []" << endl; - cout << " tx" << endl; - cout << " ledger" << endl; cout << " stop" << endl; - + cout << " tx" << endl; + cout << " unl_add []" << endl; + cout << " unl_delete " << endl; + cout << " unl_list" << endl; + cout << " unl_reset" << endl; + cout << " unlock " << endl; } int parseCommandline(int argc, char* argv[])