2017-09-15 16:06:57 +09:00
|
|
|
|
using BTCPayServer.Models;
|
2017-10-20 14:06:37 -05:00
|
|
|
|
using BTCPayServer.Services.Invoices;
|
2017-10-23 19:27:22 +09:00
|
|
|
|
using NBitcoin;
|
|
|
|
|
using NBXplorer;
|
2017-09-13 15:47:34 +09:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2017-09-13 23:50:36 +09:00
|
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
2017-09-13 15:47:34 +09:00
|
|
|
|
using System.Linq;
|
2017-10-23 19:27:22 +09:00
|
|
|
|
using System.Text;
|
2017-09-13 15:47:34 +09:00
|
|
|
|
using System.Threading.Tasks;
|
2017-12-03 14:43:52 +09:00
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using Newtonsoft.Json;
|
2018-01-06 18:57:56 +09:00
|
|
|
|
using Newtonsoft.Json.Linq;
|
2017-09-13 15:47:34 +09:00
|
|
|
|
|
|
|
|
|
namespace BTCPayServer.Data
|
|
|
|
|
{
|
|
|
|
|
public class StoreData
|
|
|
|
|
{
|
2017-10-27 17:53:04 +09:00
|
|
|
|
public string Id
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
2017-09-13 15:47:34 +09:00
|
|
|
|
|
2017-10-27 17:53:04 +09:00
|
|
|
|
public List<UserStore> UserStores
|
|
|
|
|
{
|
|
|
|
|
get; set;
|
|
|
|
|
}
|
2017-09-13 15:47:34 +09:00
|
|
|
|
|
2018-01-06 18:57:56 +09:00
|
|
|
|
[Obsolete("Use GetDerivationStrategies instead")]
|
2017-10-27 17:53:04 +09:00
|
|
|
|
public string DerivationStrategy
|
|
|
|
|
{
|
|
|
|
|
get; set;
|
|
|
|
|
}
|
2017-09-13 15:47:34 +09:00
|
|
|
|
|
2018-01-06 18:57:56 +09:00
|
|
|
|
[Obsolete("Use GetDerivationStrategies instead")]
|
|
|
|
|
public string DerivationStrategies
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<DerivationStrategy> GetDerivationStrategies(BTCPayNetworkProvider networks)
|
|
|
|
|
{
|
|
|
|
|
#pragma warning disable CS0618
|
|
|
|
|
bool btcReturned = false;
|
|
|
|
|
if (!string.IsNullOrEmpty(DerivationStrategy))
|
|
|
|
|
{
|
|
|
|
|
if (networks.BTC != null)
|
|
|
|
|
{
|
|
|
|
|
btcReturned = true;
|
|
|
|
|
yield return BTCPayServer.DerivationStrategy.Parse(DerivationStrategy, networks.BTC);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(DerivationStrategies))
|
|
|
|
|
{
|
|
|
|
|
JObject strategies = JObject.Parse(DerivationStrategies);
|
|
|
|
|
foreach (var strat in strategies.Properties())
|
|
|
|
|
{
|
|
|
|
|
var network = networks.GetNetwork(strat.Name);
|
|
|
|
|
if (network != null)
|
|
|
|
|
{
|
|
|
|
|
if (network == networks.BTC && btcReturned)
|
|
|
|
|
continue;
|
|
|
|
|
yield return BTCPayServer.DerivationStrategy.Parse(strat.Value<string>(), network);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#pragma warning restore CS0618
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-27 17:53:04 +09:00
|
|
|
|
public string StoreName
|
|
|
|
|
{
|
|
|
|
|
get; set;
|
|
|
|
|
}
|
2017-09-13 15:47:34 +09:00
|
|
|
|
|
2017-10-27 17:53:04 +09:00
|
|
|
|
public SpeedPolicy SpeedPolicy
|
|
|
|
|
{
|
|
|
|
|
get; set;
|
|
|
|
|
}
|
2017-09-13 15:47:34 +09:00
|
|
|
|
|
2017-10-27 17:53:04 +09:00
|
|
|
|
public string StoreWebsite
|
|
|
|
|
{
|
|
|
|
|
get; set;
|
|
|
|
|
}
|
2017-09-13 15:47:34 +09:00
|
|
|
|
|
2017-10-27 17:53:04 +09:00
|
|
|
|
public byte[] StoreCertificate
|
|
|
|
|
{
|
|
|
|
|
get; set;
|
|
|
|
|
}
|
2017-09-13 23:50:36 +09:00
|
|
|
|
|
2017-10-27 17:53:04 +09:00
|
|
|
|
[NotMapped]
|
|
|
|
|
public string Role
|
|
|
|
|
{
|
|
|
|
|
get; set;
|
|
|
|
|
}
|
|
|
|
|
public byte[] StoreBlob
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
2017-10-23 19:27:22 +09:00
|
|
|
|
|
2017-12-21 15:52:04 +09:00
|
|
|
|
static Network Dummy = Network.Main;
|
|
|
|
|
|
|
|
|
|
public StoreBlob GetStoreBlob()
|
2017-10-27 17:53:04 +09:00
|
|
|
|
{
|
2017-12-21 15:52:04 +09:00
|
|
|
|
return StoreBlob == null ? new StoreBlob() : new Serializer(Dummy).ToObject<StoreBlob>(Encoding.UTF8.GetString(StoreBlob));
|
2017-10-27 17:53:04 +09:00
|
|
|
|
}
|
2017-10-23 19:27:22 +09:00
|
|
|
|
|
2017-12-21 15:52:04 +09:00
|
|
|
|
public bool SetStoreBlob(StoreBlob storeBlob)
|
2017-10-27 17:53:04 +09:00
|
|
|
|
{
|
2017-12-21 15:52:04 +09:00
|
|
|
|
var original = new Serializer(Dummy).ToString(GetStoreBlob());
|
|
|
|
|
var newBlob = new Serializer(Dummy).ToString(storeBlob);
|
2017-12-03 14:43:52 +09:00
|
|
|
|
if (original == newBlob)
|
|
|
|
|
return false;
|
|
|
|
|
StoreBlob = Encoding.UTF8.GetBytes(newBlob);
|
|
|
|
|
return true;
|
2017-10-27 17:53:04 +09:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-10-23 19:27:22 +09:00
|
|
|
|
|
2017-10-27 17:53:04 +09:00
|
|
|
|
public class StoreBlob
|
|
|
|
|
{
|
2017-12-03 14:43:52 +09:00
|
|
|
|
public StoreBlob()
|
|
|
|
|
{
|
|
|
|
|
MonitoringExpiration = 60;
|
|
|
|
|
}
|
2017-10-27 17:53:04 +09:00
|
|
|
|
public bool NetworkFeeDisabled
|
|
|
|
|
{
|
|
|
|
|
get; set;
|
|
|
|
|
}
|
2017-12-03 14:43:52 +09:00
|
|
|
|
[DefaultValue(60)]
|
|
|
|
|
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
|
|
|
|
|
public int MonitoringExpiration
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
2017-10-27 17:53:04 +09:00
|
|
|
|
}
|
2017-09-13 15:47:34 +09:00
|
|
|
|
}
|