Add validation_create command to RPCServer.

This commit is contained in:
Arthur Britto
2012-04-07 16:15:14 -07:00
parent b8f1df2a18
commit 77ffbe7759
2 changed files with 59 additions and 0 deletions

View File

@@ -531,6 +531,61 @@ Json::Value RPCServer::doUnlAdd(Json::Value& params) {
else return "invalid params"; else return "invalid params";
} }
// validation_create
// validation_create <pass_phrase>
// validation_create <seed>
// validation_create <seed_key>
Json::Value RPCServer::doValidatorCreate(Json::Value& params) {
NewcoinAddress familySeed;
NewcoinAddress familyGenerator;
NewcoinAddress nodePublicKey;
NewcoinAddress nodePrivateKey;
if(params.empty())
{
std::cerr << "Creating random validation seed." << std::endl;
familySeed.setFamilySeedRandom(); // Get a random seed.
}
else if (1 == params.size())
{
if (familySeed.setFamilySeed(params[0u].asString()))
{
std::cerr << "Recognized validation seed." << std::endl;
}
else if (1 == familySeed.setFamilySeed1751(params[0u].asString()))
{
std::cerr << "Recognized 1751 validation seed." << std::endl;
}
else
{
std::cerr << "Creating validation seed from pass phrase." << std::endl;
familySeed.setFamilySeed(CKey::PassPhraseToKey(params[0u].asString()));
}
}
else return "invalid params";
// Derive generator from seed.
familyGenerator.setFamilyGenerator(familySeed);
// The node public and private is 0th of the sequence.
nodePublicKey.setNodePublic(CKey(familyGenerator, 0).GetPubKey());
nodePrivateKey.setNodePrivate(CKey(familyGenerator, familySeed.getFamilyPrivateKey(), 0).GetSecret());
// Paranoia
assert(1 == familySeed.setFamilySeed1751(familySeed.humanFamilySeed1751()));
Json::Value obj(Json::objectValue);
obj["validation_public_key"] = nodePublicKey.humanNodePublic().c_str();
obj["validation_seed"] = familySeed.humanFamilySeed().c_str();
obj["validation_key"] = familySeed.humanFamilySeed1751().c_str();
return obj;
}
void RPCServer::validatorsResponse(const boost::system::error_code& err, std::string strResponse) void RPCServer::validatorsResponse(const boost::system::error_code& err, std::string strResponse)
{ {
std::cerr << "Fetch '" VALIDATORS_FILE_NAME "' complete." << std::endl; std::cerr << "Fetch '" VALIDATORS_FILE_NAME "' complete." << std::endl;
@@ -666,6 +721,8 @@ Json::Value RPCServer::doCommand(const std::string& command, Json::Value& params
if(command=="unl_list") return doUnlList(params); if(command=="unl_list") return doUnlList(params);
if(command=="unl_reset") return doUnlReset(params); if(command=="unl_reset") return doUnlReset(params);
if(command=="validation_create") return doValidatorCreate(params);
if(command=="createfamily") return doCreateFamily(params); if(command=="createfamily") return doCreateFamily(params);
if(command=="familyinfo") return doFamilyInfo(params); if(command=="familyinfo") return doFamilyInfo(params);
if(command=="accountinfo") return doAccountInfo(params); if(command=="accountinfo") return doAccountInfo(params);

View File

@@ -53,6 +53,8 @@ class RPCServer : public boost::enable_shared_from_this<RPCServer>
Json::Value doUnlList(Json::Value& params); Json::Value doUnlList(Json::Value& params);
Json::Value doUnlReset(Json::Value& params); Json::Value doUnlReset(Json::Value& params);
Json::Value doValidatorCreate(Json::Value& params);
// Parses a string account name into a local or remote NewcoinAddress. // Parses a string account name into a local or remote NewcoinAddress.
NewcoinAddress parseAccount(const std::string& account); NewcoinAddress parseAccount(const std::string& account);
void validatorsResponse(const boost::system::error_code& err, std::string strResponse); void validatorsResponse(const boost::system::error_code& err, std::string strResponse);