mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-19 23:14:21 +01:00
LN Address - db schema fix method (#3638)
* LN Address - db schema fix method * pr changes * shorten
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Linq;
|
||||
using NBXplorer;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
@@ -7,20 +8,30 @@ namespace BTCPayServer.Data
|
||||
{
|
||||
public static APIKeyBlob GetBlob(this APIKeyData apiKeyData)
|
||||
{
|
||||
var result = apiKeyData.Blob == null
|
||||
? new APIKeyBlob()
|
||||
: JObject.Parse(ZipUtils.Unzip(apiKeyData.Blob)).ToObject<APIKeyBlob>();
|
||||
return result;
|
||||
return GetBlob<APIKeyBlob>(apiKeyData.Blob);
|
||||
}
|
||||
|
||||
public static bool SetBlob(this APIKeyData apiKeyData, APIKeyBlob blob)
|
||||
{
|
||||
var original = new Serializer(null).ToString(apiKeyData.GetBlob());
|
||||
var newBlob = new Serializer(null).ToString(blob);
|
||||
if (original == newBlob)
|
||||
var newBlob = SerializeBlob(blob);
|
||||
if (apiKeyData?.Blob?.SequenceEqual(newBlob) is true)
|
||||
return false;
|
||||
apiKeyData.Blob = ZipUtils.Zip(newBlob);
|
||||
apiKeyData.Blob = newBlob;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static T GetBlob<T>(this byte[] data)
|
||||
{
|
||||
var result = data == null
|
||||
? default
|
||||
: JObject.Parse(ZipUtils.Unzip(data)).ToObject<T>();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static byte[] SerializeBlob<T>(this T blob)
|
||||
{
|
||||
var newBlob = new Serializer(null).ToString(blob);
|
||||
return ZipUtils.Zip(newBlob);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user