|
|
@ -182,7 +182,7 @@ class Abstract_Wallet(AddressSynchronizer): |
|
|
|
self.invoices = InvoiceStore(self.storage) |
|
|
|
self.contacts = Contacts(self.storage) |
|
|
|
|
|
|
|
self.coin_price_cache = {} |
|
|
|
self._coin_price_cache = {} |
|
|
|
|
|
|
|
def load_and_cleanup(self): |
|
|
|
self.load_keystore() |
|
|
@ -1178,6 +1178,9 @@ class Abstract_Wallet(AddressSynchronizer): |
|
|
|
total_price += self.coin_price(ser.split(':')[0], price_func, ccy, v) |
|
|
|
return total_price / (input_value/Decimal(COIN)) |
|
|
|
|
|
|
|
def clear_coin_price_cache(self): |
|
|
|
self._coin_price_cache = {} |
|
|
|
|
|
|
|
def coin_price(self, txid, price_func, ccy, txin_value): |
|
|
|
""" |
|
|
|
Acquisition price of a coin. |
|
|
@ -1185,17 +1188,13 @@ class Abstract_Wallet(AddressSynchronizer): |
|
|
|
""" |
|
|
|
if txin_value is None: |
|
|
|
return Decimal('NaN') |
|
|
|
# FIXME: this mutual recursion will be really slow and might even reach |
|
|
|
# max recursion depth if there are no FX rates available as then |
|
|
|
# nothing will be cached. |
|
|
|
cache_key = "{}:{}:{}".format(str(txid), str(ccy), str(txin_value)) |
|
|
|
result = self.coin_price_cache.get(cache_key, None) |
|
|
|
result = self._coin_price_cache.get(cache_key, None) |
|
|
|
if result is not None: |
|
|
|
return result |
|
|
|
if self.txi.get(txid, {}) != {}: |
|
|
|
result = self.average_price(txid, price_func, ccy) * txin_value/Decimal(COIN) |
|
|
|
if not result.is_nan(): |
|
|
|
self.coin_price_cache[cache_key] = result |
|
|
|
self._coin_price_cache[cache_key] = result |
|
|
|
return result |
|
|
|
else: |
|
|
|
fiat_value = self.get_fiat_value(txid, ccy) |
|
|
|