From f07591eb5be82c0f7235027532c2972ffa91de22 Mon Sep 17 00:00:00 2001 From: ecdsa Date: Sat, 16 Mar 2013 21:38:10 +0100 Subject: [PATCH] Revert "fix tx.get_value bug with pruned transactions" This reverts commit 8a74be39de7e0aeaf50fd0d4ade9cdef4c51b711. --- lib/bitcoin.py | 23 +++++++++++++++-------- 1 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/bitcoin.py b/lib/bitcoin.py index 560b227..1d297ba 100644 --- a/lib/bitcoin.py +++ b/lib/bitcoin.py @@ -805,10 +805,7 @@ class Transaction: # return the balance for that tx is_send = False is_pruned = False - - 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 + v_in = v_out = v_out_mine = 0 for item in self.inputs: addr = item.get('address') @@ -819,7 +816,7 @@ class Transaction: if value is None: is_pruned = True else: - v_in_mine += value + v_in += value else: is_pruned = True @@ -829,9 +826,19 @@ class Transaction: if addr in addresses: v_out_mine += value - v = v_out_mine - v_in_mine - fee = None if is_pruned else v_out - v_in_mine - + 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 + return is_send, v, fee def as_dict(self): -- 1.7.1