Skip to content

Instantly share code, notes, and snippets.

@bajcmartinez
Created May 18, 2020 18:49
Show Gist options
  • Save bajcmartinez/c69505ea8f1c7c24ec240788dfa33ea4 to your computer and use it in GitHub Desktop.
Save bajcmartinez/c69505ea8f1c7c24ec240788dfa33ea4 to your computer and use it in GitHub Desktop.
From Zero to Blockchain in Python - Part 1 - Transaction
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