-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
blockchain_integration/pi_network/pi_network_university/blockchain_integration/models.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# blockchain_integration/models.py | ||
from. import db, bcrypt | ||
|
||
class User(db.Model, UserMixin): | ||
id = db.Column(db.Integer, primary_key=True) | ||
username = db.Column(db.String(50), unique=True, nullable=False) | ||
email = db.Column(db.String(120), unique=True, nullable=False) | ||
password = db.Column(db.String(100), nullable=False) | ||
created_at = db.Column(db.DateTime, default=db.func.current_timestamp()) | ||
updated_at = db.Column(db.DateTime, default=db.func.current_timestamp(), onupdate=db.func.current_timestamp()) | ||
|
||
def set_password(self, password): | ||
self.password = bcrypt.generate_password_hash(password).decode("utf-8") | ||
|
||
def check_password(self, password): | ||
return bcrypt.check_password_hash(self.password, password) | ||
|
||
class Wallet(db.Model): | ||
id = db.Column(db.Integer, primary_key=True) | ||
user_id = db.Column(db.Integer, db.ForeignKey("user.id")) | ||
user = db.relationship("User", backref="wallets") | ||
address = db.Column(db.String(42), nullable=False) | ||
private_key = db.Column(db.String(66), nullable=False) | ||
created_at = db.Column(db.DateTime, default=db.func.current_timestamp()) | ||
updated_at = db.Column(db.DateTime, default=db.func.current_timestamp(), onupdate=db.func.current_timestamp()) | ||
|
||
class Transaction(db.Model): | ||
id = db.Column(db.Integer, primary_key=True) | ||
wallet_id = db.Column(db.Integer, db.ForeignKey("wallet.id")) | ||
wallet = db.relationship("Wallet", backref="transactions") | ||
tx_hash = db.Column(db.String(66), nullable=False) | ||
from_address = db.Column(db.String(42), nullable=False) | ||
to_address = db.Column(db.String(42), nullable=False) | ||
value = db.Column(db.Float, nullable=False) | ||
gas = db.Column(db.Float, nullable=False) | ||
gas_price = db.Column(db.Float, nullable=False) | ||
created_at = db.Column(db.DateTime, default=db.func.current_timestamp()) | ||
updated_at = db.Column(db.DateTime, default=db.func.current_timestamp(), onupdate=db.func.current_timestamp()) | ||
|
||
@login_manager.user_loader | ||
def load_user(user_id): | ||
return User.query.get(int(user_id)) |