Skip to content

Commit

Permalink
Merge pull request #136 from carsenk/v2.5.2
Browse files Browse the repository at this point in the history
v2.5.2 Update
  • Loading branch information
metaspartan authored May 26, 2018
2 parents 8ded250 + 9b9189d commit 0e64cc0
Show file tree
Hide file tree
Showing 51 changed files with 2,280 additions and 1,094 deletions.
8 changes: 6 additions & 2 deletions denarius-qt.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
TEMPLATE = app
TARGET = Denarius
VERSION = 2.5.0.0
VERSION = 2.5.2.0
INCLUDEPATH += src src/json src/qt src/qt/plugins/mrichtexteditor
DEFINES += QT_GUI BOOST_THREAD_USE_LIB BOOST_SPIRIT_THREADSAFE
CONFIG += no_include_pwd
Expand All @@ -9,7 +9,7 @@ QT += core gui network widgets

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
lessThan(QT_MAJOR_VERSION, 5): CONFIG += static
QMAKE_CXXFLAGS = -fpermissive
QMAKE_CXXFLAGS += -fpermissive

greaterThan(QT_MAJOR_VERSION, 4) {
QT += widgets printsupport
Expand Down Expand Up @@ -77,6 +77,10 @@ contains(USE_QRCODE, 1) {
DEFINES += USE_QRCODE
LIBS += -lqrencode
}
contains(USE_PROFILER, 1) {
QMAKE_LFLAGS += -pg
QMAKE_CXXFLAGS += -pg
}

# use: qmake "USE_UPNP=1" ( enabled by default; default)
# or: qmake "USE_UPNP=0" (disabled by default)
Expand Down
72 changes: 70 additions & 2 deletions src/activemasternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "protocol.h"
#include "activemasternode.h"
#include "masternodeconfig.h"
#include <boost/lexical_cast.hpp>
#include "clientversion.h"

Expand Down Expand Up @@ -341,6 +342,55 @@ bool CActiveMasternode::GetMasterNodeVin(CTxIn& vin, CPubKey& pubkey, CKey& secr
return GetVinFromOutput(*selectedOutput, vin, pubkey, secretKey);
}

bool CActiveMasternode::GetMasterNodeVin(CTxIn& vin, CPubKey& pubkey, CKey& secretKey, std::string strTxHash, std::string strOutputIndex, std::string& errorMessage) {

// Find possible candidates
vector<COutput> possibleCoins = SelectCoinsMasternode(false);
COutput *selectedOutput;

// Find the vin
if(!strTxHash.empty()) {
// Let's find it
uint256 txHash(strTxHash);
int outputIndex = boost::lexical_cast<int>(strOutputIndex);
bool found = false;
BOOST_FOREACH(COutput& out, possibleCoins) {
if(out.tx->GetHash() == txHash && out.i == outputIndex)
{
if (out.tx->IsSpent(outputIndex))
{
errorMessage = "vin was spent";
return false;
}
selectedOutput = &out;
found = true;
break;
}
}
if(!found) {
errorMessage = "Could not locate valid vin";
return false;
}
} else {
// No output specified, Select the first one
if(possibleCoins.size() > 0) {
// May cause problems with multiple transactions.
selectedOutput = &possibleCoins[0];
} else {
errorMessage = "Could not locate specified vin from coins in wallet";
return false;
}
}

// At this point we have a selected output, retrieve the associated info
if (!GetVinFromOutput(*selectedOutput, vin, pubkey, secretKey))
{
errorMessage = "could not allocate vin";
return false;
}
return true;
}

bool CActiveMasternode::GetMasterNodeVinForPubKey(std::string collateralAddress, CTxIn& vin, CPubKey& pubkey, CKey& secretKey) {
return GetMasterNodeVinForPubKey(collateralAddress, vin, pubkey, secretKey, "", "");
}
Expand Down Expand Up @@ -413,13 +463,31 @@ bool CActiveMasternode::GetVinFromOutput(COutput out, CTxIn& vin, CPubKey& pubke
}

// get all possible outputs for running masternode
vector<COutput> CActiveMasternode::SelectCoinsMasternode()
vector<COutput> CActiveMasternode::SelectCoinsMasternode(bool fSelectUnlocked)
{
vector<COutput> vCoins;
vector<COutput> filteredCoins;
vector<COutPoint> confLockedCoins;

// Temporary unlock MN coins from masternode.conf
if(fSelectUnlocked && GetBoolArg("-mnconflock", true)) {
uint256 mnTxHash;
BOOST_FOREACH(CMasternodeConfig::CMasternodeEntry mne, masternodeConfig.getEntries()) {
mnTxHash.SetHex(mne.getTxHash());
COutPoint outpoint = COutPoint(mnTxHash, boost::lexical_cast<unsigned int>(mne.getOutputIndex()));
confLockedCoins.push_back(outpoint);
pwalletMain->UnlockCoin(outpoint);
}
}

// Retrieve all possible outputs
pwalletMain->AvailableCoinsMN(vCoins);
pwalletMain->AvailableCoinsMN(vCoins, true, fSelectUnlocked);

// Lock MN coins from masternode.conf back if they where temporary unlocked
if(!confLockedCoins.empty()) {
BOOST_FOREACH(COutPoint outpoint, confLockedCoins)
pwalletMain->LockCoin(outpoint);
}

// Filter
BOOST_FOREACH(const COutput& out, vCoins)
Expand Down
5 changes: 3 additions & 2 deletions src/activemasternode.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ class CActiveMasternode
// get 5000DNR input that can be used for the masternode
bool GetMasterNodeVin(CTxIn& vin, CPubKey& pubkey, CKey& secretKey);
bool GetMasterNodeVin(CTxIn& vin, CPubKey& pubkey, CKey& secretKey, std::string strTxHash, std::string strOutputIndex);
bool GetMasterNodeVin(CTxIn& vin, CPubKey& pubkey, CKey& secretKey, std::string strTxHash, std::string strOutputIndex, std::string& errorMessage);

bool GetMasterNodeVinForPubKey(std::string collateralAddress, CTxIn& vin, CPubKey& pubkey, CKey& secretKey);
bool GetMasterNodeVinForPubKey(std::string collateralAddress, CTxIn& vin, CPubKey& pubkey, CKey& secretKey, std::string strTxHash, std::string strOutputIndex);
vector<COutput> SelectCoinsMasternode();
vector<COutput> SelectCoinsMasternode(bool fSelectUnlocked=true);
vector<COutput> SelectCoinsMasternodeForPubKey(std::string collateralAddress);
bool GetVinFromOutput(COutput out, CTxIn& vin, CPubKey& pubkey, CKey& secretKey);

//bool SelectCoinsMasternode(CTxIn& vin, int64& nValueIn, CScript& pubScript, std::string strTxHash, std::string strOutputIndex);

// enable hot wallet mode (run a masternode with no funds)
Expand Down
1 change: 1 addition & 0 deletions src/bitcoinrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ static const CRPCCommand vRPCCommands[] =
{ "encryptwallet", &encryptwallet, false, false },
{ "validateaddress", &validateaddress, true, false },
{ "validatepubkey", &validatepubkey, true, false },
{ "fetchbalance", &fetchbalance, true, false },
{ "getbalance", &getbalance, false, false },
{ "move", &movecmd, false, false },
{ "sendfrom", &sendfrom, false, false },
Expand Down
1 change: 1 addition & 0 deletions src/bitcoinrpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ extern json_spirit::Value signmessage(const json_spirit::Array& params, bool fHe
extern json_spirit::Value verifymessage(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getreceivedbyaddress(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getreceivedbyaccount(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value fetchbalance(const json_spirit::Array& params, bool fHelp); // D e n a r i u s
extern json_spirit::Value getbalance(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value movecmd(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value sendfrom(const json_spirit::Array& params, bool fHelp);
Expand Down
2 changes: 2 additions & 0 deletions src/checkpoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ namespace Checkpoints
( 715006, uint256("0x000000000040fcb3164c963fb3031f8d73b519d3f181dde0fbd1c00280a9202f") )
( 735000, uint256("0x000000000026ee4128cd6cc718bcd6e346e83be573cbc1bd7aba846e4f843939") )
( 755516, uint256("0x00000000000a4c4951f38632c593cdd6c12fc3df3f8eb483f97cb6152589fbdb") )
( 800104, uint256("0x00000000000601e0288039f7b5da81dd6e90e0e7b2009c650a140d4b02c30811") )
( 843547, uint256("0x0000000000088b367232bbca1ca217d8d29f8cd1e7487e4f7d2bcea6412b4ce8") )
;

// TestNet has no checkpoints
Expand Down
2 changes: 1 addition & 1 deletion src/clientversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// These need to be macros, as version.cpp's and bitcoin-qt.rc's voodoo requires it
#define CLIENT_VERSION_MAJOR 2
#define CLIENT_VERSION_MINOR 5
#define CLIENT_VERSION_REVISION 0
#define CLIENT_VERSION_REVISION 2
#define CLIENT_VERSION_BUILD 0

// Converts the parameter X to a string after macro replacement on X has been performed.
Expand Down
5 changes: 5 additions & 0 deletions src/coincontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ class CCoinControl
//! Includes watch only addresses which match the ISMINE_WATCH_SOLVABLE criteria
bool fAllowWatchOnly;

bool fSplitBlock;
int nSplitBlock;

CCoinControl()
{
SetNull();
Expand All @@ -24,6 +27,8 @@ class CCoinControl
setSelected.clear();
fAllowOtherInputs = false;
fAllowWatchOnly = false;
fSplitBlock = false;
nSplitBlock = 1;
}

bool HasSelected() const
Expand Down
45 changes: 28 additions & 17 deletions src/darksend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void CDarkSendPool::CheckTimeout(){
if(!fMasterNode) {
if(state == POOL_STATUS_TRANSMISSION) {
if(fDebug) printf("CDarkSendPool::CheckTimeout() -- Session complete -- Running Check()\n");
Check();
// Check();
}
}

Expand Down Expand Up @@ -597,8 +597,8 @@ void CDarkSendPool::NewBlock()
//denominate all non-denominated inputs every 50 blocks (25 minutes)
if(pindexBest->nHeight % 50 == 0)
UnlockCoins();
// free up masternode connections every 120 blocks (1 hour) unless we are syncing
if(pindexBest->nHeight % 120 == 0 && !IsInitialBlockDownload())
// free up masternode connections every 30 blocks unless we are syncing
if(pindexBest->nHeight % 60 == 0 && !IsInitialBlockDownload())
ProcessMasternodeConnections();
}
}
Expand Down Expand Up @@ -804,8 +804,15 @@ bool CDarkSendSigner::IsVinAssociatedWithPubkey(CTxIn& vin, CPubKey& pubkey){
if(out.scriptPubKey == payee2) return true;
}
}
} else {
printf("IsVinAssociatedWithPubKey:: GetTransaction failed for %s\n",vin.prevout.hash.ToString().c_str());
}

CTxDestination address1;
ExtractDestination(payee2, address1);
CBitcoinAddress address2(address1);
printf("IsVinAssociatedWithPubKey:: vin %s is not associated with pubkey %s for address %s\n",
vin.ToString().c_str(), pubkey.GetHash().ToString().c_str(), address2.ToString().c_str());
return false;
}

Expand Down Expand Up @@ -926,7 +933,7 @@ void ThreadCheckDarkSendPool(void* parg)
unsigned int c = 0;
std::string errorMessage;

while (true)
while (true && !fShutdown)
{
c++;

Expand Down Expand Up @@ -968,27 +975,31 @@ void ThreadCheckDarkSendPool(void* parg)
masternodePayments.CleanPaymentList();
}

int mnRefresh = 90; //(5*5)
int mnRefresh = 30;

//try to sync the masternode list and payment list every 90 seconds from at least 3 nodes
if(c % mnRefresh == 0 && RequestedMasterNodeList < 3){
//try to sync the masternode list and payment list every 30 seconds from at least 3 nodes until we have them all
if(vNodes.size() > 2 && c % mnRefresh == 0 && (mnCount == 0 || vecMasternodes.size() < mnCount)) {
bool fIsInitialDownload = IsInitialBlockDownload();
if(!fIsInitialDownload) {
//LOCK(cs_vNodes);
LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodes)
{
if (pnode->nVersion >= darkSendPool.PROTOCOL_VERSION) {

//keep track of who we've asked for the list
if(pnode->HasFulfilledRequest("mnsync")) continue;
pnode->FulfilledRequest("mnsync");

printf("Successfully synced, asking for Masternode list and payment list\n");

pnode->PushMessage("dseg", CTxIn()); //request full mn list
pnode->PushMessage("mnget"); //sync payees
pnode->PushMessage("getsporks"); //get current network sporks
RequestedMasterNodeList++;
if(pnode->HasFulfilledRequest("mnsync"))
{
continue;
} else {
pnode->FulfilledRequest("mnsync");
printf("Asking for Masternode list from %s\n",pnode->addr.ToStringIPPort().c_str());

pnode->PushMessage("dseg", CTxIn()); //request full mn list
pnode->PushMessage("mnget"); //sync payees
pnode->PushMessage("getsporks"); //get current network sporks
RequestedMasterNodeList++;
break;
}
}
}
}
Expand Down
44 changes: 41 additions & 3 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ std::string HelpMessage()
"\n" + _("Masternode options:") + "\n" +
" -masternode=<n> " + _("Enable the client to act as a masternode (0-1, default: 0)") + "\n" +
" -mnconf=<file> " + _("Specify masternode configuration file (default: masternode.conf)") + "\n" +
" -mnconflock=<n> " + _("Lock masternodes from masternode configuration file (default: 1)") +
" -masternodeprivkey=<n> " + _("Set the masternode private key") + "\n" +
" -masternodeaddr=<n> " + _("Set external address:port to get to this masternode (example: address:port)") + "\n" +
" -masternodeminprotocol=<n> " + _("Ignore masternodes less than version (example: 70007; default : 0)") + "\n" +
Expand Down Expand Up @@ -434,7 +435,7 @@ bool AppInit2()

nNodeLifespan = GetArg("-addrlifespan", 7);
fUseFastIndex = GetBoolArg("-fastindex", true);
nMinerSleep = GetArg("-minersleep", 500);
nMinerSleep = GetArg("-minersleep", 30000);

CheckpointsMode = Checkpoints::STRICT;
std::string strCpMode = GetArg("-cppolicy", "strict");
Expand Down Expand Up @@ -490,7 +491,7 @@ bool AppInit2()
std::string err;
masternodeConfig.read(err);
if (!err.empty())
InitError("error while parsing masternode.conf Error: " + err);
InitError("error while parsing masternode.conf Error: " + err);

if (mapArgs.count("-connect") && mapMultiArgs["-connect"].size() > 0) {
// when only connecting to trusted nodes, do not seed via DNS, or listen by default
Expand Down Expand Up @@ -989,7 +990,44 @@ bool AppInit2()
}
}

printf("fMasterNode %d\n", fMasterNode);
if(GetBoolArg("-mnconflock", true) && pwalletMain) {
LOCK(pwalletMain->cs_wallet);
printf("Locking Masternodes:\n");
uint256 mnTxHash;
int outputIndex;
BOOST_FOREACH(CMasternodeConfig::CMasternodeEntry mne, masternodeConfig.getEntries()) {
mnTxHash.SetHex(mne.getTxHash());
outputIndex = boost::lexical_cast<unsigned int>(mne.getOutputIndex());
COutPoint outpoint = COutPoint(mnTxHash, outputIndex);
// don't lock non-spendable outpoint (i.e. it's already spent or it's not from this wallet at all)
if(pwalletMain->IsMine(CTxIn(outpoint)) != ISMINE_SPENDABLE) {
printf(" %s %s - IS NOT SPENDABLE, was not locked\n", mne.getTxHash().c_str(), mne.getOutputIndex().c_str());
continue;
}
pwalletMain->LockCoin(outpoint);
printf(" %s %s - locked successfully\n", mne.getTxHash().c_str(), mne.getOutputIndex().c_str());
}
}


// Add any masternode.conf masternodes to the adrenaline nodes
BOOST_FOREACH(CMasternodeConfig::CMasternodeEntry mne, masternodeConfig.getEntries())
{
CAdrenalineNodeConfig c(mne.getAlias(), mne.getIp(), mne.getPrivKey(), mne.getTxHash(), mne.getOutputIndex());
CWalletDB walletdb(strWalletFileName);

// add it to wallet db if doesn't exist already
if (!walletdb.ReadAdrenalineNodeConfig(c.sAddress, c))
{
if (!walletdb.WriteAdrenalineNodeConfig(c.sAddress, c))
printf("Could not add masternode config %s to adrenaline nodes.", c.sAddress.c_str());
}
// add it to adrenaline nodes if it doesn't exist already
if (!pwalletMain->mapMyAdrenalineNodes.count(c.sAddress))
pwalletMain->mapMyAdrenalineNodes.insert(make_pair(c.sAddress, c));

uiInterface.NotifyAdrenalineNodeChanged(c);
}

//Threading still needs reworking
NewThread(ThreadCheckDarkSendPool, NULL);
Expand Down
19 changes: 12 additions & 7 deletions src/kernelrecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ using namespace std;

bool KernelRecord::showTransaction(const CWalletTx &wtx)
{
if (wtx.IsCoinBase())
if (wtx.GetBlocksToMaturity() > 0 || !wtx.IsFinal() || !wtx.IsTrusted() || !wtx.IsInMainChain())
{
if (wtx.GetDepthInMainChain() < 2)
{
return false;
}
return false;
}

if (wtx.IsCoinBase() || wtx.IsCoinStake())
{
return true;
}

return true;
return false;

}

/*
Expand All @@ -34,7 +37,9 @@ vector<KernelRecord> KernelRecord::decomposeOutput(const CWallet *wallet, const
for (unsigned int nOut = 0; nOut < wtx.vout.size(); nOut++)
{
CTxOut txOut = wtx.vout[nOut];
if( wallet->IsMine(txOut) ) {
isminetype filter = wallet->IsMine(txOut);
bool isSpent = wtx.IsSpent(nOut);
if( (filter & ISMINE_SPENDABLE) && !isSpent) {
CTxDestination address;
std::string addrStr;

Expand Down
Loading

0 comments on commit 0e64cc0

Please sign in to comment.