draft
This commit is contained in:
parent
40adfbf2c9
commit
f38b8e9572
@ -197,6 +197,33 @@ CBudgetVote::CBudgetVote(CTxIn vinIn, std::string strProposalNameIn, int nBlockS
|
|||||||
nTime = GetAdjustedTime();
|
nTime = GetAdjustedTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CBudgetVote::CBudgetVote(CTxIn vinIn, std::string strProposalNameIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int nVoteIn)
|
||||||
|
{
|
||||||
|
vin = vinIn;
|
||||||
|
strProposalName = strProposalNameIn;
|
||||||
|
|
||||||
|
CBlockIndex* pindexPrev = chainActive.Tip();
|
||||||
|
if(pindexPrev != NULL)
|
||||||
|
{
|
||||||
|
//calculate beginning of payment cycle
|
||||||
|
nBlockStart = (pindexPrev->nHeight-(pindexPrev->nHeight % PAYMENT_CYCLE_BLOCKS));
|
||||||
|
//calculate the end of the cycle for this vote
|
||||||
|
nBlockEnd = nBlockStart + (PAYMENT_CYCLE_BLOCKS*nPaymentCount);
|
||||||
|
// These numbers don't require being all the same across the network due to the way
|
||||||
|
// they are sampled from the votes.
|
||||||
|
} else {
|
||||||
|
nBlockStart = 0;
|
||||||
|
nBlockEnd = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
address = addressIn;
|
||||||
|
nAmount = nAmountIn;
|
||||||
|
nVote = nVoteIn;
|
||||||
|
nTime = GetAdjustedTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool CBudgetVote::Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode)
|
bool CBudgetVote::Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode)
|
||||||
{
|
{
|
||||||
// Choose coins to use
|
// Choose coins to use
|
||||||
|
@ -25,6 +25,9 @@ class CBudgetVote;
|
|||||||
#define VOTE_YES 1
|
#define VOTE_YES 1
|
||||||
#define VOTE_NO 2
|
#define VOTE_NO 2
|
||||||
|
|
||||||
|
//Amount of blocks in a months period of time (using 2.6 minutes per)
|
||||||
|
#define PAYMENT_CYCLE_BLOCKS 16615
|
||||||
|
|
||||||
extern CBudgetManager budget;
|
extern CBudgetManager budget;
|
||||||
|
|
||||||
void DumpBudgets();
|
void DumpBudgets();
|
||||||
@ -174,6 +177,7 @@ public:
|
|||||||
|
|
||||||
CBudgetVote();
|
CBudgetVote();
|
||||||
CBudgetVote(CTxIn vinIn, std::string strProposalNameIn, int nBlockStartIn, int nBlockEndIn, CScript addressIn, CAmount nAmountIn, int nVoteIn);
|
CBudgetVote(CTxIn vinIn, std::string strProposalNameIn, int nBlockStartIn, int nBlockEndIn, CScript addressIn, CAmount nAmountIn, int nVoteIn);
|
||||||
|
CBudgetVote(CTxIn vinIn, std::string strProposalNameIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int nVoteIn);
|
||||||
|
|
||||||
bool Sign(CKey& keyCollateralAddress, CPubKey& pubKeyMasternode);
|
bool Sign(CKey& keyCollateralAddress, CPubKey& pubKeyMasternode);
|
||||||
bool SignatureValid();
|
bool SignatureValid();
|
||||||
|
@ -39,24 +39,26 @@ Value mnbudget(const Array& params, bool fHelp)
|
|||||||
|
|
||||||
if(strCommand == "vote-many")
|
if(strCommand == "vote-many")
|
||||||
{
|
{
|
||||||
/* std::vector<CMasternodeConfig::CMasternodeEntry> mnEntries;
|
std::vector<CMasternodeConfig::CMasternodeEntry> mnEntries;
|
||||||
mnEntries = masternodeConfig.getEntries();
|
mnEntries = masternodeConfig.getEntries();
|
||||||
|
|
||||||
if (params.size() != 5)
|
if (params.size() != 5)
|
||||||
throw runtime_error("Correct usage of vote-many is 'mnbudget vote-many PROPOSAL-NAME BLOCKSTART BLOCKEND XADDRESS AMOUNT YEA|NAY'");
|
throw runtime_error("Correct usage of vote-many is 'mnbudget vote-many PROPOSAL-NAME PAYMENT_COUNT DASH_ADDRESS USD_AMOUNT YES|NO|ABSTAIN'");
|
||||||
|
|
||||||
std::string strProposalName = params[1].get_str();
|
std::string strProposalName = params[1].get_str();
|
||||||
if(strProposalName.size() > 20)
|
if(strProposalName.size() > 20)
|
||||||
return "Invalid proposal name, limit of 20 characters.";
|
return "Invalid proposal name, limit of 20 characters.";
|
||||||
|
|
||||||
int nBlockStart = params[2].get_int();
|
int nPaymentCount = params[2].get_int();
|
||||||
int nBlockEnd = params[3].get_int();
|
CBitcoinAddress address(params[3].get_str());
|
||||||
CBitcoinAddress address(params[4].get_str());
|
|
||||||
if (!address.IsValid())
|
if (!address.IsValid())
|
||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Dash address");
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Dash address");
|
||||||
|
|
||||||
CAmount nAmount = AmountFromValue(params[5]);
|
// Parse Dash address
|
||||||
std::string strVote = params[6].get_str().c_str();
|
CScript scriptPubKey = GetScriptForDestination(address.Get());
|
||||||
|
|
||||||
|
CAmount nAmount = AmountFromValue(params[4]);
|
||||||
|
std::string strVote = params[5].get_str().c_str();
|
||||||
|
|
||||||
if(strVote != "yes" && strVote != "no") return "You can only vote 'yes' or 'no'";
|
if(strVote != "yes" && strVote != "no") return "You can only vote 'yes' or 'no'";
|
||||||
int nVote = VOTE_ABSTAIN;
|
int nVote = VOTE_ABSTAIN;
|
||||||
@ -95,7 +97,7 @@ Value mnbudget(const Array& params, bool fHelp)
|
|||||||
if(!darkSendSigner.SetKey(strMasterNodePrivKey, errorMessage, keyMasternode, pubKeyMasternode))
|
if(!darkSendSigner.SetKey(strMasterNodePrivKey, errorMessage, keyMasternode, pubKeyMasternode))
|
||||||
return(" Error upon calling SetKey");
|
return(" Error upon calling SetKey");
|
||||||
|
|
||||||
CBudgetVote vote(pmn->vin, strProposalName, nBlockStart, nBlockEnd, address, nAmount, nVote);
|
CBudgetVote vote(pmn->vin, strProposalName, nPaymentCount, scriptPubKey, nAmount, nVote);
|
||||||
if(!vote.Sign(keyMasternode, pubKeyMasternode)){
|
if(!vote.Sign(keyMasternode, pubKeyMasternode)){
|
||||||
return "Failure to sign.";
|
return "Failure to sign.";
|
||||||
}
|
}
|
||||||
@ -104,30 +106,32 @@ Value mnbudget(const Array& params, bool fHelp)
|
|||||||
vote.Relay();
|
vote.Relay();
|
||||||
}
|
}
|
||||||
|
|
||||||
return("Voted successfully " + boost::lexical_cast<std::string>(success) + " time(s) and failed " + boost::lexical_cast<std::string>(failed) + " time(s).");*/
|
return("Voted successfully " + boost::lexical_cast<std::string>(success) + " time(s) and failed " + boost::lexical_cast<std::string>(failed) + " time(s).");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strCommand == "vote")
|
if(strCommand == "vote")
|
||||||
{
|
{
|
||||||
/* std::vector<CMasternodeConfig::CMasternodeEntry> mnEntries;
|
std::vector<CMasternodeConfig::CMasternodeEntry> mnEntries;
|
||||||
mnEntries = masternodeConfig.getEntries();
|
mnEntries = masternodeConfig.getEntries();
|
||||||
|
|
||||||
if (params.size() != 5)
|
if (params.size() != 5)
|
||||||
throw runtime_error("Correct usage of vote-many is 'mnbudget vote PROPOSAL-NAME BLOCKSTART BLOCKEND XADDRESS AMOUNT YEA|NAY'");
|
throw runtime_error("Correct usage of vote-many is 'mnbudget vote PROPOSAL-NAME PAYMENT_COUNT DASH_ADDRESS USD_AMOUNT YES|NO|ABSTAIN'");
|
||||||
|
|
||||||
std::string strProposalName = params[1].get_str();
|
std::string strProposalName = params[1].get_str();
|
||||||
|
|
||||||
if(strProposalName.size() > 20)
|
if(strProposalName.size() > 20)
|
||||||
return "Invalid proposal name, limit of 20 characters.";
|
return "Invalid proposal name, limit of 20 characters.";
|
||||||
|
|
||||||
int nBlockStart = params[2].get_int();
|
int nPaymentCount = params[2].get_int();
|
||||||
int nBlockEnd = params[3].get_int();
|
CBitcoinAddress address(params[3].get_str());
|
||||||
CBitcoinAddress address(params[4].get_str());
|
|
||||||
if (!address.IsValid())
|
if (!address.IsValid())
|
||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Dash address");
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Dash address");
|
||||||
|
|
||||||
CAmount nAmount = AmountFromValue(params[5]);
|
// Parse Dash address
|
||||||
std::string strVote = params[6].get_str().c_str();
|
CScript scriptPubKey = GetScriptForDestination(address.Get());
|
||||||
|
|
||||||
|
CAmount nAmount = AmountFromValue(params[4]);
|
||||||
|
std::string strVote = params[5].get_str().c_str();
|
||||||
|
|
||||||
if(strVote != "yes" && strVote != "no") return "You can only vote 'yes' or 'no'";
|
if(strVote != "yes" && strVote != "no") return "You can only vote 'yes' or 'no'";
|
||||||
int nVote = VOTE_ABSTAIN;
|
int nVote = VOTE_ABSTAIN;
|
||||||
@ -141,12 +145,12 @@ Value mnbudget(const Array& params, bool fHelp)
|
|||||||
if(!darkSendSigner.SetKey(strMasterNodePrivKey, errorMessage, keyMasternode, pubKeyMasternode))
|
if(!darkSendSigner.SetKey(strMasterNodePrivKey, errorMessage, keyMasternode, pubKeyMasternode))
|
||||||
return(" Error upon calling SetKey");
|
return(" Error upon calling SetKey");
|
||||||
|
|
||||||
CBudgetVote vote(activeMasternode.vin, strProposalName, nBlockStart, nBlockEnd, address, nAmount, nVote);
|
CBudgetVote vote(activeMasternode.vin, strProposalName, nPaymentCount, scriptPubKey, nAmount, nVote);
|
||||||
if(!vote.Sign(keyMasternode, pubKeyMasternode)){
|
if(!vote.Sign(keyMasternode, pubKeyMasternode)){
|
||||||
return "Failure to sign.";
|
return "Failure to sign.";
|
||||||
}
|
}
|
||||||
|
|
||||||
vote.Relay();*/
|
vote.Relay();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user