-
Notifications
You must be signed in to change notification settings - Fork 0
/
withdrawTransaction.py
36 lines (29 loc) · 1021 Bytes
/
withdrawTransaction.py
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
26
27
28
29
30
31
32
33
34
35
36
from transaction import Transaction
class WithdrawTransaction(Transaction):
def __init__(self, account, amount):
super().__init__(amount)
self._account = account
self._succeeded = False
@property
def succeeded(self):
return self._succeeded
def execute(self):
super().execute()
self._succeeded = self._account.withdraw(self._amount)
def rollback(self):
super().rollback()
if self._account.deposit(self._amount):
self._reversed = True
self._executed = False
self._succeeded = False
else:
self._reversed = False
self._executed = True
self._succeeded = True
def print(self):
if self._succeeded:
print(f"You have withdrawn {self._amount} from {self._account.name}'s account")
else:
print("Your withdrawral was unsuccessful")
if self._reversed:
print("Withdraw was reversed.")