BlockChain: Make data structure easily serializable.

This commit is contained in:
2020-09-07 00:46:37 +02:00
parent 8d16a546d5
commit 127add53c0
3 changed files with 12 additions and 2 deletions

View File

@@ -11,10 +11,12 @@ namespace BasicBlockChain.Core
public int Index { get; set; } public int Index { get; set; }
public DateTime Date { get; set; } public DateTime Date { get; set; }
public string PreviousHash { get; set; } public string PreviousHash { get; set; }
public List<Transaction> Transactions { get; } = new List<Transaction>(); public List<Transaction> Transactions { get; set; } = new List<Transaction>();
public string Hash { get; set; } public string Hash { get; set; }
public int Nonce { get; set; } public int Nonce { get; set; }
public Block() { }
public Block(DateTime date, Block previousBlock, IList<Transaction> transactions) public Block(DateTime date, Block previousBlock, IList<Transaction> transactions)
{ {
Index = (previousBlock?.Index ?? -1) + 1; Index = (previousBlock?.Index ?? -1) + 1;

View File

@@ -7,7 +7,7 @@ namespace BasicBlockChain.Core
public class BlockChain public class BlockChain
{ {
public List<Transaction> PendingTransactions { get; } = new List<Transaction>(); public List<Transaction> PendingTransactions { get; } = new List<Transaction>();
public List<Block> Chain { get; } = new List<Block>(); public List<Block> Chain { get; set; } = new List<Block>();
public int Difficulty { get; set; } = 2; public int Difficulty { get; set; } = 2;
public int Reward { get; set; } = 1_000_000; public int Reward { get; set; } = 1_000_000;
@@ -23,6 +23,10 @@ namespace BasicBlockChain.Core
} }
return _users; return _users;
} }
set
{
_users = value;
}
} }
private void InitUsers() private void InitUsers()
@@ -65,6 +69,8 @@ namespace BasicBlockChain.Core
} }
} }
public BlockChain() { }
public BlockChain(DateTime? genesisDate = null, int difficulty = 2, int reward = 1_000_000) public BlockChain(DateTime? genesisDate = null, int difficulty = 2, int reward = 1_000_000)
{ {
Block genesisBlock = new Block(genesisDate ?? DateTime.UtcNow, null, null); Block genesisBlock = new Block(genesisDate ?? DateTime.UtcNow, null, null);

View File

@@ -9,6 +9,8 @@ namespace BasicBlockChain.Core
public long MicroCoinAmount { get; set; } public long MicroCoinAmount { get; set; }
public DateTime Date { get; set; } public DateTime Date { get; set; }
public Transaction() { }
public Transaction(string sender, string receiver, long microCoinAmount, DateTime date) public Transaction(string sender, string receiver, long microCoinAmount, DateTime date)
{ {
Sender = sender; Sender = sender;