Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmpa committed Jul 9, 2024
2 parents 0e7e8d0 + 3fc77e0 commit 7a9be4f
Show file tree
Hide file tree
Showing 16 changed files with 420 additions and 136 deletions.
24 changes: 20 additions & 4 deletions Assets/Phantasma.SDK/WebClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,27 @@ public static IEnumerator RPCRequest(string url, string method, int timeout, int
try
{
var stringResponse = request.downloadHandler.text;
if (method.ToUpper() == "GETNFT" && parameters.Length > 0 && ((string)parameters[0]).ToUpper() == "GAME")

try
{
root = JSONReader.ReadFromString(stringResponse);
}
catch
{
// TODO remove later: Temporary HACK for binary data inside JSON
var cutFrom = stringResponse.IndexOf(",{\"Key\" : \"OriginalMetadata\"");
stringResponse = stringResponse.Substring(0, cutFrom) + "]}";
if (method.ToUpper() == "GETNFT" && parameters.Length > 0 && ((string)parameters[0]).ToUpper() == "GAME")
{
Log.Write($"RPC response [{requestNumber}]\nurl: {url}\nFailed to parse GAME NFT, trying workaround. JSON: " + stringResponse, Log.Level.Logic);
// TODO remove later: Temporary HACK for binary data inside JSON
var cutFrom = stringResponse.IndexOf(",{\"Key\":\"OriginalMetadata\"", StringComparison.InvariantCultureIgnoreCase);
if (cutFrom > 0)
{
stringResponse = stringResponse.Substring(0, cutFrom) + "]}";
}
}
else
{
throw;
}
}

root = JSONReader.ReadFromString(stringResponse);
Expand Down
13 changes: 11 additions & 2 deletions Assets/Phantasma/Phantasma.Business/src/VM/Utils/DisasmUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@ public struct DisasmMethodCall

public VMObject[] Arguments;

public override string ToString()
public string ToString(bool useNewlines)
{
var sb = new StringBuilder();
sb.Append($"{ContractName}.{MethodName}(");
for (int i=0; i<Arguments.Length; i++)
for (int i = 0; i < Arguments.Length; i++)
{
if (i > 0)
{
sb.Append(',');
if(useNewlines)
{
sb.Append('\n');
}
}

var arg = Arguments[i];
Expand All @@ -29,6 +33,11 @@ public override string ToString()
sb.Append(")");
return sb.ToString();
}

public override string ToString()
{
return ToString(true);
}
}

public static class DisasmUtils
Expand Down
21 changes: 17 additions & 4 deletions Assets/Phantasma/Phantasma.Core/src/Domain/WalletLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using LunarLabs.Parser;
using Phantasma.Core.Cryptography;
using Phantasma.Core.Numerics;
using UnityEngine;

namespace Phantasma.Core.Domain
{
Expand Down Expand Up @@ -115,7 +116,7 @@ public Connection(string token, int version)
}
}

private Random rnd = new Random();
private System.Random rnd = new System.Random();

private Dictionary<string, Connection> _connections = new Dictionary<string, Connection>();

Expand Down Expand Up @@ -481,7 +482,7 @@ private void HandleSignTx(string[] args, Connection connection, int id, Action<i
var txNexus = args[index]; index++;
if (txNexus != this.Nexus)
{
answer = APIUtils.FromAPIResult(new Error() { message = $"signTx: Expected nexus {this.Nexus}, instead got {txNexus}" });
answer = APIUtils.FromAPIResult(new Error() { message = $"signTx: Expected nexus {this.Nexus}, instead got {txNexus}. Wrong network selected, please check Dapp or Wallet settings" });
callback(id, answer, false);
_isPendingRequest = false;
return;
Expand All @@ -499,7 +500,11 @@ private void HandleSignTx(string[] args, Connection connection, int id, Action<i
}

var chain = args[index]; index++;
var script = Base16.Decode(args[index], false); index++;
var scriptEncoded = args[index]; index++;

Debug.Log($"[WalletLink:HandleSignTx] chain: {chain}, script: {scriptEncoded}");

var script = Base16.Decode(scriptEncoded, false);

if (script == null)
{
Expand Down Expand Up @@ -616,7 +621,14 @@ private void HandleSignTxSignature(string[] args, Connection connection, int id,
var platform = connection.Version >= 2 ? args[2].ToLower() : "phantasma";

var transaction = Phantasma.Core.Domain.Transaction.Unserialize(data);

if (transaction.NexusName != this.Nexus)
{
answer = APIUtils.FromAPIResult(new Error() { message = $"signData: Expected nexus {this.Nexus}, instead got {transaction.NexusName}. Wrong network selected, please check Dapp or Wallet settings" });
callback(id, answer, false);
_isPendingRequest = false;
return;
}

SignTransactionSignature(transaction, platform, signatureKind, (signature, txError) => {
if (signature != null)
{
Expand Down Expand Up @@ -848,6 +860,7 @@ public void Execute(string cmd, Action<int, DataNode, bool> callback)
{
answer = APIUtils.FromAPIResult(new Error() { message = "Invalid or missing API token" });
callback(id, answer, false);
_isPendingRequest = false;
return;
}

Expand Down
Binary file added Assets/Resources/Tokens/RAA.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
140 changes: 140 additions & 0 deletions Assets/Resources/Tokens/RAA.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Assets/Resources/pgl_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 1 addition & 5 deletions Assets/Scripts/Updater/UpdateChecker.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Security.Policy;
using System.Text.RegularExpressions;
using Poltergeist;
using TMPro;
using UnityEngine;
using UnityEngine.Networking;

public class UpdateChecker : MonoBehaviour
{
public string githubOwner = "phantasma-io"; // Your GitHub username
public string githubRepo = "PoltergeistLite"; // Your repository name
public string currentVersion = "1.0.5"; // Current version of your game
public string currentVersion = "1.1.0"; // Current version of your game

private const string GITHUB_RELEASES_URL = "https://github.com/";
private static string URL = "";
Expand Down
21 changes: 15 additions & 6 deletions Assets/Scripts/Wallet/DescriptionUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,9 @@ private static string ShortenTokenId(string tokenId)
return tokenId.Substring(0, 5) + "..." + tokenId.Substring(tokenId.Length - 5);
}

public static IEnumerator GetDescription(byte[] script, Action<string, string> callback)
public static IEnumerator GetDescription(byte[] script, bool devMode, Action<string, string> callback)
{
foreach (var entry in methodTable.Keys)
{
Debug.Log("disam method: " + entry);
}
Debug.Log("disam methods: " + string.Join(", ", methodTable.Keys));

if(knownContracts == null)
{
Expand Down Expand Up @@ -217,7 +214,13 @@ public static IEnumerator GetDescription(byte[] script, Action<string, string> c
}

// Put it to log so that developer can easily check what PG is receiving.
Log.Write("GetDescription(): Contract's description: " + entry.ToString());
var unprocessedMethodCall = "Unprocessed method call: " + entry.ToString();
Log.Write(unprocessedMethodCall);
if(devMode)
{
sb.AppendLine(unprocessedMethodCall);
sb.AppendLine();
}

switch (GetCallFullName(entry))
{
Expand Down Expand Up @@ -371,6 +374,12 @@ public static IEnumerator GetDescription(byte[] script, Action<string, string> c
if (typeAuction == 0)
{
sb.AppendLine($"\u2605 List {tokenSymbol} NFT #{ShortenTokenId(nftNumber)} for a Fixed Auction with a price of {price} {priceSymbol}.");
if (devMode)
{
sb.AppendLine($"Start date: {startDate} [unix seconds: {startDate.Value}].");
sb.AppendLine($"End date: {untilDate} [unix seconds: {untilDate.Value}].");
sb.AppendLine($"Extension period: {extensionPeriod}.");
}
break;
}
else if (typeAuction == 1)
Expand Down
9 changes: 8 additions & 1 deletion Assets/Scripts/Wallet/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ public class Settings

public const string PasswordModeTag = "password.mode";

public const string DevModeTag = "developer.mode";

public string phantasmaRPCURL;
public string phantasmaExplorer;
public string phantasmaNftExplorer;
Expand All @@ -121,6 +123,7 @@ public class Settings
public MnemonicPhraseLength mnemonicPhraseLength;
public MnemonicPhraseVerificationMode mnemonicPhraseVerificationMode;
public PasswordMode passwordMode;
public bool devMode;

public override string ToString()
{
Expand All @@ -141,7 +144,8 @@ public override string ToString()
"NFT sort direction: " + this.nftSortDirection + "\n" +
"Mnemonic phrase length: " + this.mnemonicPhraseLength + "\n" +
"Mnemonic phrase verification mode: " + this.mnemonicPhraseVerificationMode + "\n" +
"Password mode: " + this.passwordMode;
"Password mode: " + this.passwordMode + "\n" +
"Developer mode: " + this.devMode;
}

public void LoadLogSettings()
Expand Down Expand Up @@ -227,6 +231,8 @@ public void Load()
this.passwordMode = PasswordMode.Ask_Always;
}

this.devMode = PlayerPrefs.GetInt(DevModeTag, 0) != 0;

Log.Write("Settings: Load: " + ToString());
}

Expand Down Expand Up @@ -357,6 +363,7 @@ public void Save()
PlayerPrefs.SetString(MnemonicPhraseLengthTag, this.mnemonicPhraseLength.ToString());
PlayerPrefs.SetString(MnemonicPhraseVerificationModeTag, this.mnemonicPhraseVerificationMode.ToString());
PlayerPrefs.SetString(PasswordModeTag, this.passwordMode.ToString());
PlayerPrefs.SetInt(DevModeTag, this.devMode ? 1 : 0);
PlayerPrefs.Save();

Log.Write("Settings: Save: " + ToString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ public partial class WalletGUI : MonoBehaviour
#region MODAL PROMPTS
private string[] ModalNone = new string[] { };
private string[] ModalOk = new string[] { "Ok" };
// ModalOkCopy automatically processes "Copy" button press
private string[] ModalOkCopy = new string[] { "Ok", "Copy to clipboard" };
// ModalOkCopy_NoAutoCopy requires "Copy" button press callback to be implemented
private string[] ModalOkCopy_NoAutoCopy = new string[] { "Ok", "Copy to clipboard" };
private string[] ModalOkView = new string[] { "Ok", "View" };
private string[] ModalConfirmCancel = new string[] { "Confirm", "Cancel" };
private string[] ModalSendCancel = new string[] { "Send", "Cancel" };
Expand Down
Loading

0 comments on commit 7a9be4f

Please sign in to comment.