raw
genesis                 1 // Copyright (c) 2009-2010 Satoshi Nakamoto
genesis 2 // Copyright (c) 2009-2012 The Bitcoin developers
genesis 3 // Distributed under the MIT/X11 software license, see the accompanying
genesis 4 // file license.txt or http://www.opensource.org/licenses/mit-license.php.
genesis 5 #ifndef BITCOIN_WALLET_H
genesis 6 #define BITCOIN_WALLET_H
genesis 7
genesis 8 #include "bignum.h"
genesis 9 #include "key.h"
genesis 10 #include "script.h"
genesis 11
genesis 12 class CWalletTx;
genesis 13 class CReserveKey;
genesis 14 class CWalletDB;
genesis 15
genesis 16 // A CWallet is an extension of a keystore, which also maintains a set of
genesis 17 // transactions and balances, and provides the ability to create new
genesis 18 // transactions
genesis 19 class CWallet : public CCryptoKeyStore
genesis 20 {
genesis 21 private:
genesis 22 bool SelectCoinsMinConf(int64 nTargetValue, int nConfMine, int nConfTheirs, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64& nValueRet) const;
genesis 23 bool SelectCoins(int64 nTargetValue, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64& nValueRet) const;
genesis 24
genesis 25 CWalletDB *pwalletdbEncryption;
genesis 26
genesis 27 public:
genesis 28 mutable CCriticalSection cs_wallet;
genesis 29
genesis 30 bool fFileBacked;
genesis 31 std::string strWalletFile;
genesis 32
genesis 33 std::set<int64> setKeyPool;
genesis 34
genesis 35 typedef std::map<unsigned int, CMasterKey> MasterKeyMap;
genesis 36 MasterKeyMap mapMasterKeys;
genesis 37 unsigned int nMasterKeyMaxID;
genesis 38
genesis 39 CWallet()
genesis 40 {
genesis 41 fFileBacked = false;
genesis 42 nMasterKeyMaxID = 0;
genesis 43 pwalletdbEncryption = NULL;
genesis 44 }
genesis 45 CWallet(std::string strWalletFileIn)
genesis 46 {
genesis 47 strWalletFile = strWalletFileIn;
genesis 48 fFileBacked = true;
genesis 49 nMasterKeyMaxID = 0;
genesis 50 pwalletdbEncryption = NULL;
genesis 51 }
genesis 52
genesis 53 std::map<uint256, CWalletTx> mapWallet;
genesis 54 std::vector<uint256> vWalletUpdated;
genesis 55
genesis 56 std::map<uint256, int> mapRequestCount;
genesis 57
genesis 58 std::map<CBitcoinAddress, std::string> mapAddressBook;
genesis 59
genesis 60 std::vector<unsigned char> vchDefaultKey;
genesis 61
genesis 62 // keystore implementation
genesis 63 // Adds a key to the store, and saves it to disk.
genesis 64 bool AddKey(const CKey& key);
genesis 65 // Adds a key to the store, without saving it to disk (used by LoadWallet)
genesis 66 bool LoadKey(const CKey& key) { return CCryptoKeyStore::AddKey(key); }
genesis 67
genesis 68 // Adds an encrypted key to the store, and saves it to disk.
genesis 69 bool AddCryptedKey(const std::vector<unsigned char> &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret);
genesis 70 // Adds an encrypted key to the store, without saving it to disk (used by LoadWallet)
genesis 71 bool LoadCryptedKey(const std::vector<unsigned char> &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret) { return CCryptoKeyStore::AddCryptedKey(vchPubKey, vchCryptedSecret); }
genesis 72
genesis 73 bool Unlock(const SecureString& strWalletPassphrase);
genesis 74 bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase);
genesis 75 bool EncryptWallet(const SecureString& strWalletPassphrase);
genesis 76
genesis 77 bool AddToWallet(const CWalletTx& wtxIn);
genesis 78 bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate = false);
genesis 79 bool EraseFromWallet(uint256 hash);
genesis 80 void WalletUpdateSpent(const CTransaction& prevout);
genesis 81 int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false);
genesis 82 void ReacceptWalletTransactions();
genesis 83 void ResendWalletTransactions();
genesis 84 int64 GetBalance() const;
genesis 85 int64 GetUnconfirmedBalance() const;
genesis 86 bool CreateTransaction(const std::vector<std::pair<CScript, int64> >& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet);
genesis 87 bool CreateTransaction(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet);
genesis 88 bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey);
genesis 89 std::string SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, bool fAskFee=false);
genesis 90 std::string SendMoneyToBitcoinAddress(const CBitcoinAddress& address, int64 nValue, CWalletTx& wtxNew, bool fAskFee=false);
genesis 91
genesis 92 bool NewKeyPool();
genesis 93 bool TopUpKeyPool();
genesis 94 void ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool);
genesis 95 void KeepKey(int64 nIndex);
genesis 96 void ReturnKey(int64 nIndex);
genesis 97 bool GetKeyFromPool(std::vector<unsigned char> &key, bool fAllowReuse=true);
genesis 98 int64 GetOldestKeyPoolTime();
genesis 99
genesis 100 bool IsMine(const CTxIn& txin) const;
genesis 101 int64 GetDebit(const CTxIn& txin) const;
genesis 102 bool IsMine(const CTxOut& txout) const
genesis 103 {
genesis 104 return ::IsMine(*this, txout.scriptPubKey);
genesis 105 }
genesis 106 int64 GetCredit(const CTxOut& txout) const
genesis 107 {
genesis 108 if (!MoneyRange(txout.nValue))
genesis 109 throw std::runtime_error("CWallet::GetCredit() : value out of range");
genesis 110 return (IsMine(txout) ? txout.nValue : 0);
genesis 111 }
genesis 112 bool IsChange(const CTxOut& txout) const
genesis 113 {
genesis 114 CBitcoinAddress address;
genesis 115 if (ExtractAddress(txout.scriptPubKey, this, address))
genesis 116 CRITICAL_BLOCK(cs_wallet)
genesis 117 if (!mapAddressBook.count(address))
genesis 118 return true;
genesis 119 return false;
genesis 120 }
genesis 121 int64 GetChange(const CTxOut& txout) const
genesis 122 {
genesis 123 if (!MoneyRange(txout.nValue))
genesis 124 throw std::runtime_error("CWallet::GetChange() : value out of range");
genesis 125 return (IsChange(txout) ? txout.nValue : 0);
genesis 126 }
genesis 127 bool IsMine(const CTransaction& tx) const
genesis 128 {
genesis 129 BOOST_FOREACH(const CTxOut& txout, tx.vout)
genesis 130 if (IsMine(txout))
genesis 131 return true;
genesis 132 return false;
genesis 133 }
genesis 134 bool IsFromMe(const CTransaction& tx) const
genesis 135 {
genesis 136 return (GetDebit(tx) > 0);
genesis 137 }
genesis 138 int64 GetDebit(const CTransaction& tx) const
genesis 139 {
genesis 140 int64 nDebit = 0;
genesis 141 BOOST_FOREACH(const CTxIn& txin, tx.vin)
genesis 142 {
genesis 143 nDebit += GetDebit(txin);
genesis 144 if (!MoneyRange(nDebit))
genesis 145 throw std::runtime_error("CWallet::GetDebit() : value out of range");
genesis 146 }
genesis 147 return nDebit;
genesis 148 }
genesis 149 int64 GetCredit(const CTransaction& tx) const
genesis 150 {
genesis 151 int64 nCredit = 0;
genesis 152 BOOST_FOREACH(const CTxOut& txout, tx.vout)
genesis 153 {
genesis 154 nCredit += GetCredit(txout);
genesis 155 if (!MoneyRange(nCredit))
genesis 156 throw std::runtime_error("CWallet::GetCredit() : value out of range");
genesis 157 }
genesis 158 return nCredit;
genesis 159 }
genesis 160 int64 GetChange(const CTransaction& tx) const
genesis 161 {
genesis 162 int64 nChange = 0;
genesis 163 BOOST_FOREACH(const CTxOut& txout, tx.vout)
genesis 164 {
genesis 165 nChange += GetChange(txout);
genesis 166 if (!MoneyRange(nChange))
genesis 167 throw std::runtime_error("CWallet::GetChange() : value out of range");
genesis 168 }
genesis 169 return nChange;
genesis 170 }
genesis 171 void SetBestChain(const CBlockLocator& loc)
genesis 172 {
genesis 173 CWalletDB walletdb(strWalletFile);
genesis 174 walletdb.WriteBestBlock(loc);
genesis 175 }
genesis 176
genesis 177 int LoadWallet(bool& fFirstRunRet);
genesis 178 // bool BackupWallet(const std::string& strDest);
genesis 179
genesis 180 bool SetAddressBookName(const CBitcoinAddress& address, const std::string& strName);
genesis 181
genesis 182 bool DelAddressBookName(const CBitcoinAddress& address);
genesis 183
genesis 184 void UpdatedTransaction(const uint256 &hashTx)
genesis 185 {
genesis 186 CRITICAL_BLOCK(cs_wallet)
genesis 187 vWalletUpdated.push_back(hashTx);
genesis 188 }
genesis 189
genesis 190 void PrintWallet(const CBlock& block);
genesis 191
genesis 192 void Inventory(const uint256 &hash)
genesis 193 {
genesis 194 CRITICAL_BLOCK(cs_wallet)
genesis 195 {
genesis 196 std::map<uint256, int>::iterator mi = mapRequestCount.find(hash);
genesis 197 if (mi != mapRequestCount.end())
genesis 198 (*mi).second++;
genesis 199 }
genesis 200 }
genesis 201
genesis 202 int GetKeyPoolSize()
genesis 203 {
genesis 204 return setKeyPool.size();
genesis 205 }
genesis 206
genesis 207 bool GetTransaction(const uint256 &hashTx, CWalletTx& wtx);
genesis 208
genesis 209 bool SetDefaultKey(const std::vector<unsigned char> &vchPubKey);
genesis 210 };
genesis 211
genesis 212
genesis 213 class CReserveKey
genesis 214 {
genesis 215 protected:
genesis 216 CWallet* pwallet;
genesis 217 int64 nIndex;
genesis 218 std::vector<unsigned char> vchPubKey;
genesis 219 public:
genesis 220 CReserveKey(CWallet* pwalletIn)
genesis 221 {
genesis 222 nIndex = -1;
genesis 223 pwallet = pwalletIn;
genesis 224 }
genesis 225
genesis 226 ~CReserveKey()
genesis 227 {
genesis 228 if (!fShutdown)
genesis 229 ReturnKey();
genesis 230 }
genesis 231
genesis 232 void ReturnKey();
genesis 233 std::vector<unsigned char> GetReservedKey();
genesis 234 void KeepKey();
genesis 235 };
genesis 236
genesis 237
genesis 238 //
genesis 239 // A transaction with a bunch of additional info that only the owner cares
genesis 240 // about. It includes any unrecorded transactions needed to link it back
genesis 241 // to the block chain.
genesis 242 //
genesis 243 class CWalletTx : public CMerkleTx
genesis 244 {
genesis 245 public:
genesis 246 const CWallet* pwallet;
genesis 247
genesis 248 std::vector<CMerkleTx> vtxPrev;
genesis 249 std::map<std::string, std::string> mapValue;
genesis 250 std::vector<std::pair<std::string, std::string> > vOrderForm;
genesis 251 unsigned int fTimeReceivedIsTxTime;
genesis 252 unsigned int nTimeReceived; // time received by this node
genesis 253 char fFromMe;
genesis 254 std::string strFromAccount;
genesis 255 std::vector<char> vfSpent; // which outputs are already spent
genesis 256
genesis 257 // memory only
genesis 258 mutable char fDebitCached;
genesis 259 mutable char fCreditCached;
genesis 260 mutable char fAvailableCreditCached;
genesis 261 mutable char fChangeCached;
genesis 262 mutable int64 nDebitCached;
genesis 263 mutable int64 nCreditCached;
genesis 264 mutable int64 nAvailableCreditCached;
genesis 265 mutable int64 nChangeCached;
genesis 266
genesis 267 // memory only UI hints
genesis 268 mutable unsigned int nTimeDisplayed;
genesis 269 mutable int nLinesDisplayed;
genesis 270 mutable char fConfirmedDisplayed;
genesis 271
genesis 272 CWalletTx()
genesis 273 {
genesis 274 Init(NULL);
genesis 275 }
genesis 276
genesis 277 CWalletTx(const CWallet* pwalletIn)
genesis 278 {
genesis 279 Init(pwalletIn);
genesis 280 }
genesis 281
genesis 282 CWalletTx(const CWallet* pwalletIn, const CMerkleTx& txIn) : CMerkleTx(txIn)
genesis 283 {
genesis 284 Init(pwalletIn);
genesis 285 }
genesis 286
genesis 287 CWalletTx(const CWallet* pwalletIn, const CTransaction& txIn) : CMerkleTx(txIn)
genesis 288 {
genesis 289 Init(pwalletIn);
genesis 290 }
genesis 291
genesis 292 void Init(const CWallet* pwalletIn)
genesis 293 {
genesis 294 pwallet = pwalletIn;
genesis 295 vtxPrev.clear();
genesis 296 mapValue.clear();
genesis 297 vOrderForm.clear();
genesis 298 fTimeReceivedIsTxTime = false;
genesis 299 nTimeReceived = 0;
genesis 300 fFromMe = false;
genesis 301 strFromAccount.clear();
genesis 302 vfSpent.clear();
genesis 303 fDebitCached = false;
genesis 304 fCreditCached = false;
genesis 305 fAvailableCreditCached = false;
genesis 306 fChangeCached = false;
genesis 307 nDebitCached = 0;
genesis 308 nCreditCached = 0;
genesis 309 nAvailableCreditCached = 0;
genesis 310 nChangeCached = 0;
genesis 311 nTimeDisplayed = 0;
genesis 312 nLinesDisplayed = 0;
genesis 313 fConfirmedDisplayed = false;
genesis 314 }
genesis 315
genesis 316 IMPLEMENT_SERIALIZE
genesis 317 (
genesis 318 CWalletTx* pthis = const_cast<CWalletTx*>(this);
genesis 319 if (fRead)
genesis 320 pthis->Init(NULL);
genesis 321 char fSpent = false;
genesis 322
genesis 323 if (!fRead)
genesis 324 {
genesis 325 pthis->mapValue["fromaccount"] = pthis->strFromAccount;
genesis 326
genesis 327 std::string str;
genesis 328 BOOST_FOREACH(char f, vfSpent)
genesis 329 {
genesis 330 str += (f ? '1' : '0');
genesis 331 if (f)
genesis 332 fSpent = true;
genesis 333 }
genesis 334 pthis->mapValue["spent"] = str;
genesis 335 }
genesis 336
genesis 337 nSerSize += SerReadWrite(s, *(CMerkleTx*)this, nType, nVersion,ser_action);
genesis 338 READWRITE(vtxPrev);
genesis 339 READWRITE(mapValue);
genesis 340 READWRITE(vOrderForm);
genesis 341 READWRITE(fTimeReceivedIsTxTime);
genesis 342 READWRITE(nTimeReceived);
genesis 343 READWRITE(fFromMe);
genesis 344 READWRITE(fSpent);
genesis 345
genesis 346 if (fRead)
genesis 347 {
genesis 348 pthis->strFromAccount = pthis->mapValue["fromaccount"];
genesis 349
genesis 350 if (mapValue.count("spent"))
genesis 351 BOOST_FOREACH(char c, pthis->mapValue["spent"])
genesis 352 pthis->vfSpent.push_back(c != '0');
genesis 353 else
genesis 354 pthis->vfSpent.assign(vout.size(), fSpent);
genesis 355 }
genesis 356
genesis 357 pthis->mapValue.erase("fromaccount");
genesis 358 pthis->mapValue.erase("version");
genesis 359 pthis->mapValue.erase("spent");
genesis 360 )
genesis 361
genesis 362 // marks certain txout's as spent
genesis 363 // returns true if any update took place
genesis 364 bool UpdateSpent(const std::vector<char>& vfNewSpent)
genesis 365 {
genesis 366 bool fReturn = false;
genesis 367 for (int i=0; i < vfNewSpent.size(); i++)
genesis 368 {
genesis 369 if (i == vfSpent.size())
genesis 370 break;
genesis 371
genesis 372 if (vfNewSpent[i] && !vfSpent[i])
genesis 373 {
genesis 374 vfSpent[i] = true;
genesis 375 fReturn = true;
genesis 376 fAvailableCreditCached = false;
genesis 377 }
genesis 378 }
genesis 379 return fReturn;
genesis 380 }
genesis 381
genesis 382 // make sure balances are recalculated
genesis 383 void MarkDirty()
genesis 384 {
genesis 385 fCreditCached = false;
genesis 386 fAvailableCreditCached = false;
genesis 387 fDebitCached = false;
genesis 388 fChangeCached = false;
genesis 389 }
genesis 390
genesis 391 void MarkSpent(unsigned int nOut)
genesis 392 {
genesis 393 if (nOut >= vout.size())
genesis 394 throw std::runtime_error("CWalletTx::MarkSpent() : nOut out of range");
genesis 395 vfSpent.resize(vout.size());
genesis 396 if (!vfSpent[nOut])
genesis 397 {
genesis 398 vfSpent[nOut] = true;
genesis 399 fAvailableCreditCached = false;
genesis 400 }
genesis 401 }
genesis 402
genesis 403 bool IsSpent(unsigned int nOut) const
genesis 404 {
genesis 405 if (nOut >= vout.size())
genesis 406 throw std::runtime_error("CWalletTx::IsSpent() : nOut out of range");
genesis 407 if (nOut >= vfSpent.size())
genesis 408 return false;
genesis 409 return (!!vfSpent[nOut]);
genesis 410 }
genesis 411
genesis 412 int64 GetDebit() const
genesis 413 {
genesis 414 if (vin.empty())
genesis 415 return 0;
genesis 416 if (fDebitCached)
genesis 417 return nDebitCached;
genesis 418 nDebitCached = pwallet->GetDebit(*this);
genesis 419 fDebitCached = true;
genesis 420 return nDebitCached;
genesis 421 }
genesis 422
genesis 423 int64 GetCredit(bool fUseCache=true) const
genesis 424 {
genesis 425 // Must wait until coinbase is safely deep enough in the chain before valuing it
genesis 426 if (IsCoinBase() && GetBlocksToMaturity() > 0)
genesis 427 return 0;
genesis 428
genesis 429 // GetBalance can assume transactions in mapWallet won't change
genesis 430 if (fUseCache && fCreditCached)
genesis 431 return nCreditCached;
genesis 432 nCreditCached = pwallet->GetCredit(*this);
genesis 433 fCreditCached = true;
genesis 434 return nCreditCached;
genesis 435 }
genesis 436
genesis 437 int64 GetAvailableCredit(bool fUseCache=true) const
genesis 438 {
genesis 439 // Must wait until coinbase is safely deep enough in the chain before valuing it
genesis 440 if (IsCoinBase() && GetBlocksToMaturity() > 0)
genesis 441 return 0;
genesis 442
genesis 443 if (fUseCache && fAvailableCreditCached)
genesis 444 return nAvailableCreditCached;
genesis 445
genesis 446 int64 nCredit = 0;
genesis 447 for (int i = 0; i < vout.size(); i++)
genesis 448 {
genesis 449 if (!IsSpent(i))
genesis 450 {
genesis 451 const CTxOut &txout = vout[i];
genesis 452 nCredit += pwallet->GetCredit(txout);
genesis 453 if (!MoneyRange(nCredit))
genesis 454 throw std::runtime_error("CWalletTx::GetAvailableCredit() : value out of range");
genesis 455 }
genesis 456 }
genesis 457
genesis 458 nAvailableCreditCached = nCredit;
genesis 459 fAvailableCreditCached = true;
genesis 460 return nCredit;
genesis 461 }
genesis 462
genesis 463
genesis 464 int64 GetChange() const
genesis 465 {
genesis 466 if (fChangeCached)
genesis 467 return nChangeCached;
genesis 468 nChangeCached = pwallet->GetChange(*this);
genesis 469 fChangeCached = true;
genesis 470 return nChangeCached;
genesis 471 }
genesis 472
genesis 473 void GetAmounts(int64& nGeneratedImmature, int64& nGeneratedMature, std::list<std::pair<CBitcoinAddress, int64> >& listReceived,
genesis 474 std::list<std::pair<CBitcoinAddress, int64> >& listSent, int64& nFee, std::string& strSentAccount) const;
genesis 475
genesis 476 void GetAccountAmounts(const std::string& strAccount, int64& nGenerated, int64& nReceived,
genesis 477 int64& nSent, int64& nFee) const;
genesis 478
genesis 479 bool IsFromMe() const
genesis 480 {
genesis 481 return (GetDebit() > 0);
genesis 482 }
genesis 483
genesis 484 bool IsConfirmed() const
genesis 485 {
genesis 486 // Quick answer in most cases
genesis 487 if (!IsFinal())
genesis 488 return false;
genesis 489 if (GetDepthInMainChain() >= 1)
genesis 490 return true;
genesis 491 if (!IsFromMe()) // using wtx's cached debit
genesis 492 return false;
genesis 493
genesis 494 // If no confirmations but it's from us, we can still
genesis 495 // consider it confirmed if all dependencies are confirmed
genesis 496 std::map<uint256, const CMerkleTx*> mapPrev;
genesis 497 std::vector<const CMerkleTx*> vWorkQueue;
genesis 498 vWorkQueue.reserve(vtxPrev.size()+1);
genesis 499 vWorkQueue.push_back(this);
genesis 500 for (int i = 0; i < vWorkQueue.size(); i++)
genesis 501 {
genesis 502 const CMerkleTx* ptx = vWorkQueue[i];
genesis 503
genesis 504 if (!ptx->IsFinal())
genesis 505 return false;
genesis 506 if (ptx->GetDepthInMainChain() >= 1)
genesis 507 continue;
genesis 508 if (!pwallet->IsFromMe(*ptx))
genesis 509 return false;
genesis 510
genesis 511 if (mapPrev.empty())
genesis 512 BOOST_FOREACH(const CMerkleTx& tx, vtxPrev)
genesis 513 mapPrev[tx.GetHash()] = &tx;
genesis 514
genesis 515 BOOST_FOREACH(const CTxIn& txin, ptx->vin)
genesis 516 {
genesis 517 if (!mapPrev.count(txin.prevout.hash))
genesis 518 return false;
genesis 519 vWorkQueue.push_back(mapPrev[txin.prevout.hash]);
genesis 520 }
genesis 521 }
genesis 522 return true;
genesis 523 }
genesis 524
genesis 525 bool WriteToDisk();
genesis 526
genesis 527 int64 GetTxTime() const;
genesis 528 int GetRequestCount() const;
genesis 529
genesis 530 void AddSupportingTransactions(CTxDB& txdb);
genesis 531
genesis 532 bool AcceptWalletTransaction(CTxDB& txdb, bool fCheckInputs=true);
genesis 533 bool AcceptWalletTransaction();
genesis 534
genesis 535 void RelayWalletTransaction(CTxDB& txdb);
genesis 536 void RelayWalletTransaction();
genesis 537 };
genesis 538
genesis 539
genesis 540 //
genesis 541 // Private key that includes an expiration date in case it never gets used.
genesis 542 //
genesis 543 class CWalletKey
genesis 544 {
genesis 545 public:
genesis 546 CPrivKey vchPrivKey;
genesis 547 int64 nTimeCreated;
genesis 548 int64 nTimeExpires;
genesis 549 std::string strComment;
genesis 550 //// todo: add something to note what created it (user, getnewaddress, change)
genesis 551 //// maybe should have a map<string, string> property map
genesis 552
genesis 553 CWalletKey(int64 nExpires=0)
genesis 554 {
genesis 555 nTimeCreated = (nExpires ? GetTime() : 0);
genesis 556 nTimeExpires = nExpires;
genesis 557 }
genesis 558
genesis 559 IMPLEMENT_SERIALIZE
genesis 560 (
genesis 561 if (!(nType & SER_GETHASH))
genesis 562 READWRITE(nVersion);
genesis 563 READWRITE(vchPrivKey);
genesis 564 READWRITE(nTimeCreated);
genesis 565 READWRITE(nTimeExpires);
genesis 566 READWRITE(strComment);
genesis 567 )
genesis 568 };
genesis 569
genesis 570
genesis 571
genesis 572
genesis 573
genesis 574
genesis 575 //
genesis 576 // Account information.
genesis 577 // Stored in wallet with key "acc"+string account name
genesis 578 //
genesis 579 class CAccount
genesis 580 {
genesis 581 public:
genesis 582 std::vector<unsigned char> vchPubKey;
genesis 583
genesis 584 CAccount()
genesis 585 {
genesis 586 SetNull();
genesis 587 }
genesis 588
genesis 589 void SetNull()
genesis 590 {
genesis 591 vchPubKey.clear();
genesis 592 }
genesis 593
genesis 594 IMPLEMENT_SERIALIZE
genesis 595 (
genesis 596 if (!(nType & SER_GETHASH))
genesis 597 READWRITE(nVersion);
genesis 598 READWRITE(vchPubKey);
genesis 599 )
genesis 600 };
genesis 601
genesis 602
genesis 603
genesis 604 //
genesis 605 // Internal transfers.
genesis 606 // Database key is acentry<account><counter>
genesis 607 //
genesis 608 class CAccountingEntry
genesis 609 {
genesis 610 public:
genesis 611 std::string strAccount;
genesis 612 int64 nCreditDebit;
genesis 613 int64 nTime;
genesis 614 std::string strOtherAccount;
genesis 615 std::string strComment;
genesis 616
genesis 617 CAccountingEntry()
genesis 618 {
genesis 619 SetNull();
genesis 620 }
genesis 621
genesis 622 void SetNull()
genesis 623 {
genesis 624 nCreditDebit = 0;
genesis 625 nTime = 0;
genesis 626 strAccount.clear();
genesis 627 strOtherAccount.clear();
genesis 628 strComment.clear();
genesis 629 }
genesis 630
genesis 631 IMPLEMENT_SERIALIZE
genesis 632 (
genesis 633 if (!(nType & SER_GETHASH))
genesis 634 READWRITE(nVersion);
genesis 635 // Note: strAccount is serialized as part of the key, not here.
genesis 636 READWRITE(nCreditDebit);
genesis 637 READWRITE(nTime);
genesis 638 READWRITE(strOtherAccount);
genesis 639 READWRITE(strComment);
genesis 640 )
genesis 641 };
genesis 642
genesis 643 bool GetWalletFile(CWallet* pwallet, std::string &strWalletFileOut);
genesis 644
genesis 645 #endif