Github repo located here: https://github.com/supsam89/digiwear_nft_drop
The command I'm having problems with is brownie run scripts/deploy.py
I am trying to deploy a drop/lottery contract that picks multiple winners randomly based on entrants (then will eventually transfer an NFT to them).
When I get to end the drop/lottery function it either takes too long (gas intensive) or doesn't work. After performing time.sleep(60)
the state remains as "Calculating winners".
The function I believe is causing the problem in NFTDrop.sol:
function endDrop() public onlyOwner {
drop_state = DROP_STATE.CALCULATING_WINNERS;
bytes32 requestId = requestRandomness(keyhash, fee);
emit RequestedRandomness(requestId);
}
function fulfillRandomness(bytes32 _requestId, uint256 _randomness) internal override {
require(
drop_state == DROP_STATE.CALCULATING_WINNERS,
"Not calculating winners yet!"
);
require(_randomness > 0, "randomness-not-found");
uint256[] memory expandedValues = expand(_randomness, tokenAmount);
for (uint256 i = 0; i < tokenAmount; i++) {
uint256 indexOfWinner = expandedValues[i] % entrants.length;
recentWinner = entrants[indexOfWinner];
winners.push(recentWinner);
}
drop_state = DROP_STATE.CLOSED;
randomness = _randomness;
}
function expand(uint256 _randomness, uint256 _numberOfTokens) public pure returns (uint256[] memory expandedValues) {
expandedValues = new uint256[](_numberOfTokens);
for (uint256 i = 0; i < _numberOfTokens; i++) {
expandedValues[i] = uint256(keccak256(abi.encode(_randomness, i)));
}
return expandedValues;
}
Any help to the problem or advise on how to code this better would be greatly appreciated!
Thanks in advance.