Example #1
0
    def add_io(self, vbox):
        if self.tx.locktime > 0:
            vbox.addWidget(QLabel("LockTime: %d\n" % self.tx.locktime))

        vbox.addWidget(QLabel(_("Inputs") + ' (%d)'%len(self.tx.inputs())))
        ext = QTextCharFormat()
        rec = QTextCharFormat()
        rec.setBackground(QBrush(QColor("lightgreen")))
        rec.setToolTip(_("Wallet receive address"))
        chg = QTextCharFormat()
        chg.setBackground(QBrush(QColor("yellow")))
        chg.setToolTip(_("Wallet change address"))

        def text_format(addr):
            if self.wallet.is_mine(addr):
                return chg if self.wallet.is_change(addr) else rec
            return ext

        def format_amount(amt):
            return self.main_window.format_amount(amt, whitespaces = True)

        i_text = QTextEdit()
        i_text.setFont(QFont(MONOSPACE_FONT))
        i_text.setReadOnly(True)
        i_text.setMaximumHeight(100)
        cursor = i_text.textCursor()
        for x in self.tx.inputs():
            if x['type'] == 'coinbase':
                cursor.insertText('coinbase')
            else:
                prevout_hash = x.get('prevout_hash')
                prevout_n = x.get('prevout_n')
                cursor.insertText(prevout_hash[0:8] + '...', ext)
                cursor.insertText(prevout_hash[-8:] + ":%-4d " % prevout_n, ext)
                addr = x.get('address')
                if addr == "(pubkey)":
                    _addr = self.wallet.find_pay_to_pubkey_address(prevout_hash, prevout_n)
                    if _addr:
                        addr = _addr
                if addr is None:
                    addr = _('unknown')
                cursor.insertText(addr, text_format(addr))
                if x.get('value'):
                    cursor.insertText(format_amount(x['value']), ext)
            cursor.insertBlock()

        vbox.addWidget(i_text)
        vbox.addWidget(QLabel(_("Outputs") + ' (%d)'%len(self.tx.outputs())))
        o_text = QTextEdit()
        o_text.setFont(QFont(MONOSPACE_FONT))
        o_text.setReadOnly(True)
        o_text.setMaximumHeight(100)
        cursor = o_text.textCursor()
        for addr, v in self.tx.get_outputs():
            cursor.insertText(addr, text_format(addr))
            if v is not None:
                cursor.insertText('\t', ext)
                cursor.insertText(format_amount(v), ext)
            cursor.insertBlock()
        vbox.addWidget(o_text)
Example #2
0
 def task():
     wallet.wait_until_synchronized()
     if wallet.is_found():
         msg = _("Recovery successful")
     else:
         msg = _("No transactions found for this seed")
     self.emit(QtCore.SIGNAL('synchronized'), msg)
Example #3
0
    def create_proposal(self):
        manager = self.parent.masternode_manager

        try:
            proposal = self.create_proposal_from_widgets()
        except Exception as e:
            return QMessageBox.critical(self, _('Error'), _(str(e)))

        pw = None
        if manager.wallet.use_encryption:
            pw = self.parent.password_dialog(msg=_(
                'Please enter your password to create a budget proposal.'))
            if pw is None:
                return

        manager.add_proposal(proposal)

        def sign_done(proposal, tx):
            print_error('proposal tx sign done: %s' % proposal.proposal_name)
            if tx:
                label = _('Budget Proposal Tx: ') + proposal.proposal_name
                self.parent.broadcast_transaction(tx, label)
                self.parent.masternode_manager.save()

        self.create_proposal_tx(proposal, pw, sign_done)
    def sign_announce(self, alias):
        """Sign an announce for alias. This is called by SignAnnounceWidget."""
        pw = None
        if self.manager.wallet.use_encryption:
            pw = self.gui.password_dialog(msg=_(
                'Please enter your password to activate masternode "%s".' %
                alias))
            if pw is None:
                return

        self.sign_announce_widget.sign_button.setEnabled(False)

        def sign_thread():
            return self.manager.sign_announce(alias, pw)

        def on_sign_successful(mn):
            self.print_msg('Successfully signed Masternode Announce.')
            self.send_announce(alias)

        # Proceed to broadcasting the announcement, or re-enable the button.
        def on_sign_error(err):
            self.print_error('Error signing MasternodeAnnounce:')
            # Print traceback information to error log.
            self.print_error(''.join(traceback.format_tb(err[2])))
            self.print_error(''.join(
                traceback.format_exception_only(err[0], err[1])))
            self.sign_announce_widget.sign_button.setEnabled(True)

        util.WaitingDialog(self, _('Signing Masternode Announce...'),
                           sign_thread, on_sign_successful, on_sign_error)
    def save_current_masternode(self, as_new=False):
        """Save the masternode that is being viewed.

        If as_new is True, a new masternode will be created.
        """
        delegate_privkey = str(self.masternode_editor.delegate_key_edit.text())
        try:
            self.manager.import_masternode_delegate(delegate_privkey)
            delegate_pubkey = bitcoin.public_key_from_private_key(
                delegate_privkey)
        except Exception:
            # Show an error if the private key is invalid and not an empty string.
            if delegate_privkey:
                QMessageBox.warning(
                    self, _('Warning'),
                    _('Ignoring invalid delegate private key.'))
            delegate_pubkey = ''

        alias = str(self.masternode_editor.alias_edit.text())
        # Construct a new masternode.
        if as_new:
            kwargs = self.masternode_editor.get_masternode_args()
            kwargs['delegate_key'] = delegate_pubkey
            del kwargs['vin']
            self.mapper.revert()
            self.masternodes_widget.add_masternode(
                MasternodeAnnounce(**kwargs))
        else:
            self.mapper.submit()
        self.manager.save()
        self.masternodes_widget.select_masternode(alias)
Example #6
0
 def toggle_passphrase(self):
     if self.features.passphrase_protection:
         self.msg = _("Confirm on your %s device to disable passphrases")
     else:
         self.msg = _("Confirm on your %s device to enable passphrases")
     enabled = not self.features.passphrase_protection
     self.apply_settings(use_passphrase=enabled)
    def create_layout(self):
        self.masternodes_widget = MasternodesWidget(self.manager)

        self.tabs = QTabWidget()
        self.tabs.addTab(self.create_view_masternode_tab(),
                         _('View Masternode'))
        self.tabs.addTab(self.create_collateral_tab(), _('Choose Collateral'))
        self.tabs.addTab(self.create_sign_announce_tab(),
                         _('Activate Masternode'))
        self.tabs.addTab(self.create_masternode_conf_tab(),
                         _('Masternode.conf'))
        # Disabled until API is stable.
        #        self.tabs.addTab(self.create_vote_tab(), _('Vote'))

        # Connect to the selection signal so we can update the widget mapper.
        self.masternodes_widget.view.selectionModel().selectionChanged.connect(
            self.on_view_selection_changed)

        bottom_buttons = util.Buttons(util.CloseButton(self))

        vbox = QVBoxLayout()
        vbox.addWidget(QLabel(_('Masternodes:')))
        vbox.addWidget(self.masternodes_widget, stretch=1)
        vbox.addWidget(self.tabs)
        vbox.addLayout(bottom_buttons)
        self.setLayout(vbox)
Example #8
0
    def __init__(self, parent):
        super(CharacterDialog, self).__init__(parent)
        self.setWindowTitle(_("KeepKey Seed Recovery"))
        self.character_pos = 0
        self.word_pos = 0
        self.loop = QEventLoop()
        self.word_help = QLabel()
        self.char_buttons = []

        vbox = QVBoxLayout(self)
        vbox.addWidget(WWLabel(CHARACTER_RECOVERY))
        hbox = QHBoxLayout()
        hbox.addWidget(self.word_help)
        for i in range(4):
            char_button = CharacterButton('*')
            char_button.setMaximumWidth(36)
            self.char_buttons.append(char_button)
            hbox.addWidget(char_button)
        self.accept_button = CharacterButton(_("Accept Word"))
        self.accept_button.clicked.connect(partial(self.process_key, 32))
        self.rejected.connect(partial(self.loop.exit, 1))
        hbox.addWidget(self.accept_button)
        hbox.addStretch(1)
        vbox.addLayout(hbox)

        self.finished_button = QPushButton(_("Seed Entered"))
        self.cancel_button = QPushButton(_("Cancel"))
        self.finished_button.clicked.connect(
            partial(self.process_key, Qt.Key_Return))
        self.cancel_button.clicked.connect(self.rejected)
        buttons = Buttons(self.finished_button, self.cancel_button)
        vbox.addSpacing(40)
        vbox.addLayout(buttons)
        self.refresh()
        self.show()
Example #9
0
    def update(self, proposals, main_window):
        item = self.currentItem()
        current_proposal = item.data(ProposalsModel.TXID,
                                     Qt.UserRole).toString() if item else None

        self.model.set_proposals(proposals)
        self.clear()
        row_count = self.model.rowCount()
        if row_count < 1:
            return
        for r in range(row_count):
            get_data = lambda col, row=r: self.model.data(
                self.model.index(row, col))
            name = _(str(get_data(ProposalsModel.NAME).toString()))
            url = _(str(get_data(ProposalsModel.URL).toString()))
            yes_count = str(get_data(ProposalsModel.YES_COUNT).toString())
            no_count = str(get_data(ProposalsModel.NO_COUNT).toString())
            start_block = str(get_data(ProposalsModel.START_BLOCK).toString())
            end_block = str(get_data(ProposalsModel.END_BLOCK).toString())
            amount = str(get_data(ProposalsModel.AMOUNT).toString())
            address = str(get_data(ProposalsModel.ADDRESS).toString())
            txid = str(get_data(ProposalsModel.TXID).toString())
            display_txid = '%s...%s' % (txid[0:8], txid[-8:])

            item = QTreeWidgetItem([
                name, url, yes_count, no_count, start_block, end_block, amount,
                address, display_txid
            ])
            item.setFont(ProposalsModel.START_BLOCK,
                         QFont(util.MONOSPACE_FONT))
            item.setFont(ProposalsModel.END_BLOCK, QFont(util.MONOSPACE_FONT))
            item.setFont(ProposalsModel.ADDRESS, QFont(util.MONOSPACE_FONT))
            item.setFont(ProposalsModel.TXID, QFont(util.MONOSPACE_FONT))

            if name:
                item.setData(ProposalsModel.NAME, Qt.UserRole, name)
            if txid:
                item.setData(ProposalsModel.TXID, Qt.UserRole, txid)

            is_my_proposal = False
            if main_window.masternode_manager.get_proposal(name) is not None:
                is_my_proposal = True
            if is_my_proposal:
                item.setBackground(ProposalsModel.NAME,
                                   QBrush(QColor(MY_PROPOSAL_COLOR)))
                item.setToolTip(ProposalsModel.NAME,
                                _('You created this proposal.'))

            is_my_address = main_window.wallet.is_mine(address)
            if is_my_address:
                item.setBackground(ProposalsModel.ADDRESS,
                                   QBrush(QColor(MY_ADDRESS_COLOR)))
                item.setToolTip(ProposalsModel.ADDRESS,
                                _('You own this address.'))

            self.addTopLevelItem(item)

            if current_proposal == name:
                self.setCurrentItem(item)
 def on_vote_successful(result):
     errmsg, res = result
     if res:
         QMessageBox.information(self, _('Success'),
                                 _('Successfully voted'))
     else:
         QMessageBox.critical(self, _('Error Voting'), _(errmsg))
     self.proposals_widget.editor.vote_button.setEnabled(True)
Example #11
0
 def add_cosigner_dialog(self, run_next, index, is_valid):
     title = _("Add Cosigner") + " %d" % index
     message = ' '.join([
         _('Please enter the master public key (xpub) of your cosigner.'),
         _('Enter their master private key (xprv) if you want to be able to sign for them.'
           )
     ])
     return self.text_input(title, message, is_valid)
Example #12
0
 def save(self):
     name = 'signed_%s.txn' % (self.tx.hash()[0:8]) if self.tx.is_complete() else 'unsigned.txn'
     fileName = self.main_window.getSaveFileName(_("Select where to save your signed transaction"), name, "*.txn")
     if fileName:
         with open(fileName, "w+") as f:
             f.write(json.dumps(self.tx.as_dict(), indent=4) + '\n')
         self.show_message(_("Transaction saved successfully"))
         self.saved = True
Example #13
0
 def set_pin(self, remove):
     if remove:
         self.msg = _("Confirm on your %s device to disable PIN protection")
     elif self.features.pin_protection:
         self.msg = _("Confirm on your %s device to change your PIN")
     else:
         self.msg = _("Confirm on your %s device to set a PIN")
     self.change_pin(remove)
Example #14
0
 def __init__(self, parent=None):
     MyTreeWidget.__init__(self, parent, self.create_menu, [
         _('Address'),
         _('Label'),
         _('Amount'),
         _('Height'),
         _('Output point')
     ], 1)
     self.setSelectionMode(QAbstractItemView.ExtendedSelection)
Example #15
0
 def show_xpub_dialog(self, xpub, run_next):
     msg = ' '.join([
         _("Here is your master public key."),
         _("Please share it with your cosigners.")
     ])
     vbox = QVBoxLayout()
     layout = SeedLayout(xpub, title=msg, icon=False)
     vbox.addLayout(layout.layout())
     self.exec_layout(vbox, _('Master Public Key'))
     return None
 def delete_current_masternode(self):
     """Delete the masternode that is being viewed."""
     mn = self.selected_masternode()
     if QMessageBox.question(
             self, _('Delete'),
             _('Do you want to remove the masternode configuration for') +
             ' %s?' % mn.alias, QMessageBox.Yes | QMessageBox.No,
             QMessageBox.No) == QMessageBox.Yes:
         self.masternodes_widget.remove_masternode(mn.alias)
         self.masternodes_widget.view.selectRow(0)
Example #17
0
 def restore_seed_dialog(self, run_next, test):
     options = []
     if self.opt_ext:
         options.append('ext')
     if self.opt_bip39:
         options.append('bip39')
     title = _('Enter Seed')
     message = _(
         'Please enter your seed phrase in order to restore your wallet.')
     return self.seed_input(title, message, test, options)
Example #18
0
 def wipe_device():
     wallet = window.wallet
     if wallet and sum(wallet.get_balance()):
         title = _("Confirm Device Wipe")
         msg = _("Are you SURE you want to wipe the device?\n"
                 "Your wallet still has zaap in it!")
         if not self.question(
                 msg, title=title, icon=QMessageBox.Critical):
             return
     invoke_client('wipe_device', unpair_after=True)
Example #19
0
 def __init__(self, parent=None):
     super(ProposalsModel, self).__init__(parent)
     self.proposals = []
     headers = [
         {
             Qt.DisplayRole: _('Name'),
         },
         {
             Qt.DisplayRole: _('URL'),
         },
         {
             Qt.DisplayRole: _('Yes Votes'),
         },
         {
             Qt.DisplayRole: _('No Votes'),
         },
         {
             Qt.DisplayRole: _('Start Block'),
         },
         {
             Qt.DisplayRole: _('End Block'),
         },
         {
             Qt.DisplayRole: _('Amount'),
         },
         {
             Qt.DisplayRole: _('Address'),
         },
         {
             Qt.DisplayRole: _('Fee Tx'),
         },
     ]
     for d in headers:
         d[Qt.EditRole] = d[Qt.DisplayRole]
     self.headers = headers
    def __init__(self, parent=None):
        super(MasternodeEditor, self).__init__(parent)

        self.alias_edit = QLineEdit()
        self.alias_edit.setPlaceholderText(
            _('Enter a name for this masternode'))

        self.vin_edit = PrevOutWidget()

        self.addr_edit = NetworkAddressWidget()
        self.delegate_key_edit = QLineEdit()
        self.delegate_key_edit.setFont(QFont(util.MONOSPACE_FONT))
        self.delegate_key_edit.setPlaceholderText(
            _('Your masternode\'s private key'))
        self.protocol_version_edit = QLineEdit()
        self.protocol_version_edit.setText('70201')

        self.status_edit = QLineEdit()
        self.status_edit.setPlaceholderText(_('Masternode status'))
        self.status_edit.setReadOnly(True)

        form = QFormLayout()
        form.addRow(_('Alias:'), self.alias_edit)
        form.addRow(_('Status:'), self.status_edit)
        form.addRow(_('Collateral zaap Output:'), self.vin_edit)
        form.addRow(_('Masternode Private Key:'), self.delegate_key_edit)
        form.addRow(_('Address:'), self.addr_edit)
        form.addRow(_('Protocol Version:'), self.protocol_version_edit)

        self.setLayout(form)
Example #21
0
    def __init__(self, parent=None):
        super(ProposalsTreeWidget, self).__init__(parent, self.create_menu, [
            _('Name'),
            _('URL'),
            _('Yes Votes'),
            _('No Votes'),
            _('Start Block'),
            _('End Block'),
            _('Amount'),
            _('Address'),
            _('Fee Tx')
        ], 0)

        header = self.header()
        header.setResizeMode(ProposalsModel.NAME, QHeaderView.ResizeToContents)
        header.setResizeMode(ProposalsModel.URL, QHeaderView.Stretch)
        header.setResizeMode(ProposalsModel.YES_COUNT,
                             QHeaderView.ResizeToContents)
        header.setResizeMode(ProposalsModel.NO_COUNT,
                             QHeaderView.ResizeToContents)
        header.setResizeMode(ProposalsModel.ADDRESS,
                             QHeaderView.ResizeToContents)
        header.setResizeMode(ProposalsModel.TXID, QHeaderView.ResizeToContents)

        self.model = ProposalsModel()
Example #22
0
 def confirm_seed_dialog(self, run_next, test):
     self.app.clipboard().clear()
     title = _('Confirm Seed')
     message = ' '.join([
         _('Your seed is important!'),
         _('If you lose your seed, your money will be permanently lost.'),
         _('To make sure that you have properly saved your seed, please retype it here.'
           )
     ])
     seed, is_bip39, is_ext = self.seed_input(title, message, test, None)
     return seed
Example #23
0
 def populate_modes(self):
     self.modes.blockSignals(True)
     self.modes.clear()
     self.modes.addItem(_("Summary Text PIN (requires dongle replugging)") if self.txdata['confirmationType'] == 1 else _("Summary Text PIN is Disabled"))
     if self.txdata['confirmationType'] > 1:
         self.modes.addItem(_("Security Card Challenge"))
         if not self.cfg['pair']:
             self.modes.addItem(_("Mobile - Not paired")) 
         else:
             self.modes.addItem(_("Mobile - %s") % self.cfg['pair'][1]) 
     self.modes.blockSignals(False)
Example #24
0
    def __init__(self, main_widget, parent=None):
        super(ProposalEditor, self).__init__(parent)
        self.main_widget = main_widget

        self.name_edit = QLineEdit()
        self.url_edit = QLineEdit()
        self.start_block_edit = QLineEdit()
        self.end_block_edit = QLineEdit()
        self.amount_edit = QLineEdit()
        self.address_edit = QLineEdit()
        self.txid_edit = QLineEdit()
        for i in [
                self.name_edit, self.url_edit, self.start_block_edit,
                self.end_block_edit, self.amount_edit, self.address_edit,
                self.txid_edit
        ]:
            i.setReadOnly(True)

        self.mapper = QDataWidgetMapper()
        self.mapper.setModel(self.main_widget.proxy_model)
        self.mapper.setSubmitPolicy(QDataWidgetMapper.ManualSubmit)

        self.mapper.addMapping(self.name_edit, ProposalsModel.NAME)
        self.mapper.addMapping(self.url_edit, ProposalsModel.URL)
        self.mapper.addMapping(self.start_block_edit,
                               ProposalsModel.START_BLOCK)
        self.mapper.addMapping(self.end_block_edit, ProposalsModel.END_BLOCK)
        self.mapper.addMapping(self.amount_edit, ProposalsModel.AMOUNT)
        self.mapper.addMapping(self.address_edit, ProposalsModel.ADDRESS)
        self.mapper.addMapping(self.txid_edit, ProposalsModel.TXID)

        block_hbox = QHBoxLayout()
        block_hbox.addWidget(self.start_block_edit)
        block_hbox.addWidget(QLabel(' - '))
        block_hbox.addWidget(self.end_block_edit)

        self.vote_combo = QComboBox()
        self.vote_combo.addItem(_('Yes'))
        self.vote_combo.addItem(_('No'))
        self.vote_button = QPushButton(_('Vote'))
        self.vote_button.clicked.connect(self.cast_vote)

        vote_hbox = util.Buttons(self.vote_combo, self.vote_button)

        form = QFormLayout()
        form.addRow(_('Name:'), self.name_edit)
        form.addRow(_('URL:'), self.url_edit)
        form.addRow(_('Blocks:'), block_hbox)
        form.addRow(_('Monthly Payment:'), self.amount_edit)
        form.addRow(_('Payment Address:'), self.address_edit)
        form.addRow(_('Fee TxID:'), self.txid_edit)

        form.addRow(_('Vote:'), vote_hbox)
        self.setLayout(form)
Example #25
0
 def __init__(self, parent):
     MyTreeWidget.__init__(self, parent, self.create_menu, [
         _('Expires'),
         _('Requestor'),
         _('Description'),
         _('Amount'),
         _('Status')
     ], 2)
     self.setSortingEnabled(True)
     self.header().setResizeMode(1, QHeaderView.Interactive)
     self.setColumnWidth(1, 200)
Example #26
0
 def build_tray_menu(self):
     # Avoid immediate GC of old menu when window closed via its action
     self.old_menu = self.tray.contextMenu()
     m = QMenu()
     for window in self.windows:
         submenu = m.addMenu(window.wallet.basename())
         submenu.addAction(_("Show/Hide"), window.show_or_hide)
         submenu.addAction(_("Close"), window.close)
     m.addAction(_("Dark/Light"), self.toggle_tray_icon)
     m.addSeparator()
     m.addAction(_("Exit Electrum-zaap"), self.close)
     self.tray.setContextMenu(m)
Example #27
0
 def callback_PinMatrixRequest(self, msg):
     if msg.type == 2:
         msg = _("Enter a new PIN for your %s:")
     elif msg.type == 3:
         msg = (_("Re-enter the new PIN for your %s.\n\n"
                  "NOTE: the positions of the numbers have changed!"))
     else:
         msg = _("Enter your current %s PIN:")
     pin = self.handler.get_pin(msg % self.device)
     if not pin:
         return self.proto.Cancel()
     return self.proto.PinMatrixAck(pin=pin)
Example #28
0
 def __init__(self, parent):
     MyTreeWidget.__init__(self, parent, self.create_menu, [
         _('Date'),
         _('Address'), '',
         _('Description'),
         _('Amount'),
         _('Status')
     ], 3)
     self.currentItemChanged.connect(self.item_changed)
     self.itemClicked.connect(self.item_changed)
     self.setSortingEnabled(True)
     self.setColumnWidth(0, 180)
     self.hideColumn(1)
Example #29
0
 def callback_PassphraseRequest(self, req):
     if self.creating_wallet:
         msg = _("Enter a passphrase to generate this wallet.  Each time "
                 "you use this wallet your %s will prompt you for the "
                 "passphrase.  If you forget the passphrase you cannot "
                 "access the zaap in the wallet.") % self.device
     else:
         msg = _("Enter the passphrase to unlock this wallet:")
     passphrase = self.handler.get_passphrase(msg, self.creating_wallet)
     if passphrase is None:
         return self.proto.Cancel()
     passphrase = bip39_normalize_passphrase(passphrase)
     return self.proto.PassphraseAck(passphrase=passphrase)
Example #30
0
 def update_dlg(self):
     self.modes.setCurrentIndex(self.cfg['mode'])
     self.modebox.setVisible(True)
     self.addPair.setText(_("Pair") if not self.cfg['pair'] else _("Re-Pair"))
     self.addPair.setVisible(self.txdata['confirmationType'] > 2)
     self.helpmsg.setText(helpTxt[self.cfg['mode'] if self.cfg['mode'] < 2 else 2 if self.cfg['pair'] else 4])
     self.helpmsg.setMinimumHeight(180 if self.txdata['confirmationType'] == 1 else 100)
     self.pairbox.setVisible(False)
     self.helpmsg.setVisible(True)
     self.pinbox.setVisible(self.cfg['mode'] == 0)
     self.cardbox.setVisible(self.cfg['mode'] == 1)
     self.pintxt.setFocus(True) if self.cfg['mode'] == 0 else self.cardtxt.setFocus(True)
     self.setMaximumHeight(200)