public BlockDetail GetBlockDetail(string hash) { var block = BlockDac.Default.SelectByHash(hash); if (block == null) { return(null); } BlockDetail detail = new BlockDetail(); detail.TradeCount = block.Header.TotalTransaction; detail.TotalOutput = block.Transactions.SelectMany(x => x.Outputs).Where(x => x.Amount > 0).Sum(x => x.Amount); var reward = POC.GetNewBlockReward(block.Header.Height); detail.Height = block.Header.Height; detail.Timestamp = block.Header.Timestamp; detail.Difficulty = POC.CalculateDifficulty(block.Header.Bits); detail.Bits = block.Header.Bits; detail.Version = block.Header.Version; detail.Nonce = block.Header.Nonce; detail.BlockReward = reward; detail.Hash = block.Header.Hash; detail.PreviousBlockHash = block.Header.PreviousBlockHash; var nextHash = BlockDac.Default.GetBlockHashByHeight(detail.Height + 1); detail.NextBlockHash = nextHash; detail.TranList = new List <TransOM>(); block.Transactions.ForEach(x => { detail.TranList.Add(x.ConvertToDetail()); }); var tx = detail.TranList.Skip(0); var totalFee = tx.SelectMany(x => x.OutputList).Sum(x => x.Amount) - tx.SelectMany(x => x.InputList).Sum(x => x.Amount); detail.TransactionFees = totalFee; return(detail); }
public static void SaveBlockRates() { long difficulty = 0; if (PoolCenterJob.Current.CurrentStartMiningMsg != null) { var block = RedisManager.Current.GetDataInRedis <BlockMsg>(PoolCenterJob.Current.CurrentStartMiningMsg.Id); difficulty = Convert.ToInt64(POC.CalculateDifficulty(block.Header.Bits)); } else { var height = NodeApi.Current.GetBlockHeight(); var block = NodeApi.Current.GetBlockByHeight(height); difficulty = Convert.ToInt64(POC.CalculateDifficulty(block.Header.Bits)); } BlockRatesComponent component = new BlockRatesComponent(); component.SaveBlockRates(CenterCache.GenarateBlockCount, difficulty); CenterCache.GenarateBlockCount = 0; }