Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/avalanche.cpp
Show First 20 Lines • Show All 438 Lines • ▼ Show 20 Lines | for (const auto &peer : g_avalanche->getPeers()) { | ||||
obj.pushKV("nodecount", uint64_t(peer.node_count)); | obj.pushKV("nodecount", uint64_t(peer.node_count)); | ||||
ret.push_back(obj); | ret.push_back(obj); | ||||
} | } | ||||
return ret; | return ret; | ||||
} | } | ||||
static UniValue getrawavalancheproof(const Config &config, | |||||
const JSONRPCRequest &request) { | |||||
RPCHelpMan{ | |||||
"getrawavalancheproof", | |||||
"Lookup for a known avalanche proof by id.\n", | |||||
{ | |||||
{"proofid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, | |||||
"The hex encoded avalanche proof identifier."}, | |||||
}, | |||||
RPCResult{ | |||||
RPCResult::Type::OBJ, | |||||
"", | |||||
"", | |||||
{{ | |||||
{RPCResult::Type::STR_HEX, "proof", | |||||
"The hex encoded proof matching the identifier."}, | |||||
{RPCResult::Type::BOOL, "orphan", | |||||
"Whether the proof is an orphan."}, | |||||
}}, | |||||
}, | |||||
RPCExamples{HelpExampleRpc("getrawavalancheproof", "<proofid>")}, | |||||
} | |||||
.Check(request); | |||||
if (!g_avalanche) { | |||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Avalanche is not initialized"); | |||||
} | |||||
const avalanche::ProofId proofid = | |||||
avalanche::ProofId::fromHex(request.params[0].get_str()); | |||||
bool isOrphan = false; | |||||
auto proof = g_avalanche->getProof(proofid); | |||||
if (!proof) { | |||||
proof = g_avalanche->getOrphan(proofid); | |||||
isOrphan = true; | |||||
} | |||||
if (!proof) { | |||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Proof not found"); | |||||
} | |||||
UniValue ret(UniValue::VOBJ); | |||||
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); | |||||
ss << *proof; | |||||
ret.pushKV("proof", HexStr(ss)); | |||||
ret.pushKV("orphan", isOrphan); | |||||
return ret; | |||||
} | |||||
static void verifyProofOrThrow(const NodeContext &node, avalanche::Proof &proof, | static void verifyProofOrThrow(const NodeContext &node, avalanche::Proof &proof, | ||||
const std::string &proofHex) { | const std::string &proofHex) { | ||||
bilingual_str error; | bilingual_str error; | ||||
if (!avalanche::Proof::FromHex(proof, proofHex, error)) { | if (!avalanche::Proof::FromHex(proof, proofHex, error)) { | ||||
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, error.original); | throw JSONRPCError(RPC_DESERIALIZATION_ERROR, error.original); | ||||
} | } | ||||
avalanche::ProofValidationState state; | avalanche::ProofValidationState state; | ||||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | static const CRPCCommand commands[] = { | ||||
// category name actor (function) argNames | // category name actor (function) argNames | ||||
// ------------------- ------------------------ ---------------------- ---------- | // ------------------- ------------------------ ---------------------- ---------- | ||||
{ "avalanche", "getavalanchekey", getavalanchekey, {}}, | { "avalanche", "getavalanchekey", getavalanchekey, {}}, | ||||
{ "avalanche", "addavalanchenode", addavalanchenode, {"nodeid"}}, | { "avalanche", "addavalanchenode", addavalanchenode, {"nodeid"}}, | ||||
{ "avalanche", "buildavalancheproof", buildavalancheproof, {"sequence", "expiration", "master", "stakes"}}, | { "avalanche", "buildavalancheproof", buildavalancheproof, {"sequence", "expiration", "master", "stakes"}}, | ||||
{ "avalanche", "decodeavalancheproof", decodeavalancheproof, {"proof"}}, | { "avalanche", "decodeavalancheproof", decodeavalancheproof, {"proof"}}, | ||||
{ "avalanche", "delegateavalancheproof", delegateavalancheproof, {"proof", "privatekey", "publickey", "delegation"}}, | { "avalanche", "delegateavalancheproof", delegateavalancheproof, {"proof", "privatekey", "publickey", "delegation"}}, | ||||
{ "avalanche", "getavalanchepeerinfo", getavalanchepeerinfo, {}}, | { "avalanche", "getavalanchepeerinfo", getavalanchepeerinfo, {}}, | ||||
{ "avalanche", "getrawavalancheproof", getrawavalancheproof, {"proofid"}}, | |||||
{ "avalanche", "sendavalancheproof", sendavalancheproof, {"proof"}}, | { "avalanche", "sendavalancheproof", sendavalancheproof, {"proof"}}, | ||||
{ "avalanche", "verifyavalancheproof", verifyavalancheproof, {"proof"}}, | { "avalanche", "verifyavalancheproof", verifyavalancheproof, {"proof"}}, | ||||
}; | }; | ||||
// clang-format on | // clang-format on | ||||
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) { | for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) { | ||||
t.appendCommand(commands[vcidx].name, &commands[vcidx]); | t.appendCommand(commands[vcidx].name, &commands[vcidx]); | ||||
} | } | ||||
} | } |