@@ -15,16 +15,16 @@
Loading
15 15
namespace TW::Bitcoin {
16 16
17 17
/// Estimate encoded size by simple formula
18 -
int64_t estimateSimpleFee(FeeCalculator& feeCalculator, const TransactionPlan& plan, int outputSize, const Bitcoin::Proto::SigningInput& input) {
19 -
    return feeCalculator.calculate(plan.utxos.size(), outputSize, input.byte_fee());
18 +
int64_t estimateSimpleFee(const FeeCalculator& feeCalculator, const TransactionPlan& plan, int outputSize, int64_t byteFee) {
19 +
    return feeCalculator.calculate(plan.utxos.size(), outputSize, byteFee);
20 20
}
21 21
22 22
/// Estimate encoded size by invoking sign(sizeOnly), get actual size
23 -
int64_t estimateSegwitFee(FeeCalculator& feeCalculator, const TransactionPlan& plan, int outputSize, const Bitcoin::Proto::SigningInput& input) {
23 +
int64_t estimateSegwitFee(const FeeCalculator& feeCalculator, const TransactionPlan& plan, int outputSize, const Bitcoin::Proto::SigningInput& input) {
24 24
    TWPurpose coinPurpose = TW::purpose(static_cast<TWCoinType>(input.coin_type()));
25 25
    if (coinPurpose != TWPurposeBIP84) {
26 26
        // not segwit, return default simple estimate
27 -
        return estimateSimpleFee(feeCalculator, plan, outputSize, input);
27 +
        return estimateSimpleFee(feeCalculator, plan, outputSize, input.byte_fee());
28 28
    }
29 29
30 30
    // duplicate input, with the current plan
@@ -35,7 +35,7 @@
Loading
35 35
    auto result = signer.sign();
36 36
    if (!result) {
37 37
        // signing failed; return default simple estimate
38 -
        return estimateSimpleFee(feeCalculator, plan, outputSize, input);
38 +
        return estimateSimpleFee(feeCalculator, plan, outputSize, input.byte_fee());
39 39
    }
40 40
41 41
    // Obtain the encoded size
@@ -65,12 +65,13 @@
Loading
65 65
    auto plan = TransactionPlan();
66 66
    plan.amount = input.amount();
67 67
68 -
    auto output_size = 2;
69 -
    auto& feeCalculator = getFeeCalculator(static_cast<TWCoinType>(input.coin_type()));
68 +
    const auto& feeCalculator = getFeeCalculator(static_cast<TWCoinType>(input.coin_type()));
70 69
    auto unspentSelector = UnspentSelector(feeCalculator);
70 +
    bool maxAmount = input.use_max_amount();
71 71
72 72
    // select UTXOs
73 -
    if (!input.use_max_amount()) {
73 +
    auto output_size = 2;
74 +
    if (!maxAmount) {
74 75
        output_size = 2; // output + change
75 76
        plan.utxos = unspentSelector.select(input.utxo(), plan.amount, input.byte_fee(), output_size);
76 77
    } else {
@@ -82,7 +83,7 @@
Loading
82 83
83 84
    // Compute fee.
84 85
    // must preliminary set change so that there is a second output
85 -
    if (!input.use_max_amount()) {
86 +
    if (!maxAmount) {
86 87
        plan.amount = input.amount();
87 88
        plan.fee = 0;
88 89
        plan.change = plan.availableAmount - plan.amount;
@@ -97,7 +98,7 @@
Loading
97 98
    assert(plan.fee >= 0 && plan.fee <= plan.availableAmount);
98 99
    
99 100
    // adjust/compute amount
100 -
    if (!input.use_max_amount()) {
101 +
    if (!maxAmount) {
101 102
        // reduce amount if needed
102 103
        plan.amount = std::max(Amount(0), std::min(plan.amount, plan.availableAmount - plan.fee));
103 104
    } else {
@@ -109,7 +110,7 @@
Loading
109 110
    // compute change
110 111
    plan.change = plan.availableAmount - plan.amount - plan.fee;
111 112
    assert(plan.change >= 0 && plan.change <= plan.availableAmount);
112 -
    assert(!input.use_max_amount() || plan.change == 0); // change is 0 in max amount case
113 +
    assert(!maxAmount || plan.change == 0); // change is 0 in max amount case
113 114
114 115
    assert(plan.amount + plan.change + plan.fee == plan.availableAmount);
115 116

@@ -34,7 +34,7 @@
Loading
34 34
    std::vector<Proto::UnspentTransaction> selectMaxAmount(const T& utxos, int64_t byteFee);
35 35
36 36
    /// Construct, using provided feeCalculator (see getFeeCalculator()).
37 -
    explicit UnspentSelector(FeeCalculator& feeCalculator) : feeCalculator(feeCalculator) {}
37 +
    explicit UnspentSelector(const FeeCalculator& feeCalculator) : feeCalculator(feeCalculator) {}
38 38
    UnspentSelector() : UnspentSelector(getFeeCalculator(TWCoinTypeBitcoin)) {}
39 39
40 40
    template <typename T>
@@ -47,7 +47,7 @@
Loading
47 47
    }
48 48
49 49
  private:
50 -
    FeeCalculator& feeCalculator;
50 +
    const FeeCalculator& feeCalculator;
51 51
    template <typename T> std::vector<Proto::UnspentTransaction> filterDustInput(const T& selectedUtxos, int64_t byteFee);
52 52
};
53 53
Files Coverage
src 95.20%
walletconsole/lib 94.81%
Project Totals (429 files) 95.18%

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading