Ejemplo n.º 1
0
        public Miner Create(
            BlockSigned signedBlock,
            IFeedback feedback)
        {
            var signedBlockHash = _cryptography.CalculateHash(signedBlock);

            return(new Miner(signedBlock.HashTargetBits, signedBlock, signedBlockHash, _cryptography, feedback));
        }
Ejemplo n.º 2
0
 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");
     }
 }
Ejemplo n.º 3
0
        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");
            }
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
 public BlockHashed(BlockSigned signed, HashTarget hashTarget)
 {
     Signed     = signed;
     HashTarget = hashTarget;
 }
Ejemplo n.º 6
0
        public Hash CalculateHash(BlockSigned signedBlock)
        {
            var dataToHash = signedBlock.SerializeToBinary();

            return(CalculateHash(dataToHash));
        }