public void Validate(BlocksIndex index, Block nextBlock) { var expectedIndex = index.IsEmpty ? 1 : index.Last.Index + 1;; if (nextBlock.Index != expectedIndex) { throw new ArgumentException("Invalid Index value"); } var expectedSignature = index.IsEmpty ? HashValue.Empty : index.Last.Signature;; if (nextBlock.PreviousBlock != expectedSignature) { throw new ArgumentException("Invalid PreviousBlock value"); } var realHash = _blockSigner.Sign(nextBlock.Index, nextBlock.Node, nextBlock.Rnd, nextBlock.PreviousBlock, nextBlock.Transactions); if (realHash != nextBlock.Signature) { throw new ArgumentException("Invalid Signature"); } }
public Block Create(long index, INode node, string rnd, HashValue previousBlock, IReadOnlyList <Transaction> transactions) { var hash = _blockSigner.Sign(index, node, rnd, previousBlock, transactions); return(new Block(index, node, rnd, previousBlock, hash, transactions)); }