From 30fb9e9b66eaa8cb0ab0bc1251aba5363b52dbda Mon Sep 17 00:00:00 2001 From: Jason Elie Bou Kheir <5115126+jasonboukheir@users.noreply.github.com> Date: Sun, 22 Oct 2023 21:27:29 -0700 Subject: [PATCH] feat(indexer): :sparkles: add `IndexerClientAsset` to store indexer info --- .../Clients/Indexer/IndexerClientAsset.cs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Runtime/Algorand.Unity/Clients/Indexer/IndexerClientAsset.cs b/Runtime/Algorand.Unity/Clients/Indexer/IndexerClientAsset.cs index 37d5acb9e..9ac1cd017 100644 --- a/Runtime/Algorand.Unity/Clients/Indexer/IndexerClientAsset.cs +++ b/Runtime/Algorand.Unity/Clients/Indexer/IndexerClientAsset.cs @@ -1,10 +1,40 @@ +using Cysharp.Threading.Tasks; using UnityEngine; namespace Algorand.Unity { + [HelpURL(DocUrl.Api + "Algorand.Unity.IndexerClientAsset.html")] [CreateAssetMenu(menuName = "Algorand/Indexer Client")] public class IndexerClientAsset : ScriptableObject { + public AlgorandNetwork network; + + [ContextMenuItem("Test Connection", nameof(TestConnection))] public IndexerClient client; + + private void TestConnection() + { + TestConnectionAsync().Forget(); + } + + private async UniTaskVoid TestConnectionAsync() + { + var (error, resultWrapped) = await client.MakeHealthCheck(); + var result = resultWrapped.WrappedValue; + + if (error) Debug.LogError(error); + else + { + Debug.Log($"Indexer connection healthy. Version: {result.Version}"); + if (result.Errors != null && result.Errors.Length > 0) + { + for (var i = 0; i < result.Errors.Length; i++) + { + Debug.LogWarning(result.Errors[i]); + } + Debug.LogWarning($"Got {result.Errors.Length} errors from the indexer."); + } + } + } } }