-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathProgram.cs
277 lines (243 loc) · 11.3 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
using System;
using banktesterforms;
using System.Threading.Tasks;
using System.Net.Http;
using System.IO;
namespace CloudBankTester
{
class Program
{
/* INSTANCE VARIABLES */
public static KeyboardReader reader = new KeyboardReader();
// public static String rootFolder = System.getProperty("user.dir") + File.separator +"bank" + File.separator ;
public static String rootFolder = AppDomain.CurrentDomain.BaseDirectory;
public static String prompt = "Start Mode> ";
public static String[] commandsAvailable = new String[] { "Load Bank Keys", "Show Coins",
"Deposite Coin", "Withdraw Coins","Check Receipt", "Write Check","Get Check",
"Echo", "Get Print Welcome from Bank", "Send to a Skywallet from Bank", "Receive from Skywallet to Bank", "Transfer to another Skywallet", "quit" };
//public static int timeout = 10000; // Milliseconds to wait until the request is ended.
// public static FileUtils fileUtils = new FileUtils(rootFolder, bank);
public static Random myRandom = new Random();
public static string url = "";
public static string privateKey = "";
public static string account = "";
public static string sign = "Sean Worthington";
public static BankKeys myKeys;
private static CloudBankUtils receiptHolder;
private static HttpClientHandler han;
private static HttpClient cli;
/* MAIN METHOD */
public static void Main(String[] args)
{
han = new HttpClientHandler();
han.ServerCertificateCustomValidationCallback =
(httpRequestMessage, cert, cetChain, policyErrors) =>
{
return true;
};
cli = new HttpClient(han);
printWelcome();
run().Wait(); // Makes all commands available and loops
Console.Out.WriteLine("Thank you for using CloudBank Tester. Goodbye.");
} // End main
/* STATIC METHODS */
public static async Task run()
{
bool restart = false;
while (!restart)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.Out.WriteLine("");
// Console.Out.WriteLine("========================================");
Console.Out.WriteLine("");
Console.Out.WriteLine("Commands Available:");
Console.ForegroundColor = ConsoleColor.White;
int commandCounter = 1;
foreach (String command in commandsAvailable)
{
Console.Out.WriteLine(commandCounter + (". " + command));
commandCounter++;
}
Console.ForegroundColor = ConsoleColor.Green;
Console.Out.Write(prompt);
Console.ForegroundColor = ConsoleColor.White;
int commandRecieved = reader.readInt(1,13);
switch (commandRecieved)
{
case 1:
loadKeys();
break;
case 2:
await showCoins();
break;
case 3:
receiptHolder = await depositAsync();
break;
case 4:
await withdraw();
break;
case 5:
await receipt();
break;
case 6:
await writeCheck();
break;
case 7:
await GetCheck();
break;
case 8:
await Echo();
break;
case 9:
await bankPrintWelcome();
break;
case 10:
receiptHolder = await sendtoSkywallet();
break;
case 11:
receiptHolder = await recieveFromSkywallet();
break;
case 12:
receiptHolder = await transferBetweenSkywallets();
break;
case 13:
Console.Out.WriteLine("Goodbye!");
Environment.Exit(0);
break;
default:
Console.Out.WriteLine("Command failed. Try again.");
break;
}// end switch
}// end while
}// end run method
private static async Task bankPrintWelcome()
{
CloudBankUtils cbu = new CloudBankUtils(myKeys, cli);
await cbu.printWelcomeFromBank();
}
private static async Task Echo()
{
CloudBankUtils cbu = new CloudBankUtils(myKeys, cli);
await cbu.echoFromBank();
}
public static void printWelcome()
{
Console.ForegroundColor = ConsoleColor.Green;
Console.Out.WriteLine("╔══════════════════════════════════════════════════════════════════╗");
Console.Out.WriteLine("║ CloudBank Tester v.11.19.17 ║");
Console.Out.WriteLine("║ Used to Authenticate Test CloudBank ║");
Console.Out.WriteLine("║ This Software is provided as is with all faults, defects ║");
Console.Out.WriteLine("║ and errors, and without warranty of any kind. ║");
Console.Out.WriteLine("║ Free from the CloudCoin Consortium. ║");
Console.Out.WriteLine("╚══════════════════════════════════════════════════════════════════╝");
Console.ForegroundColor = ConsoleColor.White;
} // End print welcome
static void loadKeys()
{
//insert own keys
url = "";
privateKey = "";
account = "";
Console.Out.WriteLine("Public key is " + url );
Console.Out.WriteLine("Private key is " + privateKey);
Console.Out.WriteLine("account is " + account);
myKeys = new BankKeys(url, privateKey, account);
}
/* Show coins will populate the CloudBankUtils with the totals of each denominations
These totals are public properties that can be accessed */
static async Task showCoins()
{
CloudBankUtils cbu = new CloudBankUtils(myKeys, cli);
await cbu.showCoins();
Console.Out.WriteLine("Ones in our bank:" + cbu.onesInBank );
Console.Out.WriteLine("Five in our bank:" + cbu.fivesInBank);
Console.Out.WriteLine("Twenty Fives in our bank:" + cbu.twentyFivesInBank);
Console.Out.WriteLine("Hundreds in our bank:" + cbu.hundredsInBank );
Console.Out.WriteLine("Two Hundred Fifties in our bank:" + cbu.twohundredfiftiesInBank );
}//end show coins
/* Deposit allow you to send a stack file to the CloudBank */
static async Task<CloudBankUtils> depositAsync()
{
CloudBankUtils sender = new CloudBankUtils( myKeys, cli);
Console.Out.WriteLine("What is the path to your stack file?");
//string path = reader.readString();
string path = AppDomain.CurrentDomain.BaseDirectory ;
path += reader.readString();
Console.Out.WriteLine("Loading " + path);
sender.loadStackFromFile(path);
await sender.sendStackToCloudBank();
return sender;
}//end deposit
static async Task<CloudBankUtils> sendtoSkywallet()
{
CloudBankUtils sender = new CloudBankUtils(myKeys, cli);
Console.Out.WriteLine("Which skywallet are you sending to?");
string sw = reader.readString();
Console.Out.WriteLine("How Much?");
int amount = reader.readInt();
await sender.SendToSkywallet(amount, sw);
return sender;
}//end deposit
private static async Task<CloudBankUtils> transferBetweenSkywallets()
{
CloudBankUtils sender = new CloudBankUtils(myKeys, cli);
Console.Out.WriteLine("Which skywallet are you sending to?");
string sw = reader.readString();
Console.Out.WriteLine("How Much?");
int amount = reader.readInt();
await sender.TransferBetweenSkywallets(amount, sw);
return sender;
}
private static async Task<CloudBankUtils> recieveFromSkywallet()
{
CloudBankUtils sender = new CloudBankUtils(myKeys, cli);
await sender.RecieveFromSkywallet();
return sender;
}
static async Task withdraw()
{
CloudBankUtils receiver;
if (receiptHolder == null)
receiver = new CloudBankUtils(myKeys, cli);
else
receiver = receiptHolder;
Console.Out.WriteLine("How many CloudCoins are you withdrawing?");
int amount = reader.readInt();
await receiver.getStackFromCloudBank(amount);
if (receiver.haveStackFromWithdrawal)
receiver.saveStackToFile(AppDomain.CurrentDomain.BaseDirectory);
else
Console.Out.WriteLine("Failed to withdraw");
}//end deposit
static async Task receipt()
{
if (receiptHolder == null)
Console.Out.WriteLine("There has not been a recent deposit. So no receipt can be shown.");
else
{
await receiptHolder.getReceipt();
Console.Out.WriteLine(receiptHolder.interpretReceipt().interpretation);
}
}//end deposit
static async Task writeCheck()
{
Console.Out.WriteLine("How many CloudCoins are you withdrawing?");
int amount = reader.readInt();
Console.Out.WriteLine("Who are you Paying?");
string payto = reader.readString();
Console.Out.WriteLine("Who is being Emailed?");
string emailto = reader.readString();
var request = await cli.GetAsync("https://"+url+"/service/write_check?pk=" + privateKey + "&action=email&amount="+amount+"&emailto="+emailto+"&payto="+payto+"&from="+account+"&signby="+sign);
string response = await request.Content.ReadAsStringAsync();
Console.Out.WriteLine(response);
}
static async Task GetCheck()
{
Console.Out.WriteLine("What is the Check's Id?");
string id = reader.readString();
var request = await cli.GetAsync("https://" + url + "/service/checks?id="+id+"&receive=json");
string response = await request.Content.ReadAsStringAsync();
Console.Out.WriteLine(response);
}
}
}