Ejemplo n.º 1
0
        public async Task <BlockHashed> MineGenesisAsync(int?numberOfThreads)
        {
            var genesisMiner = MinerFactory.Create(Genesis.GetBlockData(Cryptography, DateTime.UtcNow.Ticks), _feedback);

            return(await _feedback.Execute("MineGenesis",
                                           () => MineAsync(genesisMiner, numberOfThreads),
                                           () => $"{nameof(numberOfThreads)}: {numberOfThreads}"));
        }
Ejemplo n.º 2
0
        private async Task <BlockHashed> GenerateGenesisBlock()
        {
            var feedback     = new NullFeedBack();
            var genesisMiner = _minerFactory.Create(Genesis.GetBlockData(_cryptography, DateTime.UtcNow.Ticks), feedback);

            genesisMiner.Start(1);
            return(await genesisMiner.GetBlock());
        }
Ejemplo n.º 3
0
        public async Task GenerateBlock_GenesisBlock_Invalidate_Hash()
        {
            var genesisBlock = await GenerateGenesisBlock();

            var newGenesisSignedBlock = Genesis.GetBlockData(_cryptography, DateTime.UtcNow.Ticks);

            _chainData.ValidateGenesisBlock(new BlockHashed(newGenesisSignedBlock, genesisBlock.HashTarget), out var _);
        }
Ejemplo n.º 4
0
        public bool ValidateGenesisBlock(BlockHashed newBlock, out BlockchainState blockchainState)
        {
            var expectedSignedGenesis = Genesis.GetBlockData(_cryptography, newBlock.Signed.Data.TimeStamp);
            var result = ValidateParent(0, Genesis.Hash, newBlock.Signed.Data,
                                        out blockchainState);

            if (result)
            {
                ValidateSignature(expectedSignedGenesis.Stamp, newBlock.Signed);
                ValidateBlockHash(expectedSignedGenesis, newBlock.HashTarget);
            }

            return(result);
        }