store deserialized tx in/out in wallet file for fast computation
This commit is contained in:
@@ -499,9 +499,9 @@ class Plugin(BasePlugin):
|
||||
@hook
|
||||
def load_wallet(self, wallet):
|
||||
tx_list = {}
|
||||
for item in self.wallet.get_tx_history(self.wallet.storage.get("current_account", None)):
|
||||
tx_hash, conf, is_mine, value, fee, balance, timestamp = item
|
||||
tx_list[tx_hash] = {'value': value, 'timestamp': timestamp, 'balance': balance}
|
||||
for item in self.wallet.get_history(self.wallet.storage.get("current_account", None)):
|
||||
tx_hash, conf, value, timestamp = item
|
||||
tx_list[tx_hash] = {'value': value, 'timestamp': timestamp }
|
||||
|
||||
self.tx_list = tx_list
|
||||
self.cur_exchange = self.config.get('use_exchange', "Blockchain")
|
||||
@@ -572,20 +572,21 @@ class Plugin(BasePlugin):
|
||||
except Exception:
|
||||
newtx = self.wallet.get_tx_history()
|
||||
v = newtx[[x[0] for x in newtx].index(str(item.data(0, Qt.UserRole).toPyObject()))][3]
|
||||
tx_info = {'timestamp':int(time.time()), 'value': v }
|
||||
tx_info = {'timestamp':int(time.time()), 'value': v}
|
||||
pass
|
||||
tx_time = int(tx_info['timestamp'])
|
||||
tx_value = Decimal(str(tx_info['value'])) / 100000000
|
||||
if self.cur_exchange == "CoinDesk":
|
||||
tx_time_str = datetime.datetime.fromtimestamp(tx_time).strftime('%Y-%m-%d')
|
||||
try:
|
||||
tx_fiat_val = "%.2f %s" % (Decimal(str(tx_info['value'])) / 100000000 * Decimal(self.resp_hist['bpi'][tx_time_str]), "USD")
|
||||
tx_fiat_val = "%.2f %s" % (value * Decimal(self.resp_hist['bpi'][tx_time_str]), "USD")
|
||||
except KeyError:
|
||||
tx_fiat_val = "%.2f %s" % (self.btc_rate * Decimal(str(tx_info['value']))/100000000 , "USD")
|
||||
elif self.cur_exchange == "Winkdex":
|
||||
tx_time_str = datetime.datetime.fromtimestamp(tx_time).strftime('%Y-%m-%d') + "T16:00:00-04:00"
|
||||
try:
|
||||
tx_rate = self.resp_hist[[x['timestamp'] for x in self.resp_hist].index(tx_time_str)]['price']
|
||||
tx_fiat_val = "%.2f %s" % (Decimal(tx_info['value']) / 100000000 * Decimal(tx_rate)/Decimal("100.0"), "USD")
|
||||
tx_fiat_val = "%.2f %s" % (tx_value * Decimal(tx_rate)/Decimal("100.0"), "USD")
|
||||
except ValueError:
|
||||
tx_fiat_val = "%.2f %s" % (self.btc_rate * Decimal(tx_info['value'])/100000000 , "USD")
|
||||
except KeyError:
|
||||
@@ -594,7 +595,7 @@ class Plugin(BasePlugin):
|
||||
tx_time_str = datetime.datetime.fromtimestamp(tx_time).strftime('%Y-%m-%d')
|
||||
try:
|
||||
num = self.resp_hist[tx_time_str].replace(',','')
|
||||
tx_fiat_val = "%.2f %s" % (Decimal(str(tx_info['value'])) / 100000000 * Decimal(num), self.fiat_unit())
|
||||
tx_fiat_val = "%.2f %s" % (tx_value * Decimal(num), self.fiat_unit())
|
||||
except KeyError:
|
||||
tx_fiat_val = _("No data")
|
||||
|
||||
|
||||
@@ -42,30 +42,28 @@ class Plugin(BasePlugin):
|
||||
@hook
|
||||
def export_history_dialog(self, d,hbox):
|
||||
self.wallet = d.wallet
|
||||
|
||||
history = self.wallet.get_tx_history()
|
||||
|
||||
history = self.wallet.get_history()
|
||||
if len(history) > 0:
|
||||
b = QPushButton(_("Preview plot"))
|
||||
hbox.addWidget(b)
|
||||
b.clicked.connect(lambda: self.do_plot(self.wallet))
|
||||
b.clicked.connect(lambda: self.do_plot(self.wallet, history))
|
||||
else:
|
||||
b = QPushButton(_("No history to plot"))
|
||||
hbox.addWidget(b)
|
||||
|
||||
|
||||
|
||||
def do_plot(self,wallet):
|
||||
history = wallet.get_tx_history()
|
||||
def do_plot(self, wallet, history):
|
||||
balance_Val=[]
|
||||
fee_val=[]
|
||||
value_val=[]
|
||||
datenums=[]
|
||||
unknown_trans=0
|
||||
pending_trans=0
|
||||
counter_trans=0
|
||||
unknown_trans = 0
|
||||
pending_trans = 0
|
||||
counter_trans = 0
|
||||
balance = 0
|
||||
for item in history:
|
||||
tx_hash, confirmations, is_mine, value, fee, balance, timestamp = item
|
||||
tx_hash, confirmations, value, timestamp = item
|
||||
balance += value
|
||||
if confirmations:
|
||||
if timestamp is not None:
|
||||
try:
|
||||
@@ -73,24 +71,15 @@ class Plugin(BasePlugin):
|
||||
balance_string = format_satoshis(balance, False)
|
||||
balance_Val.append(float((format_satoshis(balance,False)))*1000.0)
|
||||
except [RuntimeError, TypeError, NameError] as reason:
|
||||
unknown_trans=unknown_trans+1
|
||||
unknown_trans += 1
|
||||
pass
|
||||
else:
|
||||
unknown_trans=unknown_trans+1
|
||||
unknown_trans += 1
|
||||
else:
|
||||
pending_trans=pending_trans+1
|
||||
pending_trans += 1
|
||||
|
||||
if value is not None:
|
||||
value_string = format_satoshis(value, True)
|
||||
value_val.append(float(value_string)*1000.0)
|
||||
else:
|
||||
value_string = '--'
|
||||
|
||||
if fee is not None:
|
||||
fee_string = format_satoshis(fee, True)
|
||||
fee_val.append(float(fee_string))
|
||||
else:
|
||||
fee_string = '0'
|
||||
value_string = format_satoshis(value, True)
|
||||
value_val.append(float(value_string)*1000.0)
|
||||
|
||||
if tx_hash:
|
||||
label, is_default_label = wallet.get_label(tx_hash)
|
||||
@@ -139,12 +128,9 @@ class Plugin(BasePlugin):
|
||||
|
||||
xfmt = md.DateFormatter('%Y-%m-%d')
|
||||
ax.xaxis.set_major_formatter(xfmt)
|
||||
axarr[1].plot(datenums,fee_val,marker='o',linestyle='-',color='red',label='Fee')
|
||||
axarr[1].plot(datenums,value_val,marker='o',linestyle='-',color='green',label='Value')
|
||||
|
||||
|
||||
|
||||
|
||||
axarr[1].legend(loc='upper left')
|
||||
# plt.annotate('unknown transaction = %d \n pending transactions = %d' %(unknown_trans,pending_trans),xy=(0.7,0.05),xycoords='axes fraction',size=12)
|
||||
plt.show()
|
||||
|
||||
Reference in New Issue
Block a user