diff --git a/lib/bitcoin.py b/lib/bitcoin.py index 1d297bac..560b2275 100644 --- a/lib/bitcoin.py +++ b/lib/bitcoin.py @@ -805,7 +805,10 @@ class Transaction: # return the balance for that tx is_send = False is_pruned = False - v_in = v_out = v_out_mine = 0 + + v_in_mine = 0 # sum of transaction inputs coming from my addresses + v_out = 0 # sum of all transaction outputs + v_out_mine = 0 # sum of outputs sent to my addresses for item in self.inputs: addr = item.get('address') @@ -816,7 +819,7 @@ class Transaction: if value is None: is_pruned = True else: - v_in += value + v_in_mine += value else: is_pruned = True @@ -826,19 +829,9 @@ class Transaction: if addr in addresses: v_out_mine += value - if not is_pruned: - # all inputs are mine: - fee = v_out - v_in - v = v_out_mine - v_in - else: - # some inputs are mine: - fee = None - if is_send: - v = v_out_mine - v_out - else: - # no input is mine - v = v_out_mine - + v = v_out_mine - v_in_mine + fee = None if is_pruned else v_out - v_in_mine + return is_send, v, fee def as_dict(self):