diff --git a/pybtc/blockchain.py b/pybtc/blockchain.py index 77aded1..c7bc491 100644 --- a/pybtc/blockchain.py +++ b/pybtc/blockchain.py @@ -600,19 +600,20 @@ class Block(): self.target = None self.fee = 0 self.witness_root_hash = None - if txs[0].coinbase: - if version > 1: - self.height = int.from_bytes(txs[0].tx_in[0].sig_script.raw[1:5], "little") - self.coinbase = txs[0].tx_in[0].sig_script.raw[5:] - else: - self.coinbase = txs[0].tx_in[0].sig_script.raw - try: - for out in txs[0].tx_out: - if out.pk_script.ntype == 3: - if b'\xaa!\xa9\xed' == out.pk_script.data[:4]: - self.witness_root_hash = out.pk_script.data[4:36] - except: - pass + if txs: + if txs[0].coinbase: + if version > 1: + self.height = int.from_bytes(txs[0].tx_in[0].sig_script.raw[1:5], "little") + self.coinbase = txs[0].tx_in[0].sig_script.raw[5:] + else: + self.coinbase = txs[0].tx_in[0].sig_script.raw + try: + for out in txs[0].tx_out: + if out.pk_script.ntype == 3: + if b'\xaa!\xa9\xed' == out.pk_script.data[:4]: + self.witness_root_hash = out.pk_script.data[4:36] + except: + pass def calculate_commitment(self, witness = None): wtxid_list = [b"\x00" * 32,] diff --git a/pybtc/tools.py b/pybtc/tools.py index 6b66ad0..ebb2fc0 100644 --- a/pybtc/tools.py +++ b/pybtc/tools.py @@ -439,7 +439,8 @@ def merkle_branches(tx_hash_list): if len(new_hash_list) > 1: tx_hash_list = new_hash_list else: - branches.append(new_hash_list.pop(0)) + if new_hash_list: + branches.append(new_hash_list.pop(0)) return branches