-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
107 lines (94 loc) · 2.56 KB
/
main.c
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
#include <stdio.h>
#include <stdlib.h>
#include "src/utils.h"
BlockChain B;
void inquire_transactions(int user);
void inqure_bal(int user);
void displayBlockChain();
void displayBlock(int bnum);
void main()
{
srand(time(NULL));
system("clear");
initBlockChain();
int input;
char temp;
printf("\n\nYou have started the blockchain.\nPress enter\n");
scanf("%c", &temp);
while (1)
{
printf("\n\n");
printf("1 - Add a user\n");
printf("2 - View balance\n");
printf("3 - Make a transaction\n");
printf("4 - Attack a random block\n");
printf("5 - Validate the blockchain\n");
printf("6 - View User's Transaction history\n");
printf("7 - View Block chain\n");
printf("8 - Display block by block number\n");
printf("0 - Kill the blockchain\n\n");
printf("Enter your choice: ");
scanf("%d", &input);
if (input == 0)
{
deleteBlockChain();
printf("Block chain terimnated sucessfully!\n");
break;
}
else if (input == 1)
{
addUser();
}
else if (input == 2)
{
int user;
printf("Enter user uID: ");
scanf("%d", &user);
inqure_bal(user);
}
else if (input == 3)
{
int sender;
int reciever;
double amount;
printf("Enter sender ID: ");
scanf("%d", &sender);
printf("Enter reciever ID: ");
scanf("%d", &reciever);
printf("Enter amount to be transferred: ");
scanf("%lf", &amount);
transact(sender, reciever, amount);
}
else if (input == 4)
{
attack();
}
else if (input == 5)
{
validate();
}
else if (input == 6)
{
printf("Enter user ID: ");
int user;
scanf("%d", &user);
inquire_transactions(user);
}
else if (input == 7)
{
displayBlockChain();
}
else if (input == 8)
{
int bnum;
printf("Enter block number: ");
scanf("%d", &bnum);
displayBlock(bnum);
}
else
printf("Invalid input! Try again!\n");
printf("Press enter to continue!\n");
scanf("%c", &temp);
scanf("%c", &temp);
}
}