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
6179f392
Commit
6179f392
authored
Jun 21, 2017
by
Jeremy Bokobza
Committed by
GitHub
Jun 21, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #106 from dangershony/light-wallet-fee-estimator
Adding a fee estimator
parents
5ae36c40
26ef3c0a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
0 deletions
+76
-0
LightWalletFeature.cs
Breeze/src/Breeze.Wallet/LightWalletFeature.cs
+1
-0
WalletFeePolicy.cs
Breeze/src/Breeze.Wallet/WalletFeePolicy.cs
+75
-0
No files found.
Breeze/src/Breeze.Wallet/LightWalletFeature.cs
View file @
6179f392
...
...
@@ -41,6 +41,7 @@ namespace Breeze.Wallet
{
services
.
AddSingleton
<
IWalletSyncManager
,
LightWalletSyncManager
>();
services
.
AddSingleton
<
IWalletManager
,
WalletManager
>();
services
.
AddSingleton
<
IWalletFeePolicy
,
LightWalletFeePolicy
>();
services
.
AddSingleton
<
WalletController
>();
});
...
...
Breeze/src/Breeze.Wallet/WalletFeePolicy.cs
0 → 100644
View file @
6179f392
using
System
;
using
NBitcoin
;
using
Stratis.Bitcoin.MemoryPool
;
using
Stratis.Bitcoin.MemoryPool.Fee
;
using
Stratis.Bitcoin.Wallet
;
namespace
Breeze.Wallet
{
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
;
/// <summary>
/// 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
;
this
.
minTxFee
=
new
FeeRate
(
1000
);
this
.
fallbackFee
=
new
FeeRate
(
20000
);
this
.
payTxFee
=
new
FeeRate
(
0
);
this
.
maxTxFee
=
new
Money
(
0.1
M
,
MoneyUnit
.
BTC
);
}
public
Money
GetRequiredFee
(
int
txBytes
)
{
return
Math
.
Max
(
this
.
minTxFee
.
GetFee
(
txBytes
),
MempoolValidator
.
MinRelayTxFee
.
GetFee
(
txBytes
));
}
public
Money
GetMinimumFee
(
int
txBytes
,
int
confirmTarget
)
{
// payTxFee is the user-set global for desired feerate
return
this
.
GetMinimumFee
(
txBytes
,
confirmTarget
,
this
.
payTxFee
.
GetFee
(
txBytes
));
}
public
Money
GetMinimumFee
(
int
txBytes
,
int
confirmTarget
,
Money
targetFee
)
{
Money
nFeeNeeded
=
targetFee
;
// User didn't set: use -txconfirmtarget to estimate...
if
(
nFeeNeeded
==
0
)
{
int
estimateFoundTarget
=
confirmTarget
;
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
nFeeNeeded
=
Math
.
Max
(
nFeeNeeded
,
this
.
GetRequiredFee
(
txBytes
));
// But always obey the maximum
if
(
nFeeNeeded
>
this
.
maxTxFee
)
nFeeNeeded
=
this
.
maxTxFee
;
return
nFeeNeeded
;
}
}
}
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