Skip to content

Commit

Permalink
Optimise Verifier
Browse files Browse the repository at this point in the history
  • Loading branch information
skibitsky committed May 9, 2024
1 parent 6525e6a commit b2ae9e4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
31 changes: 17 additions & 14 deletions WalletConnectSharp.Core/Models/Verify/Verifier.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
using System.Net;
using Newtonsoft.Json;
using WalletConnectSharp.Common.Utils;
using Newtonsoft.Json;
using WalletConnectSharp.Common.Logging;

namespace WalletConnectSharp.Core.Models.Verify;

public class Verifier
public sealed class Verifier : IDisposable
{
public const string VerifyServer = "https://verify.walletconnect.com";

public CancellationTokenSource CancellationTokenSource { get; }
private const string VerifyServer = "https://verify.walletconnect.com";

public Verifier()
private readonly HttpClient _client = new()
{
this.CancellationTokenSource = new CancellationTokenSource(Clock.AsTimeSpan(Clock.FIVE_SECONDS));
}
Timeout = TimeSpan.FromSeconds(5)
};

public async Task<string> Resolve(string attestationId)
{
try
{
using HttpClient client = new HttpClient();
var url = $"{VerifyServer}/attestation/{attestationId}";
var results = await client.GetStringAsync(url);
WCLogger.Log($"[Verifier] Resolving attestation {attestationId} from {url}");
var results = await _client.GetStringAsync(url);
WCLogger.Log($"[Verifier] Resolved attestation. Results: {results}");

var verifiedContext = JsonConvert.DeserializeObject<VerifiedContext>(results);

return verifiedContext != null ? verifiedContext.Origin : "";
return verifiedContext != null ? verifiedContext.Origin : string.Empty;
}
catch
{
return "";
return string.Empty;
}
}

public void Dispose()
{
_client?.Dispose();
}
}
1 change: 1 addition & 0 deletions WalletConnectSharp.Core/WalletConnectCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ protected virtual void Dispose(bool disposing)
MessageHandler?.Dispose();
Expirer?.Dispose();
Pairing?.Dispose();
Verify?.Dispose();
}

Disposed = true;
Expand Down

0 comments on commit b2ae9e4

Please sign in to comment.