2023-11-28 10:26:35 +01:00
|
|
|
#nullable enable
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
|
|
using NBitcoin;
|
|
|
|
|
|
|
|
namespace BTCPayServer.Services.Fees
|
|
|
|
{
|
2023-12-19 12:23:20 +09:00
|
|
|
public class FallbackFeeProvider : IFeeProvider
|
2023-11-28 10:26:35 +01:00
|
|
|
{
|
2023-12-19 12:23:20 +09:00
|
|
|
public FallbackFeeProvider(IFeeProvider[] providers)
|
|
|
|
{
|
|
|
|
Providers = providers;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IFeeProvider[] Providers { get; }
|
|
|
|
|
2023-11-28 10:26:35 +01:00
|
|
|
public async Task<FeeRate> GetFeeRateAsync(int blockTarget = 20)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < Providers.Length; i++)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return await Providers[i].GetFeeRateAsync(blockTarget);
|
|
|
|
}
|
|
|
|
catch when (i < Providers.Length - 1)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new NotSupportedException("No provider available");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|