示例#1
0
        public List <RewardList> GetAllUnPaidRewardGroup(string tableName, string blockHashes)
        {
            RewardListDac             dac    = new RewardListDac();
            Dictionary <string, long> dic    = dac.GetAllUnPaidRewardGroup(tableName, blockHashes);
            List <RewardList>         result = new List <RewardList>();

            foreach (var item in dic)
            {
                result.Add(new RewardList {
                    MinerAddress = item.Key, ActualReward = item.Value, OriginalReward = item.Value
                });
            }
            return(result);
        }
示例#2
0
        public RewardList InsertRewardList(RewardList entity)
        {
            RewardListDac dac = new RewardListDac();
            //if (dac.IsExisted(entity.BlockHash))
            //{
            //    throw new Exception("block hash has existed");
            //}
            //调接口获取奖励
            //AuthenticationHeaderValue authHeaderValue = null;
            //RpcClient client = new RpcClient(new Uri(MiningPoolSetting.API_URI), authHeaderValue, null, null, "application/json");
            //RpcRequest request = RpcRequest.WithParameterList("GetBlockReward", new List<object> { entity.BlockHash }, 1);
            //RpcResponse response = await client.SendRequestAsync(request);
            //if (response.HasError)
            //{
            //    throw new ApiCustomException(response.Error.Code, response.Error.Message);
            //}

            //long totalReward = response.GetResult<long>();
            RewardList reward = new RewardList();

            AwardSetting setting = ConfigurationTool.GetAppSettings <AwardSetting>("OmniCoin.MiningPool.Business.conf.json", "AwardSetting");

            //double extractProportion = setting.ExtractProportion;
            //double serviceFeeProportion = setting.ServiceFeeProportion;
            reward.BlockHash      = entity.BlockHash;
            reward.GenerateTime   = entity.GenerateTime;
            reward.Hashes         = entity.Hashes;
            reward.MinerAddress   = entity.MinerAddress;
            reward.OriginalReward = entity.OriginalReward;
            //reward.ActualReward = Convert.ToInt64(entity.OriginalReward * extractProportion);
            reward.ActualReward            = Convert.ToInt64(entity.OriginalReward);
            reward.Paid                    = 0;
            reward.PaidTime                = Framework.Time.EpochStartTime.Millisecond;
            reward.IsCommissionProcessed   = 0;
            reward.CommissionProcessedTime = 0;
            //此市transaction为“”,需要同步后才能写数据进去
            reward.TransactionHash = entity.TransactionHash;

            dac.Insert(reward);

            return(reward);
        }
示例#3
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);
            }
        }
示例#4
0
        public void UpdatePaidStatus(long id, string transactionHash)
        {
            RewardListDac dac = new RewardListDac();

            dac.UpdatePaid(id, 1, transactionHash);
        }
示例#5
0
        public RewardList GetRewardByHash(string hash)
        {
            RewardListDac dac = new RewardListDac();

            return(dac.SelectByHash(hash));
        }
示例#6
0
        public void UpdateNullPaidStatus(string tableName, string address, string blockHashes)
        {
            RewardListDac dac = new RewardListDac();

            dac.UpdateNullPaid(tableName, address, 1, blockHashes);
        }
示例#7
0
        public RewardList GetRewardById(long id)
        {
            RewardListDac dac = new RewardListDac();

            return(dac.SelectById(id));
        }
示例#8
0
        public long GetActualReward(string address, string blockHash)
        {
            RewardListDac dac = new RewardListDac();

            return(dac.GetActualReward(address, blockHash));
        }
示例#9
0
        public void UpdatePaidStatusByAddresses(string tableName, string address, string transactionHash, string blockHashes)
        {
            RewardListDac dac = new RewardListDac();

            dac.UpdatePaidByAddresses(tableName, address, 1, transactionHash, blockHashes);
        }
示例#10
0
        public List <RewardList> GetUnPaidRewardBlock()
        {
            RewardListDac dac = new RewardListDac();

            return(dac.GetUnPaidRewardBlock());
        }
示例#11
0
        public List <RewardList> GetCustomUnPaidReward(int count)
        {
            RewardListDac dac = new RewardListDac();

            return(dac.GetCustomUnPaidReward(count));
        }
示例#12
0
        /// <summary>
        /// 固定地址的发奖励,测试发消息队列专用
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="blockHashes"></param>
        /// <returns></returns>
        public List <RewardList> GetAllUnPaidRewardByAddresses(string tableName, string blockHashes, string addresses)
        {
            RewardListDac dac = new RewardListDac();

            return(dac.GetAllUnPaidRewardByAddresses(tableName, blockHashes, addresses));
        }
示例#13
0
        /// <summary>
        /// 获取单个矿工的已发放的奖励
        /// </summary>
        /// <param name="address"></param>
        /// <returns></returns>
        public long GetPaidReward(string address)
        {
            RewardListDac dac = new RewardListDac();

            return(dac.GetPaidReward(address, 1));
        }
示例#14
0
        public List <RewardList> GetAllReward()
        {
            RewardListDac dac = new RewardListDac();

            return(dac.SelectAll());
        }
示例#15
0
        public void DeleteReward(string hash)
        {
            RewardListDac dac = new RewardListDac();

            dac.Delete(hash);
        }
示例#16
0
        /*
         * public void UpdatePaidStatus(string hash, int status)
         * {
         *  RewardListDac dac = new RewardListDac();
         *  dac.UpdatePaid(hash, status);
         * }
         */

        public void DeleteReward(long id)
        {
            RewardListDac dac = new RewardListDac();

            dac.Delete(id);
        }