-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLeaderboard.py
159 lines (149 loc) · 3.17 KB
/
Leaderboard.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
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
from tkinter import *
import web3
from web3 import Web3
import numpy as np
#Init Web3
w3 = Web3(Web3.HTTPProvider("http://127.0.0.1:7545"))
#Names of Companies or Households
names = ['name1','name2','name3','name4','name5','name6','name7','name8','name9','name10']
#Contract Properties
contractAdress = "0xd5e49e2141b60681057432aa64851d7bd1b054a5"
contractAbi = '''[
{
"constant": false,
"inputs": [
{
"name": "_receiver",
"type": "address"
},
{
"name": "_amount",
"type": "uint256"
},
{
"name": "_credential",
"type": "uint256"
}
],
"name": "createTokens",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_receiver",
"type": "address"
},
{
"name": "_amount",
"type": "uint256"
}
],
"name": "transferTokens",
"outputs": [
{
"name": "success",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "checkBalance",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "address"
}
],
"name": "balance",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "sender",
"type": "address"
},
{
"indexed": false,
"name": "receiver",
"type": "address"
},
{
"indexed": false,
"name": "amount",
"type": "uint256"
}
],
"name": "Transfer",
"type": "event"
}
]'''
#Init Contract
sustainergy_contract = w3.eth.contract(address=Web3.toChecksumAddress(contractAdress),abi=contractAbi)
class Window(Frame):
# Window Creation
def __init__(self, master=None):
Frame.__init__(self, master)
self.master = master
self.init_window()
#Creation of init_window
def init_window(self):
# changing the title of our master widget
self.master.title("Sustainergy")
# allowing the widget to take the full space of the root window
self.pack(fill=BOTH, expand=1)
# creating a button instance
refresh = Button(self, text="Refresh", command = self.showText)
# placing the button on my window
refresh.place(x=0, y=350)
self.showText()
#Show leaderboard
def showText(self):
balances = np.empty(10)
for i in range(10):
balances[i] =sustainergy_contract.functions.balance(w3.eth.accounts[i]).call()
indecies = np.argsort(balances)
for i in range(10):
text = Label(self, text=w3.eth.accounts[indecies[9-i]])
text.place(x=0, y = i*20+20)
text = Label(self, text=names[indecies[9-i]])
text.place(x=400, y= i*20+20)
text = Label(self, text=balances[indecies[9-i]])
text.place(x=500, y= i*20+20)
root = Tk()
#Windowsize
root.geometry("600x350")
app = Window(root)
root.mainloop()