diff options
author | Gregory Maxwell <greg@xiph.org> | 2012-08-23 12:38:50 -0700 |
---|---|---|
committer | Gregory Maxwell <greg@xiph.org> | 2012-08-23 12:38:50 -0700 |
commit | 47753fa369f15274718779ffea1e2f151aa8307d (patch) | |
tree | 0caa89a1b21692c7e9a1dc03404280455186773f /src/wallet.h | |
parent | cf78183fadac6e9fccb51c7355cfa34641fc06d5 (diff) | |
parent | c3f95ef13f48d21db53992984976eac93e7a08fc (diff) | |
download | bitcoin-47753fa369f15274718779ffea1e2f151aa8307d.tar.xz |
Merge pull request #1393 from luke-jr/refactor_times
Refactor transaction/accounting time
Diffstat (limited to 'src/wallet.h')
-rw-r--r-- | src/wallet.h | 95 |
1 files changed, 94 insertions, 1 deletions
diff --git a/src/wallet.h b/src/wallet.h index 5bf38699ef..9103aa675e 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -5,12 +5,19 @@ #ifndef BITCOIN_WALLET_H #define BITCOIN_WALLET_H +#include <string> +#include <vector> + +#include <stdlib.h> + #include "main.h" #include "key.h" #include "keystore.h" #include "script.h" #include "ui_interface.h" +#include "util.h" +class CAccountingEntry; class CWalletTx; class CReserveKey; class CWalletDB; @@ -103,6 +110,7 @@ public: } std::map<uint256, CWalletTx> mapWallet; + int64 nOrderPosNext; std::map<uint256, int> mapRequestCount; std::map<CTxDestination, std::string> mapAddressBook; @@ -136,6 +144,10 @@ public: bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase); bool EncryptWallet(const SecureString& strWalletPassphrase); + typedef std::pair<CWalletTx*, CAccountingEntry*> TxPair; + typedef std::multimap<int64, TxPair > TxItems; + TxItems OrderedTxItems(std::string strAccount = ""); + void MarkDirty(); bool AddToWallet(const CWalletTx& wtxIn); bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate = false, bool fFindBlock = false); @@ -304,6 +316,32 @@ public: }; +typedef std::map<std::string, std::string> mapValue_t; + + +static +void +ReadOrderPos(int64& nOrderPos, mapValue_t& mapValue) +{ + if (!mapValue.count("n")) + { + nOrderPos = -1; // TODO: calculate elsewhere + return; + } + nOrderPos = atoi64(mapValue["n"].c_str()); +} + + +static +void +WriteOrderPos(const int64& nOrderPos, mapValue_t& mapValue) +{ + if (nOrderPos == -1) + return; + mapValue["n"] = i64tostr(nOrderPos); +} + + /** A transaction with a bunch of additional info that only the owner cares about. * It includes any unrecorded transactions needed to link it back to the block chain. */ @@ -314,13 +352,15 @@ private: public: std::vector<CMerkleTx> vtxPrev; - std::map<std::string, std::string> mapValue; + mapValue_t mapValue; std::vector<std::pair<std::string, std::string> > vOrderForm; unsigned int fTimeReceivedIsTxTime; unsigned int nTimeReceived; // time received by this node + unsigned int nTimeSmart; char fFromMe; std::string strFromAccount; std::vector<char> vfSpent; // which outputs are already spent + int64 nOrderPos; // position in ordered transaction list // memory only mutable bool fDebitCached; @@ -360,6 +400,7 @@ public: vOrderForm.clear(); fTimeReceivedIsTxTime = false; nTimeReceived = 0; + nTimeSmart = 0; fFromMe = false; strFromAccount.clear(); vfSpent.clear(); @@ -371,6 +412,7 @@ public: nCreditCached = 0; nAvailableCreditCached = 0; nChangeCached = 0; + nOrderPos = -1; } IMPLEMENT_SERIALIZE @@ -392,6 +434,11 @@ public: fSpent = true; } pthis->mapValue["spent"] = str; + + WriteOrderPos(pthis->nOrderPos, pthis->mapValue); + + if (nTimeSmart) + pthis->mapValue["timesmart"] = strprintf("%u", nTimeSmart); } nSerSize += SerReadWrite(s, *(CMerkleTx*)this, nType, nVersion,ser_action); @@ -412,11 +459,17 @@ public: pthis->vfSpent.push_back(c != '0'); else pthis->vfSpent.assign(vout.size(), fSpent); + + ReadOrderPos(pthis->nOrderPos, pthis->mapValue); + + pthis->nTimeSmart = mapValue.count("timesmart") ? (unsigned int)atoi64(pthis->mapValue["timesmart"]) : 0; } pthis->mapValue.erase("fromaccount"); pthis->mapValue.erase("version"); pthis->mapValue.erase("spent"); + pthis->mapValue.erase("n"); + pthis->mapValue.erase("timesmart"); ) // marks certain txout's as spent @@ -705,6 +758,9 @@ public: int64 nTime; std::string strOtherAccount; std::string strComment; + mapValue_t mapValue; + int64 nOrderPos; // position in ordered transaction list + uint64 nEntryNo; CAccountingEntry() { @@ -718,18 +774,55 @@ public: strAccount.clear(); strOtherAccount.clear(); strComment.clear(); + nOrderPos = -1; } IMPLEMENT_SERIALIZE ( + CAccountingEntry& me = *const_cast<CAccountingEntry*>(this); if (!(nType & SER_GETHASH)) READWRITE(nVersion); // Note: strAccount is serialized as part of the key, not here. READWRITE(nCreditDebit); READWRITE(nTime); READWRITE(strOtherAccount); + + if (!fRead) + { + WriteOrderPos(nOrderPos, me.mapValue); + + if (!(mapValue.empty() && _ssExtra.empty())) + { + CDataStream ss(nType, nVersion); + ss.insert(ss.begin(), '\0'); + ss << mapValue; + ss.insert(ss.end(), _ssExtra.begin(), _ssExtra.end()); + me.strComment.append(ss.str()); + } + } + READWRITE(strComment); + + size_t nSepPos = strComment.find("\0", 0, 1); + if (fRead) + { + me.mapValue.clear(); + if (std::string::npos != nSepPos) + { + CDataStream ss(std::vector<char>(strComment.begin() + nSepPos + 1, strComment.end()), nType, nVersion); + ss >> me.mapValue; + me._ssExtra = std::vector<char>(ss.begin(), ss.end()); + } + ReadOrderPos(me.nOrderPos, me.mapValue); + } + if (std::string::npos != nSepPos) + me.strComment.erase(nSepPos); + + me.mapValue.erase("n"); ) + +private: + std::vector<char> _ssExtra; }; bool GetWalletFile(CWallet* pwallet, std::string &strWalletFileOut); |