-
Notifications
You must be signed in to change notification settings - Fork 4
/
FeeCalculator.cpp
executable file
·86 lines (56 loc) · 1.56 KB
/
FeeCalculator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
* FeeCalculator.cpp
*
* Created on: 12 lug 2016
* Author: giovanni
*/
#include "FeeCalculator.h"
#include "PaymentChannel.h"
#include <iostream>
/*
FeeCalculatorOld::~FeeCalculatorOld() {
// TODO Auto-generated destructor stub
}
double FeeCalculatorOld::getSendingFee(double payment, PaymentChannel & p, int A, int B){
if (feeType==FIXED){
}
return baseFee;
}
*/
void FeeCalculatorOptimized::dump(){
std::cout << "Basefee: " << baseFee << " \n";
std::cout << "Slow:" << slow << " Shigh " << shigh << "\n";
}
std::vector<long> FeeCalculatorOptimized::getPoints(ln_units resFundsA, ln_units resFundsB){
std::vector<long> points;
points.push_back(0);
if (resFundsA > resFundsB){
points.push_back((resFundsA-resFundsB)/2);
}
points.push_back(resFundsA);
return points;
}
std::vector<long> FeeCalculatorOptimized::getSlopes(ln_units resFundsA, ln_units resFundsB){
std::vector<long> slopes;
if (resFundsA > resFundsB){
slopes.push_back(slow);
slopes.push_back(shigh);
} else
slopes.push_back(shigh);
return slopes;
}
millisatoshis FeeCalculatorOptimized::calcFee(millisatoshis P, PaymentChannel * pc, bool reverse=false){
ln_units fundsA,fundsB;
fundsA = !reverse ? pc->getResidualFundsA() : pc->getResidualFundsB();
fundsB = reverse ? pc->getResidualFundsA() : pc->getResidualFundsB();
ln_units imbh = (fundsA - fundsB)/2;
millisatoshis fee=0;
if (fundsA > fundsB) {
if ( P <= imbh )
fee = baseFee + slow * P;
else
fee = baseFee + slow * imbh + (P-imbh) * shigh;
} else
fee = baseFee + P * shigh;
return fee;
}