@@ -228,16 +228,35 @@ class CKeyPool
228
228
}
229
229
};
230
230
231
- /* * A key allocated from the key pool. */
231
+ /* * A wrapper to reserve a key from a wallet keypool
232
+ *
233
+ * CReserveKey is used to reserve a key from the keypool. It is passed around
234
+ * during the CreateTransaction/CommitTransaction procedure.
235
+ *
236
+ * Instantiating a CReserveKey does not reserve a keypool key. To do so,
237
+ * GetReservedKey() needs to be called on the object. Once a key has been
238
+ * reserved, call KeepKey() on the CReserveKey object to make sure it is not
239
+ * returned to the keypool. Call ReturnKey() to return the key to the keypool
240
+ * so it can be re-used (for example, if the key was used in a new transaction
241
+ * and that transaction was not completed and needed to be aborted).
242
+ *
243
+ * If a key is reserved and KeepKey() is not called, then the key will be
244
+ * returned to the keypool when the CReserveObject goes out of scope.
245
+ */
232
246
class CReserveKey
233
247
{
234
248
protected:
249
+ // ! The wallet to reserve the keypool key from
235
250
CWallet* pwallet;
251
+ // ! The index of the key in the keypool
236
252
int64_t nIndex{-1 };
253
+ // ! The public key
237
254
CPubKey vchPubKey;
255
+ // ! Whether this is from the internal (change output) keypool
238
256
bool fInternal {false };
239
257
240
258
public:
259
+ // ! Construct a CReserveKey object. This does NOT reserve a key from the keypool yet
241
260
explicit CReserveKey (CWallet* pwalletIn)
242
261
{
243
262
pwallet = pwalletIn;
@@ -246,13 +265,17 @@ class CReserveKey
246
265
CReserveKey (const CReserveKey&) = delete ;
247
266
CReserveKey& operator =(const CReserveKey&) = delete ;
248
267
268
+ // ! Destructor. If a key has been reserved and not KeepKey'ed, it will be returned to the keypool
249
269
~CReserveKey ()
250
270
{
251
271
ReturnKey ();
252
272
}
253
273
254
- void ReturnKey ();
274
+ // ! Reserve a key from the keypool
255
275
bool GetReservedKey (CPubKey &pubkey, bool internal = false );
276
+ // ! Return a key to the keypool
277
+ void ReturnKey ();
278
+ // ! Keep the key. Do not return it to the keypool when this object goes out of scope
256
279
void KeepKey ();
257
280
};
258
281
0 commit comments