From 172213be5b174243dc501c1103ad5fe2fee67a16 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Tue, 18 Jun 2019 15:19:13 -0400 Subject: 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. --- src/interfaces/wallet.cpp | 6 ++++-- src/interfaces/wallet.h | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'src/interfaces') diff --git a/src/interfaces/wallet.cpp b/src/interfaces/wallet.cpp index 240670cbe7..93374ea825 100644 --- a/src/interfaces/wallet.cpp +++ b/src/interfaces/wallet.cpp @@ -140,9 +140,11 @@ public: void abortRescan() override { m_wallet->AbortRescan(); } bool backupWallet(const std::string& filename) override { return m_wallet->BackupWallet(filename); } std::string getWalletName() override { return m_wallet->GetName(); } - bool getKeyFromPool(bool internal, CPubKey& pub_key) override + bool getNewDestination(const OutputType type, const std::string label, CTxDestination& dest) override { - return m_wallet->GetKeyFromPool(pub_key, internal); + LOCK(m_wallet->cs_wallet); + std::string error; + return m_wallet->GetNewDestination(type, label, dest, error); } bool getPubKey(const CKeyID& address, CPubKey& pub_key) override { return m_wallet->GetPubKey(address, pub_key); } bool getPrivKey(const CKeyID& address, CKey& key) override { return m_wallet->GetKey(address, key); } diff --git a/src/interfaces/wallet.h b/src/interfaces/wallet.h index 7096f54047..25815d8532 100644 --- a/src/interfaces/wallet.h +++ b/src/interfaces/wallet.h @@ -76,8 +76,8 @@ public: //! Get wallet name. virtual std::string getWalletName() = 0; - // Get key from pool. - virtual bool getKeyFromPool(bool internal, CPubKey& pub_key) = 0; + // Get a new address. + virtual bool getNewDestination(const OutputType type, const std::string label, CTxDestination& dest) = 0; //! Get public key. virtual bool getPubKey(const CKeyID& address, CPubKey& pub_key) = 0; -- cgit v1.2.3 From 33d13edd2bda0af90660e275ea4fa96ca9896f2a Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Tue, 18 Jun 2019 15:48:20 -0400 Subject: Replace CReserveKey with ReserveDestinatoin Instead of reserving keys, reserve destinations which are backed by keys --- src/interfaces/wallet.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/interfaces') diff --git a/src/interfaces/wallet.cpp b/src/interfaces/wallet.cpp index 93374ea825..4a97ee0c21 100644 --- a/src/interfaces/wallet.cpp +++ b/src/interfaces/wallet.cpp @@ -36,7 +36,7 @@ namespace { class PendingWalletTxImpl : public PendingWalletTx { public: - explicit PendingWalletTxImpl(CWallet& wallet) : m_wallet(wallet), m_key(&wallet) {} + explicit PendingWalletTxImpl(CWallet& wallet) : m_wallet(wallet), m_dest(&wallet) {} const CTransaction& get() override { return *m_tx; } @@ -47,7 +47,7 @@ public: auto locked_chain = m_wallet.chain().lock(); LOCK(m_wallet.cs_wallet); CValidationState state; - if (!m_wallet.CommitTransaction(m_tx, std::move(value_map), std::move(order_form), m_key, state)) { + if (!m_wallet.CommitTransaction(m_tx, std::move(value_map), std::move(order_form), m_dest, state)) { reject_reason = state.GetRejectReason(); return false; } @@ -56,7 +56,7 @@ public: CTransactionRef m_tx; CWallet& m_wallet; - CReserveKey m_key; + ReserveDestination m_dest; }; //! Construct wallet tx struct. @@ -238,7 +238,7 @@ public: auto locked_chain = m_wallet->chain().lock(); LOCK(m_wallet->cs_wallet); auto pending = MakeUnique(*m_wallet); - if (!m_wallet->CreateTransaction(*locked_chain, recipients, pending->m_tx, pending->m_key, fee, change_pos, + if (!m_wallet->CreateTransaction(*locked_chain, recipients, pending->m_tx, pending->m_dest, fee, change_pos, fail_reason, coin_control, sign)) { return {}; } -- cgit v1.2.3