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

Gestion de multiples MainNode et essis de connexion

parent 4bbc4170
No related branches found
No related tags found
No related merge requests found
......@@ -32,7 +32,7 @@ class AddCommunityDialog(QDialog, Ui_AddCommunityDialog):
'''
server = self.serverEdit.text()
port = self.portBox.value()
community = self.account.communities.addCommunity(MainNode(server, port))
community = self.account.communities.addCommunity(MainNode(server, port), self.account.keyFingerprint())
self.account.wallets.addWallet(community.currency)
self.communityView.setModel( CommunityTreeModel(community) )
......
'''
Created on 2 févr. 2014
@author: inso
'''
from PyQt5.QtWidgets import QWidget
from cutecoin.gen_resources.communityTabWidget_uic import Ui_CommunityTabWidget
class CommunityTabWidget(QWidget, Ui_CommunityTabWidget):
'''
classdocs
'''
def __init__(self, community):
'''
Constructor
'''
super(CommunityTabWidget, self).__init__()
self.setupUi(self)
self.community = community
......@@ -6,6 +6,7 @@ Created on 1 févr. 2014
from cutecoin.gen_resources.mainwindow_uic import Ui_MainWindow
from PyQt5.QtWidgets import QMainWindow
from cutecoin.gui.addAccountDialog import AddAccountDialog
from cutecoin.gui.communityTabWidget import CommunityTabWidget
from cutecoin.models.account.wallets.listModel import WalletsListModel
from cutecoin.models.wallet.listModel import WalletListModel
......@@ -47,3 +48,6 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.accountNameLabel = self.core.currentAccount.name
self.walletsList.setModel(WalletsListModel(self.core.currentAccount))
self.walletContent.setModel(WalletListModel(self.core.currentAccount.wallets.walletsList[0]))
for community in self.core.currentAccount.communities.communitiesList:
self.communitiesTab.addPage(CommunityTabWidget(community), community.name())
......@@ -23,8 +23,7 @@ class Account(object):
self.wallets = Wallets()
for community in self.communities.communitiesList:
wallet = self.wallets.addWallet(community.currency)
#TODO: Gerer le cas ou plusieurs noeuds sont presents dans la liste et le 0 ne repond pas
wallet.refreshCoins(community.knownNodes[0], self.keyFingerprint())
wallet.refreshCoins(community, self.keyFingerprint())
self.receivedTransactions = []
self.sentTransactions = []
......@@ -32,13 +31,19 @@ class Account(object):
def addWallet(name, currency):
self.wallets.addWallet(name, currency)
def keyFingerprint():
def keyFingerprint(self):
gpg = gnupg.GPG()
availableKeys = gpg.list_keys(True)
availableKeys = gpg.list_keys()
for k in availableKeys:
if k['key_id'] == self.pgpKey:
if k['keyid'] == self.pgpKey:
return k['fingerprint']
return ""
def transactionsReceived(self):
pass
def transactionsSent(self):
pass
......@@ -22,19 +22,17 @@ class Communities(object):
if com.currency == currency:
return com
#TODO: Check membership
def addCommunity(self, mainNode):
ucoin.settings['server'] = mainNode.server
ucoin.settings['port'] = mainNode.port
currentAmendment = ucoin.hdc.amendments.Promoted().get()
currency = currentAmendment['currency']
community = self.getCommunity(currency)
if community == None:
community = Community(mainNode, currency)
self.communitiesList.append(community)
def addCommunity(self, mainNode, accountFingerprint):
community = Community(mainNode)
self.members = community.ucoinRequest(lambda:ucoin.hdc.amendments.view.Members(community.currentAmendmentId()).get)
return community
#TODO: Check membership
for member in self.members:
if member['value'] == accountFingerprint:
self.communitiesList.append(community)
return community
return None
#TODO: Jsonify this model
def saveJson(self):
......
......@@ -25,7 +25,7 @@ class CommunitiesListModel(QAbstractListModel):
if role == Qt.DisplayRole:
row=index.row()
value = self.communities.communitiesList[row].currency
value = self.communities.communitiesList[row].name()
return value
def flags(self,index):
......
......@@ -5,35 +5,51 @@ Created on 1 févr. 2014
'''
import ucoinpy as ucoin
import hashlib
import json
class Community(object):
'''
classdocs
'''
def __init__(self, mainNode, currency):
def __init__(self, mainNode):
'''
Constructor
'''
self.knownNodes = []
self.knownNodes.append(mainNode)
self.currency = currency
self.ucoinInstance = ucoin
currentAmendment = self.ucoinRequest(lambda : self.ucoinInstance.hdc.amendments.Current().get)
self.currency = currentAmendment['currency']
def members(self):
'''
Listing members of a community
'''
members = self.ucoinRequest(lambda : self.ucoinInstance.hdc.amendments.view.Members().get)
return members
#TODO: Try connecting with nodes of the list if the first fails
# Maybe create a method
ucoin.settings['server'] = self.knowNodes[0].server
ucoin.settings['port'] = self.knowNodes[0].port
def ucoinRequest(self, request):
for node in self.knownNodes:
if node.available == True:
self.ucoinInstance.settings['server'] = node.server
self.ucoinInstance.settings['port'] = node.port
print("Trying to connect to : " + node.getText())
return (request())()
raise RuntimeError("Cannot connect to any node")
members = ucoin.hdc.amendments.view.Members().get()
return members
def nodes(self):
return self.knownNodes
def currentAmendmentId(self):
currentAmendment = self.ucoinRequest(lambda:ucoin.hdc.amendments.Current().get)
currentAmendmentHash = hashlib.sha1(json.dumps(currentAmendment).encode('utf-8')).hexdigest()
amendmentId = str(currentAmendment["number"]) + "-" + currentAmendmentHash
print("Amendment : " + amendmentId)
return amendmentId
def name(self):
return self.currency
#TODO: Jsonify this model
def saveJson(self):
......
......@@ -7,7 +7,7 @@ Created on 5 févr. 2014
class CommunityItemModel(object):
def __init__(self, community, communitiesItem=None):
self.communitiesItem = communitiesItem
self.communityText = community.currency
self.communityText = community.name()
self.mainNodeItems = []
def appendChild(self, item):
......
......@@ -16,6 +16,7 @@ class Node(object):
'''
self.server = server
self.port = port
self.available = True
def __eq__(self, other):
......
......@@ -31,10 +31,8 @@ class Wallet(object):
value += coin.value()
return value
def refreshCoins(self, mainNode, pgpFingerprint):
ucoin.settings['server'] = mainNode
ucoin.settings['port'] = mainNode
dataList = ucoin.hdc.coins.List(pgpFingerprint).get()
def refreshCoins(self, community, pgpFingerprint):
dataList = community.ucoinRequest(lambda:ucoin.hdc.coins.List(pgpFingerprint).get)
for issaunces in dataList['coins']:
issuer = issaunces['issuer']
for coinsIds in issaunces['ids']:
......
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