aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfurszy <matiasfurszyfer@protonmail.com>2022-05-24 12:29:51 -0300
committerfurszy <matiasfurszyfer@protonmail.com>2022-07-08 11:18:35 -0300
commit198fcca162f4d2f877feab485e629ff89818ff56 (patch)
treec2d761c60589b323f811883963853326e421718d /src
parent7a45c33d1f8a758850cf8e7bd6ad508939ba5c0d (diff)
wallet: refactor, include 'FeeCalculation' inside 'CreatedTransactionResult'
Diffstat (limited to 'src')
-rw-r--r--src/wallet/feebumper.cpp3
-rw-r--r--src/wallet/interfaces.cpp3
-rw-r--r--src/wallet/rpc/spend.cpp5
-rw-r--r--src/wallet/spend.cpp12
-rw-r--r--src/wallet/spend.h8
-rw-r--r--src/wallet/test/spend_tests.cpp3
-rw-r--r--src/wallet/test/wallet_tests.cpp5
-rw-r--r--src/wallet/wallet.h1
8 files changed, 15 insertions, 25 deletions
diff --git a/src/wallet/feebumper.cpp b/src/wallet/feebumper.cpp
index 5e70ed4a30..9bd7e62c28 100644
--- a/src/wallet/feebumper.cpp
+++ b/src/wallet/feebumper.cpp
@@ -220,8 +220,7 @@ Result CreateRateBumpTransaction(CWallet& wallet, const uint256& txid, const CCo
constexpr int RANDOM_CHANGE_POSITION = -1;
bilingual_str fail_reason;
- FeeCalculation fee_calc_out;
- std::optional<CreatedTransactionResult> txr = CreateTransaction(wallet, recipients, RANDOM_CHANGE_POSITION, fail_reason, new_coin_control, fee_calc_out, false);
+ std::optional<CreatedTransactionResult> txr = CreateTransaction(wallet, recipients, RANDOM_CHANGE_POSITION, fail_reason, new_coin_control, false);
if (!txr) {
errors.push_back(Untranslated("Unable to create transaction.") + Untranslated(" ") + fail_reason);
return Result::WALLET_ERROR;
diff --git a/src/wallet/interfaces.cpp b/src/wallet/interfaces.cpp
index 327276f2ed..cec103b02b 100644
--- a/src/wallet/interfaces.cpp
+++ b/src/wallet/interfaces.cpp
@@ -258,9 +258,8 @@ public:
bilingual_str& fail_reason) override
{
LOCK(m_wallet->cs_wallet);
- FeeCalculation fee_calc_out;
std::optional<CreatedTransactionResult> txr = CreateTransaction(*m_wallet, recipients, change_pos,
- fail_reason, coin_control, fee_calc_out, sign);
+ fail_reason, coin_control, sign);
if (!txr) return {};
fee = txr->fee;
change_pos = txr->change_pos;
diff --git a/src/wallet/rpc/spend.cpp b/src/wallet/rpc/spend.cpp
index 0e8cee5db8..362e9113fb 100644
--- a/src/wallet/rpc/spend.cpp
+++ b/src/wallet/rpc/spend.cpp
@@ -157,8 +157,7 @@ UniValue SendMoney(CWallet& wallet, const CCoinControl &coin_control, std::vecto
// Send
constexpr int RANDOM_CHANGE_POSITION = -1;
bilingual_str error;
- FeeCalculation fee_calc_out;
- std::optional<CreatedTransactionResult> txr = CreateTransaction(wallet, recipients, RANDOM_CHANGE_POSITION, error, coin_control, fee_calc_out, true);
+ std::optional<CreatedTransactionResult> txr = CreateTransaction(wallet, recipients, RANDOM_CHANGE_POSITION, error, coin_control, true);
if (!txr) {
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, error.original);
}
@@ -167,7 +166,7 @@ UniValue SendMoney(CWallet& wallet, const CCoinControl &coin_control, std::vecto
if (verbose) {
UniValue entry(UniValue::VOBJ);
entry.pushKV("txid", tx->GetHash().GetHex());
- entry.pushKV("fee_reason", StringForFeeReason(fee_calc_out.reason));
+ entry.pushKV("fee_reason", StringForFeeReason(txr->fee_calc.reason));
return entry;
}
return tx->GetHash().GetHex();
diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp
index 1d22d0993e..9846335da7 100644
--- a/src/wallet/spend.cpp
+++ b/src/wallet/spend.cpp
@@ -662,7 +662,6 @@ static std::optional<CreatedTransactionResult> CreateTransactionInternal(
int change_pos,
bilingual_str& error,
const CCoinControl& coin_control,
- FeeCalculation& fee_calc_out,
bool sign) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
{
AssertLockHeld(wallet.cs_wallet);
@@ -954,7 +953,6 @@ static std::optional<CreatedTransactionResult> CreateTransactionInternal(
// Before we return success, we assume any change key will be used to prevent
// accidental re-use.
reservedest.KeepDestination();
- fee_calc_out = feeCalc;
wallet.WalletLogPrintf("Fee Calculation: Fee:%d Bytes:%u Tgt:%d (requested %d) Reason:\"%s\" Decay %.5f: Estimation: (%g - %g) %.2f%% %.1f/(%.1f %d mem %.1f out) Fail: (%g - %g) %.2f%% %.1f/(%.1f %d mem %.1f out)\n",
nFeeRet, nBytes, feeCalc.returnedTarget, feeCalc.desiredTarget, StringForFeeReason(feeCalc.reason), feeCalc.est.decay,
@@ -964,7 +962,7 @@ static std::optional<CreatedTransactionResult> CreateTransactionInternal(
feeCalc.est.fail.start, feeCalc.est.fail.end,
(feeCalc.est.fail.totalConfirmed + feeCalc.est.fail.inMempool + feeCalc.est.fail.leftMempool) > 0.0 ? 100 * feeCalc.est.fail.withinTarget / (feeCalc.est.fail.totalConfirmed + feeCalc.est.fail.inMempool + feeCalc.est.fail.leftMempool) : 0.0,
feeCalc.est.fail.withinTarget, feeCalc.est.fail.totalConfirmed, feeCalc.est.fail.inMempool, feeCalc.est.fail.leftMempool);
- return CreatedTransactionResult(tx, nFeeRet, nChangePosInOut);
+ return CreatedTransactionResult(tx, nFeeRet, nChangePosInOut, feeCalc);
}
std::optional<CreatedTransactionResult> CreateTransaction(
@@ -973,7 +971,6 @@ std::optional<CreatedTransactionResult> CreateTransaction(
int change_pos,
bilingual_str& error,
const CCoinControl& coin_control,
- FeeCalculation& fee_calc_out,
bool sign)
{
if (vecSend.empty()) {
@@ -988,7 +985,7 @@ std::optional<CreatedTransactionResult> CreateTransaction(
LOCK(wallet.cs_wallet);
- std::optional<CreatedTransactionResult> txr_ungrouped = CreateTransactionInternal(wallet, vecSend, change_pos, error, coin_control, fee_calc_out, sign);
+ std::optional<CreatedTransactionResult> txr_ungrouped = CreateTransactionInternal(wallet, vecSend, change_pos, error, coin_control, sign);
TRACE4(coin_selection, normal_create_tx_internal, wallet.GetName().c_str(), txr_ungrouped.has_value(),
txr_ungrouped.has_value() ? txr_ungrouped->fee : 0, txr_ungrouped.has_value() ? txr_ungrouped->change_pos : 0);
if (!txr_ungrouped) return std::nullopt;
@@ -998,7 +995,7 @@ std::optional<CreatedTransactionResult> CreateTransaction(
CCoinControl tmp_cc = coin_control;
tmp_cc.m_avoid_partial_spends = true;
bilingual_str error2; // fired and forgotten; if an error occurs, we discard the results
- std::optional<CreatedTransactionResult> txr_grouped = CreateTransactionInternal(wallet, vecSend, change_pos, error2, tmp_cc, fee_calc_out, sign);
+ std::optional<CreatedTransactionResult> txr_grouped = CreateTransactionInternal(wallet, vecSend, change_pos, error2, tmp_cc, sign);
// if fee of this alternative one is within the range of the max fee, we use this one
const bool use_aps{txr_grouped.has_value() ? (txr_grouped->fee <= txr_ungrouped->fee + wallet.m_max_aps_fee) : false};
TRACE5(coin_selection, aps_create_tx_internal, wallet.GetName().c_str(), use_aps, txr_grouped.has_value(),
@@ -1045,8 +1042,7 @@ bool FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& nFeeRet,
}
}
- FeeCalculation fee_calc_out;
- std::optional<CreatedTransactionResult> txr = CreateTransaction(wallet, vecSend, nChangePosInOut, error, coinControl, fee_calc_out, false);
+ std::optional<CreatedTransactionResult> txr = CreateTransaction(wallet, vecSend, nChangePosInOut, error, coinControl, false);
if (!txr) return false;
CTransactionRef tx_new = txr->tx;
nFeeRet = txr->fee;
diff --git a/src/wallet/spend.h b/src/wallet/spend.h
index cba42d6fae..ecf9b695ee 100644
--- a/src/wallet/spend.h
+++ b/src/wallet/spend.h
@@ -6,6 +6,7 @@
#define BITCOIN_WALLET_SPEND_H
#include <consensus/amount.h>
+#include <policy/fees.h> // for FeeCalculation
#include <wallet/coinselection.h>
#include <wallet/transaction.h>
#include <wallet/wallet.h>
@@ -107,10 +108,11 @@ struct CreatedTransactionResult
{
CTransactionRef tx;
CAmount fee;
+ FeeCalculation fee_calc;
int change_pos;
- CreatedTransactionResult(CTransactionRef tx, CAmount fee, int change_pos)
- : tx(tx), fee(fee), change_pos(change_pos) {}
+ CreatedTransactionResult(CTransactionRef _tx, CAmount _fee, int _change_pos, const FeeCalculation& _fee_calc)
+ : tx(_tx), fee(_fee), fee_calc(_fee_calc), change_pos(_change_pos) {}
};
/**
@@ -118,7 +120,7 @@ struct CreatedTransactionResult
* selected by SelectCoins(); Also create the change output, when needed
* @note passing change_pos as -1 will result in setting a random position
*/
-std::optional<CreatedTransactionResult> CreateTransaction(CWallet& wallet, const std::vector<CRecipient>& vecSend, int change_pos, bilingual_str& error, const CCoinControl& coin_control, FeeCalculation& fee_calc_out, bool sign = true);
+std::optional<CreatedTransactionResult> CreateTransaction(CWallet& wallet, const std::vector<CRecipient>& vecSend, int change_pos, bilingual_str& error, const CCoinControl& coin_control, bool sign = true);
/**
* Insert additional inputs into the transaction by
diff --git a/src/wallet/test/spend_tests.cpp b/src/wallet/test/spend_tests.cpp
index bdc148afb4..435c139170 100644
--- a/src/wallet/test/spend_tests.cpp
+++ b/src/wallet/test/spend_tests.cpp
@@ -34,8 +34,7 @@ BOOST_FIXTURE_TEST_CASE(SubtractFee, TestChain100Setup)
coin_control.fOverrideFeeRate = true;
// We need to use a change type with high cost of change so that the leftover amount will be dropped to fee instead of added as a change output
coin_control.m_change_type = OutputType::LEGACY;
- FeeCalculation fee_calc;
- std::optional<CreatedTransactionResult> txr = CreateTransaction(*wallet, {recipient}, RANDOM_CHANGE_POSITION, error, coin_control, fee_calc);
+ std::optional<CreatedTransactionResult> txr = CreateTransaction(*wallet, {recipient}, RANDOM_CHANGE_POSITION, error, coin_control);
BOOST_CHECK(txr.has_value());
BOOST_CHECK_EQUAL(txr->tx->vout.size(), 1);
BOOST_CHECK_EQUAL(txr->tx->vout[0].nValue, recipient.nAmount + leftover_input_amount - txr->fee);
diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp
index 0c03b2f4a2..9ed840031d 100644
--- a/src/wallet/test/wallet_tests.cpp
+++ b/src/wallet/test/wallet_tests.cpp
@@ -4,7 +4,6 @@
#include <wallet/wallet.h>
-#include <any>
#include <future>
#include <memory>
#include <stdint.h>
@@ -13,7 +12,6 @@
#include <interfaces/chain.h>
#include <key_io.h>
#include <node/blockstorage.h>
-#include <node/context.h>
#include <policy/policy.h>
#include <rpc/server.h>
#include <test/util/logging.h>
@@ -523,10 +521,9 @@ public:
CTransactionRef tx;
bilingual_str error;
CCoinControl dummy;
- FeeCalculation fee_calc_out;
{
constexpr int RANDOM_CHANGE_POSITION = -1;
- std::optional<CreatedTransactionResult> txr = CreateTransaction(*wallet, {recipient}, RANDOM_CHANGE_POSITION, error, dummy, fee_calc_out);
+ std::optional<CreatedTransactionResult> txr = CreateTransaction(*wallet, {recipient}, RANDOM_CHANGE_POSITION, error, dummy);
BOOST_CHECK(txr.has_value());
tx = txr->tx;
}
diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h
index 6b12752c34..0ebc18ca8b 100644
--- a/src/wallet/wallet.h
+++ b/src/wallet/wallet.h
@@ -45,7 +45,6 @@ using LoadWalletFn = std::function<void(std::unique_ptr<interfaces::Wallet> wall
class CScript;
enum class FeeEstimateMode;
-struct FeeCalculation;
struct bilingual_str;
namespace wallet {