diff --git a/Assets/SequenceSDK/Editor/SequencePlatformCompileTest.cs b/Assets/SequenceSDK/Editor/SequencePlatformCompileTest.cs index 472df1403..f48b20fa0 100644 --- a/Assets/SequenceSDK/Editor/SequencePlatformCompileTest.cs +++ b/Assets/SequenceSDK/Editor/SequencePlatformCompileTest.cs @@ -140,43 +140,43 @@ private static void LogErrorsToFile(BuildReport report, BuildTarget target) private static void AndroidBuildTest(string path, string[] scenes) { - SequenceConfig config = SequenceConfig.GetConfig(SequenceService.None); - bool isSecureStorageEnabled = config.StoreSessionPrivateKeyInSecureStorage; + SequenceConfigBase configBase = SequenceConfig.GetConfig(SequenceService.None); + bool isSecureStorageEnabled = configBase.StoreSessionPrivateKeyInSecureStorage; BuildTarget target = BuildTarget.Android; try { BuildToPlatformAndCheckForSuccess(target, path, scenes); - AssertPluginCompatibility(config, target); - AssertAppropriateScriptingDefines(config, target); + AssertPluginCompatibility(configBase, target); + AssertAppropriateScriptingDefines(configBase, target); - config.StoreSessionPrivateKeyInSecureStorage = !config.StoreSessionPrivateKeyInSecureStorage; + configBase.StoreSessionPrivateKeyInSecureStorage = !configBase.StoreSessionPrivateKeyInSecureStorage; BuildToPlatformAndCheckForSuccess(target, path, scenes); - AssertPluginCompatibility(config, target); - AssertAppropriateScriptingDefines(config, target); + AssertPluginCompatibility(configBase, target); + AssertAppropriateScriptingDefines(configBase, target); } finally { - config.StoreSessionPrivateKeyInSecureStorage = isSecureStorageEnabled; + configBase.StoreSessionPrivateKeyInSecureStorage = isSecureStorageEnabled; CleanupBuildDirectory(); } } - private static void AssertPluginCompatibility(SequenceConfig config, BuildTarget target) + private static void AssertPluginCompatibility(SequenceConfigBase configBase, BuildTarget target) { PluginImporter pluginImporter = AssetImporter.GetAtPath(AndroidDependencyManager.SecureStoragePluginPath) as PluginImporter; Assert.IsNotNull(pluginImporter, "Plugin not found at path: " + AndroidDependencyManager.SecureStoragePluginPath); - Assert.AreEqual(config.StoreSessionPrivateKeyInSecureStorage, pluginImporter.GetCompatibleWithPlatform(target)); + Assert.AreEqual(configBase.StoreSessionPrivateKeyInSecureStorage, pluginImporter.GetCompatibleWithPlatform(target)); } - private static void AssertAppropriateScriptingDefines(SequenceConfig config, BuildTarget target) + private static void AssertAppropriateScriptingDefines(SequenceConfigBase configBase, BuildTarget target) { string defines = PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(BuildPipeline.GetBuildTargetGroup(target))); - Assert.AreEqual(config.StoreSessionPrivateKeyInSecureStorage, defines.Contains(AndroidScriptDefineSetup.EnableAndroidSecureStorage)); + Assert.AreEqual(configBase.StoreSessionPrivateKeyInSecureStorage, defines.Contains(AndroidScriptDefineSetup.EnableAndroidSecureStorage)); } } } \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/Tests/IntentSenderTests.cs b/Assets/SequenceSDK/WaaS/Tests/IntentSenderTests.cs index ccb6d58c4..e531db9e3 100644 --- a/Assets/SequenceSDK/WaaS/Tests/IntentSenderTests.cs +++ b/Assets/SequenceSDK/WaaS/Tests/IntentSenderTests.cs @@ -137,9 +137,9 @@ public async Task TestGetTransactionReceipt_noWallet() [TestCase(1000)] // intent will have been issued in the future public async Task TestTimeMismatchExceptionResultsInRetry(int timeOffset) { - SequenceConfig config = SequenceConfig.GetConfig(SequenceService.WaaS); + SequenceConfigBase configBase = SequenceConfig.GetConfig(SequenceService.WaaS); ConfigJwt configJwt = SequenceConfig.GetConfigJwt(); - IntentSender intentSender = new IntentSender(new HttpClient($"{configJwt.rpcServer.AppendTrailingSlashIfNeeded()}rpc/WaasAuthenticator"), new EOAWallet(), "", configJwt.projectId, config.WaaSVersion); + IntentSender intentSender = new IntentSender(new HttpClient($"{configJwt.rpcServer.AppendTrailingSlashIfNeeded()}rpc/WaasAuthenticator"), new EOAWallet(), "", configJwt.projectId, configBase.WaaSVersion); LogAssert.Expect(LogType.Warning, new Regex("Time mismatch*")); try { diff --git a/Packages/Sequence-Unity/Editor/AndroidCustomGradleCheck.cs b/Packages/Sequence-Unity/Editor/AndroidCustomGradleCheck.cs index d1952214b..f8dcb8354 100644 --- a/Packages/Sequence-Unity/Editor/AndroidCustomGradleCheck.cs +++ b/Packages/Sequence-Unity/Editor/AndroidCustomGradleCheck.cs @@ -21,8 +21,8 @@ public void OnPreprocessBuild(BuildReport report) { if (report.summary.platform == BuildTarget.Android) { - SequenceConfig config = SequenceConfig.GetConfig(SequenceService.None); - if (!config.StoreSessionPrivateKeyInSecureStorage) + SequenceConfigBase configBase = SequenceConfig.GetConfig(SequenceService.None); + if (!configBase.StoreSessionPrivateKeyInSecureStorage) { return; } diff --git a/Packages/Sequence-Unity/Editor/AndroidScriptDefineSetup.cs b/Packages/Sequence-Unity/Editor/AndroidScriptDefineSetup.cs index 4a5ff8195..35fd5532b 100644 --- a/Packages/Sequence-Unity/Editor/AndroidScriptDefineSetup.cs +++ b/Packages/Sequence-Unity/Editor/AndroidScriptDefineSetup.cs @@ -34,8 +34,8 @@ public void OnPreprocessBuild(BuildReport report) defineList = new List(defines.Split(';')); } - SequenceConfig config = SequenceConfig.GetConfig(SequenceService.None); - if (config.StoreSessionPrivateKeyInSecureStorage) + SequenceConfigBase configBase = SequenceConfig.GetConfig(SequenceService.None); + if (configBase.StoreSessionPrivateKeyInSecureStorage) { if (!defineList.Contains(EnableAndroidSecureStorage)) { diff --git a/Packages/Sequence-Unity/Editor/CheckUrlScheme.cs b/Packages/Sequence-Unity/Editor/CheckUrlScheme.cs index 72b6205ce..a9093b5a1 100644 --- a/Packages/Sequence-Unity/Editor/CheckUrlScheme.cs +++ b/Packages/Sequence-Unity/Editor/CheckUrlScheme.cs @@ -20,8 +20,8 @@ public class CheckUrlScheme [PostProcessBuild] public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject) { - SequenceConfig config = SequenceConfig.GetConfig(SequenceService.None); - _urlScheme = config.UrlScheme; + SequenceConfigBase configBase = SequenceConfig.GetConfig(SequenceService.None); + _urlScheme = configBase.UrlScheme; if (string.IsNullOrWhiteSpace(_urlScheme)) { diff --git a/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/Common/AssetHandler.cs b/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/Common/AssetHandler.cs index 53da5a489..1a8deed5e 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/Common/AssetHandler.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/Common/AssetHandler.cs @@ -13,7 +13,7 @@ namespace Sequence.Boilerplates public static class AssetHandler { public static readonly Texture2D DefaultTexture = new Texture2D(100, 100); // Default if we fail to fetch the texture - private static readonly string Directory = Path.Combine(Application.persistentDataPath, "assets"); + private static readonly string Directory = Path.Combine(UnityEngine.Application.persistentDataPath, "assets"); public static async Task GetSpriteAsync(string url) { diff --git a/Packages/Sequence-Unity/Sequence/SequenceFrontend/Scripts/UI/LoginPanel.cs b/Packages/Sequence-Unity/Sequence/SequenceFrontend/Scripts/UI/LoginPanel.cs index 1f03694a3..5335db7ae 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceFrontend/Scripts/UI/LoginPanel.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceFrontend/Scripts/UI/LoginPanel.cs @@ -39,11 +39,11 @@ protected override void Awake() _demoPage = FindObjectOfType(); - SequenceConfig config = SequenceConfig.GetConfig(SequenceService.WaaS); + SequenceConfigBase configBase = SequenceConfig.GetConfig(SequenceService.WaaS); SequenceWallet.OnFailedToRecoverSession += OnFailedToRecoverSession; - _storeSessionInfoAndSkipLoginWhenPossible = config.StoreSessionKey(); + _storeSessionInfoAndSkipLoginWhenPossible = configBase.StoreSessionKey(); ILogin loginHandler = SequenceLogin.GetInstance(); SetupLoginHandler(loginHandler); @@ -52,7 +52,7 @@ protected override void Awake() if (_urlScheme == null) { - _urlScheme = config.UrlScheme; + _urlScheme = configBase.UrlScheme; } } diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/EditorBrowser.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/EditorBrowser.cs index 66ebd2d9c..ec3108e71 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/EditorBrowser.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/EditorBrowser.cs @@ -1,5 +1,4 @@ using System.Text.RegularExpressions; -using UnityEngine; namespace Sequence.Authentication { @@ -25,16 +24,20 @@ public void Authenticate(string url, string redirectUrl = "") string stateFragment = _state.Substring(stateIndex); _state = "unity-editor" + stateFragment; _authenticator.BrowserModifyStateToken(_state); - Application.OpenURL(authUrl); +#if UNITY_2017_1_OR_NEWER + UnityEngine.Application.OpenURL(authUrl); +#endif PollForSuccess(); } private void PollForSuccess() { - GameObject successPoller = UnityEngine.Object.Instantiate(new GameObject("SuccessPoller")) as GameObject; +#if UNITY_2017_1_OR_NEWER + UnityEngine.GameObject successPoller = UnityEngine.Object.Instantiate(new UnityEngine.GameObject("SuccessPoller")); WebAuthSuccessPoller poller = successPoller.AddComponent(); poller.Setup(_authenticator, _authenticator.GetRedirectUrl(), _state); poller.PollForAuthSuccess(); +#endif } } } \ No newline at end of file diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/IosBrowser.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/IosBrowser.cs index b1b762c7a..975a59c3e 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/IosBrowser.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/IosBrowser.cs @@ -1,6 +1,9 @@ using System; using System.Runtime.InteropServices; + +#if UNITY_IOS && !UNITY_EDITOR using AOT; +#endif namespace Sequence.Authentication { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/JwtHelper.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/JwtHelper.cs index 0ff211794..69e802119 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/JwtHelper.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/JwtHelper.cs @@ -1,6 +1,6 @@ using System; using System.Text; -using UnityEngine; +using Newtonsoft.Json; namespace Sequence.Authentication { @@ -12,7 +12,7 @@ public static IdTokenJwtPayload GetIdTokenJwtPayload(string jwt) IdTokenJwtPayload payload; try { - payload = JsonUtility.FromJson(payloadJson); + payload = JsonConvert.DeserializeObject(payloadJson); } catch (Exception ex) { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/OpenIdAuthenticator.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/OpenIdAuthenticator.cs index fc9553d13..ef4563ee2 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/OpenIdAuthenticator.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/OpenIdAuthenticator.cs @@ -5,8 +5,6 @@ using System.Collections.Generic; using Sequence.Config; using Sequence.Utils; -using UnityEngine; -using Object = UnityEngine.Object; namespace Sequence.Authentication { @@ -44,10 +42,13 @@ public static void InjectRedirectUrl(string redirectUrl) public OpenIdAuthenticator(string nonce = null) { - SequenceConfig config = SequenceConfig.GetConfig(SequenceService.None); + SequenceConfigBase configBase = SequenceConfig.GetConfig(SequenceService.None); - _urlScheme = config.UrlScheme; - SetClientIds(config); +#if UNITY_2017_1_OR_NEWER + _urlScheme = configBase.UrlScheme; +#endif + + SetClientIds(configBase); #if UNITY_EDITOR InjectRedirectUrl("http://localhost:8080/"); @@ -55,18 +56,18 @@ public OpenIdAuthenticator(string nonce = null) _browser = CreateBrowser(); } - private void SetClientIds(SequenceConfig config) + private void SetClientIds(SequenceConfigBase configBase) { #if UNITY_IOS && !UNITY_EDITOR GoogleClientId = config.GoogleClientIdIOS; DiscordClientId = config.DiscordClientIdIOS; FacebookClientId = config.FacebookClientIdIOS; AppleClientId = config.AppleClientIdIOS; -#else // Todo get Android client ids on Android platform - GoogleClientId = config.GoogleClientId; - DiscordClientId = config.DiscordClientId; - FacebookClientId = config.FacebookClientId; - AppleClientId = config.AppleClientId; +#elif UNITY_2017_1_OR_NEWER // Todo get Android client ids on Android platform + GoogleClientId = configBase.GoogleClientId; + DiscordClientId = configBase.DiscordClientId; + FacebookClientId = configBase.FacebookClientId; + AppleClientId = configBase.AppleClientId; #endif } @@ -83,7 +84,7 @@ private IBrowser CreateBrowser() #elif UNITY_ANDROID return new StandaloneBrowser(); // Todo switch to AndroidBrowser #else - throw new NotImplementedException("No social sign in implementation for this platform"); + return new EditorBrowser(this); #endif } @@ -231,9 +232,9 @@ private string GenerateSignInUrl(string baseUrl, string clientId, string state) string url = $"{baseUrl}?response_type=code+id_token&client_id={clientId}&redirect_uri={_redirectUrl}&scope=openid+email&state={state}/"; - if (PlayerPrefs.HasKey(LoginEmail)) + if (SequencePrefs.HasKey(LoginEmail)) { - url = url.RemoveTrailingSlash() + $"&login_hint={PlayerPrefs.GetString(LoginEmail)}".AppendTrailingSlashIfNeeded(); + url = url.RemoveTrailingSlash() + $"&login_hint={SequencePrefs.GetString(LoginEmail)}".AppendTrailingSlashIfNeeded(); url = url.Replace(" ", ""); } diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple.cs index 75458b033..eeddbbf2e 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple.cs @@ -4,11 +4,14 @@ using AppleAuth.Enums; using AppleAuth.Interfaces; using AppleAuth.Native; -using UnityEngine; namespace Sequence.Authentication { - public class SignInWithApple : MonoBehaviour +#if UNITY_2017_1_OR_NEWER + public class SignInWithApple : UnityEngine.MonoBehaviour +#else + public class SignInWithApple +#endif { IAppleAuthManager m_AppleAuthManager; public string Token; diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/AppleAuth.asmdef b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/AppleAuth.asmdef index 6289ac2bf..3b209dd26 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/AppleAuth.asmdef +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/AppleAuth.asmdef @@ -1,3 +1,4 @@ { - "name": "AppleAuth" + "name": "AppleAuth", + "references":[ "GUID:b4f9c0f8f363f439b9e337f79050f189" ] } diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/AppleAuthManager.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/AppleAuthManager.cs index 5d1c0130e..f171b56ff 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/AppleAuthManager.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/AppleAuthManager.cs @@ -5,6 +5,7 @@ using AppleAuth.Enums; using AppleAuth.Interfaces; using System; +using Sequence.Utils; namespace AppleAuth { @@ -16,7 +17,7 @@ static AppleAuthManager() #if APPLE_AUTH_MANAGER_NATIVE_IMPLEMENTATION_AVAILABLE PInvoke.AppleAuth_LogMessage(versionMessage); #else - UnityEngine.Debug.Log(versionMessage); + LogHandler.Error(versionMessage); #endif } diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/Native/AppleError.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/Native/AppleError.cs index 171605ef3..c59b92fc9 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/Native/AppleError.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/Native/AppleError.cs @@ -1,11 +1,14 @@ using AppleAuth.Interfaces; using System; -using UnityEngine; namespace AppleAuth.Native { [Serializable] - internal class AppleError : IAppleError, ISerializationCallbackReceiver +#if UNITY_2017_1_OR_NEWER + internal class AppleError : IAppleError, UnityEngine.ISerializationCallbackReceiver +#else + internal class AppleError : IAppleError +#endif { public int _code = 0; public string _domain = null; diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/Native/AppleIDCredential.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/Native/AppleIDCredential.cs index 9e4d4697d..99ef1af4b 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/Native/AppleIDCredential.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/Native/AppleIDCredential.cs @@ -1,12 +1,15 @@ using AppleAuth.Enums; using AppleAuth.Interfaces; using System; -using UnityEngine; namespace AppleAuth.Native { [Serializable] - internal class AppleIDCredential : IAppleIDCredential, ISerializationCallbackReceiver +#if UNITY_2017_1_OR_NEWER + internal class AppleIDCredential : IAppleIDCredential, UnityEngine.ISerializationCallbackReceiver +#else + internal class AppleIDCredential : IAppleIDCredential +#endif { public string _base64IdentityToken = null; public string _base64AuthorizationCode = null; diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/Native/CredentialStateResponse.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/Native/CredentialStateResponse.cs index 8584bcdf3..e276cd841 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/Native/CredentialStateResponse.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/Native/CredentialStateResponse.cs @@ -1,12 +1,15 @@ using AppleAuth.Enums; using AppleAuth.Interfaces; using System; -using UnityEngine; namespace AppleAuth.Native { [Serializable] - internal class CredentialStateResponse : ICredentialStateResponse, ISerializationCallbackReceiver +#if UNITY_2017_1_OR_NEWER + internal class CredentialStateResponse : ICredentialStateResponse, UnityEngine.ISerializationCallbackReceiver +#else + internal class CredentialStateResponse : ICredentialStateResponse +#endif { public bool _success = false; public bool _hasCredentialState = false; diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/Native/LoginWithAppleIdResponse.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/Native/LoginWithAppleIdResponse.cs index 6e3583698..615db313c 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/Native/LoginWithAppleIdResponse.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/Native/LoginWithAppleIdResponse.cs @@ -1,11 +1,14 @@ using AppleAuth.Interfaces; using System; -using UnityEngine; namespace AppleAuth.Native { [Serializable] - internal class LoginWithAppleIdResponse : ILoginWithAppleIdResponse, ISerializationCallbackReceiver +#if UNITY_2017_1_OR_NEWER + internal class LoginWithAppleIdResponse : ILoginWithAppleIdResponse, UnityEngine.ISerializationCallbackReceiver +#else + internal class LoginWithAppleIdResponse : ILoginWithAppleIdResponse +#endif { public bool _success = false; public bool _hasAppleIdCredential = false; diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/Native/PasswordCredential.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/Native/PasswordCredential.cs index d0d8c0f70..5a6a31128 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/Native/PasswordCredential.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/Native/PasswordCredential.cs @@ -1,11 +1,14 @@ using AppleAuth.Interfaces; using System; -using UnityEngine; namespace AppleAuth.Native { [Serializable] - internal class PasswordCredential : IPasswordCredential, ISerializationCallbackReceiver +#if UNITY_2017_1_OR_NEWER + internal class PasswordCredential : IPasswordCredential, UnityEngine.ISerializationCallbackReceiver +#else + internal class PasswordCredential : IPasswordCredential +#endif { public string _user = null; public string _password = null; diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/Native/PayloadDeserializer.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/Native/PayloadDeserializer.cs index beda2d41a..ba1cec489 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/Native/PayloadDeserializer.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/Native/PayloadDeserializer.cs @@ -1,5 +1,5 @@ using AppleAuth.Interfaces; -using UnityEngine; +using Newtonsoft.Json; namespace AppleAuth.Native { @@ -7,12 +7,12 @@ public class PayloadDeserializer : IPayloadDeserializer { public ICredentialStateResponse DeserializeCredentialStateResponse(string payload) { - return JsonUtility.FromJson(payload); + return JsonConvert.DeserializeObject(payload); } public ILoginWithAppleIdResponse DeserializeLoginWithAppleIdResponse(string payload) { - return JsonUtility.FromJson(payload); + return JsonConvert.DeserializeObject(payload); } } } \ No newline at end of file diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/Native/PersonName.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/Native/PersonName.cs index d09963987..c19d9b504 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/Native/PersonName.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/SignInWithApple/AppleAuth/Native/PersonName.cs @@ -1,11 +1,14 @@ using System; using AppleAuth.Interfaces; -using UnityEngine; namespace AppleAuth.Native { [Serializable] - internal class PersonName : IPersonName, ISerializationCallbackReceiver +#if UNITY_2017_1_OR_NEWER + internal class PersonName : IPersonName, UnityEngine.ISerializationCallbackReceiver +#else + internal class PersonName : IPersonName +#endif { public string _namePrefix = null; public string _givenName = null; diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/StandaloneBrowser.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/StandaloneBrowser.cs index 5ea1c530d..ce4d60e0a 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/StandaloneBrowser.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/StandaloneBrowser.cs @@ -1,12 +1,12 @@ -using UnityEngine; - namespace Sequence.Authentication { public class StandaloneBrowser : IBrowser { public void Authenticate(string url, string redirectUrl = "") { - Application.OpenURL(url); +#if UNITY_2017_1_OR_NEWER + UnityEngine.Application.OpenURL(url); +#endif } public void SetState(string state) diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/WebAuthSuccessPoller.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/WebAuthSuccessPoller.cs index 1748cfde9..8b9a2b5f7 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/WebAuthSuccessPoller.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/WebAuthSuccessPoller.cs @@ -1,3 +1,4 @@ +#if UNITY_2017_1_OR_NEWER using System; using System.Collections; using System.IO; @@ -90,4 +91,5 @@ private async Task SendGetSuccessRequest() return false; } } -} \ No newline at end of file +} +#endif diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/WebBrowser.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/WebBrowser.cs index 8590cb8bb..f49c9c255 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/WebBrowser.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/WebBrowser.cs @@ -7,8 +7,6 @@ using System.Text.RegularExpressions; using System.Threading.Tasks; using Sequence.Utils; -using UnityEngine; -using UnityEngine.Networking; using Object = System.Object; namespace Sequence.Authentication @@ -38,7 +36,7 @@ public void Authenticate(string url, string redirectUrl = "") Dictionary queryParams = url.ExtractQueryAndHashParameters(); if (queryParams.TryGetValue("client_id", out string clientId)) { - GameObject receiver = new GameObject("WebBrowserMessageReceiver"); + UnityEngine.GameObject receiver = new UnityEngine.GameObject("WebBrowserMessageReceiver"); receiver.AddComponent().SetWebBrowser(this); ISocialSignIn socialSignIn = WebSocialSignInFactory.Create(method); socialSignIn.SignIn(clientId, ""); @@ -98,7 +96,8 @@ public void SignIn(string clientId, string nonce) } } - public class WebBrowserMessageReceiver : MonoBehaviour +#if UNITY_2017_1_OR_NEWER + public class WebBrowserMessageReceiver : UnityEngine.MonoBehaviour { private WebBrowser _webBrowser; @@ -113,4 +112,5 @@ public void OnGoogleSignIn(string idToken) Destroy(gameObject); } } +#endif } \ No newline at end of file diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Config/Editor/VersionSetter.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Config/Editor/VersionSetter.cs index ef1024a5c..88062dab1 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Config/Editor/VersionSetter.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Config/Editor/VersionSetter.cs @@ -1,6 +1,6 @@ -using UnityEditor; +#if UNITY_EDITOR using System.IO; -using UnityEngine; +using UnityEditor; namespace Sequence.Config.Editor { @@ -32,4 +32,6 @@ private static void InjectSDKVersionIntoResources() AssetDatabase.Refresh(); } } -} \ No newline at end of file +} + +#endif diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Config/JwtHelper.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Config/JwtHelper.cs index b7f5365cb..2b6828322 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Config/JwtHelper.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Config/JwtHelper.cs @@ -1,6 +1,6 @@ using System; using System.Text; -using UnityEngine; +using Newtonsoft.Json; namespace Sequence.Config { @@ -12,7 +12,7 @@ internal static ConfigJwt GetConfigJwt(string jwt) ConfigJwt payload; try { - payload = JsonUtility.FromJson(payloadJson); + payload = JsonConvert.DeserializeObject(payloadJson); CheckValidConfigJwt(payload); } catch (Exception ex) diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Config/PackageVersionReader.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Config/PackageVersionReader.cs index d25546574..96508d1bd 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Config/PackageVersionReader.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Config/PackageVersionReader.cs @@ -1,6 +1,5 @@ using System.IO; -using UnityEditor; -using UnityEngine; +using Newtonsoft.Json; namespace Sequence.Config { @@ -44,7 +43,7 @@ private static string FindPackageJsonPath() private static string ExtractVersionFromJson(string json) { - var jsonObj = JsonUtility.FromJson(json); + var jsonObj = JsonConvert.DeserializeObject(json); return jsonObj.version; } diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Config/SequenceConfig.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Config/SequenceConfig.cs index 31fb4b82d..e5416fe8f 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Config/SequenceConfig.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Config/SequenceConfig.cs @@ -1,12 +1,19 @@ using System; + +#if UNITY_EDITOR +using UnityEditor; +#endif + +#if UNITY_2017_1_OR_NEWER using NUnit.Framework; using NUnit.Framework.Internal; -using UnityEditor; using UnityEngine; using UnityEngine.Serialization; +#endif namespace Sequence.Config { +#if UNITY_2017_1_OR_NEWER [CreateAssetMenu(fileName = "SequenceConfig", menuName = "Sequence/SequenceConfig", order = 1)] public class SequenceConfig : ScriptableObject { @@ -16,7 +23,7 @@ public class SequenceConfig : ScriptableObject public string DiscordClientId; public string FacebookClientId; public string AppleClientId; - + [Header("Social Sign In Configuration - iOS")] public string GoogleClientIdIOS; public string DiscordClientIdIOS; @@ -26,20 +33,39 @@ public class SequenceConfig : ScriptableObject [Header("WaaS Configuration")] public string WaaSConfigKey; [FormerlySerializedAs("EnableAccountOverride")] public bool EnableMultipleAccountsPerEmail = false; - public string WaaSVersion { get; private set; } + public string WaaSVersion; - [Header("Sequence SDK Configuration")] + [Header("Sequence SDK Configuration")] public string BuilderAPIKey; public bool StoreSessionPrivateKeyInSecureStorage = false; public bool EditorStoreSessionPrivateKeyInSecureStorage = false; - private static SequenceConfig _config; - public static SequenceConfig GetConfig(SequenceService sequenceService = SequenceService.Unspecified) + private static SequenceConfigBase _configBase; + public static SequenceConfigBase GetConfig(SequenceService sequenceService = SequenceService.Unspecified) { - if (_config == null) + if (_configBase == null) { - _config = GetAppropriateConfig(sequenceService); - if (_config == null) + var config = GetAppropriateConfig(sequenceService); + _configBase = new SequenceConfigBase + { + UrlScheme = config.UrlScheme, + GoogleClientId = config.GoogleClientId, + DiscordClientId = config.DiscordClientId, + FacebookClientId = config.FacebookClientId, + AppleClientId = config.AppleClientId, + GoogleClientIdIOS = config.GoogleClientIdIOS, + DiscordClientIdIOS = config.DiscordClientIdIOS, + FacebookClientIdIOS = config.FacebookClientIdIOS, + AppleClientIdIOS = config.AppleClientIdIOS, + WaaSConfigKey = config.WaaSConfigKey, + WaaSVersion = config.WaaSVersion, + BuilderAPIKey = config.BuilderAPIKey, + EnableMultipleAccountsPerEmail = config.EnableMultipleAccountsPerEmail, + StoreSessionPrivateKeyInSecureStorage = config.StoreSessionPrivateKeyInSecureStorage, + EditorStoreSessionPrivateKeyInSecureStorage = config.EditorStoreSessionPrivateKeyInSecureStorage + }; + + if (_configBase == null) { throw new Exception("SequenceConfig not found. Make sure to create and configure it and place it at the root of your Resources folder. Create it from the top bar with Assets > Create > Sequence > SequenceConfig"); } @@ -47,19 +73,24 @@ public static SequenceConfig GetConfig(SequenceService sequenceService = Sequenc TextAsset versionFile = Resources.Load("sequence-unity-version"); if (versionFile != null) { - _config.WaaSVersion = $"1 (Unity {versionFile.text})"; + _configBase.WaaSVersion = $"1 (Unity {versionFile.text})"; } else { - _config.WaaSVersion = $"1 (Unity {PackageVersionReader.GetVersion()})"; + _configBase.WaaSVersion = $"1 (Unity {PackageVersionReader.GetVersion()})"; } #if UNITY_EDITOR && !SEQ_DISABLE_PACKAGE_OVERRIDE - _config.WaaSVersion = $"1 (Unity {PackageVersionReader.GetVersion()})"; // version file is only updated when building + _configBase.WaaSVersion = $"1 (Unity {PackageVersionReader.GetVersion()})"; // version file is only updated when building #endif } - return _config; + return _configBase; + } + + public static void SetConfig(SequenceConfigBase configBase) + { + _configBase = configBase; } private static SequenceConfig GetAppropriateConfig(SequenceService sequenceService) @@ -142,7 +173,7 @@ public static Exception MissingConfigError(string valueName) public static ConfigJwt GetConfigJwt() { - string configKey = _config.WaaSConfigKey; + string configKey = _configBase.WaaSConfigKey; if (string.IsNullOrWhiteSpace(configKey)) { throw SequenceConfig.MissingConfigError("WaaS Config Key"); @@ -150,15 +181,37 @@ public static ConfigJwt GetConfigJwt() return JwtHelper.GetConfigJwt(configKey); } + } +#else + public class SequenceConfig + { + private static SequenceConfigBase _config; - public bool StoreSessionKey() + public static SequenceConfigBase GetConfig(SequenceService sequenceService = SequenceService.Unspecified) { -#if UNITY_EDITOR - return EditorStoreSessionPrivateKeyInSecureStorage && - TestContext.CurrentTestExecutionContext?.ExecutionStatus != TestExecutionStatus.Running; -#else - return StoreSessionPrivateKeyInSecureStorage; -#endif + return _config; + } + + public static void SetConfig(SequenceConfigBase config) + { + _config = config; + } + + public static Exception MissingConfigError(string valueName) + { + return new Exception($"{valueName} is not set. Please set it in SequenceConfig asset in your Resources folder."); + } + + public static ConfigJwt GetConfigJwt() + { + string configKey = _config.WaaSConfigKey; + if (string.IsNullOrWhiteSpace(configKey)) + { + throw SequenceConfig.MissingConfigError("WaaS Config Key"); + } + + return JwtHelper.GetConfigJwt(configKey); } } +#endif } \ No newline at end of file diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Config/SequenceConfigBase.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Config/SequenceConfigBase.cs new file mode 100644 index 000000000..f2f724d8e --- /dev/null +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Config/SequenceConfigBase.cs @@ -0,0 +1,40 @@ +namespace Sequence.Config +{ + public class SequenceConfigBase + { +#if UNITY_2017_1_OR_NEWER + public string UrlScheme; + public string GoogleClientId; + public string DiscordClientId; + public string FacebookClientId; + public string AppleClientId; + public string GoogleClientIdIOS; + public string DiscordClientIdIOS; + public string FacebookClientIdIOS; + public string AppleClientIdIOS; + public string WaaSConfigKey; + public string WaaSVersion; + public string BuilderAPIKey; + public bool EnableMultipleAccountsPerEmail; + public bool StoreSessionPrivateKeyInSecureStorage; + public bool EditorStoreSessionPrivateKeyInSecureStorage; +#else + public string WaaSVersion; + public string BuilderAPIKey; + public string WaaSConfigKey; +#endif + + public bool StoreSessionKey() + { +#if UNITY_EDITOR + return EditorStoreSessionPrivateKeyInSecureStorage && + NUnit.Framework.TestContext.CurrentTestExecutionContext?.ExecutionStatus != + NUnit.Framework.Internal.TestExecutionStatus.Running; +#elif UNITY_2017_1_OR_NEWER + return StoreSessionPrivateKeyInSecureStorage; +#else + return false; +#endif + } + } +} \ No newline at end of file diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Config/SequenceConfigBase.cs.meta b/Packages/Sequence-Unity/Sequence/SequenceSDK/Config/SequenceConfigBase.cs.meta new file mode 100644 index 000000000..12d2bde78 --- /dev/null +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Config/SequenceConfigBase.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 8cdf8e4c216a4a03842c9b160f75c53d +timeCreated: 1741630811 \ No newline at end of file diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/AbiData.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/AbiData.cs index 74b17c843..4a7fd8a18 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/AbiData.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/AbiData.cs @@ -1,10 +1,8 @@ using System; -using System.Collections; -using System.Collections.Generic; +using Sequence.Utils; using System.Linq; using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using UnityEngine.Scripting; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/DelayedEncode.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/DelayedEncode.cs index 9d4523e6c..fe8812e3a 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/DelayedEncode.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/DelayedEncode.cs @@ -1,5 +1,5 @@ using System; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/DelayedEncodeData.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/DelayedEncodeData.cs index 950a105a6..dad37315a 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/DelayedEncodeData.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/DelayedEncodeData.cs @@ -1,10 +1,8 @@ using System; -using System.Collections; -using System.Collections.Generic; +using Sequence.Utils; using System.Linq; using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using UnityEngine.Scripting; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/Identity.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/Identity.cs index dfcf6a450..a472f7695 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/Identity.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/Identity.cs @@ -1,5 +1,5 @@ using System; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataCloseSession.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataCloseSession.cs index de0cd47a8..b423f6003 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataCloseSession.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataCloseSession.cs @@ -1,5 +1,5 @@ using System; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataFederateAccount.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataFederateAccount.cs index c792412e1..7dce0c7e9 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataFederateAccount.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataFederateAccount.cs @@ -1,5 +1,5 @@ using Newtonsoft.Json; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataFeeOptions.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataFeeOptions.cs index 87135db99..21b3d9a5c 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataFeeOptions.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataFeeOptions.cs @@ -1,6 +1,6 @@ using System; using Newtonsoft.Json; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataFinishValidateSession.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataFinishValidateSession.cs index fa3f742c6..1b0f24806 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataFinishValidateSession.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataFinishValidateSession.cs @@ -1,5 +1,4 @@ using System; -using UnityEngine.Scripting; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataGetIdToken.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataGetIdToken.cs index 5f0e2deb2..64aacb590 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataGetIdToken.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataGetIdToken.cs @@ -1,5 +1,5 @@ using System; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataGetSession.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataGetSession.cs index 5c08aafdf..cd73b3657 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataGetSession.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataGetSession.cs @@ -1,5 +1,5 @@ using System; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataGetTransactionReceipt.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataGetTransactionReceipt.cs index 653476d6e..760af495d 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataGetTransactionReceipt.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataGetTransactionReceipt.cs @@ -1,7 +1,6 @@ using System; using Newtonsoft.Json; -using Sequence; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataInitiateAuth.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataInitiateAuth.cs index e9e0c1fb3..deff8e28a 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataInitiateAuth.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataInitiateAuth.cs @@ -1,5 +1,5 @@ using Newtonsoft.Json; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataListAccounts.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataListAccounts.cs index 7f9334cec..0b5b61867 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataListAccounts.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataListAccounts.cs @@ -1,6 +1,5 @@ using System; -using Newtonsoft.Json; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataListSessions.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataListSessions.cs index 26925ec25..6ce4be510 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataListSessions.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataListSessions.cs @@ -1,5 +1,5 @@ using System; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataOpenSession.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataOpenSession.cs index a2e2bc7b6..be2ce6e8c 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataOpenSession.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataOpenSession.cs @@ -1,7 +1,6 @@ using System; using Newtonsoft.Json; using Sequence.Utils; -using UnityEngine.Scripting; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataSendTransaction.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataSendTransaction.cs index 7804a6334..c5f9dde02 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataSendTransaction.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataSendTransaction.cs @@ -1,12 +1,12 @@ using System; using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { [Preserve] - [System.Serializable] + [Serializable] public class IntentDataSendTransaction { public string identifier = Guid.NewGuid().ToString(); diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataSessionAuthProof.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataSessionAuthProof.cs index a54796993..4a4e826cd 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataSessionAuthProof.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataSessionAuthProof.cs @@ -1,6 +1,6 @@ using System; using Newtonsoft.Json; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataSignMessage.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataSignMessage.cs index 37107c013..0b628bf0c 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataSignMessage.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataSignMessage.cs @@ -1,7 +1,6 @@ using System; using System.Text; using Sequence.Utils; -using UnityEngine.Scripting; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataValidateSession.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataValidateSession.cs index bbc3b9242..cca23a7cd 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataValidateSession.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataValidateSession.cs @@ -1,5 +1,4 @@ using System; -using UnityEngine.Scripting; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentPayload.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentPayload.cs index 2e2dcd23e..87f8ee4ec 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentPayload.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentPayload.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IsValidMessageSignatureArgs.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IsValidMessageSignatureArgs.cs index b8376423e..5af5efea6 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IsValidMessageSignatureArgs.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IsValidMessageSignatureArgs.cs @@ -1,4 +1,4 @@ -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/Payload.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/Payload.cs index dc3840070..ecae4f331 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/Payload.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/Payload.cs @@ -1,5 +1,5 @@ using System; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/RawTransaction.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/RawTransaction.cs index 9af256fe4..52c88fe3e 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/RawTransaction.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/RawTransaction.cs @@ -2,8 +2,8 @@ using Newtonsoft.Json; using Sequence.Contracts; using Sequence.Transactions; -using UnityEngine.Scripting; using StringExtensions = Sequence.Utils.StringExtensions; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/RegisterSessionIntent.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/RegisterSessionIntent.cs index 3ef9e36bc..7d7003a70 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/RegisterSessionIntent.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/RegisterSessionIntent.cs @@ -1,4 +1,4 @@ -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/SendERC1155.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/SendERC1155.cs index 22d307381..a51d7fcb7 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/SendERC1155.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/SendERC1155.cs @@ -1,6 +1,6 @@ using System; using Newtonsoft.Json; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/SendERC1155Values.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/SendERC1155Values.cs index ee76c72e0..370144a4d 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/SendERC1155Values.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/SendERC1155Values.cs @@ -1,5 +1,5 @@ using System; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/SendERC20.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/SendERC20.cs index 1542bf5a6..0fd2a6636 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/SendERC20.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/SendERC20.cs @@ -1,5 +1,5 @@ using Newtonsoft.Json; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/SendERC721.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/SendERC721.cs index 442b593e1..5487dcbec 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/SendERC721.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/SendERC721.cs @@ -1,7 +1,6 @@ using System; using Newtonsoft.Json; -using UnityEngine; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { @@ -25,7 +24,7 @@ public SendERC721(string tokenAddress, string to, string tokenId, bool safe = tr this.safe = safe; if (!safe && data != null) { - Debug.LogError($"Error creating {GetType().Name}: {nameof(data)} can only be set when {nameof(safe)} is true.\nUsing null data."); + LogHandler.Error($"Error creating {GetType().Name}: {nameof(data)} can only be set when {nameof(safe)} is true.\nUsing null data."); data = null; } this.data = data; diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/SendIntentPayload.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/SendIntentPayload.cs index d16f410ed..ae233e5d2 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/SendIntentPayload.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/SendIntentPayload.cs @@ -1,5 +1,5 @@ using System; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/Session.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/Session.cs index 311354bd8..79da4af82 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/Session.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/Session.cs @@ -1,5 +1,5 @@ using System; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/Signature.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/Signature.cs index 2a0d91e65..ad9d26264 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/Signature.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/Signature.cs @@ -1,5 +1,5 @@ using System; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/TransactionsValidator.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/TransactionsValidator.cs index 1f475d1c2..7f820b7bb 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/TransactionsValidator.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/TransactionsValidator.cs @@ -1,7 +1,7 @@ using System; using Sequence.ABI; using Sequence.Contracts; -using UnityEngine; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { @@ -23,7 +23,7 @@ public static void Validate(Transaction[] transactions) if (!ABIRegex.MatchesFunctionABI(delayedEncode.data.abi)) { string message = $"Given {nameof(DelayedEncode)} transaction with function abi {delayedEncode.data.abi} that does not match the required regex {ABIRegex.FunctionABIRegex} - for example: \"mint(uint256,uint256)\""; - Debug.LogWarning(message + "\nAttempting to recover and parse anyways"); + LogHandler.Warning(message + "\nAttempting to recover and parse anyways"); delayedEncode.data.abi = EventParser.ParseEventDef(delayedEncode.data.abi).ToString(); if (!ABIRegex.MatchesFunctionABI(delayedEncode.data.abi)) { @@ -43,7 +43,7 @@ public static void Validate(Transaction[] transactions) if (!ABIRegex.MatchesFunctionABI(contractCall.data.abi)) { string message = $"Given {nameof(SequenceContractCall)} transaction with function abi {contractCall.data.abi} that does not match the required regex {ABIRegex.FunctionABIRegex} - for example: \"mint(uint256,uint256)\""; - Debug.LogWarning(message + "\nAttempting to recover and parse anyways"); + LogHandler.Warning(message + "\nAttempting to recover and parse anyways"); contractCall.data.abi = EventParser.ParseEventDef(contractCall.data.abi).ToString(); if (!ABIRegex.MatchesFunctionABI(contractCall.data.abi)) { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/Account.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/Account.cs index 4860c7e70..69d9dbd5d 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/Account.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/Account.cs @@ -1,4 +1,4 @@ -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/ErrorResponse.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/ErrorResponse.cs index 82e3ca531..c84047bd8 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/ErrorResponse.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/ErrorResponse.cs @@ -1,4 +1,4 @@ -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/FailedTransactionReturn.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/FailedTransactionReturn.cs index acdaa5beb..a4bb8aa1e 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/FailedTransactionReturn.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/FailedTransactionReturn.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/FeeOption.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/FeeOption.cs index ef4f54854..09a5e365b 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/FeeOption.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/FeeOption.cs @@ -1,5 +1,5 @@ using System; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/FeeOptionReturn.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/FeeOptionReturn.cs index e4e74ae8e..1f73784dd 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/FeeOptionReturn.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/FeeOptionReturn.cs @@ -1,5 +1,5 @@ using System; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/FeeOptionsResponse.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/FeeOptionsResponse.cs index 9bf7ce87c..8f0550b98 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/FeeOptionsResponse.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/FeeOptionsResponse.cs @@ -1,5 +1,5 @@ using System; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/FeeToken.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/FeeToken.cs index 4444af6e4..36e718006 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/FeeToken.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/FeeToken.cs @@ -1,6 +1,6 @@ using System.Numerics; using Newtonsoft.Json; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/GetWalletAddressReturn.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/GetWalletAddressReturn.cs index aa7dc06e6..a7329162c 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/GetWalletAddressReturn.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/GetWalletAddressReturn.cs @@ -1,4 +1,4 @@ -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponse.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponse.cs index 4e1103d72..e2421f41e 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponse.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponse.cs @@ -1,6 +1,5 @@ using System; -using Newtonsoft.Json.Linq; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseAccountFederated.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseAccountFederated.cs index 3b5d8f0a0..b0c95e52c 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseAccountFederated.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseAccountFederated.cs @@ -1,4 +1,4 @@ -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseAccountList.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseAccountList.cs index 703dbbfe2..36823937d 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseAccountList.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseAccountList.cs @@ -1,4 +1,4 @@ -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseAuthInitiated.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseAuthInitiated.cs index eeb0b721c..afe35aeb7 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseAuthInitiated.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseAuthInitiated.cs @@ -1,6 +1,6 @@ using System; using Newtonsoft.Json; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseFeeOptions.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseFeeOptions.cs index 62b7841b7..ac3d10bcb 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseFeeOptions.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseFeeOptions.cs @@ -1,6 +1,5 @@ using System; -using Newtonsoft.Json; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseGetGetIdToken.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseGetGetIdToken.cs index 73901c9ec..90902ac18 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseGetGetIdToken.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseGetGetIdToken.cs @@ -1,5 +1,5 @@ using System; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseGetSession.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseGetSession.cs index f44ce4782..391f3780c 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseGetSession.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseGetSession.cs @@ -1,5 +1,5 @@ using System; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseSessionAuthProof.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseSessionAuthProof.cs index 10d94ea96..eb599ea83 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseSessionAuthProof.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseSessionAuthProof.cs @@ -1,4 +1,4 @@ -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseSessionOpened.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseSessionOpened.cs index bc17d6997..3f964b8fc 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseSessionOpened.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseSessionOpened.cs @@ -1,5 +1,5 @@ using System; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseSignedMessage.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseSignedMessage.cs index d28e44dbd..acf41886a 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseSignedMessage.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseSignedMessage.cs @@ -1,5 +1,5 @@ using System; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseValidationFinished.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseValidationFinished.cs index 694ea4bf1..1e1e4d41b 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseValidationFinished.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseValidationFinished.cs @@ -1,5 +1,3 @@ -using UnityEngine.Scripting; - namespace Sequence.EmbeddedWallet { public class IntentResponseValidationFinished diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IsValidMessageSignatureReturn.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IsValidMessageSignatureReturn.cs index ccc7ee6ad..ec76f80a0 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IsValidMessageSignatureReturn.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IsValidMessageSignatureReturn.cs @@ -1,4 +1,4 @@ -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/MetaTxnReceipt.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/MetaTxnReceipt.cs index c61fb3a92..9e05a89bf 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/MetaTxnReceipt.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/MetaTxnReceipt.cs @@ -1,4 +1,4 @@ -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/MetaTxnReceiptLog.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/MetaTxnReceiptLog.cs index f7d2382dd..beaa0afcb 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/MetaTxnReceiptLog.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/MetaTxnReceiptLog.cs @@ -1,4 +1,4 @@ -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/RegisterSessionResponse.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/RegisterSessionResponse.cs index 08552c6d8..9260adc27 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/RegisterSessionResponse.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/RegisterSessionResponse.cs @@ -1,4 +1,4 @@ -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/SimulateResult.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/SimulateResult.cs index 94468cb6b..cefa1c7b9 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/SimulateResult.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/SimulateResult.cs @@ -1,4 +1,4 @@ -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/SuccessfulTransactionReturn.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/SuccessfulTransactionReturn.cs index d77e5ec8b..8b811aaed 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/SuccessfulTransactionReturn.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/SuccessfulTransactionReturn.cs @@ -1,9 +1,8 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using Newtonsoft.Json; using System.Collections.Generic; using System; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { @@ -65,7 +64,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist } catch (Exception ex) { - UnityEngine.Debug.LogError($"Failed to load JSON: {ex.Message}"); + LogHandler.Error($"Failed to load JSON: {ex.Message}"); throw; } @@ -91,7 +90,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist } catch (Exception ex) { - UnityEngine.Debug.LogError($"Error during JSON conversion: {ex.Message}"); + LogHandler.Error($"Error during JSON conversion: {ex.Message}"); throw; } diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/EOAWalletLinker.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/EOAWalletLinker.cs index 385c70e03..48bd261ad 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/EOAWalletLinker.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/EOAWalletLinker.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using UnityEngine; +using Sequence.Utils; namespace Sequence.EmbeddedWallet { @@ -42,7 +42,7 @@ public async Task GetLinkedWallets() } catch (Exception e) { - Debug.LogException(e); + LogHandler.Error(e.Message); return Array.Empty(); } } @@ -70,7 +70,7 @@ await client.SendRequest( } catch (Exception e) { - Debug.LogException(e); + LogHandler.Error(e.Message); return false; } } @@ -97,7 +97,7 @@ await client.SendRequest("", } catch (System.Exception e) { - Debug.LogError($"Failed to generate EOA Wallet Link: {e}"); + LogHandler.Error($"Failed to generate EOA Wallet Link: {e}"); return null; } } @@ -105,7 +105,7 @@ await client.SendRequest("", public async Task OpenEoaWalletLink() { var link = await GenerateEoaWalletLink(); - Application.OpenURL(link); + AppEnvironment.OpenUrl(link); } } diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/EOAWalletToSequenceWalletAdapter.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/EOAWalletToSequenceWalletAdapter.cs index aac25bd1a..e401f6141 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/EOAWalletToSequenceWalletAdapter.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/EOAWalletToSequenceWalletAdapter.cs @@ -7,8 +7,9 @@ using Sequence.Contracts; using Sequence.Provider; using Newtonsoft.Json; +using Sequence.Utils; using Newtonsoft.Json.Linq; -using UnityEngine; + namespace Sequence.EmbeddedWallet { public class EOAWalletToSequenceWalletAdapter : IWallet @@ -171,7 +172,7 @@ public async Task SendTransaction(Chain network, Transaction[ } catch (Exception e) { - Debug.LogError("Error while waiting for receipt: " + e.Message); + LogHandler.Error("Error while waiting for receipt: " + e.Message); string receiptExString = e.Message; var failedReturn = new FailedTransactionReturn(e.Message, null, null); failedTransactionReturns.Add(failedReturn); diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/HttpClient.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/HttpClient.cs index b436cde92..b17725047 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/HttpClient.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/HttpClient.cs @@ -3,19 +3,12 @@ using System.Globalization; using System.IO; using System.Net.Http; -using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; -using JetBrains.Annotations; using Newtonsoft.Json; -using Sequence.ABI; -using Sequence.Authentication; using Sequence.Config; -using Sequence.Provider; using Sequence.Utils; using Sequence.WaaS.DataTypes; -using UnityEngine; -using UnityEngine.Networking; namespace Sequence.EmbeddedWallet { @@ -38,10 +31,10 @@ public HttpClient(string url) this._defaultHeaders = new Dictionary(); _defaultHeaders["Content-Type"] = "application/json"; _defaultHeaders["Accept"] = "application/json"; - SequenceConfig config = SequenceConfig.GetConfig(SequenceService.WaaS); - _defaultHeaders["X-Access-Key"] = config.BuilderAPIKey; + SequenceConfigBase configBase = SequenceConfig.GetConfig(SequenceService.WaaS); + _defaultHeaders["X-Access-Key"] = configBase.BuilderAPIKey; _defaultHeaders["Accept-Signature"] = "sig=()"; - if (string.IsNullOrWhiteSpace(config.BuilderAPIKey)) + if (string.IsNullOrWhiteSpace(configBase.BuilderAPIKey)) { throw SequenceConfig.MissingConfigError("Builder API Key"); } @@ -60,8 +53,7 @@ public void AddDefaultHeader(string key, string value) this._defaultHeaders[key] = value; } - public (UnityWebRequest, string, string) BuildRequest(string path, T args, - [CanBeNull] Dictionary headers = null, string overrideUrl = null) + public (IWebRequest, string, string) BuildRequest(string path, T args, Dictionary headers = null, string overrideUrl = null) { string url = _url.AppendTrailingSlashIfNeeded() + path; url = url.RemoveTrailingSlash(); @@ -70,13 +62,12 @@ public void AddDefaultHeader(string key, string value) url = overrideUrl.AppendTrailingSlashIfNeeded() + path; } - UnityWebRequest request = UnityWebRequest.Get(url); - request.method = UnityWebRequest.kHttpVerbPOST; + IWebRequest request = WebRequestBuilder.Post(url, string.Empty); SetHeaders(request, headers); string requestJson = SetRequestData(request, args); - string method = request.method; + string method = request.Method; string headersString = ExtractHeaders(request); string curlRequest = $"curl -X {method} '{url}' {headersString} -d '{requestJson}'"; if (requestJson == "") @@ -87,7 +78,7 @@ public void AddDefaultHeader(string key, string value) return (request, curlRequest, url); } - private void SetHeaders(UnityWebRequest request, Dictionary headers) + private void SetHeaders(IWebRequest request, Dictionary headers) { if (headers == null) { @@ -114,7 +105,7 @@ private void SetHeaders(UnityWebRequest request, Dictionary head } } - private string SetRequestData(UnityWebRequest request, T args) + private string SetRequestData(IWebRequest request, T args) { string requestJson = ""; if (typeof(T) == typeof(string)) @@ -126,28 +117,27 @@ private string SetRequestData(UnityWebRequest request, T args) requestJson = JsonConvert.SerializeObject(args, serializerSettings); } byte[] requestData = Encoding.UTF8.GetBytes(requestJson); - request.uploadHandler = new UploadHandlerRaw(requestData); - request.uploadHandler.contentType = "application/json"; + request.SetRequestData(requestData); return requestJson; } - public async Task SendRequest(string path, T args, [CanBeNull] Dictionary headers = null, string overrideUrl = null) + public async Task SendRequest(string path, T args, Dictionary headers = null, string overrideUrl = null) { - (UnityWebRequest, string, string) newRequest = BuildRequest(path, args, headers, overrideUrl); - UnityWebRequest request = newRequest.Item1; + (IWebRequest, string, string) newRequest = BuildRequest(path, args, headers, overrideUrl); + IWebRequest request = newRequest.Item1; string curlRequest = newRequest.Item2; string url = newRequest.Item3; - Debug.Log(curlRequest); + LogHandler.Info(curlRequest); try { - await request.SendWebRequest(); + var response = await request.Send(); - if (request.error != null || request.result != UnityWebRequest.Result.Success || - request.responseCode < 200 || request.responseCode > 299) + if (response.Result != WebRequestResult.Success || + response.ResponseCode < 200 || response.ResponseCode > 299) { - throw new Exception($"Error sending request to {url}: {request.responseCode} {request.error}"); + throw new Exception($"Error sending request to {url}: {response.ResponseCode} {request.Error}"); } else { @@ -170,7 +160,7 @@ public async Task SendRequest(string path, T args, [CanBeNull] Dictio } else { - byte[] results = request.downloadHandler.data; + byte[] results = response.Data; responseJson = Encoding.UTF8.GetString(results); } try @@ -242,12 +232,11 @@ public async Task SendRequest(string path, T args, [CanBeNull] Dictio public async Task GetTimeShift() { - UnityWebRequest request = UnityWebRequest.Get(_waasUrl.AppendTrailingSlashIfNeeded() + "status"); - request.method = UnityWebRequest.kHttpVerbGET; + IWebRequest request = WebRequestBuilder.Get(_waasUrl.AppendTrailingSlashIfNeeded() + "status"); try { - await request.SendWebRequest(); + await request.Send(); DateTime serverTime = DateTime.Parse(request.GetResponseHeader("date")).ToUniversalTime(); DateTime localTime = DateTime.UtcNow; TimeSpan timeShift = serverTime - localTime; @@ -255,7 +244,7 @@ public async Task GetTimeShift() } catch (Exception e) { - Debug.LogError("Error getting time shift: " + e.Message); + LogHandler.Error("Error getting time shift: " + e.Message); return TimeSpan.Zero; } finally @@ -264,17 +253,17 @@ public async Task GetTimeShift() } } - private string GetRequestErrorIfAvailable(UnityWebRequest request) + private string GetRequestErrorIfAvailable(IWebRequest request) { - if (request.downloadHandler != null && request.downloadHandler.data != null) + if (request.Data != null) { - return " " + Encoding.UTF8.GetString(request.downloadHandler.data); + return " " + Encoding.UTF8.GetString(request.Data); } return ""; } - private string ExtractHeaders(UnityWebRequest request) + private string ExtractHeaders(IWebRequest request) { StringBuilder headerBuilder = new StringBuilder(); foreach (string headerKey in new string[]{"Content-Type", "Accept", "Authorization", "X-Sequence-Tenant", "X-Access-Key"}) diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/IHttpClient.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/IHttpClient.cs index 06782aa61..c3678a8b3 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/IHttpClient.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/IHttpClient.cs @@ -1,14 +1,12 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using JetBrains.Annotations; namespace Sequence.EmbeddedWallet { - public interface IHttpClient + public interface IHttpClient { - public Task SendRequest(string path, T args, - [CanBeNull] Dictionary headers = null, string overrideUrl = null); + public Task SendRequest(string path, T args, Dictionary headers = null, string overrideUrl = null); public Task GetTimeShift(); } diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/IntentSender.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/IntentSender.cs index 00762ea62..ec241b4fb 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/IntentSender.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/IntentSender.cs @@ -6,7 +6,6 @@ using Sequence.ABI; using Sequence.Utils; using Sequence.WaaS.DataTypes; -using UnityEngine; namespace Sequence.EmbeddedWallet { @@ -85,12 +84,12 @@ public async Task SendIntent(T2 args, IntentType type, uint timeBefore } else { - Debug.LogError("Unexpected intent payload type: " + intentPayload.GetType()); + LogHandler.Error("Unexpected intent payload type: " + intentPayload.GetType()); } if (currentTimeAccordingToServer > currentTimeAccordingToIntent + 1 || currentTimeAccordingToServer < currentTimeAccordingToIntent - 1) { - Debug.LogWarning("Time mismatch detected. Retrying with server time."); + LogHandler.Warning("Time mismatch detected. Retrying with server time."); return await SendIntent(args, type, timeBeforeExpiryInSeconds, (uint)currentTimeAccordingToServer); } else @@ -162,7 +161,7 @@ public async Task DropSession(string dropSessionId) public async Task PostIntent(string payload, string path) { - Debug.Log($"Sending intent: {path} | with payload: {payload}"); + LogHandler.Info($"Sending intent: {path} | with payload: {payload}"); Dictionary headers = new Dictionary(); if (typeof(T) == typeof(IntentResponse)) { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/JwtHelper.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/JwtHelper.cs index 35b730c06..95721098b 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/JwtHelper.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/JwtHelper.cs @@ -1,6 +1,6 @@ using System; using System.Text; -using UnityEngine; +using Newtonsoft.Json; namespace Sequence.EmbeddedWallet { @@ -28,7 +28,7 @@ public static Address GetWalletAddressFromJwt(string jwtToken) JwtPayload payload; try { - payload = JsonUtility.FromJson(payloadJson); + payload = JsonConvert.DeserializeObject(payloadJson); } catch (Exception ex) { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/ResponseSignatureValidator.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/ResponseSignatureValidator.cs index b7708a2d7..50e42c0dd 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/ResponseSignatureValidator.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/ResponseSignatureValidator.cs @@ -3,8 +3,6 @@ using System.Text; using Newtonsoft.Json.Linq; using Sequence.Utils; -using UnityEngine; -using UnityEngine.Networking; namespace Sequence.EmbeddedWallet { @@ -46,7 +44,7 @@ private void LoadPublicKey() catch (Exception ex) { string error = $"Error loading public key from JWKS: {ex.Message}"; - Debug.LogError(error); + LogHandler.Error(error); throw new Exception(error); } } @@ -62,9 +60,9 @@ private byte[] Base64UrlDecode(string input) return Convert.FromBase64String(output); } - public string ValidateResponse(UnityWebRequest request) + public string ValidateResponse(IWebRequest request) { - byte[] results = request.downloadHandler.data; + byte[] results = request.Data; var responseJson = Encoding.UTF8.GetString(results); string contentDigest = request.GetResponseHeader("Content-Digest"); if (string.IsNullOrWhiteSpace(contentDigest)) diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/SequenceLogin.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/SequenceLogin.cs index a0d8da173..0f54496ae 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/SequenceLogin.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/SequenceLogin.cs @@ -7,7 +7,6 @@ using Sequence.Utils; using Sequence.Utils.SecureStorage; using Sequence.Wallet; -using UnityEngine; namespace Sequence.EmbeddedWallet { @@ -181,17 +180,20 @@ private void SetupAuthenticatorAndListeners() _authenticator.PlatformSpecificSetup(); } catch (Exception e) { - Debug.LogError($"Error encountered during PlatformSpecificSetup: {e.Message}\nSocial sign in will not work."); + LogHandler.Error($"Error encountered during PlatformSpecificSetup: {e.Message}\nSocial sign in will not work."); } - Application.deepLinkActivated += _authenticator.HandleDeepLink; + +#if UNITY_2017_1_OR_NEWER + UnityEngine.Application.deepLinkActivated += _authenticator.HandleDeepLink; +#endif _authenticator.SignedIn += OnSocialLogin; _authenticator.OnSignInFailed += OnSocialSignInFailed; } private void Configure() { - SequenceConfig config = SequenceConfig.GetConfig(SequenceService.WaaS); - string waasVersion = config.WaaSVersion; + SequenceConfigBase configBase = SequenceConfig.GetConfig(SequenceService.WaaS); + string waasVersion = configBase.WaaSVersion; if (string.IsNullOrWhiteSpace(waasVersion)) { throw SequenceConfig.MissingConfigError("WaaS Version"); @@ -274,7 +276,7 @@ private async Task EnsureSessionIsValid(SequenceWallet wallet) private (EOAWallet, string, string) AttemptToCreateWalletFromSecureStorage() { ISecureStorage secureStorage = SecureStorageFactory.CreateSecureStorage(); - string walletInfo = secureStorage.RetrieveString(Application.companyName + "-" + Application.productName + "-" + _walletKey); + string walletInfo = secureStorage.RetrieveString(AppEnvironment.CompanyName + "-" + AppEnvironment.ProductName + "-" + _walletKey); if (string.IsNullOrEmpty(walletInfo)) { return (null, "", ""); @@ -383,9 +385,9 @@ public async Task ConnectToWaaS(IntentDataOpenSession loginIntent, LoginMethod m walletAddress = registerSessionResponse.wallet; OnLoginSuccess?.Invoke(sessionId, walletAddress); SequenceWallet wallet = new SequenceWallet(new Address(walletAddress), sessionId, new IntentSender(new HttpClient(SequenceLogin.WaaSWithAuthUrl), _sessionWallet, sessionId, _waasProjectId, _waasVersion), email); - PlayerPrefs.SetInt(WaaSLoginMethod, (int)method); - PlayerPrefs.SetString(OpenIdAuthenticator.LoginEmail, email); - PlayerPrefs.Save(); + SequencePrefs.SetInt(WaaSLoginMethod, (int)method); + SequencePrefs.SetString(OpenIdAuthenticator.LoginEmail, email); + SequencePrefs.Save(); _isLoggingIn = false; wallet.OnDropSessionComplete += session => { @@ -428,7 +430,7 @@ public async Task ConnectToWaaS(IntentDataOpenSession loginIntent, LoginMethod m } catch (Exception e) { - Debug.LogError("Error storing session wallet securely: " + e.Message); + LogHandler.Error("Error storing session wallet securely: " + e.Message); } } @@ -458,7 +460,7 @@ private List ParseLoginMethods(string errorMessage) case IdentityType.OIDC: if (components.Length < 3) { - Debug.LogError( + LogHandler.Error( "Invalid response from WaaS server, expected at least 3 components in OIDC login method string"); } @@ -480,7 +482,7 @@ private List ParseLoginMethods(string errorMessage) } else { - Debug.LogError("Unexpected OIDC login method string: " + components[2]); + LogHandler.Error("Unexpected OIDC login method string: " + components[2]); } break; case IdentityType.Email: @@ -493,7 +495,7 @@ private List ParseLoginMethods(string errorMessage) methods.Add(LoginMethod.PlayFab); break; default: - Debug.LogError("Unexpected identity type " + identityType); + LogHandler.Error("Unexpected identity type " + identityType); break; } } @@ -575,9 +577,9 @@ private async Task ForceCreateWaaSAccount() await ConnectToWaaS(_failedLoginIntent, _failedLoginMethod, _failedLoginEmail); - PlayerPrefs.SetInt(WaaSLoginMethod, (int)_failedLoginMethod); - PlayerPrefs.SetString(OpenIdAuthenticator.LoginEmail, _failedLoginEmail); - PlayerPrefs.Save(); + SequencePrefs.SetInt(WaaSLoginMethod, (int)_failedLoginMethod); + SequencePrefs.SetString(OpenIdAuthenticator.LoginEmail, _failedLoginEmail); + SequencePrefs.Save(); } public async Task ConnectToWaaSViaPlayFab(string titleId, string sessionTicket, string email) @@ -610,7 +612,7 @@ private void StoreWalletSecurely(string waasWalletAddress, string email) byte[] privateKeyBytes = new byte[32]; _sessionWallet.privKey.WriteToSpan(privateKeyBytes); string privateKey = privateKeyBytes.ByteArrayToHexString(); - secureStorage.StoreString(Application.companyName + "-" + Application.productName + "-" + _walletKey, privateKey + "-" + waasWalletAddress + "-" + email); + secureStorage.StoreString(AppEnvironment.CompanyName + "-" + AppEnvironment.ProductName + "-" + _walletKey, privateKey + "-" + waasWalletAddress + "-" + email); } public async Task FederateAccount(IntentDataFederateAccount federateAccount, LoginMethod method, string email) @@ -625,9 +627,9 @@ public async Task FederateAccount(IntentDataFederateAccount federateAccount, Log throw new Exception($"Email received from WaaS server doesn't match, received {responseEmail}, sent {email}"); } - PlayerPrefs.SetInt(WaaSLoginMethod, (int)method); - PlayerPrefs.SetString(OpenIdAuthenticator.LoginEmail, email); - PlayerPrefs.Save(); + SequencePrefs.SetInt(WaaSLoginMethod, (int)method); + SequencePrefs.SetString(OpenIdAuthenticator.LoginEmail, email); + SequencePrefs.Save(); _failedLoginEmail = ""; _failedLoginIntent = null; _failedLoginMethod = LoginMethod.None; diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/SequenceWallet.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/SequenceWallet.cs index 2aa799190..bad16ff8f 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/SequenceWallet.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/SequenceWallet.cs @@ -5,7 +5,6 @@ using Sequence.ABI; using Sequence.Config; using Sequence.Utils; -using UnityEngine; namespace Sequence.EmbeddedWallet { @@ -117,7 +116,7 @@ private async Task SendTransactionIntent(IntentDataSendTransa } catch (Exception e) { - Debug.LogError("Transaction was successful, but we're unable to obtain the transaction hash. Reason: " + e.Message); + LogHandler.Error("Transaction was successful, but we're unable to obtain the transaction hash. Reason: " + e.Message); OnSendTransactionComplete?.Invoke(successfulTransactionReturn); return result; } @@ -221,7 +220,7 @@ public async Task DropSession(string dropSessionId) } else { - Debug.LogError("Failed to drop sessionId: " + dropSessionId); + LogHandler.Error("Failed to drop sessionId: " + dropSessionId); } return result; } @@ -241,7 +240,7 @@ public async Task ListSessions() } catch (Exception e) { - Debug.LogWarning("Failed to list sessions: " + e.Message); + LogHandler.Warning("Failed to list sessions: " + e.Message); } OnSessionsFound?.Invoke(results); return results; @@ -257,7 +256,7 @@ public async Task WaitForTransactionReceipt(Success } catch (Exception e) { - Debug.LogError("Transaction was successful, but we're unable to obtain the transaction hash. Reason: " + e.Message); + LogHandler.Error("Transaction was successful, but we're unable to obtain the transaction hash. Reason: " + e.Message); return successfulTransactionReturn; } } diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/SessionManager.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/SessionManager.cs index 45c7b4b53..e63d057a4 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/SessionManager.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/SessionManager.cs @@ -1,3 +1,4 @@ +#if UNITY_2017_1_OR_NEWER using System; using System.Collections.Generic; using Sequence.Config; @@ -52,4 +53,6 @@ private void OnDestroy() _sessions = new List(); } } -} \ No newline at end of file +} + +#endif diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/ABI.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/ABI.cs index 353d4ad4a..46ee8d6ba 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/ABI.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/ABI.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Numerics; using System.Text; -using UnityEngine; using Sequence.Utils; namespace Sequence.ABI @@ -271,7 +270,7 @@ public static string FunctionSelector(string functionSignature) } catch (Exception ex) { - Debug.LogError($"Error generating function selector: {ex.Message}"); + LogHandler.Error($"Error generating function selector: {ex.Message}"); return string.Empty; } } @@ -351,7 +350,7 @@ public static ABIType GetParameterType(object param) } catch (Exception ex) { - Debug.LogError($"Error determining parameter type: {ex.Message}"); + LogHandler.Error($"Error determining parameter type: {ex.Message}"); } return ABIType.NONE; diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/AddressCoder.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/AddressCoder.cs index b62a577b6..dfe117ce4 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/AddressCoder.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/AddressCoder.cs @@ -1,6 +1,5 @@ - using System; -using UnityEngine; +using Sequence.Utils; namespace Sequence.ABI { @@ -24,7 +23,7 @@ public object Decode(byte[] encoded) } catch (Exception ex) { - Debug.LogError($"Failed to decode address: {ex.Message}"); + LogHandler.Error($"Failed to decode address: {ex.Message}"); return null; } } @@ -45,7 +44,7 @@ public byte[] Encode(object value) } catch (Exception ex) { - Debug.LogError($"Failed to encode address: {ex.Message}"); + LogHandler.Error($"Failed to encode address: {ex.Message}"); return new byte[0]; } } @@ -79,7 +78,7 @@ public string EncodeToString(object value) } catch (Exception ex) { - Debug.LogError($"Failed to encode address to string: {ex.Message}"); + LogHandler.Error($"Failed to encode address to string: {ex.Message}"); return string.Empty; } } @@ -99,7 +98,7 @@ public string DecodeFromString(string encodedString) } catch (Exception ex) { - Debug.LogError($"Failed to decode address from string: {ex.Message}"); + LogHandler.Error($"Failed to decode address from string: {ex.Message}"); return string.Empty; } } @@ -118,7 +117,7 @@ public static string Decode(string encodedString) } catch (Exception ex) { - Debug.LogError($"Failed to decode address: {ex.Message}"); + LogHandler.Error($"Failed to decode address: {ex.Message}"); return null; } } diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/ArrayCoder.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/ArrayCoder.cs index 7c28be57a..1266e1b2a 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/ArrayCoder.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/ArrayCoder.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using UnityEngine; +using Sequence.Utils; namespace Sequence.ABI { @@ -31,7 +31,7 @@ public byte[] Encode(List value, string evmType) } catch (Exception ex) { - Debug.LogError($"Error encoding array: {ex.Message}"); + LogHandler.Error($"Error encoding array: {ex.Message}"); return null; } } @@ -52,7 +52,7 @@ public string EncodeToString(List value, string evmType) } catch (Exception ex) { - Debug.LogError($"Error encoding array to string: {ex.Message}"); + LogHandler.Error($"Error encoding array to string: {ex.Message}"); return null; } } diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/BooleanCoder.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/BooleanCoder.cs index 6df180347..8985f9fe2 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/BooleanCoder.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/BooleanCoder.cs @@ -1,5 +1,5 @@ using System; -using UnityEngine; +using Sequence.Utils; namespace Sequence.ABI { @@ -21,7 +21,7 @@ public object Decode(byte[] encoded) } catch (Exception ex) { - Debug.LogError($"Error decoding boolean: {ex.Message}"); + LogHandler.Error($"Error decoding boolean: {ex.Message}"); return null; } } @@ -42,7 +42,7 @@ public byte[] Encode(object value) } catch (Exception ex) { - Debug.LogError($"Error encoding boolean: {ex.Message}"); + LogHandler.Error($"Error encoding boolean: {ex.Message}"); return null; } } @@ -64,7 +64,7 @@ public string EncodeToString(object value) } catch (Exception ex) { - Debug.LogError($"Error encoding boolean to string: {ex.Message}"); + LogHandler.Error($"Error encoding boolean to string: {ex.Message}"); return null; } } @@ -84,7 +84,7 @@ public bool DecodeFromString(string encodedString) } catch (Exception ex) { - Debug.LogError($"Error decoding boolean from string: {ex.Message}"); + LogHandler.Error($"Error decoding boolean from string: {ex.Message}"); return false; } } diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/BytesCoder.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/BytesCoder.cs index 93442d47d..0efc8ab0e 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/BytesCoder.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/BytesCoder.cs @@ -1,5 +1,5 @@ using System; -using UnityEngine; +using Sequence.Utils; namespace Sequence.ABI { @@ -26,7 +26,7 @@ public object Decode(byte[] encoded) } catch (Exception ex) { - Debug.LogError($"Error decoding byte array: {ex.Message}"); + LogHandler.Error($"Error decoding byte array: {ex.Message}"); return null; } } @@ -51,7 +51,7 @@ public byte[] Encode(object value) } catch (Exception ex) { - Debug.LogError($"Error encoding byte array: {ex.Message}"); + LogHandler.Error($"Error encoding byte array: {ex.Message}"); return null; } } @@ -70,7 +70,7 @@ public string EncodeToString(object value) } catch (Exception ex) { - Debug.LogError($"Error encoding byte array to string: {ex.Message}"); + LogHandler.Error($"Error encoding byte array to string: {ex.Message}"); return null; } } @@ -96,7 +96,7 @@ public string DecodeFromString(string encodedString) } catch (Exception ex) { - Debug.LogError($"Error decoding byte array from string: {ex.Message}"); + LogHandler.Error($"Error decoding byte array from string: {ex.Message}"); return null; } } diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/FixedBytesCoder.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/FixedBytesCoder.cs index d68dc13cc..8277804b0 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/FixedBytesCoder.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/FixedBytesCoder.cs @@ -2,7 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.Numerics; -using UnityEngine; +using Sequence.Utils; namespace Sequence.ABI { @@ -24,7 +24,7 @@ public object Decode(byte[] encoded) } catch (Exception ex) { - Debug.LogError($"Error decoding byte array: {ex.Message}"); + LogHandler.Error($"Error decoding byte array: {ex.Message}"); return null; } } @@ -47,7 +47,7 @@ public byte[] Encode(object value) } catch (Exception ex) { - Debug.LogError($"Error encoding byte array: {ex.Message}"); + LogHandler.Error($"Error encoding byte array: {ex.Message}"); return null; } } @@ -76,7 +76,7 @@ public string EncodeToString(object value) } catch (Exception ex) { - Debug.LogError($"Error encoding byte array to string: {ex.Message}"); + LogHandler.Error($"Error encoding byte array to string: {ex.Message}"); return null; } } @@ -97,7 +97,7 @@ public string DecodeFromString(string encodedString) } catch (Exception ex) { - Debug.LogError($"Error decoding byte array from string: {ex.Message}"); + LogHandler.Error($"Error decoding byte array from string: {ex.Message}"); return null; } } diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/NumberCoder.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/NumberCoder.cs index 51269c5ed..9217d67f1 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/NumberCoder.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/NumberCoder.cs @@ -1,6 +1,6 @@ using System; using System.Numerics; -using UnityEngine; +using Sequence.Utils; namespace Sequence.ABI { @@ -41,7 +41,7 @@ public object Decode(byte[] encoded) } catch (Exception ex) { - Debug.LogError($"Error decoding number: {ex.Message}"); + LogHandler.Error($"Error decoding number: {ex.Message}"); return null; } } @@ -75,7 +75,7 @@ public byte[] Encode(object number) } catch (Exception ex) { - Debug.LogError($"Error encoding number: {ex.Message}"); + LogHandler.Error($"Error encoding number: {ex.Message}"); return null; } } @@ -108,7 +108,7 @@ public string EncodeToString(object number) } catch (Exception ex) { - Debug.LogError($"Error encoding number to string: {ex.Message}"); + LogHandler.Error($"Error encoding number to string: {ex.Message}"); return null; } } @@ -127,7 +127,7 @@ public object DecodeFromString(string encodedString) } catch (Exception ex) { - Debug.LogError($"Error decoding number from string: {ex.Message}"); + LogHandler.Error($"Error decoding number from string: {ex.Message}"); return null; } } @@ -149,7 +149,7 @@ public byte[] EncodeSignedInt(BigInteger number, int length) } catch (Exception ex) { - Debug.LogError("Exception occurred during EncodeSignedInt: " + ex.Message); + LogHandler.Error("Exception occurred during EncodeSignedInt: " + ex.Message); throw; } } @@ -179,7 +179,7 @@ public string EncodeSignedIntString(BigInteger number, int length) } catch (Exception ex) { - Debug.LogError("Exception occurred during EncodeSignedIntString: " + ex.Message); + LogHandler.Error("Exception occurred during EncodeSignedIntString: " + ex.Message); throw; } } @@ -201,7 +201,7 @@ public byte[] EncodeUnsignedInt(BigInteger number, int length) } catch (Exception ex) { - Debug.LogError("Exception occurred during EncodeUnsignedInt: " + ex.Message); + LogHandler.Error("Exception occurred during EncodeUnsignedInt: " + ex.Message); throw; } } @@ -223,7 +223,7 @@ public string EncodeUnsignedIntString(BigInteger number, int length) } catch (Exception ex) { - Debug.LogError("Exception occurred during EncodeUnsignedIntString: " + ex.Message); + LogHandler.Error("Exception occurred during EncodeUnsignedIntString: " + ex.Message); throw; } } diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/StaticBytesCoder.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/StaticBytesCoder.cs index b17513246..039b917d1 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/StaticBytesCoder.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/StaticBytesCoder.cs @@ -1,7 +1,5 @@ using System; -using System.Collections; -using System.Collections.Generic; -using UnityEngine; +using Sequence.Utils; namespace Sequence.ABI { @@ -22,7 +20,7 @@ public object Decode(byte[] encoded) } catch (Exception ex) { - Debug.LogError("Exception occurred during Decode: " + ex.Message); + LogHandler.Error("Exception occurred during Decode: " + ex.Message); throw; } } @@ -47,7 +45,7 @@ public byte[] Encode(object value) } catch (Exception ex) { - Debug.LogError("Exception occurred during Encode: " + ex.Message); + LogHandler.Error("Exception occurred during Encode: " + ex.Message); throw; } } @@ -68,7 +66,7 @@ public string EncodeToString(object value) catch (Exception ex) { - Debug.LogError("Exception occurred during EncodeToString: " + ex.Message); + LogHandler.Error("Exception occurred during EncodeToString: " + ex.Message); throw; } } @@ -96,7 +94,7 @@ public string DecodeFromString(string encodedString) catch (Exception ex) { - Debug.LogError("Exception occurred during DecodeFromString: " + ex.Message); + LogHandler.Error("Exception occurred during DecodeFromString: " + ex.Message); throw; } } diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/StringCoder.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/StringCoder.cs index 08cf489d8..048cf86f7 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/StringCoder.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/StringCoder.cs @@ -1,6 +1,6 @@ using System; using System.Text; -using UnityEngine; +using Sequence.Utils; namespace Sequence.ABI { @@ -24,7 +24,7 @@ public object Decode(byte[] encoded) } catch (Exception ex) { - Debug.LogError("Exception occurred during Decode: " + ex.Message); + LogHandler.Error("Exception occurred during Decode: " + ex.Message); throw; } } @@ -48,7 +48,7 @@ public byte[] Encode(object value) } catch (Exception ex) { - Debug.LogError("Exception occurred during Encode: " + ex.Message); + LogHandler.Error("Exception occurred during Encode: " + ex.Message); throw; } } @@ -66,7 +66,7 @@ public string EncodeToString(object value) } catch (Exception ex) { - Debug.LogError("Exception occurred during EncodeToString: " + ex.Message); + LogHandler.Error("Exception occurred during EncodeToString: " + ex.Message); throw; } } @@ -85,7 +85,7 @@ public string DecodeFromString(string encodedString) } catch (Exception ex) { - Debug.LogError("Exception occurred during DecodeFromString: " + ex.Message); + LogHandler.Error("Exception occurred during DecodeFromString: " + ex.Message); throw; } } diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/TupleCoder.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/TupleCoder.cs index 2d6885921..2a705ebfb 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/TupleCoder.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Coders/TupleCoder.cs @@ -5,6 +5,7 @@ using System.Text; using System; using Sequence.Utils; +using Sequence.Utils; namespace Sequence.ABI @@ -84,56 +85,56 @@ public string EncodeToString(object value, string[] evmTypes) { //Statics: head(X(i)) = enc(X(i) and tail(X(i)) = "" (the empty string) case ABIType.BOOLEAN: - UnityEngine.Debug.Log("object in tuple array: boolean"); + LogHandler.Info("object in tuple array: boolean"); head_i = _booleanCoder.EncodeToString(valueTuple[i]); break; case ABIType.NUMBER: - UnityEngine.Debug.Log("object in tuple array: number"); + LogHandler.Info("object in tuple array: number"); head_i = _numberCoder.EncodeToString(valueTuple[i]); break; case ABIType.ADDRESS: - UnityEngine.Debug.Log("object in tuple array: address"); + LogHandler.Info("object in tuple array: address"); head_i = _addressCoder.EncodeToString(valueTuple[i]); break; case ABIType.FIXEDBYTES: - UnityEngine.Debug.Log("object in tuple array: static bytes"); + LogHandler.Info("object in tuple array: static bytes"); head_i = _staticBytesCoder.EncodeToString(valueTuple[i]); break; //Dynamics: head(X(i)) = enc(len( head(X(1)) ... head(X(k)) tail(X(1)) ... tail(X(i-1)) )) tail(X(i)) = enc(X(i)) case ABIType.BYTES: - UnityEngine.Debug.Log("object in tuple array: bytes"); + LogHandler.Info("object in tuple array: bytes"); head_i = _numberCoder.EncodeToString((object)(headerTotalByteLength + tailLength)); tail_i = _fixedBytesCoder.EncodeToString(valueTuple[i]); break; case ABIType.STRING: - UnityEngine.Debug.Log("object in tuple array: string"); + LogHandler.Info("object in tuple array: string"); Encoding utf8 = Encoding.UTF8; head_i = _numberCoder.EncodeToString((object)(headerTotalByteLength + tailLength)); tail_i = _fixedBytesCoder.EncodeToString(utf8.GetBytes((string)valueTuple[i])); break; case ABIType.DYNAMICARRAY: - UnityEngine.Debug.Log("object in tuple array: dynamic array"); + LogHandler.Info("object in tuple array: dynamic array"); head_i = _numberCoder.EncodeToString((object)(headerTotalByteLength + tailLength)); - UnityEngine.Debug.Log("dynamic array head: " + head_i); + LogHandler.Info("dynamic array head: " + head_i); //intList.Cast().ToList(); int numberCount = ((IList)valueTuple[i]).Count; - UnityEngine.Debug.Log("number count:" + numberCount); + LogHandler.Info("number count:" + numberCount); string numberCountEncoded = _numberCoder.EncodeToString(numberCount); - UnityEngine.Debug.Log("dynamic array tail number count: " + numberCountEncoded); + LogHandler.Info("dynamic array tail number count: " + numberCountEncoded); tail_i = numberCountEncoded + EncodeToString(valueTuple[i], ArrayUtils.BuildArrayWithRepeatedValue(ABI.GetUnderlyingCollectionTypeName(evmTypes[i]), numberCount)); - UnityEngine.Debug.Log("dynamic array tail: " + tail_i); + LogHandler.Info("dynamic array tail: " + tail_i); break; case ABIType.FIXEDARRAY: - UnityEngine.Debug.Log("object in tuple array: fixed array"); + LogHandler.Info("object in tuple array: fixed array"); numberCount = ABI.GetInnerValue(evmTypes[i]); head_i = EncodeToString(valueTuple[i], ArrayUtils.BuildArrayWithRepeatedValue(ABI.GetUnderlyingCollectionTypeName(evmTypes[i]), numberCount)); break; case ABIType.TUPLE: - UnityEngine.Debug.Log("object in tuple array: tuple"); + LogHandler.Info("object in tuple array: tuple"); head_i = _numberCoder.EncodeToString((object)(headerTotalByteLength + tailLength)); tail_i = EncodeToString(valueTuple[i], ABI.GetTupleTypes(evmTypes[i])); break; diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/FunctionAbi.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/FunctionAbi.cs index 052c9d7a4..eecbf401d 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/FunctionAbi.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/FunctionAbi.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Text; using Sequence.Utils; -using UnityEditor; namespace Sequence.ABI { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/SequenceCoder.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/SequenceCoder.cs index 0538dfcd8..32689aa15 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/SequenceCoder.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/SequenceCoder.cs @@ -1,8 +1,6 @@ using System; using System.Text; using Org.BouncyCastle.Crypto.Digests; -using UnityEngine; -using Sequence; using Sequence.Utils; namespace Sequence.ABI @@ -60,7 +58,7 @@ public static string AddressChecksum(string address) } catch (Exception ex) { - Debug.LogError($"Error computing checksum address({address}): {ex.Message}"); + LogHandler.Error($"Error computing checksum address({address}): {ex.Message}"); return address; } } @@ -87,7 +85,7 @@ public static string KeccakHashASCII(string input) } catch (Exception ex) { - Debug.LogError($"Error computing Keccak-256 hash: {ex.Message}"); + LogHandler.Error($"Error computing Keccak-256 hash: {ex.Message}"); return string.Empty; } } @@ -112,7 +110,7 @@ public static byte[] KeccakHash(byte[] input) } catch (Exception ex) { - Debug.LogError($"Error computing Keccak-256 hash: {ex.Message}"); + LogHandler.Error($"Error computing Keccak-256 hash: {ex.Message}"); return new byte[0]; } } @@ -132,7 +130,7 @@ public static string KeccakHash(string input) } catch (Exception ex) { - Debug.LogError($"Error computing Keccak-256 hash: {ex.Message}"); + LogHandler.Error($"Error computing Keccak-256 hash: {ex.Message}"); return string.Empty; } } @@ -191,7 +189,7 @@ public static byte[] HexStringToByteArray(string hexString) } catch (Exception ex) { - Debug.LogError($"Error converting hexadecimal string to byte array: {ex.Message}"); + LogHandler.Error($"Error converting hexadecimal string to byte array: {ex.Message}"); return new byte[0]; } } diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Types/ABIDataTypes.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Types/ABIDataTypes.cs index bf55a624e..e62df381d 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Types/ABIDataTypes.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/ABI/Types/ABIDataTypes.cs @@ -2,7 +2,6 @@ using System.Collections; using System.Collections.Generic; using System.Text; -using UnityEngine; namespace Sequence.ABI { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Contract/Contract.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Contract/Contract.cs index e18f51f6b..94a42deb2 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Contract/Contract.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Contract/Contract.cs @@ -4,12 +4,8 @@ using System; using System.Numerics; using Sequence.ABI; +using Sequence.Utils; using Sequence.Provider; -using Sequence.Transactions; -using System.Text; -using System.Text.RegularExpressions; -using Sequence.Wallet; -using UnityEngine; namespace Sequence.Contracts { @@ -35,7 +31,7 @@ public Contract(string contractAddress, string abi = null) this._abi = abi; if (abi == null) { - Debug.LogWarning("Creating a contract with a null ABI is not recommended. Note: Using a null abi will require you to provide the full function signature when transacting/querying the contract. Using a null abi will cause all query responses to return as a string."); + LogHandler.Warning("Creating a contract with a null ABI is not recommended. Note: Using a null abi will require you to provide the full function signature when transacting/querying the contract. Using a null abi will cause all query responses to return as a string."); this._functionAbi = null; } else @@ -74,7 +70,7 @@ private string ValidateFunctionNameRegex(string functionName) { string message = $"Given invalid {nameof(functionName)}, given: {functionName}; expected to regex match {ABIRegex.FunctionABIRegex} - for example: \"mint(uint256,uint256)\""; - Debug.LogWarning(message + "\nAttempting to recover and parse anyways"); + LogHandler.Warning(message + "\nAttempting to recover and parse anyways"); functionName = EventParser.ParseEventDef(functionName).ToString(); if (!ABIRegex.MatchesFunctionABI(functionName)) { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Contract/ContractDeployer.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Contract/ContractDeployer.cs index 6f28d6d3c..ce14ffd36 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Contract/ContractDeployer.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Contract/ContractDeployer.cs @@ -4,8 +4,6 @@ using Sequence.ABI; using Sequence.Provider; using Sequence.Wallet; -using UnityEngine; -using Sequence.Transactions; using Sequence.Utils; namespace Sequence.Contracts @@ -51,7 +49,7 @@ public static string CalculateContractAddress(BigInteger nonce, string senderAdd byte[] hashed = SequenceCoder.KeccakHash(encoded); string hashedString = SequenceCoder.ByteArrayToHexString(hashed).EnsureHexPrefix(); string address = hashedString.Substring(hashedString.Length - 40, 40).EnsureHexPrefix(); - Debug.Log($"Deployer {senderAddress}, nonce {nonce} - deployed to {address}"); + LogHandler.Info($"Deployer {senderAddress}, nonce {nonce} - deployed to {address}"); return address; } } diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Contract/ContractQuerySender.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Contract/ContractQuerySender.cs index 28297dd53..540bb3922 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Contract/ContractQuerySender.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Contract/ContractQuerySender.cs @@ -3,8 +3,6 @@ using System.Numerics; using System.Threading.Tasks; using Sequence.Provider; -using Sequence.Wallet; -using UnityEngine; using static Sequence.Contracts.Contract; namespace Sequence.Contracts diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Contract/ContractTransactionSender.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Contract/ContractTransactionSender.cs index fbf3f4eba..b497f73ef 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Contract/ContractTransactionSender.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Contract/ContractTransactionSender.cs @@ -5,8 +5,6 @@ using Sequence.Provider; using Sequence.Wallet; using Sequence.Transactions; -using UnityEngine; -using static Sequence.Contracts.Contract; namespace Sequence.Contracts { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Contract/ERC1155.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Contract/ERC1155.cs index 67f2a4a46..61f774d67 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Contract/ERC1155.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Contract/ERC1155.cs @@ -8,8 +8,6 @@ using Sequence.ABI; using Sequence.Provider; using Sequence.Utils; -using UnityEngine; -using static Sequence.Contracts.Contract; namespace Sequence.Contracts { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Contract/ERC20.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Contract/ERC20.cs index dcf273f7d..7c4ad357d 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Contract/ERC20.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Contract/ERC20.cs @@ -3,9 +3,7 @@ using System.Threading.Tasks; using Sequence.ABI; using Sequence.Provider; -using UnityEngine; using System.Numerics; -using static Sequence.Contracts.Contract; namespace Sequence.Contracts { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Contract/ERC721.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Contract/ERC721.cs index 28c117a83..edc9f0ff0 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Contract/ERC721.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Contract/ERC721.cs @@ -4,8 +4,6 @@ using System.Threading.Tasks; using Sequence.ABI; using Sequence.Provider; -using UnityEngine; -using static Sequence.Contracts.Contract; namespace Sequence.Contracts { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Contract/Ownable.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Contract/Ownable.cs index 6b55fcbd6..2993a35ed 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Contract/Ownable.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Contract/Ownable.cs @@ -2,8 +2,6 @@ using System.Collections.Generic; using System.Threading.Tasks; using Sequence.Provider; -using UnityEngine; -using static Sequence.Contracts.Contract; namespace Sequence.Contracts { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Provider/HttpRpcClient.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Provider/HttpRpcClient.cs index 1c5f82f61..0730d73db 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Provider/HttpRpcClient.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Provider/HttpRpcClient.cs @@ -3,14 +3,10 @@ using System.IO; using System.Net.Http; using System.Numerics; -using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; using Sequence.Config; using Sequence.Utils; -using UnityEngine; -using UnityEngine.Networking; - namespace Sequence.Provider { @@ -43,26 +39,25 @@ public async Task SendRequest(string requestJson) throw SequenceConfig.MissingConfigError("Builder API Key"); } - using var request = UnityWebRequest.Put(_url, requestJson); + using var request = WebRequestBuilder.Post(_url, requestJson); request.SetRequestHeader("Content-Type", "application/json"); request.SetRequestHeader("Accept", "application/json"); request.SetRequestHeader("X-Access-Key", _builderApiKey); - request.method = UnityWebRequest.kHttpVerbPOST; - string curlRequest = $"curl -X {request.method} '{_url}' -H 'Content-Type: {request.GetRequestHeader("Content-Type")}' -H 'Accept: {request.GetRequestHeader("Accept")}' -H 'X-Access-Key: {request.GetRequestHeader("X-Access-Key")}' -d '{requestJson}'"; + string curlRequest = $"curl -X {request.Method} '{_url}' -H 'Content-Type: {request.GetRequestHeader("Content-Type")}' -H 'Accept: {request.GetRequestHeader("Accept")}' -H 'X-Access-Key: {request.GetRequestHeader("X-Access-Key")}' -d '{requestJson}'"; try { - await request.SendWebRequest(); + var response = await request.Send(); - if (request.error != null || request.result != UnityWebRequest.Result.Success || request.responseCode < 200 || request.responseCode > 299) + if (request.Error != null || response.Result != WebRequestResult.Success || response.ResponseCode < 200 || response.ResponseCode > 299) { - throw new Exception($"Error sending request to {_url}: {request.responseCode} {request.error}"); + throw new Exception($"Error sending request to {_url}: {response.ResponseCode} {request.Error}"); } else { - byte[] results = request.downloadHandler.data; + byte[] results = request.Data; request.Dispose(); var responseJson = Encoding.UTF8.GetString(results); @@ -79,18 +74,18 @@ public async Task SendRequest(string requestJson) } catch (HttpRequestException e) { - throw new Exception("HTTP Request failed: " + e.Message + " reason: " + Encoding.UTF8.GetString(request.downloadHandler.data) + "\nCurl-equivalent request: " + curlRequest); + throw new Exception("HTTP Request failed: " + e.Message + " reason: " + Encoding.UTF8.GetString(request.Data) + "\nCurl-equivalent request: " + curlRequest); } catch (FormatException e) { - throw new Exception("Invalid URL format: " + e.Message + " reason: " + Encoding.UTF8.GetString(request.downloadHandler.data) + "\nCurl-equivalent request: " + curlRequest); + throw new Exception("Invalid URL format: " + e.Message + " reason: " + Encoding.UTF8.GetString(request.Data) + "\nCurl-equivalent request: " + curlRequest); } catch (FileLoadException e) { - throw new Exception("File load exception: " + e.Message + " reason: " + Encoding.UTF8.GetString(request.downloadHandler.data) + "\nCurl-equivalent request: " + curlRequest); + throw new Exception("File load exception: " + e.Message + " reason: " + Encoding.UTF8.GetString(request.Data) + "\nCurl-equivalent request: " + curlRequest); } catch (Exception e) { - throw new Exception("An unexpected error occurred: " + e.Message + " reason: " + Encoding.UTF8.GetString(request.downloadHandler.data) + "\nCurl-equivalent request: " + curlRequest); + throw new Exception("An unexpected error occurred: " + e.Message + " reason: " + Encoding.UTF8.GetString(request.Data) + "\nCurl-equivalent request: " + curlRequest); } finally { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Provider/IEthClient.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Provider/IEthClient.cs index d910ebde1..52b231ad4 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Provider/IEthClient.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Provider/IEthClient.cs @@ -2,8 +2,6 @@ using System.Collections.Generic; using System.Numerics; using System.Threading.Tasks; -using Sequence.Wallet; -using UnityEngine; namespace Sequence.Provider { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Provider/IRpcClient.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Provider/IRpcClient.cs index bd569642d..368c83c74 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Provider/IRpcClient.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Provider/IRpcClient.cs @@ -2,8 +2,6 @@ using System.Collections.Generic; using System.Numerics; using System.Threading.Tasks; -using Sequence.Wallet; -using UnityEngine; namespace Sequence.Provider { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Provider/NodeGatewayBridge.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Provider/NodeGatewayBridge.cs index 693e9ea7f..d8820b97f 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Provider/NodeGatewayBridge.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Provider/NodeGatewayBridge.cs @@ -7,7 +7,7 @@ namespace Sequence.Provider { public static class NodeGatewayBridge { - private static SequenceConfig _config = SequenceConfig.GetConfig(SequenceService.NodeGateway); + private static SequenceConfigBase _configBase = SequenceConfig.GetConfig(SequenceService.NodeGateway); #if SEQUENCE_DEV_NODEGATEWAY || SEQUENCE_DEV private const string _baseUrl = "https://dev-nodes.sequence.app/"; @@ -23,7 +23,7 @@ public static string GetNodeGatewayUrl(Chain chain) "Network is not supported. Please contact Sequence support and use your own RPC url in the meantime"); } - string builderApiKey = _config.BuilderAPIKey; + string builderApiKey = _configBase.BuilderAPIKey; if (string.IsNullOrWhiteSpace(builderApiKey)) { throw SequenceConfig.MissingConfigError("Builder API Key"); diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Provider/RpcRequest.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Provider/RpcRequest.cs index e82fa55dd..9887d76bd 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Provider/RpcRequest.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Provider/RpcRequest.cs @@ -1,5 +1,5 @@ using System.Numerics; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.Provider { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Provider/SequenceEthClient.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Provider/SequenceEthClient.cs index 20da2162e..56e4df9b8 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Provider/SequenceEthClient.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Provider/SequenceEthClient.cs @@ -5,7 +5,6 @@ using System.Threading.Tasks; using Newtonsoft.Json; using Sequence.Utils; -using UnityEngine; namespace Sequence.Provider { @@ -311,12 +310,12 @@ public Task TransactionSender(string blockHash, BigInteger tr public async Task WaitForTransactionReceipt(string transactionHash, int maxWaitTimeInMilliseconds = 15000, int timeBetweenChecksInMilliseconds = 500) { TransactionReceipt receipt = null; - float startTime = Time.time; + float startTime = AppEnvironment.Time; while (receipt == null) { receipt = await TransactionReceipt(transactionHash); - float elapsedTime = Time.time - startTime; + float elapsedTime = AppEnvironment.Time - startTime; if (elapsedTime * 1000 + timeBetweenChecksInMilliseconds >= maxWaitTimeInMilliseconds) { return receipt; diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/RLP/RLP.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/RLP/RLP.cs index 660040f4c..e7b095ab7 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/RLP/RLP.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/RLP/RLP.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Text; using Sequence.Utils; -using UnityEngine; namespace Sequence.RLP { @@ -112,16 +111,16 @@ public static object Decode(byte[] input) if (type == typeof(string)) { output = Encoding.UTF8.GetString(input).Substring(offset, dataLen); - UnityEngine.Debug.Log("output: " + output); + LogHandler.Info("output: " + output); return output; } else if (type == typeof(List)) { - UnityEngine.Debug.Log("input length: " + input.Length); + LogHandler.Info("input length: " + input.Length); while (offset(); int _offset= 0, _dataLen = 1; @@ -131,11 +130,11 @@ public static object Decode(byte[] input) byte[] restInput = new byte[dataLen]; Array.Copy(input, offset, restInput, 0, dataLen); ( _offset, _dataLen, _type) = DecodeLength(restInput); - UnityEngine.Debug.Log("Decode _offset: " + _offset); - UnityEngine.Debug.Log("Decode _dataLen: " + _dataLen); - UnityEngine.Debug.Log("Decode _type: " + _type); + LogHandler.Info("Decode _offset: " + _offset); + LogHandler.Info("Decode _dataLen: " + _dataLen); + LogHandler.Info("Decode _type: " + _type); rtn = Decode(restInput); - UnityEngine.Debug.Log("rtn: " + rtn); + LogHandler.Info("rtn: " + rtn); // outputList.Add(rtn); /*offset += _dataLen; @@ -145,15 +144,15 @@ public static object Decode(byte[] input) } else { - UnityEngine.Debug.Log("rtn: " + ((List)rtn).Count); + LogHandler.Info("rtn: " + ((List)rtn).Count); //outputList.Add(rtn); return outputList; } outputList.Add(rtn); - UnityEngine.Debug.Log("Decode offset!: " + offset); - UnityEngine.Debug.Log("Decode dataLen!: " + dataLen); + LogHandler.Info("Decode offset!: " + offset); + LogHandler.Info("Decode dataLen!: " + dataLen); } return outputList; @@ -173,14 +172,14 @@ public static object Decode(byte[] input) private static (int, int, Type) DecodeLength(byte[] input) { int length = input.Length; - UnityEngine.Debug.Log("Decode input length: " + length); + LogHandler.Info("Decode input length: " + length); if (length == 0) { throw new Exception("Input is null"); } int firstByte = input[0]; - UnityEngine.Debug.Log("Decode firstbyte: " + firstByte); + LogHandler.Info("Decode firstbyte: " + firstByte); if (firstByte <= 127) { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Transaction/EthTransaction.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Transaction/EthTransaction.cs index e7997a540..1408398a5 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Transaction/EthTransaction.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Transaction/EthTransaction.cs @@ -4,9 +4,6 @@ using System.Collections; using System.Collections.Generic; using System.Numerics; -using System.Threading.Tasks; -using Sequence.Provider; -using UnityEngine; using Sequence.Wallet; using Sequence.Utils; diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Transaction/TransferEth.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Transaction/TransferEth.cs index 295daed01..aeb8191ef 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Transaction/TransferEth.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Transaction/TransferEth.cs @@ -6,7 +6,6 @@ using Sequence.ABI; using Sequence.Provider; using Sequence.Wallet; -using UnityEngine; namespace Sequence.Transactions { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Wallet/IWallet.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Wallet/IWallet.cs index 08b7a4a71..5d067b8bf 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Wallet/IWallet.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Wallet/IWallet.cs @@ -10,7 +10,6 @@ using Sequence.Signer; using Sequence.Transactions; using Sequence.Utils; -using UnityEngine; namespace Sequence.Wallet { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Indexer/ChainIndexer.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Indexer/ChainIndexer.cs index 844c9b0ba..5a4bbd5af 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Indexer/ChainIndexer.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Indexer/ChainIndexer.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Numerics; using System.Threading.Tasks; -using UnityEngine; +using Sequence.Utils; namespace Sequence { @@ -47,7 +47,7 @@ public void OnQueryFailed(string error) error = "Indexer query failed: " + error; if (_logErrors) { - Debug.LogError(error); + LogHandler.Error(error); } OnQueryError?.Invoke(error); @@ -58,7 +58,7 @@ public void OnQueryEncounteredAnIssue(string error) string issue = "Indexer query encountered an issue: " + error; if (_logWarnings) { - Debug.LogWarning(issue); + LogHandler.Warning(issue); } OnQueryIssue?.Invoke(issue); diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Indexer/DownloadHandlerStream.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Indexer/DownloadHandlerStream.cs index 8e242dbd2..d040d19c4 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Indexer/DownloadHandlerStream.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Indexer/DownloadHandlerStream.cs @@ -1,11 +1,15 @@ using System; using System.Text; using Newtonsoft.Json; + +#if UNITY_2017_1_OR_NEWER using UnityEngine; using UnityEngine.Networking; +#endif namespace Sequence { +#if UNITY_2017_1_OR_NEWER public class DownloadHandlerStream : DownloadHandlerScript { private readonly WebRPCStreamOptions _options; @@ -52,4 +56,5 @@ protected override bool ReceiveData(byte[] data, int dataLength) } } } +#endif } \ No newline at end of file diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Indexer/HttpHandler.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Indexer/HttpHandler.cs index c3be84abb..ddbdbce6e 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Indexer/HttpHandler.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Indexer/HttpHandler.cs @@ -6,14 +6,12 @@ using System.Threading.Tasks; using Newtonsoft.Json; using Sequence.Utils; -using UnityEngine; -using UnityEngine.Networking; namespace Sequence { public class HttpHandler : IHttpHandler { - private static List _streams = new(); + private static List _streams = new(); private string _builderApiKey; private IIndexer _caller; @@ -32,27 +30,25 @@ public HttpHandler(string builderApiKey, IIndexer caller = null) public async Task HttpPost(string chainID, string endPoint, object args, int retries = 0) { string requestJson = JsonConvert.SerializeObject(args, serializerSettings); - using var req = UnityWebRequest.Put(Url(chainID, endPoint), requestJson); + using var req = WebRequestBuilder.Post(Url(chainID, endPoint), requestJson); req.SetRequestHeader("Content-Type", "application/json"); req.SetRequestHeader("Accept", "application/json"); req.SetRequestHeader("X-Access-Key", _builderApiKey); - req.method = UnityWebRequest.kHttpVerbPOST; - req.timeout = 10; // Request will timeout after 10 seconds + req.SetTimeout(10); // Request will timeout after 10 seconds string curlRequest = $"curl -X POST -H \"Content-Type: application/json\" -H \"Accept: application/json\" -H \"X-Access-Key: {req.GetRequestHeader("X-Access-Key")}\" -d '{requestJson}' {Url(chainID, endPoint)}"; try { - await req.SendWebRequest(); - if (req.responseCode < 200 || req.responseCode > 299 || req.error != null || - req.result == UnityWebRequest.Result.ConnectionError || - req.result == UnityWebRequest.Result.ProtocolError) + var response = await req.Send(); + if (response.ResponseCode < 200 || response.ResponseCode > 299 || req.Error != null || + response.Result == WebRequestResult.Failed) { - throw new Exception("Failed to make request, non-200 status code " + req.responseCode + - " with error: " + req.error + "\nCurl-equivalent request: " + curlRequest); + throw new Exception("Failed to make request, non-200 status code " + response.ResponseCode + + " with error: " + req.Error + "\nCurl-equivalent request: " + curlRequest); } - string returnText = req.downloadHandler.text; + string returnText = req.Text; req.Dispose(); return returnText; } @@ -109,14 +105,13 @@ public async Task HttpPost(string chainID, string endPoint, object args, public async void HttpStream(string chainID, string endPoint, object args, WebRPCStreamOptions options, int retries = 0) { var requestJson = JsonConvert.SerializeObject(args, serializerSettings); - using var req = UnityWebRequest.Put(Url(chainID, endPoint), requestJson); + using var req = WebRequestBuilder.Post(Url(chainID, endPoint), requestJson); req.SetRequestHeader("Content-Type", "application/json"); req.SetRequestHeader("X-Access-Key", _builderApiKey); - req.downloadHandler = new DownloadHandlerStream(options); - req.method = UnityWebRequest.kHttpVerbPOST; + //TODO: req.downloadHandler = new DownloadHandlerStream(options); _streams.Add(req); - await req.SendWebRequest(); + await req.Send(); if (_streams.Contains(req)) _streams.Remove(req); @@ -124,8 +119,8 @@ public async void HttpStream(string chainID, string endPoint, object args, We public void AbortStreams() { - foreach (var stream in _streams) - stream.Abort(); + /*TODO: foreach (var stream in _streams) + stream.Abort();*/ _streams.Clear(); } diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Indexer/Indexer.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Indexer/Indexer.cs index 49ff44fcc..e5bec1941 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Indexer/Indexer.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Indexer/Indexer.cs @@ -1,10 +1,8 @@ using System; -using UnityEngine; using System.Net.Http; using Newtonsoft.Json; using System.Threading.Tasks; using System.Collections.Generic; -using UnityEngine.Networking; using System.Numerics; using System.Runtime.CompilerServices; using System.IO; diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Integrations/Transak/DataTypes/OnOffRampQueryParameters.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Integrations/Transak/DataTypes/OnOffRampQueryParameters.cs index a71aa7a04..a9ca6f8ac 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Integrations/Transak/DataTypes/OnOffRampQueryParameters.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Integrations/Transak/DataTypes/OnOffRampQueryParameters.cs @@ -1,7 +1,3 @@ -using System; -using Newtonsoft.Json; -using UnityEngine; - namespace Sequence.Integrations.Transak { public class OnOffRampQueryParameters @@ -19,7 +15,11 @@ public OnOffRampQueryParameters(Address walletAddress, AddFundsSettings addFunds bool disableWalletAddressForm = true) { this.walletAddress = walletAddress; - this.referrerDomain = "sequence-unity: " + Application.productName; +#if UNITY_2017_1_OR_NEWER + this.referrerDomain = "sequence-unity: " + UnityEngine.Application.productName; +#else + this.referrerDomain = "sequence-unity"; +#endif this.fiatCurrency = addFundsSettings.fiatCurrency; this.disableWalletAddressForm = disableWalletAddressForm; this.defaultFiatAmount = addFundsSettings.defaultFiatAmount; diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Integrations/Transak/TransakOnRamp.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Integrations/Transak/TransakOnRamp.cs index 54da769e0..d5da276a1 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Integrations/Transak/TransakOnRamp.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Integrations/Transak/TransakOnRamp.cs @@ -5,8 +5,6 @@ using System.Threading.Tasks; using Newtonsoft.Json; using Sequence.Utils; -using UnityEngine; -using UnityEngine.Networking; namespace Sequence.Integrations.Transak { @@ -26,20 +24,20 @@ public TransakOnRamp(string walletAddress) public static async Task GetSupportedCountries() { - using UnityWebRequest request = UnityWebRequest.Get("https://api.transak.com/api/v2/countries"); - string url = request.url; + var url = "https://api.transak.com/api/v2/countries"; + using IWebRequest request = WebRequestBuilder.Get(url); string curlRequest = $"curl -X GET {url}"; try { - await request.SendWebRequest(); + var response = await request.Send(); - if (request.error != null || request.result != UnityWebRequest.Result.Success || request.responseCode < 200 || request.responseCode > 299) + if (request.Error != null || response.Result != WebRequestResult.Success || response.ResponseCode < 200 || response.ResponseCode > 299) { - throw new Exception($"Error sending request to {url}: {request.responseCode} {request.error}"); + throw new Exception($"Error sending request to {url}: {response.ResponseCode} {request.Error}"); } else { - byte[] results = request.downloadHandler.data; + byte[] results = request.Data; var responseJson = Encoding.UTF8.GetString(results); try { @@ -59,18 +57,18 @@ public static async Task GetSupportedCountries() } catch (HttpRequestException e) { - throw new Exception("HTTP Request failed: " + e.Message + " reason: " + Encoding.UTF8.GetString(request.downloadHandler.data) + "\nCurl-equivalent request: " + curlRequest); + throw new Exception("HTTP Request failed: " + e.Message + " reason: " + Encoding.UTF8.GetString(request.Data) + "\nCurl-equivalent request: " + curlRequest); } catch (FormatException e) { - throw new Exception("Invalid URL format: " + e.Message + " reason: " + Encoding.UTF8.GetString(request.downloadHandler.data) + "\nCurl-equivalent request: " + curlRequest); + throw new Exception("Invalid URL format: " + e.Message + " reason: " + Encoding.UTF8.GetString(request.Data) + "\nCurl-equivalent request: " + curlRequest); } catch (FileLoadException e) { - throw new Exception("File load exception: " + e.Message + " reason: " + Encoding.UTF8.GetString(request.downloadHandler.data) + "\nCurl-equivalent request: " + curlRequest); + throw new Exception("File load exception: " + e.Message + " reason: " + Encoding.UTF8.GetString(request.Data) + "\nCurl-equivalent request: " + curlRequest); } catch (Exception e) { - throw new Exception("An unexpected error occurred: " + e.Message + " reason: " + Encoding.UTF8.GetString(request.downloadHandler.data) + "\nCurl-equivalent request: " + curlRequest); + throw new Exception("An unexpected error occurred: " + e.Message + " reason: " + Encoding.UTF8.GetString(request.Data) + "\nCurl-equivalent request: " + curlRequest); } finally { @@ -87,7 +85,9 @@ public string GetTransakLink(string fiatCurrency = "USD", string defaultFiatAmou public void OpenTransakLink(string fiatCurrency = "USD", string defaultFiatAmount = "50", string defaultCryptoCurrency = AddFundsSettings.DefaultCryptoCurrency, string networks = AddFundsSettings.DefaultNetworks, bool disableWalletAddressForm = true) { - Application.OpenURL(GetTransakLink(fiatCurrency, defaultFiatAmount, defaultCryptoCurrency, networks, disableWalletAddressForm)); +#if UNITY_2017_1_OR_NEWER + UnityEngine.Application.OpenURL(GetTransakLink(fiatCurrency, defaultFiatAmount, defaultCryptoCurrency, networks, disableWalletAddressForm)); +#endif } } } \ No newline at end of file diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/CheckoutOption.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/CheckoutOption.cs index 6f4f329ce..f6a846e9a 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/CheckoutOption.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/CheckoutOption.cs @@ -1,4 +1,3 @@ -using UnityEngine; using Sequence.Marketplace; public interface ICheckoutOption { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/CheckoutOptions.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/CheckoutOptions.cs index 270d6c183..e24aa221b 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/CheckoutOptions.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/CheckoutOptions.cs @@ -1,7 +1,3 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - public enum CheckoutOptions { CryptoPurchase, diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/Asset.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/Asset.cs index 905f2d6c5..10460f418 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/Asset.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/Asset.cs @@ -1,5 +1,5 @@ using System.Numerics; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.Marketplace { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/CollectibleOrder.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/CollectibleOrder.cs index 8fed4721b..15b70603e 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/CollectibleOrder.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/CollectibleOrder.cs @@ -1,5 +1,5 @@ using System; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.Marketplace { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/CollectiblesFilter.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/CollectiblesFilter.cs index 76a00d1ee..4afe49d84 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/CollectiblesFilter.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/CollectiblesFilter.cs @@ -1,6 +1,6 @@ using System; using Newtonsoft.Json; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.Marketplace { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/FeeBreakdown.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/FeeBreakdown.cs index 59c923b3c..fbd73ab0d 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/FeeBreakdown.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/FeeBreakdown.cs @@ -1,6 +1,6 @@ using System; using System.Numerics; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.Marketplace { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/GetSwapPriceRequest.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/GetSwapPriceRequest.cs index 734a524bf..32106cf40 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/GetSwapPriceRequest.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/GetSwapPriceRequest.cs @@ -1,7 +1,6 @@ using System; using Newtonsoft.Json; -using UnityEngine.Scripting; -using UnityEngine.Serialization; +using Sequence.Utils; namespace Sequence.Marketplace { @@ -12,7 +11,12 @@ internal class GetSwapPriceRequest public string sellCurrencyAddress; public string buyAmount; public ulong chainId; - [FormerlySerializedAs("slippagePercentageInBasisPoints")] public ulong slippagePercentage; + +#if UNITY_2017_1_OR_NEWER + [UnityEngine.Serialization.FormerlySerializedAs("slippagePercentageInBasisPoints")] public ulong slippagePercentage; +#else + public ulong slippagePercentage; +#endif [Preserve] [JsonConstructor] diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/GetSwapPriceResponse.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/GetSwapPriceResponse.cs index 88e1c20e6..1a4a83e31 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/GetSwapPriceResponse.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/GetSwapPriceResponse.cs @@ -1,5 +1,5 @@ using System; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.Marketplace { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/GetSwapPricesRequest.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/GetSwapPricesRequest.cs index 21ed2df2a..6e1e749b5 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/GetSwapPricesRequest.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/GetSwapPricesRequest.cs @@ -1,6 +1,6 @@ using System; using Newtonsoft.Json; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.Marketplace { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/GetSwapPricesResponse.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/GetSwapPricesResponse.cs index 30e1c7048..0d25b7ef5 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/GetSwapPricesResponse.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/GetSwapPricesResponse.cs @@ -1,5 +1,5 @@ using System; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.Marketplace { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/GetSwapQuoteRequest.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/GetSwapQuoteRequest.cs index 09b0899c3..1fb23831c 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/GetSwapQuoteRequest.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/GetSwapQuoteRequest.cs @@ -1,6 +1,6 @@ using System; using Newtonsoft.Json; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.Marketplace { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/GetSwapQuoteResponse.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/GetSwapQuoteResponse.cs index 24bf5966c..f77d9286f 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/GetSwapQuoteResponse.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/GetSwapQuoteResponse.cs @@ -1,5 +1,5 @@ using System; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.Marketplace { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/ListCollectiblesWithLowestListingReturn.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/ListCollectiblesWithLowestListingReturn.cs index e1338bdef..b2653c3c2 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/ListCollectiblesWithLowestListingReturn.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/ListCollectiblesWithLowestListingReturn.cs @@ -1,5 +1,5 @@ using System; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.Marketplace { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/Order.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/Order.cs index fd64be0b7..4850c56a7 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/Order.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/Order.cs @@ -1,6 +1,6 @@ using System; using System.Numerics; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.Marketplace { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/PropertyFilter.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/PropertyFilter.cs index 75fab5cbd..bf8eacdef 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/PropertyFilter.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/PropertyFilter.cs @@ -1,7 +1,7 @@ using System; using System.Numerics; using Newtonsoft.Json; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.Marketplace { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/SwapPrice.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/SwapPrice.cs index d550ebc15..9db309da1 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/SwapPrice.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/SwapPrice.cs @@ -1,5 +1,5 @@ using System; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.Marketplace { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/SwapQuote.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/SwapQuote.cs index fcdcadcd3..96a984fef 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/SwapQuote.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/SwapQuote.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using Sequence.EmbeddedWallet; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.Marketplace { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/TokenMetadata.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/TokenMetadata.cs index 3c751e0f2..f360708c9 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/TokenMetadata.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/TokenMetadata.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using UnityEngine.Scripting; +using Sequence.Utils; namespace Sequence.Marketplace { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/HttpClient.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/HttpClient.cs index fca6d94fc..54ffb3be3 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/HttpClient.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/HttpClient.cs @@ -6,8 +6,8 @@ using System.Threading.Tasks; using Newtonsoft.Json; using Sequence.Config; +using Sequence.EmbeddedWallet; using Sequence.Utils; -using UnityEngine.Networking; namespace Sequence.Marketplace { @@ -25,8 +25,8 @@ public class HttpClient : IHttpClient public HttpClient() { - SequenceConfig config = SequenceConfig.GetConfig(SequenceService.Marketplace); - _apiKey = config.BuilderAPIKey; + SequenceConfigBase configBase = SequenceConfig.GetConfig(SequenceService.Marketplace); + _apiKey = configBase.BuilderAPIKey; #if SEQUENCE_DEV_MARKETPLACE || SEQUENCE_DEV _baseUrl = _devUrl; #else @@ -63,31 +63,29 @@ public async Task SendRequest(string url, ArgTy { requestJson = JsonConvert.SerializeObject(args, serializerSettings); } - using UnityWebRequest request = UnityWebRequest.Get(url); - request.method = UnityWebRequest.kHttpVerbPOST; + using IWebRequest request = WebRequestBuilder.Post(url); byte[] requestData = Encoding.UTF8.GetBytes(requestJson); - request.uploadHandler = new UploadHandlerRaw(requestData); - request.uploadHandler.contentType = "application/json"; + request.SetRequestData(requestData); request.SetRequestHeader("X-Access-Key", _apiKey); request.SetRequestHeader("Content-Type", "application/json"); string headersString = ExtractHeaders(request); - string method = request.method; + string method = request.Method; string curlRequest = $"curl -X {method} '{url}' {headersString} -d '{requestJson}'"; - UnityEngine.Debug.Log(curlRequest); + LogHandler.Info(curlRequest); try { - await request.SendWebRequest(); + var response = await request.Send(); - if (request.error != null || request.result != UnityWebRequest.Result.Success || - request.responseCode < 200 || request.responseCode > 299) + if (request.Error != null || response.Result != WebRequestResult.Success || + response.ResponseCode < 200 || response.ResponseCode > 299) { - throw new Exception($"Error sending request to {url}: {request.responseCode} {request.error}"); + throw new Exception($"Error sending request to {url}: {response.ResponseCode} {request.Error}"); } else { - byte[] results = request.downloadHandler.data; + byte[] results = request.Data; var responseJson = Encoding.UTF8.GetString(results); try { @@ -129,17 +127,17 @@ public async Task SendRequest(string url, ArgTy } } - private string GetRequestErrorIfAvailable(UnityWebRequest request) + private string GetRequestErrorIfAvailable(IWebRequest request) { - if (request.downloadHandler != null && request.downloadHandler.data != null) + if (request.Data != null) { - return " reason: " + Encoding.UTF8.GetString(request.downloadHandler.data); + return " reason: " + Encoding.UTF8.GetString(request.Data); } return ""; } - private string ExtractHeaders(UnityWebRequest request) + private string ExtractHeaders(IWebRequest request) { StringBuilder headerBuilder = new StringBuilder(); foreach (string headerKey in new string[]{"Content-Type", "Accept", "Authorization", "X-Sequence-Tenant", "X-Access-Key"}) diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Relayer/MintingRequestProofValidator.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Relayer/MintingRequestProofValidator.cs index fb4afb147..243c380a6 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Relayer/MintingRequestProofValidator.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Relayer/MintingRequestProofValidator.cs @@ -6,8 +6,6 @@ using Sequence.Provider; using Sequence.Utils; using Sequence.EmbeddedWallet; -using UnityEngine; -using UnityEngine.Networking; namespace Sequence.Relayer { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Relayer/PermissionedMinter.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Relayer/PermissionedMinter.cs index 684c5db19..4500d32c5 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Relayer/PermissionedMinter.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Relayer/PermissionedMinter.cs @@ -1,14 +1,10 @@ using System; using System.IO; -using System.Linq; -using System.Numerics; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; -using Sequence.Provider; +using Sequence.EmbeddedWallet; using Sequence.Utils; -using UnityEngine; -using UnityEngine.Networking; namespace Sequence.Relayer { @@ -50,29 +46,27 @@ public async Task MintToken(string tokenId, uint amount = 1) private async Task SendMintTokenRequest(string mintTokenRequestJson) { - using UnityWebRequest request = UnityWebRequest.Get(_mintEndpoint); - request.method = UnityWebRequest.kHttpVerbPOST; + using IWebRequest request = WebRequestBuilder.Post(_mintEndpoint, string.Empty); byte[] requestData = mintTokenRequestJson.ToByteArray(); - request.uploadHandler = new UploadHandlerRaw(requestData); - request.uploadHandler.contentType = "application/json"; + request.SetRequestData(requestData); request.SetRequestHeader("Content-Type", "application/json"); string curlRequest = $"curl -X POST -H \"Content-Type: application/json\" -d '{mintTokenRequestJson}' {_mintEndpoint}"; try { - await request.SendWebRequest(); + await request.Send(); - string transactionHash = request.downloadHandler.text; + string transactionHash = request.Text; request.Dispose(); OnMintTokenSuccess?.Invoke(transactionHash); } catch (FileLoadException e) { - if (request.downloadHandler != null) // Unity sometimes throws an exception here even though the response can be properly handled. I have no idea why... + if (request.Text != null) // Unity sometimes throws an exception here even though the response can be properly handled. I have no idea why... { - string transactionHash = request.downloadHandler.text; + string transactionHash = request.Text; request.Dispose(); if (!transactionHash.StartsWith("0x")) @@ -84,11 +78,11 @@ private async Task SendMintTokenRequest(string mintTokenRequestJson) OnMintTokenSuccess?.Invoke(transactionHash); return transactionHash; } - OnMintTokenFailed?.Invoke("Error minting using permissioned minter: " + e.Message + " reason: " + Encoding.UTF8.GetString(request.downloadHandler.data) + "\nCurl request: " + curlRequest); + OnMintTokenFailed?.Invoke("Error minting using permissioned minter: " + e.Message + " reason: " + Encoding.UTF8.GetString(request.Data) + "\nCurl request: " + curlRequest); } catch (Exception e) { - OnMintTokenFailed?.Invoke("Error minting using permissioned minter: " + e.Message + " reason: " + Encoding.UTF8.GetString(request.downloadHandler.data) + "\nCurl request: " + curlRequest); + OnMintTokenFailed?.Invoke("Error minting using permissioned minter: " + e.Message + " reason: " + Encoding.UTF8.GetString(request.Data) + "\nCurl request: " + curlRequest); } finally { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Relayer/PermissionedMinterTransactionQueuer.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Relayer/PermissionedMinterTransactionQueuer.cs index f21d83d1f..6d3865887 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Relayer/PermissionedMinterTransactionQueuer.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Relayer/PermissionedMinterTransactionQueuer.cs @@ -5,7 +5,6 @@ using Sequence.Relayer; using Sequence.Utils; using Sequence.EmbeddedWallet; -using UnityEngine; namespace Sequence.Relayer { @@ -22,7 +21,7 @@ public void Setup(IWallet wallet, Chain chain, string mintEndpoint, string contr private void HandleMintTokenFailed(string error) { - Debug.LogError(error); + LogHandler.Error(error); } private void OnDestroy() @@ -53,7 +52,7 @@ private bool AttemptToUpdateTransaction(PermissionedMintTransaction transaction) if (_queue[i].Item1.TokenId == transaction.TokenId) { _queue[i].Item1.Amount += transaction.Amount; - _lastTransactionAddedTime = Time.time; + _lastTransactionAddedTime = AppEnvironment.Time; return true; } } diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Relayer/SequenceWalletTransactionQueuer.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Relayer/SequenceWalletTransactionQueuer.cs index 0f06bde2d..8a5a5c031 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Relayer/SequenceWalletTransactionQueuer.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Relayer/SequenceWalletTransactionQueuer.cs @@ -6,8 +6,7 @@ using Sequence; using Sequence.Contracts; using Sequence.EmbeddedWallet; -using UnityEngine; -using UnityEngine.Serialization; +using Sequence.Utils; namespace Sequence.Relayer { @@ -37,7 +36,7 @@ private bool AttemptToUpdateTransaction(QueuedTokenTransaction transaction) if (current.Type == transaction.Type && current.ContractAddress == transaction.ContractAddress && current.TokenId == transaction.TokenId && current.ToAddress == transaction.ToAddress && current.FromAddress == transaction.FromAddress) { current.Amount += transaction.Amount; - _lastTransactionAddedTime = Time.time; + _lastTransactionAddedTime = AppEnvironment.Time; return true; } } diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Relayer/TransactionQueuer.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Relayer/TransactionQueuer.cs index 00396398c..10f4c533d 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Relayer/TransactionQueuer.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Relayer/TransactionQueuer.cs @@ -4,16 +4,25 @@ using System.Threading.Tasks; using Sequence; using Sequence.EmbeddedWallet; -using UnityEngine; -using UnityEngine.Serialization; +using Sequence.Utils; namespace Sequence.Relayer { - public abstract class TransactionQueuer : MonoBehaviour +#if UNITY_2017_1_OR_NEWER + public abstract class TransactionQueuer : UnityEngine.MonoBehaviour +#else + public abstract class TransactionQueuer +#endif { - [FormerlySerializedAs("_autoSubmitTransactions")] public bool AutoSubmitTransactions = false; - [FormerlySerializedAs("_thresholdTimeBetweenTransactionsAddedBeforeSubmittedInSeconds")] public float ThresholdTimeBetweenTransactionsAddedBeforeSubmittedInSeconds = 60f; // If _autoSubmitTransactions, we will submit all the transactions in the queue if the threshold time lapses between adding subsequent items to the queue - [FormerlySerializedAs("_minimumTimeBetweenTransactionSubmissionsInSeconds")] public float MinimumTimeBetweenTransactionSubmissionsInSeconds = 30f; // The minimum time before a transaction can be submitted on-chain after the last one was submitted +#if UNITY_2017_1_OR_NEWER + [UnityEngine.Serialization.FormerlySerializedAs("_autoSubmitTransactions")] public bool AutoSubmitTransactions = false; + [UnityEngine.Serialization.FormerlySerializedAs("_thresholdTimeBetweenTransactionsAddedBeforeSubmittedInSeconds")] public float ThresholdTimeBetweenTransactionsAddedBeforeSubmittedInSeconds = 60f; // If _autoSubmitTransactions, we will submit all the transactions in the queue if the threshold time lapses between adding subsequent items to the queue + [UnityEngine.Serialization.FormerlySerializedAs("_minimumTimeBetweenTransactionSubmissionsInSeconds")] public float MinimumTimeBetweenTransactionSubmissionsInSeconds = 30f; // The minimum time before a transaction can be submitted on-chain after the last one was submitted +#else + public bool AutoSubmitTransactions = false; + public float ThresholdTimeBetweenTransactionsAddedBeforeSubmittedInSeconds = 60f; + public float MinimumTimeBetweenTransactionSubmissionsInSeconds = 30f; +#endif protected List _queue = new List(); protected float _lastTransactionAddedTime = 0f; @@ -31,7 +40,7 @@ public virtual void Setup(IWallet wallet, Chain chain) private void Update() { if (!AutoSubmitTransactions) return; - if (_lastTransactionAddedTime > 0f && Time.time - _lastTransactionAddedTime > ThresholdTimeBetweenTransactionsAddedBeforeSubmittedInSeconds) + if (_lastTransactionAddedTime > 0f && AppEnvironment.Time - _lastTransactionAddedTime > ThresholdTimeBetweenTransactionsAddedBeforeSubmittedInSeconds) { SubmitTransactions(); } @@ -44,7 +53,7 @@ private void Update() public virtual void Enqueue(TQueueableType transaction) { _queue.Add(transaction); - _lastTransactionAddedTime = Time.time; + _lastTransactionAddedTime = AppEnvironment.Time; } /// @@ -66,7 +75,7 @@ public async Task SubmitTransactions(bool overrideWait = false, boo throw new Exception("Wallet cannot be null. User had likely not signed in yet."); } - if (!overrideWait && Time.time - _lastTransactionSubmittedTime < MinimumTimeBetweenTransactionSubmissionsInSeconds && _lastTransactionSubmittedTime > 0f) + if (!overrideWait && AppEnvironment.Time - _lastTransactionSubmittedTime < MinimumTimeBetweenTransactionSubmissionsInSeconds && _lastTransactionSubmittedTime > 0f) { return default; } @@ -75,7 +84,7 @@ public async Task SubmitTransactions(bool overrideWait = false, boo _queue.Clear(); _lastTransactionAddedTime = 0f; - _lastTransactionSubmittedTime = Time.time; + _lastTransactionSubmittedTime = AppEnvironment.Time; return result; } diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/SequenceDotNet.meta b/Packages/Sequence-Unity/Sequence/SequenceSDK/SequenceDotNet.meta new file mode 100644 index 000000000..0b5b069b9 --- /dev/null +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/SequenceDotNet.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4ec36f23818ab4a58bb50a26abf0803a +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/AppEnvironment.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/AppEnvironment.cs new file mode 100644 index 000000000..8685e4766 --- /dev/null +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/AppEnvironment.cs @@ -0,0 +1,36 @@ + +namespace Sequence.Utils +{ + public static class AppEnvironment + { + // CompanyName, ProductName, DataPath are used in the secure storage logic, which is disabled in .NET projects anyways + +#if UNITY_2017_1_OR_NEWER + public static string CompanyName => UnityEngine.Application.companyName; + public static string ProductName => UnityEngine.Application.productName; + public static string DataPath => UnityEngine.Application.persistentDataPath; + public static float Time => UnityEngine.Time.time; +#else + public static string CompanyName => "undefined"; + public static string ProductName => "undefined"; + public static string DataPath => "undefined"; + public static float Time => System.DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); +#endif + + public static void OpenUrl(string url) + { +#if UNITY_2017_1_OR_NEWER + UnityEngine.Application.OpenURL(url); +#endif + } + + public static int GetRandomNumber(int min, int max) + { +#if UNITY_2017_1_OR_NEWER + return UnityEngine.Random.Range(min, max); +#else + return new System.Random().Next(min, max); +#endif + } + } +} \ No newline at end of file diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/AppEnvironment.cs.meta b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/AppEnvironment.cs.meta new file mode 100644 index 000000000..b68d3c9f5 --- /dev/null +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/AppEnvironment.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 9264c10f1b074731bf4cbd5897026ff5 +timeCreated: 1741635082 \ No newline at end of file diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/AsyncExtensions.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/AsyncExtensions.cs index 118be21f3..7f399bf76 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/AsyncExtensions.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/AsyncExtensions.cs @@ -1,5 +1,4 @@ using System.Threading.Tasks; -using UnityEngine; namespace Sequence.Utils { @@ -13,11 +12,11 @@ public static class AsyncExtensions /// public static async Task DelayTask(float delayInSeconds) { - float currentTime = Time.time; + float currentTime = AppEnvironment.Time; float elapsedTime = 0; while (elapsedTime < delayInSeconds) { - elapsedTime = Time.time - currentTime; + elapsedTime = AppEnvironment.Time - currentTime; await Task.Yield(); } } diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/ByteArrayExtensions.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/ByteArrayExtensions.cs index 32a96dc2b..4482bcc44 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/ByteArrayExtensions.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/ByteArrayExtensions.cs @@ -1,6 +1,5 @@ using System; using System.Text; -using UnityEngine; namespace Sequence.Utils { @@ -27,7 +26,7 @@ public static string ByteArrayToHexString(this byte[] byteArray) } catch (Exception ex) { - Debug.LogError($"Error converting byte array to hexadecimal string: {ex.Message}"); + LogHandler.Error($"Error converting byte array to hexadecimal string: {ex.Message}"); return string.Empty; } } diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/CollectionUtils.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/CollectionUtils.cs index 5e732f9eb..71b142602 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/CollectionUtils.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/CollectionUtils.cs @@ -1,7 +1,6 @@ using System; using System.Collections; using System.Collections.Generic; -using Random = UnityEngine.Random; namespace Sequence.Utils { @@ -47,7 +46,7 @@ public static List CreateListOfType(Type elementType) public static T GetRandomObjectFromArray(this T[] arr) { - int randomIndex = Random.Range(0, arr.Length); + int randomIndex = AppEnvironment.GetRandomNumber(0, arr.Length); return arr[randomIndex]; } } diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/DecimalNormalizer.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/DecimalNormalizer.cs index e82488cf5..c038a2fa2 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/DecimalNormalizer.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/DecimalNormalizer.cs @@ -1,6 +1,5 @@ using System; using System.Numerics; -using UnityEngine; namespace Sequence.Utils { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/LogHandler.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/LogHandler.cs new file mode 100644 index 000000000..16c69676a --- /dev/null +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/LogHandler.cs @@ -0,0 +1,32 @@ +namespace Sequence.Utils +{ + public static class LogHandler + { + public static void Info(string message) + { +#if UNITY_2017_1_OR_NEWER + UnityEngine.Debug.Log(message); +#else + System.Console.WriteLine(message); +#endif + } + + public static void Warning(string message) + { +#if UNITY_2017_1_OR_NEWER + UnityEngine.Debug.LogWarning(message); +#else + System.Console.WriteLine(message); +#endif + } + + public static void Error(string message) + { +#if UNITY_2017_1_OR_NEWER + UnityEngine.Debug.LogError(message); +#else + System.Console.WriteLine(message); +#endif + } + } +} \ No newline at end of file diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/LogHandler.cs.meta b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/LogHandler.cs.meta new file mode 100644 index 000000000..4a722a7ef --- /dev/null +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/LogHandler.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ce7074fa535e46e68b74d43b78c54e46 +timeCreated: 1741626952 \ No newline at end of file diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/PreserveAttribute.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/PreserveAttribute.cs new file mode 100644 index 000000000..25f9ad989 --- /dev/null +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/PreserveAttribute.cs @@ -0,0 +1,15 @@ +using System; + +namespace Sequence.Utils +{ + [AttributeUsage(AttributeTargets.All, Inherited = false)] + public sealed class PreserveAttribute : Attribute + { +#if UNITY_2017_1_OR_NEWER + public PreserveAttribute() + { + new UnityEngine.Scripting.PreserveAttribute(); + } +#endif + } +} \ No newline at end of file diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/PreserveAttribute.cs.meta b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/PreserveAttribute.cs.meta new file mode 100644 index 000000000..69104cabe --- /dev/null +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/PreserveAttribute.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: dc37b7966e2b4e36a2b75adac4a1a572 +timeCreated: 1741628486 \ No newline at end of file diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/SecureStorage/AndroidKeystoreStorage.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/SecureStorage/AndroidKeystoreStorage.cs index f067c0884..ff905f9b4 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/SecureStorage/AndroidKeystoreStorage.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/SecureStorage/AndroidKeystoreStorage.cs @@ -1,7 +1,3 @@ -using System; -using System.Runtime.InteropServices; -using UnityEngine; - namespace Sequence.Utils.SecureStorage { public class AndroidKeystoreStorage : ISecureStorage diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/SecureStorage/EditorSecureStorage.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/SecureStorage/EditorSecureStorage.cs index a80c09604..773098451 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/SecureStorage/EditorSecureStorage.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/SecureStorage/EditorSecureStorage.cs @@ -1,18 +1,16 @@ -using UnityEngine; - namespace Sequence.Utils.SecureStorage { public class EditorSecureStorage : ISecureStorage { public void StoreString(string key, string value) { - PlayerPrefs.SetString(key, value); - PlayerPrefs.Save(); + SequencePrefs.SetString(key, value); + SequencePrefs.Save(); } public string RetrieveString(string key) { - return PlayerPrefs.GetString(key); + return SequencePrefs.GetString(key); } public EditorSecureStorage() diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/SecureStorage/MacOSKeychainStorage.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/SecureStorage/MacOSKeychainStorage.cs index 2cf3b1545..f2bd59883 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/SecureStorage/MacOSKeychainStorage.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/SecureStorage/MacOSKeychainStorage.cs @@ -1,6 +1,5 @@ using System; using System.Runtime.InteropServices; -using UnityEngine; namespace Sequence.Utils.SecureStorage { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/SecureStorage/WebSecureStorage.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/SecureStorage/WebSecureStorage.cs index 650874405..864d294a7 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/SecureStorage/WebSecureStorage.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/SecureStorage/WebSecureStorage.cs @@ -1,4 +1,3 @@ -using UnityEngine; namespace Sequence.Utils.SecureStorage { @@ -15,13 +14,13 @@ public WebSecureStorage() // PlayerPrefs uses IndexedDB on web platforms https://docs.unity3d.com/ScriptReference/PlayerPrefs.html public void StoreString(string key, string value) { - PlayerPrefs.SetString(key, value); - PlayerPrefs.Save(); + SequencePrefs.SetString(key, value); + SequencePrefs.Save(); } public string RetrieveString(string key) { - return PlayerPrefs.GetString(key); + return SequencePrefs.GetString(key); } } } \ No newline at end of file diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/SecureStorage/WindowsProtectedDataStorage.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/SecureStorage/WindowsProtectedDataStorage.cs index 39b2c9a63..b6e192251 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/SecureStorage/WindowsProtectedDataStorage.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/SecureStorage/WindowsProtectedDataStorage.cs @@ -1,6 +1,5 @@ using System; using System.Text; -using UnityEngine; using System.IO; #if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN @@ -11,7 +10,7 @@ namespace Sequence.Utils.SecureStorage { public class WindowsProtectedDataStorage : ISecureStorage { - public static string DataFile { get { return $"{Application.persistentDataPath}/data.bin"; } } + public static string DataFile { get { return $"{AppEnvironment.DataPath}/data.bin"; } } public WindowsProtectedDataStorage() { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/SecureStorage/iOSKeychainStorage.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/SecureStorage/iOSKeychainStorage.cs index af34f5154..736219ba1 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/SecureStorage/iOSKeychainStorage.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/SecureStorage/iOSKeychainStorage.cs @@ -1,6 +1,5 @@ using System; using System.Runtime.InteropServices; -using UnityEngine; namespace Sequence.Utils.SecureStorage { diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/SequencePrefs.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/SequencePrefs.cs new file mode 100644 index 000000000..151a583a2 --- /dev/null +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/SequencePrefs.cs @@ -0,0 +1,61 @@ +#if UNITY_2017_1_OR_NEWER +using UnityEngine; +#endif + +namespace Sequence.Utils +{ + public static class SequencePrefs + { +#if UNITY_2017_1_OR_NEWER + public static bool HasKey(string key) + { + return PlayerPrefs.HasKey(key); + } + + public static string GetString(string key) + { + return PlayerPrefs.GetString(key); + } + + public static void SetInt(string key, int value) + { + PlayerPrefs.SetInt(key, value); + } + + public static void SetString(string key, string value) + { + PlayerPrefs.SetString(key, value); + } + + public static void Save() + { + PlayerPrefs.Save(); + } +#else + public static bool HasKey(string key) + { + return false; + } + + public static string GetString(string key) + { + return ""; + } + + public static void SetInt(string key, int value) + { + + } + + public static void SetString(string key, string value) + { + + } + + public static void Save() + { + + } +#endif + } +} \ No newline at end of file diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/SequencePrefs.cs.meta b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/SequencePrefs.cs.meta new file mode 100644 index 000000000..e38f1244b --- /dev/null +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/SequencePrefs.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 933018cfbd734e14b626788d8bdc5422 +timeCreated: 1741630404 \ No newline at end of file diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/UnityWebRequestExtensions.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/UnityWebRequestExtensions.cs index 0538361c7..78190439f 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/UnityWebRequestExtensions.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/UnityWebRequestExtensions.cs @@ -1,3 +1,4 @@ +#if UNITY_2017_1_OR_NEWER using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; @@ -34,4 +35,6 @@ public static TaskAwaiter GetAwaiter(this UnityWebRequestAsyncOperation webReqOp return ((Task)tcs.Task).GetAwaiter(); } } -} \ No newline at end of file +} + +#endif diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/WebRequest.meta b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/WebRequest.meta new file mode 100644 index 000000000..7aff8284e --- /dev/null +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/WebRequest.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ef4b20fb88a54a379e9b4c3f31a8dcfd +timeCreated: 1741625936 \ No newline at end of file diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/WebRequest/IWebRequest.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/WebRequest/IWebRequest.cs new file mode 100644 index 000000000..e46a7475f --- /dev/null +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/WebRequest/IWebRequest.cs @@ -0,0 +1,32 @@ +using System; +using System.Threading.Tasks; + +namespace Sequence.Utils +{ + public enum WebRequestResult + { + Success, + Failed + } + + public struct WebRequestResponse + { + public WebRequestResult Result; + public int ResponseCode; + public byte[] Data; + } + + public interface IWebRequest : IDisposable + { + string Method { get; } + string Error { get; } + string Text { get; } + byte[] Data { get; } + void SetRequestData(byte[] data, string contentType = "application/json"); + void SetRequestHeader(string key, string value); + void SetTimeout(int timeout); + string GetRequestHeader(string key); + string GetResponseHeader(string key); + Task Send(); + } +} \ No newline at end of file diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/WebRequest/IWebRequest.cs.meta b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/WebRequest/IWebRequest.cs.meta new file mode 100644 index 000000000..a2527bbc3 --- /dev/null +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/WebRequest/IWebRequest.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 2ee46887c06247bb82acb5cea95cf626 +timeCreated: 1741625832 \ No newline at end of file diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/WebRequest/WebRequestBuilder.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/WebRequest/WebRequestBuilder.cs new file mode 100644 index 000000000..efa9f00d2 --- /dev/null +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/WebRequest/WebRequestBuilder.cs @@ -0,0 +1,30 @@ +using System.Text; + +namespace Sequence.Utils +{ + public static class WebRequestBuilder + { + public static IWebRequest Get(string url) + { + return Create(url, "GET"); + } + + public static IWebRequest Post(string url, string payload = "") + { + var request = Create(url, "POST"); + if (!string.IsNullOrEmpty(payload)) + request.SetRequestData(Encoding.UTF8.GetBytes(payload)); + + return request; + } + + private static IWebRequest Create(string url, string method) + { +#if UNITY_2017_1_OR_NEWER + return new WebRequestUnity(url, method); +#else + return new WebRequestDotnet(url, method); +#endif + } + } +} \ No newline at end of file diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/WebRequest/WebRequestBuilder.cs.meta b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/WebRequest/WebRequestBuilder.cs.meta new file mode 100644 index 000000000..3cd01abf9 --- /dev/null +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/WebRequest/WebRequestBuilder.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: fad69956dcce4cd49d0f4ce4537e7c4b +timeCreated: 1741626795 \ No newline at end of file diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/WebRequest/WebRequestDotnet.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/WebRequest/WebRequestDotnet.cs new file mode 100644 index 000000000..10c879232 --- /dev/null +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/WebRequest/WebRequestDotnet.cs @@ -0,0 +1,102 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; + +namespace Sequence.Utils +{ + public class WebRequestDotnet : IWebRequest + { + public string Method { get; private set; } + public string Error { get; private set; } + public string Text { get; private set; } + public byte[] Data { get; private set; } + + private readonly System.Net.Http.HttpClient _client; + private readonly string _url; + private readonly HttpMethod _method; + private readonly Dictionary _headers; + private readonly Dictionary _responseHeaders; + private byte[] _data; + + public WebRequestDotnet(string url, string method) + { + Method = method; + _client = new System.Net.Http.HttpClient(); + _headers = new Dictionary(); + _responseHeaders = new Dictionary(); + _url = url; + + _method = method switch + { + "POST" => HttpMethod.Post, + _ => HttpMethod.Get + }; + } + + public void SetRequestData(byte[] data, string contentType = "application/json") + { + _data = data; + } + + public void SetRequestHeader(string key, string value) + { + _headers.Add(key, value); + } + + public void SetTimeout(int timeout) + { + + } + + public string GetRequestHeader(string key) + { + return _headers.TryGetValue(key, out var value) ? value : string.Empty; + } + + public string GetResponseHeader(string key) + { + // .NET HttpClient can include header keys in lowercase + return _responseHeaders.TryGetValue(key.ToLower(), out var value) ? value : string.Empty; + } + + public async Task Send() + { + var request = new HttpRequestMessage(_method, _url); + + foreach (var headerPair in _headers) + if (headerPair.Key != "Content-Type") + request.Headers.Add(headerPair.Key, headerPair.Value); + + request.Content = new ByteArrayContent(_data); + foreach (var headerPair in _headers) + if (headerPair.Key == "Content-Type") + request.Content.Headers.Add(headerPair.Key, headerPair.Value); + + var response = await _client.SendAsync(request); + var responseData = await response.Content.ReadAsByteArrayAsync(); + + _responseHeaders.Clear(); + foreach (var responseHeaderPair in response.Headers) + _responseHeaders.Add(responseHeaderPair.Key.ToLower(), responseHeaderPair.Value.ToList()[0]); + + var result = response.IsSuccessStatusCode ? WebRequestResult.Success : WebRequestResult.Failed; + Data = responseData; + Text = Encoding.UTF8.GetString(responseData); + + return new WebRequestResponse + { + Data = responseData, + ResponseCode = (int)response.StatusCode, + Result = result + }; + } + + public void Dispose() + { + _client.Dispose(); + } + } +} \ No newline at end of file diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/WebRequest/WebRequestDotnet.cs.meta b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/WebRequest/WebRequestDotnet.cs.meta new file mode 100644 index 000000000..f75930d90 --- /dev/null +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/WebRequest/WebRequestDotnet.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 26d3d6d2dbb14b159d1d90c14d165f0a +timeCreated: 1741627517 \ No newline at end of file diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/WebRequest/WebRequestUnity.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/WebRequest/WebRequestUnity.cs new file mode 100644 index 000000000..f0189a5ba --- /dev/null +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/WebRequest/WebRequestUnity.cs @@ -0,0 +1,72 @@ +#if UNITY_2017_1_OR_NEWER +using System.Threading.Tasks; +using UnityEngine.Networking; + +namespace Sequence.Utils +{ + public class WebRequestUnity : IWebRequest + { + public string Method { get; private set; } + public string Error { get; private set; } + public string Text { get; private set; } + public byte[] Data { get; private set; } + + private readonly UnityWebRequest _request; + + public WebRequestUnity(string url, string method) + { + Method = method; + _request = UnityWebRequest.Get(url); + _request.method = method; + } + + public void SetRequestData(byte[] data, string contentType) + { + _request.uploadHandler = new UploadHandlerRaw(data); + _request.uploadHandler.contentType = contentType; + } + + public void SetRequestHeader(string key, string value) + { + _request.SetRequestHeader(key, value); + } + + public void SetTimeout(int timeout) + { + _request.timeout = timeout; + } + + public string GetRequestHeader(string key) + { + return _request.GetRequestHeader(key); + } + + public string GetResponseHeader(string key) + { + return _request.GetResponseHeader(key); + } + + public async Task Send() + { + await _request.SendWebRequest(); + Data = _request.downloadHandler.data; + Text = _request.downloadHandler.text; + Error = _request.error; + + return new WebRequestResponse + { + Data = Data, + ResponseCode = (int)_request.responseCode, + Result = _request.result == UnityWebRequest.Result.Success ? + WebRequestResult.Success : WebRequestResult.Failed + }; + } + + public void Dispose() + { + _request.Dispose(); + } + } +} + +#endif diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/WebRequest/WebRequestUnity.cs.meta b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/WebRequest/WebRequestUnity.cs.meta new file mode 100644 index 000000000..1c42781da --- /dev/null +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/WebRequest/WebRequestUnity.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 49f50fe0c37844d0888e505a3cc7377b +timeCreated: 1741625979 \ No newline at end of file