electrum

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

commit 26d09b49151b4eb7a6e486c96e47654b59ef3045
parent 0a1542e2496769a114ab9c1370b4ace4c6505a91
Author: ThomasV <thomasv@electrum.org>
Date:   Tue, 20 Feb 2018 10:52:11 +0100

fix timestamp of data in get_historical_rates

Diffstat:
Mlib/exchange_rate.py | 37+++++++++++++++++++------------------
1 file changed, 19 insertions(+), 18 deletions(-)

diff --git a/lib/exchange_rate.py b/lib/exchange_rate.py @@ -68,40 +68,41 @@ class ExchangeBase(PrintError): try: with open(filename, 'r') as f: h = json.loads(f.read()) + h['timestamp'] = timestamp except: h = None else: h = None - timestamp = False if h: self.history[ccy] = h self.on_history() - return h, timestamp + return h def get_historical_rates_safe(self, ccy, cache_dir): - h, timestamp = self.read_historical_rates(ccy, cache_dir) - if h is None or time.time() - timestamp < 24*3600: - try: - self.print_error("requesting fx history for", ccy) - h = self.request_history(ccy) - self.print_error("received fx history for", ccy) - self.on_history() - except BaseException as e: - self.print_error("failed fx history:", e) - return - filename = os.path.join(cache_dir, self.name() + '_' + ccy) - with open(filename, 'w') as f: - f.write(json.dumps(h)) + try: + self.print_error("requesting fx history for", ccy) + h = self.request_history(ccy) + self.print_error("received fx history for", ccy) + except BaseException as e: + self.print_error("failed fx history:", e) + return + filename = os.path.join(cache_dir, self.name() + '_' + ccy) + with open(filename, 'w') as f: + f.write(json.dumps(h)) + h['timestamp'] = time.time() self.history[ccy] = h self.on_history() def get_historical_rates(self, ccy, cache_dir): - result = self.history.get(ccy) - if not result and ccy in self.history_ccys(): + if ccy not in self.history_ccys(): + return + h = self.history.get(ccy) + if h is None: + h = self.read_historical_rates(ccy, cache_dir) + if h is None or h['timestamp'] < time.time() - 24*3600: t = Thread(target=self.get_historical_rates_safe, args=(ccy, cache_dir)) t.setDaemon(True) t.start() - return result def history_ccys(self): return []