Beispiel #1
0
        /// <summary>
        /// Get CurrentBlockResponse data for the Result Id.
        /// </summary>
        /// <exception cref="Xooa.Client.Exception.XooaApiException">Thrown when fails to make API call</exception>
        /// <param name="resultId">Result Id of the transaction to fetch data.</param>
        /// <param name="timeout">Timeout interval for transaction.</param>
        /// <returns>CurrentBlockResponse giving the data about the CurrentBlock request.</returns>
        public CurrentBlockResponse getResultForCurrentBlock(string resultId, string timeout = "3000")
        {
            Log.Info("Invoking URL - " + XooaConstants.RESULT_URL);

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

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

            localVarQueryParameters.Add(new KeyValuePair <string, string>(XooaConstants.ASYNC, XooaConstants.FALSE));
            localVarQueryParameters.Add(new KeyValuePair <string, string>(XooaConstants.TIMEOUT, timeout));

            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("ResultId", resultId);

            int statusCode = 0;

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

                IRestResponse response = RestClient.Execute(request);

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

                var payload = details["result"];

                CurrentBlockResponse currentBlockResponse = new CurrentBlockResponse(
                    payload["currentBlockHash"].ToString(),
                    payload["previousBlockHash"].ToString(),
                    (int)payload["blockNumber"]);

                return(currentBlockResponse);
            } catch (XooaApiException xae) {
                Log.Error(xae);
                throw xae;
            } catch (XooaRequestTimeoutException xrte) {
                Log.Error(xrte);
                throw xrte;
            } catch (System.Exception e) {
                Log.Error(e);
                throw new XooaApiException(statusCode, e.Message);
            }
        }
Beispiel #2
0
        public void testGetCurrentBlockResponse()
        {
            XooaClient xooaClient = new XooaClient();

            xooaClient.setApiToken(XooaConstants.API_TOKEN);

            try {
                CurrentBlockResponse cbr = xooaClient.getCurrentBlock();

                Assert.IsNotEmpty(cbr.getBlockNumber().ToString());

                Assert.IsNotEmpty(cbr.getCurrentBlockHash());

                Assert.IsNotEmpty(cbr.getPreviousBlockHash());
            } catch (XooaRequestTimeoutException xrte) {
                //Assert.AreEqual(typeof(XooaRequestTimeoutException), xrte.GetType());

                Assert.IsNotEmpty(xrte.getResultId());

                Assert.IsNotEmpty(xrte.getResultUrl());
            }
        }
Beispiel #3
0
        public void testGetResultForCurrentBlock()
        {
            XooaClient xooaClient = new XooaClient();

            xooaClient.setApiToken(XooaConstants.API_TOKEN);

            string resultId = "75b9f849-389e-4a2d-9717-5f47cc3a688b";

            try {
                CurrentBlockResponse currentBlock = xooaClient.getResultForCurrentBlock(resultId);

                Assert.IsNotEmpty(currentBlock.getBlockNumber().ToString());

                Assert.IsNotEmpty(currentBlock.getCurrentBlockHash());

                Assert.IsNotEmpty(currentBlock.getPreviousBlockHash());
            } catch (XooaRequestTimeoutException xrte) {
                Assert.IsNotEmpty(xrte.getResultUrl());

                Assert.IsNotEmpty(xrte.getResultId());

                Assert.AreEqual(resultId, xrte.getResultId());
            }
        }