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

Fixed a bug in peers parsing when loading a community

parent 083c6013
No related branches found
No related tags found
No related merge requests found
......@@ -33,7 +33,7 @@
<bool>false</bool>
</property>
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="tab_wallets">
<attribute name="icon">
......
......@@ -47,11 +47,14 @@ class Community(object):
endpoint_inline = next(e for e in data['endpoints']
if Endpoint.from_inline(e) is not None)
endpoint = Endpoint.from_inline(endpoint_inline)
peering = bma.network.Peering(endpoint.conn_handler())
peer_data = peering.get()
peer = Peer.from_signed_raw("{0}{1}\n".format(peer_data['raw'],
try:
peering = bma.network.Peering(endpoint.conn_handler())
peer_data = peering.get()
peer = Peer.from_signed_raw("{0}{1}\n".format(peer_data['raw'],
peer_data['signature']))
peers.append(peer)
peers.append(peer)
except:
pass
community = cls(currency, peers)
return community
......
......@@ -75,22 +75,29 @@ class Cache():
with_tx = community.request(bma.blockchain.TX)
# We parse only blocks with transactions
parsed_blocks = reversed(range(self.latest_block,
current_block['number']))
parsed_blocks = [n for n in parsed_blocks if n in with_tx['result']['blocks']]
current_block['number'] + 1))
parsed_blocks = [n for n in parsed_blocks
if n in with_tx['result']['blocks']]
for block_number in parsed_blocks:
block = community.request(bma.blockchain.Block,
req_args={'number': block_number})
signed_raw = "{0}{1}\n".format(block['raw'], block['signature'])
block_doc = Block.from_signed_raw(signed_raw)
for tx in block_doc.transactions:
in_outputs = [o for o in tx.outputs if o.pubkey == self.wallet.pubkey]
in_outputs = [o for o in tx.outputs
if o.pubkey == self.wallet.pubkey]
if len(in_outputs) > 0:
self.tx_received.append(tx)
in_inputs = [i for i in tx.issuers if i == self.wallet.pubkey]
if len(in_inputs) > 0:
logging.debug("TX:{0}".format(tx.compact()))
# remove from waiting transactions list the one which were
# validated in the blockchain
confirmed_tx = [awaiting for awaiting in self.awaiting_tx
if awaiting.compact() == tx.compact()]
for c in confirmed_tx:
logging.debug("Awaiting:{0}".format(c.compact()))
self.awaiting_tx = [awaiting for awaiting in self.awaiting_tx
if awaiting.compact() != tx.compact()]
self.tx_sent.append(tx)
......
......@@ -139,10 +139,16 @@ class ProcessConfigureCommunity(QDialog, Ui_CommunityConfigurationDialog):
'''
server = self.lineedit_server.text()
port = self.spinbox_port.value()
if self.community is not None:
self.community.add_peer(server, port)
self.tree_peers.setModel(PeeringTreeModel(self.community,
self.peers))
try:
peer_data = bma.network.Peering(ConnectionHandler(server, port))
peer = Peer.from_signed_raw("{0}{1}\n".format(peer_data['raw'],
peer_data['signature']))
self.community.peers.append(peer)
except:
QMessageBox.critical(self, "Server error",
"Cannot get node peering")
self.tree_peers.setModel(PeeringTreeModel(self.community))
def showContextMenu(self, point):
if self.stacked_pages.currentIndex() == 1:
......
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