Changeset View
Changeset View
Standalone View
Standalone View
src/interfaces/wallet.h
Show All 33 Lines | |||||
struct TxId; | struct TxId; | ||||
namespace interfaces { | namespace interfaces { | ||||
class Handler; | class Handler; | ||||
class PendingWalletTx; | class PendingWalletTx; | ||||
struct WalletAddress; | struct WalletAddress; | ||||
struct WalletBalances; | struct WalletBalances; | ||||
struct WalletTx; | |||||
struct WalletTxOut; | struct WalletTxOut; | ||||
struct WalletTxStatus; | |||||
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 94 Lines • ▼ Show 20 Lines | createTransaction(const std::vector<CRecipient> &recipients, | ||||
std::string &fail_reason) = 0; | std::string &fail_reason) = 0; | ||||
//! Return whether transaction can be abandoned. | //! Return whether transaction can be abandoned. | ||||
virtual bool transactionCanBeAbandoned(const TxId &txid) = 0; | virtual bool transactionCanBeAbandoned(const TxId &txid) = 0; | ||||
//! Abandon transaction. | //! Abandon transaction. | ||||
virtual bool abandonTransaction(const TxId &txid) = 0; | virtual bool abandonTransaction(const TxId &txid) = 0; | ||||
//! Get a transaction. | |||||
virtual CTransactionRef getTx(const TxId &txid) = 0; | |||||
//! Get transaction information. | |||||
virtual WalletTx getWalletTx(const TxId &txid) = 0; | |||||
//! Get list of all wallet transactions. | |||||
virtual std::vector<WalletTx> getWalletTxs() = 0; | |||||
//! Try to get updated status for a particular transaction, if possible | |||||
//! without blocking. | |||||
virtual bool tryGetTxStatus(const TxId &txid, WalletTxStatus &tx_status, | |||||
int &num_blocks, int64_t &adjusted_time) = 0; | |||||
//! Get transaction details. | |||||
virtual WalletTx getWalletTxDetails(const TxId &txid, | |||||
WalletTxStatus &tx_status, | |||||
WalletOrderForm &order_form, | |||||
bool &in_mempool, int &num_blocks, | |||||
int64_t &adjusted_time) = 0; | |||||
//! Get balances. | //! Get balances. | ||||
virtual WalletBalances getBalances() = 0; | virtual WalletBalances getBalances() = 0; | ||||
//! Get balances if possible without blocking. | //! Get balances if possible without blocking. | ||||
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 whether transaction input belongs to wallet. | |||||
virtual isminetype txinIsMine(const CTxIn &txin) = 0; | |||||
//! Return whether transaction output belongs to wallet. | |||||
virtual isminetype txoutIsMine(const CTxOut &txout) = 0; | |||||
//! Return debit amount if transaction input belongs to wallet. | |||||
virtual Amount getDebit(const CTxIn &txin, isminefilter filter) = 0; | |||||
//! Return credit amount if transaction input belongs to wallet. | |||||
virtual Amount getCredit(const CTxOut &txout, isminefilter filter) = 0; | |||||
//! Return AvailableCoins + LockedCoins grouped by wallet address. | //! Return AvailableCoins + LockedCoins grouped by wallet address. | ||||
//! (put change in one group with wallet address) | //! (put change in one group with wallet address) | ||||
using CoinsList = std::map<CTxDestination, | using CoinsList = std::map<CTxDestination, | ||||
std::vector<std::tuple<COutPoint, WalletTxOut>>>; | std::vector<std::tuple<COutPoint, WalletTxOut>>>; | ||||
virtual CoinsList listCoins() = 0; | virtual CoinsList listCoins() = 0; | ||||
//! Return wallet transaction output information. | //! Return wallet transaction output information. | ||||
virtual std::vector<WalletTxOut> | virtual std::vector<WalletTxOut> | ||||
▲ Show 20 Lines • Show All 75 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 information. | |||||
struct WalletTx { | |||||
CTransactionRef tx; | |||||
std::vector<isminetype> txin_is_mine; | |||||
std::vector<isminetype> txout_is_mine; | |||||
std::vector<CTxDestination> txout_address; | |||||
std::vector<isminetype> txout_address_is_mine; | |||||
Amount credit; | |||||
Amount debit; | |||||
Amount change; | |||||
int64_t time; | |||||
std::map<std::string, std::string> value_map; | |||||
bool is_coinbase; | |||||
}; | |||||
//! Updated transaction status. | |||||
struct WalletTxStatus { | |||||
int block_height; | |||||
int blocks_to_maturity; | |||||
int depth_in_main_chain; | |||||
int request_count; | |||||
unsigned int time_received; | |||||
uint32_t lock_time; | |||||
bool is_final; | |||||
bool is_trusted; | |||||
bool is_abandoned; | |||||
bool is_coinbase; | |||||
bool is_in_main_chain; | |||||
}; | |||||
//! Wallet transaction output. | //! Wallet transaction output. | ||||
struct WalletTxOut { | struct WalletTxOut { | ||||
CTxOut txout; | CTxOut txout; | ||||
int64_t time; | int64_t time; | ||||
int depth_in_main_chain = -1; | int depth_in_main_chain = -1; | ||||
bool is_spent = false; | 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 |