Skip to content

Commit

Permalink
Create models.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 3, 2024
1 parent 2f5e908 commit 1ccdcec
Showing 1 changed file with 42 additions and 0 deletions.
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))

0 comments on commit 1ccdcec

Please sign in to comment.