Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/processor.cpp
Show First 20 Lines • Show All 209 Lines • ▼ Show 20 Lines | if (argsman.IsArgSet("-avaproof")) { | ||||
masterKey = DecodeSecret(argsman.GetArg("-avamasterkey", "")); | masterKey = DecodeSecret(argsman.GetArg("-avamasterkey", "")); | ||||
if (!masterKey.IsValid()) { | if (!masterKey.IsValid()) { | ||||
error = _("the avalanche master key is invalid"); | error = _("the avalanche master key is invalid"); | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
peerData = std::make_unique<PeerData>(); | peerData = std::make_unique<PeerData>(); | ||||
{ | try { | ||||
// The proof. | |||||
CDataStream stream(ParseHex(argsman.GetArg("-avaproof", "")), | CDataStream stream(ParseHex(argsman.GetArg("-avaproof", "")), | ||||
SER_NETWORK, 0); | SER_NETWORK, 0); | ||||
stream >> peerData->proof; | stream >> peerData->proof; | ||||
} catch (const std::exception &e) { | |||||
LogPrintf("%s\n", e.what()); | |||||
error = _("the avalanche proof has invalid format"); | |||||
return nullptr; | |||||
} | } | ||||
ProofValidationState proof_state; | ProofValidationState proof_state; | ||||
if (!peerData->proof.verify(proof_state)) { | if (!peerData->proof.verify(proof_state)) { | ||||
switch (proof_state.GetResult()) { | switch (proof_state.GetResult()) { | ||||
case ProofValidationResult::NO_STAKE: | case ProofValidationResult::NO_STAKE: | ||||
error = _("the avalanche proof has no stake"); | error = _("the avalanche proof has no stake"); | ||||
return nullptr; | return nullptr; | ||||
Show All 13 Lines | if (argsman.IsArgSet("-avaproof")) { | ||||
AVALANCHE_MAX_PROOF_STAKES); | AVALANCHE_MAX_PROOF_STAKES); | ||||
return nullptr; | return nullptr; | ||||
default: | default: | ||||
error = _("the avalanche proof is invalid"); | error = _("the avalanche proof is invalid"); | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
} | } | ||||
if (masterKey.GetPubKey() != peerData->proof.getMaster()) { | |||||
error = _("the master key does not match the proof public key"); | |||||
return nullptr; | |||||
} | |||||
// Generate the delegation to the session key. | // Generate the delegation to the session key. | ||||
DelegationBuilder dgb(peerData->proof); | DelegationBuilder dgb(peerData->proof); | ||||
if (sessionKey.GetPubKey() != peerData->proof.getMaster()) { | if (sessionKey.GetPubKey() != peerData->proof.getMaster()) { | ||||
dgb.addLevel(masterKey, sessionKey.GetPubKey()); | dgb.addLevel(masterKey, sessionKey.GetPubKey()); | ||||
} | } | ||||
peerData->delegation = dgb.build(); | peerData->delegation = dgb.build(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 428 Lines • Show Last 20 Lines |