ledger-core
BitcoinLikeStrategyUtxoPicker.h
1 /*
2  *
3  * BitcoinLikeStrategyUtxoPicker.h
4  * ledger-core
5  *
6  * Created by Pierre Pollastri on 29/03/2018.
7  *
8  * The MIT License (MIT)
9  *
10  * Copyright (c) 2017 Ledger
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a copy
13  * of this software and associated documentation files (the "Software"), to deal
14  * in the Software without restriction, including without limitation the rights
15  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16  * copies of the Software, and to permit persons to whom the Software is
17  * furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be included in all
20  * copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28  * SOFTWARE.
29  *
30  */
31 
32 #ifndef LEDGER_CORE_BITCOINLIKESTRATEGYUTXOPICKER_H
33 #define LEDGER_CORE_BITCOINLIKESTRATEGYUTXOPICKER_H
34 
35 #include "BitcoinLikeUtxoPicker.h"
36 
37 namespace ledger {
38  namespace core {
40  public:
41  BitcoinLikeStrategyUtxoPicker(const std::shared_ptr<api::ExecutionContext> &context,
42  const api::Currency &currency);
43  protected:
44  Future<UTXODescriptorList> filterInputs(const std::shared_ptr<Buddy> &buddy) override;
45  UTXODescriptorList filterWithDeepFirst(const std::shared_ptr<Buddy> &buddy,
46  const std::vector<std::shared_ptr<api::BitcoinLikeOutput>>& utxo,
47  const BigInt& aggregatedAmount);
48  bool hasEnough(const std::shared_ptr<Buddy>& buddy, const BigInt& aggregatedAmount, int inputCount, bool computeOutputAmount = false);
49  inline Future<BigInt> computeAggregatedAmount(const std::shared_ptr<Buddy>& buddy);
50 
51  //Only usefull for filterWithLowestFees
52  struct EffectiveUTXO {
53  std::shared_ptr<api::BitcoinLikeOutput> output;
54  int64_t effectiveValue;
55  int64_t effectiveFees;
56  int64_t longTermFees;
57  };
58  BitcoinLikeUtxoPicker::UTXODescriptorList filterWithOptimizeSize(const std::shared_ptr<BitcoinLikeUtxoPicker::Buddy> &buddy,
59  const std::vector<std::shared_ptr<api::BitcoinLikeOutput>> &utxos,
60  const BigInt &aggregatedAmount);
61 
62  BitcoinLikeUtxoPicker::UTXODescriptorList filterWithMergeOutputs(const std::shared_ptr<BitcoinLikeUtxoPicker::Buddy> &buddy,
63  const std::vector<std::shared_ptr<api::BitcoinLikeOutput>> &utxos,
64  const BigInt &aggregatedAmount);
65 
66  //Usefull for filterWithLowFeesFirst
67  static const int64_t DEFAULT_FALLBACK_FEE = 20;
68  static const int64_t DEFAULT_DISCARD_FEE = 10;
69  static const int64_t COIN = 100000000;
70  static const int64_t MAX_MONEY = 21000000 * COIN;
71  static const uint32_t TOTAL_TRIES = 100000;
72  static const int64_t CENT = 1000000;
73  static const int64_t MIN_CHANGE = 100000;
74  private:
75  BitcoinLikeUtxoPicker::UTXODescriptorList filterWithKnapsackSolver(const std::shared_ptr<BitcoinLikeUtxoPicker::Buddy> &buddy,
76  const std::vector<std::shared_ptr<api::BitcoinLikeOutput>> &utxos,
77  const BigInt &aggregatedAmount);
78 
79  };
80  }
81 }
82 
83 
84 #endif //LEDGER_CORE_BITCOINLIKESTRATEGYUTXOPICKER_H
Definition: BitcoinLikeUtxoPicker.h:52
Definition: Deffered.hpp:49
Definition: Currency.hpp:23
Definition: BitcoinLikeStrategyUtxoPicker.h:52
Definition: Account.cpp:8
Definition: BitcoinLikeStrategyUtxoPicker.h:39
Definition: BigInt.h:56