enum
// 0-> Open state, 1 -> closed state, ...
enum LOTTERY_STATE {OPEN, CLOSED, CALCULATING_WINNER}
//init lottery_state as type: LOTTERY_STATE (is a class).
LOTTERY_STATE public lottery_state;
constructor(address _pricefeedaddress) public {
ethusd_pricefeed = AggregatorV3Interface(_pricefeedaddress);
lottery_state = LOTTERY_STATE.CLOSED; // can also: lottery_state = 1
}
// init outside connstructor, so its state variable.
// then assign within constructor.
// if you init + assign within constructor, it wont be state variable.
// example usage:
function enter() public payable {
//is lottery open?
require(lottery_state == LOTTERY_STATE.OPEN, "Lottery is not open!");
}Declaring and importing Enum
Last updated