-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
138 lines (103 loc) · 4.8 KB
/
Program.cs
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using System;
using Newtonsoft.Json;
using SecureID.p2p;
using SecureIdBlockchain.core;
namespace SecureID
{
/// <summary>
/// Entry point for SecureIDChain
/// </summary>
class Program
{
public static int Port = 0;
public static Server Server = null;
public static Client Client = new Client();
public static Blockchain SecureIdAsset = new Blockchain();
public static string username = "darkmode";
public static BlockchainCache ourCache = new BlockchainCache();
static void Main(string[] args)
{
Console.WriteLine("Hello SecureID Blockchain!");
Console.WriteLine("");
Console.WriteLine(ourCache.GetName());
var startTime = DateTime.Now;
SecureIdAsset.InitializeSecureIdChain();
if (args.Length >= 1){
Port = int.Parse(args[0]);
}
if (args.Length >= 2){
username = args[1];
}
if (Port > 0)
{
Server = new Server();
Server.Start();
}
if (username != "darkmode")
{
Console.WriteLine($"Current username is the default {username}");
}
DisplayMenu();
//Blockchain secureIdAsset = new Blockchain();
// var user = new UserIdentity("Username", "Lismore", true, true);
// secureIdAsset.CreateTransaction(new Transaction("Patrick", "Authenticator", 1, user));
// secureIdAsset.ProcessPendingTransactions("LismoreNode");
// System.Threading.Thread.Sleep(5000);
// secureIdAsset.ProcessPendingTransactions("LismoreNode2");
// Console.WriteLine(JsonConvert.SerializeObject(secureIdAsset, Formatting.Indented));
// var endTime = DateTime.Now;
// Console.WriteLine($"Duration: {endTime - startTime}");
}
/// <summary>
/// Display Menu method, prints the top level node menu
/// </summary>
/// <returns></returns>
public static void DisplayMenu(){
int selection = 0;
while (selection != 5)
{
switch (selection)
{
case 1:
Console.WriteLine("Please enter the server URL");
string serverURL = Console.ReadLine();
Client.Connect($"{serverURL}/Blockchain");
break;
case 3:
Console.WriteLine("Please enter the receiver name");
string receiverName = Console.ReadLine();
Console.WriteLine("\nPlease enter the amount");
string amount = Console.ReadLine();
Console.WriteLine("\n Thanks we are ready to create your secureID on the blockchain\n");
Console.WriteLine("Lets update secureID profile.\n Please enter your username for your public profile?\n");
string usernames = Console.ReadLine();
// set user id object
// TODO: expand UserIdentity object for full identity
// TODO: do a validation check with public/private keys before setting user object owner to true
UserIdentity user = new UserIdentity("username",usernames, true, true);
SecureIdAsset.CreateTransaction(new Transaction(username, receiverName, int.Parse("1"), user));
SecureIdAsset.ProcessPendingTransactions(username);
Client.Broadcast(JsonConvert.SerializeObject(SecureIdAsset));
break;
case 4:
Console.WriteLine("Blockchain");
Console.WriteLine(JsonConvert.SerializeObject(SecureIdAsset, Formatting.Indented));
break;
case 5:
Console.WriteLine("Exit");
break;
}
Console.WriteLine("\n=========================");
Console.WriteLine("1. Sync Node");
Console.WriteLine("2. Create new account");
Console.WriteLine("3. Create a transaction");
Console.WriteLine("4. Display Blockchain");
Console.WriteLine("5. Exit");
Console.WriteLine("\n=========================\n");
Console.WriteLine("Please select an action");
string action = Console.ReadLine();
selection = int.Parse(action);
}
}
}
}