diff --git a/src/cpp/ripple/CallRPC.cpp b/src/cpp/ripple/CallRPC.cpp index 1eb4d919fa..78fc2579ca 100644 --- a/src/cpp/ripple/CallRPC.cpp +++ b/src/cpp/ripple/CallRPC.cpp @@ -495,7 +495,7 @@ Json::Value RPCParser::parseProofSolve(const Json::Value& jvParams) return jvRequest; } -// proof_verify +// proof_verify [] [] Json::Value RPCParser::parseProofVerify(const Json::Value& jvParams) { Json::Value jvRequest; @@ -503,6 +503,12 @@ Json::Value RPCParser::parseProofVerify(const Json::Value& jvParams) jvRequest["token"] = jvParams[0u].asString(); jvRequest["solution"] = jvParams[1u].asString(); + if (jvParams.size() >= 3) + jvRequest["difficulty"] = jvParams[2u].asInt(); + + if (jvParams.size() >= 4) + jvRequest["secret"] = jvParams[3u].asString(); + return jvRequest; } @@ -735,7 +741,7 @@ Json::Value RPCParser::parseCommand(std::string strMethod, Json::Value jvParams) // { "profile", &RPCParser::parseProfile, 1, 9 }, { "proof_create", &RPCParser::parseProofCreate, 0, 2 }, { "proof_solve", &RPCParser::parseProofSolve, 1, 1 }, - { "proof_verify", &RPCParser::parseProofVerify, 2, 2 }, + { "proof_verify", &RPCParser::parseProofVerify, 2, 4 }, { "random", &RPCParser::parseAsIs, 0, 0 }, { "ripple_path_find", &RPCParser::parseRipplePathFind, 1, 2 }, { "sign", &RPCParser::parseSignSubmit, 2, 2 }, diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index 078e219652..02af628873 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -948,10 +948,13 @@ Json::Value RPCHandler::doProofSolve(Json::Value jvRequest, int& cost, ScopedLoc // { // token: // solution: +// // if either of these parameters is set, a custom verifier is used +// difficulty: // optional +// secret: // optional // } Json::Value RPCHandler::doProofVerify(Json::Value jvRequest, int& cost, ScopedLock& MasterLockHolder) { - // XXX Add ability to check proof against arbitrary secret & time + // XXX Add ability to check proof against arbitrary time Json::Value jvResult; @@ -964,8 +967,39 @@ Json::Value RPCHandler::doProofVerify(Json::Value jvRequest, int& cost, ScopedLo std::string strToken = jvRequest["token"].asString(); uint256 uSolution(jvRequest["solution"].asString()); - // XXX Proof should not be marked as used from this - POWResult prResult = theApp->getPowGen().checkProof(strToken, uSolution); + POWResult prResult; + if (jvRequest.isMember("difficulty") || jvRequest.isMember("secret")) + { + ProofOfWorkGenerator pgGen; + + if (jvRequest.isMember("difficulty")) + { + if (!jvRequest["difficulty"].isIntegral()) + return rpcError(rpcINVALID_PARAMS); + + int iDifficulty = jvRequest["difficulty"].asInt(); + + if (iDifficulty < 0 || iDifficulty > ProofOfWork::sMaxDifficulty) + return rpcError(rpcINVALID_PARAMS); + + pgGen.setDifficulty(iDifficulty); + } + + if (jvRequest.isMember("secret")) + { + uint256 uSecret(jvRequest["secret"].asString()); + pgGen.setSecret(uSecret); + } + + prResult = pgGen.checkProof(strToken, uSolution); + + jvResult["secret"] = pgGen.getSecret().GetHex(); + } + else + { + // XXX Proof should not be marked as used from this + prResult = theApp->getPowGen().checkProof(strToken, uSolution); + } std::string sToken; std::string sHuman;