static const int64 MAX_MONEY = 21000000 * COIN;
inline bool MoneyRange(int64 nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }
static const int COINBASE_MATURITY = 100;
+#ifdef USE_UPNP
+static const int fHaveUPnP = true;
+#else
+static const int fHaveUPnP = false;
+#endif
extern int nLimitProcessors;
extern int fMinimizeToTray;
extern int fMinimizeOnClose;
+extern int fUseUPnP;
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();
bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv);
bool SendMessages(CNode* pto, bool fSendTrickle);
int64 GetBalance();
+bool CreateTransaction(const vector<pair<CScript, int64> >& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet);
bool CreateTransaction(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet);
bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey);
bool BroadcastTransaction(CWalletTx& wtxNew);
return n;
}
+ bool IsStandard() const
+ {
+ foreach(const CTxIn& txin, vin)
+ if (!txin.scriptSig.IsPushOnly())
+ return error("nonstandard txin: %s", txin.scriptSig.ToString().c_str());
+ foreach(const CTxOut& txout, vout)
+ if (!::IsStandard(txout.scriptPubKey))
+ return error("nonstandard txout: %s", txout.scriptPubKey.ToString().c_str());
+ return true;
+ }
+
bool IsMine() const
{
foreach(const CTxOut& txout, vout)
return nValueOut;
}
+ static bool AllowFree(double dPriority)
+ {
+ // Large (in bytes) low-priority (new, small-coin) transactions
+ // need a fee.
+ return dPriority > COIN * 144 / 250;
+ }
+
int64 GetMinFee(unsigned int nBlockSize=1, bool fAllowFree=true) const
{
// Base fee is 1 cent per kilobyte
fMerkleVerified = false;
}
+
IMPLEMENT_SERIALIZE
(
nSerSize += SerReadWrite(s, *(CTransaction*)this, nType, nVersion, ser_action);
vector<CMerkleTx> vtxPrev;
map<string, string> mapValue;
vector<pair<string, string> > vOrderForm;
+ unsigned int fTimeReceivedIsTxTime;
unsigned int nTimeReceived; // time received by this node
char fFromMe;
- char fSpent;
- char fTimeReceivedIsTxTime;
- char fUnused;
string strFromAccount;
+ vector<char> vfSpent;
// memory only
mutable char fDebitCached;
mutable char fCreditCached;
+ mutable char fAvailableCreditCached;
mutable char fChangeCached;
mutable int64 nDebitCached;
mutable int64 nCreditCached;
+ mutable int64 nAvailableCreditCached;
mutable int64 nChangeCached;
// memory only UI hints
vtxPrev.clear();
mapValue.clear();
vOrderForm.clear();
+ fTimeReceivedIsTxTime = false;
nTimeReceived = 0;
fFromMe = false;
- fSpent = false;
- fTimeReceivedIsTxTime = false;
- fUnused = false;
strFromAccount.clear();
+ vfSpent.clear();
fDebitCached = false;
fCreditCached = false;
+ fAvailableCreditCached = false;
fChangeCached = false;
nDebitCached = 0;
nCreditCached = 0;
+ nAvailableCreditCached = 0;
nChangeCached = 0;
nTimeDisplayed = 0;
nLinesDisplayed = 0;
IMPLEMENT_SERIALIZE
(
+ CWalletTx* pthis = const_cast<CWalletTx*>(this);
if (fRead)
- const_cast<CWalletTx*>(this)->Init();
- nSerSize += SerReadWrite(s, *(CMerkleTx*)this, nType, nVersion, ser_action);
+ pthis->Init();
+ char fSpent = false;
+
+ if (!fRead)
+ {
+ pthis->mapValue["fromaccount"] = pthis->strFromAccount;
+
+ string str;
+ foreach(char f, vfSpent)
+ {
+ str += (f ? '1' : '0');
+ if (f)
+ fSpent = true;
+ }
+ pthis->mapValue["spent"] = str;
+ }
+
+ nSerSize += SerReadWrite(s, *(CMerkleTx*)this, nType, nVersion,ser_action);
READWRITE(vtxPrev);
READWRITE(mapValue);
READWRITE(vOrderForm);
- READWRITE(nVersion);
- if (fRead && nVersion < 100)
- const_cast<CWalletTx*>(this)->fTimeReceivedIsTxTime = nVersion;
+ READWRITE(fTimeReceivedIsTxTime);
READWRITE(nTimeReceived);
READWRITE(fFromMe);
READWRITE(fSpent);
- if (nVersion >= 31404)
+
+ if (fRead)
{
- READWRITE(fTimeReceivedIsTxTime);
- READWRITE(fUnused);
- READWRITE(strFromAccount);
+ pthis->strFromAccount = pthis->mapValue["fromaccount"];
+
+ if (mapValue.count("spent"))
+ foreach(char c, pthis->mapValue["spent"])
+ pthis->vfSpent.push_back(c != '0');
+ else
+ pthis->vfSpent.assign(vout.size(), fSpent);
}
+
+ pthis->mapValue.erase("fromaccount");
+ pthis->mapValue.erase("version");
+ pthis->mapValue.erase("spent");
)
+ // marks certain txout's as spent
+ // returns true if any update took place
+ bool UpdateSpent(const vector<char>& vfNewSpent)
+ {
+ bool fReturn = false;
+ for (int i=0; i < vfNewSpent.size(); i++)
+ {
+ if (i == vfSpent.size())
+ break;
+
+ if (vfNewSpent[i] && !vfSpent[i])
+ {
+ vfSpent[i] = true;
+ fReturn = true;
+ fAvailableCreditCached = false;
+ }
+ }
+ return fReturn;
+ }
+
+ void MarkDirty()
+ {
+ fCreditCached = false;
+ fAvailableCreditCached = false;
+ fDebitCached = false;
+ fChangeCached = false;
+ }
+
+ void MarkSpent(unsigned int nOut)
+ {
+ if (nOut >= vout.size())
+ throw runtime_error("CWalletTx::MarkSpent() : nOut out of range");
+ vfSpent.resize(vout.size());
+ if (!vfSpent[nOut])
+ {
+ vfSpent[nOut] = true;
+ fAvailableCreditCached = false;
+ }
+ }
+
+ bool IsSpent(unsigned int nOut) const
+ {
+ if (nOut >= vout.size())
+ throw runtime_error("CWalletTx::IsSpent() : nOut out of range");
+ if (nOut >= vfSpent.size())
+ return false;
+ return (!!vfSpent[nOut]);
+ }
+
int64 GetDebit() const
{
if (vin.empty())
return nCreditCached;
}
+ int64 GetAvailableCredit(bool fUseCache=true) const
+ {
+ // Must wait until coinbase is safely deep enough in the chain before valuing it
+ if (IsCoinBase() && GetBlocksToMaturity() > 0)
+ return 0;
+
+ if (fUseCache && fAvailableCreditCached)
+ return nAvailableCreditCached;
+
+ int64 nCredit = 0;
+ for (int i = 0; i < vout.size(); i++)
+ {
+ if (!IsSpent(i))
+ {
+ const CTxOut &txout = vout[i];
+ nCredit += txout.GetCredit();
+ if (!MoneyRange(nCredit))
+ throw runtime_error("CWalletTx::GetAvailableCredit() : value out of range");
+ }
+ }
+
+ nAvailableCreditCached = nCredit;
+ fAvailableCreditCached = true;
+ return nCredit;
+ }
+
+
int64 GetChange() const
{
if (fChangeCached)
return nChangeCached;
}
+ void GetAmounts(int64& nGeneratedImmature, int64& nGeneratedMature, list<pair<string /* address */, int64> >& listReceived,
+ list<pair<string /* address */, int64> >& listSent, int64& nFee, string& strSentAccount) const;
+
+ void GetAccountAmounts(const string& strAccount, int64& nGenerated, int64& nReceived,
+ int64& nSent, int64& nFee) const;
+
bool IsFromMe() const
{
return (GetDebit() > 0);
}
- void GetAccountAmounts(string strAccount, const set<CScript>& setPubKey,
- int64& nGenerated, int64& nReceived, int64& nSent, int64& nFee) const
- {
- nGenerated = nReceived = nSent = nFee = 0;
-
- // Generated blocks count to account ""
- if (IsCoinBase())
- {
- if (strAccount == "" && GetBlocksToMaturity() == 0)
- nGenerated = GetCredit();
- return;
- }
-
- // Received
- foreach(const CTxOut& txout, vout)
- if (setPubKey.count(txout.scriptPubKey))
- nReceived += txout.nValue;
-
- // Sent
- if (strFromAccount == strAccount)
- {
- int64 nDebit = GetDebit();
- if (nDebit > 0)
- {
- int64 nValueOut = GetValueOut();
- nFee = nDebit - nValueOut;
- nSent = nValueOut - GetChange();
- }
- }
- }
-
bool IsConfirmed() const
{
// Quick answer in most cases
{
return !(a == b);
}
+ int GetDepthInMainChain() const;
};
}
- bool WriteToDisk(bool fWriteTransactions, unsigned int& nFileRet, unsigned int& nBlockPosRet)
+ bool WriteToDisk(unsigned int& nFileRet, unsigned int& nBlockPosRet)
{
// Open history file to append
CAutoFile fileout = AppendBlockFile(nFileRet);
if (!fileout)
return error("CBlock::WriteToDisk() : AppendBlockFile failed");
- if (!fWriteTransactions)
- fileout.nType |= SER_BLOCKHEADERONLY;
// Write index header
unsigned int nSize = fileout.GetSerializeSize(*this);
nNonce = block.nNonce;
}
+ CBlock GetBlockHeader() const
+ {
+ CBlock block;
+ block.nVersion = nVersion;
+ if (pprev)
+ block.hashPrevBlock = pprev->GetBlockHash();
+ block.hashMerkleRoot = hashMerkleRoot;
+ block.nTime = nTime;
+ block.nBits = nBits;
+ block.nNonce = nNonce;
+ return block;
+ }
+
uint256 GetBlockHash() const
{
return *phashBlock;
READWRITE(vHave);
)
+ void SetNull()
+ {
+ vHave.clear();
+ }
+
+ bool IsNull()
+ {
+ return vHave.empty();
+ }
+
void Set(const CBlockIndex* pindex)
{
vHave.clear();
class CAccountingEntry
{
public:
+ string strAccount;
int64 nCreditDebit;
int64 nTime;
string strOtherAccount;
{
nCreditDebit = 0;
nTime = 0;
+ strAccount.clear();
strOtherAccount.clear();
strComment.clear();
}
(
if (!(nType & SER_GETHASH))
READWRITE(nVersion);
+ // Note: strAccount is serialized as part of the key, not here.
READWRITE(nCreditDebit);
READWRITE(nTime);
READWRITE(strOtherAccount);
//
+// Alerts are for notifying old versions if they become too obsolete and
+// need to upgrade. The message is displayed in the status bar.
// Alert messages are broadcast as a vector of signed data. Unserializing may
// not read the entire buffer if the alert is for a newer version, but older
// versions can still relay the original data.
// Actions
string strComment;
string strStatusBar;
- string strRPCError;
+ string strReserved;
IMPLEMENT_SERIALIZE
(
READWRITE(strComment);
READWRITE(strStatusBar);
- READWRITE(strRPCError);
+ READWRITE(strReserved);
)
void SetNull()
strComment.clear();
strStatusBar.clear();
- strRPCError.clear();
+ strReserved.clear();
}
string ToString() const
" nPriority = %d\n"
" strComment = \"%s\"\n"
" strStatusBar = \"%s\"\n"
- " strRPCError = \"%s\"\n"
")\n",
nVersion,
nRelayUntil,
strSetSubVer.c_str(),
nPriority,
strComment.c_str(),
- strStatusBar.c_str(),
- strRPCError.c_str());
+ strStatusBar.c_str());
}
void print() const