Skip to content

Commit 830129c

Browse files
authored
Merge pull request #3 from phantasma-io/dev
PhantasmaLink Update & Update to an example.
2 parents 5ee9d3a + edb3181 commit 830129c

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
[V.1.0.8]
2+
3+
- On the FetchAccount added the _ownershipMap to store NFTs IDs.
4+
- Added a call for getting all the NFTs IDs for a given symbol.
5+
16
[V.1.0.7]
27

38
- Added missing API Calls.

Runtime/Phantasma/Scripts/PhantasmaLinkClient.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ public struct Balance
2020
public readonly string symbol;
2121
public readonly BigInteger value;
2222
public readonly int decimals;
23+
public readonly string[] ids;
2324

24-
public Balance(string symbol, BigInteger value, int decimals)
25+
public Balance(string symbol, BigInteger value, int decimals, string[] ids)
2526
{
2627
this.symbol = symbol;
2728
this.value = value;
2829
this.decimals = decimals;
30+
this.ids = ids;
2931
}
3032
}
3133

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

8587
private Dictionary<string, Balance> _balanceMap = new Dictionary<string, Balance>();
88+
private Dictionary<string, Balance> _ownershipMap = new Dictionary<string, Balance>();
8689

8790
#region Events
8891
public static UnityEvent<bool, string> OnLogin;
@@ -165,6 +168,7 @@ private void FetchAccount(Action<bool, string> callback)
165168
this.IsLogged = true;
166169

167170
_balanceMap.Clear();
171+
_ownershipMap.Clear();
168172

169173
var balances = result.GetNode("balances");
170174
if (balances != null)
@@ -174,9 +178,17 @@ private void FetchAccount(Action<bool, string> callback)
174178
var symbol = child.GetString("symbol");
175179
var value = child.GetString("value");
176180
var decimals = child.GetInt32("decimals");
181+
var ids_node = child.GetNode("ids");
182+
var ids_array = new string[ids_node.ChildCount];
183+
for (int i = 0; i < ids_node.ChildCount; i++)
184+
{
185+
ids_array[i] = ids_node.GetString(i);
186+
}
177187

178188
var amount = BigInteger.Parse(value);
179-
_balanceMap[symbol] = new Balance(symbol, amount, decimals);
189+
_balanceMap[symbol] = new Balance(symbol, amount, decimals, ids_array);
190+
if ( ids_node.ChildCount > 0)
191+
_ownershipMap[symbol] = new Balance(symbol, amount, decimals, ids_array);
180192
}
181193
}
182194

@@ -331,6 +343,22 @@ public decimal GetBalance(string symbol)
331343

332344
return 0;
333345
}
346+
347+
/// <summary>
348+
/// Returns the NFTs IDs for a specific symbol
349+
/// </summary>
350+
/// <param name="symbol"></param>
351+
/// <returns></returns>
352+
public string[] GetNFTs(string symbol)
353+
{
354+
if (_ownershipMap.ContainsKey(symbol))
355+
{
356+
var temp = _ownershipMap[symbol];
357+
return temp.ids;
358+
}
359+
360+
return Array.Empty<string>();
361+
}
334362

335363
/// <summary>
336364
/// Login to the Dapp

Runtime/Phantasma/Scripts/Utils/WalletInteractions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void GetNFTs()
9595
if (!PhantasmaLinkClient.Instance.IsLogged) return;
9696
PhantasmaAPI api = new PhantasmaAPI("https://testnet.phantasma.io/rpc");
9797
var symbol = "CROWN";
98-
var IDs = new String[] { "" };
98+
var IDs = PhantasmaLinkClient.Instance.GetNFTs(symbol);
9999
StartCoroutine(api.GetNFTs(symbol, IDs, (nfts) =>
100100
{
101101
Debug.Log(nfts.Length);

0 commit comments

Comments
 (0)