diff --git a/CHANGELOG.md b/CHANGELOG.md index 4048001..21ce890 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/Runtime/Phantasma/Scripts/PhantasmaLinkClient.cs b/Runtime/Phantasma/Scripts/PhantasmaLinkClient.cs index 307f6a9..279a544 100644 --- a/Runtime/Phantasma/Scripts/PhantasmaLinkClient.cs +++ b/Runtime/Phantasma/Scripts/PhantasmaLinkClient.cs @@ -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; } } @@ -83,6 +85,7 @@ public string Nexus private Dictionary> _requestCallbacks = new Dictionary>(); private Dictionary _balanceMap = new Dictionary(); + private Dictionary _ownershipMap = new Dictionary(); #region Events public static UnityEvent OnLogin; @@ -165,6 +168,7 @@ private void FetchAccount(Action callback) this.IsLogged = true; _balanceMap.Clear(); + _ownershipMap.Clear(); var balances = result.GetNode("balances"); if (balances != null) @@ -174,9 +178,17 @@ private void FetchAccount(Action 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); } } @@ -331,6 +343,22 @@ public decimal GetBalance(string symbol) return 0; } + + /// + /// Returns the NFTs IDs for a specific symbol + /// + /// + /// + public string[] GetNFTs(string symbol) + { + if (_ownershipMap.ContainsKey(symbol)) + { + var temp = _ownershipMap[symbol]; + return temp.ids; + } + + return Array.Empty(); + } /// /// Login to the Dapp diff --git a/Runtime/Phantasma/Scripts/Utils/WalletInteractions.cs b/Runtime/Phantasma/Scripts/Utils/WalletInteractions.cs index 93bba00..db3dca1 100644 --- a/Runtime/Phantasma/Scripts/Utils/WalletInteractions.cs +++ b/Runtime/Phantasma/Scripts/Utils/WalletInteractions.cs @@ -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);