diff options
Diffstat (limited to 'src/interfaces')
-rw-r--r-- | src/interfaces/chain.cpp | 23 | ||||
-rw-r--r-- | src/interfaces/chain.h | 19 | ||||
-rw-r--r-- | src/interfaces/node.cpp | 13 | ||||
-rw-r--r-- | src/interfaces/node.h | 6 | ||||
-rw-r--r-- | src/interfaces/wallet.cpp | 34 | ||||
-rw-r--r-- | src/interfaces/wallet.h | 20 |
6 files changed, 54 insertions, 61 deletions
diff --git a/src/interfaces/chain.cpp b/src/interfaces/chain.cpp index 5a3420349f..775a89f4cf 100644 --- a/src/interfaces/chain.cpp +++ b/src/interfaces/chain.cpp @@ -166,27 +166,25 @@ public: } void TransactionAddedToMempool(const CTransactionRef& tx) override { - m_notifications->TransactionAddedToMempool(tx); + m_notifications->transactionAddedToMempool(tx); } void TransactionRemovedFromMempool(const CTransactionRef& tx) override { - m_notifications->TransactionRemovedFromMempool(tx); + m_notifications->transactionRemovedFromMempool(tx); } - void BlockConnected(const std::shared_ptr<const CBlock>& block, - const CBlockIndex* index, - const std::vector<CTransactionRef>& tx_conflicted) override + void BlockConnected(const std::shared_ptr<const CBlock>& block, const CBlockIndex* index) override { - m_notifications->BlockConnected(*block, tx_conflicted, index->nHeight); + m_notifications->blockConnected(*block, index->nHeight); } void BlockDisconnected(const std::shared_ptr<const CBlock>& block, const CBlockIndex* index) override { - m_notifications->BlockDisconnected(*block, index->nHeight); + m_notifications->blockDisconnected(*block, index->nHeight); } void UpdatedBlockTip(const CBlockIndex* index, const CBlockIndex* fork_index, bool is_ibd) override { - m_notifications->UpdatedBlockTip(); + m_notifications->updatedBlockTip(); } - void ChainStateFlushed(const CBlockLocator& locator) override { m_notifications->ChainStateFlushed(locator); } + void ChainStateFlushed(const CBlockLocator& locator) override { m_notifications->chainStateFlushed(locator); } Chain& m_chain; Chain::Notifications* m_notifications; }; @@ -279,7 +277,10 @@ public: auto it = ::mempool.GetIter(txid); return it && (*it)->GetCountWithDescendants() > 1; } - bool broadcastTransaction(const CTransactionRef& tx, std::string& err_string, const CAmount& max_tx_fee, bool relay) override + bool broadcastTransaction(const CTransactionRef& tx, + const CAmount& max_tx_fee, + bool relay, + std::string& err_string) override { const TransactionError err = BroadcastTransaction(m_node, tx, err_string, max_tx_fee, relay, /*wait_callback*/ false); // Chain clients only care about failures to accept the tx to the mempool. Disregard non-mempool related failures. @@ -367,7 +368,7 @@ public: { LOCK2(::cs_main, ::mempool.cs); for (const CTxMemPoolEntry& entry : ::mempool.mapTx) { - notifications.TransactionAddedToMempool(entry.GetSharedTx()); + notifications.transactionAddedToMempool(entry.GetSharedTx()); } } NodeContext& m_node; diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h index 7304f82749..caefa87e11 100644 --- a/src/interfaces/chain.h +++ b/src/interfaces/chain.h @@ -154,7 +154,10 @@ public: //! Transaction is added to memory pool, if the transaction fee is below the //! amount specified by max_tx_fee, and broadcast to all peers if relay is set to true. //! Return false if the transaction could not be added due to the fee or for another reason. - virtual bool broadcastTransaction(const CTransactionRef& tx, std::string& err_string, const CAmount& max_tx_fee, bool relay) = 0; + virtual bool broadcastTransaction(const CTransactionRef& tx, + const CAmount& max_tx_fee, + bool relay, + std::string& err_string) = 0; //! Calculate mempool ancestor and descendant counts for the given transaction. virtual void getTransactionAncestry(const uint256& txid, size_t& ancestors, size_t& descendants) = 0; @@ -217,12 +220,12 @@ public: { public: virtual ~Notifications() {} - virtual void TransactionAddedToMempool(const CTransactionRef& tx) {} - virtual void TransactionRemovedFromMempool(const CTransactionRef& ptx) {} - virtual void BlockConnected(const CBlock& block, const std::vector<CTransactionRef>& tx_conflicted, int height) {} - virtual void BlockDisconnected(const CBlock& block, int height) {} - virtual void UpdatedBlockTip() {} - virtual void ChainStateFlushed(const CBlockLocator& locator) {} + virtual void transactionAddedToMempool(const CTransactionRef& tx) {} + virtual void transactionRemovedFromMempool(const CTransactionRef& ptx) {} + virtual void blockConnected(const CBlock& block, int height) {} + virtual void blockDisconnected(const CBlock& block, int height) {} + virtual void updatedBlockTip() {} + virtual void chainStateFlushed(const CBlockLocator& locator) {} }; //! Register handler for notifications. @@ -245,7 +248,7 @@ public: //! Current RPC serialization flags. virtual int rpcSerializationFlags() = 0; - //! Synchronously send TransactionAddedToMempool notifications about all + //! Synchronously send transactionAddedToMempool notifications about all //! current mempool transactions to the specified handler and return after //! the last one is sent. These notifications aren't coordinated with async //! notifications sent by handleNotifications, so out of date async diff --git a/src/interfaces/node.cpp b/src/interfaces/node.cpp index 8a64a9d26a..905173d20b 100644 --- a/src/interfaces/node.cpp +++ b/src/interfaces/node.cpp @@ -37,6 +37,8 @@ #include <univalue.h> +#include <boost/signals2/signal.hpp> + class CWallet; fs::path GetWalletDir(); std::vector<fs::path> ListWalletDir(); @@ -150,14 +152,14 @@ public: } return false; } - bool disconnect(const CNetAddr& net_addr) override + bool disconnectByAddress(const CNetAddr& net_addr) override { if (m_context.connman) { return m_context.connman->DisconnectNode(net_addr); } return false; } - bool disconnect(NodeId id) override + bool disconnectById(NodeId id) override { if (m_context.connman) { return m_context.connman->DisconnectNode(id); @@ -260,12 +262,11 @@ public: { return MakeWallet(LoadWallet(*m_context.chain, name, error, warnings)); } - WalletCreationStatus createWallet(const SecureString& passphrase, uint64_t wallet_creation_flags, const std::string& name, std::string& error, std::vector<std::string>& warnings, std::unique_ptr<Wallet>& result) override + std::unique_ptr<Wallet> createWallet(const SecureString& passphrase, uint64_t wallet_creation_flags, const std::string& name, std::string& error, std::vector<std::string>& warnings, WalletCreationStatus& status) override { std::shared_ptr<CWallet> wallet; - WalletCreationStatus status = CreateWallet(*m_context.chain, passphrase, wallet_creation_flags, name, error, warnings, wallet); - result = MakeWallet(wallet); - return status; + status = CreateWallet(*m_context.chain, passphrase, wallet_creation_flags, name, error, warnings, wallet); + return MakeWallet(wallet); } std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) override { diff --git a/src/interfaces/node.h b/src/interfaces/node.h index 38aeb06324..53a20886cd 100644 --- a/src/interfaces/node.h +++ b/src/interfaces/node.h @@ -124,10 +124,10 @@ public: virtual bool unban(const CSubNet& ip) = 0; //! Disconnect node by address. - virtual bool disconnect(const CNetAddr& net_addr) = 0; + virtual bool disconnectByAddress(const CNetAddr& net_addr) = 0; //! Disconnect node by id. - virtual bool disconnect(NodeId id) = 0; + virtual bool disconnectById(NodeId id) = 0; //! Get total bytes recv. virtual int64_t getTotalBytesRecv() = 0; @@ -204,7 +204,7 @@ public: virtual std::unique_ptr<Wallet> loadWallet(const std::string& name, std::string& error, std::vector<std::string>& warnings) = 0; //! Create a wallet from file - virtual WalletCreationStatus createWallet(const SecureString& passphrase, uint64_t wallet_creation_flags, const std::string& name, std::string& error, std::vector<std::string>& warnings, std::unique_ptr<Wallet>& result) = 0; + virtual std::unique_ptr<Wallet> createWallet(const SecureString& passphrase, uint64_t wallet_creation_flags, const std::string& name, std::string& error, std::vector<std::string>& warnings, WalletCreationStatus& status) = 0; //! Register handler for init messages. using InitMessageFn = std::function<void(const std::string& message)>; diff --git a/src/interfaces/wallet.cpp b/src/interfaces/wallet.cpp index baea71d0bb..bb6bb4923f 100644 --- a/src/interfaces/wallet.cpp +++ b/src/interfaces/wallet.cpp @@ -19,7 +19,6 @@ #include <wallet/fees.h> #include <wallet/ismine.h> #include <wallet/load.h> -#include <wallet/psbtwallet.h> #include <wallet/rpcwallet.h> #include <wallet/wallet.h> @@ -119,19 +118,15 @@ public: } bool getPubKey(const CScript& script, const CKeyID& address, CPubKey& pub_key) override { - std::unique_ptr<SigningProvider> provider = m_wallet->GetSigningProvider(script); + std::unique_ptr<SigningProvider> provider = m_wallet->GetSolvingProvider(script); if (provider) { return provider->GetPubKey(address, pub_key); } return false; } - bool getPrivKey(const CScript& script, const CKeyID& address, CKey& key) override + SigningResult signMessage(const std::string& message, const PKHash& pkhash, std::string& str_sig) override { - std::unique_ptr<SigningProvider> provider = m_wallet->GetSigningProvider(script); - if (provider) { - return provider->GetKey(address, key); - } - return false; + return m_wallet->SignMessage(message, pkhash, str_sig); } bool isSpendable(const CTxDestination& dest) override { return m_wallet->IsMine(dest) & ISMINE_SPENDABLE; } bool haveWatchOnly() override @@ -258,19 +253,12 @@ public: } bool createBumpTransaction(const uint256& txid, const CCoinControl& coin_control, - CAmount total_fee, std::vector<std::string>& errors, CAmount& old_fee, CAmount& new_fee, CMutableTransaction& mtx) override { - if (total_fee > 0) { - return feebumper::CreateTotalBumpTransaction(m_wallet.get(), txid, coin_control, total_fee, errors, old_fee, new_fee, mtx) == - feebumper::Result::OK; - } else { - return feebumper::CreateRateBumpTransaction(*m_wallet.get(), txid, coin_control, errors, old_fee, new_fee, mtx) == - feebumper::Result::OK; - } + return feebumper::CreateRateBumpTransaction(*m_wallet.get(), txid, coin_control, errors, old_fee, new_fee, mtx) == feebumper::Result::OK; } bool signBumpTransaction(CMutableTransaction& mtx) override { return feebumper::SignTransaction(*m_wallet.get(), mtx); } bool commitBumpTransaction(const uint256& txid, @@ -357,13 +345,13 @@ public: } return {}; } - TransactionError fillPSBT(PartiallySignedTransaction& psbtx, - bool& complete, - int sighash_type = 1 /* SIGHASH_ALL */, - bool sign = true, - bool bip32derivs = false) override + TransactionError fillPSBT(int sighash_type, + bool sign, + bool bip32derivs, + PartiallySignedTransaction& psbtx, + bool& complete) override { - return FillPSBT(m_wallet.get(), psbtx, complete, sighash_type, sign, bip32derivs); + return m_wallet->FillPSBT(psbtx, complete, sighash_type, sign, bip32derivs); } WalletBalances getBalances() override { @@ -469,7 +457,7 @@ public: unsigned int getConfirmTarget() override { return m_wallet->m_confirm_target; } bool hdEnabled() override { return m_wallet->IsHDEnabled(); } bool canGetAddresses() override { return m_wallet->CanGetAddresses(); } - bool IsWalletFlagSet(uint64_t flag) override { return m_wallet->IsWalletFlagSet(flag); } + bool privateKeysDisabled() override { return m_wallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS); } OutputType getDefaultAddressType() override { return m_wallet->m_default_address_type; } OutputType getDefaultChangeType() override { return m_wallet->m_default_change_type; } CAmount getDefaultMaxTxFee() override { return m_wallet->m_default_max_tx_fee; } diff --git a/src/interfaces/wallet.h b/src/interfaces/wallet.h index d4280e8091..0e551b0a96 100644 --- a/src/interfaces/wallet.h +++ b/src/interfaces/wallet.h @@ -10,6 +10,7 @@ #include <script/standard.h> // For CTxDestination #include <support/allocators/secure.h> // For SecureString #include <ui_interface.h> // For ChangeType +#include <util/message.h> #include <functional> #include <map> @@ -84,8 +85,8 @@ public: //! Get public key. virtual bool getPubKey(const CScript& script, const CKeyID& address, CPubKey& pub_key) = 0; - //! Get private key. - virtual bool getPrivKey(const CScript& script, const CKeyID& address, CKey& key) = 0; + //! Sign message + virtual SigningResult signMessage(const std::string& message, const PKHash& pkhash, std::string& str_sig) = 0; //! Return whether wallet has private key. virtual bool isSpendable(const CTxDestination& dest) = 0; @@ -154,7 +155,6 @@ public: //! Create bump transaction. virtual bool createBumpTransaction(const uint256& txid, const CCoinControl& coin_control, - CAmount total_fee, std::vector<std::string>& errors, CAmount& old_fee, CAmount& new_fee, @@ -192,11 +192,11 @@ public: int& num_blocks) = 0; //! Fill PSBT. - virtual TransactionError fillPSBT(PartiallySignedTransaction& psbtx, - bool& complete, - int sighash_type = 1 /* SIGHASH_ALL */, - bool sign = true, - bool bip32derivs = false) = 0; + virtual TransactionError fillPSBT(int sighash_type, + bool sign, + bool bip32derivs, + PartiallySignedTransaction& psbtx, + bool& complete) = 0; //! Get balances. virtual WalletBalances getBalances() = 0; @@ -248,8 +248,8 @@ public: // Return whether the wallet is blank. virtual bool canGetAddresses() = 0; - // check if a certain wallet flag is set. - virtual bool IsWalletFlagSet(uint64_t flag) = 0; + // Return whether private keys enabled. + virtual bool privateKeysDisabled() = 0; // Get default address type. virtual OutputType getDefaultAddressType() = 0; |