aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorJohn Newbery <john@johnnewbery.com>2019-04-09 14:36:57 -0400
committerJohn Newbery <john@johnnewbery.com>2019-05-01 14:53:36 -0400
commitf1a77b0c5176306ca9f6f30211e32d3502ed4281 (patch)
treefc00587c07136db97aadf344e64beebba8e4a841 /src/wallet
parent37796b2dd49772b17ff39a1a71b73f6d2248ac6d (diff)
downloadbitcoin-f1a77b0c5176306ca9f6f30211e32d3502ed4281.tar.xz
[docs] Add doxygen comment for CReserveKey
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/wallet.h27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h
index 435f2b2a2c..7c9c7486c7 100644
--- a/src/wallet/wallet.h
+++ b/src/wallet/wallet.h
@@ -228,16 +228,35 @@ public:
}
};
-/** A key allocated from the key pool. */
+/** A wrapper to reserve a key from a wallet keypool
+ *
+ * CReserveKey is used to reserve a key from the keypool. It is passed around
+ * during the CreateTransaction/CommitTransaction procedure.
+ *
+ * Instantiating a CReserveKey does not reserve a keypool key. To do so,
+ * GetReservedKey() needs to be called on the object. Once a key has been
+ * reserved, call KeepKey() on the CReserveKey object to make sure it is not
+ * returned to the keypool. Call ReturnKey() to return the key to the keypool
+ * so it can be re-used (for example, if the key was used in a new transaction
+ * and that transaction was not completed and needed to be aborted).
+ *
+ * If a key is reserved and KeepKey() is not called, then the key will be
+ * returned to the keypool when the CReserveObject goes out of scope.
+ */
class CReserveKey
{
protected:
+ //! The wallet to reserve the keypool key from
CWallet* pwallet;
+ //! The index of the key in the keypool
int64_t nIndex{-1};
+ //! The public key
CPubKey vchPubKey;
+ //! Whether this is from the internal (change output) keypool
bool fInternal{false};
public:
+ //! Construct a CReserveKey object. This does NOT reserve a key from the keypool yet
explicit CReserveKey(CWallet* pwalletIn)
{
pwallet = pwalletIn;
@@ -246,13 +265,17 @@ public:
CReserveKey(const CReserveKey&) = delete;
CReserveKey& operator=(const CReserveKey&) = delete;
+ //! Destructor. If a key has been reserved and not KeepKey'ed, it will be returned to the keypool
~CReserveKey()
{
ReturnKey();
}
- void ReturnKey();
+ //! Reserve a key from the keypool
bool GetReservedKey(CPubKey &pubkey, bool internal = false);
+ //! Return a key to the keypool
+ void ReturnKey();
+ //! Keep the key. Do not return it to the keypool when this object goes out of scope
void KeepKey();
};