2020-06-28 21:44:35 -05:00
|
|
|
using System;
|
2020-08-09 16:00:58 +02:00
|
|
|
using System.Linq;
|
2020-05-23 21:13:18 +02:00
|
|
|
using BTCPayServer.Client.Models;
|
2018-02-19 11:06:08 +09:00
|
|
|
using NBitcoin;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
|
|
namespace BTCPayServer.Payments.Bitcoin
|
|
|
|
{
|
2018-02-19 15:09:05 +09:00
|
|
|
public class BitcoinLikeOnChainPaymentMethod : IPaymentMethodDetails
|
2018-02-19 11:06:08 +09:00
|
|
|
{
|
2019-06-04 08:59:01 +09:00
|
|
|
public PaymentType GetPaymentType() => PaymentTypes.BTCLike;
|
2018-02-19 11:06:08 +09:00
|
|
|
|
|
|
|
public string GetPaymentDestination()
|
|
|
|
{
|
2018-03-13 15:28:39 +09:00
|
|
|
return DepositAddress;
|
2018-02-19 11:06:08 +09:00
|
|
|
}
|
|
|
|
|
2019-01-07 15:35:18 +09:00
|
|
|
public decimal GetNextNetworkFee()
|
2018-02-19 11:06:08 +09:00
|
|
|
{
|
2021-03-01 09:56:57 -06:00
|
|
|
// NextNetworkFee is sometimes not initialized properly, so we return 0 in that case
|
|
|
|
return NextNetworkFee?.ToDecimal(MoneyUnit.BTC) ?? 0;
|
2018-02-19 11:06:08 +09:00
|
|
|
}
|
2019-10-07 21:06:12 -07:00
|
|
|
|
2019-11-07 13:45:45 +09:00
|
|
|
public decimal GetFeeRate()
|
|
|
|
{
|
2021-04-07 06:08:42 +02:00
|
|
|
return FeeRate?.SatoshiPerByte ?? 0;
|
2019-10-07 21:06:12 -07:00
|
|
|
}
|
|
|
|
|
2020-08-09 16:00:58 +02:00
|
|
|
public void SetPaymentDetails(IPaymentMethodDetails newPaymentMethodDetails)
|
2018-02-19 11:06:08 +09:00
|
|
|
{
|
2020-08-09 16:00:58 +02:00
|
|
|
DepositAddress = newPaymentMethodDetails.GetPaymentDestination();
|
|
|
|
KeyPath = (newPaymentMethodDetails as BitcoinLikeOnChainPaymentMethod)?.KeyPath;
|
2018-02-19 11:06:08 +09:00
|
|
|
}
|
2021-04-07 06:08:42 +02:00
|
|
|
public bool Activated { get; set; } = true;
|
2020-05-23 21:13:18 +02:00
|
|
|
public NetworkFeeMode NetworkFeeMode { get; set; }
|
2018-02-19 11:06:08 +09:00
|
|
|
|
2019-11-07 13:45:45 +09:00
|
|
|
FeeRate _NetworkFeeRate;
|
2020-05-05 07:06:32 +09:00
|
|
|
[JsonConverter(typeof(NBitcoin.JsonConverters.FeeRateJsonConverter))]
|
2019-11-07 13:45:45 +09:00
|
|
|
public FeeRate NetworkFeeRate
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
// Some old invoices don't have this field set, so we fallback on FeeRate
|
|
|
|
return _NetworkFeeRate ?? FeeRate;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
_NetworkFeeRate = value;
|
|
|
|
}
|
|
|
|
}
|
2020-03-30 00:28:22 +09:00
|
|
|
public bool PayjoinEnabled { get; set; }
|
2018-02-19 11:31:34 +09:00
|
|
|
// Those properties are JsonIgnore because their data is inside CryptoData class for legacy reason
|
2018-02-19 11:06:08 +09:00
|
|
|
[JsonIgnore]
|
|
|
|
public FeeRate FeeRate { get; set; }
|
|
|
|
[JsonIgnore]
|
2019-01-07 15:35:18 +09:00
|
|
|
public Money NextNetworkFee { get; set; }
|
2018-02-19 11:06:08 +09:00
|
|
|
[JsonIgnore]
|
2021-12-31 16:59:02 +09:00
|
|
|
public String DepositAddress { get; set; }
|
2020-08-09 16:00:58 +02:00
|
|
|
[JsonConverter(typeof(NBitcoin.JsonConverters.KeyPathJsonConverter))]
|
|
|
|
public KeyPath KeyPath { get; set; }
|
2020-01-06 13:57:32 +01:00
|
|
|
|
2018-03-13 15:28:39 +09:00
|
|
|
public BitcoinAddress GetDepositAddress(Network network)
|
|
|
|
{
|
|
|
|
return string.IsNullOrEmpty(DepositAddress) ? null : BitcoinAddress.Create(DepositAddress, network);
|
|
|
|
}
|
2018-02-19 11:31:34 +09:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////
|
2018-02-19 11:06:08 +09:00
|
|
|
}
|
|
|
|
}
|