-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
114 lines (86 loc) · 2.87 KB
/
app.py
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
import json
import os
import middleware
global chainexist
chainexist = False;
print chainexist
### FUNCTIONS ###
def display_title_bar():
# Clears the terminal screen, and displays a title bar.
os.system('clear')
print("\t**********************************************")
print("\t*** Hello brainBot App ***")
print("\t**********************************************")
def get_user_choice():
# Let users know what they can do.
print("\n[1] Initiate Transaction")
print("[2] Print Balances.")
print("[3] Print Median")
print("[4] Print all Transactions")
print("[5] Print block By Transaction")
print("[q] Quit.")
return raw_input("What would you like to do? ")
def initiate_chain():
# initiate chain
inp = []
inp.append(raw_input("Enter chain height."))
inp.append(raw_input("Enter revert probability."))
inp.append(raw_input("Enter number of accounts."))
inp.append(raw_input("Enter max transaction per block."))
middleware.initiate_chain(int(inp[0]), float(inp[1]), int(inp[2]), int(inp[3]))
global chainexist
chainexist = True
def getBalances():
print chainexist
if (chainexist):
print json.dumps(middleware.return_list_balances(), indent=4, sort_keys=True)
else:
print "No chain was previously initiated!"
def getMedian():
if chainexist == True:
print "median is " + str(middleware.getmedian())
else:
print "No chain was previously initiated!"
def getAllTransactions():
if chainexist == True:
print json.dumps([b.serialize(include_balances=False) for b in middleware.getLongestChain().values()], indent=4,
sort_keys=True)
else:
print "No chain was previously initiated!"
def getBlockById():
if chainexist == True:
id = raw_input("Enter id transaction")
block, long = middleware.getBlockByTransactionId(id)
if (block):
print json.dumps(block.serialize(), indent=4, sort_keys=True)
print " Number of confirmations is :", long
else:
print "invalid id"
else:
print "No chain was previously initiated!"
def quit():
# This function dumps the names into a file, and prints a quit message.
print("\nThanks for playing.")
### MAIN PROGRAM ###
# Set up a loop where users can choose what they'd like to do.
choice = ''
display_title_bar()
while choice != 'q':
choice = get_user_choice()
# Respond to the user's choice.
display_title_bar()
if choice == '1':
initiate_chain()
elif choice == '2':
getBalances()
elif choice == '3':
getMedian()
elif choice == '4':
getAllTransactions()
elif choice == '5':
getBlockById()
elif choice == 'q':
quit()
print("\nThanks for playing. Bye.")
else:
print("\nI didn't understand that choice.\n")