Beispiel #1
0
        public async Task GetBlockChainInfo()
        {
            Network          network = new Network();
            BlockChainInfoOM result  = await network.GetBlockChainInfo();

            Assert.IsNotNull(result);
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public async Task <BlockChainInfoOM> GetBlockChainInfo()
        {
            AuthenticationHeaderValue authHeaderValue = null;
            RpcClient   client   = new RpcClient(new Uri("http://localhost:5006"), authHeaderValue, null, null, "application/json");
            RpcRequest  request  = RpcRequest.WithNoParameters("GetBlockChainInfo", 1);
            RpcResponse response = await client.SendRequestAsync(request);

            if (response.HasError)
            {
                throw new ApiCustomException(response.Error.Code, response.Error.Message);
            }
            BlockChainInfoOM responseValue = response.GetResult <BlockChainInfoOM>();

            return(responseValue);
        }
Beispiel #3
0
        public static async Task <ApiResponse> GetBlockChainInfo()
        {
            ApiResponse response = new ApiResponse();

            try
            {
                Network          network = new Network();
                BlockChainInfo   node    = new BlockChainInfo();
                BlockChainInfoOM result  = await network.GetBlockChainInfo();

                if (result != null)
                {
                    node.Connections             = result.Connections;
                    node.IsRunning               = result.IsRunning;
                    node.LocalLastBlockHeight    = result.LocalLastBlockHeight;
                    node.LocalLastBlockTime      = result.LocalLastBlockTime;
                    node.RemoteLatestBlockHeight = result.RemoteLatestBlockHeight;
                    node.TimeOffset              = result.TimeOffset;
                    node.TempBlockCount          = result.TempBlockCount;
                    response.Result              = Newtonsoft.Json.Linq.JToken.FromObject(node);
                }
                else
                {
                    response.Result = null;
                }
            }
            catch (ApiCustomException ex)
            {
                Logger.Singleton.Error(ex.ToString());
                response.Error = new ApiError(ex.ErrorCode, ex.ToString());
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error(ex.ToString());
                response.Error = new ApiError(ex.HResult, ex.ToString());
            }
            return(response);
        }