From a891b25533ffa883c4741177dd2aa142efda5deb Mon Sep 17 00:00:00 2001 From: Inso <insomniak.fr@gmail.com> Date: Thu, 27 Mar 2014 19:29:24 +0100 Subject: [PATCH] Managing account quality in communities (voter/member/nothing) Refactoring Debugging --- Makefile | 36 ---- gen_resources.py | 40 +++++ src/cutecoin/core/__init__.py | 2 +- src/cutecoin/gui/configureAccountDialog.py | 4 +- src/cutecoin/gui/configureCommunityDialog.py | 7 +- src/cutecoin/gui/mainWindow.py | 6 +- src/cutecoin/models/account/__init__.py | 66 ++++--- .../models/account/communities/__init__.py | 28 +-- .../models/account/wallets/__init__.py | 2 +- src/cutecoin/models/community/__init__.py | 168 ++++++------------ src/cutecoin/models/community/network.py | 95 ++++++++++ src/cutecoin/models/community/treeModel.py | 22 +-- src/cutecoin/models/node/itemModel.py | 35 ---- src/cutecoin/models/person/__init__.py | 2 +- src/cutecoin/models/transaction/__init__.py | 6 +- src/cutecoin/models/transaction/factory.py | 10 +- src/cutecoin/models/wallet/__init__.py | 4 +- 17 files changed, 269 insertions(+), 264 deletions(-) delete mode 100644 Makefile create mode 100644 gen_resources.py create mode 100644 src/cutecoin/models/community/network.py diff --git a/Makefile b/Makefile deleted file mode 100644 index 057c2329..00000000 --- a/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -###### EDIT ##################### -#Directory with ui and resource files -RESOURCE_DIR = res/ui - -#Directory for compiled resources -COMPILED_DIR = src/cutecoin/gen_resources - -#UI files to compile -UI_FILES = mainwindow.ui accountConfigurationDialog.ui communityConfigurationDialog.ui communityTabWidget.ui issuanceDialog.ui transferDialog.ui addContactDialog.ui -#Qt resource files to compile -RESOURCES = - -#pyuic5 and pyrcc5 binaries -PYUIC = pyuic5 -PYRCC = pyrcc5 - -################################# -# DO NOT EDIT FOLLOWING - -COMPILED_UI = $(UI_FILES:%.ui=$(COMPILED_DIR)/%_uic.py) -COMPILED_RESOURCES = $(RESOURCES:%.qrc=$(COMPILED_DIR)/%_rc.py) - -all : resources ui - -resources : $(COMPILED_RESOURCES) - -ui : $(COMPILED_UI) - -$(COMPILED_DIR)/%_uic.py : $(RESOURCE_DIR)/%.ui - $(PYUIC) $< -o $@ - -$(COMPILED_DIR)/%_rc.py : $(RESOURCE_DIR)/%.qrc - $(PYRCC) $< -o $@ - -clean : - $(RM) $(COMPILED_UI) $(COMPILED_RESOURCES) $(COMPILED_UI:.py=.pyc) $(COMPILED_RESOURCES:.py=.pyc) diff --git a/gen_resources.py b/gen_resources.py new file mode 100644 index 00000000..49bac940 --- /dev/null +++ b/gen_resources.py @@ -0,0 +1,40 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +import sys, os, multiprocessing, subprocess + +resources = os.path.abspath(os.path.join(os.path.dirname(__file__), 'res')) +gen_resources = os.path.abspath(os.path.join(os.path.dirname(__file__), 'src', 'cutecoin', 'gen_resources')) +def convert_ui(args, **kwargs): + subprocess.call(args, **kwargs) + +def build_resources(): + try: + to_process = [] + for root, dirs, files in os.walk(resources): + for f in files: + if f.endswith('.ui'): + source = os.path.join(root, f) + dest = os.path.join(gen_resources, os.path.splitext(os.path.basename(source))[0]+'_uic.py') + exe = 'pyuic5' + elif f.endswith('.qrc'): + source = os.path.join(root, f) + dest = os.path.join(gen_resources, os.path.splitext(os.path.basename(source))[0]+'_rc.py') + exe = 'pyrcc5' + else: + continue + print(source + " >> " + dest) + to_process.append([exe, '-o', dest, source]) + + if sys.platform.startswith('win'): + # doing this in parallel on windows will crash your computer + [convert_ui(args, shell=True) for args in to_process] + else: + pool = multiprocessing.Pool() + pool.map(convert_ui, to_process) + except EnvironmentError: + print("""\ +Warning: PyQt5 development utilities (pyuic5 and pyrcc5) not found +Unable to install praxes' graphical user interface +""") + +build_resources() \ No newline at end of file diff --git a/src/cutecoin/core/__init__.py b/src/cutecoin/core/__init__.py index 15065a70..11ef6d81 100644 --- a/src/cutecoin/core/__init__.py +++ b/src/cutecoin/core/__init__.py @@ -37,7 +37,7 @@ class Core(object): def add_account(self, account): for a in self.accounts: - if a.keyId == account.keyId: + if a.keyid == account.keyid: raise KeyAlreadyUsed(account, account.keyid, a) self.accounts.append(account) diff --git a/src/cutecoin/gui/configureAccountDialog.py b/src/cutecoin/gui/configureAccountDialog.py index 7304b9e8..09538544 100644 --- a/src/cutecoin/gui/configureAccountDialog.py +++ b/src/cutecoin/gui/configureAccountDialog.py @@ -49,7 +49,7 @@ class ConfigureAccountDialog(QDialog, Ui_AccountConfigurationDialog): "", Communities()) self.combo_keys_list.currentIndexChanged[ - int].connect(self.keyChanged) + int].connect(self.key_changed) for index, key in enumerate(available_keys): self.combo_keys_list.addItem(key['uids'][0]) @@ -73,7 +73,7 @@ class ConfigureAccountDialog(QDialog, Ui_AccountConfigurationDialog): Node( server, port)) - dialog.button_box.accepted.connect(self.actionAddCommunity) + dialog.button_box.accepted.connect(self.action_add_community) dialog.exec_() def action_add_community(self): diff --git a/src/cutecoin/gui/configureCommunityDialog.py b/src/cutecoin/gui/configureCommunityDialog.py index 7aaa6e1e..96eb6ecb 100644 --- a/src/cutecoin/gui/configureCommunityDialog.py +++ b/src/cutecoin/gui/configureCommunityDialog.py @@ -31,10 +31,9 @@ class ConfigureCommunityDialog(QDialog, Ui_CommunityConfigurationDialog): default_node.trust = True default_node.hoster = True self.community = self.account.communities.add_community( - default_node, - self.account.key_fingerprint()) + default_node) self.account.wallets.add_wallet(self.community) - self.community_view.set_model(CommunityTreeModel(self.community)) + self.tree_nodes.setModel(CommunityTreeModel(self.community)) # TODO: Ask for THT pull msg_box = QMessageBox() msg_box.setText("Add a community") @@ -71,7 +70,7 @@ class ConfigureCommunityDialog(QDialog, Ui_CommunityConfigurationDialog): menu.exec_(self.tree_nodes.mapToGlobal(point)) def remove_node(self): - for index in self.community_view.selectedIndexes(): + for index in self.tree_nodes.selectedIndexes(): self.community.nodes.pop(index.row()) self.tree_nodes.setModel(CommunityTreeModel(self.community)) diff --git a/src/cutecoin/gui/mainWindow.py b/src/cutecoin/gui/mainWindow.py index a8a68ad2..9ec31b8d 100644 --- a/src/cutecoin/gui/mainWindow.py +++ b/src/cutecoin/gui/mainWindow.py @@ -38,7 +38,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): dialog = ConfigureAccountDialog(self.core, None) dialog.button_box.button( QDialogButtonBox.Ok).clicked.connect( - self.refreshMainWindow) + self.refresh) dialog.exec_() def save(self): @@ -95,7 +95,9 @@ class MainWindow(QMainWindow, Ui_MainWindow): tab_community = CommunityTabWidget( self.core.current_account, community) - self.tabs_communities.addTab(tab_community, community.name()) + quality = self.core.current_account.quality(community) + self.tabs_communities.addTab(tab_community, quality + + " in " + community.name()) self.menu_contacts_list.clear() for contact in self.core.current_account.contacts: diff --git a/src/cutecoin/models/account/__init__.py b/src/cutecoin/models/account/__init__.py index fc060cb8..07dc6eb5 100644 --- a/src/cutecoin/models/account/__init__.py +++ b/src/cutecoin/models/account/__init__.py @@ -43,7 +43,7 @@ class Account(object): account = cls(keyid, name, communities, wallets, []) for community in account.communities.communities_list: wallet = account.wallets.add_wallet(community.currency) - wallet.refresh_coins(community, account.key_fingerprint()) + wallet.refresh_coins(community, account.fingerprint()) return account @classmethod @@ -79,7 +79,7 @@ class Account(object): def add_contact(self, person): self.contacts.append(person) - def key_fingerprint(self): + def fingerprint(self): gpg = gnupg.GPG() available_keys = gpg.list_keys() logging.debug(self.keyid) @@ -92,9 +92,9 @@ class Account(object): def transactions_received(self): received = [] for community in self.communities.communities_list: - transactions_data = community.ucoin_request( + transactions_data = community.network.request( ucoin.hdc.transactions.Recipient( - self.key_fingerprint())) + self.fingerprint())) for trxData in transactions_data: received.append( factory.create_transaction( @@ -106,9 +106,9 @@ class Account(object): def transactions_sent(self): sent = [] for community in self.communities.communities_list: - transactions_data = community.ucoin_request( + transactions_data = community.network.request( ucoin.hdc.transactions.sender.Last( - self.key_fingerprint(), + self.fingerprint(), 20)) for trx_data in transactions_data: # Small bug in ucoinpy library @@ -123,9 +123,9 @@ class Account(object): def last_issuances(self, community): issuances = [] if community in self.communities.communities_list: - issuances_data = community.ucoin_request( + issuances_data = community.network.request( ucoin.hdc.transactions.sender.Issuance( - self.key_fingerprint())) + self.fingerprint())) for issuance in issuances_data: logging.debug(issuance) issuances.append( @@ -138,9 +138,9 @@ class Account(object): def issued_last_dividend(self, community): current_amendment_number = community.amendment_number() if community in self.communities.communities_list: - dividends_data = community.ucoin_request( + dividends_data = community.network.request( ucoin.hdc.transactions.sender.issuance.Dividend( - self.key_fingerprint(), + self.fingerprint(), current_amendment_number)) for dividend in dividends_data: # Small bug in ucoinpy library @@ -152,15 +152,26 @@ class Account(object): if community in self.communities.communities_list: logging.debug(coins) issuance = ucoin.wrappers.transactions.Issue( - self.key_fingerprint(), + self.fingerprint(), community.amendment_number(), coins, keyid=self.keyid) return issuance() + def transfer_coins(self, node, recipient, coins, message): + transfer = ucoin.wrappers.transactions.RawTransfer( + self.fingerprint(), + recipient.fingerprint, + coins, + message, + keyid=self.keyid, + server=node.server, + port=node.port) + return transfer() + def tht(self, community): if community in self.communities.communities_list: - tht = community.ucoinRequest(ucoin.ucg.tht(self.key_fingerprint())) + tht = community.ucoinRequest(ucoin.ucg.tht(self.fingerprint())) return tht['entries'] return None @@ -168,18 +179,18 @@ class Account(object): if community in self.communities.communities_list: hosters_fg = [] trusts_fg = [] - for trust in community.trusts(): + for trust in community.network.trusts(): peering = trust.peering() logging.debug(peering) trusts_fg.append(peering['fingerprint']) - for hoster in community.hosters(): + for hoster in community.network.hosters(): logging.debug(peering) peering = hoster.peering() hosters_fg.append(peering['fingerprint']) entry = { 'version': '1', 'currency': community.currency, - 'fingerprint': self.key_fingerprint(), + 'fingerprint': self.fingerprint(), 'hosters': hosters_fg, 'trusts': trusts_fg } @@ -193,27 +204,24 @@ class Account(object): 'signature': str(signature) } - community.ucoin_post( + community.network.post( ucoin.ucg.THT( - pgp_fingerprint=self.key_fingerprint()), + pgp_fingerprint=self.fingerprint()), dataPost) else: raise CommunityNotFoundError(self.keyid, community.amendment_id()) def pull_tht(self, community): if community in self.communities.communities_list: - community.pull_tht(self.key_fingerprint()) + community.pull_tht(self.fingerprint()) + else: + raise CommunityNotFoundError(self.keyid, community.amendment_id()) - def transfer_coins(self, node, recipient, coins, message): - transfer = ucoin.wrappers.transactions.RawTransfer( - self.key_fingerprint(), - recipient.fingerprint, - coins, - message, - keyid=self.keyid, - server=node.server, - port=node.port) - return transfer() + def quality(self, community): + if community in self.communities.communities_list: + return community.person_quality(self.fingerprint()) + else: + raise CommunityNotFoundError(self.keyid, community.amendment_id()) def jsonify_contacts(self): data = [] @@ -223,7 +231,7 @@ class Account(object): def jsonify(self): data = {'name': self.name, - 'keyId': self.keyid, + 'keyid': self.keyid, 'communities': self.communities.jsonify(self.wallets), 'contacts': self.jsonify_contacts()} return data diff --git a/src/cutecoin/models/account/communities/__init__.py b/src/cutecoin/models/account/communities/__init__.py index 7d3ecb77..62f205e9 100644 --- a/src/cutecoin/models/account/communities/__init__.py +++ b/src/cutecoin/models/account/communities/__init__.py @@ -21,35 +21,21 @@ class Communities(object): ''' self.communities_list = [] - def add_community(self, main_node, key_fingerprint): + def add_community(self, main_node): ''' - Add a community with a mainNode and the fingerprint of the account - Check if the fingerprint is present in the community members list - If its not, the account isnt added and an error is raised. + Add a community with a mainNode ''' community = Community.create(main_node) - members = community.ucoin_request( - ucoin.hdc.amendments.view.Members( - community.amendment_id())) - - logging.debug("Account fingerprint : " + key_fingerprint) - for member in members: - logging.debug(member) - if member['value'] == key_fingerprint: - self.communities_list.append(community) - return community - - raise NotMemberOfCommunityError( - key_fingerprint, - community.currency + - "-" + - community.amendment_id()) + if community not in self.communities_list: + self.communities_list.append(community) + return community + return None def jsonify(self, wallets): ''' Return the list of communities in a key:value form. ''' data = [] - for community in self.communitiesList: + for community in self.communities_list: data.append(community.jsonify(wallets)) return data diff --git a/src/cutecoin/models/account/wallets/__init__.py b/src/cutecoin/models/account/wallets/__init__.py index 6ef0808b..a544f23d 100644 --- a/src/cutecoin/models/account/wallets/__init__.py +++ b/src/cutecoin/models/account/wallets/__init__.py @@ -26,7 +26,7 @@ class Wallets(object): it means the wallet must have a different name or a different currency. ''' wallet = Wallet.create(currency) - if wallet not in self.walletslist: + if wallet not in self.wallets_list: self.wallets_list.append(wallet) else: return self.wallets_list.get(wallet) diff --git a/src/cutecoin/models/community/__init__.py b/src/cutecoin/models/community/__init__.py index eab08152..f7d488ce 100644 --- a/src/cutecoin/models/community/__init__.py +++ b/src/cutecoin/models/community/__init__.py @@ -10,6 +10,7 @@ import json import logging from cutecoin.models.node import Node from cutecoin.models.wallet import Wallet +from cutecoin.models.community.network import CommunityNetwork class Community(object): @@ -18,21 +19,21 @@ class Community(object): classdocs ''' - def __init__(self, nodes): + def __init__(self, network): ''' A community is a group of nodes using the same currency. They are all using the same amendment and are syncing their datas. An account is a member of a community if he is a member of the current amendment. ''' - self.nodes = nodes - current_amendment = self.ucoin_request(ucoin.hdc.amendments.Current()) + self.network = network + current_amendment = self.network.request(ucoin.hdc.amendments.Current()) self.currency = current_amendment['currency'] @classmethod def create(cls, main_node): nodes = [] nodes.append(main_node) - return cls(nodes) + return cls(CommunityNetwork(nodes)) @classmethod def load(cls, json_data, account): @@ -45,147 +46,92 @@ class Community(object): node_data['trust'], node_data['hoster'])) - community = cls(known_nodes) + community = cls(CommunityNetwork(known_nodes)) for wallets_data in json_data['wallets']: wallet = Wallet.load(wallets_data, community) - wallet.refreshCoins(account.key_fingerprint()) + wallet.refreshCoins(account.fingerprint()) account.wallets.wallets_list.append(wallet) return community - # TODO: Check if its working - def _search_node_by_fingerprint(self, node_fg, next_node, traversed_nodes=[]): - next_fg = next_node.peering()['fingerprint'] - if next_fg not in traversed_nodes: - traversed_nodes.append(next_fg) - if node_fg == next_fg: - return next_node - else: - for peer in next_node.peers(): - # Look for next node informations - found = self._searchTrustAddresses( - node_fg, Node( - peer['ipv4'], int( - peer['port'])), traversed_nodes) - if found is not None: - return found - return None - - def get_nodes_in_peering(self, fingerprints): - nodes = [] - for node_fg in fingerprints: - nodes.append( - self._search_node_by_fingerprint( - node_fg, - self.trusts()[0])) - return nodes - - def pull_tht(self, fingerprint): - tht = self.ucoin_request(ucoin.ucg.THT(fingerprint)) - nodes = [] - nodes.append(self.trusts()[0]) - # We add trusts to the node list - for node_fg in tht['trusts']: - nodes.append( - self._search_node_by_fingerprint( - node_fg, - self.trusts()[0])) - # We look in hosters lists - for node_fg in tht['hosters']: - # If the node was already added as a trust - if node_fg in tht['trusts']: - found_nodes = [ - node for node in nodes if node.peering()['fingerprint'] == node_fg] - if len(found_nodes) == 1: - found_nodes[0].hoster = True - else: - # not supposed to happen - pass - # Else we add it - else: - nodes.append( - self._search_node_by_fingerprint( - node_fg, - self.trusts()[0])) - - def trusts(self): - return [node for node in self.nodes if node.trust] - - def hosters(self): - return [node for node in self.nodes if node.trust] - - def members_fingerprints(self): - ''' - Listing members of a community - ''' - fingerprints = self.ucoin_request( - ucoin.hdc.amendments.view.Members( - self.amendment_id())) - members = [] - for f in fingerprints: - members.append(f['value']) - return members - - def ucoin_request(self, request, get_args={}): - for node in self.trusts(): - logging.debug("Trying to connect to : " + node.getText()) - request = node.use(request) - return request.get(**get_args) - raise RuntimeError("Cannot connect to any node") - - def ucoin_post(self, request, get_args={}): - for node in self.hosters(): - logging.debug("Trying to connect to : " + node.getText()) - request = node.use(request) - return request.post(**get_args) - raise RuntimeError("Cannot connect to any node") - - def amendment_id(self): - current_amendment = self.ucoin_request(ucoin.hdc.amendments.Current()) - current_amendment_hash = hashlib.sha1( - current_amendment['raw'].encode('utf-8')).hexdigest().upper() - amendment_id = str( - current_amendment["number"]) + "-" + current_amendment_hash - logging.debug("Amendment : " + amendment_id) - return amendment_id + def name(self): + return self.currency def __eq__(self, other): - current_amendment = self.ucoin_request(ucoin.hdc.amendments.Current()) + current_amendment = self.network.request(ucoin.hdc.amendments.Current()) current_amendment_hash = hashlib.sha1( current_amendment['raw'].encode('utf-8')).hexdigest().upper() - other_amendment = other.ucoin_request(ucoin.hdc.amendments.Current()) + other_amendment = other.network.request(ucoin.hdc.amendments.Current()) other_amendment_hash = hashlib.sha1( other_amendment['raw'].encode('utf-8')).hexdigest().upper() return (other_amendment_hash == current_amendment_hash) - def name(self): - return self.currency - def dividend(self): - current_amendment = self.ucoin_request(ucoin.hdc.amendments.Current()) + current_amendment = self.network.request(ucoin.hdc.amendments.Current()) return current_amendment['dividend'] def coin_minimal_power(self): - current_amendment = self.ucoin_request(ucoin.hdc.amendments.Current()) + current_amendment = self.network.request(ucoin.hdc.amendments.Current()) if 'coinMinimalPower' in current_amendment.keys(): return current_amendment['coinMinimalPower'] else: return 0 + def amendment_id(self): + current_amendment = self.network.request(ucoin.hdc.amendments.Current()) + current_amendment_hash = hashlib.sha1( + current_amendment['raw'].encode('utf-8')).hexdigest().upper() + amendment_id = str( + current_amendment["number"]) + "-" + current_amendment_hash + logging.debug("Amendment : " + amendment_id) + return amendment_id + def amendment_number(self): - current_amendment = self.ucoin_request(ucoin.hdc.amendments.Current()) + current_amendment = self.network.request(ucoin.hdc.amendments.Current()) return current_amendment['number'] + def person_quality(self, fingerprint): + if (fingerprint in self.voters_fingerprints()): + return "voter" + elif (fingerprint in self.members_fingerprints()): + return "member" + else: + return "nothing" + + def members_fingerprints(self): + ''' + Listing members of a community + ''' + fingerprints = self.network.request( + ucoin.hdc.amendments.view.Members( + self.amendment_id())) + members = [] + for f in fingerprints: + members.append(f['value']) + return members + + def voters_fingerprints(self): + ''' + Listing members of a community + ''' + fingerprints = self.network.request( + ucoin.hdc.amendments.view.Voters( + self.amendment_id())) + voters = [] + for f in fingerprints: + voters.append(f['value']) + return voters + def jsonify_nodes_list(self): data = [] - for node in self.nodes: + for node in self.network.nodes: data.append(node.jsonify()) return data def jsonify(self, wallets): - data = {'nodes': self.jsonify_nodeslist(), + data = {'nodes': self.jsonify_nodes_list(), 'currency': self.currency, 'wallets': wallets.jsonify(self)} return data diff --git a/src/cutecoin/models/community/network.py b/src/cutecoin/models/community/network.py new file mode 100644 index 00000000..93a855c4 --- /dev/null +++ b/src/cutecoin/models/community/network.py @@ -0,0 +1,95 @@ +''' +Created on 27 mars 2014 + +@author: inso +''' +from cutecoin.models.node import Node +import ucoinpy as ucoin +import logging + +class CommunityNetwork(object): + ''' + classdocs + ''' + + #TODO: Factory to load json + def __init__(self, nodes): + ''' + Constructor + ''' + self.nodes = nodes + + def request(self, request, get_args={}): + for node in self.trusts(): + logging.debug("Trying to connect to : " + node.getText()) + request = node.use(request) + return request.get(**get_args) + raise RuntimeError("Cannot connect to any node") + + def post(self, request, get_args={}): + for node in self.hosters(): + logging.debug("Trying to connect to : " + node.getText()) + request = node.use(request) + return request.post(**get_args) + raise RuntimeError("Cannot connect to any node") + + # TODO: Check if its working + def _search_node_by_fingerprint(self, node_fg, next_node, traversed_nodes=[]): + next_fg = next_node.peering()['fingerprint'] + if next_fg not in traversed_nodes: + traversed_nodes.append(next_fg) + if node_fg == next_fg: + return next_node + else: + for peer in next_node.peers(): + # Look for next node informations + found = self._searchTrustAddresses( + node_fg, Node( + peer['ipv4'], int( + peer['port'])), traversed_nodes) + if found is not None: + return found + return None + + def get_nodes_in_peering(self, fingerprints): + nodes = [] + for node_fg in fingerprints: + nodes.append( + self._search_node_by_fingerprint( + node_fg, + self.trusts()[0])) + return nodes + + def pull_tht(self, fingerprint): + tht = self.network.request(ucoin.ucg.THT(fingerprint)) + nodes = [] + nodes.append(self.trusts()[0]) + # We add trusts to the node list + for node_fg in tht['trusts']: + nodes.append( + self._search_node_by_fingerprint( + node_fg, + self.trusts()[0])) + # We look in hosters lists + for node_fg in tht['hosters']: + # If the node was already added as a trust + if node_fg in tht['trusts']: + found_nodes = [ + node for node in nodes if node.peering()['fingerprint'] == node_fg] + if len(found_nodes) == 1: + found_nodes[0].hoster = True + else: + # not supposed to happen + pass + # Else we add it + else: + nodes.append( + self._search_node_by_fingerprint( + node_fg, + self.trusts()[0])) + + def trusts(self): + return [node for node in self.nodes if node.trust] + + def hosters(self): + return [node for node in self.nodes if node.hoster] diff --git a/src/cutecoin/models/community/treeModel.py b/src/cutecoin/models/community/treeModel.py index 1595cbcb..9f671ee9 100644 --- a/src/cutecoin/models/community/treeModel.py +++ b/src/cutecoin/models/community/treeModel.py @@ -5,7 +5,7 @@ Created on 5 févr. 2014 ''' from PyQt5.QtCore import QAbstractItemModel, QModelIndex, Qt -from cutecoin.models.node.itemModel import MainNodeItem, NodeItem +from cutecoin.models.node.itemModel import NodeItem from cutecoin.models.community.itemModel import CommunityItemModel import logging @@ -111,24 +111,24 @@ class CommunityTreeModel(QAbstractItemModel): item.trust = value elif index.column() == 2: item.host = value - self.data_changed.emit(index, index) + self.dataChanged.emit(index, index) return True def refresh_tree_nodes(self): logging.debug("root : " + self.root_item.data(0)) - for main_node in self.community.nodes: - main_node_item = MainNodeItem(main_node, self.root_item) + for node in self.community.network.nodes: + node_item = NodeItem(node, self.root_item) logging.debug( "mainNode : " + - main_node.getText() + + node.getText() + " / " + - main_node_item.data(0)) - self.root_item.appendChild(main_node_item) - for node in main_node.downstream_peers(): - node_item = NodeItem(node, main_node_item) + node_item.data(0)) + self.root_item.appendChild(node_item) + for node in node.downstream_peers(): + child_node_item = NodeItem(node, node_item) logging.debug( "\t node : " + node.getText() + " / " + - node_item.data(0)) - main_node_item.appendChild(node_item) + child_node_item.data(0)) + node_item.appendChild(child_node_item) diff --git a/src/cutecoin/models/node/itemModel.py b/src/cutecoin/models/node/itemModel.py index 64f7ad2e..ca9b4bef 100644 --- a/src/cutecoin/models/node/itemModel.py +++ b/src/cutecoin/models/node/itemModel.py @@ -7,41 +7,6 @@ Created on 5 févr. 2014 class NodeItem(object): - def __init__(self, node, mainNodeItem=None): - self.mainNodeItem = mainNodeItem - self.nodeText = node.getText() - self.trust = node.trust - self.hoster = node.hoster - - def appendChild(self, item): - pass - - def child(self, row): - return None - - def childCount(self): - return 0 - - def columnCount(self): - return 1 - - def data(self, column): - try: - return self.nodeText - except IndexError: - return None - - def parent(self): - return self.mainNodeItem - - def row(self): - if self.mainNodeItem: - return self.mainNodeItem.nodeItems.index(self) - return 0 - - -class MainNodeItem(object): - def __init__(self, main_node, community_item=None): self.community_item = community_item self.main_node_text = main_node.getText() diff --git a/src/cutecoin/models/person/__init__.py b/src/cutecoin/models/person/__init__.py index 7cbf0dd0..5d6ad21e 100644 --- a/src/cutecoin/models/person/__init__.py +++ b/src/cutecoin/models/person/__init__.py @@ -28,7 +28,7 @@ class Person(object): ''' Create a person from the fngerprint found in a community ''' - keys = community.ucoin_request( + keys = community.network.request( ucoin.pks.Lookup(), get_args={ 'search': "0x" + diff --git a/src/cutecoin/models/transaction/__init__.py b/src/cutecoin/models/transaction/__init__.py index 26dabe68..47dd790e 100644 --- a/src/cutecoin/models/transaction/__init__.py +++ b/src/cutecoin/models/transaction/__init__.py @@ -23,14 +23,14 @@ class Transaction(object): def value(self): value = 0 - trx_data = self.community.ucoin_request( + trx_data = self.community.network.request( ucoin.hdc.transactions.View(self.sender.fingerprint + "-" + str(self.increment))) for coin in trx_data['transaction']['coins']: value += Coin.from_id(coin['id']).value() return value def currency(self): - trx_data = self.community.ucoin_request( + trx_data = self.community.network.request( ucoin.hdc.transactions.View(self.sender.fingerprint + "-" + str(self.increment))) currency = trx_data['transaction']['currency'] return currency @@ -63,7 +63,7 @@ class Issuance(Transaction): super(Issuance).__init__() def amendmentNumber(self): - self.community.ucoin_request( + self.community.network.request( ucoin.hdc.transactions.View(self.sender.fingerprint + "-" + str(self.increment))) def getText(self): diff --git a/src/cutecoin/models/transaction/factory.py b/src/cutecoin/models/transaction/factory.py index a9886ec1..f5f40ece 100644 --- a/src/cutecoin/models/transaction/factory.py +++ b/src/cutecoin/models/transaction/factory.py @@ -13,13 +13,13 @@ from cutecoin.models.transaction import Transfer, Issuance def create_transaction(sender_fingerprint, increment, community): transaction_id = sender_fingerprint + "-" + str(increment) - ucoin_transaction_view = community.ucoin_request( + transaction_view = community.network.request( ucoin.hdc.transactions.View(transaction_id)) - ucoin_transaction = ucoin_transaction_view['transaction'] + transaction_data = transaction_view['transaction'] transaction = None - if ucoin_transaction['type'] == 'TRANSFER': + if transaction_data['type'] == 'TRANSFER': transaction = Transfer() - elif ucoin_transaction['type'] == 'ISSUANCE': + elif transaction_data['type'] == 'ISSUANCE': transaction = Issuance() if transaction is not None: @@ -27,7 +27,7 @@ def create_transaction(sender_fingerprint, increment, community): transaction.community = community transaction.sender = Person.lookup(sender_fingerprint, community) transaction.recipient = Person.lookup( - ucoin_transaction['recipient'], + transaction_data['recipient'], community) return transaction diff --git a/src/cutecoin/models/wallet/__init__.py b/src/cutecoin/models/wallet/__init__.py index 45406d91..2f99ab89 100644 --- a/src/cutecoin/models/wallet/__init__.py +++ b/src/cutecoin/models/wallet/__init__.py @@ -46,7 +46,7 @@ class Wallet(object): # TODO: Refresh coins when changing current account def refreshCoins(self, fingerprint): - data_list = self.community.ucoin_request( + data_list = self.community.network.request( ucoin.hdc.coins.List({'pgp_fingerprint': fingerprint})) for issaunces in data_list['coins']: issuer = issaunces['issuer'] @@ -59,7 +59,7 @@ class Wallet(object): return self.name + " : " + \ str(self.value()) + " " + self.community.currency - def jsonifyCoinsList(self): + def jsonify_coins_list(self): data = [] for coin in self.coins: data.append({'coin': coin.get_id()}) -- GitLab