-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstateControl.py
More file actions
26 lines (23 loc) · 951 Bytes
/
stateControl.py
File metadata and controls
26 lines (23 loc) · 951 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
26
#this function is invoked if the transactions are valid
def updateState(transactionBuffer, currState):
stateCheck = currState.copy()
for key in transactionBuffer:
if key in stateCheck.keys():
stateCheck[key] += transactionBuffer[key]
# if the user already exist change their current amount of coins
else:
stateCheck[key] = transactionBuffer[key]
#if they do not, add the new coins to the new account
return stateCheck
def isValidTransaction(transactionBuffer, currState):
if sum(transactionBuffer.values()) is not 0:
return False
# this checks that no coins are created or destoryed
for key in transactionBuffer.keys():
if key in currState.keys():
accountBalance = currState[key]
else:
accountBalance = 0
if (accountBalance + transactionBuffer[key] < 0):
return False
return True