Thanks in advance for getting here and trying to see my bad code.
So, I have some trouble on trying to "sell" tickets to people and give them the possibility to buy >=1.
Now, the problem, is that i can't associate an array of 6 numbers to the ticket.
What is wrong? Thanks!
//SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import "github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol";
contract Lottery is Ownable {
uint256 constant ticketprice = 1 ether;
address pool = addresshere;
uint ID = 0;
uint256 startinglottery;
struct Picket {
uint ID;
uint[6] ticket;
}
mapping (address => Picket) hope;
address[] players;
constructor() {
startinglottery = 0;
}
function StartLottery() public onlyOwner {
startinglottery = 1;
}
function EndLottery() public onlyOwner {
startinglottery = 0;
}
function BuyTicket(address _address) public payable {
//check
require(msg.value >= ticketprice, "not enought money!");
require(startinglottery == 1, "lottery isn't started.");
//pay
payable(pool).transfer(msg.value);
//do stuff
Picket memory picket = hope[_address];
picket.ID = ID;
picket.ticket = [1,2,3,4,5]; //should be random with chainlink, but trying to understand the basic one.
players.push(_address);
ID ;
}
function getTicket(address _address) public view returns(uint, uint[6] memory) {
return (hope[_address].ID, hope[_address].ticket);
}
}
CodePudding user response:
picket.ticket = [1,2,3,4,5];
Here you're trying to assign an array of 5 items to an array of 6 items. You need to explicitly define the 6th value - which is the default value of 0
.
Also, since you're passing hardcoded low values, the compiler incorrectly marks them as uint8
. You need to cast at least the first one to uint256
(or its alias uint
) for the compiler to recognize the correct datatype.
picket.ticket = [uint256(1), 2, 3, 4, 5, 0];