Exemple #1
0
        public void Mine(Wallet wallet)
        {
            var txs           = _mempoolRepository.GetNextList();
            var lastBlockHash = _blockRepository.GetLastBlockHash();

            if (lastBlockHash == null)
            {
                lastBlockHash = InsertGenesis(wallet);
            }

            var newBlock = new Block(lastBlockHash);

            foreach (var tx in txs)
            {
                switch (tx.Type)
                {
                case TransactionType.Coins:
                    break;

                case TransactionType.VisitToTheDoctor:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }


            var coinBase         = new Wallet();
            var mainedBlockMoney = new CoinTransaction(coinBase.PublicKey, wallet.PublicKey, 100, null);

            mainedBlockMoney.Sign(coinBase);
            mainedBlockMoney.Id = Guid.NewGuid().ToString();
            mainedBlockMoney.Outputs.Add(
                new TransactionOutput(mainedBlockMoney.Reciepient, mainedBlockMoney.Amount, mainedBlockMoney.Id)
                );
            UTXOs[mainedBlockMoney.Outputs[0].Id] = mainedBlockMoney.Outputs[0];

            newBlock.AddTransaction(UTXOs, mainedBlockMoney);

            newBlock.MineBlock(new Random().Next(0, 5));


            _blockRepository.Add(newBlock);
        }