Skip to content

Commit

Permalink
Merge pull request #3 from phantasma-io/dev
Browse files Browse the repository at this point in the history
PhantasmaLink Update & Update to an example.
  • Loading branch information
TeknoPT committed Apr 17, 2023
2 parents 5ee9d3a + edb3181 commit 830129c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[V.1.0.8]

- On the FetchAccount added the _ownershipMap to store NFTs IDs.
- Added a call for getting all the NFTs IDs for a given symbol.

[V.1.0.7]

- Added missing API Calls.
Expand Down
32 changes: 30 additions & 2 deletions Runtime/Phantasma/Scripts/PhantasmaLinkClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ public struct Balance
public readonly string symbol;
public readonly BigInteger value;
public readonly int decimals;
public readonly string[] ids;

public Balance(string symbol, BigInteger value, int decimals)
public Balance(string symbol, BigInteger value, int decimals, string[] ids)
{
this.symbol = symbol;
this.value = value;
this.decimals = decimals;
this.ids = ids;
}
}

Expand Down Expand Up @@ -83,6 +85,7 @@ public string Nexus
private Dictionary<int, Action<DataNode>> _requestCallbacks = new Dictionary<int, Action<DataNode>>();

private Dictionary<string, Balance> _balanceMap = new Dictionary<string, Balance>();
private Dictionary<string, Balance> _ownershipMap = new Dictionary<string, Balance>();

#region Events
public static UnityEvent<bool, string> OnLogin;
Expand Down Expand Up @@ -165,6 +168,7 @@ private void FetchAccount(Action<bool, string> callback)
this.IsLogged = true;
_balanceMap.Clear();
_ownershipMap.Clear();
var balances = result.GetNode("balances");
if (balances != null)
Expand All @@ -174,9 +178,17 @@ private void FetchAccount(Action<bool, string> callback)
var symbol = child.GetString("symbol");
var value = child.GetString("value");
var decimals = child.GetInt32("decimals");
var ids_node = child.GetNode("ids");
var ids_array = new string[ids_node.ChildCount];
for (int i = 0; i < ids_node.ChildCount; i++)
{
ids_array[i] = ids_node.GetString(i);
}
var amount = BigInteger.Parse(value);
_balanceMap[symbol] = new Balance(symbol, amount, decimals);
_balanceMap[symbol] = new Balance(symbol, amount, decimals, ids_array);
if ( ids_node.ChildCount > 0)
_ownershipMap[symbol] = new Balance(symbol, amount, decimals, ids_array);
}
}
Expand Down Expand Up @@ -331,6 +343,22 @@ public decimal GetBalance(string symbol)

return 0;
}

/// <summary>
/// Returns the NFTs IDs for a specific symbol
/// </summary>
/// <param name="symbol"></param>
/// <returns></returns>
public string[] GetNFTs(string symbol)
{
if (_ownershipMap.ContainsKey(symbol))
{
var temp = _ownershipMap[symbol];
return temp.ids;
}

return Array.Empty<string>();
}

/// <summary>
/// Login to the Dapp
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Phantasma/Scripts/Utils/WalletInteractions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void GetNFTs()
if (!PhantasmaLinkClient.Instance.IsLogged) return;
PhantasmaAPI api = new PhantasmaAPI("https://testnet.phantasma.io/rpc");
var symbol = "CROWN";
var IDs = new String[] { "" };
var IDs = PhantasmaLinkClient.Instance.GetNFTs(symbol);
StartCoroutine(api.GetNFTs(symbol, IDs, (nfts) =>
{
Debug.Log(nfts.Length);
Expand Down

0 comments on commit 830129c

Please sign in to comment.