2018-02-20 04:45:04 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using BTCPayServer.Data;
|
|
|
|
|
using BTCPayServer.Services;
|
|
|
|
|
using BTCPayServer.Services.Invoices;
|
|
|
|
|
using BTCPayServer.Services.Rates;
|
|
|
|
|
using NBitcoin;
|
|
|
|
|
|
|
|
|
|
namespace BTCPayServer.Payments.Bitcoin
|
|
|
|
|
{
|
|
|
|
|
public class BitcoinLikePaymentHandler : PaymentMethodHandlerBase<DerivationStrategy>
|
|
|
|
|
{
|
|
|
|
|
ExplorerClientProvider _ExplorerProvider;
|
|
|
|
|
private IFeeProviderFactory _FeeRateProviderFactory;
|
|
|
|
|
private Services.Wallets.BTCPayWalletProvider _WalletProvider;
|
|
|
|
|
|
|
|
|
|
public BitcoinLikePaymentHandler(ExplorerClientProvider provider,
|
|
|
|
|
IFeeProviderFactory feeRateProviderFactory,
|
|
|
|
|
Services.Wallets.BTCPayWalletProvider walletProvider)
|
|
|
|
|
{
|
|
|
|
|
if (provider == null)
|
|
|
|
|
throw new ArgumentNullException(nameof(provider));
|
|
|
|
|
_ExplorerProvider = provider;
|
|
|
|
|
this._FeeRateProviderFactory = feeRateProviderFactory;
|
|
|
|
|
_WalletProvider = walletProvider;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override async Task<IPaymentMethodDetails> CreatePaymentMethodDetails(DerivationStrategy supportedPaymentMethod, PaymentMethod paymentMethod, BTCPayNetwork network)
|
|
|
|
|
{
|
|
|
|
|
var getFeeRate = _FeeRateProviderFactory.CreateFeeProvider(network).GetFeeRateAsync();
|
|
|
|
|
var getAddress = _WalletProvider.GetWallet(network).ReserveAddressAsync(supportedPaymentMethod.DerivationStrategyBase);
|
|
|
|
|
Payments.Bitcoin.BitcoinLikeOnChainPaymentMethod onchainMethod = new Payments.Bitcoin.BitcoinLikeOnChainPaymentMethod();
|
|
|
|
|
onchainMethod.FeeRate = await getFeeRate;
|
|
|
|
|
onchainMethod.TxFee = onchainMethod.FeeRate.GetFee(100); // assume price for 100 bytes
|
2018-03-13 07:28:39 +01:00
|
|
|
|
onchainMethod.DepositAddress = (await getAddress).ToString();
|
2018-02-20 04:45:04 +01:00
|
|
|
|
return onchainMethod;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-23 08:09:15 +01:00
|
|
|
|
public override Task<bool> IsAvailable(DerivationStrategy supportedPaymentMethod, BTCPayNetwork network)
|
2018-02-20 04:45:04 +01:00
|
|
|
|
{
|
2018-02-23 08:09:15 +01:00
|
|
|
|
return Task.FromResult(_ExplorerProvider.IsAvailable(network));
|
2018-02-20 04:45:04 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|