-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathmodels.py
47 lines (40 loc) · 1.27 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
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, BigInteger, LargeBinary, String
from contextlib import contextmanager
Session = sessionmaker()
Base = declarative_base()
@contextmanager
def session_scope():
"""Provide a transactional scope around a series of operations."""
session = Session()
try:
yield session
session.commit()
except:
session.rollback()
raise
finally:
session.close()
class Transaction(Base):
__tablename__ = 'transactions'
version = Column(Integer, primary_key=True)
expiration_date = Column(String)
src = Column(String)
dest = Column(String)
type = Column(String)
amount = Column(LargeBinary)
gas_price = Column(LargeBinary)
max_gas = Column(LargeBinary)
sq_num = Column(Integer)
pub_key = Column(String)
expiration_unixtime = Column(BigInteger)
gas_used = Column(LargeBinary)
sender_sig = Column(String)
signed_tx_hash = Column(String)
state_root_hash = Column(String)
event_root_hash = Column(String)
code_hex = Column(String)
program = Column(String)
def __repr__(self):
return '<Transaction(version = {0.version})>'.format(self)