Skip to content
Snippets Groups Projects
Commit 143f77d3 authored by inso's avatar inso
Browse files

Lien wallets <-> community dans les models

parent 42dc1d8a
No related branches found
No related tags found
No related merge requests found
...@@ -35,7 +35,7 @@ class AddCommunityDialog(QDialog, Ui_AddCommunityDialog): ...@@ -35,7 +35,7 @@ class AddCommunityDialog(QDialog, Ui_AddCommunityDialog):
port = self.portBox.value() port = self.portBox.value()
try: try:
community = self.account.communities.addCommunity(MainNode(server, port), self.account.keyFingerprint()) community = self.account.communities.addCommunity(MainNode(server, port), self.account.keyFingerprint())
self.account.wallets.addWallet(community.currency) self.account.wallets.addWallet(community)
self.communityView.setModel( CommunityTreeModel(community) ) self.communityView.setModel( CommunityTreeModel(community) )
except NotMemberOfCommunityError as e: except NotMemberOfCommunityError as e:
QErrorMessage(self).showMessage(e.message) QErrorMessage(self).showMessage(e.message)
......
...@@ -69,8 +69,7 @@ class Account(object): ...@@ -69,8 +69,7 @@ class Account(object):
def jsonify(self): def jsonify(self):
data = {'name' : self.name, data = {'name' : self.name,
'pgpKeyId' : self.pgpKeyId, 'pgpKeyId' : self.pgpKeyId,
'communities' : self.communities.jsonify(), 'communities' : self.communities.jsonify(self.wallets)}
'wallets' : self.wallets.jsonify()}
return data return data
......
...@@ -37,13 +37,13 @@ class Communities(object): ...@@ -37,13 +37,13 @@ class Communities(object):
raise NotMemberOfCommunityError(keyFingerprint, community.currency + "-" + community.amendmentId()) raise NotMemberOfCommunityError(keyFingerprint, community.currency + "-" + community.amendmentId())
def jsonify(self): def jsonify(self, wallets):
''' '''
Return the list of communities in a key:value form. Return the list of communities in a key:value form.
''' '''
data = [] data = []
for community in self.communitiesList: for community in self.communitiesList:
data.append(community.jsonify()) data.append(community.jsonify(wallets))
return data return data
......
...@@ -28,9 +28,8 @@ def loadAccount(jsonData): ...@@ -28,9 +28,8 @@ def loadAccount(jsonData):
account.pgpKeyId = jsonData['pgpKeyId'] account.pgpKeyId = jsonData['pgpKeyId']
account.name = jsonData['name'] account.name = jsonData['name']
account.communities = Communities() account.communities = Communities()
for communityData in jsonData['communities']:
account.communities.communitiesList.append(communityFactory.loadCommunity(communityData))
account.wallets = Wallets() account.wallets = Wallets()
for walletData in jsonData['wallets']:
account.wallets.walletsList.append(walletFactory.loadWallet(walletData)) for communityData in jsonData['communities']:
account.communities.communitiesList.append(communityFactory.loadCommunity(communityData, account))
return account return account
\ No newline at end of file
...@@ -37,12 +37,13 @@ class Wallets(object): ...@@ -37,12 +37,13 @@ class Wallets(object):
return w return w
return None return None
def jsonify(self): def jsonify(self, community):
''' '''
Return the list of wallets in a key:value form. Return the list of wallets in a key:value form.
''' '''
communityWallets = [w for w in self.walletsList if w.community == community]
data = [] data = []
for wallet in self.walletsList: for wallet in communityWallets:
data.append(wallet.jsonify()) data.append(wallet.jsonify())
return data return data
...@@ -67,8 +67,9 @@ class Community(object): ...@@ -67,8 +67,9 @@ class Community(object):
data.append(node.jsonify()) data.append(node.jsonify())
return data return data
def jsonify(self): def jsonify(self, wallets):
data = {'nodes' : self.jsonifyNodesList(), data = {'nodes' : self.jsonifyNodesList(),
'currency' : self.currency} 'currency' : self.currency,
'wallets' : wallets.jsonify(self)}
return data return data
...@@ -5,6 +5,7 @@ Created on 11 févr. 2014 ...@@ -5,6 +5,7 @@ Created on 11 févr. 2014
''' '''
from cutecoin.models.community import Community from cutecoin.models.community import Community
from cutecoin.models.node import MainNode from cutecoin.models.node import MainNode
from cutecoin.models.wallet import factory
import ucoinpy as ucoin import ucoinpy as ucoin
def createCommunity(mainNode): def createCommunity(mainNode):
...@@ -15,10 +16,12 @@ def createCommunity(mainNode): ...@@ -15,10 +16,12 @@ def createCommunity(mainNode):
return community return community
def loadCommunity(jsonData): def loadCommunity(jsonData, account):
community = Community() community = Community()
for nodeData in jsonData['nodes']: for nodeData in jsonData['nodes']:
community.knownNodes.append(MainNode(nodeData['server'], nodeData['port'])) community.knownNodes.append(MainNode(nodeData['server'], nodeData['port']))
community.currency = jsonData['currency'] community.currency = jsonData['currency']
for walletsData in jsonData['wallets']:
account.wallets.walletsList.append(factory.loadWallet(walletsData, community))
return community return community
...@@ -20,11 +20,12 @@ class Wallet(object): ...@@ -20,11 +20,12 @@ class Wallet(object):
Constructor Constructor
''' '''
self.coins = [] self.coins = []
self.currency = "" self.community = None
self.name = "Main Wallet"
def __eq__(self, other): def __eq__(self, other):
return ( self.currency == other.currency ) return ( self.community == other.community )
def value(self): def value(self):
value = 0 value = 0
...@@ -32,8 +33,8 @@ class Wallet(object): ...@@ -32,8 +33,8 @@ class Wallet(object):
value += coin.value() value += coin.value()
return value return value
def refreshCoins(self, community, pgpFingerprint): def refreshCoins(self, pgpFingerprint):
dataList = community.ucoinRequest(lambda : ucoin.hdc.coins.List, ctor_args={'pgp_fingerprint':pgpFingerprint}) dataList = self.community.ucoinRequest(lambda : ucoin.hdc.coins.List, ctor_args={'pgp_fingerprint':pgpFingerprint})
for issaunces in dataList['coins']: for issaunces in dataList['coins']:
issuer = issaunces['issuer'] issuer = issaunces['issuer']
for coinsIds in issaunces['ids']: for coinsIds in issaunces['ids']:
...@@ -42,7 +43,7 @@ class Wallet(object): ...@@ -42,7 +43,7 @@ class Wallet(object):
self.coins.append(coin) self.coins.append(coin)
def getText(self): def getText(self):
return str(self.value()) + " " + self.currency return self.name + " : " + str(self.value()) + " " + self.community.currency
def jsonifyCoinsList(self): def jsonifyCoinsList(self):
data = [] data = []
...@@ -52,6 +53,6 @@ class Wallet(object): ...@@ -52,6 +53,6 @@ class Wallet(object):
def jsonify(self): def jsonify(self):
return {'coins': self.jsonifyCoinsList(), return {'coins': self.jsonifyCoinsList(),
'currency': self.currency} 'name': self.name}
...@@ -6,16 +6,16 @@ Created on 11 févr. 2014 ...@@ -6,16 +6,16 @@ Created on 11 févr. 2014
from cutecoin.models.wallet import Wallet from cutecoin.models.wallet import Wallet
from cutecoin.models.coin import Coin from cutecoin.models.coin import Coin
def createWallet(currency): def createWallet(community):
wallet = Wallet() wallet = Wallet()
wallet.currency = currency wallet.community = community
return wallet return wallet
def loadWallet(jsonData): def loadWallet(jsonData, community):
wallet = Wallet() wallet = Wallet()
for coinData in jsonData['coins']: for coinData in jsonData['coins']:
wallet.coins.append(Coin(coinData['coin'])) wallet.coins.append(Coin(coinData['coin']))
wallet.currency = jsonData['currency'] wallet.community = community
return wallet return wallet
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment