From c12388c5b5d54f6b8221c1e086e916426bb331c4 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Fri, 5 Apr 2019 18:59:41 +0300 Subject: [PATCH] Reuse "generate" --- src/rpc/rpcevo.cpp | 50 ++++++++++------------------------------------ 1 file changed, 10 insertions(+), 40 deletions(-) diff --git a/src/rpc/rpcevo.cpp b/src/rpc/rpcevo.cpp index a4d50fc964..5da2aba763 100644 --- a/src/rpc/rpcevo.cpp +++ b/src/rpc/rpcevo.cpp @@ -1141,8 +1141,10 @@ UniValue protx(const JSONRPCRequest& request) void bls_generate_help() { throw std::runtime_error( - "bls generate\n" - "\nReturns a BLS secret/public key pair.\n" + "bls generate ( \"secret\" )\n" + "\nCreate a new BLS secret/public key pair or restore one from a provided BLS secret key.\n" + "\nArguments:\n" + "1. \"secret\" (string, optional) The BLS secret key.\n" "\nResult:\n" "{\n" " \"secret\": \"xxxx\", (string) BLS secret key\n" @@ -1150,49 +1152,20 @@ void bls_generate_help() "}\n" "\nExamples:\n" + HelpExampleCli("bls generate", "") + + HelpExampleCli("bls generate", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f") ); } UniValue bls_generate(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 1) { + if (request.fHelp || (request.params.size() != 1 && request.params.size() != 2)) { bls_generate_help(); } CBLSSecretKey sk; - sk.MakeNewKey(); - - UniValue ret(UniValue::VOBJ); - ret.push_back(Pair("secret", sk.ToString())); - ret.push_back(Pair("public", sk.GetPublicKey().ToString())); - return ret; -} - -void bls_sk2pk_help() -{ - throw std::runtime_error( - "bls sk2pk \"secret\"\n" - "\nParses a BLS secret key and returns the secret/public key pair.\n" - "\nArguments:\n" - "1. \"secret\" (string, required) The BLS secret key\n" - "\nResult:\n" - "{\n" - " \"secret\": \"xxxx\", (string) BLS secret key\n" - " \"public\": \"xxxx\", (string) BLS public key\n" - "}\n" - "\nExamples:\n" - + HelpExampleCli("bls sk2pk", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f") - ); -} - -UniValue bls_sk2pk(const JSONRPCRequest& request) -{ - if (request.fHelp || request.params.size() != 2) { - bls_sk2pk_help(); - } - - CBLSSecretKey sk; - if (!sk.SetHexStr(request.params[1].get_str())) { + if (request.params.size() == 1) { + sk.MakeNewKey(); + } else if (!sk.SetHexStr(request.params[1].get_str())) { throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Secret key must be a valid hex string of length %d", sk.SerSize*2)); } @@ -1211,8 +1184,7 @@ UniValue bls_sk2pk(const JSONRPCRequest& request) "\nArguments:\n" "1. \"command\" (string, required) The command to execute\n" "\nAvailable commands:\n" - " generate - Create a BLS secret/public key pair\n" - " sk2pk - Parse a BLS secret key and return the secret/public key pair\n" + " generate - Create a new BLS secret/public key pair or restore one from a provided BLS secret key\n" ); } @@ -1229,8 +1201,6 @@ UniValue _bls(const JSONRPCRequest& request) if (command == "generate") { return bls_generate(request); - } else if (command == "sk2pk") { - return bls_sk2pk(request); } else { bls_help(); }