Help with endstop switch installing

Im trying to build this astro tracker and got it to work the motor but i cannot figure out how to wire the endstop. code is below and thanks for the help

// stepper controller pin mapping
const int stepperEnPin = 0;
const int stepperMS1Pin = 1;
const int stepperMS2Pin = 2;
const int stepperMS3Pin = 3;
const int stepperRstPin = 4;
const int stepperSlpPin = 5;
const int stepperStepPin = 6;
const int stepperDirPin = 7;
const int endstopPin = 8;
const int endstopCommonPin = 9;

// other pin mapping
const int ledPin = 13;
const int switchPin = 12;
const int buttonPin = 11;

byte ledPulseLength;
byte ledPulseCount;
boolean ledPulseDown;

boolean trackEnable;

unsigned long next_step;

void setup()
{
pinMode(stepperEnPin, OUTPUT);
pinMode(stepperMS1Pin, OUTPUT);
pinMode(stepperMS2Pin, OUTPUT);
pinMode(stepperMS3Pin, OUTPUT);
pinMode(stepperRstPin, OUTPUT);
pinMode(stepperSlpPin, OUTPUT);
pinMode(stepperStepPin, OUTPUT);
pinMode(stepperDirPin, OUTPUT);
pinMode(endstopPin, INPUT_PULLUP);
pinMode(endstopCommonPin, OUTPUT);

digitalWrite(stepperEnPin, LOW);
digitalWrite(stepperMS1Pin, bitRead(microstep,2));
digitalWrite(stepperMS2Pin, bitRead(microstep,1));
digitalWrite(stepperMS3Pin, bitRead(microstep,0));
digitalWrite(stepperRstPin, HIGH);
digitalWrite(stepperSlpPin, HIGH);
digitalWrite(stepperDirPin, trackDir);
digitalWrite(endstopCommonPin, LOW);

pinMode(ledPin, OUTPUT);

trackEnable = true;

home();
next_step = micros()+step_delay;

}

So you might want to put two switches; call them TopEnd and BottomEnd.

You'll want to wire them so that if TopEnd is triggered power is removed from the motor to prevent the motor from driving further towards the top end and to send a signal to an input pin to declare reached the top end and have code wrote to handle the situation.

Do the same thing for bottom end.