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

WHT pushing and pulling : OK

parent 356d4264
No related branches found
No related tags found
No related merge requests found
......@@ -46,7 +46,6 @@ class StepPageInit(Step):
default_node = Node.create(server, port, trust=True, hoster=True)
account = self.config_dialog.account
self.config_dialog.community = account.add_community(default_node)
self.config_dialog.nodes.append(default_node)
def display_page(self):
self.config_dialog.button_previous.setEnabled(False)
......@@ -67,6 +66,12 @@ class StepPageAddNodes(Step):
pass
def display_page(self):
# We add already known nodes to the displayed list
for wallet in self.config_dialog.account.wallets:
for node in wallet.nodes:
if node not in self.config_dialog.nodes:
self.config_dialog.nodes.append(node)
tree_model = NodesTreeModel(self.config_dialog.nodes,
self.config_dialog.community.name())
self.config_dialog.tree_nodes.setModel(tree_model)
......@@ -135,6 +140,8 @@ class ProcessConfigureCommunity(QDialog, Ui_CommunityConfigurationDialog):
self.step = step_init
self.setWindowTitle("Add a community")
self.step.display_page()
def next(self):
if self.step.next_step is not None:
if self.step.is_valid():
......
......@@ -50,11 +50,19 @@ class Wallets(object):
required_trusts=1, name="Main Wallet"):
'''
Create a new wallet of a specific currency.
This wallet must not already be present in the account,
it means the wallet must have a different name or a different currency.
'''
wallet = Wallet.create(keyid, community, node,
required_trusts, name)
# We try to add already present nodes to the wallet
try:
present_nodes = wallet.get_nodes_in_peering(wallet.pull_wht())
except ValueError:
present_nodes = []
for present_node in present_nodes:
if present_node not in wallet.nodes:
wallet.nodes.append(present_node)
if wallet not in self._wallets_list:
self._wallets_list.append(wallet)
return wallet
......
......@@ -5,6 +5,7 @@ Created on 1 févr. 2014
'''
import ucoin
import re
class Node(object):
......@@ -26,6 +27,16 @@ class Node(object):
def create(cls, server, port, trust=False, hoster=False):
return cls(server, port, trust, hoster)
@classmethod
def from_endpoints(cls, endpoints):
#TODO: Manage multiple endpoints
for endpoint in endpoints:
bma_endpoints = re.compile('^BASIC_MERKLED_API( ([a-z_][a-z0-9-_.]+))?( ([0-9.]+))?( ([0-9a-f:]+))?( ([0-9]+))$')
m = bma_endpoints.match(endpoint)
server = m.group(4)
port = int(m.group(8))
return cls(server, port, False, False)
@classmethod
def load(cls, json_data):
server = json_data['server']
......
......@@ -93,11 +93,8 @@ class Wallet(object):
return sent
def pull_wht(self):
try:
wht = self.request(ucoin.network.Wallet(self.fingerprint()))
return wht['entries']
except ValueError:
return None
wht = self.request(ucoin.network.Wallet(self.fingerprint()))
return wht['entry']
def push_wht(self):
hosters_fg = []
......@@ -145,9 +142,9 @@ Hosters:
for peer in next_node.peers():
# Look for next node informations
found = self._search_node_by_fingerprint(
node_fg, Node.create(
peer['ipv4'], int(
peer['port'])), traversed_nodes)
node_fg,
Node.from_endpoints(peer['value']['endpoints']),
traversed_nodes)
if found is not None:
return found
return None
......@@ -155,10 +152,12 @@ Hosters:
def get_nodes_in_peering(self, fingerprints):
nodes = []
for node_fg in fingerprints:
nodes.append(
self._search_node_by_fingerprint(
node = self._search_node_by_fingerprint(
node_fg,
self.trusts()[0]))
self.trusts()[0])
if node is not None:
nodes.append(node)
#TODO: Check that one trust exists
return nodes
def request(self, request, get_args={}):
......
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