From c51cf776ae468af4ae4745be7af4b144bee5e93f Mon Sep 17 00:00:00 2001 From: thomasv Date: Fri, 23 Nov 2012 10:16:04 +0100 Subject: [PATCH 1/5] fix prioritization --- lib/wallet.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/wallet.py b/lib/wallet.py index e09e428dc..25888aa1a 100644 --- a/lib/wallet.py +++ b/lib/wallet.py @@ -554,6 +554,7 @@ class Wallet: h = self.history.get(addr, []) if h == ['*']: continue for tx_hash, tx_height in h: + tx = self.transactions.get(tx_hash) for output in tx.get('outputs'): if output.get('address') != addr: continue key = tx_hash + ":%d" % output.get('index') From 6e0a62fada43213f7556084ea71fab3aa1cc4c71 Mon Sep 17 00:00:00 2001 From: thomasv Date: Fri, 23 Nov 2012 14:31:25 +0100 Subject: [PATCH 2/5] return parser object because it is needed to display help --- electrum | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/electrum b/electrum index 216e94d96..463774e16 100755 --- a/electrum +++ b/electrum @@ -121,7 +121,7 @@ def prompt_password(prompt, confirm=True): password = None return password -def parse_args(): +def arg_parser(): usage = "usage: %prog [options] command\nCommands: "+ (', '.join(known_commands)) parser = optparse.OptionParser(prog=usage) parser.add_option("-g", "--gui", dest="gui", help="User interface: qt, lite, gtk or text") @@ -136,12 +136,13 @@ def parse_args(): parser.add_option("-s", "--server", dest="server", default=None, help="set server host:port:protocol, where protocol is t or h") parser.add_option("-p", "--proxy", dest="proxy", default=None, help="set proxy [type:]host[:port], where type is socks4,socks5 or http") parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="show debugging information") - return parser.parse_args() + return parser if __name__ == '__main__': - options, args = parse_args() + parser = arg_parser() + options, args = parser.parse_args() set_verbosity(options.verbose) # config is an object passed to the various constructors (wallet, interface, gui) From 5ae15d610031044dd96ad447f37e518b625443a4 Mon Sep 17 00:00:00 2001 From: thomasv Date: Fri, 23 Nov 2012 15:35:54 +0100 Subject: [PATCH 3/5] handle case where an unconfirmed transaction is pruned by the server. also, fix bug with fee sign in details --- lib/wallet.py | 82 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 62 insertions(+), 20 deletions(-) diff --git a/lib/wallet.py b/lib/wallet.py index 25888aa1a..29f9bc183 100644 --- a/lib/wallet.py +++ b/lib/wallet.py @@ -414,7 +414,11 @@ class Wallet: else: # some inputs are mine: fee = None - v = v_out_mine - v_in + if is_send: + v = v_out_mine - v_out + else: + # no input is mine + v = v_out_mine return is_send, v, fee @@ -438,7 +442,7 @@ class Wallet: + "Status: %d confirmations\n"%conf if is_mine: if fee: - tx_details += "Amount sent: %s\n"% format_satoshis(v+fee, False) \ + tx_details += "Amount sent: %s\n"% format_satoshis(v-fee, False) \ + "Transaction fee: %s\n"% format_satoshis(fee, False) else: tx_details += "Amount sent: %s\n"% format_satoshis(v, False) \ @@ -655,9 +659,8 @@ class Wallet: def receive_history_callback(self, addr, hist): - if hist != ['*']: - if not self.check_new_history(addr, hist): - raise BaseException("error: received history for %s is not consistent with known transactions"%addr) + if not self.check_new_history(addr, hist): + raise BaseException("error: received history for %s is not consistent with known transactions"%addr) with self.lock: self.history[addr] = hist @@ -697,12 +700,9 @@ class Wallet: tx_hash = tx['tx_hash'] timestamp = tx.get('timestamp') conf = self.verifier.get_confirmations(tx_hash) if self.verifier else None - is_mine, v, fee = self.get_tx_value(tx_hash) - if v is not None: - balance += v - value = v + fee if fee is not None else v - else: - value = None + is_mine, value, fee = self.get_tx_value(tx_hash) + if value is not None: + balance += value result.append( (tx_hash, conf, is_mine, value, fee, balance, timestamp) ) @@ -1069,15 +1069,57 @@ class Wallet: def check_new_history(self, addr, hist): - # - check that all tx in hist are relevant - for tx_hash, height in hist: - tx = self.transactions.get(tx_hash) - if not tx: continue - if not self.is_addr_in_tx(addr,tx): - return False - - # todo: check that we are not "orphaning" a transaction - # if we are, reject tx if unconfirmed, else reject the server + + # check that all tx in hist are relevant + if hist != ['*']: + for tx_hash, height in hist: + tx = self.transactions.get(tx_hash) + if not tx: continue + if not self.is_addr_in_tx(addr,tx): + return False + + # check that we are not "orphaning" a transaction + old_hist = self.history.get(addr) + if old_hist == ['*']: return True + + for tx_hash, height in old_hist: + if tx_hash in map(lambda x:x[0], hist): continue + found = False + for _addr, _hist in self.history.items(): + if _addr == addr: continue + if _hist == ['*']: continue + _tx_hist = map(lambda x:x[0], _hist) + if tx_hash in _tx_hist: + found = True + break + + if not found: + tx = self.transactions.get(tx_hash) + # already verified? + if tx.get('height'): + continue + # unconfirmed tx + print_error("new history is orphaning transaction:", tx_hash) + # check that all outputs are not mine, request histories + ext_requests = [] + for o in tx.get('outputs'): + _addr = o.get('address') + assert not self.is_mine(_addr) + ext_requests.append( ('blockchain.address.get_history', [_addr]) ) + + ext_h = self.interface.synchronous_get(ext_requests) + height = None + for h in ext_h: + if h == ['*']: continue + for item in h: + if item.get('tx_hash') == tx_hash: + height = item.get('height') + if height: + print_error("found height for", tx_hash, height) + self.verifier.add(tx_hash, height) + else: + print_error("removing orphaned tx from history", tx_hash) + self.transactions.pop(tx_hash) return True From 47a3739865c7ab7f6e8be740ac6bbdb307931e24 Mon Sep 17 00:00:00 2001 From: thomasv Date: Fri, 23 Nov 2012 16:11:52 +0100 Subject: [PATCH 4/5] save height of transaction --- lib/wallet.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/wallet.py b/lib/wallet.py index 29f9bc183..308c49276 100644 --- a/lib/wallet.py +++ b/lib/wallet.py @@ -1114,6 +1114,7 @@ class Wallet: for item in h: if item.get('tx_hash') == tx_hash: height = item.get('height') + tx['height'] = height if height: print_error("found height for", tx_hash, height) self.verifier.add(tx_hash, height) From 2f045315658a8ab7713b215b3c0aa79c3bc441bb Mon Sep 17 00:00:00 2001 From: thomasv Date: Fri, 23 Nov 2012 17:11:32 +0100 Subject: [PATCH 5/5] fix --- lib/wallet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/wallet.py b/lib/wallet.py index 308c49276..4fe3a86df 100644 --- a/lib/wallet.py +++ b/lib/wallet.py @@ -1079,7 +1079,7 @@ class Wallet: return False # check that we are not "orphaning" a transaction - old_hist = self.history.get(addr) + old_hist = self.history.get(addr,[]) if old_hist == ['*']: return True for tx_hash, height in old_hist: