2017-10-06 10:37:38 +09:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2018-02-19 23:13:23 +09:00
|
|
|
|
using BTCPayServer.Payments;
|
2018-02-19 03:35:19 +09:00
|
|
|
|
using BTCPayServer.Services.Invoices;
|
2018-01-09 01:56:37 +09:00
|
|
|
|
using NBitcoin;
|
2017-10-06 10:37:38 +09:00
|
|
|
|
|
|
|
|
|
namespace BTCPayServer.Data
|
|
|
|
|
{
|
2017-10-27 17:53:04 +09:00
|
|
|
|
public class AddressInvoiceData
|
|
|
|
|
{
|
2018-01-09 01:56:37 +09:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Some crypto currencies share same address prefix
|
|
|
|
|
/// For not having exceptions thrown by two address on different network, we suffix by "#CRYPTOCODE"
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Obsolete("Use GetHash instead")]
|
2017-10-27 17:53:04 +09:00
|
|
|
|
public string Address
|
|
|
|
|
{
|
|
|
|
|
get; set;
|
|
|
|
|
}
|
2017-10-06 10:37:38 +09:00
|
|
|
|
|
2018-01-09 01:56:37 +09:00
|
|
|
|
|
|
|
|
|
#pragma warning disable CS0618
|
2018-02-19 11:31:34 +09:00
|
|
|
|
public string GetAddress()
|
2018-01-09 01:56:37 +09:00
|
|
|
|
{
|
|
|
|
|
if (Address == null)
|
|
|
|
|
return null;
|
2018-02-19 11:31:34 +09:00
|
|
|
|
var index = Address.LastIndexOf("#", StringComparison.InvariantCulture);
|
2018-01-09 01:56:37 +09:00
|
|
|
|
if (index == -1)
|
2018-02-19 11:31:34 +09:00
|
|
|
|
return Address;
|
|
|
|
|
return Address.Substring(0, index);
|
2018-01-09 01:56:37 +09:00
|
|
|
|
}
|
2018-02-19 15:09:05 +09:00
|
|
|
|
public AddressInvoiceData Set(string address, PaymentMethodId paymentMethodId)
|
2018-01-09 01:56:37 +09:00
|
|
|
|
{
|
2018-03-14 19:32:24 +09:00
|
|
|
|
Address = address + "#" + paymentMethodId.ToString();
|
2018-01-09 01:56:37 +09:00
|
|
|
|
return this;
|
|
|
|
|
}
|
2018-02-19 15:09:05 +09:00
|
|
|
|
public PaymentMethodId GetpaymentMethodId()
|
2018-01-09 01:56:37 +09:00
|
|
|
|
{
|
|
|
|
|
if (Address == null)
|
|
|
|
|
return null;
|
2018-02-19 11:31:34 +09:00
|
|
|
|
var index = Address.LastIndexOf("#", StringComparison.InvariantCulture);
|
2018-02-19 15:09:05 +09:00
|
|
|
|
// Legacy AddressInvoiceData does not have the paymentMethodId attached to the Address
|
2018-01-09 01:56:37 +09:00
|
|
|
|
if (index == -1)
|
2018-02-19 15:09:05 +09:00
|
|
|
|
return PaymentMethodId.Parse("BTC");
|
2018-02-19 11:31:34 +09:00
|
|
|
|
/////////////////////////
|
2018-02-19 15:09:05 +09:00
|
|
|
|
return PaymentMethodId.Parse(Address.Substring(index + 1));
|
2018-01-09 01:56:37 +09:00
|
|
|
|
}
|
|
|
|
|
#pragma warning restore CS0618
|
|
|
|
|
|
2017-10-27 17:53:04 +09:00
|
|
|
|
public InvoiceData InvoiceData
|
|
|
|
|
{
|
|
|
|
|
get; set;
|
|
|
|
|
}
|
2017-10-06 10:37:38 +09:00
|
|
|
|
|
2017-10-27 17:53:04 +09:00
|
|
|
|
public string InvoiceDataId
|
|
|
|
|
{
|
|
|
|
|
get; set;
|
|
|
|
|
}
|
2017-10-25 01:41:01 +09:00
|
|
|
|
|
2017-10-27 17:53:04 +09:00
|
|
|
|
public DateTimeOffset? CreatedTime
|
|
|
|
|
{
|
|
|
|
|
get; set;
|
|
|
|
|
}
|
2018-01-09 01:56:37 +09:00
|
|
|
|
|
2017-10-27 17:53:04 +09:00
|
|
|
|
}
|
2017-10-06 10:37:38 +09:00
|
|
|
|
}
|