コード例 #1
0
 public string CreateTokenUri(Engine.Contract forContract)
 {
     if (forContract == null)
     {
         throw new NullReferenceException("A null contract was provided");
     }
     else
     {
         return(ContractUri + "/" + forContract.Id.ToString() + "/tokens");
     }
 }
コード例 #2
0
 public string DefineTokenTypeUri(AppId onApp, Engine.Contract forContract)
 {
     if (forContract == null)
     {
         throw new NullReferenceException("A null contract was provided");
     }
     else
     {
         return(GetContractUri(onApp) + "/" + forContract.Id.ToString() + "/define-token-type");
     }
 }
コード例 #3
0
 public string GetTokenUri(Engine.Contract forContract)
 {
     if (forContract == null)
     {
         throw new NullReferenceException("A null contract was provided");
     }
     else
     {
         return(ContractUri + "/" + forContract.Id + "/token-types");
     }
 }
コード例 #4
0
        /// <summary>
        /// <para>
        /// Before generating tokens, we need to define the type which will describe the token.
        /// </para>
        /// <see href ="https://docs-staging.arkane.network/pages/token-management.html#_create_token_type" />
        /// </summary>
        /// <param name="identity"></param>
        /// <param name="app"></param>
        /// <param name="contract"></param>
        /// <param name="token"></param>
        /// <param name="responce"></param>
        /// <returns></returns>
        public static IEnumerator CreateTokenType(Engine.Contract contract, Token token, Action <DataModel.CreateTokenTypeResult> responce)
        {
            //Define a type of token
            yield return(null);

            if (string.IsNullOrEmpty(BGSDKSettings.current.appId.clientSecret) || string.IsNullOrEmpty(BGSDKSettings.current.appId.clientId))
            {
                Debug.LogError("Failed to sync settings: you must populate the Client ID and Client Secret before you can sync settings.");
                yield return(null);
            }
            else if (string.IsNullOrEmpty(token.SystemName))
            {
                responce(new DataModel.CreateTokenTypeResult()
                {
                    hasError = true, message = "name required, null or empty name provided."
                });
                yield return(null);
            }
            else
            {
                var    request = new UnityWebRequest(BGSDKSettings.current.DefineTokenTypeUri(contract), "POST");
                byte[] bodyRaw = Encoding.UTF8.GetBytes(token.CreateTokenDefitionJson());
                request.uploadHandler   = (UploadHandler) new UploadHandlerRaw(bodyRaw);
                request.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer();
                request.SetRequestHeader("Authorization", BGSDKSettings.user.authentication.token_type + " " + BGSDKSettings.user.authentication.access_token);
                request.SetRequestHeader("Content-Type", "application/json");
                yield return(request.SendWebRequest());

                if (!request.isNetworkError && !request.isHttpError)
                {
                    string resultContent = request.downloadHandler.text;
                    var    results       = new DataModel.CreateTokenTypeResult();
                    results.result   = JsonUtility.FromJson <TokenCreateResponceData>(resultContent);
                    results.message  = "Define Token Type complete.";
                    results.httpCode = request.responseCode;
                    responce(results);
                }
                else
                {
                    responce(new DataModel.CreateTokenTypeResult()
                    {
                        hasError = true, message = "Error:" + (request.isNetworkError ? " a network error occured while attempting to define the token type." : " a HTTP error occured while attempting to define the token type."), httpCode = request.responseCode
                    });
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Fetch details about a specific contract for the current app Id
        /// </summary>
        /// <param name="contract">The contract to get</param>
        /// <param name="callback">The method to call back into with the results.</param>
        /// <returns>The Unity routine enumerator</returns>
        /// <remarks>
        /// <para>
        /// For more information please see <see href="https://docs.arkane.network/pages/token-management.html#_get_contract">https://docs.arkane.network/pages/token-management.html</see>
        /// </para>
        /// </remarks>
        /// <example>
        /// <para>
        /// How to call:
        /// </para>
        /// <code>
        /// StartCoroutine(API.TokenManagement.GetContract(Identity, contract, HandleGetContractResults));
        /// </code>
        /// </example>
        public static IEnumerator GetContract(Engine.Contract contract, Action<ContractResult> callback)
        {
            if (BGSDKSettings.current == null)
            {
                callback(new ContractResult() { hasError = true, message = "Attempted to call BGSDK.TokenManagement.GetContract with no BGSDK.Settings object applied.", result = null });
                yield return null;
            }
            else
            {
                if (BGSDKSettings.user == null)
                {
                    callback(new ContractResult() { hasError = true, message = "BGSDKIdentity required, null identity provided.\nPlease initalize the Settings.user variable before calling GetContract", result = null });
                    yield return null;
                }
                else
                {
                    UnityWebRequest www = UnityWebRequest.Get(BGSDKSettings.current.ContractUri + "/" + contract.Id);
                    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)
                    {
                        string resultContent = www.downloadHandler.text;
                        var results = new ContractResult();
                        results.result = JsonUtility.FromJson<DataModel.ContractData>(resultContent);
                        results.message = "Get Contract complete.";
                        results.httpCode = www.responseCode;
                        callback(results);
                    }
                    else
                    {
                        callback(new ContractResult() { hasError = true, message = "Error:" + (www.isNetworkError ? " a network error occured while requesting the contract." : " a HTTP error occured while requesting the contract."), result = null, httpCode = www.responseCode });
                    }
                }
            }
        }