def data(self, index, role=Qt.DisplayRole): if not index.isValid(): return None if role not in [Qt.DisplayRole, Qt.ToolTipRole, Qt.EditRole]: return None data = None c = index.column() if c == 0: if self.utxo_script: data = self.utxo_script.get_human() elif c == 1: if self.tx: data = b2x(self.tx.serialize()) elif c == 2: data = self.inIdx elif c == 3: data = sighash_types_by_value[self.sighash_type] elif c == 4: if role == Qt.CheckStateRole: data = Qt.Checked if self.anyone_can_pay else Qt.Unchecked else: data = self.anyone_can_pay elif c == self.SigHashName: data = sig_hash_name(self.sighash_type | SIGHASH_ANYONECANPAY if self. anyone_can_pay else self.sighash_type) elif c == self.SigHashExplanation: data = sig_hash_explanation(self.sighash_type | SIGHASH_ANYONECANPAY if self. anyone_can_pay else self.sighash_type) return data
def data(self, index, role = Qt.DisplayRole): if not index.isValid(): return None if role not in [Qt.DisplayRole, Qt.ToolTipRole, Qt.EditRole]: return None data = None c = index.column() if c == 0: if self.utxo_script: data = self.utxo_script.get_human() elif c == 1: if self.tx: data = b2x(self.tx.serialize()) elif c == 2: data = self.inIdx elif c == 3: data = sighash_types_by_value[self.sighash_type] elif c == 4: if role == Qt.CheckStateRole: data = Qt.Checked if self.anyone_can_pay else Qt.Unchecked else: data = self.anyone_can_pay elif c == self.SigHashName: data = sig_hash_name(self.sighash_type | SIGHASH_ANYONECANPAY if self.anyone_can_pay else self.sighash_type) elif c == self.SigHashExplanation: data = sig_hash_explanation(self.sighash_type | SIGHASH_ANYONECANPAY if self.anyone_can_pay else self.sighash_type) return data
def sign_transaction(self): """Sign the transaction.""" script, txTo, inIdx, hash_type = self.model.get_fields() if inIdx >= len(txTo.vin): self.set_result_message('Nonexistent input specified for signing.', error=True) return if not script: self.set_result_message('Invalid output script.', error=True) return privkey = self.get_private_key() if not privkey: self.set_result_message('Could not parse private key.', error=True) return sig_hash = chainparams.signature_hash(script, txTo, inIdx, hash_type) sig = privkey.sign(sig_hash) hash_type_hex = format_hex_string(hex(hash_type), with_prefix=False).decode('hex') sig = sig + hash_type_hex txTo.vin[inIdx].scriptSig = Script([sig, privkey.pub]) if self.verify_script.isChecked(): # Try verify try: VerifyScript(txTo.vin[inIdx].scriptSig, script, txTo, inIdx, (SCRIPT_VERIFY_P2SH, )) except Exception as e: self.set_result_message('Error when verifying: %s' % str(e), error=True) return self.dock.deserialize_raw(b2x(txTo.serialize())) # Deserializing a tx clears the model, so re-populate. self.model.set_fields(script=script.get_human(), inIdx=inIdx, hashType=hash_type) self.set_result_message( 'Successfully set scriptSig for input %d (SigHash type: %s).' % (inIdx, sig_hash_name(hash_type)))
def data(self, index, role = Qt.DisplayRole): if not index.isValid(): return None verified, hash_type = self.inputs[index.row()] c = index.column() data = None if c == 0: if role in [Qt.DisplayRole, Qt.EditRole]: data = str(index.row()) elif c == 1: if role in [Qt.DisplayRole, Qt.ToolTipRole]: data = 'Verified' if verified else 'Unverified' elif role == Qt.EditRole: data = verified elif c == 2: if role in [Qt.DisplayRole, Qt.ToolTipRole]: data = sig_hash_name(hash_type) elif role == Qt.EditRole: data = hash_type return data
def sign_transaction(self): """Sign the transaction.""" script, txTo, inIdx, hash_type = self.model.get_fields() if inIdx >= len(txTo.vin): self.set_result_message('Nonexistent input specified for signing.', error=True) return if not script: self.set_result_message('Invalid output script.', error=True) return privkey = self.get_private_key() if not privkey: self.set_result_message('Could not parse private key.', error=True) return sig_hash = chainparams.signature_hash(script, txTo, inIdx, hash_type) sig = privkey.sign(sig_hash) hash_type_hex = format_hex_string(hex(hash_type), with_prefix=False).decode('hex') sig = sig + hash_type_hex txTo.vin[inIdx].scriptSig = Script([sig, privkey.pub]) if self.verify_script.isChecked(): # Try verify try: VerifyScript(txTo.vin[inIdx].scriptSig, script, txTo, inIdx, (SCRIPT_VERIFY_P2SH,)) except Exception as e: self.set_result_message('Error when verifying: %s' % str(e), error=True) return self.dock.deserialize_raw(b2x(txTo.serialize())) # Deserializing a tx clears the model, so re-populate. self.model.set_fields(script=script.get_human(), inIdx=inIdx, hashType=hash_type) self.set_result_message('Successfully set scriptSig for input %d (SigHash type: %s).' % (inIdx, sig_hash_name(hash_type)))