Пример #1
0
        public Block CreateBlock(Transaction transaction, Blockchain blockchain)
        {
            Dictionary <string, decimal> transactions = ConvertTransaction(transaction);
            Block  lastBlock            = blockchain.Chain[blockchain.Length - 1];
            string parentHash           = lastBlock.Hash;
            int    blockNumber          = lastBlock.Content.BlockNumber + 1;
            int    numberOfTransacitons = transactions.Count;

            BlockContent content = new BlockContent(blockNumber, parentHash, numberOfTransacitons, transactions);
            Block        block   = new Block(content);

            return(block);
        }
Пример #2
0
        public Blockchain()
        {
            // This is the very first aka genesis transaction
            Dictionary <string, decimal> root = new Dictionary <string, decimal>();

            root.Add("Alice", 100);
            root.Add("Bob", 100);

            string parentHash           = String.Empty;
            int    blockNumber          = 0;
            int    NumberOfTransactions = 1;

            BlockContent content = new BlockContent(blockNumber, parentHash, NumberOfTransactions, root);

            _chain = new List <Block>();
            Block rootBlock = new Block(content);

            Chain.Add(rootBlock);
        }