def signature2(self, block_hash): try: fNewSigs = NewSigsActive(self.currHeight, self.isTestnet) mnping = self.getPingMessage(fNewSigs, block_hash) if fNewSigs: printDbg("mnping: %s" % mnping.hex()) sig2 = ecdsa_sign_bin(mnping, self.mnWIF) # local else: printDbg("mnping: %s" % mnping) sig2 = ecdsa_sign(mnping, self.mnWIF) return (b64decode(sig2).hex()), fNewSigs except Exception as e: err_msg = "error in signature2" printException(getCallerName(), getFunctionName(), err_msg, e.args)
def signature1(self, device): try: fNewSigs = NewSigsActive(self.currHeight, self.isTestnet) if fNewSigs: serializedData = self.getNewBroadcastMessage() else: serializedData = self.getOldBroadcastMessage() printDbg("SerializedData: %s" % serializedData) # HW wallet signature device.signMess(self.tab_main.caller, self.nodePath, serializedData, self.isTestnet) #wait for signal when device.sig1 is ready then --> finalizeStartMessage except Exception as e: err_msg = "error in signature1" printException(getCallerName(), getFunctionName(), err_msg, e.args) except KeyboardInterrupt: err_msg = "Keyboard Interrupt" printException(getCallerName(), getFunctionName(), err_msg, '') return None
def vote_thread(self, ctrl, vote_code): # vote_code index for ["yes", "abstain", "no"] if not isinstance(vote_code, int) or vote_code not in range(3): raise Exception("Wrong vote_code %s" % str(vote_code)) self.successVotes = 0 self.failedVotes = 0 self.currHeight = self.caller.rpcClient.getBlockCount() # save delay check data to cache and persist settings self.caller.parent.cache["votingDelayCheck"] = persistCacheSetting('cache_vdCheck', self.ui.randomDelayCheck.isChecked()) self.caller.parent.cache["votingDelayNeg"] = persistCacheSetting('cache_vdNeg', self.ui.randomDelayNeg_edt.value()) self.caller.parent.cache["votingDelayPos"] = persistCacheSetting('cache_vdPos', self.ui.randomDelayPos_edt.value()) for prop in self.selectedProposals: for mn in self.votingMasternodes: vote_sig = '' serialize_for_sig = '' sig_time = int(time.time()) try: # Get mnPrivKey currNode = next(x for x in self.caller.masternode_list if x['name']==mn[1]) if currNode is None: printDbg("currNode not found for current voting masternode %s" % mn[1]) self.clear() raise Exception() mnPrivKey = currNode['mnPrivKey'] self.isTestnet = currNode['isTestnet'] # Add random delay offset if self.ui.randomDelayCheck.isChecked(): minuns_max = int(self.ui.randomDelayNeg_edt.value()) plus_max = int(self.ui.randomDelayPos_edt.value()) delay_secs = random.randint(-minuns_max, plus_max) sig_time += delay_secs # Print Debug line to console mess = "Processing '%s' vote on behalf of masternode [%s]" % (self.vote_codes[vote_code], mn[1]) mess += " for the proposal {%s}" % prop.name if self.ui.randomDelayCheck.isChecked(): mess += " with offset of %d seconds" % delay_secs printDbg(mess) # Serialize and sign vote fNewSigs = NewSigsActive(self.currHeight, self.isTestnet) serialize_for_sig = self.getBudgetVoteMess(fNewSigs, mn[0][:64], currNode['collateral']['txidn'], prop.Hash, vote_code, sig_time) if fNewSigs: vote_sig = ecdsa_sign_bin(serialize_for_sig, mnPrivKey) else: vote_sig = ecdsa_sign(serialize_for_sig, mnPrivKey) # Broadcast the vote v_res = self.caller.rpcClient.mnBudgetRawVote( mn_tx_hash=currNode['collateral'].get('txid'), mn_tx_index=int(currNode['collateral'].get('txidn')), proposal_hash=prop.Hash, vote=self.vote_codes[vote_code], time=sig_time, vote_sig=vote_sig) printOK(v_res) if v_res == 'Voted successfully': self.successVotes += 1 else: self.failedVotes += 1 except Exception as e: err_msg = "Exception in vote_thread - check MN privKey" printException(getCallerName(), getFunctionName(), err_msg, e.args)