Replace manual estimatesmartfee with the newly implemented NBitcoin's estimatesmartee
MODIFY
HiddenWallet.ChaumianTumbler/Configuration/Config.cs
HiddenWallet.ChaumianTumbler/Configuration/Config.cs
@@ -10,6 +10,7 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using HiddenWallet.ChaumianTumbler.Configuration;
+using NBitcoin.RPC;
namespace HiddenWallet.ChaumianTumbler.Configuration
{
@@ -68,7 +69,8 @@ namespace HiddenWallet.ChaumianTumbler.Configuration
public int? FeeConfirmationTarget { get; private set; }
[JsonProperty(PropertyName = "FeeEstimationMode")]
- public string FeeEstimationMode { get; private set; }
+ [JsonConverter(typeof(EstimateSmartFeeModeConverter))]
+ public EstimateSmartFeeMode FeeEstimationMode { get; private set; }
public Config()
{
@@ -106,7 +108,7 @@ namespace HiddenWallet.ChaumianTumbler.Configuration
MaximumInputsPerAlices = 7;
FallBackSatoshiFeePerBytes = 300;
FeeConfirmationTarget = 2;
- FeeEstimationMode = "ECONOMICAL";
+ FeeEstimationMode = EstimateSmartFeeMode.Economical;
if (!File.Exists(path))
{
@@ -133,7 +135,7 @@ namespace HiddenWallet.ChaumianTumbler.Configuration
MaximumInputsPerAlices = config.MaximumInputsPerAlices ?? MaximumInputsPerAlices;
FallBackSatoshiFeePerBytes = config.FallBackSatoshiFeePerBytes ?? FallBackSatoshiFeePerBytes;
FeeConfirmationTarget = config.FeeConfirmationTarget ?? FeeConfirmationTarget;
- FeeEstimationMode = config.FeeEstimationMode ?? FeeEstimationMode;
+ FeeEstimationMode = config.FeeEstimationMode;
}
await ToFileAsync(path, cancel);

MODIFY
HiddenWallet.ChaumianTumbler/Global.cs
HiddenWallet.ChaumianTumbler/Global.cs
@@ -118,10 +118,8 @@ namespace HiddenWallet.ChaumianTumbler
throw new NotSupportedException("blocks != headers");
}
- if (string.IsNullOrWhiteSpace((await RpcClient.SendCommandAsync("estimatesmartfee", Config.FeeConfirmationTarget, Config.FeeEstimationMode))?.ResultString))
- {
- throw new NotSupportedException($"estimatesmartfee {Config.FeeConfirmationTarget} {Config.FeeEstimationMode} == null");
- }
+ var estimateSmartFeeResponse = await RpcClient.TryEstimateSmartFeeAsync((int)Global.Config.FeeConfirmationTarget, Global.Config.FeeEstimationMode);
+ if (estimateSmartFeeResponse == null) throw new NotSupportedException($"estimatesmartfee {Config.FeeConfirmationTarget} {Config.FeeEstimationMode} == null");
}
catch
{

MODIFY
HiddenWallet.ChaumianTumbler/TumblerStateMachine.cs
HiddenWallet.ChaumianTumbler/TumblerStateMachine.cs
@@ -293,11 +293,9 @@ namespace HiddenWallet.ChaumianTumbler
try
{
- RPCResponse result = (await Global.RpcClient.SendCommandAsync("estimatesmartfee", Global.Config.FeeConfirmationTarget, Global.Config.FeeEstimationMode));
- if (string.IsNullOrWhiteSpace(result?.ResultString)) throw new ArgumentException(nameof(result));
- var resultJToken = result.Result;
- var feeRateDecimal = resultJToken.Value<decimal>("feerate");
- var feeRate = new FeeRate(new Money(feeRateDecimal, MoneyUnit.BTC));
+ var estimateSmartFeeResponse = await Global.RpcClient.TryEstimateSmartFeeAsync((int)Global.Config.FeeConfirmationTarget, Global.Config.FeeEstimationMode);
+ if (estimateSmartFeeResponse == null) throw new InvalidOperationException("FeeRate is not yet initialized");
+ var feeRate = estimateSmartFeeResponse.FeeRate;
Money feePerBytes = (feeRate.FeePerK / 1000);
// make sure min relay fee (1000 sat) is hit

Replace manual estimatesmartfee with the newly implemented NBitcoin's estimatesmartee