From 23ea75f73721d03f1de94c2cb48bf867bac0d694 Mon Sep 17 00:00:00 2001 From: Evan Duffield Date: Wed, 11 Feb 2015 07:47:21 -0700 Subject: [PATCH] Add maximum out value for IX via spork --- configure.ac | 2 +- src/clientversion.h | 2 +- src/instantx.cpp | 5 +++++ src/qt/walletmodel.cpp | 9 +++++++++ src/rpcmisc.cpp | 8 ++++---- src/spork.cpp | 37 ++++++++++++++++++++++++++++++------- src/spork.h | 9 ++++++--- src/wallet.cpp | 1 + 8 files changed, 57 insertions(+), 16 deletions(-) diff --git a/configure.ac b/configure.ac index 8adb10f00..a99214efa 100644 --- a/configure.ac +++ b/configure.ac @@ -3,7 +3,7 @@ AC_PREREQ([2.60]) define(_CLIENT_VERSION_MAJOR, 0) define(_CLIENT_VERSION_MINOR, 11) define(_CLIENT_VERSION_REVISION, 1) -define(_CLIENT_VERSION_BUILD, 19) +define(_CLIENT_VERSION_BUILD, 20) define(_CLIENT_VERSION_IS_RELEASE, true) define(_COPYRIGHT_YEAR, 2015) AC_INIT([Darkcoin Core],[_CLIENT_VERSION_MAJOR._CLIENT_VERSION_MINOR._CLIENT_VERSION_REVISION],[info@darkcoin.io],[darkcoin]) diff --git a/src/clientversion.h b/src/clientversion.h index 6cb78377f..3892935db 100644 --- a/src/clientversion.h +++ b/src/clientversion.h @@ -12,7 +12,7 @@ #define CLIENT_VERSION_MAJOR 0 #define CLIENT_VERSION_MINOR 11 #define CLIENT_VERSION_REVISION 1 -#define CLIENT_VERSION_BUILD 19 +#define CLIENT_VERSION_BUILD 20 diff --git a/src/instantx.cpp b/src/instantx.cpp index e0e0fa57c..070602f5b 100644 --- a/src/instantx.cpp +++ b/src/instantx.cpp @@ -194,6 +194,11 @@ bool IsIXTXValid(const CTransaction& txCollateral){ } } + if(nValueOut > GetSporkValue(SPORK_5_MAX_VALUE)*COIN){ + if(fDebug) LogPrintf ("IsIXTXValid - Transaction value too high - %s\n", txCollateral.ToString().c_str()); + return false; + } + if(missingTx){ if(fDebug) LogPrintf ("IsIXTXValid - Unknown inputs in IX transaction - %s\n", txCollateral.ToString().c_str()); /* diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index e260303b7..4bd0dcc84 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -18,6 +18,7 @@ #include "ui_interface.h" #include "wallet.h" #include "walletdb.h" // for BackupWallet +#include "spork.h" #include @@ -266,6 +267,13 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact CWalletTx *newTx = transaction.getTransaction(); CReserveKey *keyChange = transaction.getPossibleKeyChange(); + + if(recipients[0].useInstantX && total > GetSporkValue(SPORK_5_MAX_VALUE)*COIN){ + emit message(tr("Send Coins"), tr("InstantX doesn't support sending values that high yet. Transactions are currently limited to %n DRK.", "", GetSporkValue(SPORK_5_MAX_VALUE)), + CClientUIInterface::MSG_ERROR); + return TransactionCreationFailed; + } + bool fCreated = wallet->CreateTransaction(vecSend, *newTx, *keyChange, nFeeRequired, strFailReason, coinControl, recipients[0].inputType, recipients[0].useInstantX); transaction.setTransactionFee(nFeeRequired); @@ -318,6 +326,7 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(WalletModelTransaction &tran } } + CReserveKey *keyChange = transaction.getPossibleKeyChange(); transaction.getRecipients(); diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index 1ca4861df..bc164491c 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -140,7 +140,7 @@ Value spork(const Array& params, bool fHelp) Object ret; while(it != mapSporksActive.end()) { - ret.push_back(Pair(sporkManager.GetSporkNameByID(it->second.nSporkID), it->second.nTimeStart)); + ret.push_back(Pair(sporkManager.GetSporkNameByID(it->second.nSporkID), it->second.nValue)); it++; } return ret; @@ -150,11 +150,11 @@ Value spork(const Array& params, bool fHelp) return "Invalid spork name"; } - // EPOCH VALUE - int64_t nEpochStart = params[1].get_int(); + // SPORK VALUE + int64_t nValue = params[1].get_int(); //broadcast new spork - if(sporkManager.UpdateSpork(nSporkID, nEpochStart)){ + if(sporkManager.UpdateSpork(nSporkID, nValue)){ return "success"; } else { return "failure"; diff --git a/src/spork.cpp b/src/spork.cpp index 5b28967fc..dbba0c528 100644 --- a/src/spork.cpp +++ b/src/spork.cpp @@ -45,7 +45,7 @@ void ProcessSpork(CNode* pfrom, std::string& strCommand, CDataStream& vRecv) } } - LogPrintf("spork - new %s ID %d Time %d bestHeight %d\n", hash.ToString().c_str(), spork.nSporkID, spork.nTimeStart, chainActive.Tip()->nHeight); + LogPrintf("spork - new %s ID %d Time %d bestHeight %d\n", hash.ToString().c_str(), spork.nSporkID, spork.nValue, chainActive.Tip()->nHeight); if(!sporkManager.CheckSignature(spork)){ LogPrintf("spork - invalid signature\n"); @@ -75,12 +75,13 @@ bool IsSporkActive(int nSporkID) int64_t r = 0; if(mapSporksActive.count(nSporkID)){ - r = mapSporksActive[nSporkID].nTimeStart; + r = mapSporksActive[nSporkID].nValue; } else { if(nSporkID == SPORK_1_MASTERNODE_PAYMENTS_ENFORCEMENT) r = SPORK_1_MASTERNODE_PAYMENTS_ENFORCEMENT_DEFAULT; if(nSporkID == SPORK_2_INSTANTX) r = SPORK_2_INSTANTX_DEFAULT; if(nSporkID == SPORK_3_INSTANTX_BLOCK_FILTERING) r = SPORK_3_INSTANTX_BLOCK_FILTERING_DEFAULT; if(nSporkID == SPORK_4_RECONVERGE) r = SPORK_4_RECONVERGE_DEFAULT; + if(nSporkID == SPORK_5_MAX_VALUE) r = SPORK_5_MAX_VALUE_DEFAULT; if(r == 0) LogPrintf("GetSpork::Unknown Spork %d\n", nSporkID); } @@ -89,11 +90,31 @@ bool IsSporkActive(int nSporkID) return r < GetTime(); } +// grab the value of the spork on the network, or the default +int GetSporkValue(int nSporkID) +{ + int r = 0; + + if(mapSporksActive.count(nSporkID)){ + r = mapSporksActive[nSporkID].nValue; + } else { + if(nSporkID == SPORK_1_MASTERNODE_PAYMENTS_ENFORCEMENT) r = SPORK_1_MASTERNODE_PAYMENTS_ENFORCEMENT_DEFAULT; + if(nSporkID == SPORK_2_INSTANTX) r = SPORK_2_INSTANTX_DEFAULT; + if(nSporkID == SPORK_3_INSTANTX_BLOCK_FILTERING) r = SPORK_3_INSTANTX_BLOCK_FILTERING_DEFAULT; + if(nSporkID == SPORK_4_RECONVERGE) r = SPORK_4_RECONVERGE_DEFAULT; + if(nSporkID == SPORK_5_MAX_VALUE) r = SPORK_5_MAX_VALUE_DEFAULT; + + if(r == 0) LogPrintf("GetSpork::Unknown Spork %d\n", nSporkID); + } + + return r; +} + bool CSporkManager::CheckSignature(CSporkMessage& spork) { //note: need to investigate why this is failing - std::string strMessage = boost::lexical_cast(spork.nSporkID) + boost::lexical_cast(spork.nTimeStart) + boost::lexical_cast(spork.nTimeSigned); + std::string strMessage = boost::lexical_cast(spork.nSporkID) + boost::lexical_cast(spork.nValue) + boost::lexical_cast(spork.nTimeSigned); std::string strPubKey = (Params().NetworkID() == CChainParams::MAIN) ? strMainPubKey : strTestPubKey; CPubKey pubkey(ParseHex(strPubKey)); @@ -107,7 +128,7 @@ bool CSporkManager::CheckSignature(CSporkMessage& spork) bool CSporkManager::Sign(CSporkMessage& spork) { - std::string strMessage = boost::lexical_cast(spork.nSporkID) + boost::lexical_cast(spork.nTimeStart) + boost::lexical_cast(spork.nTimeSigned); + std::string strMessage = boost::lexical_cast(spork.nSporkID) + boost::lexical_cast(spork.nValue) + boost::lexical_cast(spork.nTimeSigned); CKey key2; CPubKey pubkey2; @@ -132,17 +153,18 @@ bool CSporkManager::Sign(CSporkMessage& spork) return true; } -bool CSporkManager::UpdateSpork(int nSporkID, int64_t nTimeStart) +bool CSporkManager::UpdateSpork(int nSporkID, int64_t nValue) { CSporkMessage msg; msg.nSporkID = nSporkID; - msg.nTimeStart = nTimeStart; + msg.nValue = nValue; msg.nTimeSigned = GetTime(); if(Sign(msg)){ Relay(msg); mapSporks[msg.GetHash()] = msg; + mapSporksActive[nSporkID] = msg; return true; } @@ -180,11 +202,11 @@ bool CSporkManager::SetPrivKey(std::string strPrivKey) int CSporkManager::GetSporkIDByName(std::string strName) { - printf("%s\n", strName.c_str()); if(strName == "SPORK_1_MASTERNODE_PAYMENTS_ENFORCEMENT") return SPORK_1_MASTERNODE_PAYMENTS_ENFORCEMENT; if(strName == "SPORK_2_INSTANTX") return SPORK_2_INSTANTX; if(strName == "SPORK_3_INSTANTX_BLOCK_FILTERING") return SPORK_3_INSTANTX_BLOCK_FILTERING; if(strName == "SPORK_4_RECONVERGE") return SPORK_4_RECONVERGE; + if(strName == "SPORK_5_MAX_VALUE") return SPORK_5_MAX_VALUE; return -1; } @@ -195,6 +217,7 @@ std::string CSporkManager::GetSporkNameByID(int id) if(id == SPORK_2_INSTANTX) return "SPORK_2_INSTANTX"; if(id == SPORK_3_INSTANTX_BLOCK_FILTERING) return "SPORK_3_INSTANTX_BLOCK_FILTERING"; if(id == SPORK_4_RECONVERGE) return "SPORK_4_RECONVERGE"; + if(id == SPORK_5_MAX_VALUE) return "SPORK_5_MAX_VALUE"; return "Unknown"; } \ No newline at end of file diff --git a/src/spork.h b/src/spork.h index d1c5b69f2..7c991560e 100644 --- a/src/spork.h +++ b/src/spork.h @@ -23,11 +23,13 @@ using namespace boost; #define SPORK_2_INSTANTX 10001 #define SPORK_3_INSTANTX_BLOCK_FILTERING 10002 #define SPORK_4_RECONVERGE 10003 +#define SPORK_5_MAX_VALUE 10004 #define SPORK_1_MASTERNODE_PAYMENTS_ENFORCEMENT_DEFAULT 1424217600 //2015-2-18 #define SPORK_2_INSTANTX_DEFAULT 978307200 //2001-1-1 #define SPORK_3_INSTANTX_BLOCK_FILTERING_DEFAULT 1424217600 //2015-2-18 #define SPORK_4_RECONVERGE_DEFAULT 4070908800 //2099-1-1 +#define SPORK_5_MAX_VALUE_DEFAULT 1000 //1000 DRK class CSporkMessage; class CSporkManager; @@ -48,6 +50,7 @@ extern std::map mapSporksActive; extern CSporkManager sporkManager; void ProcessSpork(CNode* pfrom, std::string& strCommand, CDataStream& vRecv); +int GetSporkValue(int nSporkID); bool IsSporkActive(int nSporkID); // @@ -60,7 +63,7 @@ class CSporkMessage public: std::vector vchSig; int nSporkID; - int64_t nTimeStart; + int64_t nValue; int64_t nTimeSigned; uint256 GetHash(){ @@ -70,7 +73,7 @@ public: IMPLEMENT_SERIALIZE( READWRITE(nSporkID); - READWRITE(nTimeStart); + READWRITE(nValue); READWRITE(nTimeSigned); READWRITE(vchSig); ) @@ -95,7 +98,7 @@ public: std::string GetSporkNameByID(int id); int GetSporkIDByName(std::string strName); - bool UpdateSpork(int nSporkID, int64_t nTimeStart); + bool UpdateSpork(int nSporkID, int64_t nValue); bool SetPrivKey(std::string strPrivKey); bool CheckSignature(CSporkMessage& spork); bool Sign(CSporkMessage& spork); diff --git a/src/wallet.cpp b/src/wallet.cpp index a3d04fe90..6edfdecea 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1841,6 +1841,7 @@ bool CWallet::CreateTransaction(const vector >& vecSend, return false; } + wtxNew.BindWallet(this); {