BitSharper.Block.VerifyHeader C# (CSharp) Метод

VerifyHeader() публичный Метод

Checks the block data to ensure it follows the rules laid out in the network parameters. Specifically, throws an exception if the proof of work is invalid, if the timestamp is too far from what it should be. This is not everything that is required for a block to be valid, only what is checkable independent of the chain and without a transaction index.
public VerifyHeader ( ) : void
Результат void
        public void VerifyHeader()
        {
            // Prove that this block is OK. It might seem that we can just ignore most of these checks given that the
            // network is also verifying the blocks, but we cannot as it'd open us to a variety of obscure attacks.
            //
            // Firstly we need to ensure this block does in fact represent real work done. If the difficulty is high
            // enough, it's probably been done by the network.
            CheckProofOfWork(true);
            CheckTimestamp();
        }

Usage Example

Пример #1
0
        /// <summary>
        /// Returns a solved block that builds on top of this one. This exists for unit tests.
        /// </summary>
        internal Block CreateNextBlock(Address to, uint time)
        {
            var b = new Block(Params);

            b.DifficultyTarget = _difficultyTarget;
            b.AddCoinbaseTransaction(_emptyBytes);

            // Add a transaction paying 50 coins to the "to" address.
            var t = new Transaction(Params);

            t.AddOutput(new TransactionOutput(Params, t, Utils.ToNanoCoins(50, 0), to));
            // The input does not really need to be a valid signature, as long as it has the right general form.
            var input = new TransactionInput(Params, t, Script.CreateInputScript(_emptyBytes, _emptyBytes));
            // Importantly the outpoint hash cannot be zero as that's how we detect a coinbase transaction in isolation
            // but it must be unique to avoid 'different' transactions looking the same.
            var counter = new byte[32];

            counter[0]          = (byte)_txCounter++;
            input.Outpoint.Hash = new Sha256Hash(counter);
            t.AddInput(input);
            b.AddTransaction(t);

            b.PrevBlockHash = Hash;
            b.TimeSeconds   = time;
            b.Solve();
            b.VerifyHeader();
            return(b);
        }
All Usage Examples Of BitSharper.Block::VerifyHeader