Skip to content

Commit

Permalink
Upgrading Poltergeist and fixing some minor issues.
Browse files Browse the repository at this point in the history
Removing NEO issue
  • Loading branch information
TeknoPT committed Oct 4, 2023
1 parent 5200b72 commit ed147fe
Show file tree
Hide file tree
Showing 35 changed files with 327 additions and 94 deletions.
5 changes: 3 additions & 2 deletions Assets/Scripts/Wallet/AccountManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2057,7 +2057,8 @@ public void RefreshBalances(bool force, PlatformKind platforms = PlatformKind.No

case PlatformKind.Neo:
{
var keys = NeoKeys.FromWIF(wif);
ReportWalletBalance(platform, null);
/*var keys = NeoKeys.FromWIF(wif);
var url = GetNeoscanAPIUrl($"get_balance/{keys.Address}");
Expand Down Expand Up @@ -2190,7 +2191,7 @@ public void RefreshBalances(bool force, PlatformKind platforms = PlatformKind.No
}
});
}));
}));*/
}
break;

Expand Down
3 changes: 3 additions & 0 deletions Assets/Scripts/Wallet/AccountManagerClasses.meta

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

30 changes: 30 additions & 0 deletions Assets/Scripts/Wallet/AccountManagerClasses/Account.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;

namespace Poltergeist
{
public struct Account
{
public string name;
public PlatformKind platforms;
public string phaAddress;
public string neoAddress;
public string ethAddress;
public string WIF;
public bool passwordProtected;
public int passwordIterations;
public string salt;
public string iv;
public string password; // Not used after account upgrade to version 2.
public string misc;

public override string ToString()
{
return $"{name.ToUpper()} [{platforms}]";
}

public string GetWif(string passwordHash)
{
return String.IsNullOrEmpty(passwordHash) ? WIF : AccountManager.DecryptString(WIF, passwordHash, iv);
}
}
}
3 changes: 3 additions & 0 deletions Assets/Scripts/Wallet/AccountManagerClasses/Account.cs.meta

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

9 changes: 9 additions & 0 deletions Assets/Scripts/Wallet/AccountManagerClasses/AccountFlags.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Poltergeist
{
public enum AccountFlags
{
None = 0x0,
Master = 0x1,
Validator = 0x2
}
}

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System.Collections.Generic;
using Phantasma.SDK;

namespace Poltergeist
{
public static class AccountFlagsExtensions
{
public static List<PlatformKind> Split(this PlatformKind kind)
{
var list = new List<PlatformKind>();
foreach (var platform in AccountManager.AvailablePlatforms)
{
if (kind.HasFlag(platform))
{
list.Add(platform);
}
}
return list;
}

public static PlatformKind GetTransferTargets(this PlatformKind kind, Token token)
{
if (!token.IsSwappable())
{
return kind;
}

PlatformKind targets;

switch (kind)
{
case PlatformKind.Phantasma:
targets = PlatformKind.Phantasma;
targets |= Tokens.HasSwappableToken(token.symbol, PlatformKind.Neo) ? PlatformKind.Neo : PlatformKind.None;
targets |= Tokens.HasSwappableToken(token.symbol, PlatformKind.Ethereum) ? PlatformKind.Ethereum : PlatformKind.None;
targets |= Tokens.HasSwappableToken(token.symbol, PlatformKind.BSC) ? PlatformKind.BSC : PlatformKind.None;
return targets;

case PlatformKind.Neo:
targets = PlatformKind.Neo;
targets |= Tokens.HasSwappableToken(token.symbol, PlatformKind.Phantasma) ? PlatformKind.Phantasma : PlatformKind.None;
return targets;

case PlatformKind.Ethereum:
targets = PlatformKind.Ethereum;
targets |= Tokens.HasSwappableToken(token.symbol, PlatformKind.Phantasma) ? PlatformKind.Phantasma : PlatformKind.None;
return targets;

case PlatformKind.BSC:
targets = PlatformKind.BSC;
targets |= Tokens.HasSwappableToken(token.symbol, PlatformKind.Phantasma) ? PlatformKind.Phantasma : PlatformKind.None;
return targets;

default:
return PlatformKind.None;
}
}
public static bool ValidateTransferTarget(this PlatformKind kind, Token token, PlatformKind targetKind)
{
var targets = kind.GetTransferTargets(token);
return targets.HasFlag(targetKind);
}
}
}

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

19 changes: 19 additions & 0 deletions Assets/Scripts/Wallet/AccountManagerClasses/AccountLegacyV1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Poltergeist
{
public struct AccountLegacyV1
{
public static readonly int MinPasswordLength = 6;
public static readonly int MaxPasswordLength = 32;

public string name;
public PlatformKind platforms;
public string WIF;
public string password;
public string misc;

public override string ToString()
{
return $"{name.ToUpper()} [{platforms}]";
}
}
}

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

43 changes: 43 additions & 0 deletions Assets/Scripts/Wallet/AccountManagerClasses/AccountState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System.Collections.Generic;
using Phantasma.Core.Types;
using Phantasma.SDK;

namespace Poltergeist
{
public class AccountState
{
public PlatformKind platform;
public string name;
public string address;
public Balance[] balances;
public AccountFlags flags;
public Timestamp stakeTime;

public Archive[] archives;
public string avatarData;
public uint availableStorage;
public uint usedStorage;
public uint totalStorage => availableStorage + usedStorage;

public Dictionary<string, string> dappTokens = new Dictionary<string, string>();

public decimal GetAvailableAmount(string symbol)
{
for (int i = 0; i < balances.Length; i++)
{
var entry = balances[i];
if (entry.Symbol == symbol)
{
return entry.Available;
}
}

return 0;
}

public void RegisterDappToken(string dapp, string token)
{
dappTokens[dapp] = token;
}
}
}

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

13 changes: 13 additions & 0 deletions Assets/Scripts/Wallet/AccountManagerClasses/AccountsExport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Poltergeist
{
public struct AccountsExport
{
public string walletIdentifier;
public int accountsVersion;
public string accounts;
public bool passwordProtected;
public int passwordIterations;
public string salt;
public string iv;
}
}

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

Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
namespace Poltergeist
{
public class Balance
{
public string Symbol;
public decimal Available;
public decimal Staked;
public decimal Pending;
public decimal Claimable;
public string Chain;
public int Decimals;
public bool Burnable;
public bool Fungible;
public string PendingPlatform;
public string PendingHash;
public string[] Ids;

public decimal Total => Available + Staked + Pending + Claimable;
}
}
namespace Poltergeist
{
public class Balance
{
public string Symbol;
public decimal Available;
public decimal Staked;
public decimal Pending;
public decimal Claimable;
public string Chain;
public int Decimals;
public bool Burnable;
public bool Fungible;
public string PendingPlatform;
public string PendingHash;
public string[] Ids;

public decimal Total => Available + Staked + Pending + Claimable;
}
}
3 changes: 3 additions & 0 deletions Assets/Scripts/Wallet/AccountManagerClasses/Balance.cs.meta

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

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;

namespace Poltergeist
{
public struct HistoryEntry
{
public string hash;
public DateTime date;
public string url;
}
}
using System;

namespace Poltergeist
{
public struct HistoryEntry
{
public string hash;
public DateTime date;
public string url;
}
}

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

14 changes: 14 additions & 0 deletions Assets/Scripts/Wallet/AccountManagerClasses/PlatformKind.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace Poltergeist
{
[Flags]
public enum PlatformKind
{
None = 0x0,
Phantasma = 0x1,
Neo = 0x2,
Ethereum = 0x4,
BSC = 0x8,
}
}

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

Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
using System;

namespace Poltergeist
{
public class RefreshStatus
{
// Balance
public bool BalanceRefreshing;
public DateTime LastBalanceRefresh;
public Action BalanceRefreshCallback;
// History
public bool HistoryRefreshing;
public DateTime LastHistoryRefresh;

public override string ToString()
{
return $"BalanceRefreshing: {BalanceRefreshing}, LastBalanceRefresh: {LastBalanceRefresh}, HistoryRefreshing: {HistoryRefreshing}, LastHistoryRefresh: {LastHistoryRefresh}";
}
}
}
using System;

namespace Poltergeist
{
public class RefreshStatus
{
// Balance
public bool BalanceRefreshing;
public DateTime LastBalanceRefresh;
public Action BalanceRefreshCallback;
// History
public bool HistoryRefreshing;
public DateTime LastHistoryRefresh;

public override string ToString()
{
return $"BalanceRefreshing: {BalanceRefreshing}, LastBalanceRefresh: {LastBalanceRefresh}, HistoryRefreshing: {HistoryRefreshing}, LastHistoryRefresh: {LastHistoryRefresh}";
}
}
}

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

Loading

0 comments on commit ed147fe

Please sign in to comment.