Skip to content
This repository has been archived by the owner on Dec 25, 2017. It is now read-only.

Commit

Permalink
Pinkcoin 2.1 Update
Browse files Browse the repository at this point in the history
Pinkcoin 2.1 Update

New Features:
UI Upgrade (80%)
Side-Staking (Accessible from UI and RPC)
RPC Getnodes
  • Loading branch information
PinkDev committed May 3, 2017
1 parent dd4d91d commit 3248d37
Show file tree
Hide file tree
Showing 61 changed files with 3,712 additions and 2,074 deletions.
4 changes: 3 additions & 1 deletion pinkcoin-qt.pro
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ contains(BITCOIN_NEED_QT_PLUGINS, 1) {

INCLUDEPATH += src/leveldb/include src/leveldb/helpers
LIBS += $$PWD/src/leveldb/libleveldb.a $$PWD/src/leveldb/libmemenv.a
SOURCES += src/txdb-leveldb.cpp
SOURCES += src/txdb-leveldb.cpp
!win32 {
# we use QMAKE_CXXFLAGS_RELEASE even without RELEASE=1 because we use RELEASE to indicate linking preferences not -O preferences
genleveldb.commands = cd $$PWD/src/leveldb && CC=$$QMAKE_CC CXX=$$QMAKE_CXX $(MAKE) OPT=\"$$QMAKE_CXXFLAGS $$QMAKE_CXXFLAGS_RELEASE\" libleveldb.a libmemenv.a
Expand Down Expand Up @@ -275,6 +275,7 @@ HEADERS += src/qt/bitcoingui.h \
src/db.h \
src/txdb.h \
src/walletdb.h \
src/stakedb.h \
src/script.h \
src/stealth.h \
src/init.h \
Expand Down Expand Up @@ -357,6 +358,7 @@ SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \
src/addrman.cpp \
src/db.cpp \
src/walletdb.cpp \
src/stakedb.cpp \
src/qt/clientmodel.cpp \
src/qt/guiutil.cpp \
src/qt/transactionrecord.cpp \
Expand Down
44 changes: 39 additions & 5 deletions src/bitcoinrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ static const CRPCCommand vRPCCommands[] =
{ "getbestblockhash", &getbestblockhash, true, false },
{ "getblockcount", &getblockcount, true, false },
{ "getconnectioncount", &getconnectioncount, true, false },
{ "getnodes", &getnodes, true, false },
{ "getpeerinfo", &getpeerinfo, true, false },
{ "getdifficulty", &getdifficulty, true, false },
{ "getinfo", &getinfo, true, false },
Expand Down Expand Up @@ -319,6 +320,11 @@ static const CRPCCommand vRPCCommands[] =
{ "scanforstealthtxns", &scanforstealthtxns, false, false},
{ "getwalletinfo", &getwalletinfo, true, false},

{ "addstakeout", &addstakeout, false, false},
{ "delstakeout", &delstakeout, false, false},
{ "liststakeout", &liststakeout, false, false},
{ "getstakeoutinfo", &getstakeoutinfo, false, false},

{ "smsgenable", &smsgenable, false, false},
{ "smsgdisable", &smsgdisable, false, false},
{ "smsglocalkeys", &smsglocalkeys, false, false},
Expand All @@ -332,11 +338,6 @@ static const CRPCCommand vRPCCommands[] =
{ "smsginbox", &smsginbox, false, false},
{ "smsgoutbox", &smsgoutbox, false, false},
{ "smsgbuckets", &smsgbuckets, false, false},





};

CRPCTable::CRPCTable()
Expand Down Expand Up @@ -1333,6 +1334,13 @@ int CommandLineRPC(int argc, char *argv[])
throw runtime_error("too few parameters");
string strMethod = argv[1];

/* string strOut;
if (specialOutput(strMethod, *strOut))
{
strPrint = strOut;
return nRet;
}
*/
// Parameters default to strings
std::vector<std::string> strParams(&argv[2], &argv[argc]);
Array params = RPCConvertValues(strMethod, strParams);
Expand Down Expand Up @@ -1378,7 +1386,33 @@ int CommandLineRPC(int argc, char *argv[])
}
return nRet;
}
/*
void specialOutput(std::string strMethod, std::string *strOut)
{
bool ret = false;
if (strMethod = "getnodes")
{
if (fHelp || params.size() != 0)
throw runtime_error(
"getnodes\n"
"Returns each connected network node as addnodes in conf friendly format.");
vector<CNodeStats> vstats;
CopyNodeStats(vstats);
Value ret = NULL;
string pNode = "";
BOOST_FOREACH(const CNodeStats& stats, vstats) {
pNode += "addnode=" + stats.addrName + crlf;
}
ret.push_back(pNode);
return ret;
}
}
*/



Expand Down
11 changes: 10 additions & 1 deletion src/bitcoinrpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class CBlockIndex;
#include "json/json_spirit_reader_template.h"
#include "json/json_spirit_writer_template.h"
#include "json/json_spirit_utils.h"
#include "wallet.h"

#include "util.h"
#include "checkpoints.h"
Expand Down Expand Up @@ -70,6 +71,7 @@ json_spirit::Object JSONRPCError(int code, const std::string& message);

void ThreadRPCServer(void* parg);
int CommandLineRPC(int argc, char *argv[]);
//bool specialOutput(std::string strMethod, std::string *strOut);

/** Convert parameter values for RPC call from strings to command-specific JSON objects. */
json_spirit::Array RPCConvertValues(const std::string &strMethod, const std::vector<std::string> &strParams);
Expand Down Expand Up @@ -97,6 +99,7 @@ class CRPCCommand
rpcfn_type actor;
bool okSafeMode;
bool unlocked;
bool fGetNodes;
};

/**
Expand Down Expand Up @@ -144,8 +147,11 @@ extern uint256 ParseHashO(const json_spirit::Object& o, std::string strKey);
extern std::vector<unsigned char> ParseHexV(const json_spirit::Value& v, std::string strName);
extern std::vector<unsigned char> ParseHexO(const json_spirit::Object& o, std::string strKey);

//extern std::string getnodes(const json_spirit::Array& params, bool fHelp);

extern json_spirit::Value getconnectioncount(const json_spirit::Array& params, bool fHelp); // in rpcnet.cpp
extern json_spirit::Value getpeerinfo(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getnodes(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value dumpwallet(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value importwallet(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value dumpprivkey(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp
Expand Down Expand Up @@ -229,7 +235,10 @@ extern json_spirit::Value clearwallettransactions(const json_spirit::Array& para
extern json_spirit::Value scanforalltxns(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value scanforstealthtxns(const json_spirit::Array& params, bool fHelp);


extern json_spirit::Value addstakeout(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value delstakeout(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value liststakeout(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getstakeoutinfo(const json_spirit::Array& params, bool fHelp);

extern json_spirit::Value smsgenable(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value smsgdisable(const json_spirit::Array& params, bool fHelp);
Expand Down
4 changes: 2 additions & 2 deletions src/clientversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

// 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 0
#define CLIENT_VERSION_MINOR 1
#define CLIENT_VERSION_REVISION 0
#define CLIENT_VERSION_BUILD 5
#define CLIENT_VERSION_BUILD 0

// Converts the parameter X to a string after macro replacement on X has been performed.
// Don't merge these into one macro!
Expand Down
1 change: 1 addition & 0 deletions src/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ using namespace boost;


unsigned int nWalletDBUpdated;
unsigned int nStakeDBUpdated;



Expand Down
3 changes: 3 additions & 0 deletions src/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ class CWallet;
class CWalletTx;

extern unsigned int nWalletDBUpdated;
extern unsigned int nStakeDBUpdated;

void ThreadFlushWalletDB(void* parg);
void ThreadFlushStakeDB(void* parg);
bool BackupWallet(const CWallet& wallet, const std::string& strDest);
bool BackupStakeDB(const CWallet& stakeDB, const std::string& strDest);


class CDBEnv
Expand Down
49 changes: 49 additions & 0 deletions src/init.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 "txdb.h"
#include "walletdb.h"
#include "stakedb.h"
#include "bitcoinrpc.h"
#include "net.h"
#include "init.h"
Expand All @@ -30,6 +31,7 @@ using namespace std;
using namespace boost;

CWallet* pwalletMain;
CWallet* pstakeDB;
CClientUIInterface uiInterface;
bool fConfChange;
unsigned int nNodeLifespan;
Expand Down Expand Up @@ -93,7 +95,9 @@ void Shutdown(void* parg)
bitdb.Flush(true);
boost::filesystem::remove(GetPidFile());
UnregisterWallet(pwalletMain);
UnregisterWallet(pstakeDB);
delete pwalletMain;
delete pstakeDB;
NewThread(ExitTimeout, NULL);
MilliSleep(50);
printf("Pinkcoin exited\n\n");
Expand Down Expand Up @@ -528,11 +532,16 @@ bool AppInit2(boost::thread_group& threadGroup)

std::string strDataDir = GetDataDir().string();
std::string strWalletFileName = GetArg("-wallet", "wallet.dat");
std::string strStakeDBFileName = GetArg("-stakedb", "stake.dat");

// strWalletFileName must be a plain filename without a directory
if (strWalletFileName != boost::filesystem::basename(strWalletFileName) + boost::filesystem::extension(strWalletFileName))
return InitError(strprintf(_("Wallet %s resides outside data directory %s."), strWalletFileName.c_str(), strDataDir.c_str()));

// strStakeDBFileName must be a plain filename without a directory
if (strStakeDBFileName != boost::filesystem::basename(strStakeDBFileName) + boost::filesystem::extension(strStakeDBFileName))
return InitError(strprintf(_("Wallet %s resides outside data directory %s."), strStakeDBFileName.c_str(), strDataDir.c_str()));

// Make sure only a single Bitcoin process is using the data directory.
boost::filesystem::path pathLockFile = GetDataDir() / ".lock";
FILE* file = fopen(pathLockFile.string().c_str(), "a"); // empty lock file; created if it doesn't exist.
Expand Down Expand Up @@ -614,6 +623,19 @@ bool AppInit2(boost::thread_group& threadGroup)
return InitError(_("wallet.dat corrupt, salvage failed"));
}

if (filesystem::exists(GetDataDir() / strStakeDBFileName))
{
CDBEnv::VerifyResult r = bitdb.Verify(strStakeDBFileName, CStakeDB::Recover);
if (r == CDBEnv::RECOVER_OK)
{
string msg = strprintf(_("Warning: stake.dat corrupt, data salvaged!"
" Original stake.dat saved as stake.{timestamp}.bak in %s;"), strDataDir.c_str());
uiInterface.ThreadSafeMessageBox(msg, _("Pinkcoin"), CClientUIInterface::OK | CClientUIInterface::ICON_EXCLAMATION | CClientUIInterface::MODAL);
}
if (r == CDBEnv::RECOVER_FAIL)
return InitError(_("wallet.dat corrupt, salvage failed"));
}

// ********************************************************* Step 6: network initialization

int nSocksVersion = GetArg("-socks", 5);
Expand Down Expand Up @@ -795,6 +817,7 @@ bool AppInit2(boost::thread_group& threadGroup)
printf("Loading wallet...\n");
nStart = GetTimeMillis();
bool fFirstRun = true;
bool fFirstStakeOut = true;
pwalletMain = new CWallet(strWalletFileName);
DBErrors nLoadWalletRet = pwalletMain->LoadWallet(fFirstRun);
if (nLoadWalletRet != DB_LOAD_OK)
Expand All @@ -819,6 +842,31 @@ bool AppInit2(boost::thread_group& threadGroup)
strErrors << _("Error loading wallet.dat") << "\n";
}

pstakeDB = new CWallet(strStakeDBFileName);

SDBErrors nLoadStakeDBRet = pstakeDB->LoadStakeDB(fFirstStakeOut);
if (nLoadStakeDBRet != SDB_LOAD_OK)
{
if (nLoadStakeDBRet == SDB_CORRUPT)
strErrors << _("Error loading stake.dat: StakeDB corrupted") << "\n";
else if (nLoadStakeDBRet == SDB_NONCRITICAL_ERROR)
{
string msg(_("Warning: error reading stake.dat! Side-stake entries might be missing or incorrect."));
uiInterface.ThreadSafeMessageBox(msg, _("Pinkcoin"), CClientUIInterface::OK | CClientUIInterface::ICON_EXCLAMATION | CClientUIInterface::MODAL);
}
else if (nLoadStakeDBRet == SDB_TOO_NEW)
strErrors << _("Error loading stake.dat: StakeDB requires newer version of Pinkcoin") << "\n";
else if (nLoadStakeDBRet == SDB_NEED_REWRITE)
{
strErrors << _("StakeDB needed to be rewritten: restart Pinkcoin to complete") << "\n";
printf("%s", strErrors.str().c_str());
return InitError(strErrors.str());
}
else
strErrors << _("Error loading stake.dat") << "\n";
}


if (GetBoolArg("-upgradewallet", fFirstRun))
{
int nMaxVersion = GetArg("-upgradewallet", 0);
Expand Down Expand Up @@ -852,6 +900,7 @@ bool AppInit2(boost::thread_group& threadGroup)
printf(" wallet %15dms\n", GetTimeMillis() - nStart);

RegisterWallet(pwalletMain);
RegisterWallet(pstakeDB);

CBlockIndex *pindexRescan = pindexBest;
if (GetBoolArg("-rescan"))
Expand Down
1 change: 1 addition & 0 deletions src/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace boost {
} // namespace boost

extern CWallet* pwalletMain;
extern CWallet* pstakeDB;
void StartShutdown();
void Shutdown(void* parg);
bool AppInit2(boost::thread_group& threadGroup);
Expand Down
9 changes: 6 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const string strMessageMagic = "Pinkcoin Signed Message:\n";
int64_t nTransactionFee = MIN_TX_FEE;
int64_t nReserveBalance = 0;
int64_t nMinimumInputValue = 0;
int64_t nMinimumStakeValue = 1; // Don't stake old 0 reward blocks.
int64_t nMinimumStakeValue = 0; // Don't stake old 0 reward blocks.

extern enum Checkpoints::CPMode CheckpointsMode;

Expand Down Expand Up @@ -494,6 +494,8 @@ bool CTransaction::CheckTransaction() const
if (::GetSerializeSize(*this, SER_NETWORK, PROTOCOL_VERSION) > MAX_BLOCK_SIZE)
return DoS(100, error("CTransaction::CheckTransaction() : size limits failed"));



// Check for negative or overflow output values
int64_t nValueOut = 0;
for (unsigned int i = 0; i < vout.size(); i++)
Expand Down Expand Up @@ -1001,10 +1003,10 @@ int64_t GetProofOfStakeReward(int64_t nCoinAge, int64_t nFees, int nHeight, unsi
if (IsFlashStakeReward(nTime))
{
nSubsidy = 150 * COIN / (1 + (nHeight / nHalvingPoint / YEARLY_BLOCKCOUNT));
printf("/n/nIsFlashStake/n/n");
printf("\n\nIsFlashStake\n\n");
} else {
nSubsidy = 100 * COIN / (1 + (nHeight / nHalvingPoint / YEARLY_BLOCKCOUNT));
printf("/n/nIs NOT FlashStake/n/n");
printf("\n\nIs NOT FlashStake\n\n");
}

}
Expand Down Expand Up @@ -1409,6 +1411,7 @@ bool CTransaction::FetchInputs(CTxDB& txdb, const map<uint256, CTxIndex>& mapTes

const CTxOut& CTransaction::GetOutputFor(const CTxIn& input, const MapPrevTx& inputs) const
{

MapPrevTx::const_iterator mi = inputs.find(input.prevout.hash);
if (mi == inputs.end())
throw std::runtime_error("CTransaction::GetOutputFor() : prevout.hash not found");
Expand Down
10 changes: 7 additions & 3 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
using namespace std;
using namespace boost;

static const int MAX_OUTBOUND_CONNECTIONS = 16;
static const int MAX_OUTBOUND_CONNECTIONS = 64;

void ThreadMessageHandler2(void* parg);
void ThreadSocketHandler2(void* parg);
Expand Down Expand Up @@ -1269,8 +1269,12 @@ void MapPort()
// The second name should resolve to a list of seed addresses.

static const char *strDNSSeed[][2] = {
{"pinkarmy.ml", "pinkarmy.ml"},

{"primary", "pinkarmy.ml"},
{"frankfurt", "frankfurt.pinkarmy.ml"},
{"paris", "paris.pinkarmy.ml"},
{"singapore", "singapore.pinkarmy.ml"},
{"sydney", "sydney.pinkarmy.ml"},
{"tokyo", "tokyo.pinkarmy.ml"},
};

void ThreadDNSAddressSeed(void* parg)
Expand Down
Loading

0 comments on commit 3248d37

Please sign in to comment.