Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/avalanche.cpp
Show First 20 Lines • Show All 903 Lines • ▼ Show 20 Lines | return RPCHelpMan{ | ||||
RPCResult::Type::OBJ, | RPCResult::Type::OBJ, | ||||
"", | "", | ||||
"", | "", | ||||
{{ | {{ | ||||
{RPCResult::Type::STR_HEX, "proof", | {RPCResult::Type::STR_HEX, "proof", | ||||
"The hex encoded proof matching the identifier."}, | "The hex encoded proof matching the identifier."}, | ||||
{RPCResult::Type::BOOL, "orphan", | {RPCResult::Type::BOOL, "orphan", | ||||
"Whether the proof is an orphan."}, | "Whether the proof is an orphan."}, | ||||
{RPCResult::Type::BOOL, "isBoundToPeer", | {RPCResult::Type::BOOL, "boundToPeer", | ||||
"Whether the proof is bound to an avalanche peer."}, | "Whether the proof is bound to an avalanche peer."}, | ||||
{RPCResult::Type::BOOL, "conflicting", | |||||
"Whether the proof has a conflicting UTXO with an avalanche " | |||||
"peer."}, | |||||
{RPCResult::Type::BOOL, "finalized", | |||||
"Whether the proof is finalized by vote."}, | |||||
}}, | }}, | ||||
}, | }, | ||||
RPCExamples{HelpExampleRpc("getrawavalancheproof", "<proofid>")}, | RPCExamples{HelpExampleRpc("getrawavalancheproof", "<proofid>")}, | ||||
[&](const RPCHelpMan &self, const Config &config, | [&](const RPCHelpMan &self, const Config &config, | ||||
const JSONRPCRequest &request) -> UniValue { | const JSONRPCRequest &request) -> UniValue { | ||||
if (!g_avalanche) { | if (!g_avalanche) { | ||||
throw JSONRPCError(RPC_INTERNAL_ERROR, | throw JSONRPCError(RPC_INTERNAL_ERROR, | ||||
"Avalanche is not initialized"); | "Avalanche is not initialized"); | ||||
} | } | ||||
const avalanche::ProofId proofid = | const avalanche::ProofId proofid = | ||||
avalanche::ProofId::fromHex(request.params[0].get_str()); | avalanche::ProofId::fromHex(request.params[0].get_str()); | ||||
bool isOrphan = false; | bool isOrphan = false; | ||||
bool isBoundToPeer = false; | bool isBoundToPeer = false; | ||||
auto proof = | bool conflicting = false; | ||||
g_avalanche->withPeerManager([&](avalanche::PeerManager &pm) { | bool finalized = false; | ||||
auto proof = g_avalanche->withPeerManager( | |||||
[&](const avalanche::PeerManager &pm) { | |||||
isOrphan = pm.isOrphan(proofid); | isOrphan = pm.isOrphan(proofid); | ||||
isBoundToPeer = pm.isBoundToPeer(proofid); | isBoundToPeer = pm.isBoundToPeer(proofid); | ||||
conflicting = pm.isInConflictingPool(proofid); | |||||
finalized = | |||||
pm.forPeer(proofid, [&](const avalanche::Peer &p) { | |||||
return p.hasFinalized; | |||||
}); | |||||
return pm.getProof(proofid); | return pm.getProof(proofid); | ||||
}); | }); | ||||
if (!proof) { | if (!proof) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Proof not found"); | throw JSONRPCError(RPC_INVALID_PARAMETER, "Proof not found"); | ||||
} | } | ||||
UniValue ret(UniValue::VOBJ); | UniValue ret(UniValue::VOBJ); | ||||
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); | CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); | ||||
ss << *proof; | ss << *proof; | ||||
ret.pushKV("proof", HexStr(ss)); | ret.pushKV("proof", HexStr(ss)); | ||||
ret.pushKV("orphan", isOrphan); | ret.pushKV("orphan", isOrphan); | ||||
ret.pushKV("isBoundToPeer", isBoundToPeer); | ret.pushKV("boundToPeer", isBoundToPeer); | ||||
ret.pushKV("conflicting", conflicting); | |||||
ret.pushKV("finalized", finalized); | |||||
return ret; | return ret; | ||||
}, | }, | ||||
}; | }; | ||||
} | } | ||||
static RPCHelpMan sendavalancheproof() { | static RPCHelpMan sendavalancheproof() { | ||||
return RPCHelpMan{ | return RPCHelpMan{ | ||||
▲ Show 20 Lines • Show All 119 Lines • Show Last 20 Lines |