2018-02-19 11:06:08 +09:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using BTCPayServer.Services.Invoices;
|
|
|
|
|
using NBitcoin;
|
2019-11-07 13:45:45 +09:00
|
|
|
|
using NBXplorer.JsonConverters;
|
2018-02-19 11:06:08 +09:00
|
|
|
|
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
|
|
|
|
{
|
2019-01-07 15:35:18 +09:00
|
|
|
|
return NextNetworkFee.ToDecimal(MoneyUnit.BTC);
|
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()
|
|
|
|
|
{
|
2019-10-07 21:06:12 -07:00
|
|
|
|
return FeeRate.SatoshiPerByte;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-19 11:06:08 +09:00
|
|
|
|
public void SetPaymentDestination(string newPaymentDestination)
|
|
|
|
|
{
|
2018-03-13 15:28:39 +09:00
|
|
|
|
DepositAddress = newPaymentDestination;
|
2018-02-19 11:06:08 +09:00
|
|
|
|
}
|
2019-01-05 00:37:09 +09:00
|
|
|
|
public Data.NetworkFeeMode NetworkFeeMode { get; set; }
|
2018-02-19 11:06:08 +09:00
|
|
|
|
|
2019-11-07 13:45:45 +09:00
|
|
|
|
FeeRate _NetworkFeeRate;
|
|
|
|
|
[JsonConverter(typeof(FeeRateJsonConverter))]
|
|
|
|
|
public FeeRate NetworkFeeRate
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
// Some old invoices don't have this field set, so we fallback on FeeRate
|
|
|
|
|
return _NetworkFeeRate ?? FeeRate;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_NetworkFeeRate = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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]
|
2018-03-13 15:28:39 +09:00
|
|
|
|
public String DepositAddress { get; set; }
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|