Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            const string minerAddress = "miner1";
            const string user1Address = "A";
            const string user2Address = "B";

            BlockChain blockChain = new BlockChain(proofOfWorkDifficulty: 2, miningReward: 10);

            blockChain.CreateTransaction(new Transaction(user1Address, user2Address, 200));
            blockChain.CreateTransaction(new Transaction(user2Address, user1Address, 10));

            Console.WriteLine("Es valido: {0}", blockChain.IsValidChain());
            Console.WriteLine();
            Console.WriteLine("--------- Start mining ---------");
            blockChain.MineBlock(minerAddress);
            Console.WriteLine("BALANCE del minero: {0}", blockChain.GetBalance(minerAddress));
            blockChain.CreateTransaction(new Transaction(user1Address, user2Address, 5));
            Console.WriteLine();
            Console.WriteLine("--------- Start mining ---------");
            blockChain.MineBlock(minerAddress);
            Console.WriteLine("BALANCE del minero: {0}", blockChain.GetBalance(minerAddress));

            Console.WriteLine();
            PrintChain(blockChain);
            Console.WriteLine();
            //Console.WriteLine("Hacking the blockchain...");
            //blockChain.Chain[1].Transactions = new List<Transaction> { new Transaction(user1Address, minerAddress, 150) };
            //Console.WriteLine("Is valid: {0}", blockChain.IsValidChain());
            Console.ReadKey();
        }