From a879c822c20b63e46ea8ba9ae447a17305b5c871 Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Tue, 25 Sep 2018 22:39:20 -0400 Subject: [PATCH] check if txi.txo_ref.txo is not None before using it --- torba/basedatabase.py | 6 +++--- torba/basetransaction.py | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/torba/basedatabase.py b/torba/basedatabase.py index 35cb4b087..3cc0afc04 100644 --- a/torba/basedatabase.py +++ b/torba/basedatabase.py @@ -6,7 +6,7 @@ from twisted.internet import defer from twisted.enterprise import adbapi from torba.hash import TXRefImmutable -from torba.basetransaction import TXORefResolvable +from torba.basetransaction import BaseTransaction, TXORefResolvable log = logging.getLogger(__name__) @@ -186,7 +186,7 @@ class BaseDatabase(SQLiteMixin): '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): if save_tx == 'insert': @@ -270,7 +270,7 @@ class BaseDatabase(SQLiteMixin): return None, None, None, False @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 tx_rows = yield self.run_query( """ diff --git a/torba/basetransaction.py b/torba/basetransaction.py index 9c653b825..d19a855b0 100644 --- a/torba/basetransaction.py +++ b/torba/basetransaction.py @@ -306,7 +306,7 @@ class BaseTransaction: @property 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 def output_sum(self): @@ -316,6 +316,8 @@ class BaseTransaction: def net_account_balance(self) -> int: balance = 0 for txi in self.inputs: + if txi.txo_ref.txo is None: + continue if txi.is_my_account is None: raise ValueError( "Cannot access net_account_balance if inputs/outputs do not "