Skip to content

Commit

Permalink
Add new logo and fix integer wraparound in RPC.
Browse files Browse the repository at this point in the history
  • Loading branch information
EmberCoin committed Dec 29, 2017
1 parent 1f552cf commit d87fd13
Show file tree
Hide file tree
Showing 20 changed files with 76 additions and 111 deletions.
8 changes: 4 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1017,10 +1017,10 @@ bool GetProofOfStakeReward(CTransaction& tx, CTxDB& txdb, int64_t nFees, int64_t
time_t far_far_future;

if (TestNet()) {
past = APPROX(2017, 10, 3, 0, 0, 0);
future = APPROX(2017, 10, 4, 1, 0, 0);
far_future = APPROX(2017, 10, 4, 10, 0, 0);
far_far_future = APPROX(2017, 10, 4, 20, 0, 0);
past = APPROX(2018, 10, 3, 0, 0, 0);
future = APPROX(2018, 10, 4, 1, 0, 0);
far_future = APPROX(2018, 10, 4, 10, 0, 0);
far_far_future = APPROX(2018, 10, 4, 20, 0, 0);
} else {
// main net
past = APPROX(2017, 11, 1, 0, 0, 0);
Expand Down
4 changes: 0 additions & 4 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -550,10 +550,6 @@ class CTxIndex

};





/** Nodes collect new transactions into a block, hash them into a hash tree,
* and scan through nonce values to make the block's hash satisfy proof-of-work
* requirements. When they solve the proof-of-work, they broadcast the block
Expand Down
53 changes: 16 additions & 37 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,24 +632,18 @@ void SocketSendData(CNode *pnode)

static list<CNode*> vNodesDisconnected;

void ThreadSocketHandler()
{
void ThreadSocketHandler() {
unsigned int nPrevNodeCount = 0;

while (!ShutdownRequested())
{
//
while (!ShutdownRequested()) {
// Disconnect nodes
//
{
LOCK(cs_vNodes);
// Disconnect unused nodes
vector<CNode*> vNodesCopy = vNodes;
BOOST_FOREACH(CNode* pnode, vNodesCopy)
{
BOOST_FOREACH(CNode* pnode, vNodesCopy) {
if (pnode->fDisconnect ||
(pnode->GetRefCount() <= 0 && pnode->vRecvMsg.empty() && pnode->nSendSize == 0 && pnode->ssSend.empty()))
{
(pnode->GetRefCount() <= 0 && pnode->vRecvMsg.empty() && pnode->nSendSize == 0 && pnode->ssSend.empty())) {
// remove from vNodes
vNodes.erase(remove(vNodes.begin(), vNodes.end(), pnode), vNodes.end());

Expand All @@ -669,11 +663,9 @@ void ThreadSocketHandler()
{
// Delete disconnected nodes
list<CNode*> vNodesDisconnectedCopy = vNodesDisconnected;
BOOST_FOREACH(CNode* pnode, vNodesDisconnectedCopy)
{
BOOST_FOREACH(CNode* pnode, vNodesDisconnectedCopy) {
// wait until threads are done using it
if (pnode->GetRefCount() <= 0)
{
if (pnode->GetRefCount() <= 0) {
bool fDelete = false;
{
TRY_LOCK(pnode->cs_vSend, lockSend);
Expand All @@ -688,8 +680,7 @@ void ThreadSocketHandler()
}
}
}
if (fDelete)
{
if (fDelete) {
vNodesDisconnected.remove(pnode);
delete pnode;
}
Expand Down Expand Up @@ -725,8 +716,7 @@ void ThreadSocketHandler()
}
{
LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodes)
{
BOOST_FOREACH(CNode* pnode, vNodes) {
if (pnode->hSocket == INVALID_SOCKET)
continue;
{
Expand All @@ -745,14 +735,11 @@ void ThreadSocketHandler()
}
}

int nSelect = select(have_fds ? hSocketMax + 1 : 0,
&fdsetRecv, &fdsetSend, &fdsetError, &timeout);
int nSelect = select(have_fds ? hSocketMax + 1 : 0, &fdsetRecv, &fdsetSend, &fdsetError, &timeout);
boost::this_thread::interruption_point();

if (nSelect == SOCKET_ERROR)
{
if (have_fds)
{
if (nSelect < 0) {
if (have_fds) {
int nErr = WSAGetLastError();
LogPrintf("socket select error %d\n", nErr);
for (unsigned int i = 0; i <= hSocketMax; i++)
Expand All @@ -768,8 +755,7 @@ void ThreadSocketHandler()
// Accept new connections
//
BOOST_FOREACH(SOCKET hListenSocket, vhListenSocket)
if (hListenSocket != INVALID_SOCKET && FD_ISSET(hListenSocket, &fdsetRecv))
{
if (hListenSocket != INVALID_SOCKET && FD_ISSET(hListenSocket, &fdsetRecv)) {
struct sockaddr_storage sockaddr;
socklen_t len = sizeof(sockaddr);
SOCKET hSocket = accept(hListenSocket, (struct sockaddr*)&sockaddr, &len);
Expand All @@ -787,23 +773,16 @@ void ThreadSocketHandler()
nInbound++;
}

if (hSocket == INVALID_SOCKET)
{
if (hSocket == INVALID_SOCKET) {
int nErr = WSAGetLastError();
if (nErr != WSAEWOULDBLOCK)
LogPrintf("socket error accept failed: %d\n", nErr);
}
else if (nInbound >= min(MAX_OUTBOUND_CONNECTIONS, (int)GetArg("-maxconnections", 24)))
{
} else if (nInbound >= min(MAX_OUTBOUND_CONNECTIONS, (int)GetArg("-maxconnections", 24))) {
closesocket(hSocket);
}
else if (CNode::IsBanned(addr))
{
} else if (CNode::IsBanned(addr)) {
LogPrintf("connection from %s dropped (banned)\n", addr.ToString());
closesocket(hSocket);
}
else
{
} else {
LogPrint("net", "accepted connection %s\n", addr.ToString());
CNode* pnode = new CNode(hSocket, addr, "", true);
pnode->AddRef();
Expand Down
9 changes: 3 additions & 6 deletions src/netbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,10 @@ bool static ConnectSocketDirectly(const CService &addrConnect, SOCKET& hSocketRe
return false;
}

if (connect(hSocket, (struct sockaddr*)&sockaddr, len) == SOCKET_ERROR)
{
if (connect(hSocket, (struct sockaddr*)&sockaddr, len) == SOCKET_ERROR) {
int nErr = WSAGetLastError();
// WSAEINVAL is here because some legacy version of winsock uses it
if (nErr == WSAEINPROGRESS || nErr == WSAEWOULDBLOCK || nErr == WSAEINVAL)
{
if (nErr == WSAEINPROGRESS || nErr == WSAEWOULDBLOCK || nErr == WSAEINVAL) {
struct timeval timeout;
timeout.tv_sec = nTimeout / 1000;
timeout.tv_usec = (nTimeout % 1000) * 1000;
Expand All @@ -305,8 +303,7 @@ bool static ConnectSocketDirectly(const CService &addrConnect, SOCKET& hSocketRe
FD_ZERO(&fdset);
FD_SET(hSocket, &fdset);
int nRet = select(hSocket + 1, NULL, &fdset, NULL, &timeout);
if (nRet == 0)
{
if (nRet == 0) {
LogPrint("net", "connection to %s timeout\n", addrConnect.ToString());
closesocket(hSocket);
return false;
Expand Down
Binary file modified src/qt/res/icons/Ember.ico
Binary file not shown.
Binary file modified src/qt/res/icons/Ember_16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/qt/res/icons/Ember_64x64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/qt/res/icons/bitcoin_testnet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/qt/res/icons/overview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/qt/res/icons/staking_off.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/qt/res/icons/staking_on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/qt/res/images/about.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/qt/res/images/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions src/qt/walletmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,22 @@ qint64 WalletModel::getBalance(const CCoinControl *coinControl) const
return nBalance;
}

return wallet->GetBalance();
return wallet->GetBalance().getuint64();
}

qint64 WalletModel::getUnconfirmedBalance() const
{
return wallet->GetUnconfirmedBalance();
return wallet->GetUnconfirmedBalance().getuint64();
}

qint64 WalletModel::getStake() const
{
return wallet->GetStake();
return wallet->GetStake().getuint64();
}

qint64 WalletModel::getImmatureBalance() const
{
return wallet->GetImmatureBalance();
return wallet->GetImmatureBalance().getuint64();
}

void WalletModel::updateStatus()
Expand Down
6 changes: 3 additions & 3 deletions src/rpcmisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ Value getinfo(const Array& params, bool fHelp)
#ifdef ENABLE_WALLET
if (pwalletMain) {
obj.push_back(Pair("walletversion", pwalletMain->GetVersion()));
obj.push_back(Pair("balance", ValueFromAmount(pwalletMain->GetBalance())));
obj.push_back(Pair("newmint", ValueFromAmount(pwalletMain->GetNewMint())));
obj.push_back(Pair("stake", ValueFromAmount(pwalletMain->GetStake())));
obj.push_back(Pair("balance", ValueFromBigNumAmount(pwalletMain->GetBalance())));
obj.push_back(Pair("newmint", ValueFromBigNumAmount(pwalletMain->GetNewMint())));
obj.push_back(Pair("stake", ValueFromBigNumAmount(pwalletMain->GetStake())));
}
#endif
obj.push_back(Pair("blocks", (int)nBestHeight));
Expand Down
5 changes: 5 additions & 0 deletions src/rpcserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ int64_t AmountFromValue(const Value& value)
return nAmount;
}

Value ValueFromBigNumAmount(CBigNum amount)
{
return (double)amount.getuint256().getdouble() / (double)COIN;
}

Value ValueFromAmount(int64_t amount)
{
return (double)amount / (double)COIN;
Expand Down
1 change: 1 addition & 0 deletions src/rpcserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ extern void ShutdownRPCMining();

extern int64_t nWalletUnlockTime;
extern int64_t AmountFromValue(const json_spirit::Value& value);
extern json_spirit::Value ValueFromBigNumAmount(CBigNum amount);
extern json_spirit::Value ValueFromAmount(int64_t amount);
extern double GetDifficulty(const CBlockIndex* blockindex = NULL);

Expand Down
27 changes: 12 additions & 15 deletions src/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,8 @@ Value getreceivedbyaccount(const Array& params, bool fHelp)
}


int64_t GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMinDepth)
{
int64_t nBalance = 0;
CBigNum GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMinDepth) {
CBigNum nBalance(0);

// Tally wallet transactions
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
Expand All @@ -508,23 +507,21 @@ int64_t GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMi
return nBalance;
}

int64_t GetAccountBalance(const string& strAccount, int nMinDepth)
{
CBigNum GetAccountBalance(const string& strAccount, int nMinDepth) {
CWalletDB walletdb(pwalletMain->strWalletFile);
return GetAccountBalance(walletdb, strAccount, nMinDepth);
}


Value getbalance(const Array& params, bool fHelp)
{
Value getbalance(const Array& params, bool fHelp) {
if (fHelp || params.size() > 2)
throw runtime_error(
"getbalance [account] [minconf=1]\n"
"If [account] is not specified, returns the server's total available balance.\n"
"If [account] is specified, returns the balance in the account.");

if (params.size() == 0)
return ValueFromAmount(pwalletMain->GetBalance());
return ValueFromBigNumAmount(pwalletMain->GetBalance());

int nMinDepth = 1;
if (params.size() > 1)
Expand All @@ -534,7 +531,7 @@ Value getbalance(const Array& params, bool fHelp)
// Calculate total balance a different way from GetBalance()
// (GetBalance() sums up all unspent TxOuts)
// getbalance and getbalance '*' 0 should return the same number.
int64_t nBalance = 0;
CBigNum nBalance(0);
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
{
const CWalletTx& wtx = (*it).second;
Expand All @@ -555,16 +552,16 @@ Value getbalance(const Array& params, bool fHelp)
nBalance -= r.second;
nBalance -= allFee;
}
return ValueFromAmount(nBalance);
return ValueFromBigNumAmount(nBalance);
}

accountingDeprecationCheck();

string strAccount = AccountFromValue(params[0]);

int64_t nBalance = GetAccountBalance(strAccount, nMinDepth);

return ValueFromAmount(nBalance);
CBigNum nBalance(0);
nBalance = GetAccountBalance(strAccount, nMinDepth);
return ValueFromBigNumAmount(nBalance);
}


Expand Down Expand Up @@ -649,7 +646,7 @@ Value sendfrom(const Array& params, bool fHelp)
EnsureWalletIsUnlocked();

// Check funds
int64_t nBalance = GetAccountBalance(strAccount, nMinDepth);
CBigNum nBalance = GetAccountBalance(strAccount, nMinDepth);
if (nAmount > nBalance)
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");

Expand Down Expand Up @@ -707,7 +704,7 @@ Value sendmany(const Array& params, bool fHelp)
EnsureWalletIsUnlocked();

// Check funds
int64_t nBalance = GetAccountBalance(strAccount, nMinDepth);
CBigNum nBalance = GetAccountBalance(strAccount, nMinDepth);
if (totalAmount > nBalance)
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");

Expand Down
Loading

0 comments on commit d87fd13

Please sign in to comment.