Merge pull request #1159 from kyuupichan/master

Clean up block explorer handling.  Add menu item to go to block explorer...
This commit is contained in:
ThomasV 2015-04-27 10:05:18 +02:00
commit f39e213554
3 changed files with 39 additions and 13 deletions

View File

@ -21,7 +21,7 @@ import webbrowser
from util import *
from electrum.i18n import _
from electrum.util import format_satoshis, format_time
from electrum.util import block_explorer_URL, format_satoshis, format_time
from electrum.plugins import run_hook
@ -78,24 +78,18 @@ class HistoryWidget(MyTreeWidget):
def create_menu(self, position):
self.selectedIndexes()
item = self.currentItem()
be = self.config.get('block_explorer', 'Blockchain.info')
if be == 'Blockchain.info':
block_explorer = 'https://blockchain.info/tx/'
elif be == 'Blockr.io':
block_explorer = 'https://blockr.io/tx/info/'
elif be == 'Insight.is':
block_explorer = 'http://live.insight.is/tx/'
elif be == "Blocktrail.com":
block_explorer = 'https://www.blocktrail.com/BTC/tx/'
if not item:
return
tx_hash = str(item.data(0, Qt.UserRole).toString())
if not tx_hash:
return
tx_URL = block_explorer_URL(self.config, 'tx', tx_hash)
if not tx_URL:
return
menu = QMenu()
menu.addAction(_("Copy ID to Clipboard"), lambda: self.parent.app.clipboard().setText(tx_hash))
menu.addAction(_("Details"), lambda: self.parent.show_transaction(self.wallet.transactions.get(tx_hash)))
menu.addAction(_("Edit description"), lambda: self.edit_label(item))
menu.addAction(_("View on block explorer"), lambda: webbrowser.open(block_explorer + tx_hash))
menu.addAction(_("View on block explorer"), lambda: webbrowser.open(tx_URL))
menu.exec_(self.viewport().mapToGlobal(position))

View File

@ -18,6 +18,7 @@
import sys, time, re, threading
from electrum.i18n import _, set_language
from electrum.util import block_explorer, block_explorer_info, block_explorer_URL
from electrum.util import print_error, print_msg
import os.path, json, ast, traceback
import shutil
@ -1406,6 +1407,9 @@ class ElectrumWindow(QMainWindow):
menu.addAction(_("Encrypt/decrypt message"), lambda: self.encrypt_message(addr))
if self.wallet.is_imported(addr):
menu.addAction(_("Remove from wallet"), lambda: self.delete_imported_key(addr))
addr_URL = block_explorer_URL(self.config, 'addr', addr)
if addr_URL:
menu.addAction(_("View on block explorer"), lambda: webbrowser.open(addr_URL))
if any(addr not in self.wallet.frozen_addresses for addr in addrs):
menu.addAction(_("Freeze"), lambda: self.set_addrs_frozen(addrs, True))
@ -2566,11 +2570,11 @@ class ElectrumWindow(QMainWindow):
unit_combo.currentIndexChanged.connect(on_unit)
widgets.append((unit_label, unit_combo, unit_help))
block_explorers = ['Blockchain.info', 'Blockr.io', 'Insight.is', "Blocktrail.com"]
block_explorers = sorted(block_explorer_info.keys())
block_ex_label = QLabel(_('Online Block Explorer') + ':')
block_ex_combo = QComboBox()
block_ex_combo.addItems(block_explorers)
block_ex_combo.setCurrentIndex(block_explorers.index(self.config.get('block_explorer', 'Blockchain.info')))
block_ex_combo.setCurrentIndex(block_explorers.index(block_explorer(self.config)))
block_ex_help = HelpButton(_('Choose which online block explorer to use for functions that open a web browser'))
def on_be(x):
be_result = block_explorers[block_ex_combo.currentIndex()]

View File

@ -188,6 +188,34 @@ def age(from_date, since_date = None, target_tz=None, include_seconds=False):
else:
return "over %d years ago" % (round(distance_in_minutes / 525600))
block_explorer_info = {
'Blockchain.info': ('https://blockchain.info',
{'tx': 'tx', 'addr': 'address'}),
'Blockr.io': ('https://btc.blockr.io',
{'tx': 'tx/info', 'addr': 'address/info'}),
'Insight.is': ('https://insight.bitpay.com',
{'tx': 'tx', 'addr': 'address'}),
'Blocktrail.com': ('https://www.blocktrail.com/BTC',
{'tx': 'tx', 'addr': 'address'}),
'TradeBlock.com': ('https://tradeblock.com/blockchain',
{'tx': 'tx', 'addr': 'address'}),
}
def block_explorer(config):
return config.get('block_explorer', 'Blockchain.info')
def block_explorer_tuple(config):
return block_explorer_info.get(block_explorer(config))
def block_explorer_URL(config, kind, item):
be_tuple = block_explorer_tuple(config)
if not be_tuple:
return
kind_str = be_tuple[1].get(kind)
if not kind_str:
return
url_parts = [be_tuple[0], kind_str, item]
return "/".join(url_parts)
# URL decode
#_ud = re.compile('%([0-9a-hA-H]{2})', re.MULTILINE)