mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-01-18 13:26:47 +01:00
Cleanse objects from obsolete altcoins
This commit is contained in:
parent
b6062a94b9
commit
13e3b515c9
@ -33,12 +33,14 @@ using Microsoft.Extensions.Options;
|
||||
using NBitcoin;
|
||||
using NBitcoin.DataEncoders;
|
||||
using NBitcoin.Scripting.Parser;
|
||||
using NBXplorer;
|
||||
using NBXplorer.DerivationStrategy;
|
||||
using NBXplorer.Models;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
using StoreData = BTCPayServer.Data.StoreData;
|
||||
|
||||
namespace BTCPayServer.Tests
|
||||
{
|
||||
@ -1808,5 +1810,32 @@ namespace BTCPayServer.Tests
|
||||
}
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void PaymentMethodIdConverterIsGraceful()
|
||||
{
|
||||
var pmi = "\"BTC_hasjdfhasjkfjlajn\"";
|
||||
JsonTextReader reader = new(new StringReader(pmi));
|
||||
reader.Read();
|
||||
Assert.Null(new PaymentMethodIdJsonConverter().ReadJson(reader, typeof(PaymentMethodId), null,
|
||||
JsonSerializer.CreateDefault()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanBeBracefulAfterObsoleteShitcoin()
|
||||
{
|
||||
var blob = new StoreBlob();
|
||||
blob.PaymentMethodCriteria = new List<PaymentMethodCriteria>()
|
||||
{
|
||||
new()
|
||||
{
|
||||
Above = true,
|
||||
Value = new CurrencyValue() {Currency = "BTC", Value = 0.1m},
|
||||
PaymentMethod = new PaymentMethodId("BTC", PaymentTypes.BTCLike)
|
||||
}
|
||||
};
|
||||
var newBlob = Encoding.UTF8.GetBytes(
|
||||
new Serializer(null).ToString(blob).Replace( "paymentMethod\":\"BTC\"","paymentMethod\":\"ETH_ZYC\""));
|
||||
Assert.Empty(StoreDataExtensions.GetStoreBlob(new StoreData() {StoreBlob = newBlob}).PaymentMethodCriteria);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,9 @@ namespace BTCPayServer.Data
|
||||
|
||||
public static PullPaymentBlob GetBlob(this PullPaymentData data)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<PullPaymentBlob>(Encoding.UTF8.GetString(data.Blob));
|
||||
var result = JsonConvert.DeserializeObject<PullPaymentBlob>(Encoding.UTF8.GetString(data.Blob));
|
||||
result!.SupportedPaymentMethods = result.SupportedPaymentMethods.Where(id => id is not null).ToArray();
|
||||
return result;
|
||||
}
|
||||
public static void SetBlob(this PullPaymentData data, PullPaymentBlob blob)
|
||||
{
|
||||
|
@ -50,6 +50,7 @@ namespace BTCPayServer.Data
|
||||
var result = storeData.StoreBlob == null ? new StoreBlob() : new Serializer(null).ToObject<StoreBlob>(Encoding.UTF8.GetString(storeData.StoreBlob));
|
||||
if (result.PreferredExchange == null)
|
||||
result.PreferredExchange = CoinGeckoRateProvider.CoinGeckoName;
|
||||
result.PaymentMethodCriteria.RemoveAll(criteria => criteria.PaymentMethod is null);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,9 @@ namespace BTCPayServer.JsonConverters
|
||||
throw new JsonObjectException("A payment method id should be a string", reader);
|
||||
if (PaymentMethodId.TryParse((string)reader.Value, out var result))
|
||||
return result;
|
||||
throw new JsonObjectException("Invalid payment method id", reader);
|
||||
return null;
|
||||
// We need to do this gracefully as we have removed support for a payment type in the past which will throw here on your store each time it is loaded.
|
||||
// throw new JsonObjectException($"Invalid payment method id ({(string)reader.Value})", reader);
|
||||
}
|
||||
public override void WriteJson(JsonWriter writer, PaymentMethodId value, JsonSerializer serializer)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user