Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
Breeze
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DeStream-public
Breeze
Commits
9ef4dcde
Commit
9ef4dcde
authored
Jun 21, 2017
by
Dan Gershony
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Light wallet fee estimator to use hard coded values
parent
6179f392
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
41 deletions
+29
-41
WalletFeePolicy.cs
Breeze/src/Breeze.Wallet/WalletFeePolicy.cs
+29
-41
No files found.
Breeze/src/Breeze.Wallet/WalletFeePolicy.cs
View file @
9ef4dcde
...
@@ -9,36 +9,28 @@ namespace Breeze.Wallet
...
@@ -9,36 +9,28 @@ namespace Breeze.Wallet
public
class
LightWalletFeePolicy
:
IWalletFeePolicy
public
class
LightWalletFeePolicy
:
IWalletFeePolicy
{
{
private
readonly
BlockPolicyEstimator
blockPolicyEstimator
;
private
readonly
Money
maxTxFee
;
/// <summary>
/// Fees smaller than this (in satoshi) are considered zero fee (for transaction creation)
/// Override with -mintxfee
/// </summary>
private
readonly
FeeRate
minTxFee
;
private
readonly
FeeRate
minTxFee
;
private
readonly
Money
maxTxFee
;
private
readonly
FeeRate
highxFeePerKb
;
private
readonly
FeeRate
mediumTxFeePerKb
;
private
readonly
FeeRate
lowTxFeePerKb
;
/// <summary>
public
LightWalletFeePolicy
()
/// If fee estimation does not have enough data to provide estimates, use this fee instead.
/// Has no effect if not using fee estimation
/// Override with -fallbackfee
/// </summary>
private
readonly
FeeRate
fallbackFee
;
/// <summary>
/// Transaction fee set by the user
/// </summary>
private
readonly
FeeRate
payTxFee
;
public
LightWalletFeePolicy
(
BlockPolicyEstimator
blockPolicyEstimator
)
{
{
this
.
blockPolicyEstimator
=
blockPolicyEstimator
;
// when estimating the fee, the fee of each transactions needs to be knowen
// as this is an estimator on a light wallet we dont have the UTXO set
this
.
minTxFee
=
new
FeeRate
(
1000
);
// that leaves with few options:
this
.
fallbackFee
=
new
FeeRate
(
20000
);
// - an external service,
this
.
payTxFee
=
new
FeeRate
(
0
);
// - hard code fee per kb
// - we may even be able to monitor the size of the mempool (mini mempool)
// (not the entire trx) and try to estimate based on pending count
// TODO: make fee values confugurable on startup
this
.
highxFeePerKb
=
new
FeeRate
(
385939
);
this
.
mediumTxFeePerKb
=
new
FeeRate
(
245347
);
this
.
lowTxFeePerKb
=
new
FeeRate
(
171274
);
this
.
maxTxFee
=
new
Money
(
0.1
M
,
MoneyUnit
.
BTC
);
this
.
maxTxFee
=
new
Money
(
0.1
M
,
MoneyUnit
.
BTC
);
this
.
minTxFee
=
new
FeeRate
(
1000
);
}
}
public
Money
GetRequiredFee
(
int
txBytes
)
public
Money
GetRequiredFee
(
int
txBytes
)
...
@@ -49,27 +41,23 @@ namespace Breeze.Wallet
...
@@ -49,27 +41,23 @@ namespace Breeze.Wallet
public
Money
GetMinimumFee
(
int
txBytes
,
int
confirmTarget
)
public
Money
GetMinimumFee
(
int
txBytes
,
int
confirmTarget
)
{
{
// payTxFee is the user-set global for desired feerate
// payTxFee is the user-set global for desired feerate
return
this
.
GetMinimumFee
(
txBytes
,
confirmTarget
,
this
.
payTxFee
.
GetFee
(
txBytes
));
return
this
.
GetMinimumFee
(
txBytes
,
confirmTarget
,
this
.
lowTxFeePerKb
.
GetFee
(
txBytes
));
}
}
public
Money
GetMinimumFee
(
int
txBytes
,
int
confirmTarget
,
Money
targetFee
)
public
Money
GetMinimumFee
(
int
txBytes
,
int
confirmTarget
,
Money
targetFee
)
{
{
Money
nFeeNeeded
=
targetFee
;
Money
feeNeeded
=
targetFee
;
// User didn't set: use -txconfirmtarget to estimate...
if
(
nFeeNeeded
==
0
)
feeNeeded
=
this
.
lowTxFeePerKb
.
GetFee
(
txBytes
);
{
if
(
confirmTarget
<
50
)
feeNeeded
=
this
.
mediumTxFeePerKb
.
GetFee
(
txBytes
);
int
estimateFoundTarget
=
confirmTarget
;
if
(
confirmTarget
<
20
)
feeNeeded
=
this
.
highxFeePerKb
.
GetFee
(
txBytes
);
nFeeNeeded
=
this
.
blockPolicyEstimator
.
EstimateSmartFee
(
confirmTarget
,
null
,
out
estimateFoundTarget
).
GetFee
(
txBytes
);
// ... unless we don't have enough mempool data for estimatefee, then use fallbackFee
if
(
nFeeNeeded
==
0
)
nFeeNeeded
=
this
.
fallbackFee
.
GetFee
(
txBytes
);
}
// prevent user from paying a fee below minRelayTxFee or minTxFee
// prevent user from paying a fee below minRelayTxFee or minTxFee
nFeeNeeded
=
Math
.
Max
(
nF
eeNeeded
,
this
.
GetRequiredFee
(
txBytes
));
feeNeeded
=
Math
.
Max
(
f
eeNeeded
,
this
.
GetRequiredFee
(
txBytes
));
// But always obey the maximum
// But always obey the maximum
if
(
nF
eeNeeded
>
this
.
maxTxFee
)
if
(
f
eeNeeded
>
this
.
maxTxFee
)
nF
eeNeeded
=
this
.
maxTxFee
;
f
eeNeeded
=
this
.
maxTxFee
;
return
nF
eeNeeded
;
return
f
eeNeeded
;
}
}
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment