diff --git a/src/cutecoin/core/net/node.py b/src/cutecoin/core/net/node.py index 16474d09efb222705749a812dcea92a425d46964..916bc6d99eb941c36bc559ba9978dd51f4f8629c 100644 --- a/src/cutecoin/core/net/node.py +++ b/src/cutecoin/core/net/node.py @@ -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: diff --git a/src/cutecoin/core/transfer.py b/src/cutecoin/core/transfer.py index b4defa7a5e119cc1bb45e0adb337a656aa931995..32a45bdc4a17d3128e1e5e8216fd9e34a08f4106 100644 --- a/src/cutecoin/core/transfer.py +++ b/src/cutecoin/core/transfer.py @@ -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): diff --git a/src/cutecoin/core/txhistory.py b/src/cutecoin/core/txhistory.py index 1b0eeecd928b38a7fab7c06ac6a28f6f740ec438..264e6fd5330e689cad5ad431d0045c2d2fb20a61 100644 --- a/src/cutecoin/core/txhistory.py +++ b/src/cutecoin/core/txhistory.py @@ -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: