/// <summary> /// Returns the list of tokens owned by a wallet grouped by contract /// </summary> /// <remarks> /// <para> /// Currently this functionallity is only supported for MATIC wallets and items minted by BGSDK /// <para> /// For more information please see <see href="https://docs-staging.arkane.network/pages/reference.html#_get_inventory_arkane_api">https://docs-staging.arkane.network/pages/reference.html#_get_inventory_arkane_api</see> /// </para> /// </para> /// </remarks> /// <param name="walletId"></param> /// <param name="optionalContractAddresses">List of contract addresses to filter for, if empty or null all will be returned. Can be null</param> /// <param name="callback"></param> /// <returns>The Unity routine enumerator</returns> public static IEnumerator GetInventory(string walletId, List <string> optionalContractAddresses, Action <ListInventoryResults> callback) { if (BGSDKSettings.current == null) { callback(new ListInventoryResults() { hasError = true, message = "Attempted to call BGSDK.Wallets.UserWallet.ListNFTs with no BGSDK.Settings object applied." }); yield return(null); } else { if (BGSDKSettings.user == null) { callback(new ListInventoryResults() { hasError = true, message = "BGSDKSettings.user required, null Settings.user provided.", result = null }); yield return(null); } else { string address = BGSDKSettings.current.WalletUri + "/" + walletId + "/inventory"; if (optionalContractAddresses != null && optionalContractAddresses.Count > 0) { address += "?"; for (int i = 0; i < optionalContractAddresses.Count; i++) { if (i == 0) { address += "contract-addresses=" + optionalContractAddresses[i]; } else { address += "&contract-addresses=" + optionalContractAddresses[i]; } } } UnityWebRequest www = UnityWebRequest.Get(address); www.SetRequestHeader("Authorization", BGSDKSettings.user.authentication.token_type + " " + BGSDKSettings.user.authentication.access_token); var co = www.SendWebRequest(); while (!co.isDone) { yield return(null); } if (!www.isNetworkError && !www.isHttpError) { var results = new ListInventoryResults(); try { string resultContent = www.downloadHandler.text; results = JsonUtility.FromJson <ListInventoryResults>(Utilities.JSONArrayWrapper(resultContent)); results.message = "List NFTs complete."; results.httpCode = www.responseCode; } catch (Exception ex) { results = null; results.message = "An error occured while processing JSON results, see exception for more details."; results.exception = ex; results.httpCode = www.responseCode; } finally { callback(results); } } else { callback(new ListInventoryResults() { hasError = true, message = "Error:" + (www.isNetworkError ? " a network error occured while requesting inventory." : " a HTTP error occured while requesting inventory."), result = null, httpCode = www.responseCode }); } } } }