aboutsummaryrefslogtreecommitdiff
path: root/src/interface
diff options
context:
space:
mode:
authorRussell Yanofsky <russ@yanofsky.org>2017-04-18 16:42:30 -0400
committerJohn Newbery <john@johnnewbery.com>2018-04-04 16:52:40 -0400
commit58845587e11140e81f087a74c3db76a4d1fc3a1a (patch)
tree9a150957bd523137b38de0909e8ae1ab5e7b9984 /src/interface
parent3cab2ce5f9e159ad5a2e9ed682f28121b5248580 (diff)
downloadbitcoin-58845587e11140e81f087a74c3db76a4d1fc3a1a.tar.xz
Remove direct bitcoin calls from qt transaction table files
Diffstat (limited to 'src/interface')
-rw-r--r--src/interface/node.cpp6
-rw-r--r--src/interface/node.h7
-rw-r--r--src/interface/wallet.cpp138
-rw-r--r--src/interface/wallet.h69
4 files changed, 220 insertions, 0 deletions
diff --git a/src/interface/node.cpp b/src/interface/node.cpp
index 0e6bc4a785..a8ed275dc5 100644
--- a/src/interface/node.cpp
+++ b/src/interface/node.cpp
@@ -60,6 +60,7 @@ class NodeImpl : public Node
void initLogging() override { InitLogging(); }
void initParameterInteraction() override { InitParameterInteraction(); }
std::string getWarnings(const std::string& type) override { return GetWarnings(type); }
+ uint32_t getLogCategories() override { return ::logCategories; }
bool baseInitialize() override
{
return AppInitBasicSetup() && AppInitParameterInteraction() && AppInitSanityChecks() &&
@@ -227,6 +228,11 @@ class NodeImpl : public Node
std::vector<std::string> listRpcCommands() override { return ::tableRPC.listCommands(); }
void rpcSetTimerInterfaceIfUnset(RPCTimerInterface* iface) override { RPCSetTimerInterfaceIfUnset(iface); }
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<std::unique_ptr<Wallet>> getWallets() override
{
#ifdef ENABLE_WALLET
diff --git a/src/interface/node.h b/src/interface/node.h
index a31105f6f8..c73f45a1b0 100644
--- a/src/interface/node.h
+++ b/src/interface/node.h
@@ -22,6 +22,7 @@
class CCoinControl;
class CFeeRate;
class CNodeStats;
+class Coin;
class RPCTimerInterface;
class UniValue;
class proxyType;
@@ -66,6 +67,9 @@ public:
//! Get warnings.
virtual std::string getWarnings(const std::string& type) = 0;
+ // Get log flags.
+ virtual uint32_t getLogCategories() = 0;
+
//! Initialize app dependencies.
virtual bool baseInitialize() = 0;
@@ -184,6 +188,9 @@ public:
//! 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<std::unique_ptr<Wallet>> getWallets() = 0;
diff --git a/src/interface/wallet.cpp b/src/interface/wallet.cpp
index efc9946fb6..a6bce7d3de 100644
--- a/src/interface/wallet.cpp
+++ b/src/interface/wallet.cpp
@@ -15,6 +15,7 @@
#include <script/standard.h>
#include <support/allocators/secure.h>
#include <sync.h>
+#include <timedata.h>
#include <ui_interface.h>
#include <uint256.h>
#include <validation.h>
@@ -54,6 +55,54 @@ public:
CReserveKey m_key;
};
+//! Construct wallet tx struct.
+WalletTx MakeWalletTx(CWallet& wallet, const CWalletTx& wtx)
+{
+ WalletTx result;
+ result.tx = wtx.tx;
+ result.txin_is_mine.reserve(wtx.tx->vin.size());
+ for (const auto& txin : wtx.tx->vin) {
+ result.txin_is_mine.emplace_back(wallet.IsMine(txin));
+ }
+ result.txout_is_mine.reserve(wtx.tx->vout.size());
+ result.txout_address.reserve(wtx.tx->vout.size());
+ result.txout_address_is_mine.reserve(wtx.tx->vout.size());
+ for (const auto& txout : wtx.tx->vout) {
+ result.txout_is_mine.emplace_back(wallet.IsMine(txout));
+ result.txout_address.emplace_back();
+ result.txout_address_is_mine.emplace_back(ExtractDestination(txout.scriptPubKey, result.txout_address.back()) ?
+ IsMine(wallet, result.txout_address.back()) :
+ ISMINE_NO);
+ }
+ result.credit = wtx.GetCredit(ISMINE_ALL);
+ result.debit = wtx.GetDebit(ISMINE_ALL);
+ result.change = wtx.GetChange();
+ result.time = wtx.GetTxTime();
+ result.value_map = wtx.mapValue;
+ result.is_coinbase = wtx.IsCoinBase();
+ return result;
+}
+
+//! Construct wallet tx status struct.
+WalletTxStatus MakeWalletTxStatus(const CWalletTx& wtx)
+{
+ WalletTxStatus result;
+ auto mi = ::mapBlockIndex.find(wtx.hashBlock);
+ CBlockIndex* block = mi != ::mapBlockIndex.end() ? mi->second : nullptr;
+ result.block_height = (block ? block->nHeight : std::numeric_limits<int>::max()),
+ result.blocks_to_maturity = wtx.GetBlocksToMaturity();
+ result.depth_in_main_chain = wtx.GetDepthInMainChain();
+ result.request_count = wtx.GetRequestCount();
+ result.time_received = wtx.nTimeReceived;
+ result.lock_time = wtx.tx->nLockTime;
+ result.is_final = CheckFinalTx(*wtx.tx);
+ result.is_trusted = wtx.IsTrusted();
+ result.is_abandoned = wtx.isAbandoned();
+ result.is_coinbase = wtx.IsCoinBase();
+ result.is_in_main_chain = wtx.IsInMainChain();
+ return result;
+}
+
//! Construct wallet TxOut struct.
WalletTxOut MakeWalletTxOut(CWallet& wallet, const CWalletTx& wtx, int n, int depth)
{
@@ -205,6 +254,75 @@ public:
return feebumper::CommitTransaction(&m_wallet, txid, std::move(mtx), errors, bumped_txid) ==
feebumper::Result::OK;
}
+ CTransactionRef getTx(const uint256& txid) override
+ {
+ LOCK2(::cs_main, m_wallet.cs_wallet);
+ auto mi = m_wallet.mapWallet.find(txid);
+ if (mi != m_wallet.mapWallet.end()) {
+ return mi->second.tx;
+ }
+ return {};
+ }
+ WalletTx getWalletTx(const uint256& txid) override
+ {
+ LOCK2(::cs_main, m_wallet.cs_wallet);
+ auto mi = m_wallet.mapWallet.find(txid);
+ if (mi != m_wallet.mapWallet.end()) {
+ return MakeWalletTx(m_wallet, mi->second);
+ }
+ return {};
+ }
+ std::vector<WalletTx> getWalletTxs() override
+ {
+ LOCK2(::cs_main, m_wallet.cs_wallet);
+ std::vector<WalletTx> result;
+ result.reserve(m_wallet.mapWallet.size());
+ for (const auto& entry : m_wallet.mapWallet) {
+ result.emplace_back(MakeWalletTx(m_wallet, entry.second));
+ }
+ return result;
+ }
+ bool tryGetTxStatus(const uint256& txid,
+ interface::WalletTxStatus& tx_status,
+ int& num_blocks,
+ int64_t& adjusted_time) override
+ {
+ TRY_LOCK(::cs_main, locked_chain);
+ if (!locked_chain) {
+ return false;
+ }
+ TRY_LOCK(m_wallet.cs_wallet, locked_wallet);
+ if (!locked_wallet) {
+ return false;
+ }
+ auto mi = m_wallet.mapWallet.find(txid);
+ if (mi == m_wallet.mapWallet.end()) {
+ return false;
+ }
+ num_blocks = ::chainActive.Height();
+ adjusted_time = GetAdjustedTime();
+ tx_status = MakeWalletTxStatus(mi->second);
+ return true;
+ }
+ WalletTx getWalletTxDetails(const uint256& txid,
+ WalletTxStatus& tx_status,
+ WalletOrderForm& order_form,
+ bool& in_mempool,
+ int& num_blocks,
+ int64_t& adjusted_time) override
+ {
+ LOCK2(::cs_main, m_wallet.cs_wallet);
+ auto mi = m_wallet.mapWallet.find(txid);
+ if (mi != m_wallet.mapWallet.end()) {
+ num_blocks = ::chainActive.Height();
+ adjusted_time = GetAdjustedTime();
+ in_mempool = mi->second.InMempool();
+ order_form = mi->second.vOrderForm;
+ tx_status = MakeWalletTxStatus(mi->second);
+ return MakeWalletTx(m_wallet, mi->second);
+ }
+ return {};
+ }
WalletBalances getBalances() override
{
WalletBalances result;
@@ -236,6 +354,26 @@ public:
{
return m_wallet.GetAvailableBalance(&coin_control);
}
+ isminetype txinIsMine(const CTxIn& txin) override
+ {
+ LOCK2(::cs_main, m_wallet.cs_wallet);
+ return m_wallet.IsMine(txin);
+ }
+ isminetype txoutIsMine(const CTxOut& txout) override
+ {
+ LOCK2(::cs_main, m_wallet.cs_wallet);
+ return m_wallet.IsMine(txout);
+ }
+ CAmount getDebit(const CTxIn& txin, isminefilter filter) override
+ {
+ LOCK2(::cs_main, m_wallet.cs_wallet);
+ return m_wallet.GetDebit(txin, filter);
+ }
+ CAmount getCredit(const CTxOut& txout, isminefilter filter) override
+ {
+ LOCK2(::cs_main, m_wallet.cs_wallet);
+ return m_wallet.GetCredit(txout, filter);
+ }
CoinsList listCoins() override
{
LOCK2(::cs_main, m_wallet.cs_wallet);
diff --git a/src/interface/wallet.h b/src/interface/wallet.h
index 4510276446..b66ed63398 100644
--- a/src/interface/wallet.h
+++ b/src/interface/wallet.h
@@ -33,7 +33,9 @@ class Handler;
class PendingWalletTx;
struct WalletAddress;
struct WalletBalances;
+struct WalletTx;
struct WalletTxOut;
+struct WalletTxStatus;
using WalletOrderForm = std::vector<std::pair<std::string, std::string>>;
using WalletValueMap = std::map<std::string, std::string>;
@@ -158,6 +160,29 @@ public:
std::vector<std::string>& errors,
uint256& bumped_txid) = 0;
+ //! Get a transaction.
+ virtual CTransactionRef getTx(const uint256& txid) = 0;
+
+ //! Get transaction information.
+ virtual WalletTx getWalletTx(const uint256& 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 uint256& txid,
+ WalletTxStatus& tx_status,
+ int& num_blocks,
+ int64_t& adjusted_time) = 0;
+
+ //! Get transaction details.
+ virtual WalletTx getWalletTxDetails(const uint256& txid,
+ WalletTxStatus& tx_status,
+ WalletOrderForm& order_form,
+ bool& in_mempool,
+ int& num_blocks,
+ int64_t& adjusted_time) = 0;
+
//! Get balances.
virtual WalletBalances getBalances() = 0;
@@ -170,6 +195,18 @@ public:
//! Get available balance.
virtual CAmount 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 CAmount getDebit(const CTxIn& txin, isminefilter filter) = 0;
+
+ //! Return credit amount if transaction input belongs to wallet.
+ virtual CAmount 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<CTxDestination, std::vector<std::tuple<COutPoint, WalletTxOut>>>;
@@ -265,6 +302,38 @@ struct WalletBalances
}
};
+// 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;
+ CAmount credit;
+ CAmount debit;
+ CAmount 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.
struct WalletTxOut
{