I am following a tutorial to write a registrant contract and when I try to submit transactions to the contract I always get error :it seems this transaction will fail. If you submit it, it may consume all the gas upi provide
.
I create run a private block chain on my laptop and I deployed the contract through Mist. The source code are shown below:
pragma solidity ^0.4.18;
contract EventRegistrant {
//basic class of registrant
struct Registrant {
uint amount;
uint numTickets;
string email;
}
//define variables
address public owner;
uint public numTicketsSold;
uint public quota;
uint public price;
mapping (address => Registrant) registrantsPaid;
event Deposit (address _from, uint _amount);
event Refund (address _to, uint _amount);
//Modifiers to define following functions
//character "_" means this is a modifier
modifier onlyOwner(){
require(msg.sender != owner);
_;
}
modifier soldOut(){
require(numTicketsSold >= quota);
_;
}
function EventRegistrant(uint _quota, uint _price) public {
owner = msg.sender;
numTicketsSold = 0;
quota = _quota;
price = _price;
}
function buyTicket(string email, uint numTickets) soldOut public payable {
uint totalAmount = price * numTickets;
require(msg.value > totalAmount);
if (registrantsPaid[msg.sender].amount > 0) {
registrantsPaid[msg.sender].amount += msg.value;
registrantsPaid[msg.sender].numTickets += numTickets;
registrantsPaid[msg.sender].email = email;
} else {
registrantsPaid[msg.sender].amount = totalAmount;
registrantsPaid[msg.sender].numTickets = numTickets;
registrantsPaid[msg.sender].email = email;
}
numTicketsSold += numTickets;
if (msg.value > totalAmount) {
uint refundAmount = msg.value - totalAmount;
require(msg.sender.send(refundAmount));
}
Deposit(msg.sender, msg.value);
}
function refundTickets(address buyer) onlyOwner public {
if (registrantsPaid[buyer].amount > 0) {
if (this.balance >= registrantsPaid[buyer].amount) {
registrantsPaid[buyer].amount = 0;
numTicketsSold = numTicketsSold - registrantsPaid[buyer].numTickets;
require(buyer.send(registrantsPaid[buyer].amount));
Refund(buyer, registrantsPaid[buyer].amount);
}
}
}
function withdrawFunds() onlyOwner public {
require(owner.send(this.balance));
}
function getRegistrantsAmountPaid(address buyer) public view returns (uint) {
return registrantsPaid[buyer].amount;
}
//destructor, to delete the contract when there is no need
function kill() onlyOwner public {
selfdestruct(owner);
}
}
This is how my contract looks like in the Mist.
This is error when I submit the transaction.
Anyone can help me? thank you in advance.