예제 #1
0
        public void UpdatePaidStatus(long id, string transactionHash)
        {
            RewardListDac dac = new RewardListDac();

            dac.UpdatePaid(id, 1, transactionHash);
        }
예제 #2
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);
            }
        }
예제 #3
0
        public void UpdatePaidStatus(string tableName, string address, string transactionHash, string blockHashes)
        {
            RewardListDac dac = new RewardListDac();

            dac.UpdatePaid(tableName, address, 1, transactionHash, blockHashes);
        }