check if txi.txo_ref.txo is not None before using it

This commit is contained in:
Lex Berezhny 2018-09-25 22:39:20 -04:00
parent 841d49554c
commit a879c822c2
2 changed files with 6 additions and 4 deletions

View file

@ -6,7 +6,7 @@ from twisted.internet import defer
from twisted.enterprise import adbapi from twisted.enterprise import adbapi
from torba.hash import TXRefImmutable from torba.hash import TXRefImmutable
from torba.basetransaction import TXORefResolvable from torba.basetransaction import BaseTransaction, TXORefResolvable
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -186,7 +186,7 @@ class BaseDatabase(SQLiteMixin):
'script': sqlite3.Binary(txo.script.source) 'script': sqlite3.Binary(txo.script.source)
} }
def save_transaction_io(self, save_tx, tx, is_verified, address, txhash, history): def save_transaction_io(self, save_tx, tx: BaseTransaction, is_verified, address, txhash, history):
def _steps(t): def _steps(t):
if save_tx == 'insert': if save_tx == 'insert':
@ -270,7 +270,7 @@ class BaseDatabase(SQLiteMixin):
return None, None, None, False return None, None, None, False
@defer.inlineCallbacks @defer.inlineCallbacks
def get_transactions(self, account, offset=0, limit=100): def get_transactions(self, account, offset=0, limit=100) -> List[BaseTransaction]:
account_id = account.public_key.address account_id = account.public_key.address
tx_rows = yield self.run_query( tx_rows = yield self.run_query(
""" """

View file

@ -306,7 +306,7 @@ class BaseTransaction:
@property @property
def input_sum(self): def input_sum(self):
return sum(i.amount for i in self.inputs) return sum(i.amount for i in self.inputs if i.txo_ref.txo is not None)
@property @property
def output_sum(self): def output_sum(self):
@ -316,6 +316,8 @@ class BaseTransaction:
def net_account_balance(self) -> int: def net_account_balance(self) -> int:
balance = 0 balance = 0
for txi in self.inputs: for txi in self.inputs:
if txi.txo_ref.txo is None:
continue
if txi.is_my_account is None: if txi.is_my_account is None:
raise ValueError( raise ValueError(
"Cannot access net_account_balance if inputs/outputs do not " "Cannot access net_account_balance if inputs/outputs do not "