def get_scriptcode_for_sighash(self) -> bytes:
        """Constructs the scriptcode part of the preimage for OP_CHECKSIG,
        for a partial txin, to create a new signature.

        Note: the base impl works by mimicking a consensus-verifier and extracting
              the required fields from the already complete witness/scriptSig
              and the scriptpubkey of the funding utxo.
              In contrast, here we are the one constructing a spending txin,
              and can have knowledge beyond what will be revealed onchain.
        """
        if self.witness_script:
            if opcodes.OP_CODESEPARATOR in [x[0] for x in script_GetOp(self.witness_script)]:
                raise Exception('OP_CODESEPARATOR black magic is not supported')
            return self.witness_script
        if not self.is_segwit() and self.redeem_script:
            if opcodes.OP_CODESEPARATOR in [x[0] for x in script_GetOp(self.redeem_script)]:
                raise Exception('OP_CODESEPARATOR black magic is not supported')
            return self.redeem_script

        if desc := self.script_descriptor:
            sc = desc.expand()
            if script := sc.scriptcode_for_sighash:
                return script
            raise Exception(f"don't know scriptcode for descriptor: {desc.to_string()}")

        raise UnknownTxinType(f'cannot construct preimage_script')
Constructs the scriptcode part of the preimage for OP_CHECKSIG,
        for a partial txin, to create a new signature.

        Note: the base impl works by mimicking a consensus-verifier and extracting
              the required fields from the already complete witness/scriptSig
              and the scriptpubkey of the funding utxo.
              In contrast, here we are the one constructing a spending txin,
              and can have knowledge beyond what will be revealed onchain.
        
electrum/transaction.py