BlockChain: Make data structure easily serializable.
This commit is contained in:
@@ -11,10 +11,12 @@ namespace BasicBlockChain.Core
|
||||
public int Index { get; set; }
|
||||
public DateTime Date { 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 int Nonce { get; set; }
|
||||
|
||||
public Block() { }
|
||||
|
||||
public Block(DateTime date, Block previousBlock, IList<Transaction> transactions)
|
||||
{
|
||||
Index = (previousBlock?.Index ?? -1) + 1;
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace BasicBlockChain.Core
|
||||
public class BlockChain
|
||||
{
|
||||
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 Reward { get; set; } = 1_000_000;
|
||||
|
||||
@@ -23,6 +23,10 @@ namespace BasicBlockChain.Core
|
||||
}
|
||||
return _users;
|
||||
}
|
||||
set
|
||||
{
|
||||
_users = value;
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
Block genesisBlock = new Block(genesisDate ?? DateTime.UtcNow, null, null);
|
||||
|
||||
@@ -9,6 +9,8 @@ namespace BasicBlockChain.Core
|
||||
public long MicroCoinAmount { get; set; }
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
public Transaction() { }
|
||||
|
||||
public Transaction(string sender, string receiver, long microCoinAmount, DateTime date)
|
||||
{
|
||||
Sender = sender;
|
||||
|
||||
Reference in New Issue
Block a user