2017-10-06 10:37:38 +09:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
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
|
|
|
|
|
public ScriptId GetHash()
|
|
|
|
|
{
|
|
|
|
|
if (Address == null)
|
|
|
|
|
return null;
|
2018-02-17 13:18:16 +09:00
|
|
|
|
var index = Address.IndexOf("#", StringComparison.InvariantCulture);
|
2018-01-09 01:56:37 +09:00
|
|
|
|
if (index == -1)
|
|
|
|
|
return new ScriptId(Address);
|
|
|
|
|
return new ScriptId(Address.Substring(0, index));
|
|
|
|
|
}
|
2018-02-19 03:35:19 +09:00
|
|
|
|
public AddressInvoiceData SetHash(ScriptId scriptId, CryptoDataId cryptoDataId)
|
2018-01-09 01:56:37 +09:00
|
|
|
|
{
|
2018-02-19 03:35:19 +09:00
|
|
|
|
Address = scriptId + "#" + cryptoDataId?.ToString();
|
2018-01-09 01:56:37 +09:00
|
|
|
|
return this;
|
|
|
|
|
}
|
2018-02-19 03:35:19 +09:00
|
|
|
|
public CryptoDataId GetCryptoDataId()
|
2018-01-09 01:56:37 +09:00
|
|
|
|
{
|
|
|
|
|
if (Address == null)
|
|
|
|
|
return null;
|
2018-02-17 13:18:16 +09:00
|
|
|
|
var index = Address.IndexOf("#", StringComparison.InvariantCulture);
|
2018-01-09 01:56:37 +09:00
|
|
|
|
if (index == -1)
|
2018-02-19 03:35:19 +09:00
|
|
|
|
return CryptoDataId.Parse("BTC");
|
|
|
|
|
return CryptoDataId.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
|
|
|
|
}
|