Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements and Bug fix's #88

Merged
merged 2 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 79 additions & 6 deletions Assets/Phantasma/Phantasma.Core/src/Domain/WalletLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -139,7 +154,9 @@ private Connection ValidateRequest(string[] args)
protected abstract void GetPeer(Action<string> callback);

protected abstract void GetNexus(Action<string> callback);


protected abstract void GetWalletVersion(Action<string> callback);

protected abstract void InvokeScript(string chain, byte[] script, int id, Action<string[], string> 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
Expand Down Expand Up @@ -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<int, DataNode, bool> 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<int, DataNode, bool> 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);
Expand All @@ -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<int, DataNode, bool> 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<int, DataNode, bool> callback)
Expand Down Expand Up @@ -786,6 +847,12 @@ public void Execute(string cmd, Action<int, DataNode, bool> callback)
HandleGetPeer(args, connection, id, callback);
return;
}

case "getWalletVersion":
{
HandleGetWalletVersion(args, connection, id, callback);
return;
}

case "signData":
{
Expand Down Expand Up @@ -817,6 +884,12 @@ public void Execute(string cmd, Action<int, DataNode, bool> callback)
return;
}

case "getNexus":
{
HandleGetNexus(args, connection, id, callback);
return;
}

case "writeArchive":
{
HandleWriteArchive(args, connection, id, callback);
Expand Down
42 changes: 38 additions & 4 deletions Assets/Scripts/Wallet/AccountManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private void Awake()

var platforms = new List<PlatformKind>();
platforms.Add(PlatformKind.Phantasma);
//platforms.Add(PlatformKind.Neo);
platforms.Add(PlatformKind.Neo);
platforms.Add(PlatformKind.Ethereum);
platforms.Add(PlatformKind.BSC);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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}");
Expand Down
5 changes: 5 additions & 0 deletions Assets/Scripts/Wallet/AccountManagerClasses/AccountState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
26 changes: 13 additions & 13 deletions Assets/Scripts/Wallet/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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;
Expand All @@ -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:
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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:
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions Assets/Scripts/Wallet/WalletGUIFolder/WalletGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2386,6 +2386,7 @@ private void DoBalanceScreen()
{
accountManager.RefreshBalances(false, accountManager.CurrentPlatform);
});

var endY = DoBottomMenu();

if (accountManager.BalanceRefreshing)
Expand All @@ -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<Balance>(ref balanceScroll, startY, endY, VerticalLayout ? Units(7) : Units(6), state.balances.Where(x => x.Total >= 0.001m),
DoBalanceEntry);

Expand Down
Loading