/// <summary> /// Creates a new block and add to the chain /// </summary> /// <param name="proof">The proof given by the Proof of Work algorithm</param> /// <param name="previousHash">Hash of previous Block</param> /// <returns>New Block</returns> public Block NewBlock(long proof, string previousHash = null) { var block = new Block { Index = Chain.Count + 1, Timestamp = Utils.DateTimeToUnixTimestamp(DateTime.Now), Transactions = CurrTransactions.ToList(), Proof = proof, PrevHash = !string.IsNullOrWhiteSpace(previousHash) ? previousHash : Hash(LastBlock) }; Chain.Add(block); CurrTransactions.Clear(); return(block); }
/// <summary> /// Adds a new transaction to the list of transactions /// </summary> /// <param name="transaction">Transaction to be added to the block</param> /// <returns>The index of the block that will hold this transaction</returns> public int NewTransaction(Transaction transaction) { CurrTransactions.Add(transaction); return(LastBlock.Index + 1); }