Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        /*
         * public void Fill()
         * {
         *  IEnumerable<Transaction> mem_pool = Blockchain.Singleton.GetMemoryPool();
         *  foreach (IPolicyPlugin plugin in Plugin.Policies)
         *      mem_pool = plugin.FilterForBlock(mem_pool);
         *  List<Transaction> transactions = mem_pool.ToList();
         *  Fixed8 amount_netfee = Block.CalculateNetFee(transactions);
         *  TransactionOutput[] outputs = amount_netfee == Fixed8.Zero ? new TransactionOutput[0] : new[] { new TransactionOutput
         *  {
         *      AssetId = Blockchain.UtilityToken.Hash,
         *      Value = amount_netfee,
         *      ScriptHash = wallet.GetChangeAddress()
         *  } };
         *  while (true)
         *  {
         *      ulong nonce = GetNonce();
         *      MinerTransaction tx = new MinerTransaction
         *      {
         *          Nonce = (uint)(nonce % (uint.MaxValue + 1ul)),
         *          Attributes = new TransactionAttribute[0],
         *          Inputs = new CoinReference[0],
         *          Outputs = outputs,
         *          Witnesses = new Witness[0]
         *      };
         *      if (!snapshot.ContainsTransaction(tx.Hash))
         *      {
         *          Nonce = nonce;
         *          transactions.Insert(0, tx);
         *          break;
         *      }
         *  }
         *  TransactionHashes = transactions.Select(p => p.Hash).ToArray();
         *  Transactions = transactions.ToDictionary(p => p.Hash);
         *  NextConsensus = Blockchain.GetConsensusAddress(snapshot.GetValidators(transactions).ToArray());
         *  Timestamp = Math.Max(TimeProvider.Current.UtcNow.ToTimestamp(), PrevHeader.Timestamp + 1);
         * }
         */

        public void Fill()
        {
            IEnumerable <Transaction> mem_pool = Blockchain.Singleton.GetMemoryPool();

            foreach (IPolicyPlugin plugin in Plugin.Policies)
            {
                mem_pool = plugin.FilterForBlock(mem_pool);
            }
            List <Transaction> transactions  = mem_pool.ToList();
            Fixed8             amount_netfee = Block.CalculateNetFee(transactions);

            //By BHP
            Fixed8 amount_servicefee = ServiceFee.CalcuServiceFee(transactions);

            while (true)
            {
                ulong nonce = GetNonce();
                //By BHP
                MinerTransaction tx = new MiningTransaction().MakeMinerTransaction(wallet, BlockIndex, nonce, amount_servicefee, amount_netfee);
                if (!snapshot.ContainsTransaction(tx.Hash))
                {
                    Nonce = nonce;
                    transactions.Insert(0, tx);
                    break;
                }
            }
            TransactionHashes = transactions.Select(p => p.Hash).ToArray();
            Transactions      = transactions.ToDictionary(p => p.Hash);
            NextConsensus     = Blockchain.GetConsensusAddress(snapshot.GetValidators(transactions).ToArray());
            Timestamp         = Math.Max(TimeProvider.Current.UtcNow.ToTimestamp(), PrevHeader.Timestamp + 1);
        }