def send_announce(self, alias): """Send an announce for a masternode.""" def send_thread(): return self.manager.send_announce(alias) def on_send_successful(result): errmsg, was_announced = result if was_announced: self.print_msg( 'Successfully broadcasted MasternodeAnnounce for "%s"' % alias) QMessageBox.information( self, _('Success'), _('Masternode activated successfully.')) else: self.print_error('Failed to broadcast MasternodeAnnounce: %s' % errmsg) QMessageBox.critical(self, _('Error Sending'), _(errmsg)) self.masternodes_widget.refresh_items() self.masternodes_widget.select_masternode(alias) def on_send_error(err): self.print_error('Error sending Masternode Announce message:') # 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.masternodes_widget.refresh_items() self.masternodes_widget.select_masternode(alias) self.print_msg('Sending Masternode Announce message...') util.WaitingDialog(self, _('Broadcasting masternode...'), send_thread, on_send_successful, on_send_error)
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 submit_waiting_proposals(self): """Submit the proposals that are ready to the network.""" # Submit the proposals that are ready. results = [('', '', False)] * len(self.unsubmitted_proposals) def submit_thread(): for i, (proposal_name, txid) in enumerate(self.unsubmitted_proposals): errmsg, success = self.parent.masternode_manager.submit_proposal(proposal_name, save=False) results[i] = (proposal_name, errmsg, success) if success: print_error('Sucessfully submitted proposal "%s"' % proposal_name) else: print_error('Failed to submit proposal "%s": %s' % (proposal_name, errmsg)) return results def on_done(): msg = '' for proposal_name, errmsg, success in results: if success: msg += '<b>' + proposal_name + '</b>' + _(': submitted successfully.') else: msg += '<b>' + proposal_name + '</b>' + _(': failed! "%s"' % errmsg) msg += '\n' QMessageBox.information(self, _('Results'), msg) self.update_unsubmitted_proposals() self.parent.masternode_manager.save() self.waiting_dialog = util.WaitingDialog(self, _('Submitting Proposals...'), submit_thread, on_complete=on_done) self.waiting_dialog.start()
def cast_vote(self, proposal_name, vote_yes): """Vote for a proposal. This is called by ProposalsWidget.""" vote_choice = 'yes' if vote_yes else 'no' mn = self.selected_masternode() if not mn.announced: return QMessageBox.critical(self, _('Cannot Vote'), _('Masternode has not been activated.')) # Check that we can vote before asking for a password. try: self.manager.check_can_vote(mn.alias, proposal_name) except Exception as e: return QMessageBox.critical(self, _('Cannot Vote'), _(str(e))) self.proposals_widget.editor.vote_button.setEnabled(False) def vote_thread(): return self.manager.vote(mn.alias, proposal_name, vote_choice) # Show the result. 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) def on_vote_failed(err): self.print_error('Error sending vote:') # 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.proposals_widget.editor.vote_button.setEnabled(True) util.WaitingDialog(self, _('Voting...'), vote_thread, on_vote_successful, on_vote_failed)
def create_proposal_tx(self, proposal, pw, callback): """Create and sign the proposal fee transaction.""" result = [False] def tx_thread(): return self.parent.masternode_manager.create_proposal_tx(proposal.proposal_name, pw, save=False) def on_tx_made(tx): result[0] = tx def on_done(): callback(proposal, result[0]) self.waiting_dialog = util.WaitingDialog(self, _('Creating Transaction...'), tx_thread, on_tx_made, on_done) self.waiting_dialog.start()