Permalink
Browse files

More code cleanup

Also Changed GetProofOfWorkReward
  • Loading branch information...
Tranz5 committed Jul 18, 2014
1 parent c657b5e commit c6ba27f9926af8f7fc0b73340c175e9d327a2c85
View
@@ -78,7 +78,7 @@ class CBigNum : public BIGNUM
BN_clear_free(this);
}
//CBigNum(char n) is not portable. Use 'signed char' or 'unsigned char'.
// CBigNum(char n) is not portable. Use 'signed char' or 'unsigned char'.
CBigNum(signed char n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
CBigNum(short n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
CBigNum(int n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
View
@@ -8,7 +8,7 @@
#include "wallet.h"
extern CWalletManager* pWalletManager;
//TODO: get rid of pwalletMain
// TODO: get rid of pwalletMain
extern CWallet* pwalletMain;
void StartShutdown();
View
@@ -31,9 +31,9 @@ int64 GetWeight(int64 nIntervalBeginning, int64 nIntervalEnd)
//
// Maximum TimeWeight is 30 days.
//Tranz We are going to want to change this to fix the max weight. Requires a hard fork
//New Code:
//return min(nIntervalEnd - nIntervalBeginning - nStakeMinAge, (int64)nStakeMaxAge);
// Tranz We are going to want to change this to fix the max weight. Requires a hard fork
// New Code:
// return min(nIntervalEnd - nIntervalBeginning - nStakeMinAge, (int64)nStakeMaxAge);
return min(nIntervalEnd - nIntervalBeginning, (int64)nStakeMaxAge) - nStakeMinAge;
}
@@ -293,9 +293,9 @@ bool CheckStakeKernelHash(unsigned int nBits, const CBlock& blockFrom, unsigned
// v0.3 protocol kernel hash weight starts from 0 at the 10-day min age
// this change increases active coins participating the hash and helps
// to secure the network when proof-of-stake difficulty is low
//Tranz We are going to want to change this to fix the max weight. Requires a hard fork
//New Code:
//int64 nTimeWeight = min((int64)nTimeTx - txPrev.nTime - nStakeMinAge, (int64)nStakeMaxAge);
// Tranz We are going to want to change this to fix the max weight. Requires a hard fork
// New Code:
// int64 nTimeWeight = min((int64)nTimeTx - txPrev.nTime - nStakeMinAge, (int64)nStakeMaxAge);
int64 nTimeWeight = min((int64)nTimeTx - txPrev.nTime, (int64)nStakeMaxAge) - nStakeMinAge;
CBigNum bnCoinDayWeight = CBigNum(nValueIn) * nTimeWeight / COIN / (24 * 60 * 60);
targetProofOfStake = CBigNum(bnCoinDayWeight * bnTargetPerCoinDay).getuint256();
View
@@ -1004,11 +1004,9 @@ uint256 WantedByOrphan(const CBlock* pblockOrphan)
return pblockOrphan->hashPrevBlock;
}
// miner's coin base reward based on nBits
int64 GetProofOfWorkReward(unsigned int nHeight)
int64 GetProofOfWorkReward()
{
int64 nSubsidy = 5 * COIN;
int64 nSubsidy = 5 * COIN;
return nSubsidy;
}
@@ -1093,11 +1091,11 @@ int64 GetProofOfStakeReward(int64 nCoinAge, unsigned int nBits, unsigned int nTi
if(bCoinYearOnly)
return nRewardCoinYear;
//Stake calculation fix for small tx values courtesy of Mineral And Yukon Coinelius. This will fix the rounding of small stake rewards to zero
// Stake calculation fix for small tx values courtesy of Mineral And Yukon Coinelius. This will fix the rounding of small stake rewards to zero
int64 nSubsidy = nRewardCoinYear * nCoinAge * 33 / (365 * 33 + 8);
if (nTime > POS_REWARD_SWITCH_TIME)
nSubsidy = (nCoinAge * 33 * nRewardCoinYear) / (365 * 33 + 8);
else
else
nSubsidy = nCoinAge * 33 / (365 * 33 + 8) * nRewardCoinYear;
@@ -1183,9 +1181,9 @@ unsigned int GetNextTargetRequired(const CBlockIndex* pindexLast, bool fProofOfS
int64 nActualSpacing = pindexPrev->GetBlockTime() - pindexPrevPrev->GetBlockTime();
//Tranz saved for later.
//int nHeight = pindexPrev->nHeight+1;
//if (nHeight >= ???? & nActualSpacing < 0) nActualSpacing = 0; //Sanity Check on nActualSpacing, corrects negative block values
// Tranz saved for later.
// int nHeight = pindexPrev->nHeight+1;
// if (nHeight >= ???? & nActualSpacing < 0) nActualSpacing = 0; //Sanity Check on nActualSpacing, corrects negative block values
// ppcoin: target change every block
// ppcoin: retarget with exponential moving toward target spacing
@@ -2198,14 +2196,14 @@ bool CBlock::CheckBlock(bool fCheckPOW, bool fCheckMerkleRoot, bool fCheckSig) c
if (vtx[0].GetValueOut() > (IsProofOfWork()? MAX_MINT_PROOF_OF_WORK_LEGACY : 0))
return DoS(50, error("CheckBlock() : coinbase reward exceeded %s > %s",
FormatMoney(vtx[0].GetValueOut()).c_str(),
FormatMoney(IsProofOfWork()? GetProofOfWorkReward(nBits) : 0).c_str()));
FormatMoney(IsProofOfWork()? GetProofOfWorkReward() : 0).c_str()));
}
else
{
if (vtx[0].GetValueOut() > (IsProofOfWork()? (GetProofOfWorkReward(nBits) - vtx[0].GetMinFee() + MIN_TX_FEE) : 0))
if (vtx[0].GetValueOut() > (IsProofOfWork()? (GetProofOfWorkReward() - vtx[0].GetMinFee() + MIN_TX_FEE) : 0))
return DoS(50, error("CheckBlock() : coinbase reward exceeded %s > %s",
FormatMoney(vtx[0].GetValueOut()).c_str(),
FormatMoney(IsProofOfWork()? GetProofOfWorkReward(nBits) : 0).c_str()));
FormatMoney(IsProofOfWork()? GetProofOfWorkReward() : 0).c_str()));
}
}
@@ -2822,9 +2820,6 @@ void PrintBlockTree()
{
CBlockIndex* pindex = (*mi).second;
mapNext[pindex->pprev].push_back(pindex);
// test
//while (rand() % 3 == 0)
// mapNext[pindex->pprev].push_back(pindex);
}
vector<pair<int, CBlockIndex*> > vStack;
@@ -3147,7 +3142,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
return true;
}
//Record my external IP reported by peer
// Record my external IP reported by peer
if (addrFrom.IsRoutable() && addrMe.IsRoutable())
addrSeenByPeer = addrMe;
@@ -3761,7 +3756,7 @@ bool ProcessMessages(CNode* pfrom)
CDataStream& vRecv = pfrom->vRecv;
if (vRecv.empty())
return true;
//if (fDebug)
// if (fDebug)
// printf("ProcessMessages(%u bytes)\n", vRecv.size());
//
View
@@ -35,9 +35,9 @@ static const int64 MIN_RELAY_TX_FEE = 0.1 * CENT;
static const int64 MAX_MONEY = 120000000 * COIN;
static const int64 MAX_MINT_PROOF_OF_WORK = 5 * COIN;
static const int64 MAX_MINT_PROOF_OF_WORK_LEGACY = 5 * COIN;
static const int64 MAX_MINT_PROOF_OF_STAKE = 10 * CENT; //Incorrect value Too small
static const int64 MAX_MINT_PROOF_OF_STAKE_FIX = 1000 * CENT;//Incorrect value Too big
static const int64 MAX_MINT_PROOF_OF_STAKE_FIX2 = 100 * CENT; //Correct just right
static const int64 MAX_MINT_PROOF_OF_STAKE = 10 * CENT; // Incorrect value Too small
static const int64 MAX_MINT_PROOF_OF_STAKE_FIX = 1000 * CENT;// Incorrect value Too big
static const int64 MAX_MINT_PROOF_OF_STAKE_FIX2 = 100 * CENT; // Correct just right
static const int64 MIN_TXOUT_AMOUNT = MIN_TX_FEE;
static const unsigned int PROTOCOL_SWITCH_TIME = 1371686400; // 20 Jun 2013 00:00:00
@@ -127,7 +127,7 @@ bool LoadExternalBlockFile(FILE* fileIn);
void GenerateBitcoins(bool fGenerate, CWallet* pwallet);
bool CheckProofOfWork(uint256 hash, unsigned int nBits);
unsigned int GetNextTargetRequired(const CBlockIndex* pindexLast, bool fProofOfStake);
int64 GetProofOfWorkReward(unsigned int nBits);
int64 GetProofOfWorkReward();
int64 GetProofOfStakeReward(int64 nCoinAge, unsigned int nBits, unsigned int nTime ,bool bCoinYearOnly=false);
unsigned int ComputeMinWork(unsigned int nBase, int64 nTime);
unsigned int ComputeMinStake(unsigned int nBase, int64 nTime, unsigned int nBlockTime);
View
@@ -360,7 +360,7 @@ CBlock* CreateNewBlock(CWallet* pwallet, bool fProofOfStake)
printf("CreateNewBlock(): total size %"PRI64u"\n", nBlockSize);
if (!fProofOfStake)
pblock->vtx[0].vout[0].nValue = GetProofOfWorkReward(pblock->nBits);
pblock->vtx[0].vout[0].nValue = GetProofOfWorkReward();
// Fill in header
pblock->hashPrevBlock = pindexPrev->GetBlockHash();
View
@@ -29,4 +29,4 @@ bool CheckStake(CBlock* pblock, CWallet& wallet);
/** Base sha256 mining transform */
void SHA256Transform(void* pstate, void* pinput, const void* pinit);
#endif //MINER_H
#endif // MINER_H
View
@@ -1887,8 +1887,8 @@ void StartNode(void* parg)
printf("Error; NewThread(ThreadDumpAddress) failed\n");
// ppcoin: mint proof-of-stake blocks in the background
//hbn: each wallet gets its own thread.
//Todo: Need to add a method to choose not to run stake off wallet.
// hbn: each wallet gets its own thread.
// Todo: Need to add a method to choose not to run stake off wallet.
pWalletManager->RestartStakeMiner();
View
@@ -481,7 +481,7 @@ void BitcoinGUI::setClientModel(ClientModel *clientModel)
walletStack->setClientModel(clientModel);
rpcConsole->setClientModel(clientModel);
//Watch for wallets being loaded or unloaded
// Watch for wallets being loaded or unloaded
connect(clientModel, SIGNAL(walletAdded(QString)), this, SLOT(addWallet(QString)));
connect(clientModel, SIGNAL(walletRemoved(QString)), this, SLOT(removeWallet(QString)));
}
@@ -603,7 +603,7 @@ void BitcoinGUI::blocksIconClicked()
.arg(clientModel->getLastBlockDate().toString())
.arg(clientModel->getDifficulty())
.arg(clientModel->getPoWMHashPS())
.arg(tr("5.0000000")) //Hard Coded as HBN is always 5, but should use GetProofOfWorkReward
.arg(tr("5.0000000")) // Hard Coded as HBN is always 5, but should use GetProofOfWorkReward
.arg(walletStack->getCurrentWallet())
.arg(walletStack->getWalletVersion())
.arg(walletManager->GetWalletCount())
@@ -1166,7 +1166,7 @@ void BitcoinGUI::setEncryptionStatus(int status)
connect(labelEncryptionIcon,SIGNAL(clicked()), this, SLOT(lockIconClicked()));
break;
}
//Put here as this function will be called on any wallet or lock status change.
// Put here as this function will be called on any wallet or lock status change.
updateStakingIcon();
}
View
@@ -32,7 +32,7 @@ ClientModel::ClientModel(OptionsModel *optionsModel, QObject *parent) :
ClientModel::~ClientModel()
{
//unsubscribeFromCoreSignals();
}
int ClientModel::getNumConnections() const
@@ -671,7 +671,7 @@ void CoinControlDialog::updateView()
itemWalletAddress->setText(COLUMN_AMOUNT_INT64, strPad(QString::number(nSum), 15, " "));
itemWalletAddress->setText(COLUMN_PRIORITY, CoinControlDialog::getPriorityLabel(dPrioritySum));
itemWalletAddress->setText(COLUMN_PRIORITY_INT64, strPad(QString::number((int64)dPrioritySum), 20, " "));
//Tree Mode Weight
// Tree Mode Weight
itemWalletAddress->setText(COLUMN_WEIGHT, strPad(QString::number((uint64)nTxWeightSum),8," "));
}
View
@@ -34,7 +34,7 @@ WalletModel::WalletModel(CWallet *wallet, OptionsModel *optionsModel, QObject *p
WalletModel::~WalletModel()
{
//unsubscribeFromCoreSignals();
}
qint64 WalletModel::getBalance(const CCoinControl *coinControl) const
{
@@ -53,8 +53,6 @@ qint64 WalletModel::getBalance(const CCoinControl *coinControl) const
qint64 WalletModel::getTotBalance() const
{
//This is display only, and we don't lock coins,
//so Coin Control is not needed for now
int64 nTotBalance = 0;
BOOST_FOREACH(const wallet_map::value_type& item, pWalletManager->GetWalletMap())
{
View
@@ -99,18 +99,18 @@ class WalletModel : public QObject
// Wallet backup
bool backupWallet(const QString &filename);
bool backupAllWallets(const QString &filename);
//Wallet Inport/Export
// Wallet Inport/Export
bool dumpWallet(const QString &filename);
bool importWallet(const QString &filename);
// Wallet Repair
void checkWallet(int& nMismatchSpent, qint64& nBalanceInQuestion, int& nOrphansFound);
void repairWallet(int& nMismatchSpent, qint64& nBalanceInQuestion, int& nOrphansFound);
//PoS Information
// PoS Information
void getStakeWeight(quint64& nMinWeight, quint64& nMaxWeight, quint64& nWeight);
quint64 getTotStakeWeight();
//PoS Information about value and time
// PoS Information about value and time
void getStakeWeightFromValue(const qint64& nTime, const qint64& nValue, quint64& nWeight);
//Wallet Information about Stake For Charity
// Wallet Information about Stake For Charity
int getStakeForCharityPercent();
QString getStakeForCharityAddress();
View
@@ -110,12 +110,10 @@ Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool fPri
result.push_back(Pair("bits", HexBits(block.nBits)));
result.push_back(Pair("difficulty", GetDifficulty(blockindex)));
result.push_back(Pair("blocktrust", leftTrim(blockindex->GetBlockTrust().GetHex(), '0')));
//result.push_back(Pair("chaintrust", leftTrim(blockindex->nChainTrust.GetHex(), '0')));
if (blockindex->pprev)
result.push_back(Pair("previousblockhash", blockindex->pprev->GetBlockHash().GetHex()));
if (blockindex->pnext)
result.push_back(Pair("nextblockhash", blockindex->pnext->GetBlockHash().GetHex()));
result.push_back(Pair("flags", strprintf("%s%s", blockindex->IsProofOfStake()? "proof-of-stake" : "proof-of-work", blockindex->GeneratedStakeModifier()? " stake-modifier": "")));
result.push_back(Pair("proofhash", blockindex->IsProofOfStake()? blockindex->hashProofOfStake.GetHex() : blockindex->GetBlockHash().GetHex()));
result.push_back(Pair("entropybit", (int)blockindex->GetStakeEntropyBit()));
View
@@ -69,20 +69,7 @@ Value getsubsidy(CWallet* pWallet, const Array& params, bool fHelp)
"getsubsidy [nTarget]\n"
"Returns proof-of-work subsidy value for the specified value of target.");
unsigned int nBits = 0;
if (params.size() != 0)
{
CBigNum bnTarget(uint256(params[0].get_str()));
nBits = bnTarget.GetCompact();
}
else
{
nBits = GetNextTargetRequired(pindexBest, false);
}
return ValueFromAmount((uint64_t)GetProofOfWorkReward(nBits));
return ValueFromAmount((uint64_t)GetProofOfWorkReward());
}
Value getmininginfo(CWallet* pWallet, const Array& params, bool fHelp)
View
@@ -241,8 +241,8 @@ Value stakeforcharity(CWallet *pWallet, const Array &params, bool fHelp)
unsigned int nPer = (unsigned int) params[1].get_int();
//Turn off if we set to zero.
//Future: After we allow multiple addresses, only turn of this address
// Turn off if we set to zero.
// Future: After we allow multiple addresses, only turn of this address
if(nPer == 0)
{
pWallet->fStakeForCharity = false;
@@ -251,11 +251,11 @@ Value stakeforcharity(CWallet *pWallet, const Array &params, bool fHelp)
return Value::null;
}
//For now max percentage is 50.
// For now max percentage is 50.
if (nPer > 50 )
nPer = 50;
//Future: These will be an array of addr/per/wallet
// Future: These will be an array of addr/per/wallet
pWallet->StakeForCharityAddress = address;
pWallet->nStakeForCharityPercent = nPer;
pWallet->fStakeForCharity = true;
@@ -1523,7 +1523,7 @@ Value walletpassphrase(CWallet* pWallet, const Array& params, bool fHelp)
else
pWallet->fWalletUnlockMintOnly = false;
//HBN: Zero unlock time means forever, well 68 years, forever for crypto.
// HBN: Zero unlock time means forever, well 68 years, forever for crypto.
int64 nUnlockTime;
if (params[1].get_int64() == 0 )
@@ -2076,7 +2076,7 @@ Value unloadwallet(CWallet* pWallet, const Array& params, bool fHelp)
if (!pWalletManager->UnloadWallet(strWalletName))
throw JSONRPCError(RPC_WALLET_ERROR, string("No wallet named ") + strWalletName + " is currently loaded.");
//Tell GUI a wallet was unloaded so it can be removed from stack
// Tell GUI a wallet was unloaded so it can be removed from stack
uiInterface.NotifyWalletRemoved(strWalletName);
return string("Wallet ") + strWalletName + " unloaded.";
View
@@ -713,7 +713,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
case OP_EQUAL:
case OP_EQUALVERIFY:
//case OP_NOTEQUAL: // use OP_NUMNOTEQUAL
// case OP_NOTEQUAL: // use OP_NUMNOTEQUAL
{
// (x1 x2 - bool)
if (stack.size() < 2)
@@ -724,7 +724,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
// OP_NOTEQUAL is disabled because it would be too easy to say
// something like n != 1 and have some wiseguy pass in 1 with extra
// zero bytes after it (numerically, 0x01 == 0x0001 == 0x000001)
//if (opcode == OP_NOTEQUAL)
// if (opcode == OP_NOTEQUAL)
// fEqual = !fEqual;
popstack(stack);
popstack(stack);
@@ -932,8 +932,8 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
valtype& vchPubKey = stacktop(-1);
////// debug print
//PrintHex(vchSig.begin(), vchSig.end(), "sig: %s\n");
//PrintHex(vchPubKey.begin(), vchPubKey.end(), "pubkey: %s\n");
// PrintHex(vchSig.begin(), vchSig.end(), "sig: %s\n");
// PrintHex(vchPubKey.begin(), vchPubKey.end(), "pubkey: %s\n");
// Subset of script starting at the most recent codeseparator
CScript scriptCode(pbegincodehash, pend);
View
@@ -287,7 +287,7 @@ class CScript : public std::vector<unsigned char>
}
//explicit CScript(char b) is not portable. Use 'signed char' or 'unsigned char'.
// explicit CScript(char b) is not portable. Use 'signed char' or 'unsigned char'.
explicit CScript(signed char b) { operator<<(b); }
explicit CScript(short b) { operator<<(b); }
explicit CScript(int b) { operator<<(b); }
@@ -305,7 +305,7 @@ class CScript : public std::vector<unsigned char>
explicit CScript(const std::vector<unsigned char>& b) { operator<<(b); }
//CScript& operator<<(char b) is not portable. Use 'signed char' or 'unsigned char'.
// CScript& operator<<(char b) is not portable. Use 'signed char' or 'unsigned char'.
CScript& operator<<(signed char b) { return push_int64(b); }
CScript& operator<<(short b) { return push_int64(b); }
CScript& operator<<(int b) { return push_int64(b); }
Oops, something went wrong.

0 comments on commit c6ba27f

Please sign in to comment.