Skip to content

Commit

Permalink
Implement "quorum sign/hasrecsig/isconflicting" RPCs
Browse files Browse the repository at this point in the history
  • Loading branch information
codablock committed Jan 21, 2019
1 parent 316b6bf commit 23d7ed8
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions src/rpc/rpcquorums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "llmq/quorums.h"
#include "llmq/quorums_debug.h"
#include "llmq/quorums_dkgsession.h"
#include "llmq/quorums_signing.h"

void quorum_list_help()
{
Expand Down Expand Up @@ -155,6 +156,75 @@ UniValue quorum_dkgstatus(const JSONRPCRequest& request)
return status.ToJson(detailLevel);
}

void quorum_sign_help()
{
throw std::runtime_error(
"quorum sign llmqType \"id\" \"msgHash\"\n"
"\nArguments:\n"
"1. llmqType (int, required) LLMQ type.\n"
"2. \"id\" (string, required) Request id.\n"
"3. \"msgHash\" (string, required) Message hash.\n"
);
}

void quorum_hasrecsig_help()
{
throw std::runtime_error(
"quorum hasrecsig llmqType \"id\" \"msgHash\"\n"
"\nArguments:\n"
"1. llmqType (int, required) LLMQ type.\n"
"2. \"id\" (string, required) Request id.\n"
"3. \"msgHash\" (string, required) Message hash.\n"
);
}

void quorum_isconflicting_help()
{
throw std::runtime_error(
"quorum isconflicting llmqType \"id\" \"msgHash\"\n"
"\nArguments:\n"
"1. llmqType (int, required) LLMQ type.\n"
"2. \"id\" (string, required) Request id.\n"
"3. \"msgHash\" (string, required) Message hash.\n"
);
}

UniValue quorum_sigs_cmd(const JSONRPCRequest& request)
{
auto cmd = request.params[0].get_str();
if (request.fHelp || (request.params.size() != 4)) {
if (cmd == "sign") {
quorum_sign_help();
} else if (cmd == "hasrecsig") {
quorum_hasrecsig_help();
} else if (cmd == "isconflicting") {
quorum_isconflicting_help();
} else {
// shouldn't happen as it's already handled by the caller
throw JSONRPCError(RPC_INVALID_PARAMETER, "invalid cmd");
}
}

Consensus::LLMQType llmqType = (Consensus::LLMQType)ParseInt32V(request.params[1], "llmqType");
if (!Params().GetConsensus().llmqs.count(llmqType)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "invalid LLMQ type");
}

uint256 id = ParseHashV(request.params[2], "id");
uint256 msgHash = ParseHashV(request.params[3], "msgHash");

if (cmd == "sign") {
return llmq::quorumSigningManager->AsyncSignIfMember(llmqType, id, msgHash);
} else if (cmd == "hasrecsig") {
return llmq::quorumSigningManager->HasRecoveredSig(llmqType, id, msgHash);
} else if (cmd == "isconflicting") {
return llmq::quorumSigningManager->IsConflicting(llmqType, id, msgHash);
} else {
// shouldn't happen as it's already handled by the caller
throw JSONRPCError(RPC_INVALID_PARAMETER, "invalid cmd");
}
}

[[ noreturn ]] void quorum_help()
{
throw std::runtime_error(
Expand All @@ -167,6 +237,9 @@ UniValue quorum_dkgstatus(const JSONRPCRequest& request)
" list - List of on-chain quorums\n"
" info - Return information about a quorum\n"
" dkgstatus - Return the status of the current DKG process\n"
" sign - Threshold-sign a message\n"
" hasrecsig - Test if a valid recovered signature is present\n"
" isconflicting - Test if a conflict exists\n"
);
}

Expand All @@ -187,6 +260,8 @@ UniValue quorum(const JSONRPCRequest& request)
return quorum_info(request);
} else if (command == "dkgstatus") {
return quorum_dkgstatus(request);
} else if (command == "sign" || command == "hasrecsig" || command == "isconflicting") {
return quorum_sigs_cmd(request);
} else {
quorum_help();
}
Expand Down

0 comments on commit 23d7ed8

Please sign in to comment.