Skip to content

Commit

Permalink
Merge pull request #7 from WG91/master
Browse files Browse the repository at this point in the history
Include treasury (dev fee)
  • Loading branch information
worxcoin authored Apr 24, 2019
2 parents 33758e8 + 0d4f502 commit 15180a8
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 40 deletions.
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N)
AC_PREREQ([2.60])
define(_CLIENT_VERSION_MAJOR, 1)
define(_CLIENT_VERSION_MINOR, 3)
define(_CLIENT_VERSION_MINOR, 5)
define(_CLIENT_VERSION_REVISION, 0)
define(_CLIENT_VERSION_BUILD, 2)
define(_CLIENT_VERSION_BUILD, 1)
define(_CLIENT_VERSION_IS_RELEASE, true)
define(_COPYRIGHT_YEAR, 2018)
AC_INIT([Worx Core],[_CLIENT_VERSION_MAJOR._CLIENT_VERSION_MINOR._CLIENT_VERSION_REVISION],[http://www.worxcoin.io],[worx])
Expand Down
4 changes: 4 additions & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class CMainParams : public CChainParams
nMasternodeColleteralLimxDev = 5000; //Params().MasternodeColleteralLimxDev()
nModifierUpdateBlock = 1; // we use the version 2 for dmd
nMaxMoneyOut = 21000000 * COIN;
strDeveloperFeePayee = "WaX6WwwB8C5s5WRxCQzNpo6CAEL5uhFoAG";

const char* pszTimestamp = "29th April - Worx Birthday YAY!";
CMutableTransaction txNew;
Expand Down Expand Up @@ -206,6 +207,7 @@ class CTestNetParams : public CMainParams
nMaturity = 15;
nModifierUpdateBlock = 51197; //approx Mon, 30 Apr 2018 04:00:00 GMT
nMaxMoneyOut = 90000000 * COIN;
strDeveloperFeePayee = "---";

//! Modify the testnet genesis block so the timestamp is valid for a later start.
genesis.nTime = 1524956401;
Expand Down Expand Up @@ -280,6 +282,7 @@ class CRegTestParams : public CTestNetParams
genesis.nTime = 1524956405;
genesis.nBits = 0x207fffff;
genesis.nNonce = 20542301;
strDeveloperFeePayee = "---";

hashGenesisBlock = genesis.GetHash();

Expand Down Expand Up @@ -316,6 +319,7 @@ class CUnitTestParams : public CMainParams, public CModifiableParams
networkID = CBaseChainParams::UNITTEST;
strNetworkID = "unittest";
nDefaultPort = 3310;
strDeveloperFeePayee = "---";
vFixedSeeds.clear(); //! Unit test mode doesn't have any fixed seeds.
vSeeds.clear(); //! Unit test mode doesn't have any DNS seeds.

Expand Down
2 changes: 2 additions & 0 deletions src/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class CChainParams
std::string DarksendPoolDummyAddress() const { return strDarksendPoolDummyAddress; }
int64_t StartMasternodePayments() const { return nStartMasternodePayments; }
CBaseChainParams::Network NetworkID() const { return networkID; }
std::string GetDeveloperFeePayee() const { return strDeveloperFeePayee; }

protected:
CChainParams() {}
Expand Down Expand Up @@ -139,6 +140,7 @@ class CChainParams
std::string strSporkKey;
std::string strDarksendPoolDummyAddress;
int64_t nStartMasternodePayments;
std::string strDeveloperFeePayee;
};

/**
Expand Down
4 changes: 2 additions & 2 deletions src/clientversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

//! These need to be macros, as clientversion.cpp's and worx*-res.rc's voodoo requires it
#define CLIENT_VERSION_MAJOR 1
#define CLIENT_VERSION_MINOR 2
#define CLIENT_VERSION_MINOR 5
#define CLIENT_VERSION_REVISION 0
#define CLIENT_VERSION_BUILD 0
//bitcoingui.cpp L116
Expand All @@ -26,7 +26,7 @@
* Copyright year (2009-this)
* Todo: update this when changing our copyright comments in the source
*/
#define COPYRIGHT_YEAR 2018
#define COPYRIGHT_YEAR 2019

#endif //HAVE_CONFIG_H

Expand Down
8 changes: 4 additions & 4 deletions src/config/worx-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
#define CLIENT_VERSION_MAJOR 1

/* Minor version */
#define CLIENT_VERSION_MINOR 4
#define CLIENT_VERSION_MINOR 5

/* Build revision */
#define CLIENT_VERSION_REVISION 1
#define CLIENT_VERSION_REVISION 0

/* Version is release */
#define COPYRIGHT_YEAR 2019
Expand Down Expand Up @@ -280,7 +280,7 @@
#define PACKAGE_NAME "Worx Core"

/* Define to the full name and version of this package. */
#define PACKAGE_STRING "Worx Core 1.4.1"
#define PACKAGE_STRING "Worx Core 1.5.0"

/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "worx"
Expand All @@ -289,7 +289,7 @@
#define PACKAGE_URL ""

/* Define to the version of this package. */
#define PACKAGE_VERSION "1.4.1"
#define PACKAGE_VERSION "1.5.0"

/* Define to necessary symbol if this constant uses a non-standard name on
your system. */
Expand Down
5 changes: 4 additions & 1 deletion src/masternode-budget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ int GetBudgetPaymentCycleBlocks()
if (Params().NetworkID() == CBaseChainParams::MAIN) return 43200;
//for testing purposes

return 144; //ten times per day
return 14; //every 14 blocks
}

bool IsBudgetCollateralValid(uint256 nTxCollateralHash, uint256 nExpectedHash, std::string& strError, int64_t& nTime, int& nConf)
Expand Down Expand Up @@ -832,6 +832,9 @@ CAmount CBudgetManager::GetTotalBudget(int nHeight)
return ((nSubsidy / 100) * 10) * 1440 * 30;
}
*/
CAmount nSubsidy = GetBlockValue(nHeight);
// Amount of blocks in a months period of time (using 1 minute per) = (60*24*30)
return ((nSubsidy / 100) * 10) * 60 * 24 * 30;
}

void CBudgetManager::NewBlock()
Expand Down
74 changes: 54 additions & 20 deletions src/masternode-payments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <boost/filesystem.hpp>
#include <boost/lexical_cast.hpp>

#define DEV_FEE_BLOCK_ACTIVATION 534100 // roughly 07:45:00 UTC 17th of May 2019

/** Object for who's going to get paid on which blocks */
CMasternodePayments masternodePayments;

Expand Down Expand Up @@ -298,45 +300,58 @@ void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, int64_t nFe
hasPayment = false;
}
}

CAmount blockValue = GetBlockValue(pindexPrev->nHeight +1 );
CAmount masternodePayment = GetMasternodePayment(pindexPrev->nHeight +1, blockValue);

if (hasPayment) {
double devfeePercent = pindexPrev->nHeight + 1 >= DEV_FEE_BLOCK_ACTIVATION ? 0.10 : 0.00;

CAmount blockValue = GetBlockValue(pindexPrev->nHeight + 1);
CAmount masternodePayment = GetMasternodePayment(pindexPrev->nHeight + 1, blockValue);
CAmount developerfeeTotal = blockValue * devfeePercent;
CAmount developerfeeMasternode = masternodePayment * devfeePercent;
masternodePayment -= developerfeeMasternode;

//TEMPORARY FIX
if(pindexPrev->nHeight +1 > 151200 && pindexPrev->nHeight +1 <= 152500) {
masternodePayment = GetMasternodePayment(152501, blockValue);
}

if (hasPayment) {
CBitcoinAddress developerfeeaddress(Params().GetDeveloperFeePayee());
CScript developerfeescriptpubkey = GetScriptForDestination(developerfeeaddress.Get());
if (fProofOfStake) {
/**For Proof Of Stake vout[0] must be null
* Stake reward can be split into many different outputs, so we must
* use vout.size() to align with several different cases.
* An additional output is appended as the masternode payment
*/
unsigned int i = txNew.vout.size();
txNew.vout.resize(i + 1);
txNew.vout.resize(i + 2);
txNew.vout[i+1].scriptPubKey = developerfeescriptpubkey;
txNew.vout[i+1].nValue = developerfeeTotal;
txNew.vout[i].scriptPubKey = payee;
txNew.vout[i].nValue = masternodePayment;

//subtract mn payment from the stake reward
txNew.vout[i - 1].nValue -= masternodePayment;
LogPrintf("fProofOfStake: masternode to pay value %u\n", masternodePayment);
txNew.vout[i - 1].nValue = txNew.vout[i - 1].nValue - masternodePayment - developerfeeTotal; // TODO
} else {
txNew.vout.resize(2);
txNew.vout.resize(3);
txNew.vout[2].scriptPubKey = developerfeescriptpubkey;
txNew.vout[2].nValue = developerfeeTotal;
txNew.vout[1].scriptPubKey = payee;
txNew.vout[1].nValue = masternodePayment;
LogPrintf("CreateNewBlock: masternode to pay value %u\n", masternodePayment);
txNew.vout[0].nValue = blockValue - masternodePayment;
LogPrintf("CreateNewBlock: blockvalue to pay value %u\n", blockValue);
txNew.vout[0].nValue = blockValue - masternodePayment - developerfeeTotal;
}

CTxDestination address1;
ExtractDestination(payee, address1);
CBitcoinAddress address2(address1);

CTxDestination addressdevfee1;
ExtractDestination(developerfeescriptpubkey, addressdevfee1);
CBitcoinAddress addressdevfee2(addressdevfee1);


LogPrintf("Masternode payment of %s to %s\n", FormatMoney(masternodePayment).c_str(), address2.ToString().c_str());
LogPrintf("DeveloperFee payment of %s to %s\n", FormatMoney(developerfeeTotal).c_str(), addressdevfee2.ToString().c_str());
}

}

int CMasternodePayments::GetMinMasternodePaymentsProto()
Expand Down Expand Up @@ -539,7 +554,12 @@ bool CMasternodeBlockPayees::IsTransactionValid(const CTransaction& txNew)
nMasternode_Drift_Count = mnodeman.size() + Params().MasternodeCountDrift();
}

CAmount requiredMasternodePayment = GetMasternodePayment(nBlockHeight, nReward, nMasternode_Drift_Count);
CBitcoinAddress developerfeeaddress(Params().GetDeveloperFeePayee());
CScript developerfeescriptpubkey = GetScriptForDestination(developerfeeaddress.Get());

double devfeePercent = nBlockHeight >= DEV_FEE_BLOCK_ACTIVATION ? 0.10 : 0.00;
CAmount requiredMasternodePayment = GetMasternodePayment(nBlockHeight, nReward, nMasternode_Drift_Count) * (1 - devfeePercent);
CAmount requiredDeveloperPayment = nReward * devfeePercent;

//require at least 6 signatures
BOOST_FOREACH (CMasternodePayee& payee, vecPayments)
Expand All @@ -549,8 +569,19 @@ bool CMasternodeBlockPayees::IsTransactionValid(const CTransaction& txNew)
// if we don't have at least 6 signatures on a payee, approve whichever is the longest chain
if (nMaxSignatures < MNPAYMENTS_SIGNATURES_REQUIRED) return true;

BOOST_FOREACH (CMasternodePayee& payee, vecPayments) {
bool foundDevFee = nBlockHeight < DEV_FEE_BLOCK_ACTIVATION;
BOOST_FOREACH (CTxOut out, txNew.vout) {
if(out.scriptPubKey == developerfeescriptpubkey) {
if(out.nValue >= requiredDeveloperPayment) {
foundDevFee = true;
LogPrintf("Developer-Fee Payment found! Thanks for supporting Worx!");
}
}
}

BOOST_FOREACH (CMasternodePayee& payee, vecPayments) {
bool found = false;

BOOST_FOREACH (CTxOut out, txNew.vout) {
if (payee.scriptPubKey == out.scriptPubKey) {
if(out.nValue >= requiredMasternodePayment)
Expand All @@ -561,7 +592,7 @@ bool CMasternodeBlockPayees::IsTransactionValid(const CTransaction& txNew)
}

if (payee.nVotes >= MNPAYMENTS_SIGNATURES_REQUIRED) {
if (found) return true;
if (found && foundDevFee) return true;

CTxDestination address1;
ExtractDestination(payee.scriptPubKey, address1);
Expand All @@ -575,7 +606,11 @@ bool CMasternodeBlockPayees::IsTransactionValid(const CTransaction& txNew)
}
}

LogPrintf("CMasternodePayments::IsTransactionValid - Missing required payment of %s to %s\n", FormatMoney(requiredMasternodePayment).c_str(), strPayeesPossible.c_str());
if(foundDevFee)
LogPrintf("CMasternodePayments::IsTransactionValid - Missing required payment of %s to %s\n", FormatMoney(requiredMasternodePayment).c_str(), strPayeesPossible.c_str());
else
LogPrintf("CMasternodePayments::IsTransactionValid - Missing developerfee of %s\n", FormatMoney(requiredDeveloperPayment).c_str());

return false;
}

Expand Down Expand Up @@ -847,9 +882,8 @@ int CMasternodePayments::GetNewestBlock()
while (it != mapMasternodeBlocks.end()) {
if ((*it).first > nNewestBlock) {
nNewestBlock = (*it).first;
}
}
it++;
}

}
return nNewestBlock;
}
9 changes: 6 additions & 3 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,13 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet,
}
}

if (!fProofOfStake) {
//Masternode and general budget payments
FillBlockPayee(txNew, nFees, fProofOfStake);
//Masternode and general budget payments
FillBlockPayee(txNew, nFees, fProofOfStake);

//lost-fee-issue
txNew.vout[0].nValue += nFees;

if (!fProofOfStake) {
//Make payee
if (txNew.vout.size() > 1) {
pblock->payee = txNew.vout[1].scriptPubKey;
Expand Down
6 changes: 3 additions & 3 deletions src/pow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
bnNew = Params().ProofOfWorkLimit();
}

LogPrintf("GetNextWorkRequired RETARGET\n");
LogPrintf("nActualTimespan = %d\n", nActualTimespan);
LogPrintf("After: %08x %s\n", bnNew.GetCompact(), bnNew.ToString());
//LogPrintf("GetNextWorkRequired RETARGET\n");
//LogPrintf("nActualTimespan = %d\n", nActualTimespan);
//LogPrintf("After: %08x %s\n", bnNew.GetCompact(), bnNew.ToString());

return bnNew.GetCompact();
}
Expand Down
2 changes: 1 addition & 1 deletion src/rpcclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ static const CRPCConvertParam vRPCConvertParams[] =
{"prioritisetransaction", 1},
{"prioritisetransaction", 2},
{"spork", 1},
{"mnbudget", 3},
{"mnbudget", 4},
{"mnbudget", 6},
{"mnbudget", 8},
{"mnbudgetvoteraw", 1},
{"mnbudgetvoteraw", 4},
{"reservebalance", 0},
Expand Down
2 changes: 2 additions & 0 deletions src/rpcmining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,8 @@ Value getblocktemplate(const Array& params, bool fHelp)
result.push_back(Pair("masternode_payments", pblock->nTime > Params().StartMasternodePayments()));
result.push_back(Pair("enforce_masternode_payments", true));

result.push_back(Pair("developerfee_amount", (int64_t)pblock->vtx[0].vout[2].nValue));
result.push_back(Pair("developerfee_wallet", Params().GetDeveloperFeePayee()));
return result;
}

Expand Down
8 changes: 4 additions & 4 deletions src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* network protocol versioning
*/

static const int PROTOCOL_VERSION = 70719;
static const int PROTOCOL_VERSION = 70720;

//! initial proto version, to be increased after version/verack negotiation
static const int INIT_PROTO_VERSION = 210;
Expand All @@ -21,9 +21,9 @@ static const int INIT_PROTO_VERSION = 210;
static const int GETHEADERS_VERSION = 70077;

//! disconnect from peers older than this proto version
static const int MIN_PEER_PROTO_VERSION_BEFORE_ENFORCEMENT = 70718;
static const int MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT = 70718;
static const int MIN_PEER_PROTO_VERSION_AFTER_BLOCK_201601 = 70718;
static const int MIN_PEER_PROTO_VERSION_BEFORE_ENFORCEMENT = 70719;
static const int MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT = 70719;
static const int MIN_PEER_PROTO_VERSION_AFTER_BLOCK_201601 = 70719;

//! nTime field added to CAddress, starting with this version;
//! if possible, avoid requesting addresses nodes older than this
Expand Down

0 comments on commit 15180a8

Please sign in to comment.