Changeset View
Changeset View
Standalone View
Standalone View
src/interfaces/wallet.h
// Copyright (c) 2018 The Bitcoin Core developers | // Copyright (c) 2018 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_INTERFACES_WALLET_H | #ifndef BITCOIN_INTERFACES_WALLET_H | ||||
#define BITCOIN_INTERFACES_WALLET_H | #define BITCOIN_INTERFACES_WALLET_H | ||||
#include <amount.h> // For Amount | #include <amount.h> // For Amount | ||||
#include <primitives/transaction.h> // For CTxOut | |||||
#include <script/ismine.h> // For isminefilter, isminetype | #include <script/ismine.h> // For isminefilter, isminetype | ||||
#include <script/standard.h> // For CTxDestination | #include <script/standard.h> // For CTxDestination | ||||
#include <support/allocators/secure.h> // For SecureString | #include <support/allocators/secure.h> // For SecureString | ||||
#include <ui_interface.h> // For ChangeType | #include <ui_interface.h> // For ChangeType | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <functional> | #include <functional> | ||||
#include <map> | #include <map> | ||||
#include <memory> | #include <memory> | ||||
#include <string> | #include <string> | ||||
#include <tuple> | |||||
#include <utility> | #include <utility> | ||||
#include <vector> | #include <vector> | ||||
class CChainParams; | class CChainParams; | ||||
class CCoinControl; | class CCoinControl; | ||||
class CKey; | class CKey; | ||||
class CMutableTransaction; | class CMutableTransaction; | ||||
class COutPoint; | class COutPoint; | ||||
class CTransaction; | class CTransaction; | ||||
class CWallet; | class CWallet; | ||||
enum class OutputType; | enum class OutputType; | ||||
struct CRecipient; | struct CRecipient; | ||||
struct TxId; | struct TxId; | ||||
namespace interfaces { | namespace interfaces { | ||||
class Handler; | class Handler; | ||||
class PendingWalletTx; | class PendingWalletTx; | ||||
struct WalletBalances; | struct WalletBalances; | ||||
struct WalletTxOut; | |||||
using WalletOrderForm = std::vector<std::pair<std::string, std::string>>; | using WalletOrderForm = std::vector<std::pair<std::string, std::string>>; | ||||
using WalletValueMap = std::map<std::string, std::string>; | using WalletValueMap = std::map<std::string, std::string>; | ||||
//! Interface for accessing a wallet. | //! Interface for accessing a wallet. | ||||
class Wallet { | class Wallet { | ||||
public: | public: | ||||
virtual ~Wallet() {} | virtual ~Wallet() {} | ||||
▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | public: | ||||
virtual bool tryGetBalances(WalletBalances &balances, int &num_blocks) = 0; | virtual bool tryGetBalances(WalletBalances &balances, int &num_blocks) = 0; | ||||
//! Get balance. | //! Get balance. | ||||
virtual Amount getBalance() = 0; | virtual Amount getBalance() = 0; | ||||
//! Get available balance. | //! Get available balance. | ||||
virtual Amount getAvailableBalance(const CCoinControl &coin_control) = 0; | virtual Amount getAvailableBalance(const CCoinControl &coin_control) = 0; | ||||
//! Return AvailableCoins + LockedCoins grouped by wallet address. | |||||
//! (put change in one group with wallet address) | |||||
using CoinsList = std::map<CTxDestination, | |||||
std::vector<std::tuple<COutPoint, WalletTxOut>>>; | |||||
virtual CoinsList listCoins() = 0; | |||||
//! Return wallet transaction output information. | |||||
virtual std::vector<WalletTxOut> | |||||
getCoins(const std::vector<COutPoint> &outputs) = 0; | |||||
// Return whether HD enabled. | // Return whether HD enabled. | ||||
virtual bool hdEnabled() = 0; | virtual bool hdEnabled() = 0; | ||||
//! Register handler for show progress messages. | //! Register handler for show progress messages. | ||||
using ShowProgressFn = | using ShowProgressFn = | ||||
std::function<void(const std::string &title, int progress)>; | std::function<void(const std::string &title, int progress)>; | ||||
virtual std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn) = 0; | virtual std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn) = 0; | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | bool balanceChanged(const WalletBalances &prev) const { | ||||
immature_balance != prev.immature_balance || | immature_balance != prev.immature_balance || | ||||
watch_only_balance != prev.watch_only_balance || | watch_only_balance != prev.watch_only_balance || | ||||
unconfirmed_watch_only_balance != | unconfirmed_watch_only_balance != | ||||
prev.unconfirmed_watch_only_balance || | prev.unconfirmed_watch_only_balance || | ||||
immature_watch_only_balance != prev.immature_watch_only_balance; | immature_watch_only_balance != prev.immature_watch_only_balance; | ||||
} | } | ||||
}; | }; | ||||
//! Wallet transaction output. | |||||
struct WalletTxOut { | |||||
CTxOut txout; | |||||
int64_t time; | |||||
int depth_in_main_chain = -1; | |||||
bool is_spent = false; | |||||
}; | |||||
//! Return implementation of Wallet interface. This function will be undefined | //! Return implementation of Wallet interface. This function will be undefined | ||||
//! in builds where ENABLE_WALLET is false. | //! in builds where ENABLE_WALLET is false. | ||||
std::unique_ptr<Wallet> MakeWallet(CWallet &wallet); | std::unique_ptr<Wallet> MakeWallet(CWallet &wallet); | ||||
} // namespace interfaces | } // namespace interfaces | ||||
#endif // BITCOIN_INTERFACES_WALLET_H | #endif // BITCOIN_INTERFACES_WALLET_H |