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/rpcwallet.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/rpcwallet.cpp')
-rw-r--r-- | src/wallet/rpcwallet.cpp | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index f9baabeda4..1801493f54 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -185,19 +185,11 @@ static UniValue getnewaddress(const JSONRPCRequest& request) } } - if (!pwallet->IsLocked()) { - pwallet->TopUpKeyPool(); - } - - // Generate a new key that is added to wallet - CPubKey newKey; - if (!pwallet->GetKeyFromPool(newKey)) { - throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first"); + CTxDestination dest; + std::string error; + if (!pwallet->GetNewDestination(output_type, label, dest, error)) { + throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, error); } - pwallet->LearnRelatedScripts(newKey, output_type); - CTxDestination dest = GetDestinationForKey(newKey, output_type); - - pwallet->SetAddressBook(dest, label, "receive"); return EncodeDestination(dest); } |