2017-09-13 15:47:34 +09:00
|
|
|
|
using NBitcoin;
|
|
|
|
|
using NBXplorer;
|
|
|
|
|
using NBXplorer.Models;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2017-09-15 16:06:57 +09:00
|
|
|
|
namespace BTCPayServer.Services.Fees
|
2017-09-13 15:47:34 +09:00
|
|
|
|
{
|
2017-10-27 17:53:04 +09:00
|
|
|
|
public class NBXplorerFeeProvider : IFeeProvider
|
|
|
|
|
{
|
|
|
|
|
public ExplorerClient ExplorerClient
|
|
|
|
|
{
|
|
|
|
|
get; set;
|
|
|
|
|
}
|
|
|
|
|
public FeeRate Fallback
|
|
|
|
|
{
|
|
|
|
|
get; set;
|
|
|
|
|
}
|
|
|
|
|
public int BlockTarget
|
|
|
|
|
{
|
|
|
|
|
get; set;
|
|
|
|
|
}
|
|
|
|
|
public async Task<FeeRate> GetFeeRateAsync()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return (await ExplorerClient.GetFeeRateAsync(BlockTarget).ConfigureAwait(false)).FeeRate;
|
|
|
|
|
}
|
|
|
|
|
catch (NBXplorerException ex) when (ex.Error.HttpCode == 400 && ex.Error.Code == "fee-estimation-unavailable")
|
|
|
|
|
{
|
|
|
|
|
return Fallback;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-13 15:47:34 +09:00
|
|
|
|
}
|