-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtransaction.py
More file actions
25 lines (21 loc) · 862 Bytes
/
transaction.py
File metadata and controls
25 lines (21 loc) · 862 Bytes
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
from lib.keys import signData, verifyData
import base64
class Transaction:
def __init__(self, sender, reciever, amount, signature=None, timestamp=None):
self.sender = sender
self.reciever = reciever
self.amount = amount
if signature==None:
self.signature = self.signTransaction()
else:
self.signature = signature
self.timestamp = timestamp
def signTransaction(self):
signature = signData(str(self.sender) + str(self.reciever) + str(self.amount))
return base64.b64encode(signature)
def verifyTransaction(self, public_key_string):
return verifyData(str(self.sender) + str(self.reciever) + str(self.amount),
public_key_string,
base64.b64decode(self.signature))
def _asdict(self):
return self.__dict__