This repository has been archived by the owner on Dec 4, 2024. It is now read-only.
forked from gdayymate/crystal-py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
49 lines (40 loc) · 1.51 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
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
from datetime import datetime
Base = declarative_base()
class Fruit(Base):
__tablename__ = "fruits"
id = Column(Integer, primary_key=True)
timestamp = Column(DateTime, default=datetime.now())
seed = Column(String)
epoch = Column(Integer)
referenced_stem_id = Column(Integer, ForeignKey("stems.id"))
signature = Column(String)
class Stem(Base):
__tablename__ = "stems"
id = Column(Integer, primary_key=True)
timestamp = Column(DateTime, default=datetime.now())
data = Column(String)
previous_hash = Column(String)
difficulty = Column(Integer)
nonce = Column(String)
hash = Column(String)
fruits = relationship("Fruit", backref="stem")
class Leaf(Base):
__tablename__ = "leaves"
id = Column(Integer, primary_key=True)
timestamp = Column(DateTime, default=datetime.now())
data = Column(String)
referenced_fruits = Column(String)
coinbase_transaction = Column(String)
difficulty = Column(Integer)
nonce = Column(String)
hash = Column(String)
class Blockchain(Base):
__tablename__ = "blockchain"
id = Column(Integer, primary_key=True)
stem_id = Column(Integer, ForeignKey("stems.id"), nullable=False)
leaf_id = Column(Integer, ForeignKey("leaves.id"), nullable=True)
stem = relationship("Stem", uselist=False, foreign_keys=[stem_id])
leaf = relationship("Leaf", uselist=False, foreign_keys=[leaf_id])