public static void Test() { DateTime bhpCreationTime = DateTime.UtcNow; FileStream fs = new FileStream($"{System.Environment.CurrentDirectory}\\BHP_Output.txt", FileMode.Create); StreamWriter sw = new StreamWriter(fs); sw.WriteLine($"Start {DateTime.Now.ToLocalTime()}"); sw.Flush(); uint blockIndex = 0; Console.WriteLine(bhpCreationTime); string line = ""; Fixed8 lastSubsidy = Fixed8.Zero; Fixed8 totalSubsidy = Fixed8.Zero; Fixed8 lastTotal = Fixed8.Zero; while (true) { Fixed8 nSubsidy = MiningSubsidy.GetMiningSubsidy(blockIndex); if (nSubsidy == Fixed8.Zero) { break; } totalSubsidy = totalSubsidy + nSubsidy; lastTotal = lastTotal + nSubsidy; line = string.Format("Height: {0},Time: {1},Subsidy:{2} BHP,Current:{3} BHP, Total:{4} BHP", blockIndex, bhpCreationTime.ToLocalTime(), nSubsidy, lastTotal, totalSubsidy); Console.WriteLine(line); if (lastSubsidy != nSubsidy) { sw.WriteLine(line); sw.Flush(); lastSubsidy = nSubsidy; lastTotal = Fixed8.Zero; } bhpCreationTime = bhpCreationTime.AddSeconds(15); blockIndex++; } Console.WriteLine(blockIndex); sw.WriteLine($"The End {DateTime.Now.ToLocalTime()}"); sw.Flush(); //关闭流 sw.Close(); fs.Close(); }
public bool VerifyRequest() { if (!State.HasFlag(ConsensusState.RequestReceived)) { return(false); } if (!Blockchain.GetConsensusAddress(snapshot.GetValidators(Transactions.Values).ToArray()).Equals(NextConsensus)) { return(false); } Transaction tx_gen = Transactions.Values.FirstOrDefault(p => p.Type == TransactionType.MinerTransaction); Fixed8 amount_netfee = Block.CalculateNetFee(Transactions.Values); Fixed8 amount_servicefee = ServiceFee.CalcuServiceFee(Transactions.Values.ToList()); //if (tx_gen?.Outputs.Sum(p => p.Value) != amount_netfee) return false; //挖矿交易和手续费单独计算 By BHP if (tx_gen?.Outputs.Where(p => p.AssetId == Blockchain.UtilityToken.Hash).Sum(p => p.Value) != amount_netfee) { return(false); } if (tx_gen?.Outputs.Where(p => p.AssetId == Blockchain.GoverningToken.Hash).Sum(p => p.Value) - MiningSubsidy.GetMiningSubsidy(BlockIndex) != amount_servicefee) { return(false); } return(true); }