mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-19 06:54:19 +01:00
GreenField: Switch to Blob for API Keys
This commit is contained in:
26
BTCPayServer/Data/APIKeyDataExtensions.cs
Normal file
26
BTCPayServer/Data/APIKeyDataExtensions.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using NBXplorer;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace BTCPayServer.Data
|
||||
{
|
||||
public static class APIKeyDataExtensions
|
||||
{
|
||||
public static APIKeyBlob GetBlob(this APIKeyData apiKeyData)
|
||||
{
|
||||
var result = apiKeyData.Blob == null
|
||||
? new APIKeyBlob()
|
||||
: JObject.Parse(ZipUtils.Unzip(apiKeyData.Blob)).ToObject<APIKeyBlob>();
|
||||
return result;
|
||||
}
|
||||
|
||||
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)
|
||||
return false;
|
||||
apiKeyData.Blob = ZipUtils.Zip(newBlob);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user