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

Fix transaction parsing

parent 28a331ee
No related branches found
No related tags found
No related merge requests found
......@@ -68,6 +68,8 @@ class Node(QObject):
the currency it should have, for example if its the first one we add
:param str address: The node address
:param int port: The node port
:return: A new node
:rtype: cutecoin.core.net.Node
"""
peer_data = yield from bma.network.Peering(ConnectionHandler(address, port)).get()
......@@ -93,6 +95,8 @@ class Node(QObject):
:param str currency: The node currency. None if we don't know\
the currency it should have, for example if its the first one we add
:param peer: The peer document
:return: A new node
:rtype: cutecoin.core.net.Node
"""
if currency is not None:
if peer.currency != currency:
......@@ -265,17 +269,11 @@ class Node(QObject):
self._fork_window = new_fork_window
self.changed.emit()
def check_noerror(self, error_code, status_code):
if error_code == QNetworkReply.NoError:
if status_code in (200, 404):
if self.state == Node.OFFLINE:
self.state = Node.ONLINE
return True
self.state = Node.OFFLINE
return False
@pyqtSlot()
def refresh(self):
"""
Refresh all data of this node
"""
logging.debug("Refresh block")
self.refresh_block()
logging.debug("Refresh info")
......@@ -290,6 +288,9 @@ class Node(QObject):
@asyncify
@asyncio.coroutine
def refresh_block(self):
"""
Refresh the blocks of this node
"""
conn_handler = self.endpoint.conn_handler()
logging.debug("Requesting {0}".format(conn_handler))
......@@ -318,6 +319,9 @@ class Node(QObject):
@asyncify
@asyncio.coroutine
def refresh_informations(self):
"""
Refresh basic information (pubkey and currency)
"""
conn_handler = self.endpoint.conn_handler()
try:
......@@ -352,6 +356,9 @@ class Node(QObject):
@asyncify
@asyncio.coroutine
def refresh_summary(self):
"""
Refresh the summary of this node
"""
conn_handler = self.endpoint.conn_handler()
try:
......@@ -376,6 +383,9 @@ class Node(QObject):
@asyncify
@asyncio.coroutine
def refresh_uid(self):
"""
Refresh the node UID
"""
conn_handler = self.endpoint.conn_handler()
try:
data = yield from bma.wot.Lookup(conn_handler, self.pubkey).get()
......@@ -408,6 +418,9 @@ class Node(QObject):
@asyncify
@asyncio.coroutine
def refresh_peers(self):
"""
Refresh the list of peers knew by this node
"""
conn_handler = self.endpoint.conn_handler()
try:
......
......@@ -142,8 +142,8 @@ class Transfer(QObject):
self.state = Transfer.VALIDATING
self._metadata['block'] = block_number
self._metadata['time'] = time
elif self.state == Transfer.VALIDATING and \
self._metadata['block'] - block_number > data_validation:
if self.state == Transfer.VALIDATING and \
self._metadata['block'] - block_number >= data_validation:
self.state = Transfer.VALIDATED
def check_refused(self, time, block_time, mediantime_blocks):
......
......@@ -76,7 +76,7 @@ class TxHistory():
@asyncio.coroutine
def _validation_state(community, block_number, current_block):
members_pubkeys = yield from community.members_pubkeys()
if block_number + community.network.fork_window(members_pubkeys) + 1 < current_block["number"]:
if block_number + community.network.fork_window(members_pubkeys) <= current_block["number"]:
state = Transfer.VALIDATED
else:
state = Transfer.VALIDATING
......@@ -86,6 +86,17 @@ class TxHistory():
def _parse_transaction(self, community, tx, block_number,
mediantime, received_list,
current_block, txid):
"""
Parse a transaction
:param cutecoin.core.Community community: The community
:param dict tx: The tx json data
:param int block_number: The block number were we found the tx
:param int mediantime: Median time on the network
:param list received_list: The list of received transactions
:param int current_block: The current block of the network
:param int txid: The latest txid
:return: the found transaction
"""
receivers = [o.pubkey for o in tx.outputs
if o.pubkey != tx.issuers[0]]
......@@ -158,11 +169,20 @@ class TxHistory():
transfer = [t for t in awaiting if t.hash == tx_hash][0]
transfer.check_registered(tx_hash, current_block['number'], mediantime,
community.network.fork_window(community.members_pubkeys()) + 1)
community.network.fork_window(community.members_pubkeys()))
return None
@asyncio.coroutine
def _parse_block(self, community, block_number, received_list, current_block, txmax):
"""
Parse a block
:param cutecoin.core.Community community: The community
:param int block_number: The block to request
:param list received_list: The list where we are appending transactions
:param int current_block: The current block of the network
:param int txmax: Latest tx id
:return: The list of transfers sent
"""
block = None
tries = 0
while block is None and tries < 3:
......
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