Fixed governance object submission issues (#812)
- Cleaned up governance object / added comments
This commit is contained in:
parent
7f52065c38
commit
5411d78b11
@ -564,29 +564,24 @@ CGovernanceObject::CGovernanceObject()
|
||||
|
||||
}
|
||||
|
||||
CGovernanceObject::CGovernanceObject(uint256 nHashParentIn, int nRevisionIn, std::string strNameIn, int64_t nTime, uint256 nFeeTXHashIn)
|
||||
CGovernanceObject::CGovernanceObject(uint256 nHashParentIn, int nRevisionIn, std::string strNameIn, int64_t nTimeIn, uint256 nFeeTXHashIn)
|
||||
{
|
||||
strName = "unknown";
|
||||
nTime = 0;
|
||||
|
||||
nHashParent = nHashParentIn; //parent object, 0 is root
|
||||
// nPriority = nPriorityIn;
|
||||
nRevision = nRevisionIn; //object revision in the system
|
||||
strName = strNameIn;
|
||||
nTime = nTimeIn;
|
||||
nFeeTXHash = nFeeTXHashIn; //fee-tx
|
||||
// nTypeVersion = nTypeVersionIn;
|
||||
}
|
||||
|
||||
CGovernanceObject::CGovernanceObject(const CGovernanceObject& other)
|
||||
{
|
||||
// COPY OTHER OBJECT'S DATA INTO THIS OBJECT
|
||||
|
||||
nHashParent = other.nHashParent;
|
||||
nRevision = other.nRevision;
|
||||
strName = other.strName;
|
||||
nTime = other.nTime;
|
||||
|
||||
nHashParent = other.nHashParent; //parent object, 0 is root
|
||||
// nPriority = other.nPriorityIn;
|
||||
nRevision = other.nRevision; //object revision in the system
|
||||
nFeeTXHash = other.nFeeTXHash; //fee-tx
|
||||
// nTypeVersion = other.nTypeVersion;
|
||||
//??
|
||||
nFeeTXHash = other.nFeeTXHash;
|
||||
strData = other.strData;
|
||||
}
|
||||
|
||||
|
@ -182,22 +182,20 @@ public:
|
||||
void UpdateLocalValidity(const CBlockIndex *pCurrentBlockIndex) {fCachedLocalValidity = IsValid(pCurrentBlockIndex, strLocalValidityError);};
|
||||
void UpdateSentinelVariables(const CBlockIndex *pCurrentBlockIndex)
|
||||
{
|
||||
/*
|
||||
#define VOTE_SIGNAL_FUNDING 1 // -- fund this object for it's stated amount
|
||||
#define VOTE_SIGNAL_VALID 2 // -- this object checks out to sentinel
|
||||
#define VOTE_SIGNAL_DELETE 3 // -- this object should be deleted from memory entirely
|
||||
#define VOTE_SIGNAL_ENDORSED 5 // -- officially endorsed by the network somehow (delegation)
|
||||
*/
|
||||
// CALCULATE MINIMUM SUPPORT LEVELS REQUIRED
|
||||
|
||||
int nMnCount = mnodeman.CountEnabled();
|
||||
int nAbsYesVoteReq = nMnCount / 10;
|
||||
|
||||
// set all flags to false
|
||||
// SET SENTINEL FLAGS TO FALSE
|
||||
|
||||
fCachedFunding = false;
|
||||
fCachedValid = false;
|
||||
fCachedDelete = false;
|
||||
fCachedEndorsed = false;
|
||||
|
||||
// SET SENTINEL FLAGS TO TRUE IF MIMIMUM SUPPORT LEVELS ARE REACHED
|
||||
|
||||
if(GetAbsoluteYesCount(VOTE_SIGNAL_FUNDING) >= nAbsYesVoteReq) fCachedFunding = true;
|
||||
if(GetAbsoluteYesCount(VOTE_SIGNAL_VALID) >= nAbsYesVoteReq) fCachedValid = true;
|
||||
if(GetAbsoluteYesCount(VOTE_SIGNAL_DELETE) >= nAbsYesVoteReq) fCachedDelete = true;
|
||||
@ -242,13 +240,7 @@ public:
|
||||
|
||||
uint256 GetHash(){
|
||||
|
||||
/*
|
||||
uint256 nHashParent; //parent object, 0 is root
|
||||
int nRevision; //object revision in the system
|
||||
std::string strName; //org name, username, prop name, etc.
|
||||
int64_t nTime; //time this object was created
|
||||
uint256 nFeeTXHash; //fee-tx
|
||||
*/
|
||||
// CREATE HASH OF ALL IMPORTANT PIECES OF DATA
|
||||
|
||||
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
|
||||
ss << nHashParent;
|
||||
@ -256,27 +248,27 @@ public:
|
||||
ss << strName;
|
||||
ss << nTime;
|
||||
ss << strData;
|
||||
// fee_tx is left out on purpose
|
||||
uint256 h1 = ss.GetHash();
|
||||
|
||||
return h1;
|
||||
}
|
||||
|
||||
/**
|
||||
* AddRegister - Example usage:
|
||||
* SetData - Example usage:
|
||||
* --------------------------------------------------------
|
||||
*
|
||||
* We don't really care what's in these, as long as the masternode network
|
||||
* believes they're accurate. Otherwise the masternodes will vote them down
|
||||
* and we'll delete them from memory (fee-loss attack).
|
||||
*
|
||||
|
||||
* dash-core is data-agnostic, for rules about data see sentinel documentation
|
||||
*
|
||||
*/
|
||||
|
||||
bool SetData(std::string& strError, std::string strDataIn)
|
||||
{
|
||||
// (assumption) this is equal to pythons len(strData) > 512*4, I think
|
||||
// SET DATA FIELD TO INPUT
|
||||
|
||||
if(strDataIn.size() > 512*4)
|
||||
{
|
||||
// (assumption) this is equal to pythons len(strData) > 512*4, I think
|
||||
strError = "Too big.";
|
||||
return false;
|
||||
}
|
||||
@ -290,27 +282,7 @@ public:
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion)
|
||||
{
|
||||
/**
|
||||
* Store all major data items in serialization for other clients
|
||||
* --
|
||||
*
|
||||
*
|
||||
* uint256 nHashParent; //parent object, 0 is root
|
||||
* int nRevision; //object revision in the system
|
||||
* std::string strName; //org name, username, prop name, etc.
|
||||
* int64_t nTime; //time this object was created
|
||||
* uint256 nFeeTXHash; //fee-tx
|
||||
*
|
||||
* // caching
|
||||
* bool fValid;
|
||||
* uint256 nHash;
|
||||
*
|
||||
* // Registers, these can be used for anything
|
||||
* // -- check governance wiki for correct usage
|
||||
* std::map<int, CGovernanceObjectRegister> mapRegister;
|
||||
*
|
||||
*
|
||||
*/
|
||||
// SERIALIZE DATA FOR SAVING/LOADING OR NETWORK FUNCTIONS
|
||||
|
||||
READWRITE(nHashParent);
|
||||
READWRITE(nRevision);
|
||||
|
@ -82,11 +82,31 @@ UniValue mngovernance(const UniValue& params, bool fHelp)
|
||||
" vote-alias - Vote on a governance object by masternode alias\n"
|
||||
);
|
||||
|
||||
|
||||
/*
|
||||
|
||||
|
||||
12.1 todo -
|
||||
|
||||
|
||||
Example Governance Item
|
||||
- This should be valid for anyone to submit
|
||||
- This should propagate and show up when syncing
|
||||
|
||||
|
||||
Command:
|
||||
mngovernance submit 71cd63efd90bb33bae023065b105a597168c0e126dc07e68693854f132f73997 0 1 1463588860 "beer-reimbursement"
|
||||
|
||||
|
||||
*/
|
||||
|
||||
if(strCommand == "prepare")
|
||||
{
|
||||
if (params.size() != 6)
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mngovernance prepare <parent-hash> <revision> <time> <name> <registers-hex>'");
|
||||
|
||||
// ASSEMBLE NEW GOVERNANCE OBJECT FROM USER PARAMETERS
|
||||
|
||||
LOCK(cs_main);
|
||||
CBlockIndex* pindex = chainActive.Tip();
|
||||
|
||||
@ -94,7 +114,9 @@ UniValue mngovernance(const UniValue& params, bool fHelp)
|
||||
mnEntries = masternodeConfig.getEntries();
|
||||
|
||||
uint256 hashParent;
|
||||
if(params[1].get_str() == "0") { // attach to root node (root node doesn't really exist, but has a hash of zero)
|
||||
|
||||
// -- attach to root node (root node doesn't really exist, but has a hash of zero)
|
||||
if(params[1].get_str() == "0") {
|
||||
hashParent = uint256();
|
||||
} else {
|
||||
hashParent = ParseHashV(params[1], "fee-tx hash, parameter 1");
|
||||
@ -107,23 +129,22 @@ UniValue mngovernance(const UniValue& params, bool fHelp)
|
||||
std::string strName = SanitizeString(params[4].get_str());
|
||||
std::string strRegisters = params[5].get_str();
|
||||
|
||||
//*************************************************************************
|
||||
// CREATE A NEW COLLATERAL TRANSACTION FOR THIS SPECIFIC OBJECT
|
||||
|
||||
// create transaction 15 minutes into the future, to allow for confirmation time
|
||||
CGovernanceObject budgetProposalBroadcast(hashParent, nRevision, strName, nTime, uint256());
|
||||
CGovernanceObject govobj(hashParent, nRevision, strName, nTime, uint256());
|
||||
|
||||
std::string strError = "";
|
||||
if(!budgetProposalBroadcast.IsValid(pindex, strError, false))
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Governance object is not valid - " + budgetProposalBroadcast.GetHash().ToString() + " - " + strError);
|
||||
if(!govobj.IsValid(pindex, strError, false))
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Governance object is not valid - " + govobj.GetHash().ToString() + " - " + strError);
|
||||
|
||||
CWalletTx wtx;
|
||||
if(!pwalletMain->GetBudgetSystemCollateralTX(wtx, budgetProposalBroadcast.GetHash(), false)){
|
||||
if(!pwalletMain->GetBudgetSystemCollateralTX(wtx, govobj.GetHash(), false)){
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Error making collateral transaction for proposal. Please check your wallet balance and make sure your wallet is unlocked.");
|
||||
}
|
||||
|
||||
// make our change address
|
||||
// -- make our change address
|
||||
CReserveKey reservekey(pwalletMain);
|
||||
//send the tx to the network
|
||||
// -- send the tx to the network
|
||||
pwalletMain->CommitTransaction(wtx, reservekey, NetMsgType::TX);
|
||||
|
||||
return wtx.GetHash().ToString();
|
||||
@ -131,7 +152,6 @@ UniValue mngovernance(const UniValue& params, bool fHelp)
|
||||
|
||||
if(strCommand == "submit")
|
||||
{
|
||||
printf("%d\n", (int)params.size());
|
||||
if (params.size() != 7)
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mngovernance submit <fee-tx> <parent-hash> <revision> <time> <name> <registers-hex>'");
|
||||
|
||||
@ -139,6 +159,8 @@ UniValue mngovernance(const UniValue& params, bool fHelp)
|
||||
throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Must wait for client to sync with masternode network. Try again in a minute or so.");
|
||||
}
|
||||
|
||||
// ASSEMBLE NEW GOVERNANCE OBJECT FROM USER PARAMETERS
|
||||
|
||||
LOCK(cs_main);
|
||||
CBlockIndex* pindex = chainActive.Tip();
|
||||
|
||||
@ -160,23 +182,25 @@ UniValue mngovernance(const UniValue& params, bool fHelp)
|
||||
std::string strName = SanitizeString(params[5].get_str());
|
||||
std::string strRegisters = params[6].get_str();
|
||||
|
||||
CGovernanceObject budgetProposalBroadcast(hashParent, nRevision, strName, nTime, fee_tx);
|
||||
// CREATE A NEW COLLATERAL TRANSACTION FOR THIS SPECIFIC OBJECT
|
||||
|
||||
CGovernanceObject govobj(hashParent, nRevision, strName, nTime, fee_tx);
|
||||
|
||||
std::string strError = "";
|
||||
if(!budgetProposalBroadcast.IsValid(pindex, strError)){
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Governance object is not valid - " + budgetProposalBroadcast.GetHash().ToString() + " - " + strError);
|
||||
if(!govobj.IsValid(pindex, strError)){
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Governance object is not valid - " + govobj.GetHash().ToString() + " - " + strError);
|
||||
}
|
||||
|
||||
// int nConf = 0;
|
||||
// if(!IsCollateralValid(hash, budgetProposalBroadcast.GetHash(), strError, budgetProposalBroadcast.nTime, nConf, GOVERNANCE_FEE_TX)){
|
||||
// if(!IsCollateralValid(hash, govobj.GetHash(), strError, govobj.nTime, nConf, GOVERNANCE_FEE_TX)){
|
||||
// throw JSONRPCError(RPC_INTERNAL_ERROR, "Proposal FeeTX is not valid - " + hash.ToString() + " - " + strError);
|
||||
// }
|
||||
|
||||
governance.mapSeenGovernanceObjects.insert(make_pair(budgetProposalBroadcast.GetHash(), SEEN_OBJECT_IS_VALID));
|
||||
budgetProposalBroadcast.Relay();
|
||||
governance.AddGovernanceObject(budgetProposalBroadcast);
|
||||
governance.mapSeenGovernanceObjects.insert(make_pair(govobj.GetHash(), SEEN_OBJECT_IS_VALID));
|
||||
govobj.Relay();
|
||||
governance.AddGovernanceObject(govobj);
|
||||
|
||||
return budgetProposalBroadcast.GetHash().ToString();
|
||||
return govobj.GetHash().ToString();
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user