check txo.has_address before calling txo.get_address()

This commit is contained in:
Lex Berezhny 2019-10-29 10:21:10 -04:00
parent 28ea43c89e
commit 8e5d47061f
2 changed files with 5 additions and 1 deletions

View file

@ -398,7 +398,7 @@ class BaseDatabase(SQLiteMixin):
for txi in tx.inputs:
if txi.txo_ref.txo is not None:
txo = txi.txo_ref.txo
if txo.get_address(self.ledger) == address:
if txo.has_address and txo.get_address(self.ledger) == address:
conn.execute(*self._insert_sql("txi", {
'txid': tx.id,
'txoid': txo.id,

View file

@ -226,6 +226,10 @@ class BaseOutput(InputOutput):
def pubkey_hash(self):
return self.script.values['pubkey_hash']
@property
def has_address(self):
return 'pubkey_hash' in self.script.values
def get_address(self, ledger):
return ledger.hash160_to_address(self.pubkey_hash)