Exemplo n.º 1
0
        public void WhenCreatingNewProvenHeaderMerkleProofIsCorrectlyCreated()
        {
            PosBlock block = this.CreatePosBlock();

            // Add 20 more transactions.
            for (int i = 0; i < 20; i++)
            {
                Transaction tx = this.Network.CreateTransaction();

                tx.AddInput(new TxIn(Script.Empty));
                tx.AddOutput(Money.COIN + i, new Script(Enumerable.Range(1, 5).SelectMany(index => Guid.NewGuid().ToByteArray())));

                block.AddTransaction(tx);
            }

            block.UpdateMerkleRoot();
            ProvenBlockHeader provenBlockHeader = CreateNewProvenBlockHeaderMock(block);

            provenBlockHeader.MerkleProof.Hashes.Should().HaveCount(6);
            provenBlockHeader.MerkleProof.Check(provenBlockHeader.HashMerkleRoot).Should().BeTrue();
        }
Exemplo n.º 2
0
        public ChainedHeaderBlock AddNextBlock(List <Transaction> transactions)
        {
            ChainedHeader previous = this.ChainIndexer.Tip;

            BlockHeader nextHeader = this.Network.Consensus.ConsensusFactory.CreateBlockHeader();

            nextHeader.HashPrevBlock = previous.HashBlock;

            ChainedHeader chainedHeader = new ChainedHeader(nextHeader, nextHeader.GetHash(), previous);

            var block = new PosBlock(chainedHeader.Header);

            foreach (var tx in transactions)
            {
                block.AddTransaction(tx);
            }

            chainedHeader.Block = block;

            this.ChainIndexer.Add(chainedHeader);
            this.AddBlockToBlockStore(block);

            return(new ChainedHeaderBlock(block, chainedHeader));
        }