aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/wallet.h
diff options
context:
space:
mode:
authorBen Woosley <ben.woosley@gmail.com>2018-05-16 18:56:41 -0700
committerBen Woosley <ben.woosley@gmail.com>2018-05-16 22:58:02 -0700
commit4b62bdf5136c174621509bf7866fbd89b61cc66a (patch)
tree01a82019101ea3506ca91ad50026484fe1654102 /src/wallet/wallet.h
parent4cfe17c3382ba750131cdc8703b2978132822070 (diff)
downloadbitcoin-4b62bdf5136c174621509bf7866fbd89b61cc66a.tar.xz
Wallet: Refactor ReserveKeyFromKeyPool for safety
ReserveKeyFromKeyPool's previous behaviour is to set nIndex to -1 if the keypool is empty, OR throw an exception for technical failures. Instead, we now return false if the keypool is empty, true if the operation succeeded. This is to make failure more easily detectable by calling code.
Diffstat (limited to 'src/wallet/wallet.h')
-rw-r--r--src/wallet/wallet.h17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h
index fecc2178e4..5e05ed3c84 100644
--- a/src/wallet/wallet.h
+++ b/src/wallet/wallet.h
@@ -999,7 +999,22 @@ public:
bool NewKeyPool();
size_t KeypoolCountExternalKeys() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
bool TopUpKeyPool(unsigned int kpSize = 0);
- void ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool, bool fRequestedInternal);
+
+ /**
+ * Reserves a key from the keypool and sets nIndex to its index
+ *
+ * @param[out] nIndex the index of the key in keypool
+ * @param[out] keypool the keypool the key was drawn from, which could be the
+ * the pre-split pool if present, or the internal or external pool
+ * @param fRequestedInternal true if the caller would like the key drawn
+ * from the internal keypool, false if external is preferred
+ *
+ * @return true if succeeded, false if failed due to empty keypool
+ * @throws std::runtime_error if keypool read failed, key was invalid,
+ * was not found in the wallet, or was misclassified in the internal
+ * or external keypool
+ */
+ bool ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool, bool fRequestedInternal);
void KeepKey(int64_t nIndex);
void ReturnKey(int64_t nIndex, bool fInternal, const CPubKey& pubkey);
bool GetKeyFromPool(CPubKey &key, bool internal = false);