public Miner Create( BlockSigned signedBlock, IFeedback feedback) { var signedBlockHash = _cryptography.CalculateHash(signedBlock); return(new Miner(signedBlock.HashTargetBits, signedBlock, signedBlockHash, _cryptography, feedback)); }
private void ValidateSignature(Address stamp, BlockSigned newBlockSigned) { // TODO: PubKey sign check. Temporary to validate genesis block if (stamp.Value != newBlockSigned.Stamp.Value) { throw new BlockchainValidationException("Block has invalid signature"); } }
public void ValidateBlockHash(BlockSigned blockSigned, HashTarget target) { var calulatedSignedHash = _cryptography.CalculateHash(blockSigned); var calulatedSignedHashBytes = calulatedSignedHash.ToBinary(); var calulatedHash = _cryptography.CalculateHash(calulatedSignedHashBytes, target.Nounce); if (calulatedHash != target.Hash) { throw new BlockchainValidationException("Block has invalid hash"); } }
public Miner( HashBits hashTargetBits, BlockSigned signedBlock, Hash signedBlockHash, Cryptography cryptography, IFeedback feedback) { _hashTarget = hashTargetBits.ToHash(); _signedBlock = signedBlock; _signedBlockBytes = signedBlockHash.ToBinary(); _cryptography = cryptography; _feedback = feedback; _taskManagerWork = new CancellationTokenSource(); InitializeTaskManagerWait(); _taskManager = new Task <HashTarget>(ManageTasks, _taskManagerWork.Token); }
public BlockHashed(BlockSigned signed, HashTarget hashTarget) { Signed = signed; HashTarget = hashTarget; }
public Hash CalculateHash(BlockSigned signedBlock) { var dataToHash = signedBlock.SerializeToBinary(); return(CalculateHash(dataToHash)); }