17 static UniValue packRetStatus(
const std::string& nodeType,
const std::string& result,
const std::string&
error)
20 statusObj.pushKV(
"node", nodeType);
21 statusObj.pushKV(
"result", result);
22 statusObj.pushKV(
"error",
error);
26 static UniValue packErrorRetStatus(
const std::string& nodeType,
const std::string&
error)
28 return packRetStatus(nodeType,
"failed",
error);
31 static UniValue packVoteReturnValue(
const UniValue& details,
int success,
int failed)
34 returnObj.pushKV(
"overall",
strprintf(
"Voted successfully %d time(s) and failed %d time(s).", success, failed));
35 returnObj.pushKV(
"detail", details);
77 for (
const auto& k : mnKeys) {
80 resultsObj.
push_back(packErrorRetStatus(k.mnAlias,
"Failure to sign."));
90 resultsObj.
push_back(packRetStatus(k.mnAlias,
"success",
""));
94 return packVoteReturnValue(resultsObj, success, failed);
101 for (
const auto& k : mnKeys) {
103 if (!k.Sign(&vote)) {
104 resultsObj.
push_back(packErrorRetStatus(k.mnAlias,
"Failure to sign."));
114 resultsObj.
push_back(packRetStatus(k.mnAlias,
"success",
""));
118 return packVoteReturnValue(resultsObj, success, failed);
127 if (mnAliasFilter && *mnAliasFilter != mne.getAlias())
continue;
129 const std::string& mnAlias = mne.getAlias();
131 resultsObj.
push_back(packErrorRetStatus(mnAlias,
"Could not get key from masternode.conf"));
137 resultsObj.
push_back(packErrorRetStatus(mnAlias,
"Can't find masternode by pubkey"));
141 mnKeys.emplace_back(mnAlias, &pmn->
vin.
prevout, mnKey);
150 throw std::runtime_error(
_(
"This is not a masternode. 'local' option disabled."));
154 throw std::runtime_error(
_(
"Active Masternode not initialized."));
161 resultsObj.
push_back(packErrorRetStatus(
"local",
"Can't find masternode by pubkey"));
172 throw std::runtime_error(
"Wallet (with voting key) not found.");
183 resultsObj.
push_back(packErrorRetStatus(*mnAliasFilter,
"Invalid or unknown proTxHash"));
191 bool filtered = mnFilter && dmn->proTxHash == mnFilter->proTxHash;
192 if (!mnFilter || filtered) {
195 throw std::runtime_error(
"Finalized budget voting is allowed only locally, from the masternode");
200 if (pwallet->
GetKey(dmn->pdmnState->keyIDVoting, mnKey)) {
201 mnKeys.emplace_back(dmn->proTxHash.ToString(), &dmn->collateralOutpoint, mnKey);
202 }
else if (filtered) {
204 "Private key for voting address %s not known by this wallet",
219 throw std::runtime_error(
_(
"This is not a deterministic masternode. 'local' option disabled."));
225 resultsObj.
push_back(packErrorRetStatus(
"local", res.getError()));
229 return {
MnKeyData(
"local", &dmn->collateralOutpoint, sk)};
238 if (fFinal && !fLegacyMN) {
239 throw std::runtime_error(
"Finalized budget voting is allowed only locally, from the masternode");
244 mnKeyList mnKeys = fLegacyMN ? getMNKeys(mnAliasFilter, resultsObj, failed)
245 : getDMNVotingKeys(pwallet, mnAliasFilter, fFinal, resultsObj, failed);
247 if (mnKeys.empty()) {
248 return packVoteReturnValue(resultsObj, 0, failed);
251 return (fFinal ? voteFinalBudget(budgetHash, mnKeys, resultsObj, failed)
252 : voteProposal(budgetHash, nVote, mnKeys, resultsObj, failed));
263 mnKeyList mnKeys = fLegacyMN ? getMNKeysForActiveMasternode(resultsObj)
264 : getDMNKeysForActiveMasternode(resultsObj);
266 if (mnKeys.empty()) {
267 return packVoteReturnValue(resultsObj, 0, 1);
270 return (fFinal ? voteFinalBudget(budgetHash, mnKeys, resultsObj, 0)
271 : voteProposal(budgetHash, nVote, mnKeys, resultsObj, 0));
CActiveDeterministicMasternodeManager * activeMasternodeManager
CBudgetManager g_budgetman
std::list< MnKeyData > mnKeyList
UniValue mnBudgetVoteInner(CWallet *const pwallet, bool fLegacyMN, const uint256 &budgetHash, bool fFinal, const CBudgetVote::VoteDirection &nVote, const Optional< std::string > &mnAliasFilter)
UniValue mnLocalBudgetVoteInner(bool fLegacyMN, const uint256 &budgetHash, bool fFinal, const CBudgetVote::VoteDirection &nVote)
OperationResult GetOperatorKey(CBLSSecretKey &key, CDeterministicMNCPtr &dmn) const
void GetKeys(CKey &privKeyMasternode, CPubKey &pubKeyMasternode) const
bool ProcessProposalVote(CBudgetVote &proposal, CNode *pfrom, CValidationState &state)
bool ProcessFinalizedBudgetVote(CFinalizedBudgetVote &vote, CNode *pfrom, CValidationState &state)
bool GetKey(const CKeyID &address, CKey &keyOut) const override
An encapsulated private key.
CPubKey GetPubKey() const
Compute the public key from a private key.
std::vector< CMasternodeEntry > getEntries()
CMasternode * Find(const COutPoint &collateralOut)
Find an entry.
static bool GetKeysFromSecret(const std::string &strSecret, CKey &keyRet, CPubKey &pubkeyRet)
Set the private/public key values, returns true if successful.
An outpoint - a combination of a transaction hash and an index n into its vout.
An encapsulated public key.
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Base Class for all signed messages on the network.
bool Sign(const CKey &key, const CKeyID &keyID)
CSignedMessage Class Functions inherited by network signed-messages.
An input of a transaction.
Capture information about block/transaction validation.
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,...
bool push_back(const UniValue &val)
std::unique_ptr< CDeterministicMNManager > deterministicMNManager
std::shared_ptr< const CDeterministicMN > CDeterministicMNCPtr
CMasternodeConfig masternodeConfig
CMasternodeMan mnodeman
Masternode manager.
CActiveMasternode activeMasternode
Keep track of the active Masternode.
std::string EncodeDestination(const CWDestination &address, const CChainParams::Base58Type addrType)
boost::optional< T > Optional
Substitute for C++17 std::optional.
MnKeyData(const std::string &_mnAlias, const COutPoint *_collateralOut, const CBLSSecretKey &_key)
const COutPoint * collateralOut
bool Sign(CSignedMessage *msg) const
MnKeyData(const std::string &_mnAlias, const COutPoint *_collateralOut, const CKey &_key)
std::atomic< bool > fMasterNode
bool error(const char *fmt, const Args &... args)
std::string _(const char *psz)
Translation function: Call Translate signal on UI interface, which returns a Optional result.
uint256 uint256S(const char *str)
std::string FormatStateMessage(const CValidationState &state)
Convert CValidationState to a human-readable message for logging.