diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2011-07-11 21:49:45 +0200 |
---|---|---|
committer | Pieter Wuille <sipa@ulyssis.org> | 2011-12-17 21:49:48 +0100 |
commit | 30ab2c9c46ce38197017ce6a6e13869617e692c7 (patch) | |
tree | f87488e5baa4b81a94ebac62f3a7ee6da612b166 | |
parent | 15a8590ecf6610387502be14d26657cb154d6201 (diff) |
Preparations for key import/export
-rw-r--r-- | src/bitcoinrpc.cpp | 1 | ||||
-rw-r--r-- | src/main.cpp | 4 | ||||
-rw-r--r-- | src/main.h | 10 | ||||
-rw-r--r-- | src/wallet.cpp | 46 | ||||
-rw-r--r-- | src/wallet.h | 5 |
5 files changed, 60 insertions, 6 deletions
diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 17189040b2..fcf2482ee0 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -12,6 +12,7 @@ #include <boost/iostreams/concepts.hpp> #include <boost/iostreams/stream.hpp> #include <boost/algorithm/string.hpp> +#include <boost/lexical_cast.hpp> #ifdef USE_SSL #include <boost/asio/ssl.hpp> #include <boost/filesystem.hpp> diff --git a/src/main.cpp b/src/main.cpp index a7871fcc16..3a4e86512c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -516,7 +516,7 @@ bool CTransaction::RemoveFromMemoryPool() -int CMerkleTx::GetDepthInMainChain(int& nHeightRet) const +int CMerkleTx::GetDepthInMainChain(CBlockIndex* &pindexRet) const { if (hashBlock == 0 || nIndex == -1) return 0; @@ -537,7 +537,7 @@ int CMerkleTx::GetDepthInMainChain(int& nHeightRet) const fMerkleVerified = true; } - nHeightRet = pindex->nHeight; + pindexRet = pindex; return pindexBest->nHeight - pindex->nHeight + 1; } diff --git a/src/main.h b/src/main.h index 3870cee864..93528cdb2b 100644 --- a/src/main.h +++ b/src/main.h @@ -695,8 +695,8 @@ public: int SetMerkleBranch(const CBlock* pblock=NULL); - int GetDepthInMainChain(int& nHeightRet) const; - int GetDepthInMainChain() const { int nHeight; return GetDepthInMainChain(nHeight); } + int GetDepthInMainChain(CBlockIndex* &pindexRet) const; + int GetDepthInMainChain() const { CBlockIndex *pindexRet; return GetDepthInMainChain(pindexRet); } bool IsInMainChain() const { return GetDepthInMainChain() > 0; } int GetBlocksToMaturity() const; bool AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs=true); @@ -758,6 +758,7 @@ public: return !(a == b); } int GetDepthInMainChain() const; + }; @@ -1263,6 +1264,11 @@ public: Set((*mi).second); } + CBlockLocator(const std::vector<uint256>& vHaveIn) + { + vHave = vHaveIn; + } + IMPLEMENT_SERIALIZE ( if (!(nType & SER_GETHASH)) diff --git a/src/wallet.cpp b/src/wallet.cpp index c451186d96..f9157e01d5 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -299,7 +299,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn) // Add a transaction to the wallet, or update it. // pblock is optional, but should be provided if the transaction is known to be in a block. // If fUpdate is true, existing transactions will be updated. -bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate) +bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate, bool fFindBlock) { uint256 hash = tx.GetHash(); CRITICAL_BLOCK(cs_wallet) @@ -586,6 +586,15 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate) return ret; } +int CWallet::ScanForWalletTransaction(const uint256& hashTx) +{ + CTransaction tx; + tx.ReadFromDisk(COutPoint(hashTx, 0)); + if (AddToWalletIfInvolvingMe(tx, NULL, true, true)) + return 1; + return 0; +} + void CWallet::ReacceptWalletTransactions() { CTxDB txdb("r"); @@ -1325,6 +1334,22 @@ void CWallet::ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool) } } +int64 CWallet::AddReserveKey(const CKeyPool& keypool) +{ + CRITICAL_BLOCK(cs_main) + CRITICAL_BLOCK(cs_wallet) + { + CWalletDB walletdb(strWalletFile); + + int64 nIndex = 1 + *(--setKeyPool.end()); + if (!walletdb.WritePool(nIndex, keypool)) + throw runtime_error("AddReserveKey() : writing added key failed"); + setKeyPool.insert(nIndex); + return nIndex; + } + return -1; +} + void CWallet::KeepKey(int64 nIndex) { // Remove from key pool @@ -1413,3 +1438,22 @@ void CReserveKey::ReturnKey() vchPubKey.clear(); } +void CWallet::GetAllReserveAddresses(set<CBitcoinAddress>& setAddress) +{ + setAddress.clear(); + + CWalletDB walletdb(strWalletFile); + + CRITICAL_BLOCK(cs_main) + BOOST_FOREACH(const int64& id, setKeyPool) + { + CKeyPool keypool; + if (!walletdb.ReadPool(id, keypool)) + throw runtime_error("GetAllReserveKeyHashes() : read failed"); + CBitcoinAddress address(keypool.vchPubKey); + assert(!keypool.vchPubKey.empty()); + if (!HaveKey(address)) + throw runtime_error("GetAllReserveKeyHashes() : unknown key in key pool"); + setAddress.insert(address); + } +} diff --git a/src/wallet.h b/src/wallet.h index e1c39a6f39..95537be63e 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -75,10 +75,11 @@ public: bool EncryptWallet(const SecureString& strWalletPassphrase); bool AddToWallet(const CWalletTx& wtxIn); - bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate = false); + bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate = false, bool fFindBlock = false); bool EraseFromWallet(uint256 hash); void WalletUpdateSpent(const CTransaction& prevout); int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false); + int ScanForWalletTransaction(const uint256& hashTx); void ReacceptWalletTransactions(); void ResendWalletTransactions(); int64 GetBalance() const; @@ -92,11 +93,13 @@ public: bool NewKeyPool(); bool TopUpKeyPool(); + int64 AddReserveKey(const CKeyPool& keypool); void ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool); void KeepKey(int64 nIndex); void ReturnKey(int64 nIndex); bool GetKeyFromPool(std::vector<unsigned char> &key, bool fAllowReuse=true); int64 GetOldestKeyPoolTime(); + void GetAllReserveAddresses(std::set<CBitcoinAddress>& setAddress); bool IsMine(const CTxIn& txin) const; int64 GetDebit(const CTxIn& txin) const; |