mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-22 03:55:53 +00:00
RPC: Add proof_verify.
This commit is contained in:
@@ -482,6 +482,17 @@ Json::Value RPCParser::parseProofCreate(const Json::Value& jvParams)
|
||||
return jvRequest;
|
||||
}
|
||||
|
||||
// proof_verify <token> <solution>
|
||||
Json::Value RPCParser::parseProofVerify(const Json::Value& jvParams)
|
||||
{
|
||||
Json::Value jvRequest;
|
||||
|
||||
jvRequest["token"] = jvParams[0u].asString();
|
||||
jvRequest["solution"] = jvParams[1u].asString();
|
||||
|
||||
return jvRequest;
|
||||
}
|
||||
|
||||
// ripple_path_find <json> [<ledger>]
|
||||
Json::Value RPCParser::parseRipplePathFind(const Json::Value& jvParams)
|
||||
{
|
||||
@@ -710,6 +721,7 @@ Json::Value RPCParser::parseCommand(std::string strMethod, Json::Value jvParams)
|
||||
{ "ping", &RPCParser::parseAsIs, 0, 0 },
|
||||
// { "profile", &RPCParser::parseProfile, 1, 9 },
|
||||
{ "proof_create", &RPCParser::parseProofCreate, 0, 1 },
|
||||
{ "proof_verify", &RPCParser::parseProofVerify, 2, 2 },
|
||||
{ "random", &RPCParser::parseAsIs, 0, 0 },
|
||||
{ "ripple_path_find", &RPCParser::parseRipplePathFind, 1, 2 },
|
||||
{ "sign", &RPCParser::parseSignSubmit, 2, 2 },
|
||||
|
||||
@@ -35,6 +35,7 @@ protected:
|
||||
Json::Value parseLogLevel(const Json::Value& jvParams);
|
||||
Json::Value parseOwnerInfo(const Json::Value& jvParams);
|
||||
Json::Value parseProofCreate(const Json::Value& jvParams);
|
||||
Json::Value parseProofVerify(const Json::Value& jvParams);
|
||||
Json::Value parseRandom(const Json::Value& jvParams);
|
||||
Json::Value parseRipplePathFind(const Json::Value& jvParams);
|
||||
Json::Value parseSMS(const Json::Value& jvParams);
|
||||
|
||||
@@ -13,6 +13,37 @@
|
||||
|
||||
SETUP_LOG();
|
||||
|
||||
|
||||
bool powResultInfo(POWResult powCode, std::string& strToken, std::string& strHuman)
|
||||
{
|
||||
static struct {
|
||||
POWResult powCode;
|
||||
const char* cpToken;
|
||||
const char* cpHuman;
|
||||
} powResultInfoA[] = {
|
||||
{ powREUSED, "powREUSED", "Proof-of-work has already been used." },
|
||||
{ powBADNONCE, "powBADNONCE", "The solution does not meet the required difficulty." },
|
||||
{ powEXPIRED, "powEXPIRED", "Token is expired." },
|
||||
{ powCORRUPT, "powCORRUPT", "Invalid token." },
|
||||
{ powTOOEASY, "powTOOEASY", "Difficulty has increased since token was issued." },
|
||||
|
||||
{ powOK, "powOK", "Valid proof-of-work." },
|
||||
};
|
||||
|
||||
int iIndex = NUMBER(powResultInfoA);
|
||||
|
||||
while (iIndex-- && powResultInfoA[iIndex].powCode != powCode)
|
||||
;
|
||||
|
||||
if (iIndex >= 0)
|
||||
{
|
||||
strToken = powResultInfoA[iIndex].cpToken;
|
||||
strHuman = powResultInfoA[iIndex].cpHuman;
|
||||
}
|
||||
|
||||
return iIndex >= 0;
|
||||
}
|
||||
|
||||
const uint256 ProofOfWork::sMinTarget("00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
|
||||
const int ProofOfWork::sMaxIterations(1 << 23);
|
||||
const int ProofOfWork::sMaxDifficulty(30);
|
||||
|
||||
@@ -20,6 +20,7 @@ enum POWResult
|
||||
powTOOEASY = 5, // the difficulty increased too much while you solved it
|
||||
};
|
||||
|
||||
bool powResultInfo(POWResult powCode, std::string& strToken, std::string& strHuman);
|
||||
|
||||
class ProofOfWork
|
||||
{
|
||||
|
||||
@@ -910,6 +910,41 @@ Json::Value RPCHandler::doProofCreate(Json::Value jvRequest, int& cost, ScopedLo
|
||||
return jvResult;
|
||||
}
|
||||
|
||||
|
||||
// {
|
||||
// token: <token>
|
||||
// solution: <solution>
|
||||
// }
|
||||
Json::Value RPCHandler::doProofVerify(Json::Value jvRequest, int& cost, ScopedLock& MasterLockHolder)
|
||||
{
|
||||
// XXX Add ability to check proof against arbitrary secret & time
|
||||
|
||||
Json::Value jvResult;
|
||||
|
||||
if (!jvRequest.isMember("token"))
|
||||
return rpcError(rpcINVALID_PARAMS);
|
||||
|
||||
if (!jvRequest.isMember("solution"))
|
||||
return rpcError(rpcINVALID_PARAMS);
|
||||
|
||||
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);
|
||||
|
||||
std::string sToken;
|
||||
std::string sHuman;
|
||||
|
||||
powResultInfo(prResult, sToken, sHuman);
|
||||
|
||||
jvResult["proof_result"] = sToken;
|
||||
jvResult["proof_result_code"] = prResult;
|
||||
jvResult["proof_result_message"] = sHuman;
|
||||
|
||||
return jvResult;
|
||||
}
|
||||
|
||||
// {
|
||||
// account: <account>|<nickname>|<account_public_key>
|
||||
// account_index: <number> // optional, defaults to 0.
|
||||
@@ -3377,6 +3412,7 @@ Json::Value RPCHandler::doCommand(const Json::Value& jvRequest, int iRole, int &
|
||||
{ "ping", &RPCHandler::doPing, false, optNone },
|
||||
// { "profile", &RPCHandler::doProfile, false, optCurrent },
|
||||
{ "proof_create", &RPCHandler::doProofCreate, false, optNone },
|
||||
{ "proof_verify", &RPCHandler::doProofVerify, true, optNone },
|
||||
{ "random", &RPCHandler::doRandom, false, optNone },
|
||||
{ "ripple_path_find", &RPCHandler::doRipplePathFind, false, optCurrent },
|
||||
{ "sign", &RPCHandler::doSign, false, optCurrent },
|
||||
|
||||
@@ -73,6 +73,7 @@ class RPCHandler
|
||||
Json::Value doPing(Json::Value params, int& cost, ScopedLock& mlh);
|
||||
Json::Value doProfile(Json::Value params, int& cost, ScopedLock& mlh);
|
||||
Json::Value doProofCreate(Json::Value params, int& cost, ScopedLock& mlh);
|
||||
Json::Value doProofVerify(Json::Value params, int& cost, ScopedLock& mlh);
|
||||
Json::Value doRandom(Json::Value jvRequest, int& cost, ScopedLock& mlh);
|
||||
Json::Value doRipplePathFind(Json::Value jvRequest, int& cost, ScopedLock& mlh);
|
||||
Json::Value doServerInfo(Json::Value params, int& cost, ScopedLock& mlh); // for humans
|
||||
|
||||
Reference in New Issue
Block a user