contract AirdropBlockHeight is VRFConsumerBase {

    bytes32 internal keyHash;
    uint256 internal fee;
    
    address public owner;
    
    uint256 public blockHeightHigh;
    uint256 public blockHeightLow;
    
    mapping (uint256 => uint256) public airdropHeights;
    uint256 public airdropCount;
    
    uint256 public randomNumber;
 
    
    /**
     * Constructor inherits VRFConsumerBase
     * 
     * Network: Mainnet
     * Chainlink VRF Coordinator address: 0xf0d54349aDdcf704F77AE15b96510dEA15cb7952
     * LINK token address:                0x514910771af9ca656af840dff83e8264ecf986ca
     * Key Hash: 0xAA77729D3466CA35AE8D28B3BBAC7CC36A5031EFDC430821C02BC31A238AF445
     */
    constructor() 
        VRFConsumerBase(
            0xf0d54349aDdcf704F77AE15b96510dEA15cb7952, // VRF Coordinator
            0x514910771AF9Ca656af840dff83E8264EcF986CA  // LINK Token
        ) public
    {
        keyHash = 0xAA77729D3466CA35AE8D28B3BBAC7CC36A5031EFDC430821C02BC31A238AF445;
        fee = 2 * 10 ** 18; // 2 LINK
        owner = msg.sender;
        airdropCount = 0;
    }
    
    
    // Checks if the function caller is the owner of the contract
    modifier onlyOwner() {
        require(msg.sender == owner);
        _;
    }

    
    /** 
     * Requests randomness from a user-provided seed
     */
    function getRandomNumber(uint256 userProvidedSeed, uint256 high, uint256 low) public onlyOwner returns (bytes32 requestId) {
        require(LINK.balanceOf(address(this)) >= fee, "Not enough LINK - fill contract with faucet");
        require(high > low, "High must be larger than low.");
        blockHeightLow = low;
        blockHeightHigh = high;
        return requestRandomness(keyHash, fee, userProvidedSeed);
    }

    /**
     * Callback function used by VRF Coordinator
     */
    function fulfillRandomness(bytes32 requestId, uint256 randomness) internal override {
        uint256 spread = blockHeightHigh - blockHeightLow + 1; // inclusive on both sides
        uint256 mod = (randomness % spread);
        randomNumber = randomness;
        airdropHeights[airdropCount] = blockHeightLow + mod;
        airdropCount++;
    }
    
    
}
function fulfillRandomness(bytes32 requestId, uint256 randomness) internal override {
    uint256 spread = blockHeightHigh - blockHeightLow + 1; // inclusive on both sides
    uint256 mod = (randomness % spread);
    randomNumber = randomness;
    airdropHeights[airdropCount] = blockHeightLow + mod;
    airdropCount++;
}

/**
 * Callback function used by VRF Coordinator
 */