commit ac7bff3aa0b0ac8913b83cef03db48e9c44f941b
parent 180059355d43217946b7c73c1086417d637fe3c8
Author: thomasv <thomasv@gitorious>
Date: Wed, 22 Feb 2012 15:39:06 +0100
support for remote wallet
Diffstat:
3 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/client/electrum b/client/electrum
@@ -40,12 +40,26 @@ if __name__ == '__main__':
parser.add_option("-f", "--fee", dest="tx_fee", default="0.005", help="set tx fee")
parser.add_option("-s", "--fromaddr", dest="from_addr", default=None, help="set source address for payto/mktx. if it isn't in the wallet, it will ask for the private key unless supplied in the format public_key:private_key. It's not saved in the wallet.")
parser.add_option("-c", "--changeaddr", dest="change_addr", default=None, help="set the change address for payto/mktx. default is a spare address, or the source address if it's not in the wallet")
+ parser.add_option("-r", "--remote", dest="remote_url", default=None, help="URL of a remote wallet")
options, args = parser.parse_args()
interface = Interface()
wallet = Wallet(interface)
wallet.set_path(options.wallet_path)
+ if options.remote_url:
+ m = re.match('^(.*?)@(.*?)$', options.remote_url)
+ # header authentication is not supported
+ if m:
+ wallet.remote_url = 'http://'+m.group(2)
+ wallet.remote_password = m.group(1)
+ else:
+ print "bad url"
+ sys.exit(1)
+ else:
+ wallet.remote_url = None
+
+
if len(args)==0:
url = None
cmd = 'gui'
diff --git a/client/interface.py b/client/interface.py
@@ -150,7 +150,7 @@ class Interface:
wallet.status[addr] = blk_hash
is_new = True
- if is_new:
+ if is_new or wallet.remote_url:
wallet.synchronize()
wallet.update_tx_history()
wallet.save()
diff --git a/client/wallet.py b/client/wallet.py
@@ -262,8 +262,8 @@ class Wallet:
self.tx_history = {}
self.imported_keys = {}
-
self.interface = interface
+ self.remote_url = None
def set_path(self, wallet_path):
@@ -456,6 +456,7 @@ class Wallet:
def synchronize(self):
+
is_new = False
while True:
if self.change_addresses == []:
@@ -481,6 +482,23 @@ class Wallet:
self.create_new_address(False)
is_new = True
+ if self.remote_url:
+ num = self.get_remote_number()
+ print num
+ while len(self.addresses)<num:
+ self.create_new_address(False)
+
+ def get_remote_number(self):
+ import jsonrpclib
+ server = jsonrpclib.Server(self.remote_url)
+ out = server.getnum(self.remote_password)
+ return out
+
+ def get_remote_mpk(self):
+ import jsonrpclib
+ server = jsonrpclib.Server(self.remote_url)
+ out = server.getkey(self.remote_password)
+ return out
def is_found(self):
return (len(self.change_addresses) > 1 ) or ( len(self.addresses) > self.gap_limit )
@@ -556,6 +574,8 @@ class Wallet:
if self.seed_version != SEED_VERSION:
raise BaseException(upgrade_msg)
+ if self.remote_url: assert self.master_public_key.encode('hex') == self.get_remote_mpk()
+
return True
def get_new_address(self):