aboutsummaryrefslogtreecommitdiff
path: root/src/interface
diff options
context:
space:
mode:
authorRussell Yanofsky <russ@yanofsky.org>2017-04-17 19:46:08 -0400
committerJohn Newbery <john@johnnewbery.com>2018-04-04 16:52:40 -0400
commit827de038ab6fa58aa3d46151eb2f8dc6add7743e (patch)
treef468c36b2f2b8a8e6f34c1ad1fc0dd4dfa275089 /src/interface
parenta0704a8996bb950ae3c4d5b5a30e9dfe34cde1d3 (diff)
Remove direct bitcoin calls from qt/coincontroldialog.cpp
Diffstat (limited to 'src/interface')
-rw-r--r--src/interface/node.cpp28
-rw-r--r--src/interface/node.h21
-rw-r--r--src/interface/wallet.cpp41
-rw-r--r--src/interface/wallet.h19
4 files changed, 109 insertions, 0 deletions
diff --git a/src/interface/node.cpp b/src/interface/node.cpp
index db03cc0627..1bd7e48b05 100644
--- a/src/interface/node.cpp
+++ b/src/interface/node.cpp
@@ -15,6 +15,9 @@
#include <net_processing.h>
#include <netaddress.h>
#include <netbase.h>
+#include <policy/feerate.h>
+#include <policy/fees.h>
+#include <policy/policy.h>
#include <primitives/block.h>
#include <rpc/server.h>
#include <scheduler.h>
@@ -29,6 +32,7 @@
#include <config/bitcoin-config.h>
#endif
#ifdef ENABLE_WALLET
+#include <wallet/fees.h>
#include <wallet/wallet.h>
#define CHECK_WALLET(x) x
#else
@@ -186,7 +190,31 @@ class NodeImpl : public Node
}
bool getNetworkActive() override { return g_connman && g_connman->GetNetworkActive(); }
unsigned int getTxConfirmTarget() override { CHECK_WALLET(return ::nTxConfirmTarget); }
+ CAmount getRequiredFee(unsigned int tx_bytes) override { CHECK_WALLET(return GetRequiredFee(tx_bytes)); }
+ CAmount getMinimumFee(unsigned int tx_bytes,
+ const CCoinControl& coin_control,
+ int* returned_target,
+ FeeReason* reason) override
+ {
+ FeeCalculation fee_calc;
+ CAmount result;
+ CHECK_WALLET(result = GetMinimumFee(tx_bytes, coin_control, ::mempool, ::feeEstimator, &fee_calc));
+ if (returned_target) *returned_target = fee_calc.returnedTarget;
+ if (reason) *reason = fee_calc.reason;
+ return result;
+ }
CAmount getMaxTxFee() override { return ::maxTxFee; }
+ CFeeRate estimateSmartFee(int num_blocks, bool conservative, int* returned_target = nullptr) override
+ {
+ FeeCalculation fee_calc;
+ CFeeRate result = ::feeEstimator.estimateSmartFee(num_blocks, &fee_calc, conservative);
+ if (returned_target) {
+ *returned_target = fee_calc.returnedTarget;
+ }
+ return result;
+ }
+ CFeeRate getDustRelayFee() override { return ::dustRelayFee; }
+ CFeeRate getPayTxFee() override { CHECK_WALLET(return ::payTxFee); }
UniValue executeRpc(const std::string& command, const UniValue& params, const std::string& uri) override
{
JSONRPCRequest req;
diff --git a/src/interface/node.h b/src/interface/node.h
index b0d435695e..606d1238e0 100644
--- a/src/interface/node.h
+++ b/src/interface/node.h
@@ -19,10 +19,13 @@
#include <tuple>
#include <vector>
+class CCoinControl;
+class CFeeRate;
class CNodeStats;
class RPCTimerInterface;
class UniValue;
class proxyType;
+enum class FeeReason;
struct CNodeStateStats;
namespace interface {
@@ -145,9 +148,27 @@ public:
//! Get tx confirm target.
virtual unsigned int getTxConfirmTarget() = 0;
+ //! Get required fee.
+ virtual CAmount getRequiredFee(unsigned int tx_bytes) = 0;
+
+ //! Get minimum fee.
+ virtual CAmount getMinimumFee(unsigned int tx_bytes,
+ const CCoinControl& coin_control,
+ int* returned_target,
+ FeeReason* reason) = 0;
+
//! Get max tx fee.
virtual CAmount getMaxTxFee() = 0;
+ //! Estimate smart fee.
+ virtual CFeeRate estimateSmartFee(int num_blocks, bool conservative, int* returned_target = nullptr) = 0;
+
+ //! Get dust relay fee.
+ virtual CFeeRate getDustRelayFee() = 0;
+
+ //! Get pay tx fee.
+ virtual CFeeRate getPayTxFee() = 0;
+
//! Execute rpc command.
virtual UniValue executeRpc(const std::string& command, const UniValue& params, const std::string& uri) = 0;
diff --git a/src/interface/wallet.cpp b/src/interface/wallet.cpp
index 8dae7ac547..cbf30f49bc 100644
--- a/src/interface/wallet.cpp
+++ b/src/interface/wallet.cpp
@@ -54,6 +54,17 @@ public:
CReserveKey m_key;
};
+//! Construct wallet TxOut struct.
+WalletTxOut MakeWalletTxOut(CWallet& wallet, const CWalletTx& wtx, int n, int depth)
+{
+ WalletTxOut result;
+ result.txout = wtx.tx->vout[n];
+ result.time = wtx.GetTxTime();
+ result.depth_in_main_chain = depth;
+ result.is_spent = wallet.IsSpent(wtx.GetHash(), n);
+ return result;
+}
+
class WalletImpl : public Wallet
{
public:
@@ -207,6 +218,36 @@ public:
{
return m_wallet.GetAvailableBalance(&coin_control);
}
+ CoinsList listCoins() override
+ {
+ LOCK2(::cs_main, m_wallet.cs_wallet);
+ CoinsList result;
+ for (const auto& entry : m_wallet.ListCoins()) {
+ auto& group = result[entry.first];
+ for (const auto& coin : entry.second) {
+ group.emplace_back(
+ COutPoint(coin.tx->GetHash(), coin.i), MakeWalletTxOut(m_wallet, *coin.tx, coin.i, coin.nDepth));
+ }
+ }
+ return result;
+ }
+ std::vector<WalletTxOut> getCoins(const std::vector<COutPoint>& outputs) override
+ {
+ LOCK2(::cs_main, m_wallet.cs_wallet);
+ std::vector<WalletTxOut> result;
+ result.reserve(outputs.size());
+ for (const auto& output : outputs) {
+ result.emplace_back();
+ auto it = m_wallet.mapWallet.find(output.hash);
+ if (it != m_wallet.mapWallet.end()) {
+ int depth = it->second.GetDepthInMainChain();
+ if (depth >= 0) {
+ result.back() = MakeWalletTxOut(m_wallet, it->second, output.n, depth);
+ }
+ }
+ }
+ return result;
+ }
bool hdEnabled() override { return m_wallet.IsHDEnabled(); }
OutputType getDefaultAddressType() override { return m_wallet.m_default_address_type; }
OutputType getDefaultChangeType() override { return m_wallet.m_default_change_type; }
diff --git a/src/interface/wallet.h b/src/interface/wallet.h
index 317b5c683c..6cc196fd94 100644
--- a/src/interface/wallet.h
+++ b/src/interface/wallet.h
@@ -16,6 +16,7 @@
#include <memory>
#include <stdint.h>
#include <string>
+#include <tuple>
#include <utility>
#include <vector>
@@ -30,6 +31,7 @@ namespace interface {
class Handler;
class PendingWalletTx;
struct WalletBalances;
+struct WalletTxOut;
using WalletOrderForm = std::vector<std::pair<std::string, std::string>>;
using WalletValueMap = std::map<std::string, std::string>;
@@ -153,6 +155,14 @@ public:
//! Get available balance.
virtual CAmount 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.
virtual bool hdEnabled() = 0;
@@ -226,6 +236,15 @@ struct WalletBalances
}
};
+//! 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
//! in builds where ENABLE_WALLET is false.
std::unique_ptr<Wallet> MakeWallet(CWallet& wallet);