aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--init.cpp21
-rw-r--r--main.cpp93
-rw-r--r--main.h1
-rw-r--r--rpc.cpp32
-rw-r--r--uibase.cpp1
-rw-r--r--uiproject.fbp2
-rw-r--r--util.cpp2
7 files changed, 133 insertions, 19 deletions
diff --git a/init.cpp b/init.cpp
index e114d80727..174cb0acbd 100644
--- a/init.cpp
+++ b/init.cpp
@@ -179,19 +179,19 @@ bool AppInit2(int argc, char* argv[])
" -testnet \t\t " + _("Use the test network\n") +
" -rpcuser=<user> \t " + _("Username for JSON-RPC connections\n") +
" -rpcpassword=<pw>\t " + _("Password for JSON-RPC connections\n") +
- " -rpcport=<port> \t\t " + _("Listen for JSON-RPC connections on <port>\n") +
+ " -rpcport=<port> \t\t " + _("Listen for JSON-RPC connections on <port> (default: 8332)\n") +
" -rpcallowip=<ip> \t\t " + _("Allow JSON-RPC connections from specified IP address\n") +
- " -rpcconnect=<ip> \t " + _("Send commands to node running on <ip>\n") +
- " -keypool=<n> \t " + _("Set key pool size to <n>\n") +
+ " -rpcconnect=<ip> \t " + _("Send commands to node running on <ip> (default: 127.0.0.1)\n") +
+ " -keypool=<n> \t " + _("Set key pool size to <n> (default: 100)\n") +
" -nolisten \t " + _("Don't accept connections from outside");
#ifdef USE_SSL
strUsage += string() +
_("\nSSL options: (see the Bitcoin Wiki for SSL setup instructions)\n") +
- " -rpcssl=1 \t " + _("Use OpenSSL (https) for JSON-RPC connections\n") +
- " -rpcsslcertificatchainfile=<file.cert>\t " + _("Server certificate file (default: server.cert)\n") +
- " -rpcsslprivatekeyfile=<file.pem> \t " + _("Server private key (default: server.pem)\n") +
- " -rpcsslciphers=<ciphers> \t " + _("Acceptable ciphers (default: TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!AH:!3DES:@STRENGTH)\n");
+ " -rpcssl=1 \t " + _("Use OpenSSL (https) for JSON-RPC connections\n") +
+ " -rpcsslcertificatechainfile=<file.cert>\t " + _("Server certificate file (default: server.cert)\n") +
+ " -rpcsslprivatekeyfile=<file.pem> \t " + _("Server private key (default: server.pem)\n") +
+ " -rpcsslciphers=<ciphers> \t " + _("Acceptable ciphers (default: TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!AH:!3DES:@STRENGTH)\n");
#endif
strUsage += string() +
@@ -330,6 +330,13 @@ bool AppInit2(int argc, char* argv[])
strErrors += _("Error loading wallet.dat \n");
printf(" wallet %15"PRI64d"ms\n", GetTimeMillis() - nStart);
+ if (GetBoolArg("-rescan"))
+ {
+ nStart = GetTimeMillis();
+ ScanForWalletTransactions(pindexGenesisBlock);
+ printf(" rescan %15"PRI64d"ms\n", GetTimeMillis() - nStart);
+ }
+
printf("Done loading\n");
//// debug print
diff --git a/main.cpp b/main.cpp
index 051e9c4de4..d19cbeff98 100644
--- a/main.cpp
+++ b/main.cpp
@@ -187,6 +187,19 @@ bool AddToWalletIfMine(const CTransaction& tx, const CBlock* pblock)
return true;
}
+bool AddToWalletIfFromMe(const CTransaction& tx, const CBlock* pblock)
+{
+ if (tx.IsFromMe() || mapWallet.count(tx.GetHash()))
+ {
+ CWalletTx wtx(tx);
+ // Get merkle branch if transaction was found in a block
+ if (pblock)
+ wtx.SetMerkleBranch(pblock);
+ return AddToWallet(wtx);
+ }
+ return true;
+}
+
bool EraseFromWallet(uint256 hash)
{
CRITICAL_BLOCK(cs_mapWallet)
@@ -404,7 +417,7 @@ void CWalletTx::GetAmounts(int64& nGenerated, list<pair<string, int64> >& listRe
if (IsCoinBase())
{
- if (GetBlocksToMaturity() == 0)
+ if (GetDepthInMainChain() >= COINBASE_MATURITY)
nGenerated = GetCredit();
return;
}
@@ -429,8 +442,13 @@ void CWalletTx::GetAmounts(int64& nGenerated, list<pair<string, int64> >& listRe
else if (ExtractPubKey(txout.scriptPubKey, false, vchPubKey))
address = PubKeyToAddress(vchPubKey);
else
- address = " unknown "; // some type of weird non-standard transaction?
+ {
+ printf("CWalletTx::GetAmounts: Unknown transaction type found, txid %s\n",
+ this->GetHash().ToString().c_str());
+ address = " unknown ";
+ }
+ // Don't report 'change' txouts
if (nDebit > 0 && txout.IsChange())
continue;
@@ -466,8 +484,19 @@ void CWalletTx::GetAccountAmounts(const string& strAccount, int64& nGenerated, i
CRITICAL_BLOCK(cs_mapAddressBook)
{
foreach(const PAIRTYPE(string,int64)& r, listReceived)
- if (mapAddressBook.count(r.first) && mapAddressBook[r.first] == strAccount)
+ {
+ if (mapAddressBook.count(r.first))
+ {
+ if (mapAddressBook[r.first] == strAccount)
+ {
+ nReceived += r.second;
+ }
+ }
+ else if (strAccount.empty())
+ {
nReceived += r.second;
+ }
+ }
}
}
@@ -849,11 +878,50 @@ bool CWalletTx::AcceptWalletTransaction(CTxDB& txdb, bool fCheckInputs)
return false;
}
+int ScanForWalletTransactions(CBlockIndex* pindexStart)
+{
+ int ret = 0;
+
+ CBlockIndex* pindex = pindexStart;
+ CRITICAL_BLOCK(cs_mapWallet)
+ {
+ while (pindex)
+ {
+ CBlock block;
+ block.ReadFromDisk(pindex, true);
+ foreach(CTransaction& tx, block.vtx)
+ {
+ uint256 hash = tx.GetHash();
+ if (mapWallet.count(hash)) continue;
+ AddToWalletIfMine(tx, &block);
+ if (mapWallet.count(hash))
+ {
+ ++ret;
+ printf("Added missing RECEIVE %s\n", hash.ToString().c_str());
+ continue;
+ }
+ AddToWalletIfFromMe(tx, &block);
+ if (mapWallet.count(hash))
+ {
+ ++ret;
+ printf("Added missing SEND %s\n", hash.ToString().c_str());
+ continue;
+ }
+ }
+ pindex = pindex->pnext;
+ }
+ }
+ return ret;
+}
+
void ReacceptWalletTransactions()
{
CTxDB txdb("r");
- CRITICAL_BLOCK(cs_mapWallet)
+ bool fRepeat = true;
+ while (fRepeat) CRITICAL_BLOCK(cs_mapWallet)
{
+ fRepeat = false;
+ vector<CDiskTxPos> vMissingTx;
foreach(PAIRTYPE(const uint256, CWalletTx)& item, mapWallet)
{
CWalletTx& wtx = item.second;
@@ -875,12 +943,15 @@ void ReacceptWalletTransactions()
{
if (!txindex.vSpent[i].IsNull() && wtx.vout[i].IsMine())
{
- printf("ReacceptWalletTransactions found spent coin %sbc %s\n", FormatMoney(wtx.GetCredit()).c_str(), wtx.GetHash().ToString().c_str());
wtx.fSpent = true;
- wtx.WriteToDisk();
- break;
+ vMissingTx.push_back(txindex.vSpent[i]);
}
}
+ if (wtx.fSpent)
+ {
+ printf("ReacceptWalletTransactions found spent coin %sbc %s\n", FormatMoney(wtx.GetCredit()).c_str(), wtx.GetHash().ToString().c_str());
+ wtx.WriteToDisk();
+ }
}
}
else
@@ -890,6 +961,12 @@ void ReacceptWalletTransactions()
wtx.AcceptWalletTransaction(txdb, false);
}
}
+ if (!vMissingTx.empty())
+ {
+ // TODO: optimize this to scan just part of the block chain?
+ if (ScanForWalletTransactions(pindexGenesisBlock))
+ fRepeat = true; // Found missing transactions: re-do Reaccept.
+ }
}
}
@@ -1361,8 +1438,6 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex)
return true;
}
-
-
bool Reorganize(CTxDB& txdb, CBlockIndex* pindexNew)
{
printf("REORGANIZE\n");
diff --git a/main.h b/main.h
index 3c7bcb22f0..a7ef336e00 100644
--- a/main.h
+++ b/main.h
@@ -69,6 +69,7 @@ bool AddKey(const CKey& key);
vector<unsigned char> GenerateNewKey();
bool AddToWallet(const CWalletTx& wtxIn);
void WalletUpdateSpent(const COutPoint& prevout);
+int ScanForWalletTransactions(CBlockIndex* pindexStart);
void ReacceptWalletTransactions();
bool LoadBlockIndex(bool fAllowNew=true);
void PrintBlockTree();
diff --git a/rpc.cpp b/rpc.cpp
index f80b24ea72..055e0cf1e7 100644
--- a/rpc.cpp
+++ b/rpc.cpp
@@ -621,6 +621,36 @@ Value getbalance(const Array& params, bool fHelp)
if (params.size() == 0)
return ((double)GetBalance() / (double)COIN);
+ if (params[0].get_str() == "*") {
+ // Calculate total balance a different way from GetBalance()
+ // (GetBalance() sums up all unspent TxOuts)
+ // getbalance and getbalance '*' should always return the same number.
+ int64 nBalance = 0;
+ vector<string> vAccounts;
+ for (map<uint256, CWalletTx>::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
+ {
+ const CWalletTx& wtx = (*it).second;
+ int64 allGenerated, allFee;
+ allGenerated = allFee = 0;
+ string strSentAccount;
+ list<pair<string, int64> > listReceived;
+ list<pair<string, int64> > listSent;
+ wtx.GetAmounts(allGenerated, listReceived, listSent, allFee, strSentAccount);
+ foreach(const PAIRTYPE(string,int64)& r, listReceived)
+ {
+ nBalance += r.second;
+ if (!count(vAccounts.begin(), vAccounts.end(), r.first))
+ vAccounts.push_back(r.first);
+ }
+ foreach(const PAIRTYPE(string,int64)& r, listSent)
+ nBalance -= r.second;
+ nBalance -= allFee;
+ nBalance += allGenerated;
+ }
+ printf("Found %d accounts\n", vAccounts.size());
+ return (double)nBalance / (double)COIN;
+ }
+
string strAccount = AccountFromValue(params[0]);
int nMinDepth = 1;
if (params.size() > 1)
@@ -1056,6 +1086,8 @@ Value listaccounts(const Array& params, bool fHelp)
foreach(const PAIRTYPE(string, int64)& r, listReceived)
if (mapAddressBook.count(r.first))
mapAccountBalances[mapAddressBook[r.first]] += r.second;
+ else
+ mapAccountBalances[""] += r.second;
}
}
}
diff --git a/uibase.cpp b/uibase.cpp
index 9fe98993ed..a421e776e3 100644
--- a/uibase.cpp
+++ b/uibase.cpp
@@ -61,7 +61,6 @@ CMainFrameBase::CMainFrameBase( wxWindow* parent, wxWindowID id, const wxString&
m_toolBar->Realize();
m_statusBar = this->CreateStatusBar( 1, wxST_SIZEGRIP, wxID_ANY );
- m_statusBar->SetBackgroundColour( wxColour( 240, 240, 240 ) );
wxBoxSizer* bSizer2;
bSizer2 = new wxBoxSizer( wxVERTICAL );
diff --git a/uiproject.fbp b/uiproject.fbp
index f3f9dc9fd0..bf01732ea8 100644
--- a/uiproject.fbp
+++ b/uiproject.fbp
@@ -282,7 +282,7 @@
</object>
</object>
<object class="wxStatusBar" expanded="1">
- <property name="bg">240,240,240</property>
+ <property name="bg"></property>
<property name="context_help"></property>
<property name="enabled">1</property>
<property name="fg"></property>
diff --git a/util.cpp b/util.cpp
index 694f913045..0ad9532d65 100644
--- a/util.cpp
+++ b/util.cpp
@@ -165,7 +165,7 @@ inline int OutputDebugStringF(const char* pszFormat, ...)
GetDataDir(pszFile);
strlcat(pszFile, "/debug.log", sizeof(pszFile));
fileout = fopen(pszFile, "a");
- setbuf(fileout, NULL); // unbuffered
+ if (fileout) setbuf(fileout, NULL); // unbuffered
}
if (fileout)
{