btcpayserver/BTCPayServer/Data/StoreData.cs

142 lines
3.5 KiB
C#
Raw Normal View History

using BTCPayServer.Models;
2017-10-20 14:06:37 -05:00
using BTCPayServer.Services.Invoices;
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;
using System.Text;
2017-09-13 15:47:34 +09:00
using System.Threading.Tasks;
using System.ComponentModel;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
2017-09-13 15:47:34 +09:00
namespace BTCPayServer.Data
{
public class StoreData
{
public string Id
{
get;
set;
}
2017-09-13 15:47:34 +09:00
public List<UserStore> UserStores
{
get; set;
}
2017-09-13 15:47:34 +09:00
[Obsolete("Use GetDerivationStrategies instead")]
public string DerivationStrategy
{
get; set;
}
2017-09-13 15:47:34 +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
}
public string StoreName
{
get; set;
}
2017-09-13 15:47:34 +09:00
public SpeedPolicy SpeedPolicy
{
get; set;
}
2017-09-13 15:47:34 +09:00
public string StoreWebsite
{
get; set;
}
2017-09-13 15:47:34 +09:00
public byte[] StoreCertificate
{
get; set;
}
2017-09-13 23:50:36 +09:00
[NotMapped]
public string Role
{
get; set;
}
public byte[] StoreBlob
{
get;
set;
}
static Network Dummy = Network.Main;
public StoreBlob GetStoreBlob()
{
return StoreBlob == null ? new StoreBlob() : new Serializer(Dummy).ToObject<StoreBlob>(Encoding.UTF8.GetString(StoreBlob));
}
public bool SetStoreBlob(StoreBlob storeBlob)
{
var original = new Serializer(Dummy).ToString(GetStoreBlob());
var newBlob = new Serializer(Dummy).ToString(storeBlob);
if (original == newBlob)
return false;
StoreBlob = Encoding.UTF8.GetBytes(newBlob);
return true;
}
}
public class StoreBlob
{
public StoreBlob()
{
MonitoringExpiration = 60;
}
public bool NetworkFeeDisabled
{
get; set;
}
[DefaultValue(60)]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
public int MonitoringExpiration
{
get;
set;
}
}
2017-09-13 15:47:34 +09:00
}