Proposal nTime based on fee transaction block
This commit is contained in:
parent
0e7b73e166
commit
805452955b
@ -227,12 +227,6 @@ bool CActiveMasternode::Register(std::string strService, std::string strKeyMaste
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!ConnectNode((CAddress)service, service.ToString().c_str())){
|
|
||||||
errorMessage = strprintf("Error: Could not connect to %s", service.ToString());
|
|
||||||
LogPrintf("CActiveMasternode::Register() - %s\n", errorMessage);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Register(vin, CService(strService), keyCollateralAddress, pubKeyCollateralAddress, keyMasternode, pubKeyMasternode, errorMessage);
|
return Register(vin, CService(strService), keyCollateralAddress, pubKeyCollateralAddress, keyMasternode, pubKeyMasternode, errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ int GetBudgetPaymentCycleBlocks(){
|
|||||||
return 50;
|
return 50;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsBudgetCollateralValid(uint256 nTxCollateralHash, uint256 nExpectedHash, std::string& strError)
|
bool IsBudgetCollateralValid(uint256 nTxCollateralHash, uint256 nExpectedHash, std::string& strError, int64_t& nTime)
|
||||||
{
|
{
|
||||||
CTransaction txCollateral;
|
CTransaction txCollateral;
|
||||||
uint256 nBlockHash;
|
uint256 nBlockHash;
|
||||||
@ -69,6 +69,7 @@ bool IsBudgetCollateralValid(uint256 nTxCollateralHash, uint256 nExpectedHash, s
|
|||||||
CBlockIndex* pindex = (*mi).second;
|
CBlockIndex* pindex = (*mi).second;
|
||||||
if (chainActive.Contains(pindex)) {
|
if (chainActive.Contains(pindex)) {
|
||||||
conf += chainActive.Height() - pindex->nHeight + 1;
|
conf += chainActive.Height() - pindex->nHeight + 1;
|
||||||
|
nTime = pindex->nTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,6 +89,7 @@ void CBudgetManager::CheckOrphanVotes()
|
|||||||
LogPrintf("LOCK - %\n", __func__);
|
LogPrintf("LOCK - %\n", __func__);
|
||||||
LOCK(cs);
|
LOCK(cs);
|
||||||
|
|
||||||
|
|
||||||
std::string strError = "";
|
std::string strError = "";
|
||||||
std::map<uint256, CBudgetVote>::iterator it1 = mapOrphanMasternodeBudgetVotes.begin();
|
std::map<uint256, CBudgetVote>::iterator it1 = mapOrphanMasternodeBudgetVotes.begin();
|
||||||
while(it1 != mapOrphanMasternodeBudgetVotes.end()){
|
while(it1 != mapOrphanMasternodeBudgetVotes.end()){
|
||||||
@ -906,7 +908,7 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string strError = "";
|
std::string strError = "";
|
||||||
if(!IsBudgetCollateralValid(finalizedBudgetBroadcast.nFeeTXHash, finalizedBudgetBroadcast.GetHash(), strError)){
|
if(!IsBudgetCollateralValid(finalizedBudgetBroadcast.nFeeTXHash, finalizedBudgetBroadcast.GetHash(), strError, finalizedBudgetBroadcast.nTime)){
|
||||||
LogPrintf("Finalized Budget FeeTX is not valid - %s - %s\n", finalizedBudgetBroadcast.nFeeTXHash.ToString(), strError);
|
LogPrintf("Finalized Budget FeeTX is not valid - %s - %s\n", finalizedBudgetBroadcast.nFeeTXHash.ToString(), strError);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1098,7 +1100,7 @@ CBudgetProposal::CBudgetProposal()
|
|||||||
fValid = true;
|
fValid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CBudgetProposal::CBudgetProposal(std::string strProposalNameIn, std::string strURLIn, int nBlockStartIn, int nBlockEndIn, CScript addressIn, CAmount nAmountIn, uint256 nFeeTXHashIn, int64_t nTimeIn)
|
CBudgetProposal::CBudgetProposal(std::string strProposalNameIn, std::string strURLIn, int nBlockStartIn, int nBlockEndIn, CScript addressIn, CAmount nAmountIn, uint256 nFeeTXHashIn)
|
||||||
{
|
{
|
||||||
strProposalName = strProposalNameIn;
|
strProposalName = strProposalNameIn;
|
||||||
strURL = strURLIn;
|
strURL = strURLIn;
|
||||||
@ -1106,7 +1108,6 @@ CBudgetProposal::CBudgetProposal(std::string strProposalNameIn, std::string strU
|
|||||||
nBlockEnd = nBlockEndIn;
|
nBlockEnd = nBlockEndIn;
|
||||||
address = addressIn;
|
address = addressIn;
|
||||||
nAmount = nAmountIn;
|
nAmount = nAmountIn;
|
||||||
nTime = nTimeIn;
|
|
||||||
nFeeTXHash = nFeeTXHashIn;
|
nFeeTXHash = nFeeTXHashIn;
|
||||||
fValid = true;
|
fValid = true;
|
||||||
}
|
}
|
||||||
@ -1143,14 +1144,7 @@ bool CBudgetProposal::IsValid(std::string& strError, bool fCheckCollateral)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(fCheckCollateral){
|
if(fCheckCollateral){
|
||||||
if(!IsBudgetCollateralValid(nFeeTXHash, GetHash(), strError)){
|
if(!IsBudgetCollateralValid(nFeeTXHash, GetHash(), strError, nTime)){
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(masternodeSync.IsSynced()) {
|
|
||||||
if(nTime < GetTime() - (60*60*2) || nTime < GetTime() - (60*60)) {
|
|
||||||
strError = "Time is out of acceptable range.";
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1341,8 +1335,8 @@ CBudgetProposalBroadcast::CBudgetProposalBroadcast()
|
|||||||
nBlockStart = 0;
|
nBlockStart = 0;
|
||||||
nBlockEnd = 0;
|
nBlockEnd = 0;
|
||||||
nAmount = 0;
|
nAmount = 0;
|
||||||
nTime = 0;
|
|
||||||
nFeeTXHash = 0;
|
nFeeTXHash = 0;
|
||||||
|
nTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
CBudgetProposalBroadcast::CBudgetProposalBroadcast(const CBudgetProposal& other)
|
CBudgetProposalBroadcast::CBudgetProposalBroadcast(const CBudgetProposal& other)
|
||||||
@ -1357,7 +1351,7 @@ CBudgetProposalBroadcast::CBudgetProposalBroadcast(const CBudgetProposal& other)
|
|||||||
nTime = other.nTime;
|
nTime = other.nTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
CBudgetProposalBroadcast::CBudgetProposalBroadcast(std::string strProposalNameIn, std::string strURLIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int nBlockStartIn, uint256 nFeeTXHashIn, int64_t nTimeIn)
|
CBudgetProposalBroadcast::CBudgetProposalBroadcast(std::string strProposalNameIn, std::string strURLIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int nBlockStartIn, uint256 nFeeTXHashIn)
|
||||||
{
|
{
|
||||||
strProposalName = strProposalNameIn;
|
strProposalName = strProposalNameIn;
|
||||||
strURL = strURLIn;
|
strURL = strURLIn;
|
||||||
@ -1372,8 +1366,6 @@ CBudgetProposalBroadcast::CBudgetProposalBroadcast(std::string strProposalNameIn
|
|||||||
nAmount = nAmountIn;
|
nAmount = nAmountIn;
|
||||||
|
|
||||||
nFeeTXHash = nFeeTXHashIn;
|
nFeeTXHash = nFeeTXHashIn;
|
||||||
|
|
||||||
nTime = nTimeIn;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBudgetProposalBroadcast::Relay()
|
void CBudgetProposalBroadcast::Relay()
|
||||||
@ -1458,6 +1450,7 @@ CFinalizedBudget::CFinalizedBudget()
|
|||||||
vecBudgetPayments.clear();
|
vecBudgetPayments.clear();
|
||||||
mapVotes.clear();
|
mapVotes.clear();
|
||||||
nFeeTXHash = 0;
|
nFeeTXHash = 0;
|
||||||
|
nTime = 0;
|
||||||
fValid = true;
|
fValid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1468,6 +1461,7 @@ CFinalizedBudget::CFinalizedBudget(const CFinalizedBudget& other)
|
|||||||
vecBudgetPayments = other.vecBudgetPayments;
|
vecBudgetPayments = other.vecBudgetPayments;
|
||||||
mapVotes = other.mapVotes;
|
mapVotes = other.mapVotes;
|
||||||
nFeeTXHash = other.nFeeTXHash;
|
nFeeTXHash = other.nFeeTXHash;
|
||||||
|
nTime = other.nTime;
|
||||||
fValid = true;
|
fValid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1652,7 +1646,7 @@ bool CFinalizedBudget::IsValid(std::string& strError, bool fCheckCollateral)
|
|||||||
|
|
||||||
std::string strError2 = "";
|
std::string strError2 = "";
|
||||||
if(fCheckCollateral){
|
if(fCheckCollateral){
|
||||||
if(!IsBudgetCollateralValid(nFeeTXHash, GetHash(), strError2)){
|
if(!IsBudgetCollateralValid(nFeeTXHash, GetHash(), strError2, nTime)){
|
||||||
{strError = "Invalid Collateral : " + strError2; return false;}
|
{strError = "Invalid Collateral : " + strError2; return false;}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ void DumpBudgets();
|
|||||||
int GetBudgetPaymentCycleBlocks();
|
int GetBudgetPaymentCycleBlocks();
|
||||||
|
|
||||||
//Check the collateral transaction for the budget proposal/finalized budget
|
//Check the collateral transaction for the budget proposal/finalized budget
|
||||||
bool IsBudgetCollateralValid(uint256 nTxCollateralHash, uint256 nExpectedHash, std::string& strError);
|
bool IsBudgetCollateralValid(uint256 nTxCollateralHash, uint256 nExpectedHash, std::string& strError, int64_t& nTime);
|
||||||
|
|
||||||
/** Save Budget Manager (budget.dat)
|
/** Save Budget Manager (budget.dat)
|
||||||
*/
|
*/
|
||||||
@ -208,6 +208,7 @@ public:
|
|||||||
std::vector<CTxBudgetPayment> vecBudgetPayments;
|
std::vector<CTxBudgetPayment> vecBudgetPayments;
|
||||||
map<uint256, CFinalizedBudgetVote> mapVotes;
|
map<uint256, CFinalizedBudgetVote> mapVotes;
|
||||||
uint256 nFeeTXHash;
|
uint256 nFeeTXHash;
|
||||||
|
int64_t nTime;
|
||||||
|
|
||||||
CFinalizedBudget();
|
CFinalizedBudget();
|
||||||
CFinalizedBudget(const CFinalizedBudget& other);
|
CFinalizedBudget(const CFinalizedBudget& other);
|
||||||
@ -276,6 +277,7 @@ public:
|
|||||||
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||||
READWRITE(LIMITED_STRING(strBudgetName, 20));
|
READWRITE(LIMITED_STRING(strBudgetName, 20));
|
||||||
READWRITE(nFeeTXHash);
|
READWRITE(nFeeTXHash);
|
||||||
|
READWRITE(nTime);
|
||||||
READWRITE(nBlockStart);
|
READWRITE(nBlockStart);
|
||||||
READWRITE(vecBudgetPayments);
|
READWRITE(vecBudgetPayments);
|
||||||
|
|
||||||
@ -381,7 +383,7 @@ public:
|
|||||||
|
|
||||||
CBudgetProposal();
|
CBudgetProposal();
|
||||||
CBudgetProposal(const CBudgetProposal& other);
|
CBudgetProposal(const CBudgetProposal& other);
|
||||||
CBudgetProposal(std::string strProposalNameIn, std::string strURLIn, int nBlockStartIn, int nBlockEndIn, CScript addressIn, CAmount nAmountIn, uint256 nFeeTXHashIn, int64_t nTimeIn);
|
CBudgetProposal(std::string strProposalNameIn, std::string strURLIn, int nBlockStartIn, int nBlockEndIn, CScript addressIn, CAmount nAmountIn, uint256 nFeeTXHashIn);
|
||||||
|
|
||||||
void Calculate();
|
void Calculate();
|
||||||
bool AddOrUpdateVote(CBudgetVote& vote, std::string& strError);
|
bool AddOrUpdateVote(CBudgetVote& vote, std::string& strError);
|
||||||
@ -413,7 +415,6 @@ public:
|
|||||||
int GetNays();
|
int GetNays();
|
||||||
int GetAbstains();
|
int GetAbstains();
|
||||||
CAmount GetAmount() {return nAmount;}
|
CAmount GetAmount() {return nAmount;}
|
||||||
|
|
||||||
void SetAllotted(CAmount nAllotedIn) {nAlloted = nAllotedIn;}
|
void SetAllotted(CAmount nAllotedIn) {nAlloted = nAllotedIn;}
|
||||||
CAmount GetAllotted() {return nAlloted;}
|
CAmount GetAllotted() {return nAlloted;}
|
||||||
|
|
||||||
@ -423,7 +424,6 @@ public:
|
|||||||
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
|
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
|
||||||
ss << strProposalName;
|
ss << strProposalName;
|
||||||
ss << strURL;
|
ss << strURL;
|
||||||
ss << nTime;
|
|
||||||
ss << nBlockStart;
|
ss << nBlockStart;
|
||||||
ss << nBlockEnd;
|
ss << nBlockEnd;
|
||||||
ss << nAmount;
|
ss << nAmount;
|
||||||
@ -462,7 +462,7 @@ private:
|
|||||||
public:
|
public:
|
||||||
CBudgetProposalBroadcast();
|
CBudgetProposalBroadcast();
|
||||||
CBudgetProposalBroadcast(const CBudgetProposal& other);
|
CBudgetProposalBroadcast(const CBudgetProposal& other);
|
||||||
CBudgetProposalBroadcast(std::string strProposalNameIn, std::string strURLIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int nBlockStartIn, uint256 nFeeTXHashIn, int64_t nTimeIn);
|
CBudgetProposalBroadcast(std::string strProposalNameIn, std::string strURLIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int nBlockStartIn, uint256 nFeeTXHashIn);
|
||||||
|
|
||||||
void Relay();
|
void Relay();
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ Value mnbudget(const Array& params, bool fHelp)
|
|||||||
//*************************************************************************
|
//*************************************************************************
|
||||||
|
|
||||||
// create transaction 15 minutes into the future, to allow for confirmation time
|
// create transaction 15 minutes into the future, to allow for confirmation time
|
||||||
CBudgetProposalBroadcast budgetProposalBroadcast(strProposalName, strURL, nPaymentCount, scriptPubKey, nAmount, nBlockStart, 0, GetAdjustedTime()+(60*15));
|
CBudgetProposalBroadcast budgetProposalBroadcast(strProposalName, strURL, nPaymentCount, scriptPubKey, nAmount, nBlockStart, 0);
|
||||||
|
|
||||||
std::string strError = "";
|
std::string strError = "";
|
||||||
if(!budgetProposalBroadcast.IsValid(strError, false))
|
if(!budgetProposalBroadcast.IsValid(strError, false))
|
||||||
@ -113,12 +113,7 @@ Value mnbudget(const Array& params, bool fHelp)
|
|||||||
//send the tx to the network
|
//send the tx to the network
|
||||||
pwalletMain->CommitTransaction(wtx, reservekey, useIX ? "ix" : "tx");
|
pwalletMain->CommitTransaction(wtx, reservekey, useIX ? "ix" : "tx");
|
||||||
|
|
||||||
|
return wtx.GetHash().ToString();
|
||||||
Object returnObj;
|
|
||||||
returnObj.push_back(Pair("fee_tx", wtx.GetHash().ToString()));
|
|
||||||
returnObj.push_back(Pair("time", (int64_t)budgetProposalBroadcast.nTime));
|
|
||||||
|
|
||||||
return returnObj;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strCommand == "submit")
|
if(strCommand == "submit")
|
||||||
@ -129,8 +124,8 @@ Value mnbudget(const Array& params, bool fHelp)
|
|||||||
std::vector<CMasternodeConfig::CMasternodeEntry> mnEntries;
|
std::vector<CMasternodeConfig::CMasternodeEntry> mnEntries;
|
||||||
mnEntries = masternodeConfig.getEntries();
|
mnEntries = masternodeConfig.getEntries();
|
||||||
|
|
||||||
if (params.size() != 9)
|
if (params.size() != 8)
|
||||||
throw runtime_error("Correct usage is 'mnbudget submit proposal-name url payment_count block_start dash_address monthly_payment_dash fee_tx nTime'");
|
throw runtime_error("Correct usage is 'mnbudget submit proposal-name url payment_count block_start dash_address monthly_payment_dash fee_tx'");
|
||||||
|
|
||||||
// Check these inputs the same way we check the vote commands:
|
// Check these inputs the same way we check the vote commands:
|
||||||
// **********************************************************
|
// **********************************************************
|
||||||
@ -172,16 +167,12 @@ Value mnbudget(const Array& params, bool fHelp)
|
|||||||
CScript scriptPubKey = GetScriptForDestination(address.Get());
|
CScript scriptPubKey = GetScriptForDestination(address.Get());
|
||||||
CAmount nAmount = AmountFromValue(params[6]);
|
CAmount nAmount = AmountFromValue(params[6]);
|
||||||
uint256 hash = ParseHashV(params[7], "parameter 1");
|
uint256 hash = ParseHashV(params[7], "parameter 1");
|
||||||
int64_t nTime = params[8].get_int();
|
|
||||||
|
|
||||||
if(nTime < GetTime() - (60*60*2) || nTime > GetTime() + (60*60))
|
|
||||||
return "nTime is out of range, you must submit the proposal within 2 hours of creating the original colateral transaction";
|
|
||||||
|
|
||||||
//create the proposal incase we're the first to make it
|
//create the proposal incase we're the first to make it
|
||||||
CBudgetProposalBroadcast budgetProposalBroadcast(strProposalName, strURL, nPaymentCount, scriptPubKey, nAmount, nBlockStart, hash, nTime);
|
CBudgetProposalBroadcast budgetProposalBroadcast(strProposalName, strURL, nPaymentCount, scriptPubKey, nAmount, nBlockStart, hash);
|
||||||
|
|
||||||
std::string strError = "";
|
std::string strError = "";
|
||||||
if(!IsBudgetCollateralValid(hash, budgetProposalBroadcast.GetHash(), strError)){
|
if(!IsBudgetCollateralValid(hash, budgetProposalBroadcast.GetHash(), strError, budgetProposalBroadcast.nTime)){
|
||||||
return "Proposal FeeTX is not valid - " + hash.ToString() + " - " + strError;
|
return "Proposal FeeTX is not valid - " + hash.ToString() + " - " + strError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user