-
Notifications
You must be signed in to change notification settings - Fork 1
/
dapp.py
81 lines (62 loc) · 2.72 KB
/
dapp.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
import os
import records
from etherscan_service import EtherscanService
class Dapp:
conn = records.Database(os.environ['DATABASE_URL'])
def find_info_by_address(address):
result = Dapp.conn.query(f"SELECT organizations.name, organizations.category FROM contracts INNER JOIN organizations ON organizations.id = contracts.organization_id WHERE contracts.address = '{address}'")
return dict(result[0])
def dapps_by_category(category):
results = Dapp.conn.query("SELECT name, category FROM organizations WHERE category = '{0}'".format(category))
names = []
for result in results:
names.append(result['name'])
return names
def dapps_by_other_categories(category):
results = Dapp.conn.query("SELECT name, category FROM organizations WHERE category <> '{0}'".format(category))
names = []
for result in results:
names.append(result['name'])
return names
def contracts_by_category(category):
results = Dapp.conn.query("SELECT contracts.address FROM organizations INNER JOIN contracts ON organizations.id = contracts.organization_id WHERE organizations.category = '{0}'".format(category))
addresses = []
for result in results:
addresses.append(result['address'])
return addresses
def contracts_by_other_categories(category):
results = Dapp.conn.query("SELECT contracts.address FROM organizations INNER JOIN contracts ON organizations.id = contracts.organization_id WHERE organizations.category <> '{0}'".format(category))
addresses = []
for result in results:
addresses.append(result['address'])
return addresses
def ooi_info(contract, category):
result = []
e = EtherscanService()
oois = Dapp.contracts_by_category(category)
for ooi in oois:
info = Dapp.find_info_by_address(ooi)
result.append({
'name': info['name'],
'category': info['category'],
'shared_users': e.addresses_in_common([contract, ooi])
})
return result
def external_ooi_info(contract, category):
result = []
e = EtherscanService()
external_oois = Dapp.contracts_by_other_categories(category)
for ooi in external_oois:
info = Dapp.find_info_by_address(ooi)
result.append({
'name': info['name'],
'category': info['category'],
'shared_users': e.addresses_in_common([contract, ooi])
})
return result
def users(contract):
e = EtherscanService()
count = len(e.addresses_by_contract(contract))
return {
'count': count,
}