diff --git a/src/rpc/avalanche.cpp b/src/rpc/avalanche.cpp --- a/src/rpc/avalanche.cpp +++ b/src/rpc/avalanche.cpp @@ -75,9 +75,10 @@ } } -static void verifyProofOrThrow(const NodeContext &node, avalanche::Proof &proof, - const std::string &proofHex) { +static avalanche::ProofRef verifyProofOrThrow(const NodeContext &node, + const std::string &proofHex) { bilingual_str error; + avalanche::Proof proof; if (!avalanche::Proof::FromHex(proof, proofHex, error)) { throw JSONRPCError(RPC_DESERIALIZATION_ERROR, error.original); } @@ -91,6 +92,8 @@ "The proof is invalid: " + state.ToString()); } } + + return std::make_shared(std::move(proof)); } static RPCHelpMan addavalanchenode() { @@ -124,9 +127,8 @@ const NodeId nodeid = request.params[0].get_int64(); CPubKey key = ParsePubKey(request.params[1]); - auto proof = std::make_shared(); NodeContext &node = EnsureNodeContext(request.context); - verifyProofOrThrow(node, *proof, request.params[2].get_str()); + auto proof = verifyProofOrThrow(node, request.params[2].get_str()); const avalanche::ProofId &proofid = proof->getId(); if (key != proof->getMaster()) { @@ -938,13 +940,12 @@ "Avalanche is not initialized"); } - auto proof = std::make_shared(); NodeContext &node = EnsureNodeContext(request.context); // Verify the proof. Note that this is redundant with the // verification done when adding the proof to the pool, but we get a // chance to give a better error message. - verifyProofOrThrow(node, *proof, request.params[0].get_str()); + auto proof = verifyProofOrThrow(node, request.params[0].get_str()); // Add the proof to the pool if we don't have it already. Since the // proof verification has already been done, a failure likely @@ -982,8 +983,7 @@ const JSONRPCRequest &request) -> UniValue { RPCTypeCheck(request.params, {UniValue::VSTR}); - avalanche::Proof proof; - verifyProofOrThrow(EnsureNodeContext(request.context), proof, + verifyProofOrThrow(EnsureNodeContext(request.context), request.params[0].get_str()); return true;