kivy: improve blockchain dialog

This commit is contained in:
ThomasV 2017-03-27 21:31:37 +02:00
parent 59b0b51f24
commit 51f8816ec7
3 changed files with 64 additions and 42 deletions

View File

@ -3,45 +3,64 @@ from kivy.factory import Factory
from kivy.properties import ObjectProperty from kivy.properties import ObjectProperty
from kivy.lang import Builder from kivy.lang import Builder
from electrum.i18n import _
Builder.load_string(''' Builder.load_string('''
#:import _ electrum_gui.kivy.i18n._ #:import _ electrum_gui.kivy.i18n._
<CheckpointDialog@Popup> <CheckpointDialog@Popup>
id: popup id: popup
title: _('Blockchain')
size_hint: 1, 1
cp_height: 0 cp_height: 0
cp_value: '' cp_value: ''
title: _('Checkpoint')
size_hint: 0.8, 0.8
pos_hint: {'top':0.9}
BoxLayout: BoxLayout:
orientation: 'vertical' orientation: 'vertical'
Label: padding: '10dp'
id: description spacing: '10dp'
text: 'In the event of a blockchain fork, a checkpoint can be used to ensure that you are on the correct blockchain.' TopLabel:
halign: 'left' height: '48dp'
text_size: self.width, None id: bc_height
size: self.texture_size text: ''
BoxLayout: TopLabel:
height: '48dp'
id: bc_status
text: ''
Widget:
size_hint: 1, 0.1
TopLabel:
text: _("In order to verify the history returned by your main server, Electrum downloads block headers from random nodes. These headers are then used to check that transactions sent by the server really are in the blockchain.")
font_size: '6pt'
Widget:
size_hint: 1, 0.1
GridLayout:
orientation: 'horizontal' orientation: 'horizontal'
size_hint: 1, 0.2 cols: 2
Label: height: '36dp'
text: _('Height') TopLabel:
height: '48dp' text: _('Checkpoint') + ':'
height: '36dp'
TextInput: TextInput:
id: height_input id: height_input
height: '36dp'
size_hint_y: None
text: '%d'%root.cp_height text: '%d'%root.cp_height
input_type: 'number'
on_focus: root.on_height_str() on_focus: root.on_height_str()
TopLabel: TopLabel:
text: _('Block hash') + ':' text: _('Block hash') + ':'
TxHashLabel: TxHashLabel:
data: root.cp_value data: root.cp_value
Widget:
size_hint: 1, 0.1
Label: Label:
text: 'Edit the height to fetch a checkpoint from your main server, and check its value from independent sources.' font_size: '6pt'
text: _('If there is a fork of the blockchain, you need to configure your checkpoint in order to make sure that you are on the correct side of the fork. Enter a block number to fetch a checkpoint from your main server, and check its value from independent sources.')
halign: 'left' halign: 'left'
text_size: self.width, None text_size: self.width, None
size: self.texture_size size: self.texture_size
Widget: Widget:
size_hint: 1, 0.3 size_hint: 1, 0.3
BoxLayout: BoxLayout:
@ -68,6 +87,12 @@ class CheckpointDialog(Factory.Popup):
self.cp_height, self.cp_value = self.network.blockchain.get_checkpoint() self.cp_height, self.cp_value = self.network.blockchain.get_checkpoint()
self.callback = callback self.callback = callback
n_nodes = len(network.get_interfaces())
n_blocks = network.get_local_height()
self.ids.bc_height.text = _("Verified headers: %d blocks.")%n_blocks
self.ids.bc_status.text = _("Connected to %d nodes.")%n_nodes if n_nodes else _("Not connected?")
def on_height_str(self): def on_height_str(self):
try: try:
new_height = int(self.ids.height_input.text) new_height = int(self.ids.height_input.text)

View File

@ -121,10 +121,10 @@ Builder.load_string('''
action: partial(root.coinselect_dialog, self) action: partial(root.coinselect_dialog, self)
CardSeparator CardSeparator
SettingsItem: SettingsItem:
status: root.checkpoint_status() status: root.blockchain_status()
title: _('Checkpoint') + ': ' + self.status title: _('Blockchain') + ': ' + self.status
description: _("Configure blockchain checkpoint") description: _("Configure checkpoints")
action: partial(root.checkpoint_dialog, self) action: partial(root.blockchain_dialog, self)
''') ''')
@ -147,7 +147,7 @@ class SettingsDialog(Factory.Popup):
self._language_dialog = None self._language_dialog = None
self._unit_dialog = None self._unit_dialog = None
self._coinselect_dialog = None self._coinselect_dialog = None
self._checkpoint_dialog = None self._blockchain_dialog = None
def update(self): def update(self):
self.wallet = self.app.wallet self.wallet = self.app.wallet
@ -191,19 +191,19 @@ class SettingsDialog(Factory.Popup):
self._coinselect_dialog = ChoiceDialog(_('Coin selection'), choosers, chooser_name, cb) self._coinselect_dialog = ChoiceDialog(_('Coin selection'), choosers, chooser_name, cb)
self._coinselect_dialog.open() self._coinselect_dialog.open()
def checkpoint_status(self): def blockchain_status(self):
height, value = self.app.network.blockchain.get_checkpoint() height = self.app.network.get_local_height()
return "Block %d"% height if height else _("Genesis block") return "%d blocks"% height
def checkpoint_dialog(self, item, dt): def blockchain_dialog(self, item, dt):
from checkpoint_dialog import CheckpointDialog from checkpoint_dialog import CheckpointDialog
if self._checkpoint_dialog is None: if self._blockchain_dialog is None:
def callback(height, value): def callback(height, value):
if value: if value:
self.app.network.blockchain.set_checkpoint(height, value) self.app.network.blockchain.set_checkpoint(height, value)
item.status = self.checkpoint_status() item.status = self.checkpoint_status()
self._checkpoint_dialog = CheckpointDialog(self.app.network, callback) self._blockchain_dialog = CheckpointDialog(self.app.network, callback)
self._checkpoint_dialog.open() self._blockchain_dialog.open()
def proxy_status(self): def proxy_status(self):
server, port, protocol, proxy, auto_connect = self.app.network.get_parameters() server, port, protocol, proxy, auto_connect = self.app.network.get_parameters()

View File

@ -1,18 +1,20 @@
Popup: Popup:
id: nd id: nd
title: _('Network') title: _('Network')
n_nodes: len(app.network.get_interfaces())
blockchain_height: app.network.get_local_height()
is_connected: app.network.is_connected() is_connected: app.network.is_connected()
server: app.network.interface.host
BoxLayout: BoxLayout:
orientation: 'vertical' orientation: 'vertical'
padding: '10dp' padding: '10dp'
spacing: '10dp' spacing: '10dp'
TopLabel: TopLabel:
s1: _("Connected to %d nodes.")%root.n_nodes if root.n_nodes else _("Not connected?") text: _("Connected to %s.")%root.server if root.is_connected else _("Not connected?")
s2: _("Blockchain length") + ": %d "%root.blockchain_height + _("blocks") Widget:
text: self.s1 + '\n' + self.s2 size_hint: 1, 0.1
TopLabel:
text: _("Electrum retrieves your wallet information from a single server. In addition, it connects to a number of extra nodes, in order to fetch block headers. Block headers are used to verify the information sent by the address server, using Simple Payment Verification (SPV).")
font_size: '6pt'
Widget: Widget:
size_hint: 1, 0.1 size_hint: 1, 0.1
GridLayout: GridLayout:
@ -33,11 +35,6 @@ Popup:
size_hint_y: None size_hint_y: None
Widget: Widget:
size_hint: 1, 0.1 size_hint: 1, 0.1
TopLabel:
text: _("Electrum retrieves your wallet information from a single node (address server). In addition, it connects to a number of extra nodes, in order to fetch block headers. Block headers are used to verify the information sent by the address server, using Simple Payment Verification (SPV).")
font_size: '6pt'
Widget:
size_hint: 1, 0.1
TopLabel: TopLabel:
text: _("If auto-connect is checked, the address server will be selected automatically.") text: _("If auto-connect is checked, the address server will be selected automatically.")
font_size: '6pt' font_size: '6pt'