I wanted to get started with blockchain development and I know how it works but for some strange reasons to me, when I make a change in previous transactions hash value doesn't change in the previous block either in next block.
I have tried adding a few more elements in the transaction but it still doesn't change.
This is Program.cs file
class Program
{
static void Main(string[] args)
{
string[] genesisTransaction = { "This is genesis transaction", "Satoshi sent 10 bitcoins to Teufik" };
Block genesisBlock = new Block(0, genesisTransaction);
string[] firstTransaction = { "This is first transaction","Teufik sent 5 bitcoins to Tamara" };
Block firstBlock = new Block(genesisBlock.GetBlockHash(), firstTransaction);
Console.Write("Genesis block: ");
Console.WriteLine(genesisBlock.GetBlockHash());
Console.Write("First block: ");
Console.WriteLine(firstBlock.GetBlockHash());
}
}
This is Block class
class Block
{
private int blockHash;
private int previousHash;
private string[] transactions;
public Block(int previousHash, string[] transactions)
{
this.previousHash = previousHash;
this.transactions = transactions;
object[] contents = { transactions.GetHashCode(), previousHash };
blockHash = contents.GetHashCode();
}
public int GetBlockHash() => blockHash;
public int GetPreviousHash() => previousHash;
public string[] GetTransactions() => transactions;
}
The actual result should be: By adding/deleting even one character hash value will give a different value