def finalizeStartMessage(self, text): sig1 = text if sig1=="None": # Signature refused by the user self.sigdone.emit("None") return printOK("first signature: %s" % sig1) # ------ some default config scriptSig = '' sequence = 0xffffffff try: # block_hash = hash(currBlock-12) currBlock = self.rpcClient.getBlockCount() if currBlock is None: raise Exception('Unable to get current block number') block_hash = self.rpcClient.getBlockHash(currBlock - 12) if block_hash is None: raise Exception('Unable to get blockhash for block %d' % currBlock - 12) printDbg("Current block from PIVX client: %s" % str(currBlock)) printDbg("Hash of 12 blocks ago: %s" % block_hash) vintx = bytes.fromhex(self.collateral['txid'])[::-1].hex() vinno = self.collateral['txidn'].to_bytes(4, byteorder='big')[::-1].hex() vinsig = num_to_varint(len(scriptSig) / 2).hex() + bytes.fromhex(scriptSig)[::-1].hex() vinseq = sequence.to_bytes(4, byteorder='big')[::-1].hex() ipv6map = ipmap(self.ip, self.port) #printDbg("ipv6map: %s" % ipv6map) collateral_in = num_to_varint(len(self.collateral['pubKey'])/2).hex() + self.collateral['pubKey'] delegate_in = num_to_varint(len(self.mnPubKey)/2).hex() + self.mnPubKey except Exception as e: err_msg = "error in startMessage" printException(getCallerName(), getFunctionName(), err_msg, e) return work_sig_time = self.sig_time.to_bytes(8, byteorder='big')[::-1].hex() work_protoversion = self.protocol_version.to_bytes(4, byteorder='big')[::-1].hex() last_ping_block_hash = bytes.fromhex(block_hash)[::-1].hex() serializedData = serialize_input_str(self.collateral['txid'], self.collateral['txidn'], sequence, scriptSig) + block_hash + str(self.sig_time) printDbg("serializedData: %s" % serializedData) sig2 = self.signature2(serializedData) printOK("second signature: %s" % sig2) work = vintx + vinno + vinsig + vinseq work += ipv6map + collateral_in + delegate_in work += num_to_varint(len(sig1) / 2).hex() + sig1 work += work_sig_time + work_protoversion work += vintx + vinno + vinsig + vinseq work += last_ping_block_hash + work_sig_time work += num_to_varint(len(sig2) / 2).hex() + sig2 # nnLastDsq to zero work += "0"*16 # Emit signal self.sigdone.emit(work)
def getPingMessage(self, fNewSigs, block_hash): if fNewSigs: ss = bytes.fromhex(self.collateral["txid"])[::-1] ss += (self.collateral["txidn"]).to_bytes(4, byteorder='little') ss += bytes([0, 255, 255, 255, 255]) ss += bytes.fromhex(block_hash)[::-1] ss += (self.sig_time).to_bytes(8, byteorder='little') return bitcoin.bin_dbl_sha256(ss) else: scriptSig = '' sequence = 0xffffffff return serialize_input_str(self.collateral['txid'], self.collateral['txidn'], sequence, scriptSig) + \ block_hash + str(self.sig_time)