diff --git a/src/interfaces/node.h b/src/interfaces/node.h --- a/src/interfaces/node.h +++ b/src/interfaces/node.h @@ -23,6 +23,7 @@ class CFeeRate; struct CNodeStateStats; struct CNodeStats; +class Coin; class Config; class HTTPRPCRequestProcessor; class proxyType; @@ -181,6 +182,9 @@ //! Unset RPC timer interface. virtual void rpcUnsetTimerInterface(RPCTimerInterface *iface) = 0; + //! Get unspent outputs associated with a transaction. + virtual bool getUnspentOutput(const COutPoint &output, Coin &coin) = 0; + //! Return interfaces for accessing wallets (if any). virtual std::vector> getWallets() = 0; diff --git a/src/interfaces/node.cpp b/src/interfaces/node.cpp --- a/src/interfaces/node.cpp +++ b/src/interfaces/node.cpp @@ -240,6 +240,10 @@ void rpcUnsetTimerInterface(RPCTimerInterface *iface) override { RPCUnsetTimerInterface(iface); } + bool getUnspentOutput(const COutPoint &output, Coin &coin) override { + LOCK(::cs_main); + return ::pcoinsTip->GetCoin(output, coin); + } std::vector> getWallets() override { #ifdef ENABLE_WALLET std::vector> wallets; diff --git a/src/interfaces/wallet.h b/src/interfaces/wallet.h --- a/src/interfaces/wallet.h +++ b/src/interfaces/wallet.h @@ -39,7 +39,9 @@ class PendingWalletTx; struct WalletAddress; struct WalletBalances; +struct WalletTx; struct WalletTxOut; +struct WalletTxStatus; using WalletOrderForm = std::vector>; using WalletValueMap = std::map; @@ -150,6 +152,27 @@ //! Abandon transaction. 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 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. virtual WalletBalances getBalances() = 0; @@ -162,6 +185,18 @@ //! Get available balance. 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. //! (put change in one group with wallet address) using CoinsList = std::map txin_is_mine; + std::vector txout_is_mine; + std::vector txout_address; + std::vector txout_address_is_mine; + Amount credit; + Amount debit; + Amount change; + int64_t time; + std::map 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. struct WalletTxOut { CTxOut txout; diff --git a/src/interfaces/wallet.cpp b/src/interfaces/wallet.cpp --- a/src/interfaces/wallet.cpp +++ b/src/interfaces/wallet.cpp @@ -15,8 +15,10 @@ #include