2018-02-19 02:38:03 +09:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using BTCPayServer.Services.Invoices;
|
|
|
|
|
using NBitcoin;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
2018-02-19 11:06:08 +09:00
|
|
|
|
namespace BTCPayServer.Payments.Bitcoin
|
2018-02-19 02:38:03 +09:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public class BitcoinLikePaymentData : CryptoPaymentData
|
|
|
|
|
{
|
|
|
|
|
public PaymentTypes GetPaymentType()
|
|
|
|
|
{
|
|
|
|
|
return PaymentTypes.BTCLike;
|
|
|
|
|
}
|
|
|
|
|
public BitcoinLikePaymentData()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public BitcoinLikePaymentData(Coin coin, bool rbf)
|
|
|
|
|
{
|
|
|
|
|
Outpoint = coin.Outpoint;
|
|
|
|
|
Output = coin.TxOut;
|
|
|
|
|
ConfirmationCount = 0;
|
|
|
|
|
RBF = rbf;
|
|
|
|
|
}
|
|
|
|
|
[JsonIgnore]
|
|
|
|
|
public OutPoint Outpoint { get; set; }
|
|
|
|
|
[JsonIgnore]
|
|
|
|
|
public TxOut Output { get; set; }
|
|
|
|
|
public int ConfirmationCount { get; set; }
|
|
|
|
|
public bool RBF { get; set; }
|
2019-01-05 13:31:05 +09:00
|
|
|
|
public decimal NetworkFee { get; set; }
|
2018-02-19 02:38:03 +09:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// This is set to true if the payment was created before CryptoPaymentData existed in BTCPayServer
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool Legacy { get; set; }
|
|
|
|
|
|
|
|
|
|
public string GetPaymentId()
|
|
|
|
|
{
|
|
|
|
|
return Outpoint.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string[] GetSearchTerms()
|
|
|
|
|
{
|
|
|
|
|
return new[] { Outpoint.Hash.ToString() };
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-19 18:54:21 +09:00
|
|
|
|
public decimal GetValue()
|
2018-02-19 02:38:03 +09:00
|
|
|
|
{
|
2018-02-19 18:54:21 +09:00
|
|
|
|
return Output.Value.ToDecimal(MoneyUnit.BTC);
|
2018-02-19 02:38:03 +09:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-29 09:43:50 +00:00
|
|
|
|
public bool PaymentCompleted(PaymentEntity entity, BTCPayNetworkBase network)
|
2018-02-19 02:38:03 +09:00
|
|
|
|
{
|
|
|
|
|
return ConfirmationCount >= network.MaxTrackedConfirmation;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-29 09:43:50 +00:00
|
|
|
|
public bool PaymentConfirmed(PaymentEntity entity, SpeedPolicy speedPolicy, BTCPayNetworkBase network)
|
2018-02-19 02:38:03 +09:00
|
|
|
|
{
|
|
|
|
|
if (speedPolicy == SpeedPolicy.HighSpeed)
|
|
|
|
|
{
|
|
|
|
|
return ConfirmationCount >= 1 || !RBF;
|
|
|
|
|
}
|
|
|
|
|
else if (speedPolicy == SpeedPolicy.MediumSpeed)
|
|
|
|
|
{
|
|
|
|
|
return ConfirmationCount >= 1;
|
|
|
|
|
}
|
2018-05-11 22:12:45 +09:00
|
|
|
|
else if (speedPolicy == SpeedPolicy.LowMediumSpeed)
|
|
|
|
|
{
|
|
|
|
|
return ConfirmationCount >= 2;
|
|
|
|
|
}
|
2018-02-19 02:38:03 +09:00
|
|
|
|
else if (speedPolicy == SpeedPolicy.LowSpeed)
|
|
|
|
|
{
|
|
|
|
|
return ConfirmationCount >= 6;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-12-18 21:35:52 +09:00
|
|
|
|
|
2019-05-29 09:43:50 +00:00
|
|
|
|
public BitcoinAddress GetDestination(BTCPayNetworkBase network)
|
2018-12-18 21:35:52 +09:00
|
|
|
|
{
|
2019-05-29 09:43:50 +00:00
|
|
|
|
return Output.ScriptPubKey.GetDestinationAddress(((BTCPayNetwork)network).NBitcoinNetwork);
|
2018-12-18 21:35:52 +09:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-29 09:43:50 +00:00
|
|
|
|
string CryptoPaymentData.GetDestination(BTCPayNetworkBase network)
|
2018-12-18 21:35:52 +09:00
|
|
|
|
{
|
|
|
|
|
return GetDestination(network).ToString();
|
|
|
|
|
}
|
2018-02-19 02:38:03 +09:00
|
|
|
|
}
|
|
|
|
|
}
|