mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-23 12:35:50 +00:00
RPC: Add ability to specify a custom secret in proof_create.
This commit is contained in:
@@ -471,14 +471,17 @@ Json::Value RPCParser::parseAccountRaw(const Json::Value& jvParams, bool bPeer)
|
|||||||
return jvRequest;
|
return jvRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
// proof_create [<difficulty>]
|
// proof_create [<difficulty>] [<secret>]
|
||||||
Json::Value RPCParser::parseProofCreate(const Json::Value& jvParams)
|
Json::Value RPCParser::parseProofCreate(const Json::Value& jvParams)
|
||||||
{
|
{
|
||||||
Json::Value jvRequest;
|
Json::Value jvRequest;
|
||||||
|
|
||||||
if (1 == jvParams.size())
|
if (jvParams.size() >= 1)
|
||||||
jvRequest["difficulty"] = jvParams[0u].asInt();
|
jvRequest["difficulty"] = jvParams[0u].asInt();
|
||||||
|
|
||||||
|
if (jvParams.size() >= 2)
|
||||||
|
jvRequest["secret"] = jvParams[1u].asString();
|
||||||
|
|
||||||
return jvRequest;
|
return jvRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -730,7 +733,7 @@ Json::Value RPCParser::parseCommand(std::string strMethod, Json::Value jvParams)
|
|||||||
{ "peers", &RPCParser::parseAsIs, 0, 0 },
|
{ "peers", &RPCParser::parseAsIs, 0, 0 },
|
||||||
{ "ping", &RPCParser::parseAsIs, 0, 0 },
|
{ "ping", &RPCParser::parseAsIs, 0, 0 },
|
||||||
// { "profile", &RPCParser::parseProfile, 1, 9 },
|
// { "profile", &RPCParser::parseProfile, 1, 9 },
|
||||||
{ "proof_create", &RPCParser::parseProofCreate, 0, 1 },
|
{ "proof_create", &RPCParser::parseProofCreate, 0, 2 },
|
||||||
{ "proof_solve", &RPCParser::parseProofSolve, 1, 1 },
|
{ "proof_solve", &RPCParser::parseProofSolve, 1, 1 },
|
||||||
{ "proof_verify", &RPCParser::parseProofVerify, 2, 2 },
|
{ "proof_verify", &RPCParser::parseProofVerify, 2, 2 },
|
||||||
{ "random", &RPCParser::parseAsIs, 0, 0 },
|
{ "random", &RPCParser::parseAsIs, 0, 0 },
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ public:
|
|||||||
void sweep(void);
|
void sweep(void);
|
||||||
|
|
||||||
const uint256& getSecret() const { return mSecret; }
|
const uint256& getSecret() const { return mSecret; }
|
||||||
|
void setSecret(const uint256& secret) { mSecret = secret; }
|
||||||
|
|
||||||
static int getPowEntry(const uint256& target, int iterations);
|
static int getPowEntry(const uint256& target, int iterations);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -879,15 +879,20 @@ Json::Value RPCHandler::doProfile(Json::Value jvRequest, int& cost, ScopedLock&
|
|||||||
}
|
}
|
||||||
|
|
||||||
// {
|
// {
|
||||||
// difficulty: <number> // optional, if set, a temporary generator is
|
// // if either of these parameters is set, a custom generator is used
|
||||||
// // instantiated and its secret included
|
// difficulty: <number> // optional
|
||||||
|
// secret: <secret> // optional
|
||||||
// }
|
// }
|
||||||
Json::Value RPCHandler::doProofCreate(Json::Value jvRequest, int& cost, ScopedLock& MasterLockHolder)
|
Json::Value RPCHandler::doProofCreate(Json::Value jvRequest, int& cost, ScopedLock& MasterLockHolder)
|
||||||
{
|
{
|
||||||
// XXX: Add ability to create proof with arbitrary secret and time
|
// XXX: Add ability to create proof with arbitrary time
|
||||||
|
|
||||||
Json::Value jvResult(Json::objectValue);
|
Json::Value jvResult(Json::objectValue);
|
||||||
|
|
||||||
|
if (jvRequest.isMember("difficulty") || jvRequest.isMember("secret"))
|
||||||
|
{
|
||||||
|
ProofOfWorkGenerator pgGen;
|
||||||
|
|
||||||
if (jvRequest.isMember("difficulty"))
|
if (jvRequest.isMember("difficulty"))
|
||||||
{
|
{
|
||||||
if (!jvRequest["difficulty"].isIntegral())
|
if (!jvRequest["difficulty"].isIntegral())
|
||||||
@@ -898,8 +903,14 @@ Json::Value RPCHandler::doProofCreate(Json::Value jvRequest, int& cost, ScopedLo
|
|||||||
if (iDifficulty < 0 || iDifficulty > ProofOfWork::sMaxDifficulty)
|
if (iDifficulty < 0 || iDifficulty > ProofOfWork::sMaxDifficulty)
|
||||||
return rpcError(rpcINVALID_PARAMS);
|
return rpcError(rpcINVALID_PARAMS);
|
||||||
|
|
||||||
ProofOfWorkGenerator pgGen;
|
|
||||||
pgGen.setDifficulty(iDifficulty);
|
pgGen.setDifficulty(iDifficulty);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (jvRequest.isMember("secret"))
|
||||||
|
{
|
||||||
|
uint256 uSecret(jvRequest["secret"].asString());
|
||||||
|
pgGen.setSecret(uSecret);
|
||||||
|
}
|
||||||
|
|
||||||
jvResult["token"] = pgGen.getProof().getToken();
|
jvResult["token"] = pgGen.getProof().getToken();
|
||||||
jvResult["secret"] = pgGen.getSecret().GetHex();
|
jvResult["secret"] = pgGen.getSecret().GetHex();
|
||||||
|
|||||||
Reference in New Issue
Block a user