Skip to content

Commit

Permalink
add mnbudgetvoteraw
Browse files Browse the repository at this point in the history
Closes: #621
  • Loading branch information
UdjinM6 authored and schinzelh committed Sep 24, 2015
1 parent 5e656df commit 3d91fe3
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/rpcclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "mnbudget", 4 },
{ "mnbudget", 6 },
{ "mnbudget", 8 },
{ "mnbudgetvoteraw", 1 },
{ "mnbudgetvoteraw", 4 },
};

class CRPCConvertTable
Expand Down
52 changes: 52 additions & 0 deletions src/rpcmasternode-budget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,58 @@ Value mnbudget(const Array& params, bool fHelp)
return Value::null;
}

Value mnbudgetvoteraw(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 6)
throw runtime_error(
"mnbudgetvoteraw <masternode-tx-hash> <masternode-tx-index> <proposal-hash> <yes|no> <time> <vote-sig>\n"
"Compile and relay a proposal vote with provided external signature instead of signing vote internally\n"
);

uint256 hashMnTx = ParseHashV(params[0], "mn tx hash");
int nMnTxIndex = params[1].get_int();
CTxIn vin = CTxIn(hashMnTx, nMnTxIndex);

uint256 hashProposal = ParseHashV(params[2], "Proposal hash");
std::string strVote = params[3].get_str();

if(strVote != "yes" && strVote != "no") return "You can only vote 'yes' or 'no'";
int nVote = VOTE_ABSTAIN;
if(strVote == "yes") nVote = VOTE_YES;
if(strVote == "no") nVote = VOTE_NO;

int64_t nTime = params[4].get_int64();
std::string strSig = params[5].get_str();
bool fInvalid = false;
vector<unsigned char> vchSig = DecodeBase64(strSig.c_str(), &fInvalid);

if (fInvalid)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Malformed base64 encoding");

CMasternode* pmn = mnodeman.Find(vin);
if(pmn == NULL)
{
return "Failure to find masternode in list : " + vin.ToString();
}

CBudgetVote vote(vin, hashProposal, nVote);
vote.nTime = nTime;
vote.vchSig = vchSig;

if(!vote.SignatureValid(true)){
return "Failure to verify signature.";
}

std::string strError = "";
if(budget.UpdateProposal(vote, NULL, strError)){
budget.mapSeenMasternodeBudgetVotes.insert(make_pair(vote.GetHash(), vote));
vote.Relay();
return "Voted successfully";
} else {
return "Error voting : " + strError;
}
}

Value mnfinalbudget(const Array& params, bool fHelp)
{
string strCommand;
Expand Down
1 change: 1 addition & 0 deletions src/rpcserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ static const CRPCCommand vRPCCommands[] =
{ "dash", "masternode", &masternode, true, true, false },
{ "dash", "masternodelist", &masternodelist, true, true, false },
{ "dash", "mnbudget", &mnbudget, true, true, false },
{ "dash", "mnbudgetvoteraw", &mnbudgetvoteraw, true, true, false },
{ "dash", "mnfinalbudget", &mnfinalbudget, true, true, false },
{ "dash", "mnsync", &mnsync, true, true, false },
{ "dash", "spork", &spork, true, true, false },
Expand Down
1 change: 1 addition & 0 deletions src/rpcserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ extern json_spirit::Value spork(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value masternode(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value masternodelist(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value mnbudget(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value mnbudgetvoteraw(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value mnfinalbudget(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value mnsync(const json_spirit::Array& params, bool fHelp);

Expand Down

0 comments on commit 3d91fe3

Please sign in to comment.