diff options
author | Andrew Chow <achow101-github@achow101.com> | 2019-06-18 15:19:13 -0400 |
---|---|---|
committer | Andrew Chow <achow101-github@achow101.com> | 2019-07-09 16:43:10 -0400 |
commit | 172213be5b174243dc501c1103ad5fe2fee67a16 (patch) | |
tree | 2f890eb657ffa7b95ff6fb7e04b58a58c4ba081f /src/wallet/wallet.cpp | |
parent | 0853d8d2fd3cd19c3aea495f228222c7a8536e08 (diff) | |
download | bitcoin-172213be5b174243dc501c1103ad5fe2fee67a16.tar.xz |
Add GetNewDestination to CWallet to fetch new destinations
Instead of having the same multiple lines of code everywhere
that new destinations are fetched, introduce GetNewDestination as
a member function of CWallet which does the key fetching, label
setting, script generation, and destination generation.
Diffstat (limited to 'src/wallet/wallet.cpp')
-rw-r--r-- | src/wallet/wallet.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index bde52d7791..7a7ff2b6cb 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3513,6 +3513,27 @@ bool CWallet::GetKeyFromPool(CPubKey& result, bool internal) return true; } +bool CWallet::GetNewDestination(const OutputType type, const std::string label, CTxDestination& dest, std::string& error) +{ + LOCK(cs_wallet); + error.clear(); + if (!IsLocked()) { + TopUpKeyPool(); + } + + // Generate a new key that is added to wallet + CPubKey new_key; + if (!GetKeyFromPool(new_key)) { + error = "Error: Keypool ran out, please call keypoolrefill first"; + return false; + } + LearnRelatedScripts(new_key, type); + dest = GetDestinationForKey(new_key, type); + + SetAddressBook(dest, label, "receive"); + return true; +} + static int64_t GetOldestKeyTimeInPool(const std::set<int64_t>& setKeyPool, WalletBatch& batch) { if (setKeyPool.empty()) { return GetTime(); |