forked from krruzic/trtlbotplusplus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
69 lines (49 loc) · 2.21 KB
/
models.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
import random
from sqlalchemy import Table, Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
def gen_hex():
all = "0123456789abcdef"
result = [random.choice('abcdef')] + [random.choice(all) for _ in range(4)]
random.shuffle(result)
result.insert(0, random.choice(all[1:]))
return ''.join(result)
class Wallet(Base):
__tablename__ = 'wallets'
id = Column(Integer, primary_key=True)
address = Column(String(99), unique=True, nullable=False)
userid = Column(Integer, default=-1)
messageid = Column(Integer, default=0)
deposit = Column(String(99), unique=True, nullable=True)
def __repr__(self):
return "<User {} has Wallet {}>".format(self.userid,self.address)
def __init__(self, address, userid, messageid):
self.address = address
self.userid = int(userid)
self.messageid = int(messageid)
class TipJar(Base):
__tablename__ = 'tips'
id = Column(Integer, primary_key=True)
paymentid = Column(String(64), unique=True, nullable=False)
userid = Column(Integer, default=-1)
amount = Column(Integer, default=0)
withdraw = Column(String(64), unique=True, nullable=False)
def __repr__(self):
return "<User {} has {} available to tip>".format(self.userid, self.amount)
def __init__(self, paymentid, userid, amount):
self.paymentid = paymentid
self.userid = int(userid)
self.amount = int(amount)
self.withdraw = gen_hex() # use this at the end of PID when withdrawing
class Transaction(Base):
__tablename__ = 'transactions'
id = Column(Integer, primary_key=True)
tx = Column(String(128), unique=True, nullable=False)
amount = Column(Integer, default=0)
paymentid = Column(String(64), unique=True, nullable=False)
def __repr__(self):
return "<tx hash {} transferred {} to PID: {}>".format(self.tx, self.amount, self.paymentid)
def __init__(self, tx, amount, pid):
self.tx = tx
self.amount = amount
self.paymentid = pid