diff --git a/src/cutecoin/core/transfer.py b/src/cutecoin/core/transfer.py index 32a45bdc4a17d3128e1e5e8216fd9e34a08f4106..29902ca573b85fda70195b39ee820347d87a902a 100644 --- a/src/cutecoin/core/transfer.py +++ b/src/cutecoin/core/transfer.py @@ -70,11 +70,13 @@ class Transfer(QObject): return cls(None, Transfer.TO_SEND, metadata) @classmethod - def create_from_blockchain(cls, hash, state, metadata): + def create_from_blockchain(cls, hash, metadata, block_number, time, nb_validation): """ Create a new transfer sent from another cutecoin instance """ - return cls(hash, state, metadata) + tx = cls(hash, Transfer.VALIDATING, metadata) + tx.check_registered(block_number, time, nb_validation) + return tx @classmethod def load(cls, data): @@ -128,7 +130,7 @@ class Transfer(QObject): return result - def check_registered(self, txhash, block_number, time, data_validation): + def check_registered(self, txhash, block_number, time, nb_validation): """ Check if the transfer was registered in a block. Update the transfer state to VALIDATED if it was registered. @@ -136,6 +138,7 @@ class Transfer(QObject): :param txhash: A transaction ucoinpy object found in the block :param int block_number: The block number checked :param int time: The time of the block + :param int nb_validation: The number of validations needed to become VALIDATED """ if txhash == self.hash: if self.state == Transfer.AWAITING: @@ -143,7 +146,7 @@ class Transfer(QObject): self._metadata['block'] = block_number self._metadata['time'] = time if self.state == Transfer.VALIDATING and \ - self._metadata['block'] - block_number >= data_validation: + self._metadata['block'] - block_number >= nb_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 f3638899d86847a556d8098b834f2b755a00bfb9..98bb117ab9195b90671de12fa14f1d45a2a3da81 100644 --- a/src/cutecoin/core/txhistory.py +++ b/src/cutecoin/core/txhistory.py @@ -100,9 +100,7 @@ class TxHistory(): """ receivers = [o.pubkey for o in tx.outputs if o.pubkey != tx.issuers[0]] - - state = yield from TxHistory._validation_state(community, block_number, current_block) - + nb_validations = community.network.fork_window((yield from community.members_pubkeys())) if len(receivers) == 0: receivers = [tx.issuers[0]] @@ -131,13 +129,13 @@ class TxHistory(): if i == self.wallet.pubkey]) > 0 in_outputs = len([o for o in tx.outputs if o.pubkey == self.wallet.pubkey]) > 0 - awaiting = [t for t in self._transfers + watched = [t for t in self._transfers if t.state in (Transfer.AWAITING, Transfer.VALIDATING)] # We check if the transaction correspond to one we sent # but not from this cutecoin Instance tx_hash = hashlib.sha1(tx.signed_raw().encode("ascii")).hexdigest().upper() - if tx_hash not in [t.hash for t in awaiting]: + if tx_hash not in [t.hash for t in watched]: # If the wallet pubkey is in the issuers we sent this transaction if in_issuers: outputs = [o for o in tx.outputs @@ -147,8 +145,9 @@ class TxHistory(): amount += o.amount metadata['amount'] = amount transfer = Transfer.create_from_blockchain(tx_hash, - state, - metadata.copy()) + metadata.copy(), + current_block['number'], + mediantime, nb_validations) return transfer # If we are not in the issuers, # maybe it we are in the recipients of this transaction @@ -159,18 +158,16 @@ class TxHistory(): for o in outputs: amount += o.amount metadata['amount'] = amount - - if tx_hash not in [t.hash for t in awaiting]: - transfer = Transfer.create_from_blockchain(tx_hash, - state, - metadata.copy()) - received_list.append(transfer) - return transfer + transfer = Transfer.create_from_blockchain(tx_hash, + metadata.copy(), + current_block['number'], + mediantime, nb_validations) + received_list.append(transfer) + return transfer else: - transfer = [t for t in awaiting if t.hash == tx_hash][0] + transfer = [t for t in watched if t.hash == tx_hash][0] - transfer.check_registered(tx_hash, current_block['number'], mediantime, - community.network.fork_window(community.members_pubkeys())) + transfer.check_registered(tx_hash, current_block['number'], mediantime, nb_validations) return None @asyncio.coroutine