Created
May 18, 2020 18:49
-
-
Save bajcmartinez/c69505ea8f1c7c24ec240788dfa33ea4 to your computer and use it in GitHub Desktop.
From Zero to Blockchain in Python - Part 1 - Transaction
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
import time | |
class Transaction: | |
def __init__(self, sender, recipient, amount): | |
""" | |
Creates a new transaction | |
:param sender: <str> sender account | |
:param recipient: <str> recipient account | |
:param amount: <float> amount to be transferred | |
""" | |
self.sender = sender | |
self.recipient = recipient | |
self.timestamp = time.time() | |
self.amount = amount | |
def validate(self): | |
""" | |
Checks if a transaction is valid | |
:return: <bool> True if it is valid, False if not. | |
""" | |
# Prevent stealing by creating negative transactions | |
if self.amount < 0: | |
return False | |
return True | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment