electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 8757adac40d91ec4d3e8031a63de53bc782bb4e9
parent a41d3d6a8256656fc41f4466fddb4de3aa5a4a69
Author: thomasv <thomasv@gitorious>
Date:   Fri, 10 Feb 2012 13:23:39 +0100

rewrite from_addr, allow to select addr from wallet

Diffstat:
Mclient/electrum | 47+++++++++++++++++++++++++----------------------
Mclient/wallet.py | 9+++++----
2 files changed, 30 insertions(+), 26 deletions(-)

diff --git a/client/electrum b/client/electrum @@ -191,7 +191,7 @@ if __name__ == '__main__': print "payto <recipient> <amount> [label]" print "create and broadcast a transaction." print "<recipient> can be a bitcoin address or a label" - print "options: --fromaddr, --changeaddr" + print "options: --fee, --fromaddr, --changeaddr" elif cmd2== 'sendtx': print "sendtx <tx>" print "broadcast a transaction to the network. <tx> must be in hexadecimal" @@ -210,7 +210,7 @@ if __name__ == '__main__': elif cmd2 == 'mktx': print "create a signed transaction. password protected" print "syntax: mktx <recipient> <amount> [label]" - print "options: --fromaddr, --changeaddr" + print "options: --fee, --fromaddr, --changeaddr" elif cmd2 == 'seed': print "show generation seed of your wallet. password protected." elif cmd2 == 'eval': @@ -303,27 +303,25 @@ if __name__ == '__main__': wallet.save() elif cmd in ['payto', 'mktx']: + is_temporary = False if options.from_addr: - #temporally import key and remove the other addresses - addr = options.from_addr - if addr.find(":") == -1: - addr = addr + ":" + getpass.getpass('Private key:') - wallet.imported_keys = {} - if not wallet.import_key(options.from_addr,password): - print "invalid key pair" - exit(1) - addr = wallet.imported_keys.keys()[0] - wallet.history[addr] = interface.retrieve_history(addr) - wallet.synchronize() - wallet.update_tx_history() - wallet.addresses = [] - wallet.change_addresses = [] - change_addr = addr - save = False + from_addr = options.from_addr + if from_addr not in wallet.all_addresses(): + if from_addr.find(":") == -1: + keypair = from_addr + ":" + getpass.getpass('Private key:') + else: + keypair = from_addr + from_addr = keypair.split(':')[0] + if not wallet.import_key(keypair,password): + print "invalid key pair" + exit(1) + is_temporary = True else: - save = True + from_addr = None + if options.change_addr: change_addr = options.change_addr + for k, v in wallet.labels.items(): if v == to_address: to_address = k @@ -333,9 +331,10 @@ if __name__ == '__main__': change_addr = k try: tx = wallet.mktx( to_address, amount, label, password, - fee = options.tx_fee, change_addr = change_addr, save = save ) - except BaseException, e: - print e + fee = options.tx_fee, change_addr = change_addr, from_addr = from_addr ) + except: + import traceback + traceback.print_exc(file=sys.stdout) tx = None if tx and cmd=='payto': @@ -344,6 +343,10 @@ if __name__ == '__main__': else: print tx + if is_temporary: + wallet.imported_keys.pop(from_addr) + wallet.save() + elif cmd == 'sendtx': tx = args[1] r, h = wallet.sendtx( tx ) diff --git a/client/wallet.py b/client/wallet.py @@ -574,13 +574,14 @@ class Wallet: return conf, unconf - def choose_tx_inputs( self, amount, fixed_fee ): + def choose_tx_inputs( self, amount, fixed_fee, from_addr = None ): """ todo: minimize tx size """ total = 0 fee = self.fee if fixed_fee is None else fixed_fee coins = [] - for addr in self.all_addresses(): + domain = [from_addr] if from_addr else self.all_addresses() + for addr in domain: h = self.history.get(addr) if h is None: continue for item in h: @@ -687,10 +688,10 @@ class Wallet: default_label = 'at: ' + o_addr tx['default_label'] = default_label - def mktx(self, to_address, amount, label, password, fee=None, change_addr=None, save=True): + def mktx(self, to_address, amount, label, password, fee=None, change_addr=None, from_addr= None): if not self.is_valid(to_address): raise BaseException("Invalid address") - inputs, total, fee = self.choose_tx_inputs( amount, fee ) + inputs, total, fee = self.choose_tx_inputs( amount, fee, from_addr ) if not inputs: raise BaseException("Not enough funds") outputs = self.choose_tx_outputs( to_address, amount, fee, total, change_addr )