From 8a74be39de7e0aeaf50fd0d4ade9cdef4c51b711 Mon Sep 17 00:00:00 2001 From: ecdsa Date: Sat, 16 Mar 2013 21:22:03 +0100 Subject: [PATCH 1/4] fix tx.get_value bug with pruned transactions --- lib/bitcoin.py | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/lib/bitcoin.py b/lib/bitcoin.py index 1d297bac0..560b22754 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): From f07591eb5be82c0f7235027532c2972ffa91de22 Mon Sep 17 00:00:00 2001 From: ecdsa Date: Sat, 16 Mar 2013 21:38:10 +0100 Subject: [PATCH 2/4] Revert "fix tx.get_value bug with pruned transactions" This reverts commit 8a74be39de7e0aeaf50fd0d4ade9cdef4c51b711. --- lib/bitcoin.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/bitcoin.py b/lib/bitcoin.py index 560b22754..1d297bac0 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): From f0671a9ada47ba586a34cc174bf3fe30b690bf3a Mon Sep 17 00:00:00 2001 From: ecdsa Date: Sat, 16 Mar 2013 22:04:28 +0100 Subject: [PATCH 3/4] fix tx.get_value() --- lib/bitcoin.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/bitcoin.py b/lib/bitcoin.py index 1d297bac0..6a8c48648 100644 --- a/lib/bitcoin.py +++ b/lib/bitcoin.py @@ -805,6 +805,7 @@ class Transaction: # return the balance for that tx is_send = False is_pruned = False + is_partial = False v_in = v_out = v_out_mine = 0 for item in self.inputs: @@ -818,7 +819,9 @@ class Transaction: else: v_in += value else: - is_pruned = True + is_partial = True + + if not is_send: is_partial = False for item in self.outputs: addr, value = item @@ -826,11 +829,7 @@ 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: + if is_pruned: # some inputs are mine: fee = None if is_send: @@ -838,7 +837,18 @@ class Transaction: else: # no input is mine v = v_out_mine - + + else: + v = v_out_mine - v_in + + if is_partial: + # some inputs are mine, but not all + fee = None + is_send = v < 0 + else: + # all inputs are mine + fee = v_out - v_in + return is_send, v, fee def as_dict(self): From a6ae46631f1a946031b3a57ff66feffb311fc6dc Mon Sep 17 00:00:00 2001 From: Maran Date: Sat, 16 Mar 2013 23:38:49 +0100 Subject: [PATCH 4/4] Fix export master public key --- lib/wallet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/wallet.py b/lib/wallet.py index b39770eec..7935dfe04 100644 --- a/lib/wallet.py +++ b/lib/wallet.py @@ -182,7 +182,7 @@ class Wallet: return s[0] == 1 def get_master_public_key(self): - return self.sequences[0].master_public_key + return self.config.get("master_public_key") def get_address_index(self, address): if address in self.imported_keys.keys():