mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-06 03:02:37 +02:00
refactor: Move wallet methods out of chain.h and node.h
Add WalletClient interface so node interface is cleaner and don't need wallet-specific methods. The new NodeContext::wallet_client pointer will also be needed to eliminate global wallet variables like ::vpwallets, because createWallet(), loadWallet(), getWallets(), etc methods called by the GUI need a way to get a reference to the list of open wallets if it is no longer a global variable. Also tweaks splash screen registration for load wallet events to be delayed until after wallet client is created.
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#define BITCOIN_INTERFACES_WALLET_H
|
||||
|
||||
#include <amount.h> // For CAmount
|
||||
#include <interfaces/chain.h> // For ChainClient
|
||||
#include <pubkey.h> // For CKeyID and CScriptID (definitions needed in CTxDestination instantiation)
|
||||
#include <script/standard.h> // For CTxDestination
|
||||
#include <support/allocators/secure.h> // For SecureString
|
||||
@@ -28,9 +29,11 @@ class CWallet;
|
||||
enum class FeeReason;
|
||||
enum class OutputType;
|
||||
enum class TransactionError;
|
||||
enum class WalletCreationStatus;
|
||||
enum isminetype : unsigned int;
|
||||
struct CRecipient;
|
||||
struct PartiallySignedTransaction;
|
||||
struct WalletContext;
|
||||
struct bilingual_str;
|
||||
typedef uint8_t isminefilter;
|
||||
|
||||
@@ -301,6 +304,34 @@ public:
|
||||
virtual CWallet* wallet() { return nullptr; }
|
||||
};
|
||||
|
||||
//! Wallet chain client that in addition to having chain client methods for
|
||||
//! starting up, shutting down, and registering RPCs, also has additional
|
||||
//! methods (called by the GUI) to load and create wallets.
|
||||
class WalletClient : public ChainClient
|
||||
{
|
||||
public:
|
||||
//! Create new wallet.
|
||||
virtual std::unique_ptr<Wallet> createWallet(const std::string& name, const SecureString& passphrase, uint64_t wallet_creation_flags, WalletCreationStatus& status, bilingual_str& error, std::vector<bilingual_str>& warnings) = 0;
|
||||
|
||||
//! Load existing wallet.
|
||||
virtual std::unique_ptr<Wallet> loadWallet(const std::string& name, bilingual_str& error, std::vector<bilingual_str>& warnings) = 0;
|
||||
|
||||
//! Return default wallet directory.
|
||||
virtual std::string getWalletDir() = 0;
|
||||
|
||||
//! Return available wallets in wallet directory.
|
||||
virtual std::vector<std::string> listWalletDir() = 0;
|
||||
|
||||
//! Return interfaces for accessing wallets (if any).
|
||||
virtual std::vector<std::unique_ptr<Wallet>> getWallets() = 0;
|
||||
|
||||
//! Register handler for load wallet messages. This callback is triggered by
|
||||
//! createWallet and loadWallet above, and also triggered when wallets are
|
||||
//! loaded at startup or by RPC.
|
||||
using LoadWalletFn = std::function<void(std::unique_ptr<Wallet> wallet)>;
|
||||
virtual std::unique_ptr<Handler> handleLoadWallet(LoadWalletFn fn) = 0;
|
||||
};
|
||||
|
||||
//! Information about one wallet address.
|
||||
struct WalletAddress
|
||||
{
|
||||
@@ -379,6 +410,10 @@ struct WalletTxOut
|
||||
//! dummywallet.cpp and throws if the wallet component is not compiled.
|
||||
std::unique_ptr<Wallet> MakeWallet(const std::shared_ptr<CWallet>& wallet);
|
||||
|
||||
//! Return implementation of ChainClient interface for a wallet client. This
|
||||
//! function will be undefined in builds where ENABLE_WALLET is false.
|
||||
std::unique_ptr<WalletClient> MakeWalletClient(Chain& chain, ArgsManager& args, std::vector<std::string> wallet_filenames);
|
||||
|
||||
} // namespace interfaces
|
||||
|
||||
#endif // BITCOIN_INTERFACES_WALLET_H
|
||||
|
||||
Reference in New Issue
Block a user