Beispiel #1
0
        public async Task InvokeRequest_OptionalParameter_Valid()
        {
            DefaultRpcInvoker invoker         = this.GetInvoker();
            IServiceProvider  serviceProvider = this.GetServiceProvider();
            IRouteContext     routeContext    = this.GetRouteContext <TestRouteClass>();


            //No params specified
            RpcRequest  stringRequest = RpcRequest.WithNoParameters("Optional", "1");
            RpcResponse response      = await invoker.InvokeRequestAsync(stringRequest, RpcPath.Default, routeContext);

            RpcResponse resultResponse = Assert.IsType <RpcResponse>(response);

            Assert.Null(resultResponse.Result);
            Assert.False(resultResponse.HasError);

            //Param is empty
            stringRequest = RpcRequest.WithParameterList("Optional", new object[0], "1");
            response      = await invoker.InvokeRequestAsync(stringRequest, RpcPath.Default, routeContext);

            resultResponse = Assert.IsType <RpcResponse>(response);
            Assert.Null(resultResponse.Result);
            Assert.False(resultResponse.HasError);


            //Param is a string
            stringRequest = RpcRequest.WithParameterList("Optional", new[] { JToken.FromObject("Test") }, "1");
            response      = await invoker.InvokeRequestAsync(stringRequest, RpcPath.Default, routeContext);

            resultResponse = Assert.IsType <RpcResponse>(response);
            Assert.NotNull(resultResponse.Result);
            Assert.Equal("Test", resultResponse.Result);
        }
Beispiel #2
0
        public async Task StopEngine()
        {
            AuthenticationHeaderValue authHeaderValue = null;
            RpcClient   client   = new RpcClient(new Uri(WalletNetwork.NetWork), authHeaderValue, null, null, "application/json");
            RpcRequest  request  = RpcRequest.WithNoParameters("StopEngine", 1);
            RpcResponse response = await client.SendRequestAsync(request);

            if (response.HasError)
            {
                throw new ApiCustomException(response.Error.Code, response.Error.Message);
            }
        }
Beispiel #3
0
        public async Task ClearBanned()
        {
            AuthenticationHeaderValue authHeaderValue = null;
            RpcClient   client   = new RpcClient(new Uri("http://localhost:5006"), authHeaderValue, null, null, "application/json");
            RpcRequest  request  = RpcRequest.WithNoParameters("ClearBanned", 1);
            RpcResponse response = await client.SendRequestAsync(request);

            if (response.HasError)
            {
                throw new ApiCustomException(response.Error.Code, response.Error.Message);
            }
        }
Beispiel #4
0
        public async Task <ChainTipsOM[]> GetChainTips()
        {
            AuthenticationHeaderValue authHeaderValue = null;
            RpcClient   client   = new RpcClient(new Uri(WalletNetwork.NetWork), authHeaderValue, null, null, "application/json");
            RpcRequest  request  = RpcRequest.WithNoParameters("GetChainTips", 1);
            RpcResponse response = await client.SendRequestAsync(request);

            if (response.HasError)
            {
                throw new ApiCustomException(response.Error.Code, response.Error.Message);
            }
            ChainTipsOM[] responseValue = response.GetResult <ChainTipsOM[]>();
            return(responseValue);
        }
Beispiel #5
0
        public async Task <PeerInfoOM[]> GetPeerInfo()
        {
            AuthenticationHeaderValue authHeaderValue = null;
            RpcClient   client   = new RpcClient(new Uri("http://localhost:5006"), authHeaderValue, null, null, "application/json");
            RpcRequest  request  = RpcRequest.WithNoParameters("GetPeerInfo", 1);
            RpcResponse response = await client.SendRequestAsync(request);

            if (response.HasError)
            {
                throw new ApiCustomException(response.Error.Code, response.Error.Message);
            }
            PeerInfoOM[] responseValue = response.GetResult <PeerInfoOM[]>();
            return(responseValue);
        }
Beispiel #6
0
        public async Task InvokeRequest_ServiceProvider_Pass()
        {
            RpcRequest stringRequest = RpcRequest.WithNoParameters("Test", "1");

            DefaultRpcInvoker invoker         = this.GetInvoker();
            IServiceProvider  serviceProvider = this.GetServiceProvider();
            IRouteContext     routeContext    = this.GetRouteContext <TestIoCRouteClass>();
            RpcResponse       response        = await invoker.InvokeRequestAsync(stringRequest, RpcPath.Default, routeContext);

            RpcResponse resultResponse = Assert.IsType <RpcResponse>(response);

            Assert.NotNull(resultResponse.Result);
            Assert.Equal(1, resultResponse.Result);
        }
Beispiel #7
0
        /* 实现思路
         * 1、调取JsonRpc接口获取当前区块高度
         * 2、根据当前区块高度排除数据库中6个以内的区块(因为一定是未确认的)
         * 3、拿出剩余未确认的区块,调取Rpc接口判断区块是否被确认
         * 4、批量更新数据库的确认状态和是否作废状态
         * 5、需要更新RewardList表中的是否作废状态
         *
         * 备注:Rpc接口判断区块是否被确认这个接口需要自己用Rpc写
         * 接口:根据传入的区块Hash判断是否区块是否被确认
         * 接口返回值:返回被确认的区块Hash
         */

        /// <summary>
        /// 更新区块的确认状态和抛弃状态
        /// </summary>
        /// <returns></returns>
        public async Task GetVerifiedHashes()
        {
            //不能直接调用OmniCoin.Bussiness,需要使用JsonRpc调用接口
            //先通过JsonRpc获取当前区块高度
            LogHelper.Debug($"****************begin to sync blocks********************");
            BlocksDac                 dac             = new BlocksDac();
            RewardListDac             rewardDac       = new RewardListDac();
            MinersDac                 minersDac       = new MinersDac();
            AuthenticationHeaderValue authHeaderValue = null;

            LogHelper.Debug($"API_URI is {MiningPoolSetting.API_URI}");
            long responseValue = 0;

            try
            {
                RpcClient   client   = new RpcClient(new Uri(MiningPoolSetting.API_URI), authHeaderValue, null, null, "application/json");
                RpcRequest  request  = RpcRequest.WithNoParameters("GetBlockCount", 1);
                RpcResponse response = await client.SendRequestAsync(request);

                if (response.HasError)
                {
                    throw new ApiCustomException(response.Error.Code, response.Error.Message);
                }

                responseValue = response.GetResult <long>();
                LogHelper.Debug($"responseValue:{responseValue}");
                LogHelper.Debug($"sqlite block hight is {responseValue}");
                if (responseValue - 100 > 0)
                {
                    //根据responseValue获取数据库中高度小于responseValue - 6的所有Hash值
                    List <string> hashes      = dac.GetAppointedHash(responseValue - 100);
                    RpcRequest    requestHash = RpcRequest.WithParameterList("GetVerifiedHashes", new List <object> {
                        hashes
                    }, 1);
                    RpcResponse responseHash = await client.SendRequestAsync(requestHash);

                    if (responseHash.HasError)
                    {
                        throw new ApiCustomException(response.Error.Code, response.Error.Message);
                    }
                    List <Block> list = responseHash.GetResult <List <Block> >();
                    LogHelper.Info($"Verified Hashes count is {list.Count}");

                    /*发送到阿里云消息队列
                     * foreach (Block item in list)
                     * {
                     *  //根据Block获取RewardList
                     *  string tableName = "RewardList" + Time.GetLocalDateTime(item.Timestamp).ToString("yyyyMMdd");
                     *  List<RewardList> rewardList = rewardDac.GetListByHash(tableName, item.Hash);
                     *  string sendBody = Newtonsoft.Json.JsonConvert.SerializeObject(new { item, rewardList });
                     *
                     *  AliMQ.ProducerMessage producer = new AliMQ.ProducerMessage();
                     *  producer.Initialize("MinerReward");
                     *  producer.SendNormalMessage(item.GeneratorId, sendBody, item.Hash);
                     * }
                     */
                    //根据list的值批量更新数据库
                    foreach (var item in list)
                    {
                        LogHelper.Info($"begin update block confirm");
                        UpdateBlockConfirmed(item.Hash, (item.IsVerified ? 1 : 0), (item.IsDiscarded ? 1 : 0));
                        string tableName = "RewardList" + Time.GetLocalDateTime(item.Timestamp).ToString("yyyyMMdd");
                        //如果区块作废就更新RewardList表状态
                        if (item.IsDiscarded)
                        {
                            LogHelper.Info($"begin update discarded blocks");
                            rewardDac.UpdatePaid(tableName, item.Hash, 2, responseValue - 100);
                            //更新Miners表中的未发放UnpaidReward余额
                            minersDac.UpdateDiscardedUnpaidReward(tableName, item.Hash);
                        }
                    }
                    //丢弃那些状态失败的,根据区块高度和confirm=0更新IsDiscard
                    UpdateFailBlock(responseValue - 100);
                    LogHelper.Debug($"****************end to sync blocks********************");
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message, ex);
            }
        }