示例#1
0
        /// <summary>
        /// The query API endpoint is used for querying (reading) a blockchain ledger using smart contract function.
        /// The endpoint must call a function already defined in your smart contract app which will process the query request.
        /// The function name is part of the endpoint URL, or can be entered as the fcn parameter when testing using the Sandbox.
        /// The function arguments (number of arguments and type) is determined by the smart contract.
        /// The smart contract is responsible for validation and exception management.
        /// In case of error the smart contract is responsible for returning the proper http error code.
        /// When exception happens, and it is not caught by smart contract or if caught and no http status code is returned,
        /// the API gateway will return http-status-code 500 to the client app.
        ///
        /// For example, if testing the sample get-set smart contract app, enter ‘get’ (without quotes) as the value for fcn.
        ///
        /// The response body is also determined by the smart contract app, and that’s also the reason why a consistent
        /// response sample is unavailable for this endpoint. A success response may be either 200 or 202.
        /// </summary>
        /// <exception cref="Xooa.Client.Exception.XooaApiException">Thrown when fails to make API call</exception>
        /// <param name="functionName">Function Name to Query.</param>
        /// <param name="args">Arguments for the Query.</param>
        /// <returns>PendingTransactionResponse giving the resultId and resultUrl.</returns>
        public PendingTransactionResponse queryAsync(string functionName, string[] args)
        {
            Log.Info("Invoking URL - " + XooaConstants.QUERY_URL);

            var localVarPath = XooaConstants.QUERY_URL;
            var contentType  = XooaConstants.CONTENT_TYPE;

            var localVarQueryParameters = new List <KeyValuePair <string, string> >();

            localVarQueryParameters.Add(new KeyValuePair <string, string>(XooaConstants.ASYNC, XooaConstants.TRUE));
            localVarQueryParameters.Add(new KeyValuePair <string, string>(XooaConstants.TIMEOUT, "1000"));

            var localVarHeaderParams = new Dictionary <string, string>();

            localVarHeaderParams.Add(XooaConstants.ACCEPT, XooaConstants.CONTENT_TYPE);
            localVarHeaderParams.Add(XooaConstants.AUTHORIZATION, XooaConstants.TOKEN + ApiToken);

            var localVarPathParams = new Dictionary <string, string>();

            localVarPathParams.Add("fcn", functionName);

            int statusCode = 0;

            string jsonData = "[\"";

            for (int i = 0; i < args.Length; i++)
            {
                jsonData += args[i];

                if (i != args.Length - 1)
                {
                    jsonData += "\", \"";
                }
            }
            jsonData += "\"]";

            try {
                RestRequest request = XooaSDK.Client.Util.Request.PrepareRequest(localVarPath,
                                                                                 RestSharp.Method.POST, localVarQueryParameters, jsonData, localVarHeaderParams,
                                                                                 null, localVarPathParams, contentType);

                IRestResponse response = RestClient.ExecuteTaskAsync(request).Result;

                JObject details = XooaSDK.Client.Util.Request.getDataAsync(response);

                PendingTransactionResponse pendingTransactionResponse = new PendingTransactionResponse(
                    details["resultId"].ToString(), details["resultURL"].ToString());

                return(pendingTransactionResponse);
            } catch (XooaApiException xae) {
                Log.Error(xae);
                throw xae;
            } catch (System.Exception e) {
                Log.Error(e);
                throw new XooaApiException(statusCode, e.Message);
            }
        }
示例#2
0
        public void testGetTransactionByTransactionIdAsync()
        {
            XooaClient xooaClient = new XooaClient();

            xooaClient.setApiToken(XooaConstants.API_TOKEN);

            PendingTransactionResponse ptr = xooaClient.getTransactionByTransactionIdAsync("1159c90618cc535338e8dfb39fc86800405ff9c082f7011808d4307a3104ef8d");

            Assert.IsNotEmpty(ptr.getResultId());

            Assert.IsNotEmpty(ptr.getResultUrl());
        }
示例#3
0
        public void testGetBlockByNumberAsync()
        {
            XooaClient xooaClient = new XooaClient();

            xooaClient.setApiToken(XooaConstants.API_TOKEN);

            PendingTransactionResponse ptr = xooaClient.getBlockByNumberAsync("10");

            ptr.display();
            Assert.IsNotEmpty(ptr.getResultId());

            Assert.IsNotEmpty(ptr.getResultUrl());
        }
示例#4
0
        public void testInvokeAsync()
        {
            string functionName = "set";

            string[] args = { "args1", "350" };

            XooaClient xooaClient = new XooaClient();

            xooaClient.setApiToken(XooaConstants.API_TOKEN);

            PendingTransactionResponse pendingResponse = xooaClient.invokeAsync(functionName, args);

            pendingResponse.display();

            Assert.IsNotEmpty(pendingResponse.getResultId());

            Assert.IsNotEmpty(pendingResponse.getResultUrl());
        }
示例#5
0
        /// <summary>
        /// Use this endpoint to Get transaction by transaction id.
        /// </summary>
        /// <exception cref="Xooa.Client.Exception.XooaApiException">Thrown when fails to make API call</exception>
        /// <param name="transactionId">Transaction Id to fetch data</param>
        /// <returns>PendingTransactionResponse giving the resultId for the transaction.</returns>
        public PendingTransactionResponse getTransactionByTransactionIdAsync(string transactionId)
        {
            Log.Info("Invoking URL - " + XooaConstants.BLOCK_DATA_URL);

            var localVarPath = XooaConstants.BLOCK_DATA_URL;
            var contentType  = XooaConstants.CONTENT_TYPE;

            var localVarQueryParameters = new List <KeyValuePair <string, string> >();

            localVarQueryParameters.Add(new KeyValuePair <string, string>(XooaConstants.ASYNC, XooaConstants.TRUE));
            localVarQueryParameters.Add(new KeyValuePair <string, string>(XooaConstants.TIMEOUT, "1000"));

            var localVarHeaderParams = new Dictionary <string, string>();

            localVarHeaderParams.Add(XooaConstants.ACCEPT, XooaConstants.CONTENT_TYPE);
            localVarHeaderParams.Add(XooaConstants.AUTHORIZATION, XooaConstants.TOKEN + apiToken);

            var localVarPathParams = new Dictionary <string, string>();

            localVarPathParams.Add("TransactionId", transactionId);

            int statusCode = 0;

            try {
                RestRequest request = XooaSDK.Client.Util.Request.PrepareRequest(localVarPath, RestSharp.Method.GET,
                                                                                 localVarQueryParameters, null, localVarHeaderParams, null, localVarPathParams, contentType);

                IRestResponse response = RestClient.ExecuteTaskAsync(request).Result;

                JObject details = XooaSDK.Client.Util.Request.getDataAsync(response);

                PendingTransactionResponse pendingTransactionResponse = new PendingTransactionResponse(
                    details["resultId"].ToString(), details["resultURL"].ToString());

                return(pendingTransactionResponse);
            } catch (XooaApiException xae) {
                Log.Error(xae);
                throw xae;
            } catch (System.Exception e) {
                Log.Error(e);
                throw new XooaApiException(statusCode, e.Message);
            }
        }
        public void testEnrollIdentityAsync()
        {
            XooaClient xooaClient = new XooaClient();

            xooaClient.setApiToken(XooaConstants.API_TOKEN);

            var attrs = new List <attrs>();

            attrs.Add(new attrs("sample", "value", false));

            IdentityRequest request = new IdentityRequest("Kavi", "r", true, attrs);

            PendingTransactionResponse response = xooaClient.enrollIdentityAsync(request);

            response.display();

            Assert.IsNotEmpty(response.getResultId());

            Assert.IsNotEmpty(response.getResultUrl());
        }
示例#7
0
        static void Main(string[] args)
        {
            //WebSocket socket = new WebSocket();
            //socket.subscribeAllEvents();

            XooaClient client = new XooaClient();

            client.setApiToken("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJBcGlLZXkiOiJIU0E0SkZRLUFHUjQ0NUstSkcwOUMzMi1CUDgyVDRZIiwiQXBpU2VjcmV0IjoiS2JZSzdDVHVaWThZSk9aIiwiUGFzc3BocmFzZSI6IjA1N2M2ODM3NjgyZDBjODBkMTllYTk0NjliYzI0MzczIiwiaWF0IjoxNTQzOTkzNjIzfQ.BkNZ6N5FfjCdYsAOYisFSelUDftDhnY3f8OYf4EgXYc");

            //client.subscribeAllEvents((data) => {
            //    Console.WriteLine("data - ", data.ToString());
            //});

            try {
                Console.WriteLine("----- Start -----");

                Console.WriteLine("----- Validate -----");

                client.validate().display();

                Console.WriteLine();

                Console.WriteLine("----- Current Block -----");

                client.getCurrentBlock().display();

                Console.WriteLine();

                Console.WriteLine("----- Current Block Async -----");

                PendingTransactionResponse currentBlockResponse = client.getCurrentBlockAsync();
                currentBlockResponse.display();

                Console.WriteLine();

                Console.WriteLine("----- Current Block From Result Id -----");

                client.getResultForCurrentBlock(currentBlockResponse.getResultId()).display();

                Console.WriteLine();

                Console.WriteLine("----- Block by Number -----");

                client.getBlockByNumber("10").display();

                Console.WriteLine();

                Console.WriteLine("----- Block by NUmber Async -----");

                PendingTransactionResponse blockByNumber = client.getBlockByNumberAsync("10");
                blockByNumber.display();

                Console.WriteLine();

                Console.WriteLine("----- Block Data from Result Id -----");

                client.getResultForBlockByNumber(blockByNumber.getResultId()).display();

                Console.WriteLine();

                Console.WriteLine("----- Invoke -----");

                string[] invokeargs = { "argsx", "200" };

                client.invoke("set", invokeargs).display();

                Console.WriteLine();

                Console.WriteLine("----- Query -----");

                string[] queryArgs = { "argsx" };

                client.query("get", queryArgs).display();

                Console.WriteLine();

                Console.WriteLine("----- Invoke Async -----");

                string[] invokeargs2 = { "argsx", "400" };

                PendingTransactionResponse invokeResponse = client.invokeAsync("set", invokeargs2);
                invokeResponse.display();
                Thread.Sleep(4000);

                Console.WriteLine();

                Console.WriteLine("----- Invoke from Result Id -----");

                client.getResultForInvoke(invokeResponse.getResultId()).display();

                Console.WriteLine();

                Console.WriteLine("----- Query Async -----");

                PendingTransactionResponse queryResponse = client.queryAsync("get", queryArgs);
                queryResponse.display();

                Console.WriteLine();

                Console.WriteLine("----- Query from Result ID -----");

                client.getResultForQuery(queryResponse.getResultId()).display();

                Console.WriteLine();

                Console.WriteLine("----- Current Identity -----");

                client.currentIdentity().display();

                Console.WriteLine();

                Console.WriteLine("----- Get All Identities -----");

                List <IdentityResponse> identities = client.getIdentities();
                foreach (IdentityResponse identity in identities)
                {
                    identity.display();
                    Console.WriteLine();
                }

                Console.WriteLine("----- Enroll Identity -----");

                attrs Attrib = new attrs("Name", "Value", false);

                List <attrs> attributes = new List <attrs>();
                attributes.Add(Attrib);

                IdentityRequest idReq = new IdentityRequest("Kavi", "r", false, attributes);

                IdentityResponse newIdentity1 = client.enrollIdentity(idReq);
                newIdentity1.display();

                Console.WriteLine();

                Console.WriteLine("----- Enroll Identity Async -----");

                PendingTransactionResponse pendingIdentity = client.enrollIdentityAsync(idReq);
                pendingIdentity.display();

                Console.WriteLine();

                Console.WriteLine("----- New Identity from Result Id -----");

                IdentityResponse newIdentity2 = client.getResultForIdentity(pendingIdentity.getResultId());
                newIdentity2.display();

                Console.WriteLine();

                Console.WriteLine("----- Regenerate New API Token -----");

                IdentityResponse newTokenId = client.regenerateIdentityApiToken(newIdentity1.getId());
                newTokenId.display();

                Console.WriteLine();

                Console.WriteLine("----- Get Identity -----");

                client.getIdentity(newTokenId.getId()).display();

                Console.WriteLine();

                Console.WriteLine("----- Delete Identity -----");

                string deleted1 = client.deleteIdentity(newIdentity2.getId());
                Console.WriteLine(deleted1);
                string deleted2 = client.deleteIdentity(newIdentity1.getId());
                Console.WriteLine(deleted2);

                Console.WriteLine();

                Console.WriteLine("----- End -----");
            } catch (XooaApiException xae) {
                xae.display();
            } catch (XooaRequestTimeoutException xrte) {
                xrte.display();
            }
            //Console.ReadLine();
        }