private void HandleWalletResults(ListWalletResult walletResult)
 {
     if (!walletResult.hasError)
     {
         walletData = walletResult.result;
         Debug.Log("List Wallets Responce:\nReturned " + walletResult.result.Count.ToString() + " wallets. You can review the results in the inspector.");
     }
     else
     {
         Debug.Log("List Wallets Responce:\nHas Error: " + walletResult.hasError + "\nMessage: " + walletResult.message);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Create a whitelabel wallet
        /// </summary>
        /// <remarks>
        /// <para>
        /// For more information see <see href="https://docs-staging.arkane.network/pages/whitelabel.html#_create_wallet_arkane_api">https://docs-staging.arkane.network/pages/whitelabel.html#_create_wallet_arkane_api</see>
        /// </para>
        /// </remarks>
        /// <param name="pincode"></param>
        /// <param name="alias"></param>
        /// <param name="description"></param>
        /// <param name="identifier"></param>
        /// <param name="secretType"></param>
        /// <param name="callback"></param>
        /// <returns>The Unity routine enumerator</returns>
        public static IEnumerator CreateWhitelableWallet(string pincode, string alias, string description, string identifier, string secretType, Action <ListWalletResult> callback)
        {
            if (BGSDKSettings.current == null)
            {
                callback(new ListWalletResult()
                {
                    hasError = true, message = "Attempted to call BGSDK.Wallets.CreateWhitelabelWallet with no BGSDK.Settings object applied."
                });
                yield return(null);
            }
            else
            {
                if (BGSDKSettings.user == null)
                {
                    callback(new ListWalletResult()
                    {
                        hasError = true, message = "BGSDKSettings.user required, null Settings.user provided.\n Please initalize the Settings.user before calling CreateWhitelableWallet", result = null
                    });
                    yield return(null);
                }
                else
                {
                    WWWForm form = new WWWForm();
                    form.AddField("pincode", pincode);
                    form.AddField("alias", alias);
                    form.AddField("description", description);
                    form.AddField("identifier", identifier);
                    form.AddField("secretType", secretType);
                    form.AddField("walletType", "WHITE_LABEL");

                    UnityWebRequest www = UnityWebRequest.Post(BGSDKSettings.current.WalletUri, form);;
                    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 ListWalletResult();
                        try
                        {
                            string resultContent = www.downloadHandler.text;
                            results.result = new System.Collections.Generic.List <Wallet>();
                            results.result.Add(JsonUtility.FromJson <Wallet>(Utilities.JSONArrayWrapper(resultContent)));
                            results.message  = "Create wallet 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 ListWalletResult()
                        {
                            hasError = true, message = "Error:" + (www.isNetworkError ? " a network error occured while attempting creat a whitelable wallet." : " a HTTP error occured while attempting to creat a whitelable wallet."), result = null, httpCode = www.responseCode
                        });
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets a user wallet as available to the authorized Settings.user
        /// </summary>
        /// <param name="Settings.user">The Settings.user to query for</param>
        /// <param name="callback">A method pointer to handle the results of the query</param>
        /// <returns>The Unity routine enumerator</returns>
        /// <remarks>
        /// <see href="https://docs.arkane.network/pages/reference.html#get-specific-user-wallet">https://docs.arkane.network/pages/reference.html#get-specific-user-wallet</see>
        /// </remarks>
        public static IEnumerator Get(string walletId, Action <ListWalletResult> callback)
        {
            if (BGSDKSettings.current == null)
            {
                callback(new ListWalletResult()
                {
                    hasError = true, message = "Attempted to call BGSDK.Wallets.UserWallet.Get with no BGSDK.Settings object applied."
                });
                yield return(null);
            }
            else
            {
                if (BGSDKSettings.user == null)
                {
                    callback(new ListWalletResult()
                    {
                        hasError = true, message = "BGSDKSettings.user required, null Settings.user provided.", result = null
                    });
                    yield return(null);
                }
                else
                {
                    UnityWebRequest www = UnityWebRequest.Get(BGSDKSettings.current.WalletUri + "/" + walletId);
                    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 ListWalletResult();
                        try
                        {
                            string resultContent = www.downloadHandler.text;
                            results.result = new System.Collections.Generic.List <Wallet>();
                            results.result.Add(JsonUtility.FromJson <Wallet>(resultContent));
                            results.message  = "Wallet refresh 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 ListWalletResult()
                        {
                            hasError = true, message = "Error:" + (www.isNetworkError ? " a network error occured while requesting a user's wallet." : " a HTTP error occured while requesting a user's wallet."), result = null, httpCode = www.responseCode
                        });
                    }
                }
            }
        }