From dde3ebbaddfe03f8ff8e25536386491d266a5ab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Novo?= <34069419+TeknoPT@users.noreply.github.com> Date: Tue, 9 Jan 2024 09:47:30 +0000 Subject: [PATCH 1/2] Improvements and Bug fix's - Added Get Wallet Version - Fixed GetPeer and GetNexus - Fixed Neo Address but not data - Fixed some issues related to balances --- .../Phantasma.Core/src/Domain/WalletLink.cs | 85 +++++++++++++++++-- Assets/Scripts/Wallet/AccountManager.cs | 38 ++++++++- .../AccountManagerClasses/AccountState.cs | 5 ++ .../Wallet/WalletGUIFolder/WalletGUI.cs | 7 ++ .../Wallet/WalletLink/WalletConnector.cs | 37 ++++++-- ProjectSettings/ProjectSettings.asset | 4 +- 6 files changed, 160 insertions(+), 16 deletions(-) diff --git a/Assets/Phantasma/Phantasma.Core/src/Domain/WalletLink.cs b/Assets/Phantasma/Phantasma.Core/src/Domain/WalletLink.cs index 91b93dc..b85ae65 100644 --- a/Assets/Phantasma/Phantasma.Core/src/Domain/WalletLink.cs +++ b/Assets/Phantasma/Phantasma.Core/src/Domain/WalletLink.cs @@ -83,6 +83,21 @@ public struct Signature : IAPIResult public string signature; public string random; } + + public struct Peer : IAPIResult + { + public string peer; + } + + public struct NexusResult : IAPIResult + { + public string nexus; + } + + public struct WalletVersion : IAPIResult + { + public string version; + } public class Connection { @@ -139,7 +154,9 @@ private Connection ValidateRequest(string[] args) protected abstract void GetPeer(Action callback); protected abstract void GetNexus(Action callback); - + + protected abstract void GetWalletVersion(Action callback); + protected abstract void InvokeScript(string chain, byte[] script, int id, Action callback); // NOTE for security, signData should not be usable as a way of signing transaction. That way the wallet is responsible for appending random bytes to the message, and return those in callback @@ -278,13 +295,37 @@ private void HandleGetAccount(string[] args, Connection connection, int id, Acti } #endregion + #region Nexus + + private void HandleGetNexus(string[] args, Connection connection, int id, Action callback) + { + DataNode answer; + bool success = false; + + if (args.Length > 1) + { + answer = APIUtils.FromAPIResult(new Error() { message = $"getNexus: Invalid amount of arguments: {args.Length}" }); + callback(id, answer, success); + _isPendingRequest = false; + return; + } + + GetNexus((nexus) => { + success = true; + answer = APIUtils.FromAPIResult(new NexusResult { nexus = nexus }); + callback(id, answer, success); + _isPendingRequest = false; + }); + } + #endregion + #region Peer private void HandleGetPeer(string[] args, Connection connection, int id, Action callback) { DataNode answer; bool success = false; - if (args.Length != 0) + if (args.Length > 1) { answer = APIUtils.FromAPIResult(new Error() { message = $"getPeer: Invalid amount of arguments: {args.Length}" }); callback(id, answer, success); @@ -294,16 +335,36 @@ private void HandleGetPeer(string[] args, Connection connection, int id, Action< GetPeer((peer) => { success = true; - SingleResult result; - result.value = peer; - answer = APIUtils.FromAPIResult(result); - + answer = APIUtils.FromAPIResult(new Peer() { peer = peer }); callback(id, answer, success); _isPendingRequest = false; }); } #endregion + #region Wallet Version + private void HandleGetWalletVersion(string[] args, Connection connection, int id, Action callback) + { + DataNode answer; + bool success = false; + + if (args.Length > 1) + { + answer = APIUtils.FromAPIResult(new Error() { message = $"getWalletVersion: Invalid amount of arguments: {args.Length}" }); + callback(id, answer, success); + _isPendingRequest = false; + return; + } + + GetWalletVersion((version) => { + success = true; + answer = APIUtils.FromAPIResult(new WalletVersion() { version = version }); + callback(id, answer, success); + _isPendingRequest = false; + }); + } + #endregion + #region Sign Data private void HandleSignData(string[] args, Connection connection, int id, Action callback) @@ -786,6 +847,12 @@ public void Execute(string cmd, Action callback) HandleGetPeer(args, connection, id, callback); return; } + + case "getWalletVersion": + { + HandleGetWalletVersion(args, connection, id, callback); + return; + } case "signData": { @@ -817,6 +884,12 @@ public void Execute(string cmd, Action callback) return; } + case "getNexus": + { + HandleGetNexus(args, connection, id, callback); + return; + } + case "writeArchive": { HandleWriteArchive(args, connection, id, callback); diff --git a/Assets/Scripts/Wallet/AccountManager.cs b/Assets/Scripts/Wallet/AccountManager.cs index c63dbb9..19117b7 100644 --- a/Assets/Scripts/Wallet/AccountManager.cs +++ b/Assets/Scripts/Wallet/AccountManager.cs @@ -127,7 +127,7 @@ private void Awake() var platforms = new List(); platforms.Add(PlatformKind.Phantasma); - //platforms.Add(PlatformKind.Neo); + platforms.Add(PlatformKind.Neo); platforms.Add(PlatformKind.Ethereum); platforms.Add(PlatformKind.BSC); @@ -1568,6 +1568,26 @@ public void SelectAccount(int index) platforms.Add(PlatformKind.BSC); } + if (!platforms.Contains(PlatformKind.Neo)) + { + var account = Accounts[_selectedAccountIndex]; + account.platforms |= PlatformKind.Neo; + Accounts[_selectedAccountIndex] = account; + + _states[PlatformKind.Neo] = new AccountState() + { + platform = PlatformKind.Neo, + address = GetAddress(CurrentIndex, PlatformKind.Neo), + balances = new Balance[0], + flags = AccountFlags.None, + name = ValidationUtils.ANONYMOUS_NAME, + }; + + SaveAccounts(); + + platforms.Add(PlatformKind.Neo); + } + CurrentPlatform = platforms.FirstOrDefault(); _states.Clear(); @@ -2057,7 +2077,21 @@ public void RefreshBalances(bool force, PlatformKind platforms = PlatformKind.No case PlatformKind.Neo: { - ReportWalletBalance(platform, null); + var keys = NeoKeys.FromWIF(wif); + var state = new AccountState() + { + platform = platform, + address = keys.Address, + name = "Anonymous", + balances = new Balance[0], + flags = AccountFlags.None, + archives = new Archive[0], + avatarData = "", + usedStorage = 0, + availableStorage = 0, + stakeTime = 0, + }; + ReportWalletBalance(platform, state); /*var keys = NeoKeys.FromWIF(wif); var url = GetNeoscanAPIUrl($"get_balance/{keys.Address}"); diff --git a/Assets/Scripts/Wallet/AccountManagerClasses/AccountState.cs b/Assets/Scripts/Wallet/AccountManagerClasses/AccountState.cs index 1c3bd66..2369ac6 100644 --- a/Assets/Scripts/Wallet/AccountManagerClasses/AccountState.cs +++ b/Assets/Scripts/Wallet/AccountManagerClasses/AccountState.cs @@ -23,6 +23,11 @@ public class AccountState public decimal GetAvailableAmount(string symbol) { + if (balances == null) + { + return 0; + } + for (int i = 0; i < balances.Length; i++) { var entry = balances[i]; diff --git a/Assets/Scripts/Wallet/WalletGUIFolder/WalletGUI.cs b/Assets/Scripts/Wallet/WalletGUIFolder/WalletGUI.cs index a06ef13..c1190f9 100644 --- a/Assets/Scripts/Wallet/WalletGUIFolder/WalletGUI.cs +++ b/Assets/Scripts/Wallet/WalletGUIFolder/WalletGUI.cs @@ -2386,6 +2386,7 @@ private void DoBalanceScreen() { accountManager.RefreshBalances(false, accountManager.CurrentPlatform); }); + var endY = DoBottomMenu(); if (accountManager.BalanceRefreshing) @@ -2410,6 +2411,12 @@ private void DoBalanceScreen() decimal feeBalance = state.GetAvailableAmount("KCAL"); + if (state.balances == null) + { + DrawCenteredText($"No assets found in this {accountManager.CurrentPlatform} account."); + return; + } + var balanceCount = DoScrollArea(ref balanceScroll, startY, endY, VerticalLayout ? Units(7) : Units(6), state.balances.Where(x => x.Total >= 0.001m), DoBalanceEntry); diff --git a/Assets/Scripts/Wallet/WalletLink/WalletConnector.cs b/Assets/Scripts/Wallet/WalletLink/WalletConnector.cs index 9a2e974..8e2f7f4 100644 --- a/Assets/Scripts/Wallet/WalletLink/WalletConnector.cs +++ b/Assets/Scripts/Wallet/WalletLink/WalletConnector.cs @@ -11,7 +11,9 @@ using Phantasma.Core.Numerics; using Phantasma.Core.Utils; using Phantasma.SDK; +using Poltergeist.Neo2.Core; using Poltergeist.PhantasmaLegacy.Ethereum; +using UnityEngine.Device; namespace Poltergeist { @@ -144,6 +146,11 @@ protected override void GetAccount(string platform, int version, Action new Balance() { symbol = x.Symbol, @@ -174,7 +181,14 @@ protected override void GetNexus(Action callback) { callback(AccountManager.Instance.Settings.nexusName); } - + + protected override void GetWalletVersion(Action callback) + { + callback(Application.version.StartsWith("v") + ? Application.version.Substring(1) + : Application.version); + } + protected override void InvokeScript(string chain, byte[] script, int id, Action callback) { @@ -451,7 +465,7 @@ protected override void SignData(string platform, SignatureKind kind, byte[] dat var accountManager = AccountManager.Instance; var targetPlatform = RequestPlatform(platform); - if (targetPlatform == PlatformKind.None || targetPlatform == PlatformKind.Neo) + if (targetPlatform == PlatformKind.None) { callback(null, null, "Unsupported platform: " + platform); return; @@ -484,18 +498,29 @@ protected override void SignData(string platform, SignatureKind kind, byte[] dat Phantasma.Core.Cryptography.Signature signature; var wif = account.GetWif(AccountManager.Instance.CurrentPasswordHash); + var phantasmaKeys = PhantasmaKeys.FromWIF(wif); switch (kind) { case SignatureKind.Ed25519: - var phantasmaKeys = PhantasmaKeys.FromWIF(wif); signature = phantasmaKeys.Sign(msg); break; case SignatureKind.ECDSA: - var ethKeys = EthereumKey.FromWIF(wif); - var signatureBytes = Poltergeist.PhantasmaLegacy.Cryptography.CryptoUtils.Sign(msg, ethKeys.PrivateKey, ethKeys.PublicKey, ECDsaCurve.Secp256k1); - signature = new ECDsaSignature(signatureBytes, ECDsaCurve.Secp256k1); + + if ( targetPlatform == PlatformKind.Ethereum || targetPlatform == PlatformKind.BSC) + { + var ethKeys = EthereumKey.FromWIF(wif); + + var signatureBytes = Poltergeist.PhantasmaLegacy.Cryptography.CryptoUtils.Sign(msg, ethKeys.PrivateKey, ethKeys.PublicKey, ECDsaCurve.Secp256k1); + signature = new ECDsaSignature(signatureBytes, ECDsaCurve.Secp256k1); + } + else + { + var neoKeys = NeoKeys.FromWIF(wif); + var signatureBytes = Poltergeist.PhantasmaLegacy.Cryptography.CryptoUtils.Sign(msg, neoKeys.PrivateKey, neoKeys.CompressedPublicKey, ECDsaCurve.Secp256k1); + signature = new ECDsaSignature(signatureBytes, ECDsaCurve.Secp256k1); + } break; default: diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 644fbf9..701d5f5 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -133,7 +133,7 @@ PlayerSettings: vulkanEnableLateAcquireNextImage: 0 vulkanEnableCommandBufferRecycling: 1 loadStoreDebugModeEnabled: 0 - bundleVersion: 2.8.8 + bundleVersion: 2.8.9 preloadedAssets: [] metroInputSource: 0 wsaTransparentSwapchain: 0 @@ -164,7 +164,7 @@ PlayerSettings: iPhone: 0 tvOS: 0 overrideDefaultApplicationIdentifier: 1 - AndroidBundleVersionCode: 36 + AndroidBundleVersionCode: 37 AndroidMinSdkVersion: 22 AndroidTargetSdkVersion: 33 AndroidPreferredInstallLocation: 1 From c294c288a563a694952eb90f8a3b3a3e1936f896 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Novo?= <34069419+TeknoPT@users.noreply.github.com> Date: Thu, 25 Jan 2024 15:46:15 +0000 Subject: [PATCH 2/2] Update Poltergeist --- Assets/Scripts/Wallet/AccountManager.cs | 4 ++-- Assets/Scripts/Wallet/Settings.cs | 26 ++++++++++++------------- ProjectSettings/ProjectSettings.asset | 8 ++++---- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Assets/Scripts/Wallet/AccountManager.cs b/Assets/Scripts/Wallet/AccountManager.cs index 19117b7..a965d5d 100644 --- a/Assets/Scripts/Wallet/AccountManager.cs +++ b/Assets/Scripts/Wallet/AccountManager.cs @@ -271,11 +271,11 @@ public void UpdateRPCURL(PlatformKind platformKind) string url; if(Settings.nexusKind == NexusKind.Main_Net) { - url = $"https://peers.phantasma.io/mainnet-getpeers.json"; + url = $"https://peers.phantasma.info/mainnet-getpeers.json"; } else { - url = $"https://peers.phantasma.io/testnet-getpeers.json"; + url = $"https://peers.phantasma.info/testnet-getpeers.json"; } rpcBenchmarkedPhantasma = 0; diff --git a/Assets/Scripts/Wallet/Settings.cs b/Assets/Scripts/Wallet/Settings.cs index afa05bb..009a04a 100644 --- a/Assets/Scripts/Wallet/Settings.cs +++ b/Assets/Scripts/Wallet/Settings.cs @@ -396,11 +396,11 @@ public string GetDefaultValue(string tag) switch (nexusKind) { case NexusKind.Main_Net: - _return_value = "https://pharpc1.phantasma.io/rpc"; + _return_value = "https://pharpc1.phantasma.info/rpc"; break; case NexusKind.Test_Net: - _return_value = "https://testnet.phantasma.io/rpc"; + _return_value = "https://testnet.phantasma.info/rpc"; break; case NexusKind.Mankini_Test_Net: @@ -412,7 +412,7 @@ public string GetDefaultValue(string tag) break; default: - _return_value = "https://pharpc1.phantasma.io/rpc"; + _return_value = "https://pharpc1.phantasma.info/rpc"; break; } break; @@ -421,11 +421,11 @@ public string GetDefaultValue(string tag) switch (nexusKind) { case NexusKind.Main_Net: - _return_value = "https://explorer.phantasma.io"; + _return_value = "https://explorer.phantasma.info"; break; case NexusKind.Test_Net: - _return_value = "https://test-explorer.phantasma.io/"; + _return_value = "https://test-explorer.phantasma.info/"; break; case NexusKind.Mankini_Test_Net: @@ -437,7 +437,7 @@ public string GetDefaultValue(string tag) break; default: - _return_value = "https://explorer.phantasma.io"; + _return_value = "https://explorer.phantasma.info"; break; } break; @@ -477,15 +477,15 @@ public string GetDefaultValue(string tag) break; case NexusKind.Test_Net: - _return_value = "http://mankinighost.phantasma.io:30333"; + _return_value = "http://mankinighost.phantasma.info:30333"; break; case NexusKind.Mankini_Test_Net: - _return_value = "http://mankinighost.phantasma.io:30333"; + _return_value = "http://mankinighost.phantasma.info:30333"; break; default: - _return_value = "http://mankinighost.phantasma.io:30333"; + _return_value = "http://mankinighost.phantasma.info:30333"; break; } break; @@ -502,7 +502,7 @@ public string GetDefaultValue(string tag) break; case EthereumNetwork.Local_Net: - _return_value = "http://mankinieth.phantasma.io:7545/"; + _return_value = "http://mankinieth.phantasma.info:7545/"; break; default: @@ -548,15 +548,15 @@ public string GetDefaultValue(string tag) break; case NexusKind.Test_Net: - _return_value = "http://mankinighost.phantasma.io:4000"; + _return_value = "http://mankinighost.phantasma.info:4000"; break; case NexusKind.Mankini_Test_Net: - _return_value = "http://mankinighost.phantasma.io:4000"; + _return_value = "http://mankinighost.phantasma.info:4000"; break; default: - _return_value = "http://mankinighost.phantasma.io:4000"; + _return_value = "http://mankinighost.phantasma.info:4000"; break; } break; diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 701d5f5..f47d30a 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -133,7 +133,7 @@ PlayerSettings: vulkanEnableLateAcquireNextImage: 0 vulkanEnableCommandBufferRecycling: 1 loadStoreDebugModeEnabled: 0 - bundleVersion: 2.8.9 + bundleVersion: 2.8.10 preloadedAssets: [] metroInputSource: 0 wsaTransparentSwapchain: 0 @@ -156,7 +156,7 @@ PlayerSettings: applicationIdentifier: Android: com.Phantasma.PoltergeistWallet Standalone: com.Phantasma.PoltergeistWallet - iPhone: com.Phantasma.PoltergeistWallet + iPhone: io.phantasma.poltergeist buildNumber: Bratwurst: 0 Standalone: 0 @@ -164,9 +164,9 @@ PlayerSettings: iPhone: 0 tvOS: 0 overrideDefaultApplicationIdentifier: 1 - AndroidBundleVersionCode: 37 + AndroidBundleVersionCode: 39 AndroidMinSdkVersion: 22 - AndroidTargetSdkVersion: 33 + AndroidTargetSdkVersion: 34 AndroidPreferredInstallLocation: 1 aotOptions: stripEngineCode: 1