-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccountModel.py
More file actions
25 lines (20 loc) · 868 Bytes
/
Copy pathAccountModel.py
File metadata and controls
25 lines (20 loc) · 868 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
class AccountModel:
def __init__(self):
# keep tracks of pubKey of all participants in the network
self.accounts = []
self.balances = {}
# add a new account using pubKey
def addAccount(self, pubKeyString):
if not pubKeyString in self.accounts:
self.accounts.append(pubKeyString)
self.balances[pubKeyString] = 0
# get balance of an account using pubKey
def getBalance(self, pubKeyString):
if pubKeyString not in self.accounts:
self.addAccount(pubKeyString)
return self.balances[pubKeyString]
# update balance of an account: amount can be positive/negative
def updateBalance(self, pubKeyString, amount):
if pubKeyString not in self.accounts:
self.addAccount(pubKeyString)
self.balances[pubKeyString] += amount