Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
178 lines (147 loc) · 6.2 KB
/
Copy pathmain.cpp
File metadata and controls
178 lines (147 loc) · 6.2 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
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
// #include "src/DLS.cpp"
// #include "src/Ledger.cpp"
// #include "src/Wallet.cpp"
#include "src/utils.cpp"
int main() {
int choice;
Wallet* wallets = new Wallet[100];
int walletCounter = 0;
DLS dls;
string password;
cout<< "\n\n\n<-***-***-***-***-***-***-***-***-***-***-***-***->"<<endl;
cout << "Welcome to our Decentralized Ledger System!" << endl;
cout<< "<-***-***-***-***-***-***-***-***-***-***-***-***->"<<endl;
while(choice!=6){
cout << "\n\n>>> Choose an option:" << endl;
cout << "1. Add a new wallet" << endl;
cout << "2. Send money between wallets" << endl;
cout << "3. View Ledger" << endl;
cout << "4. View balance" << endl;
cout << "5. Display Wallets"<<endl;
cout << "6. Exit" << endl<<endl<<endl;
cout << "Enter your choice: ";
cin >> choice;
if(cin.fail()){
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
choice=0;
}
cout<<"\n\n\n";
switch (choice) {
case 1: {
bool nameExists;
wallets[walletCounter] = Wallet(0);
string walletName;
cout << "Enter the name of the wallet:";
cin >> walletName;
while (true) {
nameExists = false;
for (int i = 0; i < Wallet::walletCounter; i++) {
if (wallets[i].name == walletName) {
nameExists = true;
cout << "😕 Wallet name already exists. Please enter a different name: ";
cin >> walletName;
break;
}
}
if (!nameExists) {
break;
}
}
wallets[walletCounter].name = walletName;
cout << "🤫 Enter a password for the wallet number " << walletCounter + 1<< " : ";
do {
cin >> password;
if (password.length()<8){
cout<<"🫣 Password must be atleast 8 characters long. Please enter again: ";
}
} while (password.length()<8);
wallets[walletCounter].setPassword(password);
cout << "🔐 Password set successfully!" << endl<<endl;
cout << "🤑 Enter initial balance for the new wallet : ";
cin >> wallets[walletCounter].balance;
cout<<"# Your wallet no is: "<<walletCounter+1<<endl;
cout<<"🔑 Your Public Key is: "<<wallets[walletCounter].publicKey<<endl;
cout<<"🤫 Your Private Key is: "<<wallets[walletCounter].getPrivateKey()<<endl;
cout<<"[NOTE: Keep your private key safe and do not share it with anyone.]"<<endl<<endl;
cout << "🎉 Wallet created successfully!" << endl;
cout << "--> " << wallets[walletCounter].balance << " rupees added to the wallet." << endl << endl;
walletCounter++;
break;
}
case 2: {
string sender, recipient;
double amount;
cout << "\n\n\n";
cout << "🫳 Enter the wallet name of the SENDER: ";
cin >> sender;
cout << "🫴 Enter the wallet name of the RECIPIENT: ";
cin >> recipient;
cout << "💰 Enter the amount to be sent: ";
cin >> amount;
cout << "🫣 Enter the password for the sender's wallet: ";
cin >> password;
cout << endl;
Wallet* senderWallet, *recipientWallet;
for (int i = 0; i < Wallet::walletCounter; i++) {
if (wallets[i].name == sender) {
senderWallet = &wallets[i];
if (password != senderWallet->getPassword()){
cout<<"😕 Invalid password. Please try again."<<endl;
break;
}
}
if (wallets[i].name == recipient) {
recipientWallet = &wallets[i];
}
}
if (senderWallet == NULL || recipientWallet == NULL) {
cout << "😕 Invalid wallet name. Please try again." << endl;
break;
}
cout<<endl<<endl<<"⏳ Making transaction......"<<endl<<endl;
Ledger ledger = send(recipientWallet->publicKey, senderWallet->publicKey, amount, wallets);
break;
}
case 3: {
cout << "\n\n\n";
cout << "📜 Ledger:" << endl <<endl;
dls.printLedger();
cout<<"-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"<<endl<<endl<<endl;
break;
}
case 4: {
string walletName;
cout << "💳 Enter the wallet name: ";
cin >> walletName;
for (int i = 0; i < Wallet::walletCounter; i++) {
if (wallets[i].name == walletName) {
cout << "💸 Balance: " << wallets[i].balance << endl;
break;
}
}
break;
}
case 5: {
cout << "📜 Wallets:" << endl;
for (int i = 0; i < Wallet::walletCounter; i++) {
if (wallets[i].name != "") {
cout << "Wallet " << i + 1 << ": " << wallets[i].name << endl;
}
}
break;
}
case 6: {
cout << "🙌 Thank you for using our DLS system! 😘" << endl;
return 0;
}
default: {
cout << "😕 Invalid choice. Please try again." << endl;
choice = 0;
break;
}
}
}
delete[] wallets;
return 0;
}