aboutsummaryrefslogtreecommitdiff
path: root/src/wallet.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2011-07-11 21:49:45 +0200
committerPieter Wuille <sipa@ulyssis.org>2011-12-17 21:49:48 +0100
commit30ab2c9c46ce38197017ce6a6e13869617e692c7 (patch)
treef87488e5baa4b81a94ebac62f3a7ee6da612b166 /src/wallet.cpp
parent15a8590ecf6610387502be14d26657cb154d6201 (diff)
Preparations for key import/export
Diffstat (limited to 'src/wallet.cpp')
-rw-r--r--src/wallet.cpp46
1 files changed, 45 insertions, 1 deletions
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);
+ }
+}