-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.cs
More file actions
52 lines (51 loc) · 1.54 KB
/
Copy pathUser.cs
File metadata and controls
52 lines (51 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace BlockchainTestCase
{
class User
{
List<Miner> miners;
public byte[] id;
List<int> unusedIds;
public User(List<Miner> minersList, List<int> ids)
{
Random rd = new Random();
id = new byte[32]; rd.NextBytes(id);
miners = minersList;
unusedIds = ids;
}
public void SetMiners(List<Miner> minerList)
{
miners = minerList;
}
public void CreateRandomTransaction(User to)
{
Console.WriteLine("Started transaction");
Random rd = new Random();
SHA256 sh = SHA256.Create();
Transaction tr = new Transaction(id, to.id, rd.Next(), unusedIds[rd.Next(0,unusedIds.Count)]);
//Signing should require something more complex requiring the private and public key of the signer
if (tr.SetSign(sh.ComputeHash(tr.Sum())))
{
Console.WriteLine("Broadcasting to miners");
//Broadcast to miners
foreach(Miner mn in miners)
{
mn.AssignTransaction(tr);
}
}
else
{
Console.WriteLine("Transaction failed to be created");
}
}
public void UsedTransaction(int id)
{
unusedIds.Remove(id);
}
}
}