Browse Source

kivy: improve blockchain dialog

2.9.x
ThomasV 8 years ago
parent
commit
51f8816ec7
  1. 65
      gui/kivy/uix/dialogs/checkpoint_dialog.py
  2. 24
      gui/kivy/uix/dialogs/settings.py
  3. 17
      gui/kivy/uix/ui_screens/network.kv

65
gui/kivy/uix/dialogs/checkpoint_dialog.py

@ -3,45 +3,64 @@ from kivy.factory import Factory
from kivy.properties import ObjectProperty
from kivy.lang import Builder
from electrum.i18n import _
Builder.load_string('''
#:import _ electrum_gui.kivy.i18n._
<CheckpointDialog@Popup>
id: popup
title: _('Blockchain')
size_hint: 1, 1
cp_height: 0
cp_value: ''
title: _('Checkpoint')
size_hint: 0.8, 0.8
pos_hint: {'top':0.9}
BoxLayout:
orientation: 'vertical'
Label:
id: description
text: 'In the event of a blockchain fork, a checkpoint can be used to ensure that you are on the correct blockchain.'
halign: 'left'
text_size: self.width, None
size: self.texture_size
BoxLayout:
padding: '10dp'
spacing: '10dp'
TopLabel:
height: '48dp'
id: bc_height
text: ''
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'
size_hint: 1, 0.2
Label:
text: _('Height')
height: '48dp'
cols: 2
height: '36dp'
TopLabel:
text: _('Checkpoint') + ':'
height: '36dp'
TextInput:
id: height_input
height: '36dp'
size_hint_y: None
text: '%d'%root.cp_height
input_type: 'number'
on_focus: root.on_height_str()
TopLabel:
text: _('Block hash') + ':'
TxHashLabel:
data: root.cp_value
TopLabel:
text: _('Block hash') + ':'
TxHashLabel:
data: root.cp_value
Widget:
size_hint: 1, 0.1
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'
text_size: self.width, None
size: self.texture_size
Widget:
size_hint: 1, 0.3
BoxLayout:
@ -68,6 +87,12 @@ class CheckpointDialog(Factory.Popup):
self.cp_height, self.cp_value = self.network.blockchain.get_checkpoint()
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):
try:
new_height = int(self.ids.height_input.text)

24
gui/kivy/uix/dialogs/settings.py

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

17
gui/kivy/uix/ui_screens/network.kv

@ -1,18 +1,20 @@
Popup:
id: nd
title: _('Network')
n_nodes: len(app.network.get_interfaces())
blockchain_height: app.network.get_local_height()
is_connected: app.network.is_connected()
server: app.network.interface.host
BoxLayout:
orientation: 'vertical'
padding: '10dp'
spacing: '10dp'
TopLabel:
s1: _("Connected to %d nodes.")%root.n_nodes if root.n_nodes else _("Not connected?")
s2: _("Blockchain length") + ": %d "%root.blockchain_height + _("blocks")
text: self.s1 + '\n' + self.s2
text: _("Connected to %s.")%root.server if root.is_connected else _("Not connected?")
Widget:
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:
size_hint: 1, 0.1
GridLayout:
@ -33,11 +35,6 @@ Popup:
size_hint_y: None
Widget:
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:
text: _("If auto-connect is checked, the address server will be selected automatically.")
font_size: '6pt'

Loading…
Cancel
Save