electrum

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

commit d41785c7838b019dbab47ad7bf4f7d87086f549d
parent 832369d7c444270bbd562798a438e6c460c1c85c
Author: ThomasV <thomasv@gitorious>
Date:   Tue,  2 Jun 2015 09:18:39 +0200

save payment requests in requests_dir

Diffstat:
Mgui/qt/main_window.py | 5+++--
Mlib/commands.py | 10++++------
Mlib/wallet.py | 51++++++++++++++++++++++++++++++++++-----------------
3 files changed, 41 insertions(+), 25 deletions(-)

diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py @@ -714,13 +714,14 @@ class ElectrumWindow(QMainWindow): return i = self.expires_combo.currentIndex() expiration = map(lambda x: x[1], expiration_values)[i] - self.wallet.save_payment_request(addr, amount, message, expiration) + self.wallet.save_payment_request(self.config, addr, amount, message, expiration) self.update_receive_tab() self.update_address_tab() self.save_request_button.setEnabled(False) def export_payment_request(self, addr): - pr = self.wallet.make_bip70_request(self.config, addr) + r = self.wallet.get_payment_request(addr) + pr = self.wallet.make_bip70_request(self.config, r) name = 'request.bip70' fileName = self.getSaveFileName(_("Select where to save your payment request"), name, "*.bip70") if fileName: diff --git a/lib/commands.py b/lib/commands.py @@ -522,13 +522,10 @@ class Commands: @command('w') def addrequest(self, amount, reason='', expiration=60*60): - """Create a payment request""" - addr = self.wallet.get_unused_address(None) - if addr is None: - return False + """Create a payment request. """ amount = int(Decimal(amount)*COIN) - self.wallet.save_payment_request(addr, amount, reason, expiration) - return addr + key = self.wallet.add_payment_request(self.config, amount, reason, expiration) + return self.wallet.get_payment_request(key) if key else False @command('w') def removerequest(self, address): @@ -577,6 +574,7 @@ command_options = { 'account': (None, "--account", "Account"), 'reason': (None, "--reason", "Description of the request"), 'expiration': (None, "--expiration", "Time in seconds"), + 'request_dir': (None, "--request_dir", "Directory where request are written"), } diff --git a/lib/wallet.py b/lib/wallet.py @@ -1231,25 +1231,10 @@ class Abstract_Wallet(object): if not self.history.get(addr) and addr not in self.receive_requests.keys(): return addr - def remove_payment_request(self, addr): - if addr not in self.receive_requests: - return False - self.receive_requests.pop(addr) - self.storage.put('receive_requests2', self.receive_requests) - return True - def save_payment_request(self, addr, amount, message, expiration): - self.set_label(addr, message) - if addr in self.receive_requests: - self.receive_requests[addr]['amount'] = amount - else: - now = int(time.time()) - self.receive_requests[addr] = {'time':now, 'amount':amount, 'expiration':expiration} - self.storage.put('receive_requests2', self.receive_requests, True) - - def make_bip70_request(self, config, addr): + def make_bip70_request(self, config, req): from paymentrequest import make_payment_request - req = self.receive_requests[addr] + addr = req['address'] time = req['time'] amount = req['amount'] expiration = req['expiration'] @@ -1260,6 +1245,38 @@ class Abstract_Wallet(object): cert_path = config.get('ssl_cert_path') return make_payment_request(outputs, message, time, time + expiration, key_path, cert_path) + def get_payment_request(self, key): + return self.receive_requests.get(key) + + def save_payment_request(self, config, addr, amount, message, expiration): + #if addr in self.receive_requests: + # self.receive_requests[addr]['amount'] = amount + self.set_label(addr, message) + now = int(time.time()) + r = {'time':now, 'amount':amount, 'expiration':expiration, 'address':addr} + if config.get('requests_dir'): + pr = self.make_bip70_request(config, r) + path = os.path.join(config.get('www_dir'), addr + '.bip70') + with open(path, 'w') as f: + f.write(pr) + r['url'] = 'bitcoin:?r=file://' + path + self.receive_requests[addr] = r + self.storage.put('receive_requests2', self.receive_requests) + + def add_payment_request(self, config, amount, message, expiration): + addr = self.get_unused_address(None) + if addr is None: + return False + self.save_payment_request(config, addr, amount, message, expiration) + return addr + + def remove_payment_request(self, addr): + if addr not in self.receive_requests: + return False + self.receive_requests.pop(addr) + self.storage.put('receive_requests2', self.receive_requests) + return True + class Imported_Wallet(Abstract_Wallet): wallet_type = 'imported'