Exemplo n.º 1
0
        /// <summary>
        /// Creates a new Block and adds it to the chain
        /// </summary>
        /// <param name="proof"></param>
        /// <param name="previousHash"></param>
        public Block NewBlock(string proof, string previousHash)
        {
            Block block = new Block()
            {
                Index        = Chain.Count + 1,
                PreviousHash = previousHash,
                Proof        = proof,
                TimeStamp    = DateTime.Now,
                Transactions = CurrentTransactions.ToList()
            };

            //Reset the current list of transactions
            CurrentTransactions.Clear();

            Chain.Add(block);

            return(block);
        }
Exemplo n.º 2
0
        /// <summary>
        ///  Creates a new block and appends it to the block chain
        /// </summary>
        /// <param name="proof">The proof given by the Proof of Work algorithm</param>
        /// <param name="previous_hash">(Optional)Hash of the previous block</param>
        /// <returns>New Block</returns>
        private Block NewBlock(long proof, string previous_hash = null)
        {
            //create the new block
            var newBlock = new Block
            {
                Index        = Chain.Count + 1,
                Timestamp    = DateTime.Now,
                Transactions = new List <Transaction>(CurrentTransactions),
                Proof        = proof,
                PreviousHash = previous_hash ?? Blockchain.Hash(LastBlock)
            };

            //reset the transactions
            CurrentTransactions.Clear();

            Chain.Add(newBlock);
            return(newBlock);
        }