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

Save when root node changes

parent 7bddd262
No related branches found
No related tags found
No related merge requests found
...@@ -254,8 +254,11 @@ class Application(QObject): ...@@ -254,8 +254,11 @@ class Application(QObject):
for community in account.communities: for community in account.communities:
community.network.blockchain_rollback.connect(community.rollback_cache) community.network.blockchain_rollback.connect(community.rollback_cache)
community.network.new_block_mined.connect(lambda b, co=community: account.refresh_transactions(self, co)) community.network.new_block_mined.connect(lambda b, co=community:
community.network.blockchain_rollback.connect(lambda b, co=community: account.rollback_transaction(self, co)) account.refresh_transactions(self, co))
community.network.blockchain_rollback.connect(lambda b, co=community:
account.rollback_transaction(self, co))
community.network.root_nodes_changed.connect(lambda acc=account: self.save(acc))
def load_cache(self, account): def load_cache(self, account):
""" """
......
...@@ -23,6 +23,7 @@ class Network(QObject): ...@@ -23,6 +23,7 @@ class Network(QObject):
given community. given community.
""" """
nodes_changed = pyqtSignal() nodes_changed = pyqtSignal()
root_nodes_changed = pyqtSignal()
new_block_mined = pyqtSignal(int) new_block_mined = pyqtSignal(int)
blockchain_rollback = pyqtSignal(int) blockchain_rollback = pyqtSignal(int)
...@@ -238,12 +239,16 @@ class Network(QObject): ...@@ -238,12 +239,16 @@ class Network(QObject):
n.state = Node.DESYNCED n.state = Node.DESYNCED
def _check_nodes_unique(self): def _check_nodes_unique(self):
"""
Check that all nodes are unique by them pubkeys
"""
pubkeys = set() pubkeys = set()
unique_nodes = [] unique_nodes = []
for n in self.nodes: for n in self.nodes:
if n.pubkey not in pubkeys: if n.pubkey not in pubkeys:
unique_nodes.append(n) unique_nodes.append(n)
pubkeys.add(n.pubkey) pubkeys.add(n.pubkey)
self._nodes = unique_nodes self._nodes = unique_nodes
def fork_window(self, members_pubkeys): def fork_window(self, members_pubkeys):
...@@ -272,12 +277,14 @@ class Network(QObject): ...@@ -272,12 +277,14 @@ class Network(QObject):
Add a node to the root nodes list Add a node to the root nodes list
""" """
self._root_nodes.append(node) self._root_nodes.append(node)
self.root_nodes_changed.emit()
def remove_root_node(self, index): def remove_root_node(self, index):
""" """
Remove a node from the root nodes list Remove a node from the root nodes list
""" """
self._root_nodes.pop(index) self._root_nodes.pop(index)
self.root_nodes_changed.emit()
def is_root_node(self, node): def is_root_node(self, node):
""" """
......
...@@ -91,11 +91,13 @@ class NetworkTabWidget(QWidget, Ui_NetworkTabWidget): ...@@ -91,11 +91,13 @@ class NetworkTabWidget(QWidget, Ui_NetworkTabWidget):
def set_root_node(self): def set_root_node(self):
node = self.sender().data() node = self.sender().data()
self.community.network.add_root_node(node) self.community.network.add_root_node(node)
self.table_network.model().sourceModel().refresh_nodes()
@pyqtSlot() @pyqtSlot()
def unset_root_node(self): def unset_root_node(self):
index = self.sender().data() index = self.sender().data()
self.community.network.remove_root_node(index) self.community.network.remove_root_node(index)
self.table_network.model().sourceModel().refresh_nodes()
@pyqtSlot() @pyqtSlot()
def open_node_in_browser(self): def open_node_in_browser(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment