From eb44ef327d345d3c499db4c9bcd6e1bb5f07760e Mon Sep 17 00:00:00 2001 From: Harm Aarts Date: Fri, 1 Jun 2018 10:53:06 +0200 Subject: [PATCH] Reduce indentation level This makes the method easier to read. Skip negative tx heights too. A transaction height can be negative too, see the wallet modules TX_HEIGHT_LOCAL and TX_HEIGHT_UNCONF_PARENT constants. --- lib/verifier.py | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/lib/verifier.py b/lib/verifier.py index 1f94016ed..e70bcf987 100644 --- a/lib/verifier.py +++ b/lib/verifier.py @@ -42,29 +42,31 @@ class SPV(ThreadJob): interface = self.network.interface if not interface: return + blockchain = interface.blockchain if not blockchain: return - lh = self.network.get_local_height() + + local_height = self.network.get_local_height() unverified = self.wallet.get_unverified_txs() for tx_hash, tx_height in unverified.items(): # do not request merkle branch before headers are available - if (tx_height > 0) and (tx_height <= lh): - header = blockchain.read_header(tx_height) - if header is None: - index = tx_height // 2016 - if index < len(blockchain.checkpoints): - self.network.request_chunk(interface, index) - else: - if (tx_hash not in self.requested_merkle - and tx_hash not in self.merkle_roots): + if tx_height <= 0 or tx_height > local_height: + continue - self.network.get_merkle_for_transaction( - tx_hash, - tx_height, - self.verify_merkle) - self.print_error('requested merkle', tx_hash) - self.requested_merkle.add(tx_hash) + header = blockchain.read_header(tx_height) + if header is None: + index = tx_height // 2016 + if index < len(blockchain.checkpoints): + self.network.request_chunk(interface, index) + elif (tx_hash not in self.requested_merkle + and tx_hash not in self.merkle_roots): + self.network.get_merkle_for_transaction( + tx_hash, + tx_height, + self.verify_merkle) + self.print_error('requested merkle', tx_hash) + self.requested_merkle.add(tx_hash) if self.network.blockchain() != self.blockchain: self.blockchain = self.network.blockchain()