Status TimeProofService::checkProof(LogicalTime time, const TimeProof& proof, const Key& key) {
    auto myProof = getProof(time, key);
    if (myProof != proof) {
        return Status(ErrorCodes::TimeProofMismatch, "Proof does not match the cluster time");
    }
    return Status::OK();
}
Example #2
0
// {
//   // if either of these parameters is set, a custom generator is used
//   difficulty: <number>       // optional
//   secret: <secret>           // optional
// }
Json::Value doProofCreate (RPC::Context& context)
{
    // XXX: Add ability to create proof with arbitrary time
    Json::Value     jvResult (Json::objectValue);

    if (context.params_.isMember ("difficulty") ||
        context.params_.isMember ("secret"))
    {
        // VFALCO TODO why aren't we using the app's factory?
        auto pgGen = make_ProofOfWorkFactory ();

        if (context.params_.isMember ("difficulty"))
        {
            if (!context.params_["difficulty"].isIntegral ())
                return RPC::invalid_field_error ("difficulty");

            int const iDifficulty (context.params_["difficulty"].asInt ());

            if (iDifficulty < 0 ||
                iDifficulty > ProofOfWorkFactory::kMaxDifficulty)
            {
                return RPC::invalid_field_error ("difficulty");
            }

            pgGen->setDifficulty (iDifficulty);
        }

        if (context.params_.isMember ("secret"))
        {
            uint256 uSecret (context.params_["secret"].asString ());
            pgGen->setSecret (uSecret);
        }

        jvResult["token"] = pgGen->getProof ().getToken ();
        jvResult["secret"] = to_string (pgGen->getSecret ());
    }
    else
    {
        jvResult["token"]
                = getApp().getProofOfWorkFactory ().getProof ().getToken ();
    }

    return jvResult;
}