This repository has been archived by the owner on Feb 16, 2022. It is now read-only.
forked from BlockHub/PayoutScriptArk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.py
134 lines (107 loc) · 4.65 KB
/
install.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
import psycopg2
from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT # <-- ADD THIS LINE
import logging.handlers
import config
def create_db(user_name, password):
# check if database doesn't already exists
try:
con = psycopg2.connect(dbname='postgres',
user=user_name,
host='localhost',
password=password)
con.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT) # <-- ADD THIS LINE
cur = con.cursor()
cur.execute("CREATE DATABASE payoutscript_administration")
except psycopg2.ProgrammingError:
return
def create_table_locks(user_name, password):
con = psycopg2.connect(dbname='payoutscript_administration',
user=user_name,
host='localhost',
password=password)
con.autocommit = True
cur = con.cursor()
cur.execute("""CREATE TABLE IF NOT EXISTS locks (
id SERIAL PRIMARY KEY,
locked BOOLEAN);""")
def create_table_delegate(user_name, password):
con = psycopg2.connect(dbname='payoutscript_administration',
user=user_name,
host='localhost',
password=password)
con.autocommit = True
cur = con.cursor()
cur.execute("""CREATE TABLE IF NOT EXISTS delegate (
id SERIAL PRIMARY KEY,
address VARCHAR(50),
reward BIGINT);""")
def grant_privileges(user_name, password):
con = psycopg2.connect(dbname='payoutscript_administration',
user=user_name,
host='localhost',
password=password)
con.autocommit = True
cur = con.cursor()
cur.execute("""GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO {};""".format(config.CONNECTION['USER']))
def create_empty_lock(user_name, password):
con = psycopg2.connect(dbname='payoutscript_administration',
user=user_name,
host='localhost',
password=password)
con.autocommit = True
cur = con.cursor()
cur.execute("""INSERT INTO
locks
VALUES (1, FALSE)
ON CONFLICT DO NOTHING;""")
def create_delegate_entry(user_name, password):
con = psycopg2.connect(dbname='payoutscript_administration',
user=user_name,
host='localhost',
password=password)
con.autocommit = True
cur = con.cursor()
cur.execute("""INSERT INTO delegate (id, address, reward)
VALUES (1, '{}', 0)
ON CONFLICT DO NOTHING;;""".format(config.DELEGATE['ADDRESS']))
def create_table_users_payouts(user_name, password):
con = psycopg2.connect(dbname='payoutscript_administration',
user=user_name,
host='localhost',
password=password)
con.autocommit = True
cur = con.cursor()
cur.execute("""CREATE TABLE IF NOT EXISTS users_payouts (
address VARCHAR(50) PRIMARY KEY,
payout BIGINT,
last_payout BIGINT);""")
if __name__ == '__main__':
# Initialize logging
logger = logging.getLogger(__name__)
handler = logging.handlers.RotatingFileHandler(config.LOGGING['LOGDIR'],
encoding='utf-8',
maxBytes=10 * 1024 * 1024,
backupCount=5)
formatter = logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.setLevel(config.LOGGING['LOGGING_LEVEL'])
user_name = input('Please provide a psql user eligble to create a database: ')
password = input('Please provide the password of psql user "{}": '.format(user_name))
print('Creating database')
create_db(user_name, password)
print('Success')
print('creating tables')
create_table_locks(user_name, password)
create_table_delegate(user_name, password)
create_table_users_payouts(user_name, password)
print('Success')
print('granting privileges')
grant_privileges(user_name, password)
print('success')
print('creating lock')
create_empty_lock(user_name, password)
print('success')
print('creating delegate entry')
create_delegate_entry(user_name, password)
print('success')